Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
concrete_dbs.hpp
Go to the documentation of this file.
1#pragma once
2
14
15namespace bb::avm2::simulation {
16
17// Generates events.
18class ContractDB final : public ContractDBInterface {
19 public:
29
30 // Gets an instance from the DB and proves address derivation from the result.
31 // This does NOT prove that the address is in the nullifier tree.
32 // Silo the address and use the MerkleDB to prove that.
34 // Gets a class from the DB and proves class id derivation from the result.
35 // This does NOT prove that the class id is in the nullifier tree.
36 // Silo the class id and use the MerkleDB to prove that.
38 // Gets the bytecode commitment for a contract class ID.
40 // Gets the debug function name for a contract address and function selector.
42 const FunctionSelector& selector) const override;
43
44 void add_contracts(const ContractDeploymentData& contract_deployment_data) override;
45
49
50 private:
55};
56
57// Generates events.
59 public:
73
74 // Unconstrained.
75 TreeStates get_tree_state() const override;
76 void create_checkpoint() override;
77 void commit_checkpoint() override;
78 void revert_checkpoint() override;
79 uint32_t get_checkpoint_id() const override;
80
81 // Constrained.
82 FF storage_read(const AztecAddress& contract_address, const FF& slot) const override;
84 const FF& slot,
85 const FF& value,
86 bool is_protocol_write) override;
87 bool was_storage_written(const AztecAddress& contract_address, const FF& slot) const override;
88
89 bool nullifier_exists(const AztecAddress& contract_address, const FF& nullifier) const override;
90 bool siloed_nullifier_exists(const FF& nullifier) const override;
91 // Throws if the nullifier already exists, but still performs a membership proof.
92 void nullifier_write(const AztecAddress& contract_address, const FF& nullifier) override;
93 void siloed_nullifier_write(const FF& nullifier) override;
94
95 // Returns a unique note hash stored in the tree at leaf_index.
96 bool note_hash_exists(uint64_t leaf_index, const FF& unique_note_hash) const override;
97 void note_hash_write(const AztecAddress& contract_address, const FF& note_hash) override;
98 void siloed_note_hash_write(const FF& note_hash) override;
99 void unique_note_hash_write(const FF& note_hash) override;
100 bool l1_to_l2_msg_exists(uint64_t leaf_index, const FF& msg_hash) const override;
101
102 void pad_trees() override;
103
104 void add_checkpoint_listener(CheckpointNotifiable& listener) { checkpoint_listeners.push_back(&listener); }
105
107
108 private:
111
113 // TODO: when you have a merkle gadget, consider marking it "mutable" so that read can be const.
114 // It's usually ok for mutexes but a gadget is big...
120
121 // Set for semantics.
122 using Slot = FF;
124
125 // Stack of tree counters for checkpoints. Starts empty.
127 { { .note_hash_counter = 0, .nullifier_counter = 0, .l2_to_l1_msg_counter = 0 } }
128 };
129};
130
131} // namespace bb::avm2::simulation
std::shared_ptr< Napi::ThreadSafeFunction > add_contracts
Interface for a checkpoint notifiable.
Definition db.hpp:131
std::optional< std::string > get_debug_function_name(const AztecAddress &address, const FunctionSelector &selector) const override
ContractDBInterface & raw_contract_db
ClassIdDerivationInterface & class_id_derivation
ContractDB(ContractDBInterface &raw_contract_db, AddressDerivationInterface &address_derivation, ClassIdDerivationInterface &class_id_derivation, const ProtocolContracts &protocol_contracts)
AddressDerivationInterface & address_derivation
const ProtocolContracts & protocol_contracts
std::optional< ContractClass > get_contract_class(const ContractClassId &class_id) const override
std::optional< FF > get_bytecode_commitment(const ContractClassId &class_id) const override
void add_checkpoint_listener(CheckpointNotifiable &listener)
WrittenPublicDataSlotsInterface & written_public_data_slots
void note_hash_write(const AztecAddress &contract_address, const FF &note_hash) override
std::vector< CheckpointNotifiable * > checkpoint_listeners
std::stack< TreeCounters > tree_counters_stack
LowLevelMerkleDBInterface & as_unconstrained() const override
NoteHashTreeCheckInterface & note_hash_tree_check
LowLevelMerkleDBInterface & raw_merkle_db
MerkleDB(LowLevelMerkleDBInterface &raw_merkle_db, PublicDataTreeCheckInterface &public_data_tree_check, NullifierTreeCheckInterface &nullifier_tree_check, NoteHashTreeCheckInterface &note_hash_tree_check, WrittenPublicDataSlotsInterface &written_public_data_slots, L1ToL2MessageTreeCheckInterface &l1_to_l2_msg_tree_check)
void unique_note_hash_write(const FF &note_hash) override
void nullifier_write_internal(std::optional< AztecAddress > contract_address, const FF &nullifier)
TreeStates get_tree_state() const override
bool was_storage_written(const AztecAddress &contract_address, const FF &slot) const override
NullifierTreeCheckInterface & nullifier_tree_check
uint32_t get_checkpoint_id() const override
bool note_hash_exists(uint64_t leaf_index, const FF &unique_note_hash) const override
void siloed_note_hash_write(const FF &note_hash) override
void siloed_nullifier_write(const FF &nullifier) override
FF storage_read(const AztecAddress &contract_address, const FF &slot) const override
bool siloed_nullifier_exists(const FF &nullifier) const override
PublicDataTreeCheckInterface & public_data_tree_check
void storage_write(const AztecAddress &contract_address, const FF &slot, const FF &value, bool is_protocol_write) override
bool nullifier_exists_internal(std::optional< AztecAddress > contract_address, const FF &nullifier) const
void nullifier_write(const AztecAddress &contract_address, const FF &nullifier) override
L1ToL2MessageTreeCheckInterface & l1_to_l2_msg_tree_check
bool l1_to_l2_msg_exists(uint64_t leaf_index, const FF &msg_hash) const override
FF ContractClassId
FF FunctionSelector
AvmFlavorSettings::FF FF
Definition field.hpp:10
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13