From d803c547b2c9775da60f092979e212667487ec98 Mon Sep 17 00:00:00 2001 From: eigmax Date: Fri, 9 Jun 2023 20:50:14 +0800 Subject: [PATCH] Be compitable with Groth16 --- src/config/config.cpp | 9 ++++++++- src/prover/prover.cpp | 11 ++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/config/config.cpp b/src/config/config.cpp index c283d203e..6602c37e5 100644 --- a/src/config/config.cpp +++ b/src/config/config.cpp @@ -1,4 +1,5 @@ #include +#include #include #include "definitions.hpp" #include "config.hpp" @@ -263,7 +264,13 @@ void Config::load(json &config) finalVerifier = configPath + "/final/final.verifier.dat"; finalVerkey = configPath + "/final/final.fflonk.verkey.json"; finalStarkZkey = configPath + "/final/final.fflonk.zkey"; - + // check if file exists + ifstream f; + f.open(finalVerkey); + if (f.fail()) { + finalVerkey = configPath + "/final/final.verkey.json"; + finalStarkZkey = configPath + "/final/final.g16.0001.zkey"; + } if (config.contains("rom") && config["rom"].is_string()) rom = config["rom"]; diff --git a/src/prover/prover.cpp b/src/prover/prover.cpp index 45ada1f5f..7f8878af7 100644 --- a/src/prover/prover.cpp +++ b/src/prover/prover.cpp @@ -113,8 +113,10 @@ Prover::Prover(Goldilocks &fr, cout << "Prover::genBatchProof() successfully allocated " << polsSize << " bytes" << endl; } - prover = new Fflonk::FflonkProver(AltBn128::Engine::engine, pAddress, polsSize); - prover->setZkey(zkey.get()); + if (Zkey::FFLONK_PROTOCOL_ID == protocolId) { + prover = new Fflonk::FflonkProver(AltBn128::Engine::engine, pAddress, polsSize); + prover->setZkey(zkey.get()); + } StarkInfo _starkInfoRecursiveF(config, config.recursivefStarkInfo); pAddressStarksRecursiveF = (void *)malloc(_starkInfoRecursiveF.mapTotalN * sizeof(Goldilocks::Element)); @@ -142,8 +144,6 @@ Prover::~Prover() BinFileUtils::BinFile *pZkey = zkey.release(); ZKeyUtils::Header *pZkeyHeader = zkeyHeader.release(); - assert(groth16Prover.get() == nullptr); - assert(groth16Prover == nullptr); assert(zkey.get() == nullptr); assert(zkey == nullptr); assert(zkeyHeader.get() == nullptr); @@ -168,7 +168,8 @@ Prover::~Prover() } free(pAddressStarksRecursiveF); - delete prover; + if (prover != NULL) + delete prover; delete starkZkevm; delete starksC12a;