44 auto wire_rev = revision_to_wire(
revision_);
46 auto l1_info =
client_.get_tree_info(
47 wsdb::WsdbGetTreeInfo{ .treeId = tree_id_to_wire(MerkleTreeId::L1_TO_L2_MESSAGE_TREE), .revision = wire_rev });
48 auto nh_info =
client_.get_tree_info(
49 wsdb::WsdbGetTreeInfo{ .treeId = tree_id_to_wire(MerkleTreeId::NOTE_HASH_TREE), .revision = wire_rev });
50 auto null_info =
client_.get_tree_info(
51 wsdb::WsdbGetTreeInfo{ .treeId = tree_id_to_wire(MerkleTreeId::NULLIFIER_TREE), .revision = wire_rev });
52 auto pd_info =
client_.get_tree_info(
53 wsdb::WsdbGetTreeInfo{ .treeId = tree_id_to_wire(MerkleTreeId::PUBLIC_DATA_TREE), .revision = wire_rev });
57 .next_available_leaf_index = l1_info.size },
59 .next_available_leaf_index = nh_info.size },
61 .next_available_leaf_index = null_info.size },
63 .next_available_leaf_index = pd_info.size },
80 auto resp =
client_.get_sibling_path(wsdb::WsdbGetSiblingPath{
81 .treeId = tree_id_to_wire(tree_id), .revision = revision_to_wire(
revision_), .leafIndex = leaf_index });
82 return fr_vec_from_wire(resp.path);
88 auto resp =
client_.find_low_leaf(wsdb::WsdbFindLowLeaf{
89 .treeId = tree_id_to_wire(tree_id), .revision = revision_to_wire(
revision_), .key = fr_to_wire(
value) });
95 auto resp =
client_.get_leaf_value(wsdb::WsdbGetLeafValue{
96 .treeId = tree_id_to_wire(tree_id), .revision = revision_to_wire(
revision_), .leafIndex = leaf_index });
97 if (!resp.value.has_value()) {
98 throw std::runtime_error(
"Invalid get_leaf_value request for tree " +
102 return fr_from_wire(resp.value.value());
107 auto resp =
client_.get_public_data_leaf_preimage(
108 wsdb::WsdbGetPublicDataLeafPreimage{ .revision = revision_to_wire(
revision_), .leafIndex = leaf_index });
109 if (!resp.preimage.has_value()) {
110 throw std::runtime_error(
"Invalid get_leaf_preimage_public_data_tree request for index " +
113 return indexed_public_data_leaf_from_wire(resp.preimage.value());
118 auto resp =
client_.get_nullifier_leaf_preimage(
119 wsdb::WsdbGetNullifierLeafPreimage{ .revision = revision_to_wire(
revision_), .leafIndex = leaf_index });
120 if (!resp.preimage.has_value()) {
121 throw std::runtime_error(
"Invalid get_leaf_preimage_nullifier_tree request for index " +
124 return indexed_nullifier_leaf_from_wire(resp.preimage.value());
134 auto resp =
client_.sequential_insert_public_data(wsdb::WsdbSequentialInsertPublicData{
135 .leaves = { public_data_leaf_to_wire(leaf_value) }, .forkId =
revision_.
forkId });
137 return sequential_public_data_from_wire(resp.result);
143 auto resp =
client_.sequential_insert_nullifier(wsdb::WsdbSequentialInsertNullifier{
144 .leaves = { nullifier_leaf_to_wire(leaf_value) }, .forkId =
revision_.
forkId });
146 return sequential_nullifier_from_wire(resp.result);
151 std::vector<Fr> wire_leaves;
152 wire_leaves.reserve(leaves.size());
153 for (
const auto& leaf : leaves) {
154 wire_leaves.push_back(fr_to_wire(leaf));
156 client_.append_leaves(wsdb::WsdbAppendLeaves{
164 case MerkleTreeId::NULLIFIER_TREE: {
166 padding_leaves.reserve(num_leaves);
168 for (
size_t i = 0; i < num_leaves; i++) {
169 padding_leaves.push_back(nullifier_leaf_to_wire(empty_leaf));
171 client_.batch_insert_nullifier(wsdb::WsdbBatchInsertNullifier{ .leaves =
std::move(padding_leaves),
176 case MerkleTreeId::NOTE_HASH_TREE: {
177 std::vector<Fr> padding_leaves;
178 padding_leaves.reserve(num_leaves);
180 for (
size_t i = 0; i < num_leaves; i++) {
181 padding_leaves.push_back(fr_to_wire(zero));
183 client_.append_leaves(wsdb::WsdbAppendLeaves{ .treeId = tree_id_to_wire(MerkleTreeId::NOTE_HASH_TREE),
189 throw std::runtime_error(
"Padding not supported for tree " +
std::to_string(
static_cast<uint64_t
>(tree_id)));
#define NULLIFIER_SUBTREE_HEIGHT
void revert_checkpoint() override
avm2::simulation::IndexedLeaf< avm2::simulation::PublicDataLeafValue > get_leaf_preimage_public_data_tree(avm2::simulation::index_t leaf_index) const override
world_state::WorldStateRevision revision_
void invalidate_tree_roots_cache()
avm2::FF get_leaf_value(avm2::simulation::MerkleTreeId tree_id, avm2::simulation::index_t leaf_index) const override
wsdb::WsdbIpcClient & client_
crypto::merkle_tree::GetLowIndexedLeafResponse get_low_indexed_leaf(avm2::simulation::MerkleTreeId tree_id, const avm2::FF &value) const override
void pad_tree(avm2::simulation::MerkleTreeId tree_id, size_t num_leaves) override
WsdbIpcMerkleDB(wsdb::WsdbIpcClient &client, world_state::WorldStateRevision revision)
Construct from a connected WSDB IPC client and world state revision.
uint32_t get_checkpoint_id() const override
void create_checkpoint() override
avm2::simulation::SequentialInsertionResult< avm2::simulation::NullifierLeafValue > insert_indexed_leaves_nullifier_tree(const avm2::simulation::NullifierLeafValue &leaf_value) override
void commit_checkpoint() override
avm2::TreeSnapshots get_tree_roots() const override
avm2::simulation::IndexedLeaf< avm2::simulation::NullifierLeafValue > get_leaf_preimage_nullifier_tree(avm2::simulation::index_t leaf_index) const override
std::stack< uint32_t > checkpoint_stack_
void append_leaves(avm2::simulation::MerkleTreeId tree_id, std::span< const avm2::FF > leaves) override
avm2::simulation::SequentialInsertionResult< avm2::simulation::PublicDataLeafValue > insert_indexed_leaves_public_data_tree(const avm2::simulation::PublicDataLeafValue &leaf_value) override
std::optional< avm2::TreeSnapshots > cached_tree_roots_
avm2::simulation::SiblingPath get_sibling_path(avm2::simulation::MerkleTreeId tree_id, avm2::simulation::index_t leaf_index) const override
AVM range check gadget for witness generation.
::bb::crypto::merkle_tree::fr_sibling_path SiblingPath
::bb::crypto::merkle_tree::index_t index_t
std::vector< bb::fr > fr_vec_from_wire(const std::vector< Fr > &w)
world_state::SequentialInsertionResult< crypto::merkle_tree::NullifierLeafValue > sequential_nullifier_from_wire(const wire::SequentialInsertionResultNullifier &w)
wire::NullifierLeafValue nullifier_leaf_to_wire(const crypto::merkle_tree::NullifierLeafValue &d)
wire::WorldStateRevision revision_to_wire(const world_state::WorldStateRevision &d)
crypto::merkle_tree::IndexedLeaf< crypto::merkle_tree::PublicDataLeafValue > indexed_public_data_leaf_from_wire(const wire::IndexedPublicDataLeafValue &w)
Fr fr_to_wire(const bb::fr &d)
world_state::SequentialInsertionResult< crypto::merkle_tree::PublicDataLeafValue > sequential_public_data_from_wire(const wire::SequentialInsertionResultPublicData &w)
MerkleTreeId tree_id_to_wire(world_state::MerkleTreeId d)
wire::PublicDataLeafValue public_data_leaf_to_wire(const crypto::merkle_tree::PublicDataLeafValue &d)
bb::fr fr_from_wire(const Fr &w)
crypto::merkle_tree::IndexedLeaf< crypto::merkle_tree::NullifierLeafValue > indexed_nullifier_leaf_from_wire(const wire::IndexedNullifierLeafValue &w)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
std::string to_string(bb::avm2::ValueTag tag)
AppendOnlyTreeSnapshot l1_to_l2_message_tree
static NullifierLeafValue empty()
LowLevelMerkleDBInterface implementation backed by WSDB IPC.
Wire <-> domain conversion helpers for the aztec-wsdb service.