Skip to content

Commit 9370939

Browse files
committed
feat: WIP first pass hint collecting dbs c++ sim
1 parent 66f43e1 commit 9370939

File tree

13 files changed

+568
-77
lines changed

13 files changed

+568
-77
lines changed

barretenberg/cpp/src/barretenberg/vm2/simulation/gadgets/concrete_dbs.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
namespace bb::avm2::simulation {
88

99
// Contracts DB starts.
10-
std::optional<ContractInstance> ContractDB::get_contract_instance(const AztecAddress& address) const
10+
std::optional<ContractInstance> ContractDB::get_contract_instance(const AztecAddress& address)
1111
{
1212
std::optional<ContractInstance> instance = raw_contract_db.get_contract_instance(address);
1313
// If we didn't get a contract instance, we don't prove anything.
@@ -26,7 +26,7 @@ std::optional<ContractInstance> ContractDB::get_contract_instance(const AztecAdd
2626
return instance;
2727
}
2828

29-
std::optional<ContractClass> ContractDB::get_contract_class(const ContractClassId& class_id) const
29+
std::optional<ContractClass> ContractDB::get_contract_class(const ContractClassId& class_id)
3030
{
3131
std::optional<ContractClass> klass = raw_contract_db.get_contract_class(class_id);
3232
// If we didn't get a contract class, we don't prove anything.

barretenberg/cpp/src/barretenberg/vm2/simulation/gadgets/concrete_dbs.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ class ContractDB final : public ContractDBInterface {
3030
// Gets an instance from the DB and proves address derivation from the result.
3131
// This does NOT prove that the address is in the nullifier tree.
3232
// Silo the address and use the MerkleDB to prove that.
33-
std::optional<ContractInstance> get_contract_instance(const AztecAddress& address) const override;
33+
std::optional<ContractInstance> get_contract_instance(const AztecAddress& address) override;
3434
// Gets a class from the DB and proves class id derivation from the result.
3535
// This does NOT prove that the class id is in the nullifier tree.
3636
// Silo the class id and use the MerkleDB to prove that.
37-
std::optional<ContractClass> get_contract_class(const ContractClassId& class_id) const override;
37+
std::optional<ContractClass> get_contract_class(const ContractClassId& class_id) override;
3838

3939
private:
4040
ContractDBInterface& raw_contract_db;

barretenberg/cpp/src/barretenberg/vm2/simulation/gadgets/update_check.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace {
1111

1212
using UnconstrainedPoseidon2 = crypto::Poseidon2<crypto::Poseidon2Bn254ScalarFieldParams>;
1313

14-
FF unconstrained_read(const LowLevelMerkleDBInterface& merkle_db, const FF& leaf_slot)
14+
FF unconstrained_read(LowLevelMerkleDBInterface& merkle_db, const FF& leaf_slot)
1515
{
1616
auto [present, index] = merkle_db.get_low_indexed_leaf(world_state::MerkleTreeId::PUBLIC_DATA_TREE, leaf_slot);
1717
auto preimage = merkle_db.get_leaf_preimage_public_data_tree(index);

barretenberg/cpp/src/barretenberg/vm2/simulation/interfaces/db.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ class ContractDBInterface {
1818
public:
1919
virtual ~ContractDBInterface() = default;
2020

21-
virtual std::optional<ContractInstance> get_contract_instance(const AztecAddress& address) const = 0;
22-
virtual std::optional<ContractClass> get_contract_class(const ContractClassId& class_id) const = 0;
21+
virtual std::optional<ContractInstance> get_contract_instance(const AztecAddress& address) = 0;
22+
virtual std::optional<ContractClass> get_contract_class(const ContractClassId& class_id) = 0;
2323
};
2424

2525
// Aliases.
@@ -45,13 +45,13 @@ class LowLevelMerkleDBInterface {
4545

4646
virtual TreeSnapshots get_tree_roots() const = 0;
4747

48-
virtual SiblingPath get_sibling_path(MerkleTreeId tree_id, index_t leaf_index) const = 0;
49-
virtual GetLowIndexedLeafResponse get_low_indexed_leaf(MerkleTreeId tree_id, const FF& value) const = 0;
48+
virtual SiblingPath get_sibling_path(MerkleTreeId tree_id, index_t leaf_index) = 0;
49+
virtual GetLowIndexedLeafResponse get_low_indexed_leaf(MerkleTreeId tree_id, const FF& value) = 0;
5050
// Returns the value if it exists, 0 otherwise.
51-
virtual FF get_leaf_value(MerkleTreeId tree_id, index_t leaf_index) const = 0;
51+
virtual FF get_leaf_value(MerkleTreeId tree_id, index_t leaf_index) = 0;
5252
// We don't template the preimage methods because templated methods cannot be virtual.
53-
virtual IndexedLeaf<PublicDataLeafValue> get_leaf_preimage_public_data_tree(index_t leaf_index) const = 0;
54-
virtual IndexedLeaf<NullifierLeafValue> get_leaf_preimage_nullifier_tree(index_t leaf_index) const = 0;
53+
virtual IndexedLeaf<PublicDataLeafValue> get_leaf_preimage_public_data_tree(index_t leaf_index) = 0;
54+
virtual IndexedLeaf<NullifierLeafValue> get_leaf_preimage_nullifier_tree(index_t leaf_index) = 0;
5555

5656
virtual SequentialInsertionResult<PublicDataLeafValue> insert_indexed_leaves_public_data_tree(
5757
const PublicDataLeafValue& leaf_value) = 0;

barretenberg/cpp/src/barretenberg/vm2/simulation/lib/db_types.hpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,18 @@ struct TreeCounters {
1919
};
2020

2121
} // namespace bb::avm2::simulation
22+
23+
// Specialization of std::hash for std::vector<FF> to be used as a key in unordered_flat_map.
24+
// Used in raw_data_dbs and hinting_dbs
25+
namespace std {
26+
template <> struct hash<std::vector<bb::avm2::FF>> {
27+
size_t operator()(const std::vector<bb::avm2::FF>& vec) const
28+
{
29+
size_t seed = vec.size();
30+
for (const auto& item : vec) {
31+
seed ^= std::hash<bb::avm2::FF>{}(item) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
32+
}
33+
return seed;
34+
}
35+
};
36+
} // namespace std

0 commit comments

Comments
 (0)