Skip to content

Commit 5be53b6

Browse files
authored
feat: merge-train/barretenberg (#19653)
BEGIN_COMMIT_OVERRIDE chore: add graph_description_keccak test (#19575) chore: update commit hash in blake files in blake audit scope (#19593) feat: enable asserts in WASM builds (#19632) chore: remove unnecessary "inputs" structs (#19660) fix: overflow in wasm assert (#19690) chore!: sha audit 2 (#19436) chore: add logic audit scope (and add old bigfield scope) (#19680) END_COMMIT_OVERRIDE
2 parents dc714c7 + 11ac02c commit 5be53b6

Some content is hidden

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

51 files changed

+437
-294
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# External Audit Scope: Bigfield
2+
3+
Repository: https://github.com/AztecProtocol/aztec-packages
4+
5+
Commit hash: [d0ee94134b6cf290cf93cccf30354278d2bdff59](https://github.com/AztecProtocol/aztec-packages/tree/d0ee94134b6cf290cf93cccf30354278d2bdff59)
6+
7+
## Files to Audit
8+
9+
Note: Paths relative to `aztec-packages/barretenberg/cpp/src/barretenberg`
10+
11+
1. `stdlib/primitives/bigfield/bigfield.hpp`
12+
2. `stdlib/primitives/bigfield/bigfield_impl.hpp`
13+
3. `stdlib/primitives/bigfield/constants.hpp`
14+
15+
Relations: (wasn't explicitly in the SoW but was still audited)
16+
17+
4. `relations/non_native_field_relations.hpp`
18+
19+
## Summary of Module
20+
21+
The `bigfield` module implements non-native field arithmetic inside a circuit. It enables arithmetic operations on field elements from a different (larger) field than the native circuit field, which is essential for operations like
22+
23+
- Recursive verification of BN254-based proofs inside BN254 circuits, and
24+
- ECDSA verification where we need to work with secp256k1/r1 field elements inside BN254-based circuits.
25+
26+
**Representation**: Each `bigfield` element is represented using:
27+
28+
- 4 binary basis limbs of 68 bits each (total 272 bits)
29+
- A prime basis limb (the value mod native field modulus)
30+
- Maximum value tracking for each limb to enable lazy reduction
31+
32+
The value is: `limb[0] + limb[1] * 2^68 + limb[2] * 2^136 + limb[3] * 2^204`
33+
34+
**Operations**: Implements full field arithmetic (+, -, \*, /) with:
35+
36+
- Lazy reduction to minimize expensive range checks
37+
- Chinese Remainder Theorem (CRT) for efficient multiplication verification
38+
- Optimized gate usage (4 gates for addition, custom gates for multiplication)
39+
40+
**CRT-based Multiplication**: To verify `a * b = r mod p`:
41+
42+
- Checks equation holds mod 2^272 (binary basis) via schoolbook multiplication
43+
- Checks equation holds mod native field (prime basis) via single multiplication gate
44+
- Ensures both sides are less than CRT modulus `M = 2^272 * n`
45+
46+
**Range Tracking**: The module tracks maximum values of limbs to:
47+
48+
- Determine when reduction is needed before overflow
49+
- Compute appropriate range constraints for quotient/carry values
50+
- Enable batching multiple operations before reduction
51+
52+
Please refer to the [bigfield README](https://github.com/AztecProtocol/aztec-packages/blob/d0ee94134b6cf290cf93cccf30354278d2bdff59/barretenberg/cpp/src/barretenberg/stdlib/primitives/bigfield/README.md) for detailed specification of the multiplication, addition, subtraction, and division algorithms.
53+
54+
> Note: The README uses LaTeX notation which doesn't render well on GitHub; you might need to use Markdown preview in VS Code to render the file.
55+
56+
## Test Files
57+
58+
1. `stdlib/primitives/bigfield/bigfield.test.cpp`
Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# External Audit Scope: Biggroup
22

33
Repository: https://github.com/AztecProtocol/aztec-packages
4+
45
Commit hash: [553c5eb82901955c638b943065acd3e47fc918c0](https://github.com/AztecProtocol/aztec-packages/tree/553c5eb82901955c638b943065acd3e47fc918c0)
56

67
## Files to Audit
@@ -13,24 +14,20 @@ The following files are to be audited, located in the `stdlib/primitives/biggrou
1314
4. `stdlib/primitives/biggroup/biggroup_tables.hpp`
1415
5. `stdlib/primitives/biggroup/biggroup_secp256k1.hpp`
1516
6. `stdlib/primitives/biggroup/biggroup_edgecase_handling.hpp`
16-
17-
Update: Fixed lookup tables are implemented in `stdlib_circuit_builders/plookup_tables/non_native_group_generator.cpp` which must be added to the scope.
18-
1917
7. `stdlib_circuit_builders/plookup_tables/non_native_group_generator.cpp`
2018
8. `stdlib_circuit_builders/plookup_tables/non_native_group_generator.hpp`
2119

2220
## Brief Summary of Module
2321

24-
The biggroup module implements elliptic-curve operations using UltraHonk arithmetisation in barretenberg. This is specifically implemented to work for three curves[^1]: bn254, secp256k1 and secp256r1.
22+
The biggroup module implements elliptic-curve operations using UltraHonk arithmetisation in barretenberg. This is specifically implemented to work for three curves: bn254, secp256k1 and secp256r1 (see Note 1).
2523

26-
Please refer to the [biggroup README](https://github.com/AztecProtocol/aztec-packages/blob/553c5eb82901955c638b943065acd3e47fc918c0/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/README.md) for details on the specification and implementation details.[^2]
24+
Please refer to the [biggroup README](https://github.com/AztecProtocol/aztec-packages/blob/553c5eb82901955c638b943065acd3e47fc918c0/barretenberg/cpp/src/barretenberg/stdlib/primitives/biggroup/README.md) for details on the specification and implementation details (see Note 2).
25+
26+
> Note 1: Our implementation can _technically_ work for other curves as well (so long as the base and scalar fields of the curve can be represented with our bigfield module) but we have not tested it for other curves.
27+
>
28+
> Note 2: The README uses Latex notation which doesn't render well on Github, you might need to use Markdown preview in VS code to render the file.
2729
2830
## Test Files
31+
2932
1. `stdlib/primitives/biggroup/biggroup.test.cpp`
3033
2. `stdlib/primitives/biggroup/biggroup_secp256k1.test.cpp`
31-
32-
33-
34-
[^1]: Our implementation can _technically_ work for other curves as well (so long as the base and scalar fields of the curve can be represented with our bigfield module) but we have not tested it for other curves.
35-
36-
[^2]: The README uses Latex notation which doesn't render well on Github, you might need to use Markdown preview in VS code to render the file.

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

Lines changed: 0 additions & 34 deletions
This file was deleted.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# External Audit Scope: Logic
2+
3+
Repository: https://github.com/AztecProtocol/aztec-packages
4+
5+
Commit hash: TBD
6+
7+
## Files to Audit
8+
9+
Note: Paths relative to `aztec-packages/barretenberg/cpp/src/barretenberg`
10+
11+
1. `stdlib/primitives/logic/logic.hpp`
12+
2. `stdlib/primitives/logic/logic.cpp`
13+
3. `stdlib_circuit_builders/plookup_tables/uint.hpp` (lookup tables)
14+
15+
## Summary of Module
16+
17+
The `logic` module provides circuit-friendly implementations of bitwise logical operations (XOR and AND) over variable-length unsigned integers using plookup tables.
18+
19+
Main function: `create_logic_constraint(a, b, num_bits, is_xor_gate)`
20+
21+
- Computes `a XOR b` or `a AND b` for inputs up to `num_bits` in length
22+
- Supports inputs up to 252 bits (grumpkin::MAX_NO_WRAP_INTEGER_BIT_LENGTH)
23+
24+
The implementation:
25+
26+
- Decomposes inputs into 32-bit chunks
27+
- Performs lookups against `UINT32_XOR` or `UINT32_AND` multi-tables for each chunk
28+
- The lookup operation implicitly enforces 32-bit range constraints on each chunk
29+
- For non-32-bit-aligned inputs, the final chunk is explicitly range-constrained to the remaining bits
30+
- Input values are reconstructed from chunks and verified via `assert_equal`
31+
- If both inputs are constants, the operation is computed natively without circuit constraints
32+
- If one input is constant, it is converted to a witness before processing
33+
34+
## Test Files
35+
36+
1. `stdlib/primitives/logic/logic.test.cpp`
37+
38+
## Dependencies
39+
40+
- Plookup read: `stdlib/primitives/plookup/plookup.hpp`

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

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
# External Audit Scope: Ultra + MegaCircuitBuilder
22

33
Repository: https://github.com/AztecProtocol/aztec-packages
4-
Commit hash: To be added in January
4+
5+
Commit hash: [6d14241271ad07c72937498b66f28df630662c2c](https://github.com/AztecProtocol/aztec-packages/tree/6d14241271ad07c72937498b66f28df630662c2c)
6+
57
Status: Planned, [Luke, Raju]
68

79
## Files to Audit
810

911
Note: Paths relative to `aztec-packages/barretenberg/cpp/src/barretenberg`
1012

11-
12-
1313
### Circuit Builders
14+
1415
1. `stdlib_circuit_builders/circuit_builder_base.hpp`
1516
2. `stdlib_circuit_builders/circuit_builder_base_impl.hpp`
1617
3. `stdlib_circuit_builders/ultra_circuit_builder.hpp`
@@ -23,6 +24,7 @@ Note: Paths relative to `aztec-packages/barretenberg/cpp/src/barretenberg`
2324
10. `honk/execution_trace/gate_data.hpp`
2425

2526
### Relations (Ultra)
27+
2628
11. `relations/ultra_arithmetic_relation.hpp`
2729
12. `relations/permutation_relation.hpp`
2830
13. `relations/logderiv_lookup_relation.hpp`
@@ -34,10 +36,12 @@ Note: Paths relative to `aztec-packages/barretenberg/cpp/src/barretenberg`
3436
19. `relations/poseidon2_internal_relation.hpp`
3537

3638
### Relations (Mega-only)
39+
3740
20. `relations/ecc_op_queue_relation.hpp`
3841
21. `relations/databus_lookup_relation.hpp`
3942

4043
### Lookup infrastructure
44+
4145
22. `stdlib_circuit_builders/plookup_tables/plookup_tables.hpp`
4246
23. `stdlib_circuit_builders/plookup_tables/plookup_tables.cpp`
4347
24. `stdlib_circuit_builders/plookup_tables/types.hpp`
@@ -48,21 +52,34 @@ Note: Paths relative to `aztec-packages/barretenberg/cpp/src/barretenberg`
4852
### ECC Op Queue
4953

5054
The following is "joint" functionality for the ECCVM and the Mega circuit builder (called `UltraOps`. In this audit, we only care about how things are represented in the Mega circuit builder.
55+
5156
28. `op_queue/ecc_op_queue.hpp`
5257
29. `op_queue/ecc_ops_table.hpp` (especially the `UltraEccOpsTable` class and its methods)
5358

59+
### Stdlib Goblin Components
60+
61+
We represent bn254 group elements in the Mega circuit builder using "Goblinized" representations. Particularly, the `goblin_field` represents bn254 base field elements (x, y coordinates), and the `biggroup_goblin` represents bn254 group elements.
62+
63+
30. `stdlib/primitives/bigfield/goblin_field.hpp`
64+
31. `stdlib/primitives/biggroup/biggroup_goblin.hpp`
65+
32. `stdlib/primitives/biggroup/biggroup_goblin_impl.hpp`
66+
5467
### Databus
68+
5569
Within this audit, it is important to make sure that the databus "correctly links up" with the Mega circuit builder. Therefore, the following file is also in the scope of the audit.
56-
30. `stdlib_circuit_builders/databus.hpp`
70+
71+
33. `stdlib_circuit_builders/databus.hpp`
5772

5873
### ACIR Format
59-
31. `dsl/acir_format/range_constraint.hpp`
74+
75+
34. `dsl/acir_format/range_constraint.hpp`
6076

6177
## Brief Summary of Module
6278

6379
The Ultra/MegaCircuitBuilder module implements the core circuit construction infrastructure for Barretenberg's proving system.
6480

6581
**Class Hierarchy:**
82+
6683
```
6784
CircuitBuilderBase<FF>
6885
└── UltraCircuitBuilder_<ExecutionTrace>
@@ -78,6 +95,7 @@ CircuitBuilderBase<FF>
7895
## Test Files
7996

8097
### Circuit Builder Tests
98+
8199
1. `circuit_checker/ultra_circuit_builder_basic.test.cpp`
82100
2. `circuit_checker/ultra_circuit_builder_arithmetic.test.cpp`
83101
3. `circuit_checker/ultra_circuit_builder_elliptic.test.cpp`
@@ -89,20 +107,25 @@ CircuitBuilderBase<FF>
89107
9. `circuit_checker/mega_circuit_builder.test.cpp`
90108

91109
### Relation Tests
110+
92111
10. `relations/ultra_relation_consistency.test.cpp`
93112

94113
### Test Utilities
114+
95115
1. `circuit_checker/circuit_checker.hpp`
96116
2. `circuit_checker/ultra_circuit_checker.hpp`
97117
3. `circuit_checker/ultra_circuit_checker.cpp`
98118

99119
## Security Mechanisms
100120

101121
### SMT (Satisfiability Modulo Theories) Verification
122+
102123
1. `smt_verification/circuit/ultra_circuit.test.cpp`
103124

104125
## Misc. Tests (NOT part of the audit, but might be helpful to situation)
126+
105127
The full prove-verify testing package is more extensive than the mere `circuit_checker` tests. Therefore, the following tests might be helpful as reference points.
128+
106129
1. `ultra_honk/lookup.test.cpp`
107130
2. `ultra_honk/permutation.test.cpp`
108131
3. `ultra_honk/rom_ram.test.cpp`

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="db8f42e3"
16+
pinned_short_hash="0d7388db"
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/boomerang_value_detection/graph.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,6 +1266,47 @@ inline void StaticAnalyzer_<FF, CircuitBuilder>::remove_unnecessary_sha256_plook
12661266
}
12671267
}
12681268

1269+
/**
1270+
* @brief This method removes false positive cases from keccak lookup tables.
1271+
* Tables which are enumerated in keccak_plookup_tables are used by keccak lookup constraints. Some lookup-gate outputs
1272+
* are auxiliary (e.g. MSB) and may appear in only one gate but this is not dangerous. So we remove these variables.
1273+
* @tparam FF
1274+
* @tparam CircuitBuilder
1275+
* @param table_id
1276+
* @param gate_index
1277+
*/
1278+
template <typename FF, typename CircuitBuilder>
1279+
inline void StaticAnalyzer_<FF, CircuitBuilder>::remove_unnecessary_keccak_plookup_variables(BasicTableId& table_id,
1280+
size_t gate_index)
1281+
{
1282+
auto find_position = [&](uint32_t real_variable_index) {
1283+
return variables_in_one_gate.contains(real_variable_index);
1284+
};
1285+
1286+
std::unordered_set<BasicTableId> keccak_plookup_tables{
1287+
BasicTableId::KECCAK_INPUT, BasicTableId::KECCAK_OUTPUT, BasicTableId::KECCAK_CHI, BasicTableId::KECCAK_THETA,
1288+
BasicTableId::KECCAK_RHO, BasicTableId::KECCAK_RHO_1, BasicTableId::KECCAK_RHO_2, BasicTableId::KECCAK_RHO_3,
1289+
BasicTableId::KECCAK_RHO_4, BasicTableId::KECCAK_RHO_5, BasicTableId::KECCAK_RHO_6, BasicTableId::KECCAK_RHO_7,
1290+
BasicTableId::KECCAK_RHO_8, BasicTableId::KECCAK_RHO_9
1291+
};
1292+
1293+
auto& lookup_block = circuit_builder.blocks.lookup;
1294+
1295+
if (keccak_plookup_tables.contains(table_id)) {
1296+
uint32_t real_out_idx = this->to_real(lookup_block.w_o()[gate_index]);
1297+
uint32_t real_right_idx = this->to_real(lookup_block.w_r()[gate_index]);
1298+
if (variables_gate_counts[real_out_idx] != 1 || variables_gate_counts[real_right_idx] != 1) {
1299+
bool find_out = find_position(real_out_idx);
1300+
auto q_c = lookup_block.q_c()[gate_index];
1301+
if (q_c.is_zero()) {
1302+
if (find_out) {
1303+
variables_in_one_gate.erase(real_out_idx);
1304+
}
1305+
}
1306+
}
1307+
}
1308+
}
1309+
12691310
/**
12701311
* @brief this method removes false cases in lookup table for a given gate.
12711312
* it uses all functions above for lookup tables to remove all variables that appear in one gate,
@@ -1294,6 +1335,8 @@ inline void StaticAnalyzer_<FF, CircuitBuilder>::process_current_plookup_gate(si
12941335
this->remove_unnecessary_aes_plookup_variables(table_id, gate_index);
12951336
// false cases for sha256
12961337
this->remove_unnecessary_sha256_plookup_variables(table_id, gate_index);
1338+
// false cases for keccak
1339+
this->remove_unnecessary_keccak_plookup_variables(table_id, gate_index);
12971340
// if the amount of unique elements from columns of plookup tables = 1, it means that
12981341
// variable from this column aren't used and we can remove it.
12991342
if (column_1.size() == 1) {

barretenberg/cpp/src/barretenberg/boomerang_value_detection/graph.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ template <typename FF, typename CircuitBuilder> class StaticAnalyzer_ {
142142
void remove_unnecessary_range_constrains_variables();
143143
void remove_unnecessary_aes_plookup_variables(bb::plookup::BasicTableId& table_id, size_t gate_index);
144144
void remove_unnecessary_sha256_plookup_variables(bb::plookup::BasicTableId& table_id, size_t gate_index);
145+
void remove_unnecessary_keccak_plookup_variables(bb::plookup::BasicTableId& table_id, size_t gate_index);
145146
void remove_record_witness_variables();
146147

147148
std::unordered_set<uint32_t> get_variables_in_one_gate();

0 commit comments

Comments
 (0)