Skip to content

Commit 6ce8775

Browse files
authored
feat: merge-train/barretenberg (#18096)
BEGIN_COMMIT_OVERRIDE chore!: EC add from ACIR, part 1 (#18013) chore: `logderiv_lookup_relation` audit, cleanups and documentation (#17336) chore: remove unused stdlib schnorr (#18103) END_COMMIT_OVERRIDE
2 parents 41d60d0 + 2effaa2 commit 6ce8775

File tree

17 files changed

+210
-491
lines changed

17 files changed

+210
-491
lines changed

barretenberg/cpp/scripts/stdlib-tests

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@ stdlib_ecdsa_tests
66
stdlib_pedersen_commitment_tests
77
stdlib_pedersen_hash_tests
88
stdlib_poseidon2_tests
9-
stdlib_schnorr_tests
109
stdlib_sha256_tests

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="16dc4478"
16+
pinned_short_hash="84c467db"
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
function compress_and_upload {

barretenberg/cpp/src/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ set(BARRETENBERG_TARGET_OBJECTS
184184
$<TARGET_OBJECTS:stdlib_pedersen_hash_objects>
185185
$<TARGET_OBJECTS:stdlib_poseidon2_objects>
186186
$<TARGET_OBJECTS:stdlib_primitives_objects>
187-
$<TARGET_OBJECTS:stdlib_schnorr_objects>
188187
$<TARGET_OBJECTS:stdlib_sha256_objects>
189188
$<TARGET_OBJECTS:stdlib_translator_vm_verifier_objects>
190189
$<TARGET_OBJECTS:sumcheck_objects>

barretenberg/cpp/src/barretenberg/dsl/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ set(DSL_DEPENDENCIES
33
ultra_honk
44
stdlib_sha256
55
stdlib_aes128
6+
stdlib_blake2s
67
stdlib_blake3s
78
stdlib_keccak
89
stdlib_poseidon2
9-
stdlib_schnorr
1010
stdlib_honk_verifier
1111
stdlib_chonk_verifier)
1212

barretenberg/cpp/src/barretenberg/dsl/acir_format/ec_operations.cpp

Lines changed: 52 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,70 @@
1313

1414
namespace acir_format {
1515

16+
/**
17+
* @brief Create constraints for addition of two points on the Grumpkin curve.
18+
*
19+
* @details We proceed in 2 steps:
20+
* 1. We reconstruct the Grumpkin points input1, input2 and input_result for which we must check input1 + input2 =
21+
* input_result. The reconstruction handles all cases: has_valid_witness_assignments equal to false (write_vk
22+
* scenario) and a witness predicate. If:
23+
* - has_valid_witness_assignments is false, then we set input1 = input2 = input_result equal to the generator of
24+
* Grumpkin
25+
* - the predicate is witness false, we set input1 and input2 to be the generator of Grumpkin.
26+
* 2. We compute input1 + input2 and check that it agrees with input_result.
27+
*
28+
* @note We do not need to enforce in-circuit that input_result is on the curve because we check that input_result is
29+
* equal to result, which we know is on the curve as it is the sum of two points on the curve. In the case of predicate
30+
* equal to witness false, the constraint is supposed to be inactive, so we even if input_result is not checked to be on
31+
* the curve in this case, it is OK.
32+
*
33+
* @tparam Builder
34+
* @param builder
35+
* @param input
36+
* @param has_valid_witness_assignments
37+
*/
1638
template <typename Builder>
1739
void create_ec_add_constraint(Builder& builder, const EcAdd& input, bool has_valid_witness_assignments)
1840
{
19-
// Input to cycle_group points
2041
using cycle_group_ct = bb::stdlib::cycle_group<Builder>;
2142
using field_ct = bb::stdlib::field_t<Builder>;
2243
using bool_ct = bb::stdlib::bool_t<Builder>;
2344

24-
auto input1_point = to_grumpkin_point(
25-
input.input1_x, input.input1_y, input.input1_infinite, has_valid_witness_assignments, input.predicate, builder);
26-
auto input2_point = to_grumpkin_point(
27-
input.input2_x, input.input2_y, input.input2_infinite, has_valid_witness_assignments, input.predicate, builder);
45+
// Step 1.
46+
bool_ct predicate = bool_ct(to_field_ct(input.predicate, builder));
2847

29-
// Compute the result of the addition
30-
cycle_group_ct result = input1_point + input2_point;
31-
// AUDITTODO: Is this necessary? If so, ensure cycle_group addition always returns standard form. If not, clarify.
32-
result.standardize();
33-
34-
// Create copy-constraints between the computed result and the expected result stored in the input witness indices
3548
field_ct input_result_x = field_ct::from_witness_index(&builder, input.result_x);
3649
field_ct input_result_y = field_ct::from_witness_index(&builder, input.result_y);
3750
bool_ct input_result_infinite = bool_ct(field_ct::from_witness_index(&builder, input.result_infinite));
3851

39-
result.x().assert_equal(input_result_x);
40-
result.y().assert_equal(input_result_y);
41-
result.is_point_at_infinity().assert_equal(input_result_infinite);
52+
if (!has_valid_witness_assignments) {
53+
builder.set_variable(input_result_x.get_witness_index(), bb::grumpkin::g1::affine_one.x);
54+
builder.set_variable(input_result_y.get_witness_index(), bb::grumpkin::g1::affine_one.y);
55+
builder.set_variable(input_result_infinite.get_witness_index(), bb::fr(0));
56+
}
57+
58+
cycle_group_ct input1_point = to_grumpkin_point(
59+
input.input1_x, input.input1_y, input.input1_infinite, has_valid_witness_assignments, predicate, builder);
60+
cycle_group_ct input2_point = to_grumpkin_point(
61+
input.input2_x, input.input2_y, input.input2_infinite, has_valid_witness_assignments, predicate, builder);
62+
// Note that input_result is computed by Noir and passed to bb via ACIR. Hence, it is always a valid point on
63+
// Grumpkin.
64+
cycle_group_ct input_result(input_result_x, input_result_y, input_result_infinite, /*assert_on_curve=*/false);
65+
66+
// Step 2.
67+
cycle_group_ct result = input1_point + input2_point;
68+
69+
if (!predicate.is_constant()) {
70+
cycle_group_ct to_be_asserted_equal = cycle_group_ct::conditional_assign(predicate, input_result, result);
71+
result.assert_equal(to_be_asserted_equal);
72+
} else {
73+
// The assert_equal method standardizes both points before comparing, so if either of them is the point at
74+
// infinity, the coordinates will be assigned to be (0,0). This is OK as long as Noir developers do not use the
75+
// coordinates of a point at infinity (otherwise input_result might be the point at infinity different from (0,
76+
// 0, true), and the fact that assert_equal passes doesn't imply anything for the original coordinates of
77+
// input_result).
78+
result.assert_equal(input_result);
79+
}
4280
}
4381

4482
template void create_ec_add_constraint<bb::UltraCircuitBuilder>(bb::UltraCircuitBuilder& builder,

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,24 @@
1111

1212
namespace acir_format {
1313

14+
/**
15+
* @brief Constraints for addition of two points on the Grumpkin curve.
16+
*
17+
* @details EcAdd constraints have 10 components:
18+
* - input1_x: x-coordinate of the first input point
19+
* - input1_y: y-coordinate of the first input point
20+
* - input1_infinite: flag indicating if the first input point is the point at infinity
21+
* - input2_x: x-coordinate of the second input point
22+
* - input2_y: y-coordinate of the second input point
23+
* - input2_infinite: flag indicating if the second input point is the point at infinity
24+
* - predicate: flag indicating whether the constraint is active
25+
* - result_x: witness index for the x-coordinate of the resulting point
26+
* - result_y: witness index for the y-coordinate of the resulting point
27+
* - result_infinite: witness index for the flag indicating if the result is the point at infinity
28+
*
29+
* The data related to input1 and input2 can either be given by witnesses or constants. However, x and y coordinates
30+
* pertaining to the same input must be either all witnesses or all constants.
31+
*/
1432
struct EcAdd {
1533
WitnessOrConstant<bb::fr> input1_x;
1634
WitnessOrConstant<bb::fr> input1_y;

barretenberg/cpp/src/barretenberg/dsl/acir_format/multi_scalar_mul.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ void create_multi_scalar_mul_constraint(Builder& builder,
2626
using field_ct = stdlib::field_t<Builder>;
2727
using bool_ct = stdlib::bool_t<Builder>;
2828

29+
bool_ct predicate = bool_ct(to_field_ct(input.predicate, builder));
30+
2931
std::vector<cycle_group_ct> points;
3032
std::vector<cycle_scalar_ct> scalars;
3133

@@ -35,7 +37,7 @@ void create_multi_scalar_mul_constraint(Builder& builder,
3537
input.points[i + 1],
3638
input.points[i + 2],
3739
has_valid_witness_assignments,
38-
input.predicate,
40+
predicate,
3941
builder);
4042

4143
// Reconstruct the scalar from the low and high limbs

barretenberg/cpp/src/barretenberg/dsl/acir_format/witness_constant.cpp

Lines changed: 41 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ using namespace bb::stdlib;
1414

1515
/**
1616
* @brief Convert inputs representing a Grumpkin point into a cycle_group element.
17-
* @details Inputs x, y, and is_infinite are used to construct the point. If no valid witness is provided or if the
18-
* predicate is constant false, the point is set to the generator point. If the predicate is a non-constant witness, the
19-
* point is conditionally assigned to the generator point based on the predicate value. This ensures that the point is
20-
* always valid and will not trigger any on_curve assertions.
17+
* @details Inputs x, y, and is_infinite are used to construct the point. We handle two cases:
18+
* 1. has_valid_witness_assignments is false: we are in a write_vk scenario. In this case, we set the point to be the
19+
* generator of Grumpkin.
20+
* 2. predicate is a witness: we conditionally assign the point depending on the predicate; if it is witness true, we
21+
* use the witnesses provided, otherwise, we set the point to be the generator of Grumpkin.
2122
*
2223
* @tparam Builder
2324
* @tparam FF
@@ -29,69 +30,59 @@ using namespace bb::stdlib;
2930
* @param builder
3031
* @return bb::stdlib::cycle_group<Builder>
3132
*/
32-
template <typename Builder, typename FF>
33-
bb::stdlib::cycle_group<Builder> to_grumpkin_point(const WitnessOrConstant<FF>& input_x,
34-
const WitnessOrConstant<FF>& input_y,
35-
const WitnessOrConstant<FF>& input_infinite,
33+
template <typename Builder>
34+
bb::stdlib::cycle_group<Builder> to_grumpkin_point(const WitnessOrConstant<typename Builder::FF>& input_x,
35+
const WitnessOrConstant<typename Builder::FF>& input_y,
36+
const WitnessOrConstant<typename Builder::FF>& input_infinite,
3637
bool has_valid_witness_assignments,
37-
const WitnessOrConstant<FF>& predicate,
38+
const bb::stdlib::bool_t<Builder>& predicate,
3839
Builder& builder)
3940
{
4041
using bool_ct = bb::stdlib::bool_t<Builder>;
4142
using field_ct = bb::stdlib::field_t<Builder>;
43+
44+
bool constant_coordinates = input_x.is_constant && input_y.is_constant;
45+
4246
auto point_x = to_field_ct(input_x, builder);
4347
auto point_y = to_field_ct(input_y, builder);
4448
auto infinite = bool_ct(to_field_ct(input_infinite, builder));
4549

46-
// Coordinates should not have mixed constancy. In the case they do, convert constant coordinate to fixed witness.
47-
BB_ASSERT_EQ(input_x.is_constant, input_y.is_constant, "to_grumpkin_point: Inconsistent constancy of coordinates");
48-
// TODO(https://github.com/AztecProtocol/aztec-packages/issues/17514): Avoid mixing constant/witness coordinates
49-
if (point_x.is_constant() != point_y.is_constant()) {
50-
if (point_x.is_constant()) {
51-
point_x.convert_constant_to_fixed_witness(&builder);
52-
} else if (point_y.is_constant()) {
53-
point_y.convert_constant_to_fixed_witness(&builder);
54-
}
55-
}
56-
57-
bool constant_coordinates = input_x.is_constant && input_y.is_constant;
58-
59-
// In a witness is not provided, or the relevant predicate is constant false, we ensure the coordinates correspond
60-
// to a valid point to avoid erroneous failures during circuit construction. We only do this if the coordinates are
61-
// non-constant since otherwise no variable indices exist.
62-
bool constant_false_predicate = predicate.is_constant && predicate.value == FF(0);
63-
if ((!has_valid_witness_assignments || constant_false_predicate) && !constant_coordinates) {
64-
auto one = bb::grumpkin::g1::affine_one;
65-
builder.set_variable(input_x.index, one.x);
66-
builder.set_variable(input_y.index, one.y);
50+
// If a witness is not provided (we are in a write_vk scenario) we ensure the coordinates correspond to a valid
51+
// point to avoid erroneous failures during circuit construction. We only do this if the coordinates are
52+
// non-constant since otherwise no variable indices exist. Note that there is no need to assign the infinite flag
53+
// because native on-curve checks will always pass as long x and y coordinates correspond to a valid point on
54+
// Grumpkin.
55+
if (!has_valid_witness_assignments && !constant_coordinates) {
56+
builder.set_variable(input_x.index, bb::grumpkin::g1::affine_one.x);
57+
builder.set_variable(input_y.index, bb::grumpkin::g1::affine_one.y);
6758
}
6859

6960
// If the predicate is a non-constant witness, conditionally replace coordinates with a valid point.
70-
// Note: this must be done before constructing the cycle_group to avoid triggering on_curve assertions
71-
if (!predicate.is_constant) {
72-
bool_ct predicate_witness = bool_ct::from_witness_index_unsafe(&builder, predicate.index);
73-
auto generator = bb::grumpkin::g1::affine_one;
74-
point_x = field_ct::conditional_assign(predicate_witness, point_x, generator.x);
75-
point_y = field_ct::conditional_assign(predicate_witness, point_y, generator.y);
76-
bool_ct generator_is_infinity = bool_ct(&builder, generator.is_point_at_infinity());
77-
infinite = bool_ct::conditional_assign(predicate_witness, infinite, generator_is_infinity);
61+
if (!predicate.is_constant()) {
62+
point_x = field_ct::conditional_assign(predicate, point_x, field_ct(bb::grumpkin::g1::affine_one.x));
63+
point_y = field_ct::conditional_assign(predicate, point_y, field_ct(bb::grumpkin::g1::affine_one.y));
64+
infinite = bool_ct::conditional_assign(predicate, infinite, bool_ct(false));
65+
} else {
66+
BB_ASSERT(predicate.get_value(), "Creating Grumpkin point with a constant predicate equal to false.");
7867
}
7968

8069
cycle_group<Builder> input_point(point_x, point_y, infinite, /*assert_on_curve=*/true);
8170
return input_point;
8271
}
8372

84-
template bb::stdlib::cycle_group<UltraCircuitBuilder> to_grumpkin_point(const WitnessOrConstant<fr>& input_x,
85-
const WitnessOrConstant<fr>& input_y,
86-
const WitnessOrConstant<fr>& input_infinite,
87-
bool has_valid_witness_assignments,
88-
const WitnessOrConstant<fr>& predicate,
89-
UltraCircuitBuilder& builder);
90-
template bb::stdlib::cycle_group<MegaCircuitBuilder> to_grumpkin_point(const WitnessOrConstant<fr>& input_x,
91-
const WitnessOrConstant<fr>& input_y,
92-
const WitnessOrConstant<fr>& input_infinite,
93-
bool has_valid_witness_assignments,
94-
const WitnessOrConstant<fr>& predicate,
95-
MegaCircuitBuilder& builder);
73+
template bb::stdlib::cycle_group<UltraCircuitBuilder> to_grumpkin_point(
74+
const WitnessOrConstant<UltraCircuitBuilder::FF>& input_x,
75+
const WitnessOrConstant<UltraCircuitBuilder::FF>& input_y,
76+
const WitnessOrConstant<UltraCircuitBuilder::FF>& input_infinite,
77+
bool has_valid_witness_assignments,
78+
const bb::stdlib::bool_t<UltraCircuitBuilder>& predicate,
79+
UltraCircuitBuilder& builder);
9680

81+
template bb::stdlib::cycle_group<MegaCircuitBuilder> to_grumpkin_point(
82+
const WitnessOrConstant<MegaCircuitBuilder::FF>& input_x,
83+
const WitnessOrConstant<MegaCircuitBuilder::FF>& input_y,
84+
const WitnessOrConstant<MegaCircuitBuilder::FF>& input_infinite,
85+
bool has_valid_witness_assignments,
86+
const bb::stdlib::bool_t<MegaCircuitBuilder>& predicate,
87+
MegaCircuitBuilder& builder);
9788
} // namespace acir_format

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ template <typename FF> struct WitnessOrConstant {
3636
}
3737
};
3838

39-
template <typename Builder, typename FF>
40-
bb::stdlib::field_t<Builder> to_field_ct(const WitnessOrConstant<FF>& input, Builder& builder)
39+
template <typename Builder>
40+
bb::stdlib::field_t<Builder> to_field_ct(const WitnessOrConstant<typename Builder::FF>& input, Builder& builder)
4141
{
4242
using field_ct = bb::stdlib::field_t<Builder>;
4343
if (input.is_constant) {
@@ -46,12 +46,12 @@ bb::stdlib::field_t<Builder> to_field_ct(const WitnessOrConstant<FF>& input, Bui
4646
return field_ct::from_witness_index(&builder, input.index);
4747
}
4848

49-
template <typename Builder, typename FF>
50-
bb::stdlib::cycle_group<Builder> to_grumpkin_point(const WitnessOrConstant<FF>& input_x,
51-
const WitnessOrConstant<FF>& input_y,
52-
const WitnessOrConstant<FF>& input_infinite,
49+
template <typename Builder>
50+
bb::stdlib::cycle_group<Builder> to_grumpkin_point(const WitnessOrConstant<typename Builder::FF>& input_x,
51+
const WitnessOrConstant<typename Builder::FF>& input_y,
52+
const WitnessOrConstant<typename Builder::FF>& input_infinite,
5353
bool has_valid_witness_assignments,
54-
const WitnessOrConstant<FF>& predicate,
54+
const bb::stdlib::bool_t<Builder>& predicate,
5555
Builder& builder);
5656

5757
} // namespace acir_format

barretenberg/cpp/src/barretenberg/relations/databus_lookup_relation.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ namespace bb {
4646
* Each column of the DataBus requires its own pair of subrelations. The column being read is selected via a unique
4747
* product, i.e. a lookup from bus column j is selected via q_busread * q_j (j = 1,2,...).
4848
*
49-
* To not compute the inverse terms packed in I_i for indices that not included in the sum we introduce a
49+
* To not compute the inverse terms packed in I_i for indices not included in the sum we introduce a
5050
* witness called inverse_exists, which is zero when either read_count_i is nonzero (a boolean called read_tag) or we
5151
* have a read gate. This is represented by setting inverse_exists = 1- (1- read_tag)*(1- is_read_gate). Since read_gate
5252
* is only dependent on selector values, we can assume that the verifier can check that it is boolean. However, if

0 commit comments

Comments
 (0)