Skip to content

Commit

Permalink
chore: cleanup phases in avm witgen (#10432)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbanks12 authored Dec 5, 2024
1 parent 65c91b6 commit bd64cc5
Show file tree
Hide file tree
Showing 6 changed files with 641 additions and 572 deletions.
1,176 changes: 605 additions & 571 deletions barretenberg/cpp/src/barretenberg/vm/avm/trace/execution.cpp

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions barretenberg/cpp/src/barretenberg/vm/avm/trace/execution.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ class Execution {
ExecutionHints const& execution_hints,
bool apply_end_gas_assertions = false);

static AvmError execute_enqueued_call(AvmTraceBuilder& trace_builder,
PublicCallRequest& public_call_request,
std::vector<FF>& returndata);

// For testing purposes only.
static void set_trace_builder_constructor(TraceBuilderConstructor constructor)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ struct PublicCallRequest {
*/
bool is_static_call = false;
FF args_hash{};
inline bool is_empty() const
{
return msg_sender == 0 && contract_address == 0 && function_selector == 0 && !is_static_call && args_hash == 0;
}
};

inline void read(uint8_t const*& it, PublicCallRequest& public_call_request)
Expand Down
27 changes: 27 additions & 0 deletions barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,33 @@ void AvmTraceBuilder::rollback_to_non_revertible_checkpoint()
merkle_tree_trace_builder.rollback_to_non_revertible_checkpoint();
}

std::vector<uint8_t> AvmTraceBuilder::get_bytecode(const FF contract_address, bool check_membership)
{
// uint32_t clk = 0;
// auto clk = static_cast<uint32_t>(main_trace.size()) + 1;

// Find the bytecode based on contract address of the public call request
const AvmContractBytecode bytecode_hint =
*std::ranges::find_if(execution_hints.all_contract_bytecode, [contract_address](const auto& contract) {
return contract.contract_instance.address == contract_address;
});
if (check_membership) {
// NullifierReadTreeHint nullifier_read_hint = bytecode_hint.contract_instance.membership_hint;
//// hinted nullifier should match the specified contract address
// ASSERT(nullifier_read_hint.low_leaf_preimage.nullifier == contract_address);
// bool is_member = merkle_tree_trace_builder.perform_nullifier_read(clk,
// nullifier_read_hint.low_leaf_preimage,
// nullifier_read_hint.low_leaf_index,
// nullifier_read_hint.low_leaf_sibling_path);
//// TODO(dbanks12): handle non-existent bytecode
//// if the contract address nullifier is hinted as "exists", the membership check should agree
// ASSERT(is_member);
}

vinfo("Found bytecode for contract address: ", contract_address);
return bytecode_hint.bytecode;
}

void AvmTraceBuilder::insert_private_state(const std::vector<FF>& siloed_nullifiers,
[[maybe_unused]] const std::vector<FF>& siloed_note_hashes)
{
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 @@ -226,6 +226,7 @@ class AvmTraceBuilder {

void checkpoint_non_revertible_state();
void rollback_to_non_revertible_checkpoint();
std::vector<uint8_t> get_bytecode(const FF contract_address, bool check_membership = false);
void insert_private_state(const std::vector<FF>& siloed_nullifiers, const std::vector<FF>& siloed_note_hashes);

// These are used for testing only.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,6 @@ contract AvmTest {
#[public]
fn n_storage_writes(num: u32) {
for i in 0..num {
context.push_nullifier(i as Field);
storage.map.at(AztecAddress::from_field(i as Field)).write(i);
}
}
Expand Down

0 comments on commit bd64cc5

Please sign in to comment.