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
19
20namespace bb::avm2::simulation {
21
22// This class interacts with the external world, without emiting any simulation events.
23// It is used for a given TX and its hinting structure assumes that the content cannot
24// change during the TX.
26 public:
28
33 const FunctionSelector& selector) const override;
34
35 void add_contracts(const ContractDeploymentData& contract_deployment_data) override;
36
37 void create_checkpoint() override;
38 void commit_checkpoint() override;
39 void revert_checkpoint() override;
40
41 private:
42 uint32_t get_checkpoint_id() const;
47
48 uint32_t action_counter = 0;
49 std::stack<uint32_t> checkpoint_stack{ { 0 } };
53};
54
55// This class interacts with the external world, without emiting any simulation events.
57 public:
59
60 TreeSnapshots get_tree_roots() const override { return tree_roots; }
61
62 // Query methods.
63 SiblingPath get_sibling_path(MerkleTreeId tree_id, index_t leaf_index) const override;
65 FF get_leaf_value(MerkleTreeId tree_id, index_t leaf_index) const override;
68
69 // State modification methods.
71 const PublicDataLeafValue& leaf_value) override;
73 const NullifierLeafValue& leaf_value) override;
75 void pad_tree(MerkleTreeId tree_id, size_t num_leaves) override;
76
77 void create_checkpoint() override;
78 void commit_checkpoint() override;
79 void revert_checkpoint() override;
80 uint32_t get_checkpoint_id() const override;
81
82 private:
85 // We start with a checkpoint id of 0, which is the assumed initial state checkpoint.
86 // This stack is for debugging purposes only.
87 std::stack<uint32_t> checkpoint_stack{ { 0 } };
88
89 // Query hints.
95 // State modification hints.
104
105 // 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:
121
122 TreeSnapshots get_tree_roots() const override;
123
124 // Query methods.
125 SiblingPath get_sibling_path(MerkleTreeId tree_id, index_t leaf_index) const override;
127 FF get_leaf_value(MerkleTreeId tree_id, index_t leaf_index) const override;
130
131 // State modification methods.
133 const PublicDataLeafValue& leaf_value) override;
135 const NullifierLeafValue& leaf_value) override;
137 void pad_tree(MerkleTreeId tree_id, size_t num_leaves) override;
138
139 void create_checkpoint() override;
140 void commit_checkpoint() override;
141 void revert_checkpoint() override;
142 uint32_t get_checkpoint_id() const override;
143
144 private:
147 std::stack<uint32_t> checkpoint_stack{ { 0 } };
148};
149
150} // 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
std::vector< AppendLeafResult > append_leaves(MerkleTreeId tree_id, std::span< const FF > leaves) override
AppendLeafResult appendLeafInternal(MerkleTreeId tree_id, const FF &leaf)
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
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
PureRawMerkleDB(world_state::WorldStateRevision ws_revision, world_state::WorldState &ws_instance)
world_state::WorldState & ws_instance
IndexedLeaf< NullifierLeafValue > get_leaf_preimage_nullifier_tree(index_t leaf_index) const override
std::vector< AppendLeafResult > append_leaves(MerkleTreeId tree_id, std::span< const FF > leaves) override
GetLowIndexedLeafResponse get_low_indexed_leaf(MerkleTreeId tree_id, const FF &value) const override
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
::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
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13