From 6b10393a22ee8628f5a0c71f19942cfd81fa45d1 Mon Sep 17 00:00:00 2001 From: fractasy Date: Wed, 17 Apr 2024 11:05:34 +0000 Subject: [PATCH] Implement FullTracer::fillInReadWriteAddresses in all forks. Change version to v6.0.2-RC1. --- src/config/version.hpp | 2 +- src/main_generator/main_generator.cpp | 8 ++-- src/main_sm/fork_1/main/eval_command.cpp | 5 ++- src/main_sm/fork_1/main/eval_command.hpp | 2 +- src/main_sm/fork_1/main/full_tracer.cpp | 54 ++++++++++++++++++++++- src/main_sm/fork_1/main/full_tracer.hpp | 4 +- src/main_sm/fork_1/main/main_executor.cpp | 14 +++--- src/main_sm/fork_2/main/eval_command.cpp | 5 ++- src/main_sm/fork_2/main/eval_command.hpp | 2 +- src/main_sm/fork_2/main/full_tracer.cpp | 54 ++++++++++++++++++++++- src/main_sm/fork_2/main/full_tracer.hpp | 4 +- src/main_sm/fork_2/main/main_executor.cpp | 14 +++--- src/main_sm/fork_3/main/eval_command.cpp | 5 ++- src/main_sm/fork_3/main/eval_command.hpp | 2 +- src/main_sm/fork_3/main/full_tracer.cpp | 54 ++++++++++++++++++++++- src/main_sm/fork_3/main/full_tracer.hpp | 4 +- src/main_sm/fork_3/main/main_executor.cpp | 14 +++--- src/main_sm/fork_4/main/eval_command.cpp | 5 ++- src/main_sm/fork_4/main/eval_command.hpp | 2 +- src/main_sm/fork_4/main/full_tracer.cpp | 54 ++++++++++++++++++++++- src/main_sm/fork_4/main/full_tracer.hpp | 4 +- src/main_sm/fork_4/main/main_executor.cpp | 24 +++++----- src/main_sm/fork_5/main/eval_command.cpp | 5 ++- src/main_sm/fork_5/main/eval_command.hpp | 2 +- src/main_sm/fork_5/main/full_tracer.cpp | 54 ++++++++++++++++++++++- src/main_sm/fork_5/main/full_tracer.hpp | 4 +- src/main_sm/fork_5/main/main_executor.cpp | 24 +++++----- src/main_sm/fork_6/main/eval_command.cpp | 5 ++- src/main_sm/fork_6/main/eval_command.hpp | 2 +- src/main_sm/fork_6/main/full_tracer.cpp | 54 ++++++++++++++++++++++- src/main_sm/fork_6/main/full_tracer.hpp | 4 +- src/main_sm/fork_6/main/main_executor.cpp | 24 +++++----- src/main_sm/fork_7/main/eval_command.cpp | 5 ++- src/main_sm/fork_7/main/eval_command.hpp | 2 +- src/main_sm/fork_7/main/full_tracer.cpp | 54 ++++++++++++++++++++++- src/main_sm/fork_7/main/full_tracer.hpp | 4 +- src/main_sm/fork_7/main/main_executor.cpp | 24 +++++----- src/main_sm/fork_8/main/eval_command.cpp | 5 ++- src/main_sm/fork_8/main/eval_command.hpp | 2 +- src/main_sm/fork_8/main/full_tracer.cpp | 54 ++++++++++++++++++++++- src/main_sm/fork_8/main/full_tracer.hpp | 4 +- src/main_sm/fork_8/main/main_executor.cpp | 24 +++++----- src/main_sm/fork_9/main/eval_command.cpp | 5 ++- src/main_sm/fork_9/main/eval_command.hpp | 2 +- src/main_sm/fork_9/main/full_tracer.cpp | 54 ++++++++++++++++++++++- src/main_sm/fork_9/main/full_tracer.hpp | 4 +- src/main_sm/fork_9/main/main_executor.cpp | 24 +++++----- src/prover/full_tracer_interface.hpp | 17 +++++++ 48 files changed, 655 insertions(+), 143 deletions(-) diff --git a/src/config/version.hpp b/src/config/version.hpp index fc2bb6054..fc0972dbb 100644 --- a/src/config/version.hpp +++ b/src/config/version.hpp @@ -1,6 +1,6 @@ #ifndef ZKEVM_PROVER_VERSION_HPP #define ZKEVM_PROVER_VERSION_HPP -#define ZKEVM_PROVER_VERSION "v6.0.1" +#define ZKEVM_PROVER_VERSION "v6.0.2-RC1" #endif diff --git a/src/main_generator/main_generator.cpp b/src/main_generator/main_generator.cpp index 235cff973..2986fe025 100644 --- a/src/main_generator/main_generator.cpp +++ b/src/main_generator/main_generator.cpp @@ -1403,7 +1403,7 @@ code += " #endif\n"; if (bFastMode) { - code += " zkResult = eval_addReadWriteAddress(ctx, smtGetResult.value);\n"; + code += " zkResult = eval_addReadWriteAddress(ctx, smtGetResult.value, key);\n"; code += " if (zkResult != ZKR_SUCCESS)\n"; code += " {\n"; code += " proverRequest.result = zkResult;\n"; @@ -1646,7 +1646,7 @@ code += " #endif\n"; if (bFastMode) { - code += " zkResult = eval_addReadWriteAddress(ctx, value);\n"; + code += " zkResult = eval_addReadWriteAddress(ctx, value, ctx.lastSWrite.key);\n"; code += " if (zkResult != ZKR_SUCCESS)\n"; code += " {\n"; code += " proverRequest.result = zkResult;\n"; @@ -2827,7 +2827,7 @@ code += " #endif\n"; if (bFastMode) { - code += " zkResult = eval_addReadWriteAddress(ctx, value);\n"; + code += " zkResult = eval_addReadWriteAddress(ctx, value, key);\n"; code += " if (zkResult != ZKR_SUCCESS)\n"; code += " {\n"; code += " proverRequest.result = zkResult;\n"; @@ -3015,7 +3015,7 @@ code += " #endif\n"; if (bFastMode) { - code += " zkResult = eval_addReadWriteAddress(ctx, scalarD);\n"; + code += " zkResult = eval_addReadWriteAddress(ctx, scalarD, ctx.lastSWrite.key);\n"; code += " if (zkResult != ZKR_SUCCESS)\n"; code += " {\n"; code += " proverRequest.result = zkResult;\n"; diff --git a/src/main_sm/fork_1/main/eval_command.cpp b/src/main_sm/fork_1/main/eval_command.cpp index 15ca18a96..e10c509dc 100644 --- a/src/main_sm/fork_1/main/eval_command.cpp +++ b/src/main_sm/fork_1/main/eval_command.cpp @@ -2063,13 +2063,14 @@ void eval_AddPointEc (Context &ctx, const RomCommand &cmd, bool dbl, RawFec::Ele ctx.fec.sub(y3, aux1, y1); } -void eval_addReadWriteAddress (Context &ctx, const mpz_class value) +void eval_addReadWriteAddress (Context &ctx, const mpz_class value, const Goldilocks::Element (&key)[4]) { zkassert(ctx.proverRequest.input.publicInputsExtended.publicInputs.forkID == 1); ((fork_1::FullTracer *)ctx.proverRequest.pFullTracer)->addReadWriteAddress( ctx.pols.A0[0], ctx.pols.A1[0], ctx.pols.A2[0], ctx.pols.A3[0], ctx.pols.A4[0], ctx.pols.A5[0], ctx.pols.A6[0], ctx.pols.A7[0], ctx.pols.B0[0], ctx.pols.B1[0], ctx.pols.B2[0], ctx.pols.B3[0], ctx.pols.B4[0], ctx.pols.B5[0], ctx.pols.B6[0], ctx.pols.B7[0], - value); + value, + key); } } // namespace \ No newline at end of file diff --git a/src/main_sm/fork_1/main/eval_command.hpp b/src/main_sm/fork_1/main/eval_command.hpp index 4bd9dc947..66c72efa3 100644 --- a/src/main_sm/fork_1/main/eval_command.hpp +++ b/src/main_sm/fork_1/main/eval_command.hpp @@ -120,7 +120,7 @@ void eval_storeLog (Context &ctx, const RomCommand &cmd, CommandResul void eval_memAlignWR_W0 (Context &ctx, const RomCommand &cmd, CommandResult &cr); void eval_memAlignWR_W1 (Context &ctx, const RomCommand &cmd, CommandResult &cr); void eval_memAlignWR8_W0 (Context &ctx, const RomCommand &cmd, CommandResult &cr); -void eval_addReadWriteAddress (Context &ctx, const mpz_class value); +void eval_addReadWriteAddress (Context &ctx, const mpz_class value, const Goldilocks::Element (&key)[4]); } // namespace diff --git a/src/main_sm/fork_1/main/full_tracer.cpp b/src/main_sm/fork_1/main/full_tracer.cpp index cdc56dbd4..e84994fbb 100644 --- a/src/main_sm/fork_1/main/full_tracer.cpp +++ b/src/main_sm/fork_1/main/full_tracer.cpp @@ -1326,7 +1326,8 @@ void FullTracer::onOpcode(Context &ctx, const RomCommand &cmd) void FullTracer::addReadWriteAddress ( const Goldilocks::Element &address0, const Goldilocks::Element &address1, const Goldilocks::Element &address2, const Goldilocks::Element &address3, const Goldilocks::Element &address4, const Goldilocks::Element &address5, const Goldilocks::Element &address6, const Goldilocks::Element &address7, const Goldilocks::Element &keyType0, const Goldilocks::Element &keyType1, const Goldilocks::Element &keyType2, const Goldilocks::Element &keyType3, const Goldilocks::Element &keyType4, const Goldilocks::Element &keyType5, const Goldilocks::Element &keyType6, const Goldilocks::Element &keyType7, - const mpz_class &value ) + const mpz_class &value, + const Goldilocks::Element (&key)[4] ) { #ifdef LOG_TIME_STATISTICS gettimeofday(&t, NULL); @@ -1349,6 +1350,10 @@ void FullTracer::addReadWriteAddress ( const Goldilocks::Element &address0, cons { InfoReadWrite infoReadWrite; infoReadWrite.balance = value.get_str(); + infoReadWrite.balanceKey[0]= key[0]; + infoReadWrite.balanceKey[1]= key[1]; + infoReadWrite.balanceKey[2]= key[2]; + infoReadWrite.balanceKey[3]= key[3]; read_write_addresses[addressHex] = infoReadWrite; } else @@ -1363,6 +1368,10 @@ void FullTracer::addReadWriteAddress ( const Goldilocks::Element &address0, cons { InfoReadWrite infoReadWrite; infoReadWrite.nonce = value.get_str(); + infoReadWrite.nonceKey[0]= key[0]; + infoReadWrite.nonceKey[1]= key[1]; + infoReadWrite.nonceKey[2]= key[2]; + infoReadWrite.nonceKey[3]= key[3]; read_write_addresses[addressHex] = infoReadWrite; } else @@ -1376,4 +1385,47 @@ void FullTracer::addReadWriteAddress ( const Goldilocks::Element &address0, cons #endif } +zkresult FullTracer::fillInReadWriteAddresses (Context &ctx) +{ + zkresult zkr; + + // For all entries in read_write_addresses + unordered_map::iterator it; + for (it = read_write_addresses.begin(); it != read_write_addresses.end(); it++) + { + Goldilocks::Element newStateRoot[4]; + string2fea(fr, finalTrace.new_state_root, newStateRoot); + + // Re-read balance for this state root + if (!it->second.balance.empty()) + { + zkassert(!fr.isZero(it->second.balanceKey[0]) || !fr.isZero(it->second.balanceKey[1]) || !fr.isZero(it->second.balanceKey[2]) || !fr.isZero(it->second.balanceKey[3])); + mpz_class balance; + zkr = ctx.pHashDB->get(ctx.proverRequest.uuid, newStateRoot, it->second.balanceKey, balance, NULL, NULL); + if (zkr != ZKR_SUCCESS) + { + zklog.error("FullTracer::fillInReadWriteAddresses() failed calling ctx.pHashDB->get(balance) result=" + zkresult2string(zkr)); + return zkr; + } + it->second.balance = balance.get_str(); + } + + // Re-read nonce for this state root + if (!it->second.nonce.empty()) + { + zkassert(!fr.isZero(it->second.nonceKey[0]) || !fr.isZero(it->second.nonceKey[1]) || !fr.isZero(it->second.nonceKey[2]) || !fr.isZero(it->second.nonceKey[3])); + mpz_class nonce; + zkr = ctx.pHashDB->get(ctx.proverRequest.uuid, newStateRoot, it->second.nonceKey, nonce, NULL, NULL); + if (zkr != ZKR_SUCCESS) + { + zklog.error("FullTracer::fillInReadWriteAddresses() failed calling ctx.pHashDB->get(nonce) result=" + zkresult2string(zkr)); + return zkr; + } + it->second.nonce = nonce.get_str(); + } + } + + return ZKR_SUCCESS; +} + } // namespace \ No newline at end of file diff --git a/src/main_sm/fork_1/main/full_tracer.hpp b/src/main_sm/fork_1/main/full_tracer.hpp index 791049d6d..3e7b576fb 100644 --- a/src/main_sm/fork_1/main/full_tracer.hpp +++ b/src/main_sm/fork_1/main/full_tracer.hpp @@ -63,7 +63,9 @@ class FullTracer: public FullTracerInterface void onOpcode (Context &ctx, const RomCommand &cmd); void addReadWriteAddress ( const Goldilocks::Element &address0, const Goldilocks::Element &address1, const Goldilocks::Element &address2, const Goldilocks::Element &faddress3, const Goldilocks::Element &address4, const Goldilocks::Element &address5, const Goldilocks::Element &address6, const Goldilocks::Element &address7, const Goldilocks::Element &keyType0, const Goldilocks::Element &keyType1, const Goldilocks::Element &keyType2, const Goldilocks::Element &keyType3, const Goldilocks::Element &keyType4, const Goldilocks::Element &keyType5, const Goldilocks::Element &keyType6, const Goldilocks::Element &keyType7, - const mpz_class &value ); + const mpz_class &value, + const Goldilocks::Element (&key)[4] ); + zkresult fillInReadWriteAddresses (Context &ctx); FullTracer(Goldilocks &fr) : fr(fr), depth(1), prevCTX(0), initGas(0), txCount(0), txTime(0), accBatchGas(0), numberOfOpcodesInThisTx(0), lastErrorOpcode(0) { }; ~FullTracer() diff --git a/src/main_sm/fork_1/main/main_executor.cpp b/src/main_sm/fork_1/main/main_executor.cpp index 02bbef069..25e6c2886 100644 --- a/src/main_sm/fork_1/main/main_executor.cpp +++ b/src/main_sm/fork_1/main/main_executor.cpp @@ -1032,11 +1032,11 @@ void MainExecutor::execute (ProverRequest &proverRequest, MainCommitPols &pols, #ifdef LOG_TIME_STATISTICS_MAIN_EXECUTOR mainMetrics.add("SMT Get", TimeDiff(t)); #endif - } - if (bProcessBatch) - { - eval_addReadWriteAddress(ctx, smtGetResult.value); + if (bProcessBatch) + { + eval_addReadWriteAddress(ctx, smtGetResult.value, key); + } } scalar2fea(fr, smtGetResult.value, fi0, fi1, fi2, fi3, fi4, fi5, fi6, fi7); @@ -1258,7 +1258,7 @@ void MainExecutor::execute (ProverRequest &proverRequest, MainCommitPols &pols, } if (bProcessBatch) { - eval_addReadWriteAddress(ctx, value); + eval_addReadWriteAddress(ctx, value, ctx.lastSWrite.key); } // If we just modified a balance @@ -1965,7 +1965,7 @@ void MainExecutor::execute (ProverRequest &proverRequest, MainCommitPols &pols, if (bProcessBatch) { - eval_addReadWriteAddress(ctx, smtGetResult.value); + eval_addReadWriteAddress(ctx, smtGetResult.value, key); } #ifdef LOG_TIME_STATISTICS_MAIN_EXECUTOR @@ -2107,7 +2107,7 @@ void MainExecutor::execute (ProverRequest &proverRequest, MainCommitPols &pols, if (bProcessBatch) { - eval_addReadWriteAddress(ctx, scalarD); + eval_addReadWriteAddress(ctx, scalarD, ctx.lastSWrite.key); } // If we just modified a balance diff --git a/src/main_sm/fork_2/main/eval_command.cpp b/src/main_sm/fork_2/main/eval_command.cpp index daca28c2b..b69181db4 100644 --- a/src/main_sm/fork_2/main/eval_command.cpp +++ b/src/main_sm/fork_2/main/eval_command.cpp @@ -2063,13 +2063,14 @@ void eval_AddPointEc (Context &ctx, const RomCommand &cmd, bool dbl, RawFec::Ele ctx.fec.sub(y3, aux1, y1); } -void eval_addReadWriteAddress (Context &ctx, const mpz_class value) +void eval_addReadWriteAddress (Context &ctx, const mpz_class value, const Goldilocks::Element (&key)[4]) { zkassert(ctx.proverRequest.input.publicInputsExtended.publicInputs.forkID == 2); // fork_2 ((fork_2::FullTracer *)ctx.proverRequest.pFullTracer)->addReadWriteAddress( ctx.pols.A0[0], ctx.pols.A1[0], ctx.pols.A2[0], ctx.pols.A3[0], ctx.pols.A4[0], ctx.pols.A5[0], ctx.pols.A6[0], ctx.pols.A7[0], ctx.pols.B0[0], ctx.pols.B1[0], ctx.pols.B2[0], ctx.pols.B3[0], ctx.pols.B4[0], ctx.pols.B5[0], ctx.pols.B6[0], ctx.pols.B7[0], - value); + value, + key); } } // namespace \ No newline at end of file diff --git a/src/main_sm/fork_2/main/eval_command.hpp b/src/main_sm/fork_2/main/eval_command.hpp index 6af3a0e5b..56b511924 100644 --- a/src/main_sm/fork_2/main/eval_command.hpp +++ b/src/main_sm/fork_2/main/eval_command.hpp @@ -120,7 +120,7 @@ void eval_storeLog (Context &ctx, const RomCommand &cmd, CommandResul void eval_memAlignWR_W0 (Context &ctx, const RomCommand &cmd, CommandResult &cr); void eval_memAlignWR_W1 (Context &ctx, const RomCommand &cmd, CommandResult &cr); void eval_memAlignWR8_W0 (Context &ctx, const RomCommand &cmd, CommandResult &cr); -void eval_addReadWriteAddress (Context &ctx, const mpz_class value); +void eval_addReadWriteAddress (Context &ctx, const mpz_class value, const Goldilocks::Element (&key)[4]); } // namespace diff --git a/src/main_sm/fork_2/main/full_tracer.cpp b/src/main_sm/fork_2/main/full_tracer.cpp index 6ca4c9c1b..9757bf6e6 100644 --- a/src/main_sm/fork_2/main/full_tracer.cpp +++ b/src/main_sm/fork_2/main/full_tracer.cpp @@ -1330,7 +1330,8 @@ void FullTracer::onOpcode(Context &ctx, const RomCommand &cmd) void FullTracer::addReadWriteAddress ( const Goldilocks::Element &address0, const Goldilocks::Element &address1, const Goldilocks::Element &address2, const Goldilocks::Element &address3, const Goldilocks::Element &address4, const Goldilocks::Element &address5, const Goldilocks::Element &address6, const Goldilocks::Element &address7, const Goldilocks::Element &keyType0, const Goldilocks::Element &keyType1, const Goldilocks::Element &keyType2, const Goldilocks::Element &keyType3, const Goldilocks::Element &keyType4, const Goldilocks::Element &keyType5, const Goldilocks::Element &keyType6, const Goldilocks::Element &keyType7, - const mpz_class &value ) + const mpz_class &value, + const Goldilocks::Element (&key)[4] ) { #ifdef LOG_TIME_STATISTICS gettimeofday(&t, NULL); @@ -1353,6 +1354,10 @@ void FullTracer::addReadWriteAddress ( const Goldilocks::Element &address0, cons { InfoReadWrite infoReadWrite; infoReadWrite.balance = value.get_str(); + infoReadWrite.balanceKey[0]= key[0]; + infoReadWrite.balanceKey[1]= key[1]; + infoReadWrite.balanceKey[2]= key[2]; + infoReadWrite.balanceKey[3]= key[3]; read_write_addresses[addressHex] = infoReadWrite; } else @@ -1367,6 +1372,10 @@ void FullTracer::addReadWriteAddress ( const Goldilocks::Element &address0, cons { InfoReadWrite infoReadWrite; infoReadWrite.nonce = value.get_str(); + infoReadWrite.nonceKey[0]= key[0]; + infoReadWrite.nonceKey[1]= key[1]; + infoReadWrite.nonceKey[2]= key[2]; + infoReadWrite.nonceKey[3]= key[3]; read_write_addresses[addressHex] = infoReadWrite; } else @@ -1380,4 +1389,47 @@ void FullTracer::addReadWriteAddress ( const Goldilocks::Element &address0, cons #endif } +zkresult FullTracer::fillInReadWriteAddresses (Context &ctx) +{ + zkresult zkr; + + // For all entries in read_write_addresses + unordered_map::iterator it; + for (it = read_write_addresses.begin(); it != read_write_addresses.end(); it++) + { + Goldilocks::Element newStateRoot[4]; + string2fea(fr, finalTrace.new_state_root, newStateRoot); + + // Re-read balance for this state root + if (!it->second.balance.empty()) + { + zkassert(!fr.isZero(it->second.balanceKey[0]) || !fr.isZero(it->second.balanceKey[1]) || !fr.isZero(it->second.balanceKey[2]) || !fr.isZero(it->second.balanceKey[3])); + mpz_class balance; + zkr = ctx.pHashDB->get(ctx.proverRequest.uuid, newStateRoot, it->second.balanceKey, balance, NULL, NULL); + if (zkr != ZKR_SUCCESS) + { + zklog.error("FullTracer::fillInReadWriteAddresses() failed calling ctx.pHashDB->get(balance) result=" + zkresult2string(zkr)); + return zkr; + } + it->second.balance = balance.get_str(); + } + + // Re-read nonce for this state root + if (!it->second.nonce.empty()) + { + zkassert(!fr.isZero(it->second.nonceKey[0]) || !fr.isZero(it->second.nonceKey[1]) || !fr.isZero(it->second.nonceKey[2]) || !fr.isZero(it->second.nonceKey[3])); + mpz_class nonce; + zkr = ctx.pHashDB->get(ctx.proverRequest.uuid, newStateRoot, it->second.nonceKey, nonce, NULL, NULL); + if (zkr != ZKR_SUCCESS) + { + zklog.error("FullTracer::fillInReadWriteAddresses() failed calling ctx.pHashDB->get(nonce) result=" + zkresult2string(zkr)); + return zkr; + } + it->second.nonce = nonce.get_str(); + } + } + + return ZKR_SUCCESS; +} + } // namespace \ No newline at end of file diff --git a/src/main_sm/fork_2/main/full_tracer.hpp b/src/main_sm/fork_2/main/full_tracer.hpp index 7a0421dc8..99ce56bf1 100644 --- a/src/main_sm/fork_2/main/full_tracer.hpp +++ b/src/main_sm/fork_2/main/full_tracer.hpp @@ -63,7 +63,9 @@ class FullTracer: public FullTracerInterface void onOpcode (Context &ctx, const RomCommand &cmd); void addReadWriteAddress ( const Goldilocks::Element &address0, const Goldilocks::Element &address1, const Goldilocks::Element &address2, const Goldilocks::Element &faddress3, const Goldilocks::Element &address4, const Goldilocks::Element &address5, const Goldilocks::Element &address6, const Goldilocks::Element &address7, const Goldilocks::Element &keyType0, const Goldilocks::Element &keyType1, const Goldilocks::Element &keyType2, const Goldilocks::Element &keyType3, const Goldilocks::Element &keyType4, const Goldilocks::Element &keyType5, const Goldilocks::Element &keyType6, const Goldilocks::Element &keyType7, - const mpz_class &value ); + const mpz_class &value, + const Goldilocks::Element (&key)[4] ); + zkresult fillInReadWriteAddresses (Context &ctx); FullTracer(Goldilocks &fr) : fr(fr), depth(1), prevCTX(0), initGas(0), txCount(0), txTime(0), accBatchGas(0), numberOfOpcodesInThisTx(0), lastErrorOpcode(0) { }; ~FullTracer() diff --git a/src/main_sm/fork_2/main/main_executor.cpp b/src/main_sm/fork_2/main/main_executor.cpp index d5d5c42db..92db44bce 100644 --- a/src/main_sm/fork_2/main/main_executor.cpp +++ b/src/main_sm/fork_2/main/main_executor.cpp @@ -1023,11 +1023,11 @@ void MainExecutor::execute (ProverRequest &proverRequest, MainCommitPols &pols, #ifdef LOG_TIME_STATISTICS_MAIN_EXECUTOR mainMetrics.add("SMT Get", TimeDiff(t)); #endif - } - if (bProcessBatch) - { - eval_addReadWriteAddress(ctx, smtGetResult.value); + if (bProcessBatch) + { + eval_addReadWriteAddress(ctx, smtGetResult.value, key); + } } #ifdef LOG_TIME_STATISTICS_MAIN_EXECUTOR @@ -1253,7 +1253,7 @@ void MainExecutor::execute (ProverRequest &proverRequest, MainCommitPols &pols, } if (bProcessBatch) { - eval_addReadWriteAddress(ctx, value); + eval_addReadWriteAddress(ctx, value, ctx.lastSWrite.key); } // If we just modified a balance @@ -1960,7 +1960,7 @@ void MainExecutor::execute (ProverRequest &proverRequest, MainCommitPols &pols, if (bProcessBatch) { - eval_addReadWriteAddress(ctx, smtGetResult.value); + eval_addReadWriteAddress(ctx, smtGetResult.value, key); } #ifdef LOG_TIME_STATISTICS_MAIN_EXECUTOR @@ -2102,7 +2102,7 @@ void MainExecutor::execute (ProverRequest &proverRequest, MainCommitPols &pols, if (bProcessBatch) { - eval_addReadWriteAddress(ctx, scalarD); + eval_addReadWriteAddress(ctx, scalarD, ctx.lastSWrite.key); } // If we just modified a balance diff --git a/src/main_sm/fork_3/main/eval_command.cpp b/src/main_sm/fork_3/main/eval_command.cpp index 41ef5d970..4f51698a1 100644 --- a/src/main_sm/fork_3/main/eval_command.cpp +++ b/src/main_sm/fork_3/main/eval_command.cpp @@ -2063,13 +2063,14 @@ void eval_AddPointEc (Context &ctx, const RomCommand &cmd, bool dbl, RawFec::Ele ctx.fec.sub(y3, aux1, y1); } -void eval_addReadWriteAddress (Context &ctx, const mpz_class value) +void eval_addReadWriteAddress (Context &ctx, const mpz_class value, const Goldilocks::Element (&key)[4]) { zkassert(ctx.proverRequest.input.publicInputsExtended.publicInputs.forkID == 3); // fork_3 ((fork_3::FullTracer *)ctx.proverRequest.pFullTracer)->addReadWriteAddress( ctx.pols.A0[0], ctx.pols.A1[0], ctx.pols.A2[0], ctx.pols.A3[0], ctx.pols.A4[0], ctx.pols.A5[0], ctx.pols.A6[0], ctx.pols.A7[0], ctx.pols.B0[0], ctx.pols.B1[0], ctx.pols.B2[0], ctx.pols.B3[0], ctx.pols.B4[0], ctx.pols.B5[0], ctx.pols.B6[0], ctx.pols.B7[0], - value); + value, + key); } } // namespace \ No newline at end of file diff --git a/src/main_sm/fork_3/main/eval_command.hpp b/src/main_sm/fork_3/main/eval_command.hpp index 6dcaf4a3a..9d6d74006 100644 --- a/src/main_sm/fork_3/main/eval_command.hpp +++ b/src/main_sm/fork_3/main/eval_command.hpp @@ -120,7 +120,7 @@ void eval_storeLog (Context &ctx, const RomCommand &cmd, CommandResul void eval_memAlignWR_W0 (Context &ctx, const RomCommand &cmd, CommandResult &cr); void eval_memAlignWR_W1 (Context &ctx, const RomCommand &cmd, CommandResult &cr); void eval_memAlignWR8_W0 (Context &ctx, const RomCommand &cmd, CommandResult &cr); -void eval_addReadWriteAddress (Context &ctx, const mpz_class value); +void eval_addReadWriteAddress (Context &ctx, const mpz_class value, const Goldilocks::Element (&key)[4]); } // namespace diff --git a/src/main_sm/fork_3/main/full_tracer.cpp b/src/main_sm/fork_3/main/full_tracer.cpp index 1a2d658ab..46b957e81 100644 --- a/src/main_sm/fork_3/main/full_tracer.cpp +++ b/src/main_sm/fork_3/main/full_tracer.cpp @@ -1330,7 +1330,8 @@ void FullTracer::onOpcode(Context &ctx, const RomCommand &cmd) void FullTracer::addReadWriteAddress ( const Goldilocks::Element &address0, const Goldilocks::Element &address1, const Goldilocks::Element &address2, const Goldilocks::Element &address3, const Goldilocks::Element &address4, const Goldilocks::Element &address5, const Goldilocks::Element &address6, const Goldilocks::Element &address7, const Goldilocks::Element &keyType0, const Goldilocks::Element &keyType1, const Goldilocks::Element &keyType2, const Goldilocks::Element &keyType3, const Goldilocks::Element &keyType4, const Goldilocks::Element &keyType5, const Goldilocks::Element &keyType6, const Goldilocks::Element &keyType7, - const mpz_class &value ) + const mpz_class &value, + const Goldilocks::Element (&key)[4] ) { #ifdef LOG_TIME_STATISTICS gettimeofday(&t, NULL); @@ -1353,6 +1354,10 @@ void FullTracer::addReadWriteAddress ( const Goldilocks::Element &address0, cons { InfoReadWrite infoReadWrite; infoReadWrite.balance = value.get_str(); + infoReadWrite.balanceKey[0]= key[0]; + infoReadWrite.balanceKey[1]= key[1]; + infoReadWrite.balanceKey[2]= key[2]; + infoReadWrite.balanceKey[3]= key[3]; read_write_addresses[addressHex] = infoReadWrite; } else @@ -1367,6 +1372,10 @@ void FullTracer::addReadWriteAddress ( const Goldilocks::Element &address0, cons { InfoReadWrite infoReadWrite; infoReadWrite.nonce = value.get_str(); + infoReadWrite.nonceKey[0]= key[0]; + infoReadWrite.nonceKey[1]= key[1]; + infoReadWrite.nonceKey[2]= key[2]; + infoReadWrite.nonceKey[3]= key[3]; read_write_addresses[addressHex] = infoReadWrite; } else @@ -1380,4 +1389,47 @@ void FullTracer::addReadWriteAddress ( const Goldilocks::Element &address0, cons #endif } +zkresult FullTracer::fillInReadWriteAddresses (Context &ctx) +{ + zkresult zkr; + + // For all entries in read_write_addresses + unordered_map::iterator it; + for (it = read_write_addresses.begin(); it != read_write_addresses.end(); it++) + { + Goldilocks::Element newStateRoot[4]; + string2fea(fr, finalTrace.new_state_root, newStateRoot); + + // Re-read balance for this state root + if (!it->second.balance.empty()) + { + zkassert(!fr.isZero(it->second.balanceKey[0]) || !fr.isZero(it->second.balanceKey[1]) || !fr.isZero(it->second.balanceKey[2]) || !fr.isZero(it->second.balanceKey[3])); + mpz_class balance; + zkr = ctx.pHashDB->get(ctx.proverRequest.uuid, newStateRoot, it->second.balanceKey, balance, NULL, NULL); + if (zkr != ZKR_SUCCESS) + { + zklog.error("FullTracer::fillInReadWriteAddresses() failed calling ctx.pHashDB->get(balance) result=" + zkresult2string(zkr)); + return zkr; + } + it->second.balance = balance.get_str(); + } + + // Re-read nonce for this state root + if (!it->second.nonce.empty()) + { + zkassert(!fr.isZero(it->second.nonceKey[0]) || !fr.isZero(it->second.nonceKey[1]) || !fr.isZero(it->second.nonceKey[2]) || !fr.isZero(it->second.nonceKey[3])); + mpz_class nonce; + zkr = ctx.pHashDB->get(ctx.proverRequest.uuid, newStateRoot, it->second.nonceKey, nonce, NULL, NULL); + if (zkr != ZKR_SUCCESS) + { + zklog.error("FullTracer::fillInReadWriteAddresses() failed calling ctx.pHashDB->get(nonce) result=" + zkresult2string(zkr)); + return zkr; + } + it->second.nonce = nonce.get_str(); + } + } + + return ZKR_SUCCESS; +} + } // namespace \ No newline at end of file diff --git a/src/main_sm/fork_3/main/full_tracer.hpp b/src/main_sm/fork_3/main/full_tracer.hpp index 14cfbd765..d1223ecb7 100644 --- a/src/main_sm/fork_3/main/full_tracer.hpp +++ b/src/main_sm/fork_3/main/full_tracer.hpp @@ -63,7 +63,9 @@ class FullTracer: public FullTracerInterface void onOpcode (Context &ctx, const RomCommand &cmd); void addReadWriteAddress ( const Goldilocks::Element &address0, const Goldilocks::Element &address1, const Goldilocks::Element &address2, const Goldilocks::Element &faddress3, const Goldilocks::Element &address4, const Goldilocks::Element &address5, const Goldilocks::Element &address6, const Goldilocks::Element &address7, const Goldilocks::Element &keyType0, const Goldilocks::Element &keyType1, const Goldilocks::Element &keyType2, const Goldilocks::Element &keyType3, const Goldilocks::Element &keyType4, const Goldilocks::Element &keyType5, const Goldilocks::Element &keyType6, const Goldilocks::Element &keyType7, - const mpz_class &value ); + const mpz_class &value, + const Goldilocks::Element (&key)[4] ); + zkresult fillInReadWriteAddresses (Context &ctx); FullTracer(Goldilocks &fr) : fr(fr), depth(1), prevCTX(0), initGas(0), txCount(0), txTime(0), accBatchGas(0), numberOfOpcodesInThisTx(0), lastErrorOpcode(0) { }; ~FullTracer() diff --git a/src/main_sm/fork_3/main/main_executor.cpp b/src/main_sm/fork_3/main/main_executor.cpp index 6e4f3ffed..58f2201e4 100644 --- a/src/main_sm/fork_3/main/main_executor.cpp +++ b/src/main_sm/fork_3/main/main_executor.cpp @@ -1023,11 +1023,11 @@ void MainExecutor::execute (ProverRequest &proverRequest, MainCommitPols &pols, #ifdef LOG_TIME_STATISTICS_MAIN_EXECUTOR mainMetrics.add("SMT Get", TimeDiff(t)); #endif - } - if (bProcessBatch) - { - eval_addReadWriteAddress(ctx, smtGetResult.value); + if (bProcessBatch) + { + eval_addReadWriteAddress(ctx, smtGetResult.value, key); + } } scalar2fea(fr, smtGetResult.value, fi0, fi1, fi2, fi3, fi4, fi5, fi6, fi7); @@ -1249,7 +1249,7 @@ void MainExecutor::execute (ProverRequest &proverRequest, MainCommitPols &pols, } if (bProcessBatch) { - eval_addReadWriteAddress(ctx, value); + eval_addReadWriteAddress(ctx, value, ctx.lastSWrite.key); } // If we just modified a balance @@ -1956,7 +1956,7 @@ void MainExecutor::execute (ProverRequest &proverRequest, MainCommitPols &pols, if (bProcessBatch) { - eval_addReadWriteAddress(ctx, smtGetResult.value); + eval_addReadWriteAddress(ctx, smtGetResult.value, key); } #ifdef LOG_TIME_STATISTICS_MAIN_EXECUTOR @@ -2098,7 +2098,7 @@ void MainExecutor::execute (ProverRequest &proverRequest, MainCommitPols &pols, if (bProcessBatch) { - eval_addReadWriteAddress(ctx, scalarD); + eval_addReadWriteAddress(ctx, scalarD, ctx.lastSWrite.key); } // If we just modified a balance diff --git a/src/main_sm/fork_4/main/eval_command.cpp b/src/main_sm/fork_4/main/eval_command.cpp index 7b1611fb5..f5261c807 100644 --- a/src/main_sm/fork_4/main/eval_command.cpp +++ b/src/main_sm/fork_4/main/eval_command.cpp @@ -2413,13 +2413,14 @@ zkresult AddPointEc (Context &ctx, bool dbl, const RawFec::Element &x1, const Ra return ZKR_SUCCESS; } -zkresult eval_addReadWriteAddress (Context &ctx, const mpz_class value) +zkresult eval_addReadWriteAddress (Context &ctx, const mpz_class value, const Goldilocks::Element (&key)[4]) { zkassert(ctx.proverRequest.input.publicInputsExtended.publicInputs.forkID == 4); // fork_4 return ((fork_4::FullTracer *)ctx.proverRequest.pFullTracer)->addReadWriteAddress( ctx.pols.A0[0], ctx.pols.A1[0], ctx.pols.A2[0], ctx.pols.A3[0], ctx.pols.A4[0], ctx.pols.A5[0], ctx.pols.A6[0], ctx.pols.A7[0], ctx.pols.B0[0], ctx.pols.B1[0], ctx.pols.B2[0], ctx.pols.B3[0], ctx.pols.B4[0], ctx.pols.B5[0], ctx.pols.B6[0], ctx.pols.B7[0], - value); + value, + key); } } // namespace \ No newline at end of file diff --git a/src/main_sm/fork_4/main/eval_command.hpp b/src/main_sm/fork_4/main/eval_command.hpp index 538e693c7..db32edffc 100644 --- a/src/main_sm/fork_4/main/eval_command.hpp +++ b/src/main_sm/fork_4/main/eval_command.hpp @@ -124,7 +124,7 @@ void eval_memAlignWR8_W0 (Context &ctx, const RomCommand &cmd, CommandResul zkresult AddPointEc (Context &ctx, bool dbl, const RawFec::Element &x1, const RawFec::Element &y1, const RawFec::Element &x2, const RawFec::Element &y2, RawFec::Element &x3, RawFec::Element &y3); -zkresult eval_addReadWriteAddress (Context &ctx, const mpz_class value); +zkresult eval_addReadWriteAddress (Context &ctx, const mpz_class value, const Goldilocks::Element (&key)[4]); mpz_class sqrtTonelliShanks ( const mpz_class &n, const mpz_class &p ); diff --git a/src/main_sm/fork_4/main/full_tracer.cpp b/src/main_sm/fork_4/main/full_tracer.cpp index d51a94f4a..10da9acf9 100644 --- a/src/main_sm/fork_4/main/full_tracer.cpp +++ b/src/main_sm/fork_4/main/full_tracer.cpp @@ -1648,7 +1648,8 @@ zkresult FullTracer::onOpcode(Context &ctx, const RomCommand &cmd) zkresult FullTracer::addReadWriteAddress ( const Goldilocks::Element &address0, const Goldilocks::Element &address1, const Goldilocks::Element &address2, const Goldilocks::Element &address3, const Goldilocks::Element &address4, const Goldilocks::Element &address5, const Goldilocks::Element &address6, const Goldilocks::Element &address7, const Goldilocks::Element &keyType0, const Goldilocks::Element &keyType1, const Goldilocks::Element &keyType2, const Goldilocks::Element &keyType3, const Goldilocks::Element &keyType4, const Goldilocks::Element &keyType5, const Goldilocks::Element &keyType6, const Goldilocks::Element &keyType7, - const mpz_class &value ) + const mpz_class &value, + const Goldilocks::Element (&key)[4] ) { #ifdef LOG_TIME_STATISTICS gettimeofday(&t, NULL); @@ -1679,6 +1680,10 @@ zkresult FullTracer::addReadWriteAddress ( const Goldilocks::Element &address0, { InfoReadWrite infoReadWrite; infoReadWrite.balance = value.get_str(); + infoReadWrite.balanceKey[0]= key[0]; + infoReadWrite.balanceKey[1]= key[1]; + infoReadWrite.balanceKey[2]= key[2]; + infoReadWrite.balanceKey[3]= key[3]; read_write_addresses[addressHex] = infoReadWrite; } else @@ -1693,6 +1698,10 @@ zkresult FullTracer::addReadWriteAddress ( const Goldilocks::Element &address0, { InfoReadWrite infoReadWrite; infoReadWrite.nonce = value.get_str(); + infoReadWrite.nonceKey[0]= key[0]; + infoReadWrite.nonceKey[1]= key[1]; + infoReadWrite.nonceKey[2]= key[2]; + infoReadWrite.nonceKey[3]= key[3]; read_write_addresses[addressHex] = infoReadWrite; } else @@ -1708,4 +1717,47 @@ zkresult FullTracer::addReadWriteAddress ( const Goldilocks::Element &address0, return ZKR_SUCCESS; } +zkresult FullTracer::fillInReadWriteAddresses (Context &ctx) +{ + zkresult zkr; + + // For all entries in read_write_addresses + unordered_map::iterator it; + for (it = read_write_addresses.begin(); it != read_write_addresses.end(); it++) + { + Goldilocks::Element newStateRoot[4]; + string2fea(fr, finalTrace.new_state_root, newStateRoot); + + // Re-read balance for this state root + if (!it->second.balance.empty()) + { + zkassert(!fr.isZero(it->second.balanceKey[0]) || !fr.isZero(it->second.balanceKey[1]) || !fr.isZero(it->second.balanceKey[2])|| !fr.isZero(it->second.balanceKey[3])); + mpz_class balance; + zkr = ctx.pHashDB->get(ctx.proverRequest.uuid, newStateRoot, it->second.balanceKey, balance, NULL, NULL); + if (zkr != ZKR_SUCCESS) + { + zklog.error("FullTracer::fillInReadWriteAddresses() failed calling ctx.pHashDB->get(balance) result=" + zkresult2string(zkr)); + return zkr; + } + it->second.balance = balance.get_str(); + } + + // Re-read nonce for this state root + if (!it->second.nonce.empty()) + { + zkassert(!fr.isZero(it->second.nonceKey[0]) || !fr.isZero(it->second.nonceKey[1]) || !fr.isZero(it->second.nonceKey[2]) || !fr.isZero(it->second.nonceKey[3])); + mpz_class nonce; + zkr = ctx.pHashDB->get(ctx.proverRequest.uuid, newStateRoot, it->second.nonceKey, nonce, NULL, NULL); + if (zkr != ZKR_SUCCESS) + { + zklog.error("FullTracer::fillInReadWriteAddresses() failed calling ctx.pHashDB->get(nonce) result=" + zkresult2string(zkr)); + return zkr; + } + it->second.nonce = nonce.get_str(); + } + } + + return ZKR_SUCCESS; +} + } // namespace \ No newline at end of file diff --git a/src/main_sm/fork_4/main/full_tracer.hpp b/src/main_sm/fork_4/main/full_tracer.hpp index 5ee64e9f5..d0cabdbc9 100644 --- a/src/main_sm/fork_4/main/full_tracer.hpp +++ b/src/main_sm/fork_4/main/full_tracer.hpp @@ -63,7 +63,9 @@ class FullTracer: public FullTracerInterface zkresult onOpcode (Context &ctx, const RomCommand &cmd); zkresult addReadWriteAddress ( const Goldilocks::Element &address0, const Goldilocks::Element &address1, const Goldilocks::Element &address2, const Goldilocks::Element &faddress3, const Goldilocks::Element &address4, const Goldilocks::Element &address5, const Goldilocks::Element &address6, const Goldilocks::Element &address7, const Goldilocks::Element &keyType0, const Goldilocks::Element &keyType1, const Goldilocks::Element &keyType2, const Goldilocks::Element &keyType3, const Goldilocks::Element &keyType4, const Goldilocks::Element &keyType5, const Goldilocks::Element &keyType6, const Goldilocks::Element &keyType7, - const mpz_class &value ); + const mpz_class &value, + const Goldilocks::Element (&key)[4] ); + zkresult fillInReadWriteAddresses (Context &ctx); FullTracer(Goldilocks &fr) : fr(fr), depth(1), prevCTX(0), initGas(0), txCount(0), txTime(0), accBatchGas(0), numberOfOpcodesInThisTx(0), lastErrorOpcode(0) { }; ~FullTracer() diff --git a/src/main_sm/fork_4/main/main_executor.cpp b/src/main_sm/fork_4/main/main_executor.cpp index 9d4c7097d..a0efcbae7 100644 --- a/src/main_sm/fork_4/main/main_executor.cpp +++ b/src/main_sm/fork_4/main/main_executor.cpp @@ -1057,17 +1057,17 @@ void MainExecutor::execute (ProverRequest &proverRequest, MainCommitPols &pols, #ifdef LOG_TIME_STATISTICS_MAIN_EXECUTOR mainMetrics.add("SMT Get", TimeDiff(t)); #endif - } - if (bProcessBatch) - { - zkResult = eval_addReadWriteAddress(ctx, smtGetResult.value); - if (zkResult != ZKR_SUCCESS) + if (bProcessBatch) { - proverRequest.result = zkResult; - logError(ctx, string("Failed calling eval_addReadWriteAddress() 1 result=") + zkresult2string(zkResult)); - pHashDB->cancelBatch(proverRequest.uuid); - return; + zkResult = eval_addReadWriteAddress(ctx, smtGetResult.value, key); + if (zkResult != ZKR_SUCCESS) + { + proverRequest.result = zkResult; + logError(ctx, string("Failed calling eval_addReadWriteAddress() 1 result=") + zkresult2string(zkResult)); + pHashDB->cancelBatch(proverRequest.uuid); + return; + } } } @@ -1290,7 +1290,7 @@ void MainExecutor::execute (ProverRequest &proverRequest, MainCommitPols &pols, } if (bProcessBatch) { - zkResult = eval_addReadWriteAddress(ctx, value); + zkResult = eval_addReadWriteAddress(ctx, value, ctx.lastSWrite.key); if (zkResult != ZKR_SUCCESS) { proverRequest.result = zkResult; @@ -2116,7 +2116,7 @@ void MainExecutor::execute (ProverRequest &proverRequest, MainCommitPols &pols, if (bProcessBatch) { - zkResult = eval_addReadWriteAddress(ctx, smtGetResult.value); + zkResult = eval_addReadWriteAddress(ctx, smtGetResult.value, key); if (zkResult != ZKR_SUCCESS) { proverRequest.result = zkResult; @@ -2276,7 +2276,7 @@ void MainExecutor::execute (ProverRequest &proverRequest, MainCommitPols &pols, if (bProcessBatch) { - zkResult = eval_addReadWriteAddress(ctx, scalarD); + zkResult = eval_addReadWriteAddress(ctx, scalarD, ctx.lastSWrite.key); if (zkResult != ZKR_SUCCESS) { proverRequest.result = zkResult; diff --git a/src/main_sm/fork_5/main/eval_command.cpp b/src/main_sm/fork_5/main/eval_command.cpp index ea3786e62..7cb78852a 100644 --- a/src/main_sm/fork_5/main/eval_command.cpp +++ b/src/main_sm/fork_5/main/eval_command.cpp @@ -2413,13 +2413,14 @@ zkresult AddPointEc (Context &ctx, bool dbl, const RawFec::Element &x1, const Ra return ZKR_SUCCESS; } -zkresult eval_addReadWriteAddress (Context &ctx, const mpz_class value) +zkresult eval_addReadWriteAddress (Context &ctx, const mpz_class value, const Goldilocks::Element (&key)[4]) { zkassert(ctx.proverRequest.input.publicInputsExtended.publicInputs.forkID == 5); // fork_5 return ((fork_5::FullTracer *)ctx.proverRequest.pFullTracer)->addReadWriteAddress( ctx.pols.A0[0], ctx.pols.A1[0], ctx.pols.A2[0], ctx.pols.A3[0], ctx.pols.A4[0], ctx.pols.A5[0], ctx.pols.A6[0], ctx.pols.A7[0], ctx.pols.B0[0], ctx.pols.B1[0], ctx.pols.B2[0], ctx.pols.B3[0], ctx.pols.B4[0], ctx.pols.B5[0], ctx.pols.B6[0], ctx.pols.B7[0], - value); + value, + key); } } // namespace \ No newline at end of file diff --git a/src/main_sm/fork_5/main/eval_command.hpp b/src/main_sm/fork_5/main/eval_command.hpp index 8dd542925..c7f7fcdb8 100644 --- a/src/main_sm/fork_5/main/eval_command.hpp +++ b/src/main_sm/fork_5/main/eval_command.hpp @@ -124,7 +124,7 @@ void eval_memAlignWR8_W0 (Context &ctx, const RomCommand &cmd, CommandResul zkresult AddPointEc (Context &ctx, bool dbl, const RawFec::Element &x1, const RawFec::Element &y1, const RawFec::Element &x2, const RawFec::Element &y2, RawFec::Element &x3, RawFec::Element &y3); -zkresult eval_addReadWriteAddress (Context &ctx, const mpz_class value); +zkresult eval_addReadWriteAddress (Context &ctx, const mpz_class value, const Goldilocks::Element (&key)[4]); mpz_class sqrtTonelliShanks ( const mpz_class &n, const mpz_class &p ); diff --git a/src/main_sm/fork_5/main/full_tracer.cpp b/src/main_sm/fork_5/main/full_tracer.cpp index 7cdac656c..45d5fc265 100644 --- a/src/main_sm/fork_5/main/full_tracer.cpp +++ b/src/main_sm/fork_5/main/full_tracer.cpp @@ -1711,7 +1711,8 @@ zkresult FullTracer::onOpcode(Context &ctx, const RomCommand &cmd) zkresult FullTracer::addReadWriteAddress ( const Goldilocks::Element &address0, const Goldilocks::Element &address1, const Goldilocks::Element &address2, const Goldilocks::Element &address3, const Goldilocks::Element &address4, const Goldilocks::Element &address5, const Goldilocks::Element &address6, const Goldilocks::Element &address7, const Goldilocks::Element &keyType0, const Goldilocks::Element &keyType1, const Goldilocks::Element &keyType2, const Goldilocks::Element &keyType3, const Goldilocks::Element &keyType4, const Goldilocks::Element &keyType5, const Goldilocks::Element &keyType6, const Goldilocks::Element &keyType7, - const mpz_class &value ) + const mpz_class &value, + const Goldilocks::Element (&key)[4] ) { #ifdef LOG_TIME_STATISTICS gettimeofday(&t, NULL); @@ -1742,6 +1743,10 @@ zkresult FullTracer::addReadWriteAddress ( const Goldilocks::Element &address0, { InfoReadWrite infoReadWrite; infoReadWrite.balance = value.get_str(); + infoReadWrite.balanceKey[0]= key[0]; + infoReadWrite.balanceKey[1]= key[1]; + infoReadWrite.balanceKey[2]= key[2]; + infoReadWrite.balanceKey[3]= key[3]; read_write_addresses[addressHex] = infoReadWrite; } else @@ -1756,6 +1761,10 @@ zkresult FullTracer::addReadWriteAddress ( const Goldilocks::Element &address0, { InfoReadWrite infoReadWrite; infoReadWrite.nonce = value.get_str(); + infoReadWrite.nonceKey[0]= key[0]; + infoReadWrite.nonceKey[1]= key[1]; + infoReadWrite.nonceKey[2]= key[2]; + infoReadWrite.nonceKey[3]= key[3]; read_write_addresses[addressHex] = infoReadWrite; } else @@ -1771,4 +1780,47 @@ zkresult FullTracer::addReadWriteAddress ( const Goldilocks::Element &address0, return ZKR_SUCCESS; } +zkresult FullTracer::fillInReadWriteAddresses (Context &ctx) +{ + zkresult zkr; + + // For all entries in read_write_addresses + unordered_map::iterator it; + for (it = read_write_addresses.begin(); it != read_write_addresses.end(); it++) + { + Goldilocks::Element newStateRoot[4]; + string2fea(fr, finalTrace.new_state_root, newStateRoot); + + // Re-read balance for this state root + if (!it->second.balance.empty()) + { + zkassert(!fr.isZero(it->second.balanceKey[0]) || !fr.isZero(it->second.balanceKey[1]) || !fr.isZero(it->second.balanceKey[2]) || !fr.isZero(it->second.balanceKey[3])); + mpz_class balance; + zkr = ctx.pHashDB->get(ctx.proverRequest.uuid, newStateRoot, it->second.balanceKey, balance, NULL, NULL); + if (zkr != ZKR_SUCCESS) + { + zklog.error("FullTracer::fillInReadWriteAddresses() failed calling ctx.pHashDB->get(balance) result=" + zkresult2string(zkr)); + return zkr; + } + it->second.balance = balance.get_str(); + } + + // Re-read nonce for this state root + if (!it->second.nonce.empty()) + { + zkassert(!fr.isZero(it->second.nonceKey[0]) || !fr.isZero(it->second.nonceKey[1]) || !fr.isZero(it->second.nonceKey[2]) || !fr.isZero(it->second.nonceKey[3])); + mpz_class nonce; + zkr = ctx.pHashDB->get(ctx.proverRequest.uuid, newStateRoot, it->second.nonceKey, nonce, NULL, NULL); + if (zkr != ZKR_SUCCESS) + { + zklog.error("FullTracer::fillInReadWriteAddresses() failed calling ctx.pHashDB->get(nonce) result=" + zkresult2string(zkr)); + return zkr; + } + it->second.nonce = nonce.get_str(); + } + } + + return ZKR_SUCCESS; +} + } // namespace \ No newline at end of file diff --git a/src/main_sm/fork_5/main/full_tracer.hpp b/src/main_sm/fork_5/main/full_tracer.hpp index f72404d23..012178481 100644 --- a/src/main_sm/fork_5/main/full_tracer.hpp +++ b/src/main_sm/fork_5/main/full_tracer.hpp @@ -66,7 +66,9 @@ class FullTracer: public FullTracerInterface zkresult onOpcode (Context &ctx, const RomCommand &cmd); zkresult addReadWriteAddress ( const Goldilocks::Element &address0, const Goldilocks::Element &address1, const Goldilocks::Element &address2, const Goldilocks::Element &faddress3, const Goldilocks::Element &address4, const Goldilocks::Element &address5, const Goldilocks::Element &address6, const Goldilocks::Element &address7, const Goldilocks::Element &keyType0, const Goldilocks::Element &keyType1, const Goldilocks::Element &keyType2, const Goldilocks::Element &keyType3, const Goldilocks::Element &keyType4, const Goldilocks::Element &keyType5, const Goldilocks::Element &keyType6, const Goldilocks::Element &keyType7, - const mpz_class &value ); + const mpz_class &value, + const Goldilocks::Element (&key)[4] ); + zkresult fillInReadWriteAddresses (Context &ctx); FullTracer(Goldilocks &fr) : fr(fr), depth(1), prevCTX(0), initGas(0), txCount(0), txTime(0), accBatchGas(0), numberOfOpcodesInThisTx(0), lastErrorOpcode(0), hasGaspriceOpcode(false), hasBalanceOpcode(false) { }; ~FullTracer() diff --git a/src/main_sm/fork_5/main/main_executor.cpp b/src/main_sm/fork_5/main/main_executor.cpp index b227679ba..fc64e998d 100644 --- a/src/main_sm/fork_5/main/main_executor.cpp +++ b/src/main_sm/fork_5/main/main_executor.cpp @@ -1050,17 +1050,17 @@ void MainExecutor::execute (ProverRequest &proverRequest, MainCommitPols &pols, #ifdef LOG_TIME_STATISTICS_MAIN_EXECUTOR mainMetrics.add("SMT Get", TimeDiff(t)); #endif - } - if (bProcessBatch) - { - zkResult = eval_addReadWriteAddress(ctx, smtGetResult.value); - if (zkResult != ZKR_SUCCESS) + if (bProcessBatch) { - proverRequest.result = zkResult; - logError(ctx, string("Failed calling eval_addReadWriteAddress() 1 result=") + zkresult2string(zkResult)); - pHashDB->cancelBatch(proverRequest.uuid); - return; + zkResult = eval_addReadWriteAddress(ctx, smtGetResult.value, key); + if (zkResult != ZKR_SUCCESS) + { + proverRequest.result = zkResult; + logError(ctx, string("Failed calling eval_addReadWriteAddress() 1 result=") + zkresult2string(zkResult)); + pHashDB->cancelBatch(proverRequest.uuid); + return; + } } } @@ -1289,7 +1289,7 @@ void MainExecutor::execute (ProverRequest &proverRequest, MainCommitPols &pols, if (bProcessBatch) { - zkResult = eval_addReadWriteAddress(ctx, value); + zkResult = eval_addReadWriteAddress(ctx, value, ctx.lastSWrite.key); if (zkResult != ZKR_SUCCESS) { proverRequest.result = zkResult; @@ -2125,7 +2125,7 @@ void MainExecutor::execute (ProverRequest &proverRequest, MainCommitPols &pols, if (bProcessBatch) { - zkResult = eval_addReadWriteAddress(ctx, smtGetResult.value); + zkResult = eval_addReadWriteAddress(ctx, smtGetResult.value, key); if (zkResult != ZKR_SUCCESS) { proverRequest.result = zkResult; @@ -2291,7 +2291,7 @@ void MainExecutor::execute (ProverRequest &proverRequest, MainCommitPols &pols, if (bProcessBatch) { - zkResult = eval_addReadWriteAddress(ctx, scalarD); + zkResult = eval_addReadWriteAddress(ctx, scalarD, ctx.lastSWrite.key); if (zkResult != ZKR_SUCCESS) { proverRequest.result = zkResult; diff --git a/src/main_sm/fork_6/main/eval_command.cpp b/src/main_sm/fork_6/main/eval_command.cpp index 7c459cdb8..dbb35bfbc 100644 --- a/src/main_sm/fork_6/main/eval_command.cpp +++ b/src/main_sm/fork_6/main/eval_command.cpp @@ -2478,13 +2478,14 @@ zkresult AddPointEc (Context &ctx, bool dbl, const RawFec::Element &x1, const Ra return ZKR_SUCCESS; } -zkresult eval_addReadWriteAddress (Context &ctx, const mpz_class value) +zkresult eval_addReadWriteAddress (Context &ctx, const mpz_class value, const Goldilocks::Element (&key)[4]) { zkassert(ctx.proverRequest.input.publicInputsExtended.publicInputs.forkID == 6); // fork_6 return ((fork_6::FullTracer *)ctx.proverRequest.pFullTracer)->addReadWriteAddress( ctx.pols.A0[0], ctx.pols.A1[0], ctx.pols.A2[0], ctx.pols.A3[0], ctx.pols.A4[0], ctx.pols.A5[0], ctx.pols.A6[0], ctx.pols.A7[0], ctx.pols.B0[0], ctx.pols.B1[0], ctx.pols.B2[0], ctx.pols.B3[0], ctx.pols.B4[0], ctx.pols.B5[0], ctx.pols.B6[0], ctx.pols.B7[0], - value); + value, + key); } } // namespace \ No newline at end of file diff --git a/src/main_sm/fork_6/main/eval_command.hpp b/src/main_sm/fork_6/main/eval_command.hpp index 8c349fe3f..1ad3644c4 100644 --- a/src/main_sm/fork_6/main/eval_command.hpp +++ b/src/main_sm/fork_6/main/eval_command.hpp @@ -125,7 +125,7 @@ void eval_memAlignWR8_W0 (Context &ctx, const RomCommand &cmd, CommandResul zkresult AddPointEc (Context &ctx, bool dbl, const RawFec::Element &x1, const RawFec::Element &y1, const RawFec::Element &x2, const RawFec::Element &y2, RawFec::Element &x3, RawFec::Element &y3); -zkresult eval_addReadWriteAddress (Context &ctx, const mpz_class value); +zkresult eval_addReadWriteAddress (Context &ctx, const mpz_class value, const Goldilocks::Element (&key)[4]); mpz_class sqrtTonelliShanks ( const mpz_class &n, const mpz_class &p ); diff --git a/src/main_sm/fork_6/main/full_tracer.cpp b/src/main_sm/fork_6/main/full_tracer.cpp index 519bce9ca..8a4cc9b1f 100644 --- a/src/main_sm/fork_6/main/full_tracer.cpp +++ b/src/main_sm/fork_6/main/full_tracer.cpp @@ -1711,7 +1711,8 @@ zkresult FullTracer::onOpcode(Context &ctx, const RomCommand &cmd) zkresult FullTracer::addReadWriteAddress ( const Goldilocks::Element &address0, const Goldilocks::Element &address1, const Goldilocks::Element &address2, const Goldilocks::Element &address3, const Goldilocks::Element &address4, const Goldilocks::Element &address5, const Goldilocks::Element &address6, const Goldilocks::Element &address7, const Goldilocks::Element &keyType0, const Goldilocks::Element &keyType1, const Goldilocks::Element &keyType2, const Goldilocks::Element &keyType3, const Goldilocks::Element &keyType4, const Goldilocks::Element &keyType5, const Goldilocks::Element &keyType6, const Goldilocks::Element &keyType7, - const mpz_class &value ) + const mpz_class &value, + const Goldilocks::Element (&key)[4] ) { #ifdef LOG_TIME_STATISTICS gettimeofday(&t, NULL); @@ -1742,6 +1743,10 @@ zkresult FullTracer::addReadWriteAddress ( const Goldilocks::Element &address0, { InfoReadWrite infoReadWrite; infoReadWrite.balance = value.get_str(); + infoReadWrite.balanceKey[0]= key[0]; + infoReadWrite.balanceKey[1]= key[1]; + infoReadWrite.balanceKey[2]= key[2]; + infoReadWrite.balanceKey[3]= key[3]; read_write_addresses[addressHex] = infoReadWrite; } else @@ -1756,6 +1761,10 @@ zkresult FullTracer::addReadWriteAddress ( const Goldilocks::Element &address0, { InfoReadWrite infoReadWrite; infoReadWrite.nonce = value.get_str(); + infoReadWrite.nonceKey[0]= key[0]; + infoReadWrite.nonceKey[1]= key[1]; + infoReadWrite.nonceKey[2]= key[2]; + infoReadWrite.nonceKey[3]= key[3]; read_write_addresses[addressHex] = infoReadWrite; } else @@ -1771,4 +1780,47 @@ zkresult FullTracer::addReadWriteAddress ( const Goldilocks::Element &address0, return ZKR_SUCCESS; } +zkresult FullTracer::fillInReadWriteAddresses (Context &ctx) +{ + zkresult zkr; + + // For all entries in read_write_addresses + unordered_map::iterator it; + for (it = read_write_addresses.begin(); it != read_write_addresses.end(); it++) + { + Goldilocks::Element newStateRoot[4]; + string2fea(fr, finalTrace.new_state_root, newStateRoot); + + // Re-read balance for this state root + if (!it->second.balance.empty()) + { + zkassert(!fr.isZero(it->second.balanceKey[0]) || !fr.isZero(it->second.balanceKey[1]) || !fr.isZero(it->second.balanceKey[2]) || !fr.isZero(it->second.balanceKey[3])); + mpz_class balance; + zkr = ctx.pHashDB->get(ctx.proverRequest.uuid, newStateRoot, it->second.balanceKey, balance, NULL, NULL); + if (zkr != ZKR_SUCCESS) + { + zklog.error("FullTracer::fillInReadWriteAddresses() failed calling ctx.pHashDB->get(balance) result=" + zkresult2string(zkr)); + return zkr; + } + it->second.balance = balance.get_str(); + } + + // Re-read nonce for this state root + if (!it->second.nonce.empty()) + { + zkassert(!fr.isZero(it->second.nonceKey[0]) || !fr.isZero(it->second.nonceKey[1]) || !fr.isZero(it->second.nonceKey[2]) || !fr.isZero(it->second.nonceKey[3])); + mpz_class nonce; + zkr = ctx.pHashDB->get(ctx.proverRequest.uuid, newStateRoot, it->second.nonceKey, nonce, NULL, NULL); + if (zkr != ZKR_SUCCESS) + { + zklog.error("FullTracer::fillInReadWriteAddresses() failed calling ctx.pHashDB->get(nonce) result=" + zkresult2string(zkr)); + return zkr; + } + it->second.nonce = nonce.get_str(); + } + } + + return ZKR_SUCCESS; +} + } // namespace \ No newline at end of file diff --git a/src/main_sm/fork_6/main/full_tracer.hpp b/src/main_sm/fork_6/main/full_tracer.hpp index 09b7b9e87..2917751c5 100644 --- a/src/main_sm/fork_6/main/full_tracer.hpp +++ b/src/main_sm/fork_6/main/full_tracer.hpp @@ -66,7 +66,9 @@ class FullTracer: public FullTracerInterface zkresult onOpcode (Context &ctx, const RomCommand &cmd); zkresult addReadWriteAddress ( const Goldilocks::Element &address0, const Goldilocks::Element &address1, const Goldilocks::Element &address2, const Goldilocks::Element &faddress3, const Goldilocks::Element &address4, const Goldilocks::Element &address5, const Goldilocks::Element &address6, const Goldilocks::Element &address7, const Goldilocks::Element &keyType0, const Goldilocks::Element &keyType1, const Goldilocks::Element &keyType2, const Goldilocks::Element &keyType3, const Goldilocks::Element &keyType4, const Goldilocks::Element &keyType5, const Goldilocks::Element &keyType6, const Goldilocks::Element &keyType7, - const mpz_class &value ); + const mpz_class &value, + const Goldilocks::Element (&key)[4] ); + zkresult fillInReadWriteAddresses (Context &ctx); FullTracer(Goldilocks &fr) : fr(fr), depth(1), prevCTX(0), initGas(0), txCount(0), txTime(0), accBatchGas(0), numberOfOpcodesInThisTx(0), lastErrorOpcode(0), hasGaspriceOpcode(false), hasBalanceOpcode(false) { }; ~FullTracer() diff --git a/src/main_sm/fork_6/main/main_executor.cpp b/src/main_sm/fork_6/main/main_executor.cpp index d6ee1e728..13775415d 100644 --- a/src/main_sm/fork_6/main/main_executor.cpp +++ b/src/main_sm/fork_6/main/main_executor.cpp @@ -1050,17 +1050,17 @@ void MainExecutor::execute (ProverRequest &proverRequest, MainCommitPols &pols, #ifdef LOG_TIME_STATISTICS_MAIN_EXECUTOR mainMetrics.add("SMT Get", TimeDiff(t)); #endif - } - if (bProcessBatch) - { - zkResult = eval_addReadWriteAddress(ctx, smtGetResult.value); - if (zkResult != ZKR_SUCCESS) + if (bProcessBatch) { - proverRequest.result = zkResult; - logError(ctx, string("Failed calling eval_addReadWriteAddress() 1 result=") + zkresult2string(zkResult)); - pHashDB->cancelBatch(proverRequest.uuid); - return; + zkResult = eval_addReadWriteAddress(ctx, smtGetResult.value, key); + if (zkResult != ZKR_SUCCESS) + { + proverRequest.result = zkResult; + logError(ctx, string("Failed calling eval_addReadWriteAddress() 1 result=") + zkresult2string(zkResult)); + pHashDB->cancelBatch(proverRequest.uuid); + return; + } } } @@ -1288,7 +1288,7 @@ void MainExecutor::execute (ProverRequest &proverRequest, MainCommitPols &pols, } if (bProcessBatch) { - zkResult = eval_addReadWriteAddress(ctx, value); + zkResult = eval_addReadWriteAddress(ctx, value, ctx.lastSWrite.key); if (zkResult != ZKR_SUCCESS) { proverRequest.result = zkResult; @@ -2125,7 +2125,7 @@ void MainExecutor::execute (ProverRequest &proverRequest, MainCommitPols &pols, if (bProcessBatch) { - zkResult = eval_addReadWriteAddress(ctx, smtGetResult.value); + zkResult = eval_addReadWriteAddress(ctx, smtGetResult.value, key); if (zkResult != ZKR_SUCCESS) { proverRequest.result = zkResult; @@ -2291,7 +2291,7 @@ void MainExecutor::execute (ProverRequest &proverRequest, MainCommitPols &pols, if (bProcessBatch) { - zkResult = eval_addReadWriteAddress(ctx, scalarD); + zkResult = eval_addReadWriteAddress(ctx, scalarD, ctx.lastSWrite.key); if (zkResult != ZKR_SUCCESS) { proverRequest.result = zkResult; diff --git a/src/main_sm/fork_7/main/eval_command.cpp b/src/main_sm/fork_7/main/eval_command.cpp index 42ad39cd6..911c9e7d0 100644 --- a/src/main_sm/fork_7/main/eval_command.cpp +++ b/src/main_sm/fork_7/main/eval_command.cpp @@ -2509,13 +2509,14 @@ zkresult AddPointEc (Context &ctx, bool dbl, const RawFec::Element &x1, const Ra return ZKR_SUCCESS; } -zkresult eval_addReadWriteAddress (Context &ctx, const mpz_class value) +zkresult eval_addReadWriteAddress (Context &ctx, const mpz_class value, const Goldilocks::Element (&key)[4]) { zkassert(ctx.proverRequest.input.publicInputsExtended.publicInputs.forkID == 7); // fork_7 return ((fork_7::FullTracer *)ctx.proverRequest.pFullTracer)->addReadWriteAddress( ctx.pols.A0[0], ctx.pols.A1[0], ctx.pols.A2[0], ctx.pols.A3[0], ctx.pols.A4[0], ctx.pols.A5[0], ctx.pols.A6[0], ctx.pols.A7[0], ctx.pols.B0[0], ctx.pols.B1[0], ctx.pols.B2[0], ctx.pols.B3[0], ctx.pols.B4[0], ctx.pols.B5[0], ctx.pols.B6[0], ctx.pols.B7[0], - value); + value, + key); } void eval_getL1InfoRoot (Context &ctx, const RomCommand &cmd, CommandResult &cr) diff --git a/src/main_sm/fork_7/main/eval_command.hpp b/src/main_sm/fork_7/main/eval_command.hpp index 496b042b4..8b068a828 100644 --- a/src/main_sm/fork_7/main/eval_command.hpp +++ b/src/main_sm/fork_7/main/eval_command.hpp @@ -151,7 +151,7 @@ void eval_fpBN254inv (Context &ctx, const RomCommand &cmd, Comm zkresult AddPointEc (Context &ctx, bool dbl, const RawFec::Element &x1, const RawFec::Element &y1, const RawFec::Element &x2, const RawFec::Element &y2, RawFec::Element &x3, RawFec::Element &y3); -zkresult eval_addReadWriteAddress (Context &ctx, const mpz_class value); +zkresult eval_addReadWriteAddress (Context &ctx, const mpz_class value, const Goldilocks::Element (&key)[4]); mpz_class sqrtTonelliShanks ( const mpz_class &n, const mpz_class &p ); diff --git a/src/main_sm/fork_7/main/full_tracer.cpp b/src/main_sm/fork_7/main/full_tracer.cpp index 5fe71bf17..01de6b31f 100644 --- a/src/main_sm/fork_7/main/full_tracer.cpp +++ b/src/main_sm/fork_7/main/full_tracer.cpp @@ -2073,7 +2073,8 @@ zkresult FullTracer::onOpcode(Context &ctx, const RomCommand &cmd) zkresult FullTracer::addReadWriteAddress ( const Goldilocks::Element &address0, const Goldilocks::Element &address1, const Goldilocks::Element &address2, const Goldilocks::Element &address3, const Goldilocks::Element &address4, const Goldilocks::Element &address5, const Goldilocks::Element &address6, const Goldilocks::Element &address7, const Goldilocks::Element &keyType0, const Goldilocks::Element &keyType1, const Goldilocks::Element &keyType2, const Goldilocks::Element &keyType3, const Goldilocks::Element &keyType4, const Goldilocks::Element &keyType5, const Goldilocks::Element &keyType6, const Goldilocks::Element &keyType7, - const mpz_class &value ) + const mpz_class &value, + const Goldilocks::Element (&key)[4] ) { #ifdef LOG_TIME_STATISTICS gettimeofday(&t, NULL); @@ -2104,6 +2105,10 @@ zkresult FullTracer::addReadWriteAddress ( const Goldilocks::Element &address0, { InfoReadWrite infoReadWrite; infoReadWrite.balance = value.get_str(); + infoReadWrite.balanceKey[0]= key[0]; + infoReadWrite.balanceKey[1]= key[1]; + infoReadWrite.balanceKey[2]= key[2]; + infoReadWrite.balanceKey[3]= key[3]; read_write_addresses[addressHex] = infoReadWrite; } else @@ -2118,6 +2123,10 @@ zkresult FullTracer::addReadWriteAddress ( const Goldilocks::Element &address0, { InfoReadWrite infoReadWrite; infoReadWrite.nonce = value.get_str(); + infoReadWrite.nonceKey[0]= key[0]; + infoReadWrite.nonceKey[1]= key[1]; + infoReadWrite.nonceKey[2]= key[2]; + infoReadWrite.nonceKey[3]= key[3]; read_write_addresses[addressHex] = infoReadWrite; } else @@ -2133,4 +2142,47 @@ zkresult FullTracer::addReadWriteAddress ( const Goldilocks::Element &address0, return ZKR_SUCCESS; } +zkresult FullTracer::fillInReadWriteAddresses (Context &ctx) +{ + zkresult zkr; + + // For all entries in read_write_addresses + unordered_map::iterator it; + for (it = read_write_addresses.begin(); it != read_write_addresses.end(); it++) + { + Goldilocks::Element newStateRoot[4]; + string2fea(fr, finalTrace.new_state_root, newStateRoot); + + // Re-read balance for this state root + if (!it->second.balance.empty()) + { + zkassert(!fr.isZero(it->second.balanceKey[0]) || !fr.isZero(it->second.balanceKey[1]) || !fr.isZero(it->second.balanceKey[2]) || !fr.isZero(it->second.balanceKey[3])); + mpz_class balance; + zkr = ctx.pHashDB->get(ctx.proverRequest.uuid, newStateRoot, it->second.balanceKey, balance, NULL, NULL); + if (zkr != ZKR_SUCCESS) + { + zklog.error("FullTracer::fillInReadWriteAddresses() failed calling ctx.pHashDB->get(balance) result=" + zkresult2string(zkr)); + return zkr; + } + it->second.balance = balance.get_str(); + } + + // Re-read nonce for this state root + if (!it->second.nonce.empty()) + { + zkassert(!fr.isZero(it->second.nonceKey[0]) || !fr.isZero(it->second.nonceKey[1]) || !fr.isZero(it->second.nonceKey[2]) || !fr.isZero(it->second.nonceKey[3])); + mpz_class nonce; + zkr = ctx.pHashDB->get(ctx.proverRequest.uuid, newStateRoot, it->second.nonceKey, nonce, NULL, NULL); + if (zkr != ZKR_SUCCESS) + { + zklog.error("FullTracer::fillInReadWriteAddresses() failed calling ctx.pHashDB->get(nonce) result=" + zkresult2string(zkr)); + return zkr; + } + it->second.nonce = nonce.get_str(); + } + } + + return ZKR_SUCCESS; +} + } // namespace \ No newline at end of file diff --git a/src/main_sm/fork_7/main/full_tracer.hpp b/src/main_sm/fork_7/main/full_tracer.hpp index c072fff8f..30a2a6723 100644 --- a/src/main_sm/fork_7/main/full_tracer.hpp +++ b/src/main_sm/fork_7/main/full_tracer.hpp @@ -70,7 +70,9 @@ class FullTracer: public FullTracerInterface zkresult onOpcode (Context &ctx, const RomCommand &cmd); zkresult addReadWriteAddress ( const Goldilocks::Element &address0, const Goldilocks::Element &address1, const Goldilocks::Element &address2, const Goldilocks::Element &faddress3, const Goldilocks::Element &address4, const Goldilocks::Element &address5, const Goldilocks::Element &address6, const Goldilocks::Element &address7, const Goldilocks::Element &keyType0, const Goldilocks::Element &keyType1, const Goldilocks::Element &keyType2, const Goldilocks::Element &keyType3, const Goldilocks::Element &keyType4, const Goldilocks::Element &keyType5, const Goldilocks::Element &keyType6, const Goldilocks::Element &keyType7, - const mpz_class &value ); + const mpz_class &value, + const Goldilocks::Element (&key)[4] ); + zkresult fillInReadWriteAddresses (Context &ctx); FullTracer(Goldilocks &fr) : fr(fr), depth(1), prevCTX(0), initGas(0), txTime(0), accBatchGas(0), numberOfOpcodesInThisTx(0), lastErrorOpcode(0), hasGaspriceOpcode(false), hasBalanceOpcode(false), txIndex(0), isForced(false) { }; ~FullTracer() diff --git a/src/main_sm/fork_7/main/main_executor.cpp b/src/main_sm/fork_7/main/main_executor.cpp index fbb00e4fb..2752e94c6 100644 --- a/src/main_sm/fork_7/main/main_executor.cpp +++ b/src/main_sm/fork_7/main/main_executor.cpp @@ -1159,17 +1159,17 @@ void MainExecutor::execute (ProverRequest &proverRequest, MainCommitPols &pols, #ifdef LOG_TIME_STATISTICS_MAIN_EXECUTOR mainMetrics.add("SMT Get", TimeDiff(t)); #endif - } - if (bProcessBatch) - { - zkResult = eval_addReadWriteAddress(ctx, smtGetResult.value); - if (zkResult != ZKR_SUCCESS) + if (bProcessBatch) { - proverRequest.result = zkResult; - logError(ctx, string("Failed calling eval_addReadWriteAddress() 1 result=") + zkresult2string(zkResult)); - pHashDB->cancelBatch(proverRequest.uuid); - return; + zkResult = eval_addReadWriteAddress(ctx, smtGetResult.value, key); + if (zkResult != ZKR_SUCCESS) + { + proverRequest.result = zkResult; + logError(ctx, string("Failed calling eval_addReadWriteAddress() 1 result=") + zkresult2string(zkResult)); + pHashDB->cancelBatch(proverRequest.uuid); + return; + } } } @@ -1400,7 +1400,7 @@ void MainExecutor::execute (ProverRequest &proverRequest, MainCommitPols &pols, } if (bProcessBatch) { - zkResult = eval_addReadWriteAddress(ctx, value); + zkResult = eval_addReadWriteAddress(ctx, value, ctx.lastSWrite.key); if (zkResult != ZKR_SUCCESS) { proverRequest.result = zkResult; @@ -2384,7 +2384,7 @@ void MainExecutor::execute (ProverRequest &proverRequest, MainCommitPols &pols, if (bProcessBatch) { - zkResult = eval_addReadWriteAddress(ctx, smtGetResult.value); + zkResult = eval_addReadWriteAddress(ctx, smtGetResult.value, key); if (zkResult != ZKR_SUCCESS) { proverRequest.result = zkResult; @@ -2551,7 +2551,7 @@ void MainExecutor::execute (ProverRequest &proverRequest, MainCommitPols &pols, if (bProcessBatch) { - zkResult = eval_addReadWriteAddress(ctx, scalarD); + zkResult = eval_addReadWriteAddress(ctx, scalarD, ctx.lastSWrite.key); if (zkResult != ZKR_SUCCESS) { proverRequest.result = zkResult; diff --git a/src/main_sm/fork_8/main/eval_command.cpp b/src/main_sm/fork_8/main/eval_command.cpp index fb83062eb..962d58a58 100644 --- a/src/main_sm/fork_8/main/eval_command.cpp +++ b/src/main_sm/fork_8/main/eval_command.cpp @@ -2510,14 +2510,15 @@ zkresult AddPointEc (Context &ctx, bool dbl, const RawFec::Element &x1, const Ra return ZKR_SUCCESS; } -zkresult eval_addReadWriteAddress (Context &ctx, const mpz_class value) +zkresult eval_addReadWriteAddress (Context &ctx, const mpz_class value, const Goldilocks::Element (&key)[4]) { zkassert(ctx.proverRequest.input.publicInputsExtended.publicInputs.forkID == 8); // fork_8 return ((fork_8::FullTracer *)ctx.proverRequest.pFullTracer)->addReadWriteAddress( ctx.pols.A0[0], ctx.pols.A1[0], ctx.pols.A2[0], ctx.pols.A3[0], ctx.pols.A4[0], ctx.pols.A5[0], ctx.pols.A6[0], ctx.pols.A7[0], ctx.pols.B0[0], ctx.pols.B1[0], ctx.pols.B2[0], ctx.pols.B3[0], ctx.pols.B4[0], ctx.pols.B5[0], ctx.pols.B6[0], ctx.pols.B7[0], ctx.pols.C0[0], ctx.pols.C1[0], ctx.pols.C2[0], ctx.pols.C3[0], ctx.pols.C4[0], ctx.pols.C5[0], ctx.pols.C6[0], ctx.pols.C7[0], - value); + value, + key); } void eval_getL1InfoRoot (Context &ctx, const RomCommand &cmd, CommandResult &cr) diff --git a/src/main_sm/fork_8/main/eval_command.hpp b/src/main_sm/fork_8/main/eval_command.hpp index b41162d19..64d3b3b50 100644 --- a/src/main_sm/fork_8/main/eval_command.hpp +++ b/src/main_sm/fork_8/main/eval_command.hpp @@ -152,7 +152,7 @@ void eval_fpBN254inv (Context &ctx, const RomCommand &cmd, Comm zkresult AddPointEc (Context &ctx, bool dbl, const RawFec::Element &x1, const RawFec::Element &y1, const RawFec::Element &x2, const RawFec::Element &y2, RawFec::Element &x3, RawFec::Element &y3); -zkresult eval_addReadWriteAddress (Context &ctx, const mpz_class value); +zkresult eval_addReadWriteAddress (Context &ctx, const mpz_class value, const Goldilocks::Element (&key)[4]); mpz_class sqrtTonelliShanks ( const mpz_class &n, const mpz_class &p ); diff --git a/src/main_sm/fork_8/main/full_tracer.cpp b/src/main_sm/fork_8/main/full_tracer.cpp index 611817074..312908ae1 100644 --- a/src/main_sm/fork_8/main/full_tracer.cpp +++ b/src/main_sm/fork_8/main/full_tracer.cpp @@ -2764,7 +2764,8 @@ zkresult FullTracer::onOpcode(Context &ctx, const RomCommand &cmd) zkresult FullTracer::addReadWriteAddress ( const Goldilocks::Element &address0, const Goldilocks::Element &address1, const Goldilocks::Element &address2, const Goldilocks::Element &address3, const Goldilocks::Element &address4, const Goldilocks::Element &address5, const Goldilocks::Element &address6, const Goldilocks::Element &address7, const Goldilocks::Element &keyType0, const Goldilocks::Element &keyType1, const Goldilocks::Element &keyType2, const Goldilocks::Element &keyType3, const Goldilocks::Element &keyType4, const Goldilocks::Element &keyType5, const Goldilocks::Element &keyType6, const Goldilocks::Element &keyType7, const Goldilocks::Element &storageKey0, const Goldilocks::Element &storageKey1, const Goldilocks::Element &storageKey2, const Goldilocks::Element &storageKey3, const Goldilocks::Element &storageKey4, const Goldilocks::Element &storageKey5, const Goldilocks::Element &storageKey6, const Goldilocks::Element &storageKey7, - const mpz_class &value ) + const mpz_class &value, + const Goldilocks::Element (&key)[4] ) { #ifdef LOG_TIME_STATISTICS gettimeofday(&t, NULL); @@ -2795,6 +2796,10 @@ zkresult FullTracer::addReadWriteAddress ( const Goldilocks::Element &address0, { InfoReadWrite infoReadWrite; infoReadWrite.balance = value.get_str(); + infoReadWrite.balanceKey[0]= key[0]; + infoReadWrite.balanceKey[1]= key[1]; + infoReadWrite.balanceKey[2]= key[2]; + infoReadWrite.balanceKey[3]= key[3]; read_write_addresses[addressHex] = infoReadWrite; } else @@ -2809,6 +2814,10 @@ zkresult FullTracer::addReadWriteAddress ( const Goldilocks::Element &address0, { InfoReadWrite infoReadWrite; infoReadWrite.nonce = value.get_str(); + infoReadWrite.nonceKey[0]= key[0]; + infoReadWrite.nonceKey[1]= key[1]; + infoReadWrite.nonceKey[2]= key[2]; + infoReadWrite.nonceKey[3]= key[3]; read_write_addresses[addressHex] = infoReadWrite; } else @@ -2874,4 +2883,47 @@ zkresult FullTracer::addReadWriteAddress ( const Goldilocks::Element &address0, return ZKR_SUCCESS; } +zkresult FullTracer::fillInReadWriteAddresses (Context &ctx) +{ + zkresult zkr; + + // For all entries in read_write_addresses + unordered_map::iterator it; + for (it = read_write_addresses.begin(); it != read_write_addresses.end(); it++) + { + Goldilocks::Element newStateRoot[4]; + string2fea(fr, finalTrace.new_state_root, newStateRoot); + + // Re-read balance for this state root + if (!it->second.balance.empty()) + { + zkassert(!fr.isZero(it->second.balanceKey[0]) || !fr.isZero(it->second.balanceKey[1]) || !fr.isZero(it->second.balanceKey[2]) || !fr.isZero(it->second.balanceKey[3])); + mpz_class balance; + zkr = ctx.pHashDB->get(ctx.proverRequest.uuid, newStateRoot, it->second.balanceKey, balance, NULL, NULL); + if (zkr != ZKR_SUCCESS) + { + zklog.error("FullTracer::fillInReadWriteAddresses() failed calling ctx.pHashDB->get(balance) result=" + zkresult2string(zkr)); + return zkr; + } + it->second.balance = balance.get_str(); + } + + // Re-read nonce for this state root + if (!it->second.nonce.empty()) + { + zkassert(!fr.isZero(it->second.nonceKey[0]) || !fr.isZero(it->second.nonceKey[1]) || !fr.isZero(it->second.nonceKey[2]) || !fr.isZero(it->second.nonceKey[3])); + mpz_class nonce; + zkr = ctx.pHashDB->get(ctx.proverRequest.uuid, newStateRoot, it->second.nonceKey, nonce, NULL, NULL); + if (zkr != ZKR_SUCCESS) + { + zklog.error("FullTracer::fillInReadWriteAddresses() failed calling ctx.pHashDB->get(nonce) result=" + zkresult2string(zkr)); + return zkr; + } + it->second.nonce = nonce.get_str(); + } + } + + return ZKR_SUCCESS; +} + } // namespace \ No newline at end of file diff --git a/src/main_sm/fork_8/main/full_tracer.hpp b/src/main_sm/fork_8/main/full_tracer.hpp index 09a679ab7..35de80319 100644 --- a/src/main_sm/fork_8/main/full_tracer.hpp +++ b/src/main_sm/fork_8/main/full_tracer.hpp @@ -79,7 +79,9 @@ class FullTracer: public FullTracerInterface zkresult addReadWriteAddress ( const Goldilocks::Element &address0, const Goldilocks::Element &address1, const Goldilocks::Element &address2, const Goldilocks::Element &faddress3, const Goldilocks::Element &address4, const Goldilocks::Element &address5, const Goldilocks::Element &address6, const Goldilocks::Element &address7, const Goldilocks::Element &keyType0, const Goldilocks::Element &keyType1, const Goldilocks::Element &keyType2, const Goldilocks::Element &keyType3, const Goldilocks::Element &keyType4, const Goldilocks::Element &keyType5, const Goldilocks::Element &keyType6, const Goldilocks::Element &keyType7, const Goldilocks::Element &storageKey0, const Goldilocks::Element &storageKey1, const Goldilocks::Element &storageKey2, const Goldilocks::Element &storageKey3, const Goldilocks::Element &storageKey4, const Goldilocks::Element &storageKey5, const Goldilocks::Element &storageKey6, const Goldilocks::Element &storageKey7, - const mpz_class &value ); + const mpz_class &value, + const Goldilocks::Element (&key)[4] ); + zkresult fillInReadWriteAddresses (Context &ctx); FullTracer(Goldilocks &fr) : fr(fr), depth(1), prevCTX(0), initGas(0), txTime(0), accBatchGas(0), numberOfOpcodesInThisTx(0), lastErrorOpcode(0), hasGaspriceOpcode(false), hasBalanceOpcode(false), txIndex(0), isForced(false) { }; ~FullTracer() diff --git a/src/main_sm/fork_8/main/main_executor.cpp b/src/main_sm/fork_8/main/main_executor.cpp index 933a7a018..8ae716c18 100644 --- a/src/main_sm/fork_8/main/main_executor.cpp +++ b/src/main_sm/fork_8/main/main_executor.cpp @@ -1166,17 +1166,17 @@ void MainExecutor::execute (ProverRequest &proverRequest, MainCommitPols &pols, #ifdef LOG_TIME_STATISTICS_MAIN_EXECUTOR mainMetrics.add("SMT Get", TimeDiff(t)); #endif - } - if (bProcessBatch) - { - zkResult = eval_addReadWriteAddress(ctx, smtGetResult.value); - if (zkResult != ZKR_SUCCESS) + if (bProcessBatch) { - proverRequest.result = zkResult; - logError(ctx, string("Failed calling eval_addReadWriteAddress() 1 result=") + zkresult2string(zkResult)); - pHashDB->cancelBatch(proverRequest.uuid); - return; + zkResult = eval_addReadWriteAddress(ctx, smtGetResult.value, key); + if (zkResult != ZKR_SUCCESS) + { + proverRequest.result = zkResult; + logError(ctx, string("Failed calling eval_addReadWriteAddress() 1 result=") + zkresult2string(zkResult)); + pHashDB->cancelBatch(proverRequest.uuid); + return; + } } } @@ -1407,7 +1407,7 @@ void MainExecutor::execute (ProverRequest &proverRequest, MainCommitPols &pols, } if (bProcessBatch) { - zkResult = eval_addReadWriteAddress(ctx, value); + zkResult = eval_addReadWriteAddress(ctx, value, ctx.lastSWrite.key); if (zkResult != ZKR_SUCCESS) { proverRequest.result = zkResult; @@ -2391,7 +2391,7 @@ void MainExecutor::execute (ProverRequest &proverRequest, MainCommitPols &pols, if (bProcessBatch) { - zkResult = eval_addReadWriteAddress(ctx, smtGetResult.value); + zkResult = eval_addReadWriteAddress(ctx, smtGetResult.value, key); if (zkResult != ZKR_SUCCESS) { proverRequest.result = zkResult; @@ -2558,7 +2558,7 @@ void MainExecutor::execute (ProverRequest &proverRequest, MainCommitPols &pols, if (bProcessBatch) { - zkResult = eval_addReadWriteAddress(ctx, scalarD); + zkResult = eval_addReadWriteAddress(ctx, scalarD, ctx.lastSWrite.key); if (zkResult != ZKR_SUCCESS) { proverRequest.result = zkResult; diff --git a/src/main_sm/fork_9/main/eval_command.cpp b/src/main_sm/fork_9/main/eval_command.cpp index be6f10bd1..ea2d6c511 100644 --- a/src/main_sm/fork_9/main/eval_command.cpp +++ b/src/main_sm/fork_9/main/eval_command.cpp @@ -2510,14 +2510,15 @@ zkresult AddPointEc (Context &ctx, bool dbl, const RawFec::Element &x1, const Ra return ZKR_SUCCESS; } -zkresult eval_addReadWriteAddress (Context &ctx, const mpz_class value) +zkresult eval_addReadWriteAddress (Context &ctx, const mpz_class value, const Goldilocks::Element (&key)[4]) { zkassert(ctx.proverRequest.input.publicInputsExtended.publicInputs.forkID == 9); // fork_9 return ((fork_9::FullTracer *)ctx.proverRequest.pFullTracer)->addReadWriteAddress( ctx.pols.A0[0], ctx.pols.A1[0], ctx.pols.A2[0], ctx.pols.A3[0], ctx.pols.A4[0], ctx.pols.A5[0], ctx.pols.A6[0], ctx.pols.A7[0], ctx.pols.B0[0], ctx.pols.B1[0], ctx.pols.B2[0], ctx.pols.B3[0], ctx.pols.B4[0], ctx.pols.B5[0], ctx.pols.B6[0], ctx.pols.B7[0], ctx.pols.C0[0], ctx.pols.C1[0], ctx.pols.C2[0], ctx.pols.C3[0], ctx.pols.C4[0], ctx.pols.C5[0], ctx.pols.C6[0], ctx.pols.C7[0], - value); + value, + key); } void eval_getL1InfoRoot (Context &ctx, const RomCommand &cmd, CommandResult &cr) diff --git a/src/main_sm/fork_9/main/eval_command.hpp b/src/main_sm/fork_9/main/eval_command.hpp index 3a57d9922..d6ee5a3d2 100644 --- a/src/main_sm/fork_9/main/eval_command.hpp +++ b/src/main_sm/fork_9/main/eval_command.hpp @@ -152,7 +152,7 @@ void eval_fpBN254inv (Context &ctx, const RomCommand &cmd, Comm zkresult AddPointEc (Context &ctx, bool dbl, const RawFec::Element &x1, const RawFec::Element &y1, const RawFec::Element &x2, const RawFec::Element &y2, RawFec::Element &x3, RawFec::Element &y3); -zkresult eval_addReadWriteAddress (Context &ctx, const mpz_class value); +zkresult eval_addReadWriteAddress (Context &ctx, const mpz_class value, const Goldilocks::Element (&key)[4]); mpz_class sqrtTonelliShanks ( const mpz_class &n, const mpz_class &p ); diff --git a/src/main_sm/fork_9/main/full_tracer.cpp b/src/main_sm/fork_9/main/full_tracer.cpp index d24f01d48..7ccb75e75 100644 --- a/src/main_sm/fork_9/main/full_tracer.cpp +++ b/src/main_sm/fork_9/main/full_tracer.cpp @@ -2171,7 +2171,8 @@ zkresult FullTracer::onOpcode(Context &ctx, const RomCommand &cmd) zkresult FullTracer::addReadWriteAddress ( const Goldilocks::Element &address0, const Goldilocks::Element &address1, const Goldilocks::Element &address2, const Goldilocks::Element &address3, const Goldilocks::Element &address4, const Goldilocks::Element &address5, const Goldilocks::Element &address6, const Goldilocks::Element &address7, const Goldilocks::Element &keyType0, const Goldilocks::Element &keyType1, const Goldilocks::Element &keyType2, const Goldilocks::Element &keyType3, const Goldilocks::Element &keyType4, const Goldilocks::Element &keyType5, const Goldilocks::Element &keyType6, const Goldilocks::Element &keyType7, const Goldilocks::Element &storageKey0, const Goldilocks::Element &storageKey1, const Goldilocks::Element &storageKey2, const Goldilocks::Element &storageKey3, const Goldilocks::Element &storageKey4, const Goldilocks::Element &storageKey5, const Goldilocks::Element &storageKey6, const Goldilocks::Element &storageKey7, - const mpz_class &value ) + const mpz_class &value, + const Goldilocks::Element (&key)[4] ) { #ifdef LOG_TIME_STATISTICS gettimeofday(&t, NULL); @@ -2202,6 +2203,10 @@ zkresult FullTracer::addReadWriteAddress ( const Goldilocks::Element &address0, { InfoReadWrite infoReadWrite; infoReadWrite.balance = value.get_str(); + infoReadWrite.balanceKey[0]= key[0]; + infoReadWrite.balanceKey[1]= key[1]; + infoReadWrite.balanceKey[2]= key[2]; + infoReadWrite.balanceKey[3]= key[3]; read_write_addresses[addressHex] = infoReadWrite; } else @@ -2216,6 +2221,10 @@ zkresult FullTracer::addReadWriteAddress ( const Goldilocks::Element &address0, { InfoReadWrite infoReadWrite; infoReadWrite.nonce = value.get_str(); + infoReadWrite.nonceKey[0]= key[0]; + infoReadWrite.nonceKey[1]= key[1]; + infoReadWrite.nonceKey[2]= key[2]; + infoReadWrite.nonceKey[3]= key[3]; read_write_addresses[addressHex] = infoReadWrite; } else @@ -2281,4 +2290,47 @@ zkresult FullTracer::addReadWriteAddress ( const Goldilocks::Element &address0, return ZKR_SUCCESS; } +zkresult FullTracer::fillInReadWriteAddresses (Context &ctx) +{ + zkresult zkr; + + // For all entries in read_write_addresses + unordered_map::iterator it; + for (it = read_write_addresses.begin(); it != read_write_addresses.end(); it++) + { + Goldilocks::Element newStateRoot[4]; + string2fea(fr, finalTrace.new_state_root, newStateRoot); + + // Re-read balance for this state root + if (!it->second.balance.empty()) + { + zkassert(!fr.isZero(it->second.balanceKey[0]) || !fr.isZero(it->second.balanceKey[1]) || !fr.isZero(it->second.balanceKey[2]) || !fr.isZero(it->second.balanceKey[3])); + mpz_class balance; + zkr = ctx.pHashDB->get(ctx.proverRequest.uuid, newStateRoot, it->second.balanceKey, balance, NULL, NULL); + if (zkr != ZKR_SUCCESS) + { + zklog.error("FullTracer::fillInReadWriteAddresses() failed calling ctx.pHashDB->get(balance) result=" + zkresult2string(zkr)); + return zkr; + } + it->second.balance = balance.get_str(); + } + + // Re-read nonce for this state root + if (!it->second.nonce.empty()) + { + zkassert(!fr.isZero(it->second.nonceKey[0]) || !fr.isZero(it->second.nonceKey[1]) || !fr.isZero(it->second.nonceKey[2]) || !fr.isZero(it->second.nonceKey[3])); + mpz_class nonce; + zkr = ctx.pHashDB->get(ctx.proverRequest.uuid, newStateRoot, it->second.nonceKey, nonce, NULL, NULL); + if (zkr != ZKR_SUCCESS) + { + zklog.error("FullTracer::fillInReadWriteAddresses() failed calling ctx.pHashDB->get(nonce) result=" + zkresult2string(zkr)); + return zkr; + } + it->second.nonce = nonce.get_str(); + } + } + + return ZKR_SUCCESS; +} + } // namespace \ No newline at end of file diff --git a/src/main_sm/fork_9/main/full_tracer.hpp b/src/main_sm/fork_9/main/full_tracer.hpp index 78bde4ce5..f58893c8c 100644 --- a/src/main_sm/fork_9/main/full_tracer.hpp +++ b/src/main_sm/fork_9/main/full_tracer.hpp @@ -71,7 +71,9 @@ class FullTracer: public FullTracerInterface zkresult addReadWriteAddress ( const Goldilocks::Element &address0, const Goldilocks::Element &address1, const Goldilocks::Element &address2, const Goldilocks::Element &faddress3, const Goldilocks::Element &address4, const Goldilocks::Element &address5, const Goldilocks::Element &address6, const Goldilocks::Element &address7, const Goldilocks::Element &keyType0, const Goldilocks::Element &keyType1, const Goldilocks::Element &keyType2, const Goldilocks::Element &keyType3, const Goldilocks::Element &keyType4, const Goldilocks::Element &keyType5, const Goldilocks::Element &keyType6, const Goldilocks::Element &keyType7, const Goldilocks::Element &storageKey0, const Goldilocks::Element &storageKey1, const Goldilocks::Element &storageKey2, const Goldilocks::Element &storageKey3, const Goldilocks::Element &storageKey4, const Goldilocks::Element &storageKey5, const Goldilocks::Element &storageKey6, const Goldilocks::Element &storageKey7, - const mpz_class &value ); + const mpz_class &value, + const Goldilocks::Element (&key)[4] ); + zkresult fillInReadWriteAddresses (Context &ctx); FullTracer(Goldilocks &fr) : fr(fr), depth(1), prevCTX(0), initGas(0), txTime(0), accBatchGas(0), numberOfOpcodesInThisTx(0), lastErrorOpcode(0), hasGaspriceOpcode(false), hasBalanceOpcode(false), txIndex(0), isForced(false) { }; ~FullTracer() diff --git a/src/main_sm/fork_9/main/main_executor.cpp b/src/main_sm/fork_9/main/main_executor.cpp index 5da8f1eba..5cedf1580 100644 --- a/src/main_sm/fork_9/main/main_executor.cpp +++ b/src/main_sm/fork_9/main/main_executor.cpp @@ -1166,17 +1166,17 @@ void MainExecutor::execute (ProverRequest &proverRequest, MainCommitPols &pols, #ifdef LOG_TIME_STATISTICS_MAIN_EXECUTOR mainMetrics.add("SMT Get", TimeDiff(t)); #endif - } - if (bProcessBatch) - { - zkResult = eval_addReadWriteAddress(ctx, smtGetResult.value); - if (zkResult != ZKR_SUCCESS) + if (bProcessBatch) { - proverRequest.result = zkResult; - logError(ctx, string("Failed calling eval_addReadWriteAddress() 1 result=") + zkresult2string(zkResult)); - pHashDB->cancelBatch(proverRequest.uuid); - return; + zkResult = eval_addReadWriteAddress(ctx, smtGetResult.value, key); + if (zkResult != ZKR_SUCCESS) + { + proverRequest.result = zkResult; + logError(ctx, string("Failed calling eval_addReadWriteAddress() 1 result=") + zkresult2string(zkResult)); + pHashDB->cancelBatch(proverRequest.uuid); + return; + } } } @@ -1407,7 +1407,7 @@ void MainExecutor::execute (ProverRequest &proverRequest, MainCommitPols &pols, } if (bProcessBatch) { - zkResult = eval_addReadWriteAddress(ctx, value); + zkResult = eval_addReadWriteAddress(ctx, value, ctx.lastSWrite.key); if (zkResult != ZKR_SUCCESS) { proverRequest.result = zkResult; @@ -2391,7 +2391,7 @@ void MainExecutor::execute (ProverRequest &proverRequest, MainCommitPols &pols, if (bProcessBatch) { - zkResult = eval_addReadWriteAddress(ctx, smtGetResult.value); + zkResult = eval_addReadWriteAddress(ctx, smtGetResult.value, key); if (zkResult != ZKR_SUCCESS) { proverRequest.result = zkResult; @@ -2558,7 +2558,7 @@ void MainExecutor::execute (ProverRequest &proverRequest, MainCommitPols &pols, if (bProcessBatch) { - zkResult = eval_addReadWriteAddress(ctx, scalarD); + zkResult = eval_addReadWriteAddress(ctx, scalarD, ctx.lastSWrite.key); if (zkResult != ZKR_SUCCESS) { proverRequest.result = zkResult; diff --git a/src/prover/full_tracer_interface.hpp b/src/prover/full_tracer_interface.hpp index 1e97ec706..f4fbab865 100644 --- a/src/prover/full_tracer_interface.hpp +++ b/src/prover/full_tracer_interface.hpp @@ -3,6 +3,7 @@ #include #include +#include "zkglobals.hpp" using namespace std; @@ -240,10 +241,26 @@ class InfoReadWrite { public: string nonce; + Goldilocks::Element nonceKey[4]; string balance; + Goldilocks::Element balanceKey[4]; string sc_code; unordered_map sc_storage; string sc_length; + InfoReadWrite() + { + // Reset nonce key + nonceKey[0] = fr.zero(); + nonceKey[1] = fr.zero(); + nonceKey[2] = fr.zero(); + nonceKey[3] = fr.zero(); + + // Reset balance key + balanceKey[0] = fr.zero(); + balanceKey[1] = fr.zero(); + balanceKey[2] = fr.zero(); + balanceKey[3] = fr.zero(); + } }; class TxGAS