11#include " barretenberg/vm2/simulation/lib/hinting_dbs.hpp"
22
3- #include < cassert>
43#include < cstdint>
54#include < optional>
65#include < span>
109
1110#include " barretenberg/common/bb_bench.hpp"
1211#include " barretenberg/common/log.hpp"
13- #include " barretenberg/crypto/merkle_tree/indexed_tree/indexed_leaf.hpp"
1412#include " barretenberg/vm2/common/avm_inputs.hpp"
1513#include " barretenberg/vm2/common/aztec_types.hpp"
16- #include " barretenberg/vm2/generated/relations/lookups_contract_instance_retrieval.hpp"
1714#include " barretenberg/vm2/simulation/interfaces/db.hpp"
1815#include " barretenberg/vm2/simulation/lib/contract_crypto.hpp"
1916
@@ -41,15 +38,15 @@ auto& get_tree_info_helper(world_state::MerkleTreeId tree_id, const auto& tree_r
4138} // namespace
4239
4340// HintingContractsDB starts.
44- std::optional<ContractInstance> HintingContractsDB::get_contract_instance (const AztecAddress& address)
41+ std::optional<ContractInstance> HintingContractsDB::get_contract_instance (const AztecAddress& address) const
4542{
4643 info (" HintingContractsDB get_contract_instance" );
4744 auto instance = db.get_contract_instance (address);
4845 // If we don't find the instance hint, this is not a catastrophic failure. The inner db should handle it, and
4946 // here we simply don't store any hint:
5047 if (instance.has_value ()) {
5148 // TODO(MW): Use/write instance to hint methods for ContractInstance, PublicKeys, ContractClass, etc.
52- contract_instances[address] = ContractInstanceHint{
49+ mapped_hints. contract_instances [address] = ContractInstanceHint{
5350 .address = address,
5451 .salt = instance->salt ,
5552 .deployer = instance->deployer_addr ,
@@ -67,23 +64,23 @@ std::optional<ContractInstance> HintingContractsDB::get_contract_instance(const
6764 return instance;
6865}
6966
70- std::optional<ContractClass> HintingContractsDB::get_contract_class (const ContractClassId& class_id)
67+ std::optional<ContractClass> HintingContractsDB::get_contract_class (const ContractClassId& class_id) const
7168{
7269 info (" HintingContractsDB get_contract_class" );
7370 auto klass = db.get_contract_class (class_id);
7471 // If we don't find the instance hint, this is not a catastrophic failure. The inner db should handle it, and
7572 // here we simply don't store any hint:
7673 if (klass.has_value ()) {
7774 // TODO(MW): Use/write instance to hint methods for ContractInstance, PublicKeys, ContractClass, etc.
78- contract_classes[class_id] = ContractClassHint{
75+ mapped_hints. contract_classes [class_id] = ContractClassHint{
7976 .classId = class_id,
8077 .artifactHash = klass->artifact_hash ,
8178 .privateFunctionsRoot = klass->private_function_root ,
8279 .packedBytecode = klass->packed_bytecode ,
8380 };
8481 // Note: HintedRawContractDB accesses the bytecode commitment 'hint' during get_contract_class, so following
8582 // same logic here:
86- bytecode_commitments[class_id] =
83+ mapped_hints. bytecode_commitments [class_id] =
8784 BytecodeCommitmentHint{ .classId = class_id, .commitment = klass->public_bytecode_commitment };
8885 }
8986
@@ -93,13 +90,13 @@ std::optional<ContractClass> HintingContractsDB::get_contract_class(const Contra
9390void HintingContractsDB::dump_hints (ExecutionHints& hints)
9491{
9592 // TODO(MW): better way than to iterate? do we want push_back?
96- for (const auto & contract_instance : contract_instances) {
93+ for (const auto & contract_instance : mapped_hints. contract_instances ) {
9794 hints.contractInstances .push_back (contract_instance.second );
9895 }
99- for (const auto & contract_class : contract_classes) {
96+ for (const auto & contract_class : mapped_hints. contract_classes ) {
10097 hints.contractClasses .push_back (contract_class.second );
10198 }
102- for (const auto & bytecode_commitment : bytecode_commitments) {
99+ for (const auto & bytecode_commitment : mapped_hints. bytecode_commitments ) {
103100 hints.bytecodeCommitments .push_back (bytecode_commitment.second );
104101 }
105102}
@@ -110,61 +107,61 @@ const AppendOnlyTreeSnapshot& HintingRawDB::get_tree_info(world_state::MerkleTre
110107 return get_tree_info_helper (tree_id, db.get_tree_roots ());
111108}
112109
113- SiblingPath HintingRawDB::get_sibling_path (world_state::MerkleTreeId tree_id, index_t leaf_index)
110+ SiblingPath HintingRawDB::get_sibling_path (world_state::MerkleTreeId tree_id, index_t leaf_index) const
114111{
115112 info (" HintingRawDB get_sib: " , leaf_index);
116113 auto tree_info = get_tree_info (tree_id);
117114 auto path = db.get_sibling_path (tree_id, leaf_index);
118115 GetSiblingPathKey key = { tree_info, tree_id, leaf_index };
119- get_sibling_path_hints[key] = path;
116+ query_hints. get_sibling_path_hints [key] = path;
120117
121118 return path;
122119}
123120
124- GetLowIndexedLeafResponse HintingRawDB::get_low_indexed_leaf (world_state::MerkleTreeId tree_id, const FF& value)
121+ GetLowIndexedLeafResponse HintingRawDB::get_low_indexed_leaf (world_state::MerkleTreeId tree_id, const FF& value) const
125122{
126123 info (" HintingRawDB get_low_indexed_leaf" );
127124 auto tree_info = get_tree_info (tree_id);
128125 auto resp = db.get_low_indexed_leaf (tree_id, value);
129126 GetPreviousValueIndexKey key = { tree_info, tree_id, value };
130- get_previous_value_index_hints[key] = { resp.is_already_present , resp.index };
127+ query_hints. get_previous_value_index_hints [key] = { resp.is_already_present , resp.index };
131128 // TODO(MW): We may need a sibling path hint so must collect it in case - see comments in public_db_sources.ts
132129 get_sibling_path (tree_id, resp.index );
133130 return resp;
134131}
135132
136- FF HintingRawDB::get_leaf_value (world_state::MerkleTreeId tree_id, index_t leaf_index)
133+ FF HintingRawDB::get_leaf_value (world_state::MerkleTreeId tree_id, index_t leaf_index) const
137134{
138135 info (" HintingRawDB get_leaf_value" );
139136 auto tree_info = get_tree_info (tree_id);
140137 auto value = db.get_leaf_value (tree_id, leaf_index);
141138 GetLeafValueKey key = { tree_info, tree_id, leaf_index };
142- get_leaf_value_hints[key] = value;
139+ query_hints. get_leaf_value_hints [key] = value;
143140 // TODO(MW): We may need a sibling path hint so must collect it in case - see comments in public_db_sources.ts
144141 get_sibling_path (tree_id, leaf_index);
145142 return value;
146143}
147144
148- IndexedLeaf<PublicDataLeafValue> HintingRawDB::get_leaf_preimage_public_data_tree (index_t leaf_index)
145+ IndexedLeaf<PublicDataLeafValue> HintingRawDB::get_leaf_preimage_public_data_tree (index_t leaf_index) const
149146{
150147 info (" HintingRawDB get_leaf_preimage_public_data_tree" );
151148 auto tree_info = get_tree_info (world_state::MerkleTreeId::PUBLIC_DATA_TREE);
152149 auto preimage = db.get_leaf_preimage_public_data_tree (leaf_index);
153150
154151 GetLeafPreimageKey key = { tree_info, leaf_index };
155- get_leaf_preimage_hints_public_data_tree[key] = preimage;
152+ query_hints. get_leaf_preimage_hints_public_data_tree [key] = preimage;
156153 // TODO(MW): We may need a sibling path hint so must collect it in case - see comments in public_db_sources.ts
157154 get_sibling_path (world_state::MerkleTreeId::PUBLIC_DATA_TREE, leaf_index);
158155 return preimage;
159156}
160157
161- IndexedLeaf<NullifierLeafValue> HintingRawDB::get_leaf_preimage_nullifier_tree (index_t leaf_index)
158+ IndexedLeaf<NullifierLeafValue> HintingRawDB::get_leaf_preimage_nullifier_tree (index_t leaf_index) const
162159{
163160 info (" HintingRawDB get_leaf_preimage_nullifier_tree" );
164161 auto tree_info = get_tree_info (world_state::MerkleTreeId::NULLIFIER_TREE);
165162 auto preimage = db.get_leaf_preimage_nullifier_tree (leaf_index);
166163 GetLeafPreimageKey key = { tree_info, leaf_index };
167- get_leaf_preimage_hints_nullifier_tree[key] = preimage;
164+ query_hints. get_leaf_preimage_hints_nullifier_tree [key] = preimage;
168165 // TODO(MW): We may need a sibling path hint so must collect it in case - see comments in public_db_sources.ts
169166 get_sibling_path (world_state::MerkleTreeId::NULLIFIER_TREE, leaf_index);
170167 return preimage;
@@ -320,12 +317,12 @@ AppendOnlyTreeSnapshot HintingRawDB::appendLeafInternal(AppendOnlyTreeSnapshot s
320317void HintingRawDB::dump_hints (ExecutionHints& hints)
321318{
322319 // TODO(MW): better way than to iterate? do we want push_back?
323- for (const auto & get_sibling_path_hint : get_sibling_path_hints) {
320+ for (const auto & get_sibling_path_hint : query_hints. get_sibling_path_hints ) {
324321 auto [hint_key, tree_id, index] = get_sibling_path_hint.first ;
325322 hints.getSiblingPathHints .push_back (GetSiblingPathHint{
326323 .hintKey = hint_key, .treeId = tree_id, .index = index, .path = get_sibling_path_hint.second });
327324 }
328- for (const auto & get_previous_value_index_hint : get_previous_value_index_hints) {
325+ for (const auto & get_previous_value_index_hint : query_hints. get_previous_value_index_hints ) {
329326 auto [hint_key, tree_id, value] = get_previous_value_index_hint.first ;
330327 hints.getPreviousValueIndexHints .push_back (GetPreviousValueIndexHint{
331328 .hintKey = hint_key,
@@ -335,17 +332,17 @@ void HintingRawDB::dump_hints(ExecutionHints& hints)
335332 .alreadyPresent = get_previous_value_index_hint.second .is_already_present ,
336333 });
337334 }
338- for (const auto & get_leaf_preimage_hint : get_leaf_preimage_hints_public_data_tree) {
335+ for (const auto & get_leaf_preimage_hint : query_hints. get_leaf_preimage_hints_public_data_tree ) {
339336 auto [hint_key, index] = get_leaf_preimage_hint.first ;
340337 hints.getLeafPreimageHintsPublicDataTree .push_back (
341338 { .hintKey = hint_key, .index = index, .leafPreimage = get_leaf_preimage_hint.second });
342339 }
343- for (const auto & get_leaf_preimage_hint : get_leaf_preimage_hints_nullifier_tree) {
340+ for (const auto & get_leaf_preimage_hint : query_hints. get_leaf_preimage_hints_nullifier_tree ) {
344341 auto [hint_key, index] = get_leaf_preimage_hint.first ;
345342 hints.getLeafPreimageHintsNullifierTree .push_back (
346343 { .hintKey = hint_key, .index = index, .leafPreimage = get_leaf_preimage_hint.second });
347344 }
348- for (const auto & get_leaf_value_hint : get_leaf_value_hints) {
345+ for (const auto & get_leaf_value_hint : query_hints. get_leaf_value_hints ) {
349346 auto [hint_key, tree_id, index] = get_leaf_value_hint.first ;
350347 hints.getLeafValueHints .push_back (GetLeafValueHint{
351348 .hintKey = hint_key, .treeId = tree_id, .index = index, .value = get_leaf_value_hint.second });
0 commit comments