18std::string
to_string(
const TreeSnapshots& snapshots)
20 return format(
"PUBLIC_DATA_TREE: ",
21 snapshots.publicDataTree,
23 snapshots.nullifierTree,
25 snapshots.noteHashTree,
26 "\nL1_TO_L2_MESSAGE_TREE: ",
27 snapshots.l1ToL2MessageTree);
34 return "PUBLIC_DATA_TREE";
36 return "NULLIFIER_TREE";
38 return "NOTE_HASH_TREE";
40 return "L1_TO_L2_MESSAGE_TREE";
53 return tree_roots.nullifierTree;
55 return tree_roots.publicDataTree;
57 return tree_roots.noteHashTree;
59 return tree_roots.l1ToL2MessageTree;
61 throw std::runtime_error(
"AVM cannot process tree id: " +
std::to_string(
static_cast<uint64_t
>(tree_id)));
70 vinfo(
"Initializing HintedRawContractDB with...",
71 "\n * contractInstances: ",
73 "\n * contractClasses: ",
75 "\n * bytecodeCommitments: ",
103 vinfo(
"Contract instance not found: ", address);
106 const auto& contract_instance_hint = it->second;
109 .salt = contract_instance_hint.salt,
110 .deployer_addr = contract_instance_hint.deployer,
111 .current_class_id = contract_instance_hint.currentContractClassId,
112 .original_class_id = contract_instance_hint.originalContractClassId,
113 .initialisation_hash = contract_instance_hint.initializationHash,
116 .
nullifier_key = contract_instance_hint.publicKeys.masterNullifierPublicKey,
117 .incoming_viewing_key = contract_instance_hint.publicKeys.masterIncomingViewingPublicKey,
118 .outgoing_viewing_key = contract_instance_hint.publicKeys.masterOutgoingViewingPublicKey,
119 .tagging_key = contract_instance_hint.publicKeys.masterTaggingPublicKey,
130 vinfo(
"Contract class not found: ", class_id);
133 const auto& contract_class_hint = it->second;
136 .artifact_hash = contract_class_hint.artifactHash,
137 .private_function_root = contract_class_hint.privateFunctionsRoot,
140 .packed_bytecode = contract_class_hint.packedBytecode,
152 : tree_roots(hints.startingTreeRoots)
154 vinfo(
"Initializing HintedRawMerkleDB with...",
155 "\n * get_sibling_path_hints: ",
157 "\n * get_previous_value_index_hints: ",
159 "\n * get_leaf_preimage_hints_public_data_tree: ",
161 "\n * get_leaf_preimage_hints_nullifier_tree: ",
163 "\n * get_leaf_value_hints: ",
165 "\n * sequential_insert_hints_public_data_tree: ",
167 "\n * sequential_insert_hints_nullifier_tree: ",
169 "\n * append_leaves_hints: ",
171 "\n * create_checkpoint_hints: ",
173 "\n * commit_checkpoint_hints: ",
175 "\n * revert_checkpoint_hints: ",
181 get_sibling_path_hint.treeId,
182 get_sibling_path_hint.index };
188 get_previous_value_index_hint.treeId,
189 get_previous_value_index_hint.value };
191 get_previous_value_index_hint.alreadyPresent,
192 get_previous_value_index_hint.index,
207 GetLeafValueKey key = { get_leaf_value_hint.hintKey, get_leaf_value_hint.treeId, get_leaf_value_hint.index };
213 sequential_insert_hint.treeId,
214 sequential_insert_hint.leaf };
220 sequential_insert_hint.treeId,
221 sequential_insert_hint.leaf };
227 AppendLeavesHintKey key = { append_leaves_hint.hintKey, append_leaves_hint.treeId, append_leaves_hint.leaves };
246 return get_tree_info_helper(tree_id,
tree_roots);
251 return get_tree_info_helper(tree_id,
tree_roots);
260 throw std::runtime_error(
format(
"Sibling path not found for key (root: ",
263 tree_info.nextAvailableLeafIndex,
265 get_tree_name(tree_id),
280 throw std::runtime_error(
format(
"Low indexed leaf not found for key (root: ",
283 tree_info.nextAvailableLeafIndex,
285 get_tree_name(tree_id),
307 throw std::runtime_error(
format(
"Leaf preimage (PUBLIC_DATA_TREE) not found for key (root: ",
310 tree_info.nextAvailableLeafIndex,
324 throw std::runtime_error(
format(
"Leaf preimage (NULLIFIER_TREE) not found for key (root: ",
327 tree_info.nextAvailableLeafIndex,
342 throw std::runtime_error(
format(
"Sequential insert hint (PUBLIC_DATA_TREE) not found for key (root: ",
345 tree_info.nextAvailableLeafIndex,
350 const auto& hint = it->second;
356 hint.lowLeavesWitnessData.leaf, hint.lowLeavesWitnessData.index, hint.lowLeavesWitnessData.path);
360 hint.insertionWitnessData.leaf, hint.insertionWitnessData.index, hint.insertionWitnessData.path);
365 debug(
"Evolved state of PUBLIC_DATA_TREE: ",
381 throw std::runtime_error(
format(
"Sequential insert hint (NULLIFIER_TREE) not found for key (root: ",
384 tree_info.nextAvailableLeafIndex,
389 const auto& hint = it->second;
395 hint.lowLeavesWitnessData.leaf, hint.lowLeavesWitnessData.index, hint.lowLeavesWitnessData.path);
399 hint.insertionWitnessData.leaf, hint.insertionWitnessData.index, hint.insertionWitnessData.path);
404 debug(
"Evolved state of NULLIFIER_TREE: ",
417 throw std::runtime_error(
420 const auto& hint = it->second;
424 throw std::runtime_error(
format(
"[create_checkpoint@",
426 "] Old checkpoint id does not match the current checkpoint id: ",
427 hint.oldCheckpointId,
432 debug(
"[create_checkpoint@",
434 "] Checkpoint evolved ",
435 hint.oldCheckpointId,
437 hint.newCheckpointId);
447 throw std::runtime_error(
450 const auto& hint = it->second;
454 throw std::runtime_error(
format(
"[commit_checkpoint@",
456 "] Old checkpoint id does not match the current checkpoint id: ",
457 hint.oldCheckpointId,
466 throw std::runtime_error(
format(
"[commit_checkpoint@",
468 "] New checkpoint id does not match the current checkpoint id: ",
469 hint.newCheckpointId,
474 debug(
"[commit_checkpoint@",
476 "] Checkpoint evolved ",
477 hint.oldCheckpointId,
479 hint.newCheckpointId);
488 throw std::runtime_error(
491 const auto& hint = it->second;
495 throw std::runtime_error(
format(
"[revert_checkpoint@",
497 "] Old checkpoint id does not match the current checkpoint id: ",
498 hint.oldCheckpointId,
507 throw std::runtime_error(
format(
"[revert_checkpoint@",
509 "] Hint tree snapshots do not match the current tree roots."));
516 throw std::runtime_error(
format(
"[revert_checkpoint@",
518 "] New checkpoint id does not match the current checkpoint id: ",
519 hint.newCheckpointId,
527 debug(
"[revert_checkpoint@",
529 "] Checkpoint evolved ",
530 hint.oldCheckpointId,
532 hint.newCheckpointId);
541 results.reserve(leaves.size());
547 for (
const auto& leaf : leaves) {
557 auto size_before = tree_info.nextAvailableLeafIndex;
558 tree_info.nextAvailableLeafIndex += num_leaves;
560 debug(
"Padded tree ", get_tree_name(tree_id),
" from size ", size_before,
" to ", tree_info.nextAvailableLeafIndex);
569 throw std::runtime_error(
format(
"Append leaves hint not found for key (root: ",
572 tree_info.nextAvailableLeafIndex,
574 get_tree_name(tree_id),
579 const auto& stateAfter = it->second;
585 debug(
"Evolved state of NOTE_HASH_TREE: ",
593 debug(
"Evolved state of L1_TO_L2_MESSAGE_TREE: ",
600 throw std::runtime_error(
"append_leaves is only supported for NOTE_HASH_TREE and L1_TO_L2_MESSAGE_TREE");
604 return { .root = tree_info.root, .path =
get_sibling_path(tree_id, tree_info.nextAvailableLeafIndex) };
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
std::string to_string(AddressingEventError e)
::bb::crypto::merkle_tree::index_t index_t
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