Skip to content

Commit

Permalink
fix: Initialize side_effect_counter based on the initial value passed…
Browse files Browse the repository at this point in the history
… to builder (#7017)
  • Loading branch information
jeanmon authored Jun 12, 2024
1 parent 1a198b8 commit 46d166b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
14 changes: 11 additions & 3 deletions barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ AvmTraceBuilder::AvmTraceBuilder(VmPublicInputs public_inputs,
// NOTE: we initialise the environment builder here as it requires public inputs
: kernel_trace_builder(std::move(public_inputs))
, side_effect_counter(side_effect_counter)
, initial_side_effect_counter(side_effect_counter)
, execution_hints(std::move(execution_hints))
{
main_trace.reserve(AVM_TRACE_SIZE);
Expand Down Expand Up @@ -4382,9 +4383,16 @@ std::vector<Row> AvmTraceBuilder::finalize(uint32_t min_trace_size, bool range_c
// 4. Whenever we hit the last row, we zero all write_offsets such that the shift relation will succeed
std::vector<AvmKernelTraceBuilder::KernelTraceEntry> kernel_trace = kernel_trace_builder.finalize();
size_t kernel_padding_main_trace_bottom = 1;
for (size_t i = 0; i < kernel_trace.size(); i++) {
auto const& src = kernel_trace.at(i);
// check the clock and iterate through the main trace until we hit the clock

// Index 1 corresponds here to the first active row of the main execution trace, as
// we already prepended the extra row for shifted columns. Therefore, initialization
// of side_effect_counter occurs occurs on this row.
main_trace.at(1).avm_kernel_side_effect_counter = initial_side_effect_counter;

// External loop iterates over the kernel entries which are sorted by increasing clk.
// Internal loop iterates to fill the gap in main trace between each kernel entries.
for (auto const& src : kernel_trace) {
// Check the clock and iterate through the main trace until we hit the clock
auto clk = src.clk;

// Until the next kernel changing instruction is encountered we set all of the values of the offset arrays
Expand Down
3 changes: 2 additions & 1 deletion barretenberg/cpp/src/barretenberg/vm/avm_trace/avm_trace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,10 @@ class AvmTraceBuilder {
0; // After a nested call, it should be initialized with MAX_SIZE_INTERNAL_STACK * call_ptr
uint8_t call_ptr = 0;

// Side effect counter will incremenent when any state writing values are
// Side effect counter will increment when any state writing values are
// encountered
uint32_t side_effect_counter = 0;
uint32_t initial_side_effect_counter; // This one is constant.
uint32_t external_call_counter = 0;

// Execution hints aid witness solving for instructions that require auxiliary information to construct
Expand Down

0 comments on commit 46d166b

Please sign in to comment.