Skip to content

Commit

Permalink
Protect with try/catch parsing of genFinalProof input JSON data
Browse files Browse the repository at this point in the history
  • Loading branch information
fractasy committed Sep 12, 2024
1 parent 860cfd6 commit 7baf9d5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
12 changes: 6 additions & 6 deletions src/prover/prover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,17 @@ Prover::Prover(Goldilocks &fr,
if (config.zkevmCmPols.size() > 0)
{
pAddress = mapFile(config.zkevmCmPols, polsSize, true);
zklog.info("Prover::genBatchProof() successfully mapped " + to_string(polsSize) + " bytes to file " + config.zkevmCmPols);
zklog.info("Prover::Prover() successfully mapped " + to_string(polsSize) + " bytes to file " + config.zkevmCmPols);
}
else
{
pAddress = calloc_zkevm(polsSize, 1);
if (pAddress == NULL)
{
zklog.error("Prover::genBatchProof() failed calling malloc() of size " + to_string(polsSize));
zklog.error("Prover::Prover() failed calling malloc() of size " + to_string(polsSize));
exitProcess();
}
zklog.info("Prover::genBatchProof() successfully allocated " + to_string(polsSize) + " bytes");
zklog.info("Prover::Prover() successfully allocated " + to_string(polsSize) + " bytes");
}

#if defined(__USE_CUDA__) && defined(ENABLE_EXPERIMENTAL_CODE)
Expand Down Expand Up @@ -999,7 +999,7 @@ void Prover::genFinalProof(ProverRequest *pProverRequest)
CircomFinalFork12::loadJsonImpl(ctxFinal, zkinRecursiveF);
if (ctxFinal->getRemaingInputsToBeSet() != 0)
{
zklog.error("Prover::genProof() Not all inputs have been set. Only " + to_string(CircomFinalFork12::get_main_input_signal_no() - ctxFinal->getRemaingInputsToBeSet()) + " out of " + to_string(CircomFinalFork12::get_main_input_signal_no()));
zklog.error("Prover::genFinalProof() Not all inputs have been set. Only " + to_string(CircomFinalFork12::get_main_input_signal_no() - ctxFinal->getRemaingInputsToBeSet()) + " out of " + to_string(CircomFinalFork12::get_main_input_signal_no()));
exitProcess();
}
TimerStopAndLog(CIRCOM_FINAL_LOAD_JSON);
Expand Down Expand Up @@ -1035,7 +1035,7 @@ void Prover::genFinalProof(ProverRequest *pProverRequest)
zkey = BinFileUtils::openExisting(config.finalStarkZkey, "zkey", 1, binPointer, polsSize - lengthPrecomputedBuffer);
protocolId = Zkey::getProtocolIdFromZkey(zkey.get());
if(protocolId != Zkey::FFLONK_PROTOCOL_ID) {
zklog.error("Prover::genBatchProof() zkey protocolId has to be Fflonk");
zklog.error("Prover::genFinalProof() zkey protocolId has to be Fflonk");
exitProcess();
}

Expand Down Expand Up @@ -1068,7 +1068,7 @@ void Prover::genFinalProof(ProverRequest *pProverRequest)
}
catch (std::exception &e)
{
zklog.error("Prover::genProof() got exception in rapid SNARK:" + string(e.what()));
zklog.error("Prover::genFinalProof() got exception in rapid SNARK:" + string(e.what()));
exitProcess();
}

Expand Down
13 changes: 11 additions & 2 deletions src/service/aggregator/aggregator_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -634,8 +634,17 @@ bool AggregatorClient::GenFinalProof (const aggregator::v1::GenFinalProofRequest
#endif

// Set the input
pProverRequest->finalProofInput = json::parse(genFinalProofRequest.recursive_proof());

try
{
pProverRequest->finalProofInput = json::parse(genFinalProofRequest.recursive_proof());
}
catch (json::parse_error& ex)
{
zklog.error("AggregatorClient::GenFinalProof() failed parsing genFinalProofRequest.recursive_proof at byte=" + to_string(ex.byte) + " error=" + ex.what());
zklog.error("input=" + genFinalProofRequest.recursive_proof());
genFinalProofResponse.set_result(aggregator::v1::Result::RESULT_ERROR);
return false;
}
// Set the aggregator address
string auxString = Remove0xIfPresent(genFinalProofRequest.aggregator_addr());
if (auxString.size() > 40)
Expand Down

0 comments on commit 7baf9d5

Please sign in to comment.