Skip to content

Commit

Permalink
Merge pull request #857 from 0xPolygonHermez/feature/check-files
Browse files Browse the repository at this point in the history
Adding check for circom files
  • Loading branch information
fractasy committed Jul 11, 2024
2 parents c67f9a5 + 72c8b59 commit 5e20747
Show file tree
Hide file tree
Showing 7 changed files with 589 additions and 2 deletions.
260 changes: 260 additions & 0 deletions src/config/setup-10.txt

Large diffs are not rendered by default.

260 changes: 260 additions & 0 deletions src/config/setup-11.txt

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions src/prover/prover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ Prover::Prover(Goldilocks &fr,
if (config.generateProof())
{
TimerStart(PROVER_INIT);

checkSetupHash(config.zkevmVerifier);
checkSetupHash(config.recursive1Verifier);
checkSetupHash(config.recursive2Verifier);
checkSetupHash(config.recursivefVerifier);
checkSetupHash(config.finalVerifier);

lastComputedRequestEndTime = 0;

sem_init(&pendingRequestSem, 0, 0);
Expand Down
54 changes: 54 additions & 0 deletions src/utils/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -759,4 +759,58 @@ void poseidonLinearHash (const vector<uint8_t> &_data, Goldilocks::Element (&res

// Free allocated memory
delete[] pBuffer;
}

void checkSetupHash(std::string datFileName) {
int fd;
struct stat sb;

fd = open(datFileName.c_str(), O_RDONLY);
if (fd == -1)
{
std::cout << ".dat file not found: " << datFileName << "\n";
throw std::system_error(errno, std::generic_category(), "open");
}

if (fstat(fd, &sb) == -1)
{
throw std::system_error(errno, std::generic_category(), "fstat");
}


uint8_t *bdata = (uint8_t *)mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0);

string hash;
SHA256(bdata, sb.st_size, hash);

string hashFormatted = hash.substr(2);
if(hash.size() % 2 != 0) hashFormatted = "0" + hashFormatted;

std::string setupFile = "src/config/setup-" + to_string(PROVER_FORK_ID) + ".txt";
std::ifstream file(setupFile);
if (!file.is_open()) {
std::cerr << "Error opening file: " << setupFile << std::endl;
exit(1);
}

std::string line;
std::string setupHash;
while (std::getline(file, line)) {
if (line.find(datFileName) != std::string::npos) {
std::istringstream iss(line);
iss >> setupHash;
}
}

if(setupHash == "") {
std::cerr << "Hash not found in setup file" << endl;
exit(1);
}

if(hashFormatted != setupHash) {
std::cerr << datFileName + "hash is different in setup file: " + setupHash + " than the actual hash " + hashFormatted << endl;
exit(1);
} else {
std::cout << datFileName + " config file is correct" << endl;
}
}
3 changes: 3 additions & 0 deletions src/utils/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "input.hpp"
#include "proof_fflonk.hpp"
#include "definitions.hpp"
#include "sha256.hpp"

using json = nlohmann::json;
using ordered_json = nlohmann::ordered_json;
Expand Down Expand Up @@ -108,4 +109,6 @@ extern string emptyString;
// Calculates the Poseidon linear hash of a buffer
void poseidonLinearHash (const vector<uint8_t> &_data, Goldilocks::Element (&result)[4]);

void checkSetupHash (std::string datFilename);

#endif
4 changes: 2 additions & 2 deletions testvectors/config_runFile_BatchProof.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
"mapConstPolsFile": false,
"mapConstantsTreeFile": false,

"inputFile": "testvectors/collection/fork_9/input_executor_3.json",
"inputFile2": "testvectors/collection/fork_9/input_executor_1.json",
"inputFile": "testvectors/collection/fork_10/input_executor_3.json",
"inputFile2": "testvectors/collection/fork_10/input_executor_1.json",

"outputPath": "runtime/output",
"configPath": "config",
Expand Down
3 changes: 3 additions & 0 deletions tools/copy_generate_files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ rsync -avz --progress ${EXCLUDE_OPTION} ${CONFIG_DIR}/ config/
rm config/scripts/rom.json
rm config/scripts/metadata-rom.txt

# Copy setup files
cp ${CONFIG_DIR}/../build/sha256.txt src/config/setup-${FORK_VERSION}.txt

#Uncomment the following line if you want to generate source code the first time after the release files generation

#Copy the chelpers files
Expand Down

0 comments on commit 5e20747

Please sign in to comment.