Skip to content

Commit

Permalink
fix: add tree snapshots to ctx
Browse files Browse the repository at this point in the history
  • Loading branch information
IlyasRidhuan committed Dec 18, 2024
1 parent 263eaad commit c37b739
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class AvmMerkleTreeTraceBuilder {
FF compute_public_tree_leaf_slot(uint32_t clk, FF contract_address, FF leaf_index);

TreeSnapshots& get_tree_snapshots() { return tree_snapshots; }
void set_tree_snapshots(TreeSnapshots& tree_snapshots) { this->tree_snapshots = tree_snapshots; }

// Public Data Tree
bool perform_storage_read(uint32_t clk,
Expand Down
7 changes: 6 additions & 1 deletion barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3754,7 +3754,8 @@ AvmError AvmTraceBuilder::constrain_external_call(OpCode opcode,

// We push the current ext call ctx onto the stack and initialize a new one
current_ext_call_ctx.last_pc = pc;
current_ext_call_ctx.success_offset = resolved_success_offset,
current_ext_call_ctx.success_offset = resolved_success_offset;
current_ext_call_ctx.tree_snapshot = merkle_tree_trace_builder.get_tree_snapshots();
external_call_ctx_stack.emplace(current_ext_call_ctx);

// Ext Ctx setup
Expand All @@ -3763,6 +3764,7 @@ AvmError AvmTraceBuilder::constrain_external_call(OpCode opcode,

set_call_ptr(static_cast<uint8_t>(clk));

<<<<<<< HEAD
// Don't try allocating more than the gas that is actually left
const auto l2_gas_allocated_to_nested_call =
std::min(static_cast<uint32_t>(read_gas_l2.val), gas_trace_builder.get_l2_gas_left());
Expand All @@ -3781,6 +3783,7 @@ AvmError AvmTraceBuilder::constrain_external_call(OpCode opcode,
.l2_gas_left = l2_gas_allocated_to_nested_call,
.da_gas_left = da_gas_allocated_to_nested_call,
.internal_return_ptr_stack = {},
.tree_snapshot = {},
};

allocate_gas_for_call(l2_gas_allocated_to_nested_call, da_gas_allocated_to_nested_call);
Expand Down Expand Up @@ -3940,6 +3943,7 @@ ReturnDataError AvmTraceBuilder::op_return(uint8_t indirect, uint32_t ret_offset
set_call_ptr(static_cast<uint8_t>(current_ext_call_ctx.context_id));
write_to_memory(
current_ext_call_ctx.success_offset, /*success=*/FF::one(), AvmMemoryTag::U1, /*fix_pc=*/false);
current_ext_call_ctx.tree_snapshot = merkle_tree_trace_builder.get_tree_snapshots();
}
}

Expand Down Expand Up @@ -4079,6 +4083,7 @@ ReturnDataError AvmTraceBuilder::op_revert(uint8_t indirect, uint32_t ret_offset
set_call_ptr(static_cast<uint8_t>(current_ext_call_ctx.context_id));
write_to_memory(
current_ext_call_ctx.success_offset, /*success=*/FF::one(), AvmMemoryTag::U1, /*fix_pc=*/false);
merkle_tree_trace_builder.set_tree_snapshots(current_ext_call_ctx.tree_snapshot);
}
}

Expand Down
1 change: 1 addition & 0 deletions barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ class AvmTraceBuilder {
uint32_t l2_gas_left; // as of start of latest nested call
uint32_t da_gas_left; // as of start of latest nested call
std::stack<uint32_t> internal_return_ptr_stack;
TreeSnapshots tree_snapshot; // This is the tree state at the time of the call
};

ExtCallCtx current_ext_call_ctx{};
Expand Down

0 comments on commit c37b739

Please sign in to comment.