From 7baf9d5e670f769db1edc2c51e8aa4e343d2443c Mon Sep 17 00:00:00 2001 From: fractasy Date: Thu, 12 Sep 2024 09:48:56 +0000 Subject: [PATCH] Protect with try/catch parsing of genFinalProof input JSON data --- src/prover/prover.cpp | 12 ++++++------ src/service/aggregator/aggregator_client.cpp | 13 +++++++++++-- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/prover/prover.cpp b/src/prover/prover.cpp index 43d6af8b1..fc9dd3651 100644 --- a/src/prover/prover.cpp +++ b/src/prover/prover.cpp @@ -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) @@ -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); @@ -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(); } @@ -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(); } diff --git a/src/service/aggregator/aggregator_client.cpp b/src/service/aggregator/aggregator_client.cpp index f643112b1..75d3334c0 100644 --- a/src/service/aggregator/aggregator_client.cpp +++ b/src/service/aggregator/aggregator_client.cpp @@ -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)