19std::string
to_string(
const TreeSnapshots& snapshots)
21 return format(
"PUBLIC_DATA_TREE: ",
22 snapshots.publicDataTree,
24 snapshots.nullifierTree,
26 snapshots.noteHashTree,
27 "\nL1_TO_L2_MESSAGE_TREE: ",
28 snapshots.l1ToL2MessageTree);
35 return "PUBLIC_DATA_TREE";
37 return "NULLIFIER_TREE";
39 return "NOTE_HASH_TREE";
41 return "L1_TO_L2_MESSAGE_TREE";
54 return tree_roots.nullifierTree;
56 return tree_roots.publicDataTree;
58 return tree_roots.noteHashTree;
60 return tree_roots.l1ToL2MessageTree;
62 throw std::runtime_error(
"AVM cannot process tree id: " +
std::to_string(
static_cast<uint64_t
>(tree_id)));
73 vinfo(
"Initializing HintedRawContractDB with...",
74 "\n * contractInstances: ",
76 "\n * contractClasses: ",
78 "\n * bytecodeCommitments: ",
106 vinfo(
"Contract instance not found: ", address);
109 const auto& contract_instance_hint = it->second;
112 .salt = contract_instance_hint.salt,
113 .deployer_addr = contract_instance_hint.deployer,
114 .current_class_id = contract_instance_hint.currentContractClassId,
115 .original_class_id = contract_instance_hint.originalContractClassId,
116 .initialisation_hash = contract_instance_hint.initializationHash,
119 .
nullifier_key = contract_instance_hint.publicKeys.masterNullifierPublicKey,
120 .incoming_viewing_key = contract_instance_hint.publicKeys.masterIncomingViewingPublicKey,
121 .outgoing_viewing_key = contract_instance_hint.publicKeys.masterOutgoingViewingPublicKey,
122 .tagging_key = contract_instance_hint.publicKeys.masterTaggingPublicKey,
136 const auto& contract_class_hint = it->second;
139 .artifact_hash = contract_class_hint.artifactHash,
140 .private_function_root = contract_class_hint.privateFunctionsRoot,
143 .packed_bytecode = contract_class_hint.packedBytecode,
155 : tree_roots(hints.startingTreeRoots)
159 vinfo(
"Initializing HintedRawMerkleDB with...",
160 "\n * get_sibling_path_hints: ",
162 "\n * get_previous_value_index_hints: ",
164 "\n * get_leaf_preimage_hints_public_data_tree: ",
166 "\n * get_leaf_preimage_hints_nullifier_tree: ",
168 "\n * get_leaf_value_hints: ",
170 "\n * sequential_insert_hints_public_data_tree: ",
172 "\n * sequential_insert_hints_nullifier_tree: ",
174 "\n * append_leaves_hints: ",
176 "\n * create_checkpoint_hints: ",
178 "\n * commit_checkpoint_hints: ",
180 "\n * revert_checkpoint_hints: ",
186 get_sibling_path_hint.treeId,
187 get_sibling_path_hint.index };
193 get_previous_value_index_hint.treeId,
194 get_previous_value_index_hint.value };
196 get_previous_value_index_hint.alreadyPresent,
197 get_previous_value_index_hint.index,
212 GetLeafValueKey key = { get_leaf_value_hint.hintKey, get_leaf_value_hint.treeId, get_leaf_value_hint.index };
218 sequential_insert_hint.treeId,
219 sequential_insert_hint.leaf };
225 sequential_insert_hint.treeId,
226 sequential_insert_hint.leaf };
232 AppendLeavesHintKey key = { append_leaves_hint.hintKey, append_leaves_hint.treeId, append_leaves_hint.leaves };
251 return get_tree_info_helper(tree_id,
tree_roots);
256 return get_tree_info_helper(tree_id,
tree_roots);
265 throw std::runtime_error(
format(
"Sibling path not found for key (root: ",
268 tree_info.nextAvailableLeafIndex,
270 get_tree_name(tree_id),
285 throw std::runtime_error(
format(
"Low indexed leaf not found for key (root: ",
288 tree_info.nextAvailableLeafIndex,
290 get_tree_name(tree_id),
312 throw std::runtime_error(
format(
"Leaf preimage (PUBLIC_DATA_TREE) not found for key (root: ",
315 tree_info.nextAvailableLeafIndex,
329 throw std::runtime_error(
format(
"Leaf preimage (NULLIFIER_TREE) not found for key (root: ",
332 tree_info.nextAvailableLeafIndex,
347 throw std::runtime_error(
format(
"Sequential insert hint (PUBLIC_DATA_TREE) not found for key (root: ",
350 tree_info.nextAvailableLeafIndex,
355 const auto& hint = it->second;
361 hint.lowLeavesWitnessData.leaf, hint.lowLeavesWitnessData.index, hint.lowLeavesWitnessData.path);
365 hint.insertionWitnessData.leaf, hint.insertionWitnessData.index, hint.insertionWitnessData.path);
370 debug(
"Evolved state of PUBLIC_DATA_TREE: ",
386 throw std::runtime_error(
format(
"Sequential insert hint (NULLIFIER_TREE) not found for key (root: ",
389 tree_info.nextAvailableLeafIndex,
394 const auto& hint = it->second;
400 hint.lowLeavesWitnessData.leaf, hint.lowLeavesWitnessData.index, hint.lowLeavesWitnessData.path);
404 hint.insertionWitnessData.leaf, hint.insertionWitnessData.index, hint.insertionWitnessData.path);
409 debug(
"Evolved state of NULLIFIER_TREE: ",
422 throw std::runtime_error(
425 const auto& hint = it->second;
429 throw std::runtime_error(
format(
"[create_checkpoint@",
431 "] Old checkpoint id does not match the current checkpoint id: ",
432 hint.oldCheckpointId,
437 debug(
"[create_checkpoint@",
439 "] Checkpoint evolved ",
440 hint.oldCheckpointId,
442 hint.newCheckpointId);
452 throw std::runtime_error(
455 const auto& hint = it->second;
459 throw std::runtime_error(
format(
"[commit_checkpoint@",
461 "] Old checkpoint id does not match the current checkpoint id: ",
462 hint.oldCheckpointId,
471 throw std::runtime_error(
format(
"[commit_checkpoint@",
473 "] New checkpoint id does not match the current checkpoint id: ",
474 hint.newCheckpointId,
479 debug(
"[commit_checkpoint@",
481 "] Checkpoint evolved ",
482 hint.oldCheckpointId,
484 hint.newCheckpointId);
493 throw std::runtime_error(
496 const auto& hint = it->second;
500 throw std::runtime_error(
format(
"[revert_checkpoint@",
502 "] Old checkpoint id does not match the current checkpoint id: ",
503 hint.oldCheckpointId,
512 throw std::runtime_error(
format(
"[revert_checkpoint@",
514 "] Hint tree snapshots do not match the current tree roots."));
521 throw std::runtime_error(
format(
"[revert_checkpoint@",
523 "] New checkpoint id does not match the current checkpoint id: ",
524 hint.newCheckpointId,
532 debug(
"[revert_checkpoint@",
534 "] Checkpoint evolved ",
535 hint.oldCheckpointId,
537 hint.newCheckpointId);
546 results.reserve(leaves.size());
552 for (
const auto& leaf : leaves) {
562 auto size_before = tree_info.nextAvailableLeafIndex;
564 tree_info.nextAvailableLeafIndex += num_leaves;
566 debug(
"Padded tree ", get_tree_name(tree_id),
" from size ", size_before,
" to ", tree_info.nextAvailableLeafIndex);
575 throw std::runtime_error(
format(
"Append leaves hint not found for key (root: ",
578 tree_info.nextAvailableLeafIndex,
580 get_tree_name(tree_id),
585 const auto& stateAfter = it->second;
591 debug(
"Evolved state of NOTE_HASH_TREE: ",
599 debug(
"Evolved state of L1_TO_L2_MESSAGE_TREE: ",
606 throw std::runtime_error(
"append_leaves is only supported for NOTE_HASH_TREE and L1_TO_L2_MESSAGE_TREE");
610 return { .root = tree_info.root, .path =
get_sibling_path(tree_id, tree_info.nextAvailableLeafIndex) };
#define BB_BENCH_NAME(name)
HintedRawContractDB(const ExecutionHints &hints)
std::optional< ContractInstance > get_contract_instance(const AztecAddress &address) const override
unordered_flat_map< ContractClassId, FF > bytecode_commitments
FF get_bytecode_commitment(const ContractClassId &class_id) const
std::optional< ContractClass > get_contract_class(const ContractClassId &class_id) const override
unordered_flat_map< ContractClassId, ContractClassHint > contract_classes
unordered_flat_map< AztecAddress, ContractInstanceHint > contract_instances
std::tuple< AppendOnlyTreeSnapshot, MerkleTreeId, std::vector< FF > > AppendLeavesHintKey
std::tuple< AppendOnlyTreeSnapshot, MerkleTreeId, NullifierLeafValue > SequentialInsertHintNullifierTreeKey
std::tuple< AppendOnlyTreeSnapshot, MerkleTreeId, FF > GetPreviousValueIndexKey
void create_checkpoint() override
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
std::stack< uint32_t > checkpoint_stack
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
void commit_checkpoint() override
void revert_checkpoint() 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
HintedRawMerkleDB(const ExecutionHints &hints)
unordered_flat_map< GetLeafPreimageKey, IndexedLeaf< PublicDataLeafValue > > get_leaf_preimage_hints_public_data_tree
std::tuple< AppendOnlyTreeSnapshot, MerkleTreeId, index_t > GetLeafValueKey
std::tuple< AppendOnlyTreeSnapshot, MerkleTreeId, index_t > GetSiblingPathKey
std::tuple< AppendOnlyTreeSnapshot, index_t > GetLeafPreimageKey
uint32_t get_checkpoint_id() const override
uint32_t checkpoint_action_counter
std::tuple< AppendOnlyTreeSnapshot, MerkleTreeId, PublicDataLeafValue > SequentialInsertHintPublicDataTreeKey
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
std::string format(Args... args)
::bb::crypto::merkle_tree::fr_sibling_path SiblingPath
::bb::crypto::merkle_tree::index_t index_t
std::string to_string(const std::array< FF, N > &arr)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
std::string to_string(bb::avm2::ValueTag tag)
uint64_t nextAvailableLeafIndex
std::vector< RevertCheckpointHint > revertCheckpointHints
std::vector< SequentialInsertHint< crypto::merkle_tree::NullifierLeafValue > > sequentialInsertHintsNullifierTree
std::vector< ContractClassHint > contractClasses
std::vector< GetPreviousValueIndexHint > getPreviousValueIndexHints
std::vector< AppendLeavesHint > appendLeavesHints
std::vector< GetLeafPreimageHint< crypto::merkle_tree::IndexedLeaf< crypto::merkle_tree::NullifierLeafValue > > > getLeafPreimageHintsNullifierTree
std::vector< CommitCheckpointHint > commitCheckpointHints
std::vector< SequentialInsertHint< crypto::merkle_tree::PublicDataLeafValue > > sequentialInsertHintsPublicDataTree
std::vector< GetSiblingPathHint > getSiblingPathHints
std::vector< GetLeafValueHint > getLeafValueHints
std::vector< GetLeafPreimageHint< crypto::merkle_tree::IndexedLeaf< crypto::merkle_tree::PublicDataLeafValue > > > getLeafPreimageHintsPublicDataTree
std::vector< ContractInstanceHint > contractInstances
std::vector< BytecodeCommitmentHint > bytecodeCommitments
std::vector< CreateCheckpointHint > createCheckpointHints
AffinePoint nullifier_key
AppendOnlyTreeSnapshot noteHashTree
AppendOnlyTreeSnapshot nullifierTree
AppendOnlyTreeSnapshot l1ToL2MessageTree
AppendOnlyTreeSnapshot publicDataTree
std::vector< crypto::merkle_tree::LeafUpdateWitnessData< LeafValueType > > low_leaf_witness_data
std::vector< crypto::merkle_tree::LeafUpdateWitnessData< LeafValueType > > insertion_witness_data