77#include < string>
88#include < vector>
99
10- #include " barretenberg/common/bb_bench.hpp"
1110#include " barretenberg/common/log.hpp"
1211#include " barretenberg/vm2/common/avm_inputs.hpp"
1312#include " barretenberg/vm2/common/aztec_types.hpp"
@@ -127,6 +126,22 @@ GetLowIndexedLeafResponse HintingRawDB::get_low_indexed_leaf(world_state::Merkle
127126 query_hints.get_previous_value_index_hints [key] = { resp.is_already_present , resp.index };
128127 // TODO(MW): We may need a sibling path hint so must collect it in case - see comments in public_db_sources.ts
129128 get_sibling_path (tree_id, resp.index );
129+
130+ if (tree_id == world_state::MerkleTreeId::NULLIFIER_TREE) {
131+ // TODO(MW): We may need a GetLeafPreimageHint for the nullifier tree when calling nullifier_exists, so collect
132+ // it
133+ // in case.
134+ // NB: The PureMerkleDB does not perform this, but the nullifier check gadget requires a leaf preimage. Ts
135+ // gathers the hint: (state_manager -> checkNullifierExists() -> doMerkleOperations -> public_db_sources ->
136+ // checkNullifierExists())
137+ get_leaf_preimage_nullifier_tree (resp.index );
138+ } else if ((tree_id == world_state::MerkleTreeId::PUBLIC_DATA_TREE) && (!resp.is_already_present )) {
139+ // TODO(MW): We may need a GetLeafPreimageHint for the public data tree when calling storage_read, so collect it
140+ // in case.
141+ // NB: The PureMerkleDB does not perform this if !is_already_present, but MerkleDB and ts perform it
142+ // unconditionally. Ts gathers the hint: (public_db_sources -> storageRead())
143+ get_leaf_preimage_public_data_tree (resp.index );
144+ }
130145 return resp;
131146}
132147
@@ -286,14 +301,14 @@ std::vector<AppendLeafResult> HintingRawDB::append_leaves(world_state::MerkleTre
286301 for (uint32_t i = 0 ; i < leaves.size (); i++) {
287302 FF root_after = i == leaves.size () - 1 ? get_tree_info (tree_id).root : results[i + 1 ].root ;
288303 // Iterate tree_info to the be state after adding this leaf:
289- tree_info = appendLeafInternal (tree_info, root_after, tree_id, leaves[i]);
304+ tree_info = appendLeafInternal (tree_info, results[i]. path , root_after, tree_id, leaves[i]);
290305 }
291306
292307 return results;
293308}
294309
295- // TODO(MW): rework
296310AppendOnlyTreeSnapshot HintingRawDB::appendLeafInternal (AppendOnlyTreeSnapshot state_before,
311+ SiblingPath& path,
297312 const FF& root_after,
298313 world_state::MerkleTreeId tree_id,
299314 const FF& leaf)
@@ -303,14 +318,15 @@ AppendOnlyTreeSnapshot HintingRawDB::appendLeafInternal(AppendOnlyTreeSnapshot s
303318 // constraint the insertion.
304319 // TODO(https://github.com/AztecProtocol/aztec-packages/issues/13380): This can be changed if the world state
305320 // appendLeaves returns the sibling paths.
306- AppendLeavesHintKey key = { state_before, tree_id, { leaf } };
321+ AppendLeavesHintKey append_key = { state_before, tree_id, { leaf } };
307322 AppendOnlyTreeSnapshot state_after = { .root = root_after,
308323 .nextAvailableLeafIndex = state_before.nextAvailableLeafIndex + 1 };
309- append_leaves_hints[key] = state_after;
310- // TODO(MW): Just store hint using result in append_leaves to avoid unnecessary extra calls to underlying db?
311- // NOTE: this call will use the /current/ db.get_tree_info() (post full append_leaves), which may not match that at
312- // root_after:
313- get_sibling_path (tree_id, state_before.nextAvailableLeafIndex );
324+ append_leaves_hints[append_key] = state_after;
325+ // TODO(MW): Storing sibling path hint manually using the result since a get_sibling_path() call here will use the
326+ // /current/ db.get_tree_info() (post full append_leaves), which may not match that at result.root. We may not care
327+ // about this (see comment in PureRawMerkleDB::append_leaves())
328+ GetSiblingPathKey path_key = { state_after, tree_id, state_before.nextAvailableLeafIndex };
329+ query_hints.get_sibling_path_hints [path_key] = path;
314330 return state_after;
315331}
316332
0 commit comments