21std::string
to_string(
const TreeSnapshots& snapshots)
23 return format(
"PUBLIC_DATA_TREE: ",
24 snapshots.public_data_tree,
26 snapshots.nullifier_tree,
28 snapshots.note_hash_tree,
29 "\nL1_TO_L2_MESSAGE_TREE: ",
30 snapshots.l1_to_l2_message_tree);
37 return "PUBLIC_DATA_TREE";
39 return "NULLIFIER_TREE";
41 return "NOTE_HASH_TREE";
43 return "L1_TO_L2_MESSAGE_TREE";
58 vinfo(
"Initializing HintedRawContractDB with...",
59 "\n * contract_instances: ",
61 "\n * contract_classes: ",
63 "\n * bytecode_commitments: ",
65 "\n * debug_function_names: ",
69 contract_instances[std::make_tuple(contract_instance_hint.hint_key, contract_instance_hint.address)] =
70 contract_instance_hint;
74 contract_classes[std::make_tuple(contract_class_hint.hint_key, contract_class_hint.class_id)] =
79 bytecode_commitments[std::make_tuple(bytecode_commitment_hint.hint_key, bytecode_commitment_hint.class_id)] =
80 bytecode_commitment_hint.commitment;
85 debug_function_name_hint.name;
102 auto key = std::make_tuple(hint_key,
address);
105 vinfo(
"Contract instance not found for key (", hint_key,
", ",
address,
")");
108 const auto& contract_instance_hint = it->second;
111 .salt = contract_instance_hint.salt,
112 .deployer = contract_instance_hint.deployer,
113 .current_contract_class_id = contract_instance_hint.current_contract_class_id,
114 .original_contract_class_id = contract_instance_hint.original_contract_class_id,
115 .initialization_hash = contract_instance_hint.initialization_hash,
118 .
nullifier_key = contract_instance_hint.public_keys.master_nullifier_public_key,
119 .incoming_viewing_key = contract_instance_hint.public_keys.master_incoming_viewing_public_key,
120 .outgoing_viewing_key = contract_instance_hint.public_keys.master_outgoing_viewing_public_key,
121 .tagging_key = contract_instance_hint.public_keys.master_tagging_public_key,
132 vinfo(
"Contract class not found for key (", hint_key,
", ",
class_id,
")");
135 const auto& contract_class_hint = it->second;
139 .artifact_hash = contract_class_hint.artifact_hash,
140 .private_functions_root = contract_class_hint.private_functions_root,
141 .packed_bytecode = contract_class_hint.packed_bytecode,
151 vinfo(
"Bytecode commitment not found for key (", hint_key,
", ",
class_id,
")");
169 debug(
"add_contracts called (no-op in hinted mode)");
177 const auto& hint = hint_it->second;
179 hint.old_checkpoint_id,
checkpoint_stack.top(),
"Old checkpoint id does not match the current checkpoint id");
190 const auto& hint = hint_it->second;
192 hint.old_checkpoint_id,
checkpoint_stack.top(),
"Old checkpoint id does not match the current checkpoint id");
196 hint.new_checkpoint_id,
checkpoint_stack.top(),
"New checkpoint id does not match the current checkpoint id");
205 const auto& hint = hint_it->second;
207 hint.old_checkpoint_id,
checkpoint_stack.top(),
"Old checkpoint id does not match the current checkpoint id");
211 hint.new_checkpoint_id,
checkpoint_stack.top(),
"New checkpoint id does not match the current checkpoint id");
222 : tree_roots(hints.starting_tree_roots)
226 vinfo(
"Initializing HintedRawMerkleDB with...",
227 "\n * get_sibling_path_hints: ",
229 "\n * get_previous_value_index_hints: ",
231 "\n * get_leaf_preimage_hints_public_data_tree: ",
233 "\n * get_leaf_preimage_hints_nullifier_tree: ",
235 "\n * get_leaf_value_hints: ",
237 "\n * sequential_insert_hints_public_data_tree: ",
239 "\n * sequential_insert_hints_nullifier_tree: ",
241 "\n * append_leaves_hints: ",
243 "\n * create_checkpoint_hints: ",
245 "\n * commit_checkpoint_hints: ",
247 "\n * revert_checkpoint_hints: ",
253 get_sibling_path_hint.tree_id,
254 get_sibling_path_hint.index };
260 get_previous_value_index_hint.tree_id,
261 get_previous_value_index_hint.value };
263 get_previous_value_index_hint.already_present,
264 get_previous_value_index_hint.index,
279 GetLeafValueKey key = { get_leaf_value_hint.hint_key, get_leaf_value_hint.tree_id, get_leaf_value_hint.index };
285 sequential_insert_hint.tree_id,
286 sequential_insert_hint.leaf };
292 sequential_insert_hint.tree_id,
293 sequential_insert_hint.leaf };
300 append_leaves_hint.tree_id,
301 append_leaves_hint.leaves };
334 throw std::runtime_error(
format(
"Sibling path not found for key (root: ",
337 tree_info.next_available_leaf_index,
339 get_tree_name(tree_id),
354 throw std::runtime_error(
format(
"Low indexed leaf not found for key (root: ",
357 tree_info.next_available_leaf_index,
359 get_tree_name(tree_id),
373 throw std::runtime_error(
format(
"Leaf value not found for key (root: ",
376 tree_info.next_available_leaf_index,
378 get_tree_name(tree_id),
392 throw std::runtime_error(
format(
"Leaf preimage (PUBLIC_DATA_TREE) not found for key (root: ",
395 tree_info.next_available_leaf_index,
409 throw std::runtime_error(
format(
"Leaf preimage (NULLIFIER_TREE) not found for key (root: ",
412 tree_info.next_available_leaf_index,
427 throw std::runtime_error(
format(
"Sequential insert hint (PUBLIC_DATA_TREE) not found for key (root: ",
430 tree_info.next_available_leaf_index,
435 const auto& hint = it->second;
441 hint.low_leaves_witness_data.leaf, hint.low_leaves_witness_data.index, hint.low_leaves_witness_data.path);
445 hint.insertion_witness_data.leaf, hint.insertion_witness_data.index, hint.insertion_witness_data.path);
450 debug(
"Evolved state of PUBLIC_DATA_TREE: ",
466 throw std::runtime_error(
format(
"Sequential insert hint (NULLIFIER_TREE) not found for key (root: ",
469 tree_info.next_available_leaf_index,
474 const auto& hint = it->second;
480 hint.low_leaves_witness_data.leaf, hint.low_leaves_witness_data.index, hint.low_leaves_witness_data.path);
484 hint.insertion_witness_data.leaf, hint.insertion_witness_data.index, hint.insertion_witness_data.path);
489 debug(
"Evolved state of NULLIFIER_TREE: ",
502 throw std::runtime_error(
505 const auto& hint = it->second;
509 throw std::runtime_error(
format(
"[create_checkpoint@",
511 "] Old checkpoint id does not match the current checkpoint id: ",
512 hint.old_checkpoint_id,
517 debug(
"[create_checkpoint@",
519 "] Checkpoint evolved ",
520 hint.old_checkpoint_id,
522 hint.new_checkpoint_id);
532 throw std::runtime_error(
535 const auto& hint = it->second;
539 throw std::runtime_error(
format(
"[commit_checkpoint@",
541 "] Old checkpoint id does not match the current checkpoint id: ",
542 hint.old_checkpoint_id,
551 throw std::runtime_error(
format(
"[commit_checkpoint@",
553 "] New checkpoint id does not match the current checkpoint id: ",
554 hint.new_checkpoint_id,
559 debug(
"[commit_checkpoint@",
561 "] Checkpoint evolved ",
562 hint.old_checkpoint_id,
564 hint.new_checkpoint_id);
573 throw std::runtime_error(
576 const auto& hint = it->second;
580 throw std::runtime_error(
format(
"[revert_checkpoint@",
582 "] Old checkpoint id does not match the current checkpoint id: ",
583 hint.old_checkpoint_id,
592 throw std::runtime_error(
format(
"[revert_checkpoint@",
594 "] Hint tree snapshots do not match the current tree roots."));
601 throw std::runtime_error(
format(
"[revert_checkpoint@",
603 "] New checkpoint id does not match the current checkpoint id: ",
604 hint.new_checkpoint_id,
612 debug(
"[revert_checkpoint@",
614 "] Checkpoint evolved ",
615 hint.old_checkpoint_id,
617 hint.new_checkpoint_id);
628 throw std::runtime_error(
format(
"Append leaves hint not found for key (root: ",
631 tree_info.next_available_leaf_index,
633 get_tree_name(tree_id),
635 std::vector<FF>(leaves.begin(), leaves.end()),
644 debug(
"Evolved state of NOTE_HASH_TREE: ",
652 debug(
"Evolved state of L1_TO_L2_MESSAGE_TREE: ",
659 throw std::runtime_error(
"append_leaves is only supported for NOTE_HASH_TREE and L1_TO_L2_MESSAGE_TREE");
666 auto size_before = tree_info.next_available_leaf_index;
668 tree_info.next_available_leaf_index += num_leaves;
670 debug(
"Padded tree ",
671 get_tree_name(tree_id),
675 tree_info.next_available_leaf_index);
697 .next_available_leaf_index = l1_to_l2_info.meta.size },
699 .next_available_leaf_index = note_hash_info.meta.size },
701 .next_available_leaf_index = nullifier_info.meta.size },
703 .next_available_leaf_index = public_data_info.meta.size },
710 return tree_snapshots;
727 if (!res.has_value()) {
728 throw std::runtime_error(
729 format(
"Invalid get_leaf_value request",
static_cast<uint64_t
>(tree_id),
" for index ", leaf_index));
739 if (!res.has_value()) {
740 throw std::runtime_error(
format(
"Invalid get_leaf_preimage_public_data_tree request for index ", leaf_index));
750 if (!res.has_value()) {
751 throw std::runtime_error(
format(
"Invalid get_leaf_preimage_nullifier_tree request for index ", leaf_index));
806 case MerkleTreeId::NULLIFIER_TREE: {
812 case MerkleTreeId::NOTE_HASH_TREE: {
813 std::vector<FF> padding_leaves(num_leaves,
FF(0));
818 throw std::runtime_error(
"Padding not supported for tree " +
std::to_string(
static_cast<uint64_t
>(tree_id)));
#define BB_ASSERT(expression,...)
#define BB_ASSERT_EQ(actual, expected,...)
#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
void commit_checkpoint() override
void revert_checkpoint() override
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
void append_leaves(MerkleTreeId tree_id, std::span< const FF > 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
void append_leaves(MerkleTreeId tree_id, std::span< const FF > leaves) override
world_state::WorldState & ws_instance
IndexedLeaf< NullifierLeafValue > get_leaf_preimage_nullifier_tree(index_t leaf_index) const override
void commit_checkpoint() override
GetLowIndexedLeafResponse get_low_indexed_leaf(MerkleTreeId tree_id, const FF &value) const override
std::optional< TreeSnapshots > cached_tree_snapshots
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
void throw_if_cancelled() const
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