Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
contract_instance_manager.cpp
Go to the documentation of this file.
2
5
6namespace bb::avm2::simulation {
7
21
34{
35 // If the instance is found, we validate that with a nullifier check, perform address derivation, and update
36 // checking. If it is not found, we validate its NON-membership with a nullifier check, and skip the rest.
37 // Note: this call to get_contract_instance performs address derivation.
39
40 const auto& tree_state = merkle_db.get_tree_state();
41 // If this is a canonical address
43 // Handle protocol contract addresses
45 assert(derived_address.has_value() == maybe_instance.has_value() &&
46 "Derived address should be found if the instance was retrieved and vice versa");
47 const ContractInstance& instance = maybe_instance.value();
48 event_emitter.emit({
49 .address = contract_address,
50 .contract_instance = maybe_instance.value_or<ContractInstance>({}),
51 // Tree context
52 .nullifier_tree_root = tree_state.nullifierTree.tree.root,
53 .public_data_tree_root = tree_state.publicDataTree.tree.root,
54 .exists = derived_address.has_value(),
55 .is_protocol_contract = true,
56 });
57
58 return instance;
59 }
60
62 // Emit error event
63 event_emitter.emit({
64 .address = contract_address,
65 .contract_instance = {}, // Empty instance for error case
66 .nullifier_tree_root = tree_state.nullifierTree.tree.root,
67 .public_data_tree_root = tree_state.publicDataTree.tree.root,
68 .deployment_nullifier = contract_address,
69 .exists = false, // Nullifier not found!
70 });
71
72 return std::nullopt;
73 }
74
75 assert(maybe_instance.has_value() && "Contract instance should be found if nullifier exists");
76 const ContractInstance& instance = maybe_instance.value();
77
78 // Validate that the contract instance is the latest if there have been any updates.
79 update_check.check_current_class_id(contract_address, instance);
80
81 event_emitter.emit({
82 .address = contract_address,
83 .contract_instance = instance,
84 // Tree context
85 .nullifier_tree_root = tree_state.nullifierTree.tree.root,
86 .public_data_tree_root = tree_state.publicDataTree.tree.root,
87 .deployment_nullifier = contract_address, // Contract address nullifier
88 .exists = true, // Nullifier found!
89 });
90
91 return instance;
92}
93
94} // namespace bb::avm2::simulation
#define MAX_PROTOCOL_CONTRACTS
#define CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS
StrictMock< MockHighLevelMerkleDB > merkle_db
StrictMock< MockContractDB > contract_db
virtual std::optional< ContractInstance > get_contract_instance(const AztecAddress &address) const =0
ContractInstanceManager(ContractDBInterface &contract_db, HighLevelMerkleDBInterface &merkle_db, UpdateCheckInterface &update_check, FieldGreaterThanInterface &ff_gt, const ProtocolContracts &protocol_contracts, EventEmitterInterface< ContractInstanceRetrievalEvent > &event_emitter)
std::optional< ContractInstance > get_contract_instance(const FF &contract_address) override
Retrieves a contract instance from the contract database.
EventEmitterInterface< ContractInstanceRetrievalEvent > & event_emitter
virtual bool nullifier_exists(const AztecAddress &contract_address, const FF &nullifier) const =0
virtual TreeStates get_tree_state() const =0
EventEmitter< DataCopyEvent > event_emitter
std::optional< AztecAddress > get_derived_address(const ProtocolContracts &protocol_contracts, const AztecAddress &canonical_address)
AvmFlavorSettings::FF FF
Definition field.hpp:10
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13