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
39 private:
44};
45
46// Generates events.
48 public:
62
63 // Unconstrained.
64 TreeStates get_tree_state() const override;
65 void create_checkpoint() override;
66 void commit_checkpoint() override;
67 void revert_checkpoint() override;
68 uint32_t get_checkpoint_id() const override;
69
70 // Constrained.
71 FF storage_read(const AztecAddress& contract_address, const FF& slot) const override;
73 const FF& slot,
74 const FF& value,
75 bool is_protocol_write) override;
76 bool was_storage_written(const AztecAddress& contract_address, const FF& slot) const override;
77
78 bool nullifier_exists(const AztecAddress& contract_address, const FF& nullifier) const override;
79 bool siloed_nullifier_exists(const FF& nullifier) const override;
80 // Throws if the nullifier already exists, but still performs a membership proof.
81 void nullifier_write(const AztecAddress& contract_address, const FF& nullifier) override;
82 void siloed_nullifier_write(const FF& nullifier) override;
83
84 // Returns a unique note hash stored in the tree at leaf_index.
85 bool note_hash_exists(uint64_t leaf_index, const FF& unique_note_hash) const override;
86 void note_hash_write(const AztecAddress& contract_address, const FF& note_hash) override;
87 void siloed_note_hash_write(const FF& note_hash) override;
88 void unique_note_hash_write(const FF& note_hash) override;
89 bool l1_to_l2_msg_exists(uint64_t leaf_index, const FF& msg_hash) const override;
90
91 void pad_trees() override;
92
93 void add_checkpoint_listener(CheckpointNotifiable& listener) { checkpoint_listeners.push_back(&listener); }
94
96
97 private:
100
102 // TODO: when you have a merkle gadget, consider marking it "mutable" so that read can be const.
103 // It's usually ok for mutexes but a gadget is big...
109
110 // Set for semantics.
111 using Slot = FF;
113
114 // Stack of tree counters for checkpoints. Starts empty.
116 { { .note_hash_counter = 0, .nullifier_counter = 0, .l2_to_l1_msg_counter = 0 } }
117 };
118};
119
120} // namespace bb::avm2::simulation
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
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
AvmFlavorSettings::FF FF
Definition field.hpp:10
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13