Skip to content

Commit

Permalink
Call fillInReadWriteAddresses() from FullTracer::onFinishBatch() in a…
Browse files Browse the repository at this point in the history
…ll forks
  • Loading branch information
fractasy committed Apr 17, 2024
1 parent 6b10393 commit fed1956
Show file tree
Hide file tree
Showing 10 changed files with 184 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/config/version.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifndef ZKEVM_PROVER_VERSION_HPP
#define ZKEVM_PROVER_VERSION_HPP

#define ZKEVM_PROVER_VERSION "v6.0.2-RC1"
#define ZKEVM_PROVER_VERSION "v6.0.2-RC2"

#endif
20 changes: 17 additions & 3 deletions src/main_sm/fork_1/main/full_tracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,9 @@ void FullTracer::onFinishBatch(Context &ctx, const RomCommand &cmd)
// getVarFromCtx(ctx, true, "newNumBatch", auxScalar);
// finalTrace.new_batch_num = auxScalar.get_ui();

// Call fillInReadWriteAddresses
fillInReadWriteAddresses(ctx);

#ifdef LOG_FULL_TRACER
zklog.info("FullTracer::onFinishBatch() new_state_root=" + finalTrace.new_state_root);
#endif
Expand Down Expand Up @@ -1333,6 +1336,8 @@ void FullTracer::addReadWriteAddress ( const Goldilocks::Element &address0, cons
gettimeofday(&t, NULL);
#endif

zkassert(!fr.isZero(key[0]) || !fr.isZero(key[1]) || !fr.isZero(key[2]) || !fr.isZero(key[3]));

// Get address
mpz_class address;
fea2scalar(fr, address, address0, address1, address2, address3, address4, address5, address6, address7);
Expand All @@ -1359,6 +1364,10 @@ void FullTracer::addReadWriteAddress ( const Goldilocks::Element &address0, cons
else
{
it->second.balance = value.get_str();
it->second.balanceKey[0]= key[0];
it->second.balanceKey[1]= key[1];
it->second.balanceKey[2]= key[2];
it->second.balanceKey[3]= key[3];
}
}
else if (keyType == SMT_KEY_NONCE)
Expand All @@ -1377,6 +1386,10 @@ void FullTracer::addReadWriteAddress ( const Goldilocks::Element &address0, cons
else
{
it->second.nonce = value.get_str();
it->second.nonceKey[0]= key[0];
it->second.nonceKey[1]= key[1];
it->second.nonceKey[2]= key[2];
it->second.nonceKey[3]= key[3];
}
}

Expand All @@ -1389,13 +1402,14 @@ zkresult FullTracer::fillInReadWriteAddresses (Context &ctx)
{
zkresult zkr;

// Get new state root fea
Goldilocks::Element newStateRoot[4];
string2fea(fr, NormalizeToNFormat(finalTrace.new_state_root, 64), newStateRoot);

// For all entries in read_write_addresses
unordered_map<string, InfoReadWrite>::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())
{
Expand Down
20 changes: 17 additions & 3 deletions src/main_sm/fork_2/main/full_tracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,9 @@ void FullTracer::onFinishBatch(Context &ctx, const RomCommand &cmd)
// getVarFromCtx(ctx, true, "newNumBatch", auxScalar);
// finalTrace.new_batch_num = auxScalar.get_ui();

// Call fillInReadWriteAddresses
fillInReadWriteAddresses(ctx);

#ifdef LOG_FULL_TRACER
zklog.info("FullTracer::onFinishBatch() new_state_root=" + finalTrace.new_state_root);
#endif
Expand Down Expand Up @@ -1337,6 +1340,8 @@ void FullTracer::addReadWriteAddress ( const Goldilocks::Element &address0, cons
gettimeofday(&t, NULL);
#endif

zkassert(!fr.isZero(key[0]) || !fr.isZero(key[1]) || !fr.isZero(key[2]) || !fr.isZero(key[3]));

// Get address
mpz_class address;
fea2scalar(fr, address, address0, address1, address2, address3, address4, address5, address6, address7);
Expand All @@ -1363,6 +1368,10 @@ void FullTracer::addReadWriteAddress ( const Goldilocks::Element &address0, cons
else
{
it->second.balance = value.get_str();
it->second.balanceKey[0]= key[0];
it->second.balanceKey[1]= key[1];
it->second.balanceKey[2]= key[2];
it->second.balanceKey[3]= key[3];
}
}
else if (keyType == SMT_KEY_NONCE)
Expand All @@ -1381,6 +1390,10 @@ void FullTracer::addReadWriteAddress ( const Goldilocks::Element &address0, cons
else
{
it->second.nonce = value.get_str();
it->second.nonceKey[0]= key[0];
it->second.nonceKey[1]= key[1];
it->second.nonceKey[2]= key[2];
it->second.nonceKey[3]= key[3];
}
}

Expand All @@ -1393,13 +1406,14 @@ zkresult FullTracer::fillInReadWriteAddresses (Context &ctx)
{
zkresult zkr;

// Get new state root fea
Goldilocks::Element newStateRoot[4];
string2fea(fr, NormalizeToNFormat(finalTrace.new_state_root, 64), newStateRoot);

// For all entries in read_write_addresses
unordered_map<string, InfoReadWrite>::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())
{
Expand Down
20 changes: 17 additions & 3 deletions src/main_sm/fork_3/main/full_tracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,9 @@ void FullTracer::onFinishBatch(Context &ctx, const RomCommand &cmd)
// getVarFromCtx(ctx, true, "newNumBatch", auxScalar);
// finalTrace.new_batch_num = auxScalar.get_ui();

// Call fillInReadWriteAddresses
fillInReadWriteAddresses(ctx);

#ifdef LOG_FULL_TRACER
zklog.info("FullTracer::onFinishBatch() new_state_root=" + finalTrace.new_state_root);
#endif
Expand Down Expand Up @@ -1337,6 +1340,8 @@ void FullTracer::addReadWriteAddress ( const Goldilocks::Element &address0, cons
gettimeofday(&t, NULL);
#endif

zkassert(!fr.isZero(key[0]) || !fr.isZero(key[1]) || !fr.isZero(key[2]) || !fr.isZero(key[3]));

// Get address
mpz_class address;
fea2scalar(fr, address, address0, address1, address2, address3, address4, address5, address6, address7);
Expand All @@ -1363,6 +1368,10 @@ void FullTracer::addReadWriteAddress ( const Goldilocks::Element &address0, cons
else
{
it->second.balance = value.get_str();
it->second.balanceKey[0]= key[0];
it->second.balanceKey[1]= key[1];
it->second.balanceKey[2]= key[2];
it->second.balanceKey[3]= key[3];
}
}
else if (keyType == SMT_KEY_NONCE)
Expand All @@ -1381,6 +1390,10 @@ void FullTracer::addReadWriteAddress ( const Goldilocks::Element &address0, cons
else
{
it->second.nonce = value.get_str();
it->second.nonceKey[0]= key[0];
it->second.nonceKey[1]= key[1];
it->second.nonceKey[2]= key[2];
it->second.nonceKey[3]= key[3];
}
}

Expand All @@ -1393,13 +1406,14 @@ zkresult FullTracer::fillInReadWriteAddresses (Context &ctx)
{
zkresult zkr;

// Get new state root fea
Goldilocks::Element newStateRoot[4];
string2fea(fr, NormalizeToNFormat(finalTrace.new_state_root, 64), newStateRoot);

// For all entries in read_write_addresses
unordered_map<string, InfoReadWrite>::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())
{
Expand Down
25 changes: 22 additions & 3 deletions src/main_sm/fork_4/main/full_tracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1026,6 +1026,14 @@ zkresult FullTracer::onFinishBatch(Context &ctx, const RomCommand &cmd)
// getVarFromCtx(ctx, true, "newNumBatch", auxScalar);
// finalTrace.new_batch_num = auxScalar.get_ui();

// Call fillInReadWriteAddresses
zkr = fillInReadWriteAddresses(ctx);
if (zkr != ZKR_SUCCESS)
{
zklog.error("FullTracer::onFinishBatch() failed calling fillInReadWriteAddresses()");
return zkr;
}

#ifdef LOG_FULL_TRACER
zklog.info("FullTracer::onFinishBatch() new_state_root=" + finalTrace.new_state_root);
#endif
Expand Down Expand Up @@ -1655,6 +1663,8 @@ zkresult FullTracer::addReadWriteAddress ( const Goldilocks::Element &address0,
gettimeofday(&t, NULL);
#endif

zkassert(!fr.isZero(key[0]) || !fr.isZero(key[1]) || !fr.isZero(key[2]) || !fr.isZero(key[3]));

// Get address
mpz_class address;
if (!fea2scalar(fr, address, address0, address1, address2, address3, address4, address5, address6, address7))
Expand Down Expand Up @@ -1689,6 +1699,10 @@ zkresult FullTracer::addReadWriteAddress ( const Goldilocks::Element &address0,
else
{
it->second.balance = value.get_str();
it->second.balanceKey[0]= key[0];
it->second.balanceKey[1]= key[1];
it->second.balanceKey[2]= key[2];
it->second.balanceKey[3]= key[3];
}
}
else if (keyType == SMT_KEY_NONCE)
Expand All @@ -1707,6 +1721,10 @@ zkresult FullTracer::addReadWriteAddress ( const Goldilocks::Element &address0,
else
{
it->second.nonce = value.get_str();
it->second.nonceKey[0]= key[0];
it->second.nonceKey[1]= key[1];
it->second.nonceKey[2]= key[2];
it->second.nonceKey[3]= key[3];
}
}

Expand All @@ -1721,13 +1739,14 @@ zkresult FullTracer::fillInReadWriteAddresses (Context &ctx)
{
zkresult zkr;

// Get new state root fea
Goldilocks::Element newStateRoot[4];
string2fea(fr, NormalizeToNFormat(finalTrace.new_state_root, 64), newStateRoot);

// For all entries in read_write_addresses
unordered_map<string, InfoReadWrite>::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())
{
Expand Down
25 changes: 22 additions & 3 deletions src/main_sm/fork_5/main/full_tracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,14 @@ zkresult FullTracer::onFinishBatch(Context &ctx, const RomCommand &cmd)
// getVarFromCtx(ctx, true, "newNumBatch", auxScalar);
// finalTrace.new_batch_num = auxScalar.get_ui();

// Call fillInReadWriteAddresses
zkr = fillInReadWriteAddresses(ctx);
if (zkr != ZKR_SUCCESS)
{
zklog.error("FullTracer::onFinishBatch() failed calling fillInReadWriteAddresses()");
return zkr;
}

#ifdef LOG_FULL_TRACER
zklog.info("FullTracer::onFinishBatch() new_state_root=" + finalTrace.new_state_root);
#endif
Expand Down Expand Up @@ -1718,6 +1726,8 @@ zkresult FullTracer::addReadWriteAddress ( const Goldilocks::Element &address0,
gettimeofday(&t, NULL);
#endif

zkassert(!fr.isZero(key[0]) || !fr.isZero(key[1]) || !fr.isZero(key[2]) || !fr.isZero(key[3]));

// Get address
mpz_class address;
if (!fea2scalar(fr, address, address0, address1, address2, address3, address4, address5, address6, address7))
Expand Down Expand Up @@ -1752,6 +1762,10 @@ zkresult FullTracer::addReadWriteAddress ( const Goldilocks::Element &address0,
else
{
it->second.balance = value.get_str();
it->second.balanceKey[0]= key[0];
it->second.balanceKey[1]= key[1];
it->second.balanceKey[2]= key[2];
it->second.balanceKey[3]= key[3];
}
}
else if (keyType == SMT_KEY_NONCE)
Expand All @@ -1770,6 +1784,10 @@ zkresult FullTracer::addReadWriteAddress ( const Goldilocks::Element &address0,
else
{
it->second.nonce = value.get_str();
it->second.nonceKey[0]= key[0];
it->second.nonceKey[1]= key[1];
it->second.nonceKey[2]= key[2];
it->second.nonceKey[3]= key[3];
}
}

Expand All @@ -1784,13 +1802,14 @@ zkresult FullTracer::fillInReadWriteAddresses (Context &ctx)
{
zkresult zkr;

// Get new state root fea
Goldilocks::Element newStateRoot[4];
string2fea(fr, NormalizeToNFormat(finalTrace.new_state_root, 64), newStateRoot);

// For all entries in read_write_addresses
unordered_map<string, InfoReadWrite>::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())
{
Expand Down
25 changes: 22 additions & 3 deletions src/main_sm/fork_6/main/full_tracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,14 @@ zkresult FullTracer::onFinishBatch(Context &ctx, const RomCommand &cmd)
// getVarFromCtx(ctx, true, "newNumBatch", auxScalar);
// finalTrace.new_batch_num = auxScalar.get_ui();

// Call fillInReadWriteAddresses
zkr = fillInReadWriteAddresses(ctx);
if (zkr != ZKR_SUCCESS)
{
zklog.error("FullTracer::onFinishBatch() failed calling fillInReadWriteAddresses()");
return zkr;
}

#ifdef LOG_FULL_TRACER
zklog.info("FullTracer::onFinishBatch() new_state_root=" + finalTrace.new_state_root);
#endif
Expand Down Expand Up @@ -1718,6 +1726,8 @@ zkresult FullTracer::addReadWriteAddress ( const Goldilocks::Element &address0,
gettimeofday(&t, NULL);
#endif

zkassert(!fr.isZero(key[0]) || !fr.isZero(key[1]) || !fr.isZero(key[2]) || !fr.isZero(key[3]));

// Get address
mpz_class address;
if (!fea2scalar(fr, address, address0, address1, address2, address3, address4, address5, address6, address7))
Expand Down Expand Up @@ -1752,6 +1762,10 @@ zkresult FullTracer::addReadWriteAddress ( const Goldilocks::Element &address0,
else
{
it->second.balance = value.get_str();
it->second.balanceKey[0]= key[0];
it->second.balanceKey[1]= key[1];
it->second.balanceKey[2]= key[2];
it->second.balanceKey[3]= key[3];
}
}
else if (keyType == SMT_KEY_NONCE)
Expand All @@ -1770,6 +1784,10 @@ zkresult FullTracer::addReadWriteAddress ( const Goldilocks::Element &address0,
else
{
it->second.nonce = value.get_str();
it->second.nonceKey[0]= key[0];
it->second.nonceKey[1]= key[1];
it->second.nonceKey[2]= key[2];
it->second.nonceKey[3]= key[3];
}
}

Expand All @@ -1784,13 +1802,14 @@ zkresult FullTracer::fillInReadWriteAddresses (Context &ctx)
{
zkresult zkr;

// Get new state root fea
Goldilocks::Element newStateRoot[4];
string2fea(fr, NormalizeToNFormat(finalTrace.new_state_root, 64), newStateRoot);

// For all entries in read_write_addresses
unordered_map<string, InfoReadWrite>::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())
{
Expand Down
Loading

0 comments on commit fed1956

Please sign in to comment.