Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
db_types.hpp
Go to the documentation of this file.
1#pragma once
2
8
9namespace bb::avm2::simulation {
10
13
14// Keys for hints stored in unordered_flat_maps, used in raw_data_dbs and hinting_dbs.
26
27// TODO(MW): Temp struct for hints to allow using a ref in the HintingContractsDB class constructor
37
38// TODO(MW): Temp struct for hints to allow using a ref in the HintingRawDB class constructor
58
63 // public data tree counter is tracked via the written public data slots tree
64
65 bool operator==(const TreeCounters& other) const = default;
66};
67
68} // namespace bb::avm2::simulation
69
70// We need this helper to avoid having const and non-const versions methods in db classes.
71auto& get_tree_info_helper(world_state::MerkleTreeId tree_id, auto& tree_roots)
72{
73 switch (tree_id) {
74 case world_state::MerkleTreeId::NULLIFIER_TREE:
75 return tree_roots.nullifier_tree;
76 case world_state::MerkleTreeId::PUBLIC_DATA_TREE:
77 return tree_roots.public_data_tree;
78 case world_state::MerkleTreeId::NOTE_HASH_TREE:
79 return tree_roots.note_hash_tree;
80 case world_state::MerkleTreeId::L1_TO_L2_MESSAGE_TREE:
81 return tree_roots.l1_to_l2_message_tree;
82 default:
83 throw std::runtime_error("AVM cannot process tree id: " + std::to_string(static_cast<uint64_t>(tree_id)));
84 }
85}
86
87// Specialization of std::hash for std::vector<FF> to be used as a key in unordered_flat_map.
88// Used in raw_data_dbs and hinting_dbs
89namespace std {
90template <> struct hash<std::vector<bb::avm2::FF>> {
91 size_t operator()(const std::vector<bb::avm2::FF>& vec) const
92 {
93 size_t seed = vec.size();
94 for (const auto& item : vec) {
95 seed ^= std::hash<bb::avm2::FF>{}(item) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
96 }
97 return seed;
98 }
99};
100} // namespace std
auto & get_tree_info_helper(world_state::MerkleTreeId tree_id, auto &tree_roots)
Definition db_types.hpp:71
void hash(State &state) noexcept
std::tuple< AppendOnlyTreeSnapshot, MerkleTreeId, index_t > GetSiblingPathKey
Definition db_types.hpp:15
std::tuple< AppendOnlyTreeSnapshot, MerkleTreeId, index_t > GetLeafValueKey
Definition db_types.hpp:18
std::tuple< uint32_t, ContractClassId > GetBytecodeCommitmentKey
Definition db_types.hpp:24
std::tuple< AztecAddress, FunctionSelector > GetDebugFunctionNameKey
Definition db_types.hpp:25
std::tuple< AppendOnlyTreeSnapshot, MerkleTreeId, NullifierLeafValue > SequentialInsertHintNullifierTreeKey
Definition db_types.hpp:20
std::tuple< AppendOnlyTreeSnapshot, index_t > GetLeafPreimageKey
Definition db_types.hpp:17
std::tuple< AppendOnlyTreeSnapshot, MerkleTreeId, PublicDataLeafValue > SequentialInsertHintPublicDataTreeKey
Definition db_types.hpp:19
std::tuple< uint32_t, AztecAddress > GetContractInstanceKey
Definition db_types.hpp:22
std::tuple< AppendOnlyTreeSnapshot, MerkleTreeId, FF > GetPreviousValueIndexKey
Definition db_types.hpp:16
std::tuple< AppendOnlyTreeSnapshot, MerkleTreeId, std::vector< FF > > AppendLeavesHintKey
Definition db_types.hpp:21
std::tuple< uint32_t, ContractClassId > GetContractClassKey
Definition db_types.hpp:23
::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
std::string to_string(bb::avm2::ValueTag tag)
unordered_flat_map< GetContractClassKey, ContractClassHint > contract_classes
Definition db_types.hpp:30
unordered_flat_map< uint32_t, ContractDBRevertCheckpointHint > revert_checkpoint_hints
Definition db_types.hpp:35
unordered_flat_map< uint32_t, ContractDBCreateCheckpointHint > create_checkpoint_hints
Definition db_types.hpp:33
unordered_flat_map< uint32_t, ContractDBCommitCheckpointHint > commit_checkpoint_hints
Definition db_types.hpp:34
unordered_flat_map< GetDebugFunctionNameKey, DebugFunctionNameHint > debug_function_names
Definition db_types.hpp:32
unordered_flat_map< GetContractInstanceKey, ContractInstanceHint > contract_instances
Definition db_types.hpp:29
unordered_flat_map< GetBytecodeCommitmentKey, BytecodeCommitmentHint > bytecode_commitments
Definition db_types.hpp:31
unordered_flat_map< uint32_t, CreateCheckpointHint > create_checkpoint_hints
Definition db_types.hpp:54
unordered_flat_map< uint32_t, CommitCheckpointHint > commit_checkpoint_hints
Definition db_types.hpp:55
unordered_flat_map< uint32_t, RevertCheckpointHint > revert_checkpoint_hints
Definition db_types.hpp:56
unordered_flat_map< AppendLeavesHintKey, AppendLeavesHint > append_leaves_hints
Definition db_types.hpp:53
unordered_flat_map< SequentialInsertHintPublicDataTreeKey, SequentialInsertHint< PublicDataLeafValue > > sequential_insert_hints_public_data_tree
Definition db_types.hpp:50
unordered_flat_map< GetLeafPreimageKey, GetLeafPreimageHint< PublicDataTreeLeafPreimage > > get_leaf_preimage_hints_public_data_tree
Definition db_types.hpp:44
unordered_flat_map< SequentialInsertHintNullifierTreeKey, SequentialInsertHint< NullifierLeafValue > > sequential_insert_hints_nullifier_tree
Definition db_types.hpp:52
unordered_flat_map< GetSiblingPathKey, GetSiblingPathHint > get_sibling_path_hints
Definition db_types.hpp:41
unordered_flat_map< GetLeafPreimageKey, GetLeafPreimageHint< NullifierTreeLeafPreimage > > get_leaf_preimage_hints_nullifier_tree
Definition db_types.hpp:46
unordered_flat_map< GetLeafValueKey, GetLeafValueHint > get_leaf_value_hints
Definition db_types.hpp:47
unordered_flat_map< GetPreviousValueIndexKey, GetPreviousValueIndexHint > get_previous_value_index_hints
Definition db_types.hpp:42
bool operator==(const TreeCounters &other) const =default
size_t operator()(const std::vector< bb::avm2::FF > &vec) const
Definition db_types.hpp:91