Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
public_tx_simulation_tester.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <memory>
5#include <optional>
6#include <span>
7#include <stack>
8#include <string>
9#include <unordered_map>
10#include <vector>
11
17
18namespace bb::avm2::testing {
19
20// In-memory contract database for tests. Holds contract classes and instances added through
21// pseudo-deployments and serves them to the simulator's raw contract DB interface.
48
49// A deployed (custom-bytecode) contract.
55
56// A public call to enqueue in a simulated transaction.
59 std::vector<FF> calldata = {};
60 bool is_static_call = false;
61};
62
63// Owns an in-process world state and contract DB, supports pseudo-deployments of custom bytecode
64// (populating the merkle trees and contract DB), and simulates public transactions through the
65// C++ AVM simulator. Each instance manages its own temporary world-state database, which is
66// removed on destruction.
68 public:
69 // The default msg_sender / fee_payer used for deployments and enqueued calls.
71
74
79
80 // Pseudo-deploys a contract from packed bytecode: derives its class id/instance/address,
81 // registers them in the contract DB, and inserts the deployment nullifier into the world
82 // state so the simulator can resolve the contract. The salt differentiates instances that
83 // share the same bytecode (and therefore the same class id).
85
86 // World-state helpers for seeding "warm" tree reads.
87 void set_public_storage(const AztecAddress& address, const FF& slot, const FF& value);
88 void insert_siloed_nullifier(const FF& siloed_nullifier);
89 void append_note_hash(const FF& note_hash);
90 void append_l1_to_l2_message(const FF& message);
91
92 // Simulates a public tx with the given app-logic enqueued calls, funding the fee payer
93 // up front. The simulation runs on a fresh world-state checkpoint that is reverted
94 // afterwards, so deployments persist across calls but per-tx writes do not.
96 const PublicSimulatorConfig& config = default_config());
97
99
102
103 private:
105 void fund_fee_payer(const AztecAddress& fee_payer);
106
107 std::string data_dir;
109 uint64_t fork_id = 0;
111 uint64_t tx_count = 0;
112};
113
114} // namespace bb::avm2::testing
world_state::WorldStateRevision current_revision() const
static AztecAddress default_sender()
PublicTxSimulationTester.
PublicTxSimulationTester & operator=(const PublicTxSimulationTester &)=delete
PublicTxSimulationTester & operator=(PublicTxSimulationTester &&)=delete
void set_public_storage(const AztecAddress &address, const FF &slot, const FF &value)
TxSimulationResult simulate_tx(const std::vector< TestEnqueuedCall > &app_calls, const PublicSimulatorConfig &config=default_config())
PublicTxSimulationTester(PublicTxSimulationTester &&)=delete
std::unique_ptr< world_state::WorldState > ws
DeployedContract deploy_contract(std::span< const uint8_t > bytecode, const FF &salt=0)
PublicTxSimulationTester(const PublicTxSimulationTester &)=delete
void add_contract_instance(const AztecAddress &address, const ContractInstance &instance)
std::optional< ContractClass > get_contract_class(const ContractClassId &class_id) const override
std::unordered_map< AztecAddress, ContractInstance > contract_instances
std::unordered_map< ContractClassId, ContractClassWithCommitment > contract_classes
void add_contracts(const ContractDeploymentData &contract_deployment_data) override
std::optional< std::string > get_debug_function_name(const AztecAddress &address, const FunctionSelector &selector) const override
void add_contract_class(const ContractClassWithCommitment &contract_class)
std::optional< FF > get_bytecode_commitment(const ContractClassId &class_id) const override
Holds the Merkle trees responsible for storing the state of the Aztec protocol.
std::vector< uint8_t > bytecode
AvmFlavorSettings::FF FF
Definition field.hpp:10
FF ContractClassId
FF FunctionSelector
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
std::unordered_map< ContractClassId, ContractClassWithCommitment > contract_classes
std::unordered_map< AztecAddress, ContractInstance > contract_instances