Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
context_helper.cpp
Go to the documentation of this file.
1#include "context_helper.hpp"
2
16
18
19using namespace bb::avm2::simulation;
20
21GadgetFuzzerContextHelper::GadgetFuzzerContextHelper(AztecAddress contract_address, bool is_static, uint32_t start_clk)
22 : execution_id_manager(start_clk)
25 , greater_than(field_gt, range_check, greater_than_emitter)
26 , memory_provider(range_check, execution_id_manager, memory_emitter)
29 , indexed_tree_check_written_slots(
30 poseidon2, merkle_check, field_gt, DOM_SEP__WRITTEN_SLOTS_MERKLE, indexed_tree_check_emitter)
31 , indexed_tree_check_retrieved_bytecodes(
33 , written_public_data_slots_tree_check(indexed_tree_check_written_slots, build_public_data_slots_tree())
34 , retrieved_bytecodes_tree_check(indexed_tree_check_retrieved_bytecodes, build_retrieved_bytecodes_tree())
35
36{
39 hints.tx = create_default_tx(contract_address, contract_address, {}, FF(0), is_static, GAS_LIMIT);
40
43
46
51 InternalCallStackManagerProvider internal_call_stack_manager_provider(internal_call_stack_emitter);
61
64 mem_provider,
65 calldata_hashing_provider,
66 internal_call_stack_manager_provider,
72}
73
74// A lighter version of ContextProvider::make_enqueued_context
76 AztecAddress msg_sender,
77 bool is_static,
78 FF transaction_fee,
80 Gas gas_limit,
81 Gas gas_used,
82 TransactionPhase phase)
83{
85 // Note: not incremented between contexts
86 uint32_t context_id = context_provider->get_next_context_id();
89 address,
90 msg_sender,
91 transaction_fee,
92 is_static,
93 gas_limit,
94 gas_used,
97 memory_provider.make_memory(static_cast<uint16_t>(context_id)),
103 phase,
104 calldata);
105}
106
107// A lighter version of ContextProvider::make_nested_context
109 AztecAddress address, AztecAddress msg_sender, ContextInterface& parent_context, bool is_static, Gas gas_limit)
110{
111
112 HintedRawMerkleDB raw_merkle_db(hints);
115 // TODO(MW): Using below causes segfault (probably stack too deep) with external call gadget fuzzer
116 // auto merkle_db = make_empty_merkle_db();
117 // Note: not incremented between contexts
118 uint32_t context_id = context_provider->get_next_context_id();
121 parent_context.get_address(),
122 msg_sender,
123 parent_context.get_transaction_fee(),
124 is_static,
125 gas_limit,
126 parent_context.get_globals(),
128 memory_provider.make_memory(static_cast<uint16_t>(context_id)),
134 parent_context.get_phase(),
135 parent_context,
136 0,
137 0);
138}
139
148} // namespace bb::avm2::fuzzing
GreaterThan greater_than
const Gas GAS_LIMIT
Definition constants.hpp:40
#define DOM_SEP__WRITTEN_SLOTS_MERKLE
#define DOM_SEP__RETRIEVED_BYTECODES_MERKLE
EventEmitter< Poseidon2PermutationMemoryEvent > perm_mem_event_emitter
EventEmitter< Poseidon2PermutationEvent > perm_event_emitter
EventEmitter< Poseidon2HashEvent > hash_event_emitter
FieldGreaterThan field_gt
EventEmitter< simulation::MerkleCheckEvent > merkle_check_emitter
RetrievedBytecodesTreeCheck retrieved_bytecodes_tree_check
EventEmitter< simulation::FieldGreaterThanEvent > field_gt_emitter
EventEmitter< simulation::RangeCheckEvent > range_check_emitter
BytecodeHasher bytecode_hasher
StrictMock< MockHighLevelMerkleDB > merkle_db
StrictMock< MockContractDB > contract_db
StrictMock< MockContractInstanceManager > contract_instance_manager
EventEmitter< BytecodeRetrievalEvent > bytecode_retrieval_emitter
EventEmitter< InternalCallStackEvent > internal_call_stack_emitter
RetrievedBytecodesTreeCheck retrieved_bytecodes_tree_check
EventEmitter< CalldataEvent > calldata_event_emitter
GadgetFuzzerContextHelper(AztecAddress contract_address=AztecAddress(0), bool is_static=false, uint32_t start_clk=0)
std::unique_ptr< simulation::ContextInterface > make_nested_fuzzing_context(AztecAddress address, AztecAddress msg_sender, ContextInterface &parent_context, bool is_static=false, Gas gas_limit=GAS_LIMIT)
std::unique_ptr< TxBytecodeManager > tx_bytecode_manager
EventEmitter< BytecodeDecompositionEvent > bytecode_decomposition_emitter
EventEmitter< ContractInstanceRetrievalEvent > contract_instance_retrieval_emitter
EventEmitter< BytecodeHashingEvent > bytecode_hashing_emitter
std::unique_ptr< simulation::ContextInterface > make_enqueued_fuzzing_context(AztecAddress address=AztecAddress(0), AztecAddress msg_sender=AztecAddress(0), bool is_static=false, FF transaction_fee=FF(0), std::span< const FF > calldata={}, Gas gas_limit=GAS_LIMIT, Gas gas_used=GAS_USED_BY_PRIVATE, TransactionPhase phase=TransactionPhase::APP_LOGIC)
WrittenPublicDataSlotsTreeCheck written_public_data_slots_tree_check
EventEmitter< UpdateCheckEvent > update_check_emitter
std::unique_ptr< simulation::ContextProvider > context_provider
DeduplicatingEventEmitter< InstructionFetchingEvent > instruction_fetching_emitter
virtual const FF & get_transaction_fee() const =0
virtual const GlobalVariables & get_globals() const =0
virtual const AztecAddress & get_address() const =0
virtual TransactionPhase get_phase() const =0
std::unique_ptr< MemoryInterface > make_memory(uint16_t space_id) override
Definition memory.hpp:57
ExecutionIdManager execution_id_manager
HintedRawMerkleDB base_merkle_db
AVM range check gadget for witness generation.
RetrievedBytecodesTree build_retrieved_bytecodes_tree()
WrittenPublicDataSlotsTree build_public_data_slots_tree()
AvmFlavorSettings::FF FF
Definition field.hpp:10
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
uint32_t context_id
Tx create_default_tx(const AztecAddress &contract_address, const AztecAddress &sender_address, const std::vector< FF > &calldata, const FF &transaction_fee, bool is_static_call, const Gas &gas_limit)
GlobalVariables create_default_globals()
Definition simulator.cpp:68
std::vector< FF > nullifiers
Definition avm_io.hpp:319
GlobalVariables global_variables
Definition avm_io.hpp:359
ProtocolContracts protocol_contracts
Definition avm_io.hpp:362
AccumulatedData non_revertible_accumulated_data
Definition avm_io.hpp:335
NiceMock< MockWrittenPublicDataSlotsTreeCheck > written_public_data_slots_tree_check