20std::string
to_string(
const TreeSnapshots& snapshots)
22 return format(
"PUBLIC_DATA_TREE: ",
23 snapshots.public_data_tree,
25 snapshots.nullifier_tree,
27 snapshots.note_hash_tree,
28 "\nL1_TO_L2_MESSAGE_TREE: ",
29 snapshots.l1_to_l2_message_tree);
36 return "PUBLIC_DATA_TREE";
38 return "NULLIFIER_TREE";
40 return "NOTE_HASH_TREE";
42 return "L1_TO_L2_MESSAGE_TREE";
57 vinfo(
"Initializing HintedRawContractDB with...",
58 "\n * contract_instances: ",
60 "\n * contract_classes: ",
62 "\n * bytecode_commitments: ",
64 "\n * debug_function_names: ",
68 contract_instances[std::make_tuple(contract_instance_hint.hint_key, contract_instance_hint.address)] =
69 contract_instance_hint;
73 contract_classes[std::make_tuple(contract_class_hint.hint_key, contract_class_hint.class_id)] =
78 bytecode_commitments[std::make_tuple(bytecode_commitment_hint.hint_key, bytecode_commitment_hint.class_id)] =
79 bytecode_commitment_hint.commitment;
84 debug_function_name_hint.name;
101 auto key = std::make_tuple(hint_key,
address);
104 vinfo(
"Contract instance not found for key (", hint_key,
", ",
address,
")");
107 const auto& contract_instance_hint = it->second;
110 .salt = contract_instance_hint.salt,
111 .deployer = contract_instance_hint.deployer,
112 .current_contract_class_id = contract_instance_hint.current_contract_class_id,
113 .original_contract_class_id = contract_instance_hint.original_contract_class_id,
114 .initialization_hash = contract_instance_hint.initialization_hash,
117 .
nullifier_key = contract_instance_hint.public_keys.master_nullifier_public_key,
118 .incoming_viewing_key = contract_instance_hint.public_keys.master_incoming_viewing_public_key,
119 .outgoing_viewing_key = contract_instance_hint.public_keys.master_outgoing_viewing_public_key,
120 .tagging_key = contract_instance_hint.public_keys.master_tagging_public_key,
131 vinfo(
"Contract class not found for key (", hint_key,
", ",
class_id,
")");
134 const auto& contract_class_hint = it->second;
138 .artifact_hash = contract_class_hint.artifact_hash,
139 .private_functions_root = contract_class_hint.private_functions_root,
140 .packed_bytecode = contract_class_hint.packed_bytecode,
150 vinfo(
"Bytecode commitment not found for key (", hint_key,
", ",
class_id,
")");
168 debug(
"add_contracts called (no-op in hinted mode)");
176 const auto& hint = hint_it->second;
188 const auto& hint = hint_it->second;
202 const auto& hint = hint_it->second;
218 : tree_roots(hints.starting_tree_roots)
222 vinfo(
"Initializing HintedRawMerkleDB with...",
223 "\n * get_sibling_path_hints: ",
225 "\n * get_previous_value_index_hints: ",
227 "\n * get_leaf_preimage_hints_public_data_tree: ",
229 "\n * get_leaf_preimage_hints_nullifier_tree: ",
231 "\n * get_leaf_value_hints: ",
233 "\n * sequential_insert_hints_public_data_tree: ",
235 "\n * sequential_insert_hints_nullifier_tree: ",
237 "\n * append_leaves_hints: ",
239 "\n * create_checkpoint_hints: ",
241 "\n * commit_checkpoint_hints: ",
243 "\n * revert_checkpoint_hints: ",
249 get_sibling_path_hint.tree_id,
250 get_sibling_path_hint.index };
256 get_previous_value_index_hint.tree_id,
257 get_previous_value_index_hint.value };
259 get_previous_value_index_hint.already_present,
260 get_previous_value_index_hint.index,
275 GetLeafValueKey key = { get_leaf_value_hint.hint_key, get_leaf_value_hint.tree_id, get_leaf_value_hint.index };
281 sequential_insert_hint.tree_id,
282 sequential_insert_hint.leaf };
288 sequential_insert_hint.tree_id,
289 sequential_insert_hint.leaf };
296 append_leaves_hint.tree_id,
297 append_leaves_hint.leaves };
330 throw std::runtime_error(
format(
"Sibling path not found for key (root: ",
333 tree_info.next_available_leaf_index,
335 get_tree_name(tree_id),
350 throw std::runtime_error(
format(
"Low indexed leaf not found for key (root: ",
353 tree_info.next_available_leaf_index,
355 get_tree_name(tree_id),
369 throw std::runtime_error(
format(
"Leaf value not found for key (root: ",
372 tree_info.next_available_leaf_index,
374 get_tree_name(tree_id),
388 throw std::runtime_error(
format(
"Leaf preimage (PUBLIC_DATA_TREE) not found for key (root: ",
391 tree_info.next_available_leaf_index,
405 throw std::runtime_error(
format(
"Leaf preimage (NULLIFIER_TREE) not found for key (root: ",
408 tree_info.next_available_leaf_index,
423 throw std::runtime_error(
format(
"Sequential insert hint (PUBLIC_DATA_TREE) not found for key (root: ",
426 tree_info.next_available_leaf_index,
431 const auto& hint = it->second;
437 hint.low_leaves_witness_data.leaf, hint.low_leaves_witness_data.index, hint.low_leaves_witness_data.path);
441 hint.insertion_witness_data.leaf, hint.insertion_witness_data.index, hint.insertion_witness_data.path);
446 debug(
"Evolved state of PUBLIC_DATA_TREE: ",
462 throw std::runtime_error(
format(
"Sequential insert hint (NULLIFIER_TREE) not found for key (root: ",
465 tree_info.next_available_leaf_index,
470 const auto& hint = it->second;
476 hint.low_leaves_witness_data.leaf, hint.low_leaves_witness_data.index, hint.low_leaves_witness_data.path);
480 hint.insertion_witness_data.leaf, hint.insertion_witness_data.index, hint.insertion_witness_data.path);
485 debug(
"Evolved state of NULLIFIER_TREE: ",
498 throw std::runtime_error(
501 const auto& hint = it->second;
505 throw std::runtime_error(
format(
"[create_checkpoint@",
507 "] Old checkpoint id does not match the current checkpoint id: ",
508 hint.old_checkpoint_id,
513 debug(
"[create_checkpoint@",
515 "] Checkpoint evolved ",
516 hint.old_checkpoint_id,
518 hint.new_checkpoint_id);
528 throw std::runtime_error(
531 const auto& hint = it->second;
535 throw std::runtime_error(
format(
"[commit_checkpoint@",
537 "] Old checkpoint id does not match the current checkpoint id: ",
538 hint.old_checkpoint_id,
547 throw std::runtime_error(
format(
"[commit_checkpoint@",
549 "] New checkpoint id does not match the current checkpoint id: ",
550 hint.new_checkpoint_id,
555 debug(
"[commit_checkpoint@",
557 "] Checkpoint evolved ",
558 hint.old_checkpoint_id,
560 hint.new_checkpoint_id);
569 throw std::runtime_error(
572 const auto& hint = it->second;
576 throw std::runtime_error(
format(
"[revert_checkpoint@",
578 "] Old checkpoint id does not match the current checkpoint id: ",
579 hint.old_checkpoint_id,
588 throw std::runtime_error(
format(
"[revert_checkpoint@",
590 "] Hint tree snapshots do not match the current tree roots."));
597 throw std::runtime_error(
format(
"[revert_checkpoint@",
599 "] New checkpoint id does not match the current checkpoint id: ",
600 hint.new_checkpoint_id,
608 debug(
"[revert_checkpoint@",
610 "] Checkpoint evolved ",
611 hint.old_checkpoint_id,
613 hint.new_checkpoint_id);
622 results.reserve(leaves.size());
628 for (
const auto& leaf : leaves) {
638 auto size_before = tree_info.next_available_leaf_index;
640 tree_info.next_available_leaf_index += num_leaves;
642 debug(
"Padded tree ",
643 get_tree_name(tree_id),
647 tree_info.next_available_leaf_index);
656 throw std::runtime_error(
format(
"Append leaves hint not found for key (root: ",
659 tree_info.next_available_leaf_index,
661 get_tree_name(tree_id),
666 const auto& state_after = it->second;
672 debug(
"Evolved state of NOTE_HASH_TREE: ",
680 debug(
"Evolved state of L1_TO_L2_MESSAGE_TREE: ",
687 throw std::runtime_error(
"append_leaves is only supported for NOTE_HASH_TREE and L1_TO_L2_MESSAGE_TREE");
691 return { .root = tree_info.root, .path =
get_sibling_path(tree_id, tree_info.next_available_leaf_index) };
709 .next_available_leaf_index = l1_to_l2_info.meta.size },
711 .next_available_leaf_index = note_hash_info.meta.size },
713 .next_available_leaf_index = nullifier_info.meta.size },
715 .next_available_leaf_index = public_data_info.meta.size },
733 if (!res.has_value()) {
734 throw std::runtime_error(
735 format(
"Invalid get_leaf_value request",
static_cast<uint64_t
>(tree_id),
" for index ", leaf_index));
745 if (!res.has_value()) {
746 throw std::runtime_error(
format(
"Invalid get_leaf_preimage_public_data_tree request for index ", leaf_index));
756 if (!res.has_value()) {
757 throw std::runtime_error(
format(
"Invalid get_leaf_preimage_nullifier_tree request for index ", leaf_index));
784 std::vector<FF> leaves_vec(leaves.begin(), leaves.end());
798 case MerkleTreeId::NULLIFIER_TREE: {
804 case MerkleTreeId::NOTE_HASH_TREE: {
805 std::vector<FF> padding_leaves(num_leaves,
FF(0));
810 throw std::runtime_error(
"Padding not supported for tree " +
std::to_string(
static_cast<uint64_t
>(tree_id)));
#define NULLIFIER_SUBTREE_HEIGHT
#define BB_BENCH_NAME(name)
HintedRawContractDB(const ExecutionHints &hints)
uint32_t get_checkpoint_id() const
std::optional< ContractInstance > get_contract_instance(const AztecAddress &address) const override
std::stack< uint32_t > checkpoint_stack
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
void create_checkpoint() override
unordered_flat_map< GetContractInstanceKey, ContractInstanceHint > contract_instances
void add_contracts(const ContractDeploymentData &contract_deployment_data) override
unordered_flat_map< uint32_t, ContractDBCommitCheckpointHint > commit_checkpoint_hints
unordered_flat_map< GetContractClassKey, ContractClassHint > contract_classes
void commit_checkpoint() override
void revert_checkpoint() override
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
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
uint32_t get_checkpoint_id() const override
uint32_t checkpoint_action_counter
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
void revert_checkpoint() override
world_state::WorldState & ws_instance
IndexedLeaf< NullifierLeafValue > get_leaf_preimage_nullifier_tree(index_t leaf_index) const override
void commit_checkpoint() 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
void create_checkpoint() 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
BatchInsertionResult< T > batch_insert_indexed_leaves(MerkleTreeId tree_id, const std::vector< T > &leaves, uint32_t subtree_depth, Fork::Id fork_id=CANONICAL_FORK_ID)
Batch inserts a set of leaves into an indexed Merkle Tree.
void append_leaves(MerkleTreeId tree_id, const std::vector< T > &leaves, Fork::Id fork_id=CANONICAL_FORK_ID)
Appends a set of leaves to an existing Merkle Tree.
std::optional< crypto::merkle_tree::IndexedLeaf< T > > get_indexed_leaf(const WorldStateRevision &revision, MerkleTreeId tree_id, index_t leaf_index) const
Get the leaf preimage object.
void revert_checkpoint(const uint64_t &forkId)
crypto::merkle_tree::TreeMetaResponse get_tree_info(const WorldStateRevision &revision, MerkleTreeId tree_id) const
Get tree metadata for a particular tree.
SequentialInsertionResult< T > insert_indexed_leaves(MerkleTreeId tree_id, const std::vector< T > &leaves, Fork::Id fork_id=CANONICAL_FORK_ID)
Inserts a set of leaves sequentially into an indexed Merkle Tree.
void commit_checkpoint(const uint64_t &forkId)
crypto::merkle_tree::fr_sibling_path get_sibling_path(const WorldStateRevision &revision, MerkleTreeId tree_id, index_t leaf_index) const
Get the sibling path object for a leaf in a tree.
std::optional< T > get_leaf(const WorldStateRevision &revision, MerkleTreeId tree_id, index_t leaf_index) const
Gets the value of a leaf in a tree.
void checkpoint(const uint64_t &forkId)
crypto::merkle_tree::GetLowIndexedLeafResponse find_low_leaf_index(const WorldStateRevision &revision, MerkleTreeId tree_id, const bb::fr &leaf_key) const
Finds the leaf that would have its nextIdx/nextValue fields modified if the target leaf were to be in...
std::string format(Args... args)
auto & get_tree_info_helper(world_state::MerkleTreeId tree_id, auto &tree_roots)
::bb::crypto::merkle_tree::fr_sibling_path SiblingPath
std::tuple< AppendOnlyTreeSnapshot, MerkleTreeId, index_t > GetSiblingPathKey
std::tuple< AppendOnlyTreeSnapshot, MerkleTreeId, index_t > GetLeafValueKey
std::tuple< AppendOnlyTreeSnapshot, MerkleTreeId, NullifierLeafValue > SequentialInsertHintNullifierTreeKey
std::tuple< AppendOnlyTreeSnapshot, index_t > GetLeafPreimageKey
std::tuple< AppendOnlyTreeSnapshot, MerkleTreeId, PublicDataLeafValue > SequentialInsertHintPublicDataTreeKey
std::tuple< AppendOnlyTreeSnapshot, MerkleTreeId, FF > GetPreviousValueIndexKey
std::tuple< AppendOnlyTreeSnapshot, MerkleTreeId, std::vector< FF > > AppendLeavesHintKey
::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 next_available_leaf_index
std::vector< SequentialInsertHint< crypto::merkle_tree::NullifierLeafValue > > sequential_insert_hints_nullifier_tree
std::vector< GetSiblingPathHint > get_sibling_path_hints
std::vector< DebugFunctionNameHint > debug_function_names
std::vector< ContractDBCreateCheckpointHint > contract_db_create_checkpoint_hints
std::vector< ContractDBCommitCheckpointHint > contract_db_commit_checkpoint_hints
std::vector< CommitCheckpointHint > commit_checkpoint_hints
std::vector< SequentialInsertHint< crypto::merkle_tree::PublicDataLeafValue > > sequential_insert_hints_public_data_tree
std::vector< RevertCheckpointHint > revert_checkpoint_hints
std::vector< ContractDBRevertCheckpointHint > contract_db_revert_checkpoint_hints
std::vector< GetPreviousValueIndexHint > get_previous_value_index_hints
std::vector< GetLeafPreimageHint< crypto::merkle_tree::IndexedLeaf< crypto::merkle_tree::PublicDataLeafValue > > > get_leaf_preimage_hints_public_data_tree
std::vector< GetLeafPreimageHint< crypto::merkle_tree::IndexedLeaf< crypto::merkle_tree::NullifierLeafValue > > > get_leaf_preimage_hints_nullifier_tree
std::vector< CreateCheckpointHint > create_checkpoint_hints
std::vector< GetLeafValueHint > get_leaf_value_hints
std::vector< AppendLeavesHint > append_leaves_hints
std::vector< ContractInstanceHint > contract_instances
std::vector< ContractClassHint > contract_classes
std::vector< BytecodeCommitmentHint > bytecode_commitments
AffinePoint nullifier_key
AppendOnlyTreeSnapshot public_data_tree
AppendOnlyTreeSnapshot l1_to_l2_message_tree
AppendOnlyTreeSnapshot nullifier_tree
AppendOnlyTreeSnapshot note_hash_tree
static NullifierLeafValue empty()
std::vector< crypto::merkle_tree::LeafUpdateWitnessData< LeafValueType > > low_leaf_witness_data
std::vector< crypto::merkle_tree::LeafUpdateWitnessData< LeafValueType > > insertion_witness_data