Skip to content

Commit 9071ea2

Browse files
authored
feat: merge-train/barretenberg (#20677)
BEGIN_COMMIT_OVERRIDE chore: update merkle tree audit scope (#20666) feat!: translator revision (#20273) END_COMMIT_OVERRIDE
2 parents 28ff8b6 + 8dc9a29 commit 9071ea2

File tree

102 files changed

+8536
-8734
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+8536
-8734
lines changed

barretenberg/cpp/scripts/audit/audit_scopes/merkle_tree_audit_scope.md

Lines changed: 38 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,59 +6,53 @@ Commit hash: TBD (link)
66
## Files to Audit
77
Note: Paths relative to `aztec-packages/barretenberg/cpp/src/barretenberg`
88

9-
### Core Merkle Tree Implementation
10-
1. `crypto/merkle_tree/merkle_tree.hpp`
11-
2. `crypto/merkle_tree/memory_tree.hpp`
12-
3. `crypto/merkle_tree/hash.hpp`
13-
4. `crypto/merkle_tree/hash_path.hpp`
14-
5. `crypto/merkle_tree/types.hpp`
15-
6. `crypto/merkle_tree/index.hpp`
16-
7. `crypto/merkle_tree/response.hpp`
17-
8. `crypto/merkle_tree/signal.hpp`
18-
19-
### Storage Implementations
20-
9. `crypto/merkle_tree/memory_store.hpp`
21-
10. `crypto/merkle_tree/lmdb_store/lmdb_tree_store.cpp`
22-
11. `crypto/merkle_tree/lmdb_store/lmdb_tree_store.hpp`
23-
24-
### Node Store
25-
12. `crypto/merkle_tree/node_store/array_store.hpp`
26-
13. `crypto/merkle_tree/node_store/cached_content_addressed_tree_store.hpp`
27-
14. `crypto/merkle_tree/node_store/content_addressed_cache.hpp`
28-
15. `crypto/merkle_tree/node_store/tree_meta.hpp`
9+
### Core Types and Utilities
10+
1. `crypto/merkle_tree/types.hpp`
11+
2. `crypto/merkle_tree/hash.hpp`
12+
3. `crypto/merkle_tree/hash_path.hpp`
13+
4. `crypto/merkle_tree/response.hpp`
14+
5. `crypto/merkle_tree/signal.hpp`
15+
16+
### Storage Layer
17+
6. `crypto/merkle_tree/lmdb_store/lmdb_tree_store.hpp`
18+
7. `crypto/merkle_tree/lmdb_store/lmdb_tree_store.cpp`
19+
20+
### Node Store (Cache + Metadata)
21+
8. `crypto/merkle_tree/node_store/cached_content_addressed_tree_store.hpp`
22+
9. `crypto/merkle_tree/node_store/content_addressed_cache.hpp`
23+
10. `crypto/merkle_tree/node_store/tree_meta.hpp`
2924

3025
### Append-Only Tree
31-
16. `crypto/merkle_tree/append_only_tree/content_addressed_append_only_tree.hpp`
26+
11. `crypto/merkle_tree/append_only_tree/content_addressed_append_only_tree.hpp`
3227

3328
### Indexed Tree
34-
17. `crypto/merkle_tree/indexed_tree/content_addressed_indexed_tree.hpp`
35-
18. `crypto/merkle_tree/indexed_tree/indexed_leaf.hpp`
36-
19. `crypto/merkle_tree/indexed_tree/fixtures.hpp`
37-
38-
### Nullifier Tree
39-
20. `crypto/merkle_tree/nullifier_tree/nullifier_tree.cpp`
40-
21. `crypto/merkle_tree/nullifier_tree/nullifier_tree.hpp`
41-
22. `crypto/merkle_tree/nullifier_tree/nullifier_memory_tree.hpp`
42-
23. `crypto/merkle_tree/nullifier_tree/nullifier_leaf.hpp`
43-
44-
### Test Fixtures
45-
24. `crypto/merkle_tree/fixtures.hpp`
46-
25. `crypto/merkle_tree/test_fixtures.hpp`
29+
12. `crypto/merkle_tree/indexed_tree/content_addressed_indexed_tree.hpp`
30+
13. `crypto/merkle_tree/indexed_tree/indexed_leaf.hpp`
4731

4832
## Summary of Module
4933

50-
The `merkle_tree` module provides a comprehensive implementation of Merkle tree data structures for the Aztec protocol, including standard Merkle trees, append-only trees, indexed trees, and nullifier trees. The module supports multiple hash policies (Pedersen hash and Poseidon2) and provides both in-memory and persistent LMDB-backed storage options. The core implementation includes content-addressed storage with caching, allowing efficient tree operations and proof generation. The append-only tree implementation is optimized for sequential insertions, while the indexed tree maintains an ordered set of leaves with nullifier functionality. The nullifier tree is a specialized indexed tree used for tracking spent notes in the Aztec protocol. The module includes utilities for computing Merkle paths, tree roots, and managing tree metadata across multiple storage backends.
34+
The `merkle_tree` module implements the persistent Merkle tree infrastructure for the Aztec protocol's world state. It provides two tree variants: append-only trees (used for NOTE_HASH_TREE, L1_TO_L2_MESSAGE_TREE, and ARCHIVE) and indexed trees (used for NULLIFIER_TREE and PUBLIC_DATA_TREE). Both use Poseidon2 hashing.
35+
36+
The storage architecture is two-layered: `ContentAddressedCachedTreeStore` wraps an in-memory cache (`ContentAddressedCache`) over a persistent LMDB backend (`LMDBTreeStore`). All tree operations are asynchronous, using thread pools and callback-based completion. The system supports block-level history, forking, checkpointing, and rollback for the world state managed by `world_state/`.
5137

5238
## Test Files
53-
1. `crypto/merkle_tree/merkle_tree.test.cpp`
54-
2. `crypto/merkle_tree/memory_tree.test.cpp`
55-
3. `crypto/merkle_tree/fixtures.test.cpp`
56-
4. `crypto/merkle_tree/lmdb_store/lmdb_tree_store.test.cpp`
57-
5. `crypto/merkle_tree/node_store/content_addressed_cache.test.cpp`
58-
6. `crypto/merkle_tree/append_only_tree/content_addressed_append_only_tree.test.cpp`
59-
7. `crypto/merkle_tree/indexed_tree/content_addressed_indexed_tree.test.cpp`
60-
8. `crypto/merkle_tree/nullifier_tree/nullifier_tree.test.cpp`
61-
9. `crypto/merkle_tree/nullifier_tree/nullifier_memory_tree.test.cpp`
39+
1. `crypto/merkle_tree/memory_tree.test.cpp`
40+
2. `crypto/merkle_tree/fixtures.test.cpp`
41+
3. `crypto/merkle_tree/lmdb_store/lmdb_tree_store.test.cpp`
42+
4. `crypto/merkle_tree/node_store/content_addressed_cache.test.cpp`
43+
5. `crypto/merkle_tree/append_only_tree/content_addressed_append_only_tree.test.cpp`
44+
6. `crypto/merkle_tree/indexed_tree/content_addressed_indexed_tree.test.cpp`
45+
7. `crypto/merkle_tree/nullifier_tree/nullifier_memory_tree.test.cpp`
46+
47+
### Test Infrastructure
48+
Non-production code used for testing and benchmarking the production files above:
49+
50+
- `crypto/merkle_tree/memory_tree.hpp` — Simple in-memory tree. Also used by vm2/simulation as a lightweight tree for AVM transaction execution.
51+
- `crypto/merkle_tree/fixtures.hpp` — Test utility functions (random directories, values, thread pools).
52+
- `crypto/merkle_tree/test_fixtures.hpp` — GTest assertion wrappers for tree state verification.
53+
- `crypto/merkle_tree/node_store/array_store.hpp` — Lightweight in-memory store substitute for LMDB in tests/benchmarks.
54+
- `crypto/merkle_tree/nullifier_tree/nullifier_memory_tree.hpp` — Reference implementation of an indexed nullifier tree, used for differential testing of `ContentAddressedIndexedTree`.
55+
- `crypto/merkle_tree/nullifier_tree/nullifier_leaf.hpp` — Leaf types used by `nullifier_memory_tree.hpp`.
6256

6357
## Security Mechanisms
6458
None identified.

barretenberg/cpp/scripts/test_chonk_standalone_vks_havent_changed.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ cd ..
1313
# - Generate a hash for versioning: sha256sum bb-chonk-inputs.tar.gz
1414
# - Upload the compressed results: aws s3 cp bb-chonk-inputs.tar.gz s3://aztec-ci-artifacts/protocol/bb-chonk-inputs-[hash(0:8)].tar.gz
1515
# Note: In case of the "Test suite failed to run ... Unexpected token 'with' " error, need to run: docker pull aztecprotocol/build:3.0
16-
pinned_short_hash="600b85bd"
16+
pinned_short_hash="53ce2d4f"
1717
pinned_chonk_inputs_url="https://aztec-ci-artifacts.s3.us-east-2.amazonaws.com/protocol/bb-chonk-inputs-${pinned_short_hash}.tar.gz"
1818

1919
script_path="$(cd "$(dirname "${BASH_SOURCE[0]}")/scripts" && pwd)/$(basename "${BASH_SOURCE[0]}")"

barretenberg/cpp/src/barretenberg/benchmark/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ add_subdirectory(chonk_bench)
77
add_subdirectory(pippenger_bench)
88
add_subdirectory(relations_bench)
99
add_subdirectory(poseidon2_bench)
10-
add_subdirectory(merkle_tree_bench)
1110
add_subdirectory(indexed_tree_bench)
1211
add_subdirectory(append_only_tree_bench)
1312
add_subdirectory(ultra_bench)

barretenberg/cpp/src/barretenberg/benchmark/append_only_tree_bench/append_only_tree.bench.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ using namespace bb::crypto::merkle_tree;
2121
namespace {
2222
using StoreType = ContentAddressedCachedTreeStore<bb::fr>;
2323

24-
using Pedersen = ContentAddressedAppendOnlyTree<StoreType, PedersenHashPolicy>;
2524
using Poseidon2 = ContentAddressedAppendOnlyTree<StoreType, Poseidon2HashPolicy>;
2625

2726
const size_t TREE_DEPTH = 32;

barretenberg/cpp/src/barretenberg/benchmark/indexed_tree_bench/indexed_tree.bench.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ using namespace bb::crypto::merkle_tree;
1818
using StoreType = ContentAddressedCachedTreeStore<NullifierLeafValue>;
1919

2020
using Poseidon2 = ContentAddressedIndexedTree<StoreType, Poseidon2HashPolicy>;
21-
using Pedersen = ContentAddressedIndexedTree<StoreType, PedersenHashPolicy>;
2221

2322
const size_t TREE_DEPTH = 40;
2423
const size_t MAX_BATCH_SIZE = 64;

barretenberg/cpp/src/barretenberg/benchmark/merkle_tree_bench/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

barretenberg/cpp/src/barretenberg/benchmark/merkle_tree_bench/merkle_tree.bench.cpp

Lines changed: 0 additions & 77 deletions
This file was deleted.

barretenberg/cpp/src/barretenberg/commitment_schemes/claim_batcher.hpp

Lines changed: 6 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,14 @@
66

77
#pragma once
88
#include "barretenberg/common/ref_vector.hpp"
9-
#include "barretenberg/common/throw_or_abort.hpp"
109
#include "barretenberg/common/zip_view.hpp"
11-
#include "barretenberg/numeric/bitop/get_msb.hpp"
1210
#include <optional>
1311

1412
namespace bb {
1513

1614
/**
17-
* @brief Logic to support batching opening claims for unshifted, shifted and interleaved polynomials in Shplemini
18-
* @details Stores references to the commitments/evaluations of unshifted, shifted and interleaved polynomials to be
15+
* @brief Logic to support batching opening claims for unshifted and shifted polynomials in Shplemini
16+
* @details Stores references to the commitments/evaluations of unshifted and shifted polynomials to be
1917
* batch opened via Shplemini. Aggregates the commitments and batching scalars for each batch into the corresponding
2018
* containers for Shplemini. Computes the batched evaluation. Contains logic for computing the per-batch scalars
2119
* used to batch each set of claims (see details below).
@@ -35,26 +33,12 @@ template <typename Curve> struct ClaimBatcher_ {
3533
// scalar used for batching the claims, excluding the power of batching challenge \rho
3634
Fr scalar = 0;
3735
};
38-
struct InterleavedBatch {
39-
std::vector<RefVector<Commitment>> commitments_groups;
40-
RefVector<Fr> evaluations;
41-
std::vector<Fr> scalars_pos;
42-
std::vector<Fr> scalars_neg;
43-
Fr shplonk_denominator;
44-
};
4536

46-
std::optional<Batch> unshifted; // commitments and evaluations of unshifted polynomials
47-
std::optional<Batch> shifted; // commitments of to-be-shifted-by-1 polys, evals of their shifts
48-
std::optional<InterleavedBatch> interleaved; // commitments to groups of polynomials to be combined by interleaving
49-
// and evaluations of the resulting interleaved polynomials
37+
std::optional<Batch> unshifted; // commitments and evaluations of unshifted polynomials
38+
std::optional<Batch> shifted; // commitments of to-be-shifted-by-1 polys, evals of their shifts
5039

5140
Batch get_unshifted() { return (unshifted) ? *unshifted : Batch{}; }
5241
Batch get_shifted() { return (shifted) ? *shifted : Batch{}; }
53-
InterleavedBatch get_interleaved() { return (interleaved) ? *interleaved : InterleavedBatch{}; }
54-
uint32_t get_groups_to_be_interleaved_size()
55-
{
56-
return (interleaved) ? static_cast<uint32_t>(interleaved->commitments_groups[0].size()) : 0;
57-
}
5842

5943
Fr get_unshifted_batch_scalar() const { return unshifted ? unshifted->scalar : Fr{ 0 }; }
6044

@@ -97,52 +81,25 @@ template <typename Curve> struct ClaimBatcher_ {
9781
shifted->scalar =
9882
r_challenge.invert() * (inverse_vanishing_eval_pos - nu_challenge * inverse_vanishing_eval_neg);
9983
}
100-
101-
if (interleaved) {
102-
const size_t interleaving_denominator_index = 2 * numeric::get_msb(get_groups_to_be_interleaved_size());
103-
104-
if (get_groups_to_be_interleaved_size() % 2 != 0) {
105-
throw_or_abort("Interleaved groups size must be even");
106-
}
107-
108-
Fr r_shift_pos = Fr(1);
109-
Fr r_shift_neg = Fr(1);
110-
interleaved->shplonk_denominator = inverted_vanishing_evals[interleaving_denominator_index];
111-
for (size_t i = 0; i < get_groups_to_be_interleaved_size(); i++) {
112-
interleaved->scalars_pos.push_back(r_shift_pos);
113-
interleaved->scalars_neg.push_back(r_shift_neg);
114-
if (i < get_groups_to_be_interleaved_size() - 1) {
115-
// to avoid unnecessary multiplication gates in a circuit
116-
r_shift_pos *= r_challenge;
117-
r_shift_neg *= (-r_challenge);
118-
}
119-
}
120-
}
12184
}
12285
/**
123-
* @brief Append the commitments and scalars from each batch of claims to the Shplemini, vectors which subsequently
86+
* @brief Append the commitments and scalars from each batch of claims to the Shplemini vectors which subsequently
12487
* will be inputs to the batch mul;
12588
* update the batched evaluation and the running batching challenge (power of rho) in place.
12689
*
12790
* @param commitments commitment inputs to the single Shplemini batch mul
12891
* @param scalars scalar inputs to the single Shplemini batch mul
12992
* @param batched_evaluation running batched evaluation of the committed multilinear polynomials
13093
* @param rho multivariate batching challenge \rho
131-
* @param rho_power current power of \rho used in the batching scalar
132-
* @param shplonk_batching_pos and @param shplonk_batching_neg consecutive powers of the Shplonk batching
133-
* challenge ν for the interleaved contributions
13494
*/
13595
void update_batch_mul_inputs_and_batched_evaluation(std::vector<Commitment>& commitments,
13696
std::vector<Fr>& scalars,
13797
Fr& batched_evaluation,
138-
const Fr& rho,
139-
Fr shplonk_batching_pos = { 0 },
140-
Fr shplonk_batching_neg = { 0 })
98+
const Fr& rho)
14199
{
142100
size_t num_powers = 0;
143101
num_powers += unshifted.has_value() ? unshifted->commitments.size() : 0;
144102
num_powers += shifted.has_value() ? shifted->commitments.size() : 0;
145-
num_powers += interleaved.has_value() ? interleaved->evaluations.size() : 0;
146103

147104
Fr rho_power = Fr(1);
148105
size_t power_idx = 0;
@@ -171,29 +128,6 @@ template <typename Curve> struct ClaimBatcher_ {
171128
// i-th shifted commitments will be multiplied by ρ^{num_unshifted + i} and r⁻¹ ⋅ (1/(z−r) − ν/(z+r))
172129
aggregate_claim_data_and_update_batched_evaluation(*shifted);
173130
}
174-
if (interleaved) {
175-
if (get_groups_to_be_interleaved_size() % 2 != 0) {
176-
throw_or_abort("Interleaved groups size must be even");
177-
}
178-
179-
size_t group_idx = 0;
180-
for (size_t j = 0; j < interleaved->commitments_groups.size(); j++) {
181-
for (size_t i = 0; i < get_groups_to_be_interleaved_size(); i++) {
182-
// The j-th commitment in group i is multiplied by ρ^{m+i} and ν^{d+1} \cdot r^j + ν^{d+2} ⋅(-r)^j
183-
// where d is the log_circuit_size
184-
commitments.emplace_back(std::move(interleaved->commitments_groups[j][i]));
185-
scalars.emplace_back(-rho_power * interleaved->shplonk_denominator *
186-
(shplonk_batching_pos * interleaved->scalars_pos[i] +
187-
shplonk_batching_neg * interleaved->scalars_neg[i]));
188-
}
189-
batched_evaluation += interleaved->evaluations[group_idx] * rho_power;
190-
power_idx++;
191-
if (power_idx < num_powers) {
192-
rho_power *= rho;
193-
}
194-
group_idx++;
195-
}
196-
}
197131

198132
BB_ASSERT_EQ(power_idx, num_powers);
199133
}

0 commit comments

Comments
 (0)