Skip to content

Commit

Permalink
feat: Sync from noir (#8740)
Browse files Browse the repository at this point in the history
Automated pull of development from the
[noir](https://github.com/noir-lang/noir) programming language, a
dependency of Aztec.
BEGIN_COMMIT_OVERRIDE
fix(ssa): RC correctness issue
(noir-lang/noir#6134)
fix: let token pretty printer handle `+=` and similar token sequences
(noir-lang/noir#6135)
fix: allow providing default implementations of unconstrained trait
methods (noir-lang/noir#6138)
feat: remove unnecessary branching in keccak impl
(noir-lang/noir#6133)
feat: do not double error on import with error
(noir-lang/noir#6131)
chore: remove unnecessary `Prover.toml`s
(noir-lang/noir#6140)
chore: split `noirc_frontend/src/tests.rs` into submodules
(noir-lang/noir#6139)
feat: remove aztec macros (noir-lang/noir#6087)
END_COMMIT_OVERRIDE

---------

Co-authored-by: TomAFrench <tom@tomfren.ch>
  • Loading branch information
AztecBot and TomAFrench authored Sep 25, 2024
1 parent 1507762 commit 0d9f547
Show file tree
Hide file tree
Showing 90 changed files with 1,128 additions and 6,012 deletions.
2 changes: 1 addition & 1 deletion .noir-sync-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
e3cdebe515e4dc4ee6e16e01bd8af25135939798
164d29e4d1960d16fdeafe2cc8ea8144a769f7b2
2 changes: 1 addition & 1 deletion noir-projects/noir-protocol-circuits/Nargo.template.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[workspace]
members = [
"crates/types",
"crates/blob",
# "crates/blob",
"crates/parity-base",
"crates/parity-lib",
"crates/parity-root",
Expand Down
64 changes: 32 additions & 32 deletions noir-projects/noir-protocol-circuits/crates/blob/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ unconstrained fn __batch_invert_impl<let N: u32>(mut x: [F; N]) -> [F; N] {
unconstrained fn __compute_fracs(z: F, ys: [F; FIELDS_PER_BLOB]) -> [F; FIELDS_PER_BLOB] {
let mut denoms: [F; FIELDS_PER_BLOB] = [BigNum::new(); FIELDS_PER_BLOB];
for i in 0..FIELDS_PER_BLOB {
denoms[i] = z.__add(NEGATIVE_ROOTS[i]); // (z - ω^i)
denoms[i] = z.__add(NEGATIVE_ROOTS[i]); // (z - omega^i)
}
let inv_denoms = __batch_invert_impl(denoms); // 1 / (z - ω^i), for all i
let inv_denoms = __batch_invert_impl(denoms); // 1 / (z - omega^i), for all i

let mut fracs: [F; FIELDS_PER_BLOB] = [BigNum::new(); FIELDS_PER_BLOB];
for i in 0..FIELDS_PER_BLOB {
let inv_denom = inv_denoms[i]; // 1 / (z - ω^i)
let inv_denom = inv_denoms[i]; // 1 / (z - omega^i)

fracs[i] = ys[i].__mul(inv_denom); // y_i / (z - ω^i)
fracs[i] = ys[i].__mul(inv_denom); // y_i / (z - omega^i)
}
fracs
}
Expand Down Expand Up @@ -260,9 +260,9 @@ fn main(blob: [F; FIELDS_PER_BLOB], kzg_commitment: [Field; 2]) -> pub (Field, F

/**
* ___d-1
* z^d - 1 \ ω^i
* z^d - 1 \ omega^i
* p(z) = --------- . / y_i . ---------
* d /____ z - ω^i
* d /____ z - omega^i
* i=0
*
* p(z) = factor . sum( y_i . num / denom )
Expand All @@ -271,7 +271,7 @@ fn main(blob: [F; FIELDS_PER_BLOB], kzg_commitment: [Field; 2]) -> pub (Field, F
* where d = 4096
*
* Precompute:
* - The d roots of unity ω^i (plus maybe their negatives for z - ω^i computations).
* - The d roots of unity omega^i (plus maybe their negatives for z - omega^i computations).
* - (1 / d)
*
* @param z
Expand Down Expand Up @@ -342,48 +342,48 @@ fn barycentric_evaluate_blob_at_z(z: F, ys: [F; FIELDS_PER_BLOB]) -> F {
let mut sum: F = BigNum::new();

// Making a call to this function causes a "stack too deep" error, so I've put the body of that function here, instead:
// let fracs = __compute_fracs(z, ys); // { y_i / (z - ω^i) }
// let fracs = __compute_fracs(z, ys); // { y_i / (z - omega^i) }

// Note: it's more efficient (saving 30k constraints) to compute:
// ___d-1
// \ / y_i \
// / | --------- | . ω^i
// /____ \ z - ω^i /
// / | --------- | . omega^i
// /____ \ z - omega^i /
// i=0
// ^^^^^^^^^
// frac
//
// ... than to compute:
//
// ___d-1
// \ / ω^i \
// \ / omega^i \
// / y_i . | --------- |
// /____ \ z - ω^i /
// /____ \ z - omega^i /
// i=0
//
// perhaps because all the ω^i terms are constant witnesses?
// perhaps because all the omega^i terms are constant witnesses?

//*****************************************************************
// This section is only needed because `__compute_fracs` isn't working (stack too deep error).

let mut fracs: [F; FIELDS_PER_BLOB] = [BigNum::new(); FIELDS_PER_BLOB]; // y_i / (z - ω^i), for all i
let mut fracs: [F; FIELDS_PER_BLOB] = [BigNum::new(); FIELDS_PER_BLOB]; // y_i / (z - omega^i), for all i

let mut denoms = [BigNum::new(); FIELDS_PER_BLOB];
for i in 0..FIELDS_PER_BLOB {
denoms[i] = z.__add(NEGATIVE_ROOTS[i]); // (z - ω^i)
denoms[i] = z.__add(NEGATIVE_ROOTS[i]); // (z - omega^i)
}

// If you're seeing a `bug` warning for this line, I think it's fine.
// Ideally, we'd be using `__compute_fracs`, anyway, but we're getting a "stack too deep" error.
let inv_denoms = __batch_invert_impl(denoms); // 1 / (z - ω^i), for all i
let inv_denoms = __batch_invert_impl(denoms); // 1 / (z - omega^i), for all i

for i in 0..FIELDS_PER_BLOB {
let num = ys[i];
let inv_denom = inv_denoms[i]; // 1 / (z - ω^i)
let inv_denom = inv_denoms[i]; // 1 / (z - omega^i)

let frac = num.__mul(inv_denom); // y_i * (1 / (z - ω^i))
let frac = num.__mul(inv_denom); // y_i * (1 / (z - omega^i))

fracs[i] = frac; // y_i / (z - ω^i)
fracs[i] = frac; // y_i / (z - omega^i)
std::as_witness(fracs[i].limbs[0]);
std::as_witness(fracs[i].limbs[1]);
std::as_witness(fracs[i].limbs[2]);
Expand Down Expand Up @@ -414,9 +414,9 @@ fn barycentric_evaluate_blob_at_z(z: F, ys: [F; FIELDS_PER_BLOB]) -> F {

// Seeking:
// ___d-1
// \ ω^i
// \ omega^i
// sum = / y_i . ---------
// /____ z - ω^i
// /____ z - omega^i
// i=0
let NUM_PARTIAL_SUMS = FIELDS_PER_BLOB / 8;
for i in 0..NUM_PARTIAL_SUMS {
Expand All @@ -426,26 +426,26 @@ fn barycentric_evaluate_blob_at_z(z: F, ys: [F; FIELDS_PER_BLOB]) -> F {

// Seeking:
// ___i*8 + 7
// \ ω^k
// \ omega^k
// partial_sum = / y_k . ---------
// /____ z - ω^k
// /____ z - omega^k
// k=i*8 + 0

for j in 0..8 {
let k = i * 8 + j;
lhs[j] = ROOTS[k]; // ω^k
rhs[j] = fracs[k]; // y_k / (z - ω^k)
lhs[j] = ROOTS[k]; // omega^k
rhs[j] = fracs[k]; // y_k / (z - omega^k)
std::as_witness(lhs[j].limbs[0]);
std::as_witness(lhs[j].limbs[1]);
std::as_witness(lhs[j].limbs[2]);
std::as_witness(rhs[j].limbs[0]);
std::as_witness(rhs[j].limbs[1]);
std::as_witness(rhs[j].limbs[2]);

// y_k * ( ω^k / (z - ω^k) )
// y_k * ( omega^k / (z - omega^k) )
let summand = ROOTS[k].__mul(fracs[k]);

// partial_sum + ( y_k * ( ω^k / (z - ω^k) ) -> partial_sum
// partial_sum + ( y_k * ( omega^k / (z - omega^k) ) -> partial_sum
partial_sum = partial_sum.__add(summand);
std::as_witness(partial_sum.limbs[0]);
std::as_witness(partial_sum.limbs[1]);
Expand All @@ -454,19 +454,19 @@ fn barycentric_evaluate_blob_at_z(z: F, ys: [F; FIELDS_PER_BLOB]) -> F {

// Seeking:
// ___i*8 - 1 ___i*8 + 7
// \ ω^i \ / y_k \
// sum_out = / y_i . --------- + / ω^k . | --------- |
// /____ z - ω^i /____ \ z - ω^k /
// \ omega^i \ / y_k \
// sum_out = / y_i . --------- + / omega^k . | --------- |
// /____ z - omega^i /____ \ z - omega^k /
// 0 k = i*8
// ^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// sum partial_sum
//
// ... that is:
//
// ___i*8 - 1 ___ 7
// \ ω^i \
// \ omega^i \
// sum_out = / y_i . --------- + / lhs[j] . rhs[j]
// /____ z - ω^i /____
// /____ z - omega^i /____
// 0 j = 0
// ^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^
// sum partial_sum
Expand Down
20 changes: 10 additions & 10 deletions noir-projects/noir-protocol-circuits/crates/types/src/constants.nr
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ global ARGS_LENGTH: u32 = 16;
*
* In the kernel circuits, we accumulate elements such as note hashes and the nullifiers from all functions calls in a
* transaction. Therefore, we always must have:
* MAX_XXX_PER_TX MAX_XXX_PER_CALL
* MAX_XXX_PER_TX >= MAX_XXX_PER_CALL
*
* For instance:
* MAX_NOTE_HASHES_PER_TX MAX_NOTE_HASHES_PER_CALL
* MAX_NULLIFIERS_PER_TX MAX_NULLIFIERS_PER_CALL
* MAX_NOTE_HASHES_PER_TX >= MAX_NOTE_HASHES_PER_CALL
* MAX_NULLIFIERS_PER_TX >= MAX_NULLIFIERS_PER_CALL
*
*/

Expand Down Expand Up @@ -137,7 +137,7 @@ global AZTEC_TARGET_COMMITTEE_SIZE: u32 = 48;
// The following is taken from building a block and looking at the `lastArchive` value in it.
// You can run the `integration_l1_publisher.test.ts` and look at the first blocks in the fixtures.
global GENESIS_ARCHIVE_ROOT: Field = 0x1200a06aae1368abe36530b585bd7a4d2ba4de5037b82076412691a187d7621e;
// The following and the value in `deploy_l1_contracts´ must match. We should not have the code both places, but
// The following and the value in `deploy_l1_contracts` must match. We should not have the code both places, but
// we are running into circular dependency issues. #3342
global FEE_JUICE_INITIAL_MINT: Field = 20000000000;

Expand Down Expand Up @@ -333,12 +333,12 @@ global AVM_PUBLIC_COLUMN_MAX_SIZE_LOG2 = 8;
* +-----------+-------------------------------+----------------------+
* | Hash size | Number of elements hashed (n) | Condition to use |
* |-----------+-------------------------------+----------------------|
* | LOW | n 8 | 0 < hash_index 32 |
* | MID | 8 < n 16 | 32 < hash_index 40 |
* | HIGH | 16 < n 48 | 40 < hash_index 48 |
* | LOW | n <= 8 | 0 < hash_index <= 32 |
* | MID | 8 < n <= 16 | 32 < hash_index <= 40 |
* | HIGH | 16 < n <= 48 | 40 < hash_index <= 48 |
* +-----------+-------------------------------+----------------------+
*/
// Indices with size 8
// Indices with size <= 8
global GENERATOR_INDEX__NOTE_HASH: u32 = 1;
global GENERATOR_INDEX__NOTE_HASH_NONCE: u32 = 2;
global GENERATOR_INDEX__UNIQUE_NOTE_HASH: u32 = 3;
Expand Down Expand Up @@ -371,10 +371,10 @@ global GENERATOR_INDEX__SIDE_EFFECT: u32 = 29;
global GENERATOR_INDEX__FEE_PAYLOAD: u32 = 30;
global GENERATOR_INDEX__COMBINED_PAYLOAD: u32 = 31;
global GENERATOR_INDEX__TX_NULLIFIER: u32 = 32;
// Indices with size 16
// Indices with size <= 16
global GENERATOR_INDEX__TX_REQUEST: u32 = 33;
global GENERATOR_INDEX__SIGNATURE_PAYLOAD: u32 = 34;
// Indices with size 44
// Indices with size <= 44
global GENERATOR_INDEX__VK: u32 = 41;
global GENERATOR_INDEX__PRIVATE_CIRCUIT_PUBLIC_INPUTS: u32 = 42;
global GENERATOR_INDEX__PUBLIC_CIRCUIT_PUBLIC_INPUTS: u32 = 43;
Expand Down
1 change: 0 additions & 1 deletion noir/.rebuild_patterns_native
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
^noir/scripts/test_native.sh
^noir/noir-repo/acvm-repo
^noir/noir-repo/compiler
^noir/noir-repo/aztec_macros
^noir/noir-repo/noir_stdlib
^noir/noir-repo/tooling/backend_interface
^noir/noir-repo/tooling/bb_abstraction_leaks
Expand Down
1 change: 0 additions & 1 deletion noir/.rebuild_patterns_packages
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
^noir/noir-repo/yarn.lock
^noir/noir-repo/acvm-repo
^noir/noir-repo/compiler
^noir/noir-repo/aztec_macros
^noir/noir-repo/noir_stdlib
^noir/noir-repo/tooling/noir_codegen
^noir/noir-repo/tooling/noir_js
Expand Down
4 changes: 1 addition & 3 deletions noir/Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ nargo-src:
# Relevant source (TODO finer-grained 'tooling')
COPY --dir \
noir-repo/acvm-repo \
noir-repo/aztec_macros \
noir-repo/compiler \
noir-repo/noir_stdlib \
noir-repo/tooling \
Expand Down Expand Up @@ -43,7 +42,7 @@ nargo:
SAVE IMAGE aztecprotocol/nargo

test:
FROM +nargo
FROM +nargo-src
COPY ./scripts/test_native.sh ./scripts/test_native.sh
COPY noir-repo/.rustfmt.toml noir-repo/.rustfmt.toml

Expand Down Expand Up @@ -116,7 +115,6 @@ packages-deps:
# Relevant source (TODO finer-grained)
COPY --dir \
noir-repo/acvm-repo \
noir-repo/aztec_macros \
noir-repo/compiler \
noir-repo/docs \
noir-repo/noir_stdlib \
Expand Down
Loading

0 comments on commit 0d9f547

Please sign in to comment.