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
21 // public data tree counter is tracked via the written public data slots tree
22
23 bool operator==(const TreeCounters& other) const = default;
24};
25
26// Generates events.
27class ContractDB final : public ContractDBInterface {
28 public:
36
37 // Gets an instance from the DB and proves address derivation from the result.
38 // This does NOT prove that the address is in the nullifier tree.
39 // Silo the address and use the MerkleDB to prove that.
41 // Gets a class from the DB and proves class id derivation from the result.
42 // This does NOT prove that the class id is in the nullifier tree.
43 // Silo the class id and use the MerkleDB to prove that.
45
46 private:
50 // TODO: EventEmitters.
51};
52
53// Generates events.
55 public:
69
70 // Unconstrained.
71 TreeStates get_tree_state() const override;
72 void create_checkpoint() override;
73 void commit_checkpoint() override;
74 void revert_checkpoint() override;
75 uint32_t get_checkpoint_id() const override;
76
77 // Constrained.
78 FF storage_read(const AztecAddress& contract_address, const FF& slot) const override;
80 const FF& slot,
81 const FF& value,
82 bool is_protocol_write) override;
83 bool was_storage_written(const AztecAddress& contract_address, const FF& slot) const override;
84
85 bool nullifier_exists(const AztecAddress& contract_address, const FF& nullifier) const override;
86 bool siloed_nullifier_exists(const FF& nullifier) const override;
87 // Returns false if the nullifier already exists, performing a membership proof instead.
88 bool nullifier_write(const AztecAddress& contract_address, const FF& nullifier) override;
89 bool siloed_nullifier_write(const FF& nullifier) override;
90
91 // Returns a unique note hash stored in the tree at leaf_index.
92 bool note_hash_exists(uint64_t leaf_index, const FF& unique_note_hash) const override;
93 void note_hash_write(const AztecAddress& contract_address, const FF& note_hash) override;
94 void siloed_note_hash_write(const FF& note_hash) override;
95 void unique_note_hash_write(const FF& note_hash) override;
96 bool l1_to_l2_msg_exists(uint64_t leaf_index, const FF& msg_hash) const override;
97
98 void pad_trees() override;
99
100 void add_checkpoint_listener(CheckpointNotifiable& listener) { checkpoint_listeners.push_back(&listener); }
101
103
104 private:
107
109 // TODO: when you have a merkle gadget, consider marking it "mutable" so that read can be const.
110 // It's usually ok for mutexes but a gadget is big...
116
117 // Set for semantics.
118 using Slot = FF;
120
121 // Stack of tree counters for checkpoints. Starts empty.
123 { { .note_hash_counter = 0, .nullifier_counter = 0, .l2_to_l1_msg_counter = 0 } }
124 };
125};
126
127} // namespace bb::avm2::simulation
ContractDBInterface & raw_contract_db
ClassIdDerivationInterface & class_id_derivation
ContractDB(ContractDBInterface &raw_contract_db, AddressDerivationInterface &address_derivation, ClassIdDerivationInterface &class_id_derivation)
AddressDerivationInterface & address_derivation
std::optional< ContractClass > get_contract_class(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
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 nullifier_write_internal(std::optional< AztecAddress > contract_address, const FF &nullifier)
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
FF storage_read(const AztecAddress &contract_address, const FF &slot) const override
bool siloed_nullifier_exists(const FF &nullifier) const override
bool nullifier_write(const AztecAddress &contract_address, const FF &nullifier) 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
bool siloed_nullifier_write(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
AvmFlavorSettings::FF FF
Definition field.hpp:10
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
bool operator==(const TreeCounters &other) const =default