Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
db.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <optional>
4#include <span>
5
14
15namespace bb::avm2::simulation {
16
18 public:
19 virtual ~ContractDBInterface() = default;
20
25 const FunctionSelector& selector) const = 0;
26
27 virtual void add_contracts(const ContractDeploymentData& contract_deployment_data) = 0;
28
29 virtual void create_checkpoint() = 0;
30 virtual void commit_checkpoint() = 0;
31 virtual void revert_checkpoint() = 0;
32};
33
34// Aliases.
41template <typename LeafValueType>
43
44// The sibling path and root after the insertion.
49
50// Low level access to a merkle db. In general these will not be constrained.
52 public:
53 virtual ~LowLevelMerkleDBInterface() = default;
54
55 virtual TreeSnapshots get_tree_roots() const = 0;
56
57 virtual SiblingPath get_sibling_path(MerkleTreeId tree_id, index_t leaf_index) const = 0;
59 // Returns the value if it exists, 0 otherwise.
60 virtual FF get_leaf_value(MerkleTreeId tree_id, index_t leaf_index) const = 0;
61 // We don't template the preimage methods because templated methods cannot be virtual.
64
66 const PublicDataLeafValue& leaf_value) = 0;
68 const NullifierLeafValue& leaf_value) = 0;
69
70 // todo(ilyas): does this need to be a vector of appendLeafResult? We should only care abou the end of appendings
72
73 virtual void pad_tree(MerkleTreeId tree_id, size_t num_leaves) = 0;
74
75 virtual void create_checkpoint() = 0;
76 virtual void commit_checkpoint() = 0;
77 virtual void revert_checkpoint() = 0;
78 // Returns the id of the current checkpoint.
79 // This is a unique id for the lifetime of the db.
80 virtual uint32_t get_checkpoint_id() const = 0;
81};
82
83class NullifierCollisionException : public std::runtime_error {
84 public:
85 NullifierCollisionException(const std::string& message)
86 : std::runtime_error(message)
87 {}
88};
89
90// High level access to a merkle db. In general these will be constrained.
92 public:
93 virtual ~HighLevelMerkleDBInterface() = default;
94
95 virtual TreeStates get_tree_state() const = 0;
96
97 virtual FF storage_read(const AztecAddress& contract_address, const FF& slot) const = 0;
99 const FF& slot,
100 const FF& value,
101 bool is_protocol_write) = 0;
102 virtual bool was_storage_written(const AztecAddress& contract_address, const FF& slot) const = 0;
103
104 virtual bool nullifier_exists(const AztecAddress& contract_address, const FF& nullifier) const = 0;
105 virtual bool siloed_nullifier_exists(const FF& nullifier) const = 0;
106 // Throws a NullifierCollisionException if the nullifier already exists.
107 virtual void nullifier_write(const AztecAddress& contract_address, const FF& nullifier) = 0;
108 virtual void siloed_nullifier_write(const FF& nullifier) = 0;
109
110 virtual bool note_hash_exists(uint64_t leaf_index, const FF& unique_note_hash) const = 0;
111 virtual void note_hash_write(const AztecAddress& contract_address, const FF& note_hash) = 0;
112 virtual void siloed_note_hash_write(const FF& note_hash) = 0;
113 virtual void unique_note_hash_write(const FF& note_hash) = 0;
114 virtual bool l1_to_l2_msg_exists(uint64_t leaf_index, const FF& msg_hash) const = 0;
115
116 virtual void create_checkpoint() = 0;
117 virtual void commit_checkpoint() = 0;
118 virtual void revert_checkpoint() = 0;
119 virtual uint32_t get_checkpoint_id() const = 0;
120
121 virtual void pad_trees() = 0;
122
124};
125
132 public:
133 virtual ~CheckpointNotifiable() = default;
134 virtual void on_checkpoint_created() = 0;
135 virtual void on_checkpoint_committed() = 0;
136 virtual void on_checkpoint_reverted() = 0;
137};
138
139} // namespace bb::avm2::simulation
Interface for a checkpoint notifiable.
Definition db.hpp:131
virtual void add_contracts(const ContractDeploymentData &contract_deployment_data)=0
virtual std::optional< FF > get_bytecode_commitment(const ContractClassId &class_id) const =0
virtual std::optional< std::string > get_debug_function_name(const AztecAddress &address, const FunctionSelector &selector) const =0
virtual std::optional< ContractInstance > get_contract_instance(const AztecAddress &address) const =0
virtual std::optional< ContractClass > get_contract_class(const ContractClassId &class_id) const =0
virtual bool note_hash_exists(uint64_t leaf_index, const FF &unique_note_hash) const =0
virtual void unique_note_hash_write(const FF &note_hash)=0
virtual FF storage_read(const AztecAddress &contract_address, const FF &slot) const =0
virtual uint32_t get_checkpoint_id() const =0
virtual bool was_storage_written(const AztecAddress &contract_address, const FF &slot) const =0
virtual void note_hash_write(const AztecAddress &contract_address, const FF &note_hash)=0
virtual bool nullifier_exists(const AztecAddress &contract_address, const FF &nullifier) const =0
virtual void siloed_note_hash_write(const FF &note_hash)=0
virtual void storage_write(const AztecAddress &contract_address, const FF &slot, const FF &value, bool is_protocol_write)=0
virtual bool siloed_nullifier_exists(const FF &nullifier) const =0
virtual void siloed_nullifier_write(const FF &nullifier)=0
virtual bool l1_to_l2_msg_exists(uint64_t leaf_index, const FF &msg_hash) const =0
virtual void nullifier_write(const AztecAddress &contract_address, const FF &nullifier)=0
virtual TreeStates get_tree_state() const =0
virtual LowLevelMerkleDBInterface & as_unconstrained() const =0
virtual IndexedLeaf< PublicDataLeafValue > get_leaf_preimage_public_data_tree(index_t leaf_index) const =0
virtual std::vector< AppendLeafResult > append_leaves(MerkleTreeId tree_id, std::span< const FF > leaves)=0
virtual TreeSnapshots get_tree_roots() const =0
virtual void pad_tree(MerkleTreeId tree_id, size_t num_leaves)=0
virtual IndexedLeaf< NullifierLeafValue > get_leaf_preimage_nullifier_tree(index_t leaf_index) const =0
virtual SequentialInsertionResult< NullifierLeafValue > insert_indexed_leaves_nullifier_tree(const NullifierLeafValue &leaf_value)=0
virtual GetLowIndexedLeafResponse get_low_indexed_leaf(MerkleTreeId tree_id, const FF &value) const =0
virtual SiblingPath get_sibling_path(MerkleTreeId tree_id, index_t leaf_index) const =0
virtual uint32_t get_checkpoint_id() const =0
virtual SequentialInsertionResult< PublicDataLeafValue > insert_indexed_leaves_public_data_tree(const PublicDataLeafValue &leaf_value)=0
virtual FF get_leaf_value(MerkleTreeId tree_id, index_t leaf_index) const =0
NullifierCollisionException(const std::string &message)
Definition db.hpp:85
::bb::crypto::merkle_tree::fr_sibling_path SiblingPath
Definition db.hpp:36
::bb::crypto::merkle_tree::index_t index_t
Definition db.hpp:37
FF ContractClassId
FF FunctionSelector
AvmFlavorSettings::FF FF
Definition field.hpp:10
std::vector< fr > fr_sibling_path
Definition hash_path.hpp:16
STL namespace.
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13