Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
raw_data_dbs.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <span>
4#include <stack>
5#include <tuple>
6
20
21namespace bb::avm2::simulation {
22
23// This class interacts with the external world, without emiting any simulation events.
24// It is used for a given TX and its hinting structure assumes that the content cannot
25// change during the TX.
27 public:
29
34 const FunctionSelector& selector) const override;
35
36 void add_contracts(const ContractDeploymentData& contract_deployment_data) override;
37
38 void create_checkpoint() override;
39 void commit_checkpoint() override;
40 void revert_checkpoint() override;
41
42 private:
43 uint32_t get_checkpoint_id() const;
48
49 uint32_t action_counter = 0;
50 std::stack<uint32_t> checkpoint_stack{ { 0 } };
54};
55
56// This class interacts with the external world, without emiting any simulation events.
58 public:
60
61 TreeSnapshots get_tree_roots() const override { return tree_roots; }
62
63 // Query methods.
64 SiblingPath get_sibling_path(MerkleTreeId tree_id, index_t leaf_index) const override;
66 FF get_leaf_value(MerkleTreeId tree_id, index_t leaf_index) const override;
69
70 // State modification methods.
72 const PublicDataLeafValue& leaf_value) override;
74 const NullifierLeafValue& leaf_value) override;
75 void append_leaves(MerkleTreeId tree_id, std::span<const FF> leaves) override;
76 void pad_tree(MerkleTreeId tree_id, size_t num_leaves) override;
77
78 void create_checkpoint() override;
79 void commit_checkpoint() override;
80 void revert_checkpoint() override;
81 uint32_t get_checkpoint_id() const override;
82
83 private:
86 // We start with a checkpoint id of 0, which is the assumed initial state checkpoint.
87 // This stack is for debugging purposes only.
88 std::stack<uint32_t> checkpoint_stack{ { 0 } };
89
90 // Query hints.
96 // State modification hints.
105
106 // Private helper methods.
109};
110
111// todo(facundo): When used in pure simulation mode, the return values from tree insertions are not used (since we don't
112// care about sibling paths nor do we need new root info within the simulator - they're managed by the world state).
113// We might need to look into a different interface for the simulator only. This might even open the door to batch
114// insertions (since we won't be tied to SequentialInsertionResult).
116 public:
136
137 TreeSnapshots get_tree_roots() const override;
138
139 // Query methods.
140 SiblingPath get_sibling_path(MerkleTreeId tree_id, index_t leaf_index) const override;
142 FF get_leaf_value(MerkleTreeId tree_id, index_t leaf_index) const override;
145
146 // State modification methods.
148 const PublicDataLeafValue& leaf_value) override;
150 const NullifierLeafValue& leaf_value) override;
151 void append_leaves(MerkleTreeId tree_id, std::span<const FF> leaves) override;
152 void pad_tree(MerkleTreeId tree_id, size_t num_leaves) override;
153
154 void create_checkpoint() override;
155 void commit_checkpoint() override;
156 void revert_checkpoint() override;
157 uint32_t get_checkpoint_id() const override;
158
159 private:
160 // Helper to check cancellation before write operations - throws CancelledException if cancelled
162 {
164 cancellation_token_->check_and_throw();
165 }
166 }
167
170 std::stack<uint32_t> checkpoint_stack{ { 0 } };
174};
175
176} // namespace bb::avm2::simulation
std::shared_ptr< Napi::ThreadSafeFunction > add_contracts
unordered_flat_map< uint32_t, ContractDBRevertCheckpointHint > revert_checkpoint_hints
unordered_flat_map< GetBytecodeCommitmentKey, FF > bytecode_commitments
std::optional< ContractClass > get_contract_class(const ContractClassId &class_id) const override
unordered_flat_map< uint32_t, ContractDBCreateCheckpointHint > create_checkpoint_hints
unordered_flat_map< GetContractInstanceKey, ContractInstanceHint > contract_instances
unordered_flat_map< uint32_t, ContractDBCommitCheckpointHint > commit_checkpoint_hints
unordered_flat_map< GetContractClassKey, ContractClassHint > contract_classes
std::optional< std::string > get_debug_function_name(const AztecAddress &address, const FunctionSelector &selector) const override
std::optional< FF > get_bytecode_commitment(const ContractClassId &class_id) const override
unordered_flat_map< GetDebugFunctionNameKey, std::string > debug_function_names
unordered_flat_map< GetLeafValueKey, FF > get_leaf_value_hints
unordered_flat_map< uint32_t, RevertCheckpointHint > revert_checkpoint_hints
unordered_flat_map< SequentialInsertHintNullifierTreeKey, SequentialInsertHint< NullifierLeafValue > > sequential_insert_hints_nullifier_tree
GetLowIndexedLeafResponse get_low_indexed_leaf(MerkleTreeId tree_id, const FF &value) const override
unordered_flat_map< AppendLeavesHintKey, AppendOnlyTreeSnapshot > append_leaves_hints
SiblingPath get_sibling_path(MerkleTreeId tree_id, index_t leaf_index) const override
unordered_flat_map< uint32_t, CommitCheckpointHint > commit_checkpoint_hints
unordered_flat_map< GetSiblingPathKey, SiblingPath > get_sibling_path_hints
SequentialInsertionResult< NullifierLeafValue > insert_indexed_leaves_nullifier_tree(const NullifierLeafValue &leaf_value) override
unordered_flat_map< uint32_t, CreateCheckpointHint > create_checkpoint_hints
IndexedLeaf< PublicDataLeafValue > get_leaf_preimage_public_data_tree(index_t leaf_index) const override
IndexedLeaf< NullifierLeafValue > get_leaf_preimage_nullifier_tree(index_t leaf_index) const override
FF get_leaf_value(MerkleTreeId tree_id, index_t leaf_index) const override
unordered_flat_map< GetLeafPreimageKey, IndexedLeaf< NullifierLeafValue > > get_leaf_preimage_hints_nullifier_tree
unordered_flat_map< SequentialInsertHintPublicDataTreeKey, SequentialInsertHint< PublicDataLeafValue > > sequential_insert_hints_public_data_tree
TreeSnapshots get_tree_roots() const override
unordered_flat_map< GetLeafPreimageKey, IndexedLeaf< PublicDataLeafValue > > get_leaf_preimage_hints_public_data_tree
uint32_t get_checkpoint_id() const override
SequentialInsertionResult< PublicDataLeafValue > insert_indexed_leaves_public_data_tree(const PublicDataLeafValue &leaf_value) override
unordered_flat_map< GetPreviousValueIndexKey, GetLowIndexedLeafResponse > get_previous_value_index_hints
const AppendOnlyTreeSnapshot & get_tree_info(MerkleTreeId tree_id) const
void pad_tree(MerkleTreeId tree_id, size_t num_leaves) override
void append_leaves(MerkleTreeId tree_id, std::span< const FF > leaves) override
world_state::WorldStateRevision ws_revision
IndexedLeaf< PublicDataLeafValue > get_leaf_preimage_public_data_tree(index_t leaf_index) const override
SiblingPath get_sibling_path(MerkleTreeId tree_id, index_t leaf_index) const override
void append_leaves(MerkleTreeId tree_id, std::span< const FF > leaves) override
world_state::WorldState & ws_instance
IndexedLeaf< NullifierLeafValue > get_leaf_preimage_nullifier_tree(index_t leaf_index) const override
GetLowIndexedLeafResponse get_low_indexed_leaf(MerkleTreeId tree_id, const FF &value) const override
std::optional< TreeSnapshots > cached_tree_snapshots
PureRawMerkleDB(world_state::WorldStateRevision ws_revision, world_state::WorldState &ws_instance, bool cache_tree_roots=true, CancellationTokenPtr cancellation_token=nullptr)
Constructor for PureRawMerkleDB.
std::stack< uint32_t > checkpoint_stack
TreeSnapshots get_tree_roots() const override
void pad_tree(MerkleTreeId tree_id, size_t num_leaves) override
SequentialInsertionResult< NullifierLeafValue > insert_indexed_leaves_nullifier_tree(const NullifierLeafValue &leaf_value) override
FF get_leaf_value(MerkleTreeId tree_id, index_t leaf_index) const override
SequentialInsertionResult< PublicDataLeafValue > insert_indexed_leaves_public_data_tree(const PublicDataLeafValue &leaf_value) override
uint32_t get_checkpoint_id() const override
Holds the Merkle trees responsible for storing the state of the Aztec protocol.
::bb::crypto::merkle_tree::fr_sibling_path SiblingPath
Definition db.hpp:36
std::shared_ptr< CancellationToken > CancellationTokenPtr
::bb::crypto::merkle_tree::index_t index_t
Definition db.hpp:37
FF ContractClassId
FF FunctionSelector
AvmFlavorSettings::FF FF
Definition field.hpp:10
::ankerl::unordered_dense::map< Key, T > unordered_flat_map
Definition map.hpp:15
STL namespace.
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13