Skip to content

Commit 65d96ef

Browse files
authored
feat: merge-train/barretenberg (#19541)
BEGIN_COMMIT_OVERRIDE chore: Improve Chonk debug info (#19538) chore: translator non-native and decomp relations audit (#19081) chore: add safety to derive_generators and tweak pedersen scope (#19525) fix: ci-barretenberg-full mode fixes (#19466) test: use WASM backend for bbjs-test acir tests (#19529) fix: use absolute path in run_test.sh for CI fix: use env_objects in bb-external library fix: completeness issue in cycle scalar constructor from bigfield (#19475) chore: review a few minor files for ultra/mega audit (#19513) END_COMMIT_OVERRIDE
2 parents 88578c1 + 113f414 commit 65d96ef

31 files changed

+1118
-939
lines changed

barretenberg/acir_tests/bbjs-test/src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ async function generateProof({
2424
oracleHash?: string;
2525
multiThreaded?: boolean;
2626
}) {
27-
const { UltraHonkBackend, Barretenberg } = await import('@aztec/bb.js');
27+
const { UltraHonkBackend, Barretenberg, BackendType } = await import('@aztec/bb.js');
2828

2929
logger.debug(`Generating proof for ${bytecodePath}...`);
3030
const circuitArtifact = await fs.readFile(bytecodePath);
3131
const bytecode = JSON.parse(circuitArtifact.toString()).bytecode;
32-
const bb = await Barretenberg.new({ threads: multiThreaded ? 8 : 1 });
32+
const bb = await Barretenberg.new({ threads: multiThreaded ? 8 : 1, backend: BackendType.Wasm });
3333
const backend = new UltraHonkBackend(bytecode, bb);
3434

3535
const witness = await fs.readFile(witnessPath);
@@ -62,9 +62,9 @@ async function generateProof({
6262
}
6363

6464
async function verifyProof({ directory }: { directory: string }) {
65-
const { UltraHonkVerifierBackend, Barretenberg } = await import('@aztec/bb.js');
65+
const { UltraHonkVerifierBackend, Barretenberg, BackendType } = await import('@aztec/bb.js');
6666

67-
const bb = await Barretenberg.new({ threads: 1 });
67+
const bb = await Barretenberg.new({ threads: 1, backend: BackendType.Wasm });
6868
const verifier = new UltraHonkVerifierBackend(bb);
6969

7070
const proof = await fs.readFile(proofPath(directory));

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,7 @@ Commit hash: 4a956ceb179c2fe855e4f1fd78f2594e7fc3f5ea
88
#### Native implementation
99
1. ```barretenberg/cpp/src/barretenberg/crypto/pedersen_hash/pedersen.hpp```
1010
2. ```barretenberg/cpp/src/barretenberg/crypto/pedersen_hash/pedersen.cpp```
11-
3. ```barretenberg/cpp/src/barretenberg/crypto/pedersen_hash/c_bind.hpp```
12-
4. ```barretenberg/cpp/src/barretenberg/crypto/pedersen_hash/c_bind.cpp```
13-
14-
#### Tests
15-
5. ```barretenberg/cpp/src/barretenberg/crypto/pedersen_hash/pedersen.test.cpp```
16-
- Test vectors for Pedersen hash implementation
17-
18-
11+
3. ```barretenberg/cpp/src/barretenberg/crypto/generators/generator_data.hpp```
1912

2013
### Summary of the module
2114

@@ -39,6 +32,9 @@ Key features:
3932
- Uses precomputed generator points for efficiency
4033
- Based on the hardness of the discrete logarithm problem
4134

35+
#### Tests
36+
- ```barretenberg/cpp/src/barretenberg/crypto/pedersen_hash/pedersen.test.cpp```
37+
4238
### Documentation
4339

4440
Pedersen commitments: https://en.wikipedia.org/wiki/Commitment_scheme#Pedersen_commitment

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Note: Paths relative to `aztec-packages/barretenberg/cpp/src/barretenberg`
2020
7. `honk/execution_trace/execution_trace_block.hpp`
2121
8. `honk/execution_trace/ultra_execution_trace.hpp`
2222
9. `honk/execution_trace/mega_execution_trace.hpp`
23-
10. `honk/execution_trace/gate_data.hpp` (TO BE REVIEWED)
23+
10. `honk/execution_trace/gate_data.hpp`
2424

2525
### Relations (Ultra)
2626
11. `relations/ultra_arithmetic_relation.hpp`
@@ -41,7 +41,7 @@ Note: Paths relative to `aztec-packages/barretenberg/cpp/src/barretenberg`
4141
22. `stdlib_circuit_builders/plookup_tables/plookup_tables.hpp`
4242
23. `stdlib_circuit_builders/plookup_tables/plookup_tables.cpp`
4343
24. `stdlib_circuit_builders/plookup_tables/types.hpp`
44-
25. `stdlib_circuit_builders/plookup_tables/dummy.hpp` (TO BE REVIEWED)
44+
25. `stdlib_circuit_builders/plookup_tables/dummy.hpp`
4545
26. `stdlib/primitives/plookup/plookup.hpp`
4646
27. `stdlib/primitives/plookup/plookup.cpp`
4747

barretenberg/cpp/src/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,19 @@ add_library(
205205
${BARRETENBERG_TARGET_OBJECTS}
206206
)
207207

208+
# bb-external: A complete static library for external consumers (e.g. barretenberg-rs).
209+
# Includes everything from libbarretenberg.a plus env and vm2_stub.
210+
# This provides a single library file that external bindings can link against.
211+
if(NOT WASM)
212+
add_library(
213+
bb-external
214+
STATIC
215+
${BARRETENBERG_TARGET_OBJECTS}
216+
$<TARGET_OBJECTS:env_objects>
217+
$<TARGET_OBJECTS:vm2_stub>
218+
)
219+
endif()
220+
208221
if(WASM)
209222
# When building this wasm "executable", we include the wasi module but exclude the env module.
210223
# That's because we expect this wasm to be run as a wasi "reactor" and for the host environment

barretenberg/cpp/src/barretenberg/chonk/chonk.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -601,13 +601,19 @@ void Chonk::update_native_verifier_accumulator(const VerifierInputs& queue_entry
601601
}
602602
}
603603

604-
if (!queue_entry.is_kernel) {
605-
native_verifier_accum_hash = native_verifier_accum.hash_with_origin_tagging(*verifier_transcript);
606-
}
607-
608604
info("Chonk accumulate: prover and verifier accumulators match: ",
609605
prover_accumulator.compare_with_verifier_claim(native_verifier_accum) ? "true" : "false");
610-
info("Chonk accumulate: hash of verifier accumulator computed natively ", native_verifier_accum_hash);
606+
607+
// Update the native verifier accumulator hash if we are accumulating an app (i.e. the previous circuit was a
608+
// kernel) or if the last app has been accumulated (i.e. the current circuit is the tail kernel)
609+
bool update_verifier_accum_hash = is_previous_circuit_a_kernel || has_last_app_been_accumulated;
610+
if (update_verifier_accum_hash) {
611+
native_verifier_accum_hash = native_verifier_accum.hash_with_origin_tagging(*verifier_transcript);
612+
info("Chonk accumulate: hash of verifier accumulator computed natively set in previous kernel IO: ",
613+
native_verifier_accum_hash);
614+
}
615+
has_last_app_been_accumulated = num_circuits_accumulated + 1 == num_circuits - 4;
616+
is_previous_circuit_a_kernel = queue_entry.is_kernel;
611617

612618
info("======= END OF DEBUGGING INFO FOR NATIVE FOLDING STEP =======");
613619
}

barretenberg/cpp/src/barretenberg/chonk/chonk.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ class Chonk : public IVCBase {
141141
#ifndef NDEBUG
142142
VerifierAccumulator native_verifier_accum; // native verifier accumulator used in prover folding
143143
FF native_verifier_accum_hash; // hash of the native verifier accumulator when entering recursive verification
144+
bool is_previous_circuit_a_kernel = true;
145+
bool has_last_app_been_accumulated = false;
144146
#endif
145147

146148
// PARALLEL QUEUES: These two queues must stay synchronized.

barretenberg/cpp/src/barretenberg/dsl/acir_format/range_constraint.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// === AUDIT STATUS ===
2-
// internal: { status: Planned, auditors: [Luke, Raju], commit: }
2+
// internal: { status: Complete, auditors: [Luke, Raju], commit: }
33
// external_1: { status: not started, auditors: [], commit: }
44
// external_2: { status: not started, auditors: [], commit: }
55
// =====================

barretenberg/cpp/src/barretenberg/ecc/groups/group.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,18 @@ template <typename Fq_, typename Fr_, typename Params> class group {
8888
const size_t num_generators,
8989
const size_t starting_index = 0)
9090
{
91+
// Safety: domain_separator_bytes is indexed via &domain_separator_bytes[0] below.
92+
// An empty domain separator would be UB and also defeats domain separation.
93+
BB_ASSERT(!domain_separator_bytes.empty(), "derive_generators: domain_separator_bytes must be non-empty");
94+
95+
// We serialize the generator index into 4 bytes (uint32_t). Ensure we never silently truncate.
96+
if (num_generators > 0) {
97+
BB_ASSERT(starting_index <= static_cast<size_t>(UINT32_MAX),
98+
"derive_generators: starting_index exceeds uint32 range");
99+
BB_ASSERT(num_generators <= (static_cast<size_t>(UINT32_MAX) - starting_index + 1),
100+
"derive_generators: starting_index + num_generators exceeds uint32 range");
101+
}
102+
91103
std::vector<affine_element> result;
92104
const auto domain_hash = blake3::blake3s_constexpr(&domain_separator_bytes[0], domain_separator_bytes.size());
93105
std::vector<uint8_t> generator_preimage;

barretenberg/cpp/src/barretenberg/honk/execution_trace/gate_data.hpp

Lines changed: 17 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
// === AUDIT STATUS ===
2-
// internal: { status: Planned, auditors: [Luke], commit: }
2+
// internal: { status: Complete, auditors: [Luke], commit: }
33
// external_1: { status: not started, auditors: [], commit: }
44
// external_2: { status: not started, auditors: [], commit: }
55
// =====================
66

77
#pragma once
8-
#include "barretenberg/common/serialize.hpp"
98
#include "barretenberg/ecc/curves/bn254/fr.hpp"
109
#include <cstdint>
1110

12-
// TODO(#557): The field-specific aliases for gates should be removed and the type could be explicit when this
13-
// structures are used to avoid having foo_gate and foo_gate_grumpkin (i.e. use foo_gate<field> instead). Moreover, we
14-
// need to ensure the read/write functions handle grumpkin gates as well.
1511
namespace bb {
12+
13+
// 3-wire addition gate: a*a_scaling + b*b_scaling + c*c_scaling + const_scaling = 0
1614
template <typename FF> struct add_triple_ {
1715
uint32_t a;
1816
uint32_t b;
@@ -23,6 +21,7 @@ template <typename FF> struct add_triple_ {
2321
FF const_scaling;
2422
};
2523

24+
// 4-wire addition gate: a*a_scaling + b*b_scaling + c*c_scaling + d*d_scaling + const_scaling = 0
2625
template <typename FF> struct add_quad_ {
2726
uint32_t a;
2827
uint32_t b;
@@ -34,6 +33,8 @@ template <typename FF> struct add_quad_ {
3433
FF d_scaling;
3534
FF const_scaling;
3635
};
36+
37+
// 4-wire mul-add gate: a*b*mul_scaling + a*a_scaling + b*b_scaling + c*c_scaling + d*d_scaling + const_scaling = 0
3738
template <typename FF> struct mul_quad_ {
3839
uint32_t a;
3940
uint32_t b;
@@ -46,14 +47,8 @@ template <typename FF> struct mul_quad_ {
4647
FF d_scaling;
4748
FF const_scaling;
4849
};
49-
template <typename FF> struct mul_triple_ {
50-
uint32_t a;
51-
uint32_t b;
52-
uint32_t c;
53-
FF mul_scaling;
54-
FF c_scaling;
55-
FF const_scaling;
56-
};
50+
51+
// Arithmetic gate with standard selector naming: q_m*a*b + q_l*a + q_r*b + q_o*c + q_c = 0
5752
template <typename FF> struct arithmetic_triple_ {
5853
uint32_t a;
5954
uint32_t b;
@@ -66,7 +61,10 @@ template <typename FF> struct arithmetic_triple_ {
6661

6762
friend bool operator==(arithmetic_triple_<FF> const& lhs, arithmetic_triple_<FF> const& rhs) = default;
6863
};
64+
6965
using arithmetic_triple = arithmetic_triple_<bb::fr>;
66+
67+
// Goblin ECCVM operation: stores op type, point coordinates (split into limbs), and scalar
7068
struct ecc_op_tuple {
7169
uint32_t op;
7270
uint32_t x_lo;
@@ -78,52 +76,7 @@ struct ecc_op_tuple {
7876
bool return_is_infinity;
7977
};
8078

81-
template <typename B, typename FF> inline void read(B& buf, arithmetic_triple_<FF>& constraint)
82-
{
83-
using serialize::read;
84-
read(buf, constraint.a);
85-
read(buf, constraint.b);
86-
read(buf, constraint.c);
87-
read(buf, constraint.q_m);
88-
read(buf, constraint.q_l);
89-
read(buf, constraint.q_r);
90-
read(buf, constraint.q_o);
91-
read(buf, constraint.q_c);
92-
}
93-
template <typename B, typename FF> inline void write(B& buf, arithmetic_triple_<FF> const& constraint)
94-
{
95-
using serialize::write;
96-
write(buf, constraint.a);
97-
write(buf, constraint.b);
98-
write(buf, constraint.c);
99-
write(buf, constraint.q_m);
100-
write(buf, constraint.q_l);
101-
write(buf, constraint.q_r);
102-
write(buf, constraint.q_o);
103-
write(buf, constraint.q_c);
104-
}
105-
106-
template <typename FF> struct fixed_group_add_quad_ {
107-
uint32_t a;
108-
uint32_t b;
109-
uint32_t c;
110-
uint32_t d;
111-
FF q_x_1;
112-
FF q_x_2;
113-
FF q_y_1;
114-
FF q_y_2;
115-
};
116-
template <typename FF> struct fixed_group_init_quad_ {
117-
FF q_x_1;
118-
FF q_x_2;
119-
FF q_y_1;
120-
FF q_y_2;
121-
};
122-
template <typename FF> struct accumulator_triple_ {
123-
std::vector<uint32_t> left;
124-
std::vector<uint32_t> right;
125-
std::vector<uint32_t> out;
126-
};
79+
// Embedded curve point addition: (x1, y1) + sign_coefficient * (x2, y2) = (x3, y3)
12780
template <typename FF> struct ecc_add_gate_ {
12881
uint32_t x1;
12982
uint32_t y1;
@@ -133,19 +86,22 @@ template <typename FF> struct ecc_add_gate_ {
13386
uint32_t y3;
13487
FF sign_coefficient;
13588
};
89+
90+
// Embedded curve point doubling: 2 * (x1, y1) = (x3, y3)
13691
template <typename FF> struct ecc_dbl_gate_ {
13792
uint32_t x1;
13893
uint32_t y1;
13994
uint32_t x3;
14095
uint32_t y3;
14196
};
14297

98+
// Databus lookup gate: reads value at index from calldata/returndata
14399
template <typename FF> struct databus_lookup_gate_ {
144100
uint32_t index;
145101
uint32_t value;
146102
};
147103

148-
/* External gate data for poseidon2 external round*/
104+
// External gate data for poseidon2 external round
149105
template <typename FF> struct poseidon2_external_gate_ {
150106
uint32_t a;
151107
uint32_t b;
@@ -154,7 +110,7 @@ template <typename FF> struct poseidon2_external_gate_ {
154110
size_t round_idx;
155111
};
156112

157-
/* Internal gate data for poseidon2 internal round*/
113+
// Internal gate data for poseidon2 internal round
158114
template <typename FF> struct poseidon2_internal_gate_ {
159115
uint32_t a;
160116
uint32_t b;

barretenberg/cpp/src/barretenberg/relations/delta_range_constraint_relation.hpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,23 @@
99

1010
namespace bb {
1111

12+
/**
13+
* @brief Delta Range Constraint Relation for efficient range checks
14+
*
15+
* @details This relation enables efficient range proofs by enforcing that consecutive wire values differ by at most 3.
16+
* When witnesses are sorted in ascending order, constraining adjacent differences to be in {0, 1, 2, 3} proves that
17+
* the full range of values lies within a bounded interval.
18+
*
19+
*/
1220
template <typename FF_> class DeltaRangeConstraintRelationImpl {
1321
public:
1422
using FF = FF_;
1523

1624
static constexpr std::array<size_t, 4> SUBRELATION_PARTIAL_LENGTHS{
17-
6, // range constrain sub-relation 1
18-
6, // range constrain sub-relation 2
19-
6, // range constrain sub-relation 3
20-
6 // range constrain sub-relation 4
25+
6, // sub-relation 1: D_0 = w_2 - w_1
26+
6, // sub-relation 2: D_1 = w_3 - w_2
27+
6, // sub-relation 3: D_2 = w_4 - w_3
28+
6 // sub-relation 4: D_3 = w_1_shifst - w_4
2129
};
2230

2331
/**
@@ -41,13 +49,13 @@ template <typename FF_> class DeltaRangeConstraintRelationImpl {
4149
*
4250
* @param evals transformed to `evals + C(in(X)...)*scaling_factor`
4351
* @param in an std::array containing the fully extended Univariate edges.
44-
* @param parameters contains beta, gamma, and public_input_delta, ....
52+
* @param parameters unused
4553
* @param scaling_factor optional term to scale the evaluation before adding to evals.
4654
*/
4755
template <typename ContainerOverSubrelations, typename AllEntities, typename Parameters>
4856
inline static void accumulate(ContainerOverSubrelations& accumulators,
4957
const AllEntities& in,
50-
const Parameters&,
58+
BB_UNUSED const Parameters&,
5159
const FF& scaling_factor)
5260
{
5361
using Accumulator = std::tuple_element_t<0, ContainerOverSubrelations>;

0 commit comments

Comments
 (0)