Skip to content

Commit

Permalink
feat: Sync from noir (#11196)
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
chore: add end step for formatting workflow
(noir-lang/noir#7070)
feat(LSP): code action to import trait in a method call
(noir-lang/noir#7066)
feat!: Handle generic fields in `StructDefinition::fields` and move old
functionality to `StructDefinition::fields_as_written`
(noir-lang/noir#7067)
chore(ci): Check various inliner aggressiveness setttings in Brillig
reports (noir-lang/noir#7049)
chore: reenable reports on rollup root circuits
(noir-lang/noir#7061)
fix: don't always select trait impl when verifying trait constraints
(noir-lang/noir#7041)
chore: mark some critical libraries as good again
(noir-lang/noir#7065)
fix: Reduce memory usage in mem2reg
(noir-lang/noir#7053)
feat: Allow associated types to be ellided from trait constraints
(noir-lang/noir#7026)
chore(perf): try using vec-collections's VecSet in AliasSet
(noir-lang/noir#7058)
chore: reduce number of iterations of `acvm::compiler::compile`
(noir-lang/noir#7050)
chore: add `noir_check_shuffle` as a critical library
(noir-lang/noir#7056)
chore: clippy warning fix (noir-lang/noir#7051)
chore(ci): Unify compilation/execution report jobs that take averages
with single runs (noir-lang/noir#7048)
fix(nargo_fmt): let doc comment could come after regular comment
(noir-lang/noir#7046)
fix(nargo_fmt): don't consider identifiers the same if they are equal…
(noir-lang/noir#7043)
feat: auto-import traits when suggesting trait methods
(noir-lang/noir#7037)
feat: avoid inserting `inc_rc` instructions into ACIR
(noir-lang/noir#7036)
fix(lsp): suggest all possible trait methods, but only visible ones
(noir-lang/noir#7027)
chore: add more protocol circuits to reports
(noir-lang/noir#6977)
feat: avoid generating a new witness when checking if linear expression
is zero (noir-lang/noir#7031)
feat: skip codegen of zero iteration loops
(noir-lang/noir#7030)
END_COMMIT_OVERRIDE

---------

Co-authored-by: Tom French <[email protected]>
Co-authored-by: Tom French <[email protected]>
Co-authored-by: Jake Fecher <[email protected]>
  • Loading branch information
4 people authored Jan 15, 2025
1 parent 57da116 commit 3ed22ed
Show file tree
Hide file tree
Showing 72 changed files with 1,433 additions and 300 deletions.
2 changes: 1 addition & 1 deletion .noir-sync-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
db28cb9ffb710c286b54dbfcf57292ae3dffb03d
9471e28ad6f02bf2fae3782c3db68106b615595f
3 changes: 2 additions & 1 deletion noir-projects/aztec-nr/aztec/src/macros/dispatch/mod.nr
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,9 @@ comptime fn str_size_in_fields(typ: Type) -> Option<u32> {
comptime fn struct_size_in_fields(typ: Type) -> Option<u32> {
typ.as_struct().map(|typ: (StructDefinition, [Type])| {
let struct_type = typ.0;
let generics = typ.1;
let mut size = 0;
for field in struct_type.fields() {
for field in struct_type.fields(generics) {
size += size_in_fields(field.1);
}
size
Expand Down
10 changes: 6 additions & 4 deletions noir-projects/aztec-nr/aztec/src/macros/notes/mod.nr
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ comptime fn generate_note_properties(s: StructDefinition) -> Quoted {
let property_selector_type = type_of(PropertySelector { index: 0, offset: 0, length: 0 });
let note_header_type: Type = type_of(NoteHeader::empty());

let non_header_fields = s.fields().filter(|(_, typ): (Quoted, Type)| typ != note_header_type);
let non_header_fields =
s.fields_as_written().filter(|(_, typ): (Quoted, Type)| typ != note_header_type);

let properties_types = non_header_fields
.map(|(name, _): (Quoted, Type)| quote { pub $name: $property_selector_type })
Expand Down Expand Up @@ -827,7 +828,7 @@ comptime fn index_note_fields(
let mut indexed_fixed_fields: [(Quoted, Type, u32)] = &[];
let mut indexed_nullable_fields = &[];
let mut counter: u32 = 0;
for field in s.fields() {
for field in s.fields_as_written() {
let (name, typ) = field;
if (typ != NOTE_HEADER_TYPE) {
if nullable_fields.all(|field| field != name) {
Expand All @@ -845,9 +846,10 @@ comptime fn index_note_fields(

/// Injects `NoteHeader` to the note struct if not present.
comptime fn inject_note_header(s: StructDefinition) {
let filtered_header = s.fields().filter(|(_, typ): (Quoted, Type)| typ == NOTE_HEADER_TYPE);
let filtered_header =
s.fields_as_written().filter(|(_, typ): (Quoted, Type)| typ == NOTE_HEADER_TYPE);
if (filtered_header.len() == 0) {
let new_fields = s.fields().push_back((quote { header }, NOTE_HEADER_TYPE));
let new_fields = s.fields_as_written().push_back((quote { header }, NOTE_HEADER_TYPE));
s.set_fields(new_fields);
}
}
Expand Down
3 changes: 2 additions & 1 deletion noir-projects/aztec-nr/aztec/src/macros/storage/mod.nr
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ pub comptime fn storage(s: StructDefinition) -> Quoted {
// TODO(#8658): uncomment the code below to inject the Context type parameter.
//let mut new_storage_fields = &[];
//let context_generic = s.add_generic("Context");
for field in s.fields() {
for field in s.fields_as_written() {
// FIXME: This doesn't handle field types with generics
let (name, typ) = field;
let (storage_field_constructor, serialized_size) =
generate_storage_field_constructor(typ, quote { $slot }, false);
Expand Down
14 changes: 9 additions & 5 deletions noir-projects/aztec-nr/aztec/src/macros/utils.nr
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,11 @@ comptime fn signature_of_type(typ: Type) -> Quoted {
let element_typ_quote = signature_of_type(element_type);
f"[{element_typ_quote};{array_len}]".quoted_contents()
} else if typ.as_struct().is_some() {
let (s, _) = typ.as_struct().unwrap();
let field_signatures =
s.fields().map(|(_, typ): (Quoted, Type)| signature_of_type(typ)).join(quote {,});
let (s, generics) = typ.as_struct().unwrap();
let field_signatures = s
.fields(generics)
.map(|(_, typ): (Quoted, Type)| signature_of_type(typ))
.join(quote {,});
f"({field_signatures})".quoted_contents()
} else if typ.as_tuple().is_some() {
// Note that tuples are handled the same way as structs
Expand Down Expand Up @@ -201,9 +203,11 @@ pub(crate) comptime fn compute_event_selector(s: StructDefinition) -> Field {
// The signature will be "Foo(Field,AztecAddress)".
let event_name = s.name();
let args_signatures = s
.fields()
.fields_as_written()
.map(|(_, typ): (Quoted, Type)| {
signature_of_type(typ) // signature_of_type can handle structs, so this supports nested structs
// signature_of_type can handle structs, so this supports nested structs
// FIXME: Field generics are not handled here!
signature_of_type(typ)
})
.join(quote {,});
let signature_quote = quote { $event_name($args_signatures) };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
unconstrained_config::{compute_roots_of_unity, D_INV, F, LOG_FIELDS_PER_BLOB},
};

use bigint::BigNum;
use bigint::{BigNum, BigNumTrait};
// Fixed hash method:
use types::hash::poseidon2_hash_subarray;
// Variable hash method:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use crate::blob_public_inputs::{BlobCommitment, BlockBlobPublicInputs};
use super::blob_public_inputs::Deserialize;
use types::{
abis::sponge_blob::SpongeBlob,
constants::{BLOB_PUBLIC_INPUTS, BLOBS_PER_BLOCK, FIELDS_PER_BLOB},
};

// TODO(#10323): this was added to save simulation time (~1min in ACVM, ~3mins in wasm -> 500ms).
// The use of bignum adds a lot of unconstrained code which overloads limits when simulating.
// If/when simulation times of unconstrained are improved, remove this.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use bigint::{BigNum, fields::bls12_381Fr::BLS12_381_Fr_Params};
use bigint::{bignum::{BigNum, BigNumTrait}, fields::bls12_381Fr::BLS12_381_Fr_Params};
use types::constants::FIELDS_PER_BLOB;

// TODO(#9982): Delete this file and go back to using config.nr - calculating ROOTS in unconstrained is insecure.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ pub comptime fn pack_from_fields<N>(
result = quote { $buffer[$already_consumed] as $typ };
consumed = 1;
} else if typ.as_struct().is_some() {
let (nested_def, _) = typ.as_struct().unwrap();
let (nested_def, generics) = typ.as_struct().unwrap();
let nested_name = nested_def.name();
let mut deserialized_fields_list = &[];
for field in nested_def.fields() {
for field in nested_def.fields(generics) {
let (field_name, field_type) = field;
let (deserialized_field, consumed_by_field) = pack_from_fields(
quote { $field_name },
Expand Down Expand Up @@ -106,7 +106,7 @@ pub comptime fn flatten_to_fields(name: Quoted, typ: Type, omit: [Quoted]) -> ([
} else if typ.as_struct().is_some() {
// For struct we pref
let nested_struct = typ.as_struct().unwrap();
let params = nested_struct.0.fields();
let params = nested_struct.0.fields(nested_struct.1);
let struct_flattened = params.map(|(param_name, param_type): (Quoted, Type)| {
let maybe_prefixed_name = if name == quote {} {
// Triggered when the param name is of a value available in the current scope (e.g. a function
Expand Down
3 changes: 2 additions & 1 deletion noir/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ function build {
if ! cache_download noir-$hash.tar.gz; then
# Fake this so artifacts have a consistent hash in the cache and not git hash dependent
export COMMIT_HASH="$(echo "$hash" | sed 's/-.*//g')"
parallel denoise ::: ./scripts/bootstrap_native.sh ./scripts/bootstrap_packages.sh
denoise ./scripts/bootstrap_native.sh
denoise ./scripts/bootstrap_packages.sh
cache_upload noir-$hash.tar.gz noir-repo/target/release/nargo noir-repo/target/release/acvm packages
fi
github_endgroup
Expand Down
3 changes: 3 additions & 0 deletions noir/noir-repo/.github/critical_libraries_status/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.actual.jsonl
.actual.jsonl.jq
.failures.jsonl.jq
26 changes: 26 additions & 0 deletions noir/noir-repo/.github/workflows/formatting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,29 @@ jobs:
- name: Format test suite
working-directory: ./test_programs
run: ./format.sh check

# This is a job which depends on all test jobs and reports the overall status.
# This allows us to add/remove test jobs without having to update the required workflows.
formatting-end:
name: Formatting End
runs-on: ubuntu-22.04
# We want this job to always run (even if the dependant jobs fail) as we want this job to fail rather than skipping.
if: ${{ always() }}
needs:
- clippy
- rustfmt
- eslint
- nargo_fmt

steps:
- name: Report overall success
run: |
if [[ $FAIL == true ]]; then
exit 1
else
exit 0
fi
env:
# We treat any skipped or failing jobs as a failure for the workflow as a whole.
FAIL: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') || contains(needs.*.result, 'skipped') }}

93 changes: 56 additions & 37 deletions noir/noir-repo/.github/workflows/reports.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,19 @@ jobs:
- name: Generate Brillig bytecode size report
working-directory: ./test_programs
run: |
./gates_report_brillig.sh
mv gates_report_brillig.json ../gates_report_brillig.json
mkdir ./reports
./gates_report_brillig.sh 9223372036854775807
jq '.programs |= map(.package_name |= (. + "_inliner_max"))' gates_report_brillig.json > ./reports/gates_report_brillig_inliner_max.json
./gates_report_brillig.sh 0
jq '.programs |= map(.package_name |= (. + "_inliner_zero"))' gates_report_brillig.json > ./reports/gates_report_brillig_inliner_zero.json
./gates_report_brillig.sh -9223372036854775808
jq '.programs |= map(.package_name |= (. + "_inliner_min"))' gates_report_brillig.json > ./reports/gates_report_brillig_inliner_min.json
# Merge all reports
jq -s '{ programs: map(.programs) | add }' ./reports/* > ../gates_report_brillig.json
- name: Compare Brillig bytecode size reports
id: brillig_bytecode_diff
Expand Down Expand Up @@ -165,8 +176,19 @@ jobs:
- name: Generate Brillig execution report
working-directory: ./test_programs
run: |
./gates_report_brillig_execution.sh
mv gates_report_brillig_execution.json ../gates_report_brillig_execution.json
mkdir ./reports
./gates_report_brillig_execution.sh 9223372036854775807
jq '.programs |= map(.package_name |= (. + "_inliner_max"))' gates_report_brillig_execution.json > ./reports/gates_report_brillig_execution_inliner_max.json
./gates_report_brillig_execution.sh 0
jq '.programs |= map(.package_name |= (. + "_inliner_zero"))' gates_report_brillig_execution.json > ./reports/gates_report_brillig_execution_inliner_zero.json
./gates_report_brillig_execution.sh -9223372036854775808
jq '.programs |= map(.package_name |= (. + "_inliner_min"))' gates_report_brillig_execution.json > ./reports/gates_report_brillig_execution_inliner_min.json
# Merge all reports
jq -s '{ programs: map(.programs) | add }' ./reports/* > ../gates_report_brillig_execution.json
- name: Compare Brillig execution reports
id: brillig_execution_diff
Expand Down Expand Up @@ -299,15 +321,18 @@ jobs:
fail-fast: false
matrix:
include:
# - project: { repo: AztecProtocol/aztec-packages, path: noir-projects/noir-contracts, is_library: true }
- project: { repo: AztecProtocol/aztec-packages, path: noir-projects/noir-protocol-circuits/crates/private-kernel-inner, take_average: true }
- project: { repo: AztecProtocol/aztec-packages, path: noir-projects/noir-protocol-circuits/crates/private-kernel-tail, take_average: true }
- project: { repo: AztecProtocol/aztec-packages, path: noir-projects/noir-protocol-circuits/crates/private-kernel-reset, take_average: true }
- project: { repo: AztecProtocol/aztec-packages, path: noir-projects/noir-protocol-circuits/crates/rollup-root, take_average: true }
#- project: { repo: AztecProtocol/aztec-packages, path: noir-projects/noir-protocol-circuits/crates/rollup-block-root }
- project: { repo: AztecProtocol/aztec-packages, path: noir-projects/noir-protocol-circuits/crates/rollup-block-merge, take_average: true }
- project: { repo: AztecProtocol/aztec-packages, path: noir-projects/noir-protocol-circuits/crates/rollup-base-private, take_average: true }
- project: { repo: AztecProtocol/aztec-packages, path: noir-projects/noir-protocol-circuits/crates/rollup-base-public, take_average: true }
# - project: { repo: AztecProtocol/aztec-packages, path: noir-projects/noir-contracts, cannot_execute: true }
- project: { repo: AztecProtocol/aztec-packages, path: noir-projects/noir-protocol-circuits/crates/private-kernel-inner, num_runs: 5 }
- project: { repo: AztecProtocol/aztec-packages, path: noir-projects/noir-protocol-circuits/crates/private-kernel-tail, num_runs: 5 }
- project: { repo: AztecProtocol/aztec-packages, path: noir-projects/noir-protocol-circuits/crates/private-kernel-reset, num_runs: 5 }
- project: { repo: AztecProtocol/aztec-packages, path: noir-projects/noir-protocol-circuits/crates/rollup-base-private, num_runs: 5 }
- project: { repo: AztecProtocol/aztec-packages, path: noir-projects/noir-protocol-circuits/crates/rollup-base-public, num_runs: 5 }
- project: { repo: AztecProtocol/aztec-packages, path: noir-projects/noir-protocol-circuits/crates/rollup-block-merge, num_runs: 5 }
- project: { repo: AztecProtocol/aztec-packages, path: noir-projects/noir-protocol-circuits/crates/rollup-block-root-empty, num_runs: 5, cannot_execute: true }
- project: { repo: AztecProtocol/aztec-packages, path: noir-projects/noir-protocol-circuits/crates/rollup-block-root-single-tx, num_runs: 1, flags: "--skip-brillig-constraints-check --skip-underconstrained-check", cannot_execute: true }
- project: { repo: AztecProtocol/aztec-packages, path: noir-projects/noir-protocol-circuits/crates/rollup-block-root, num_runs: 1, flags: "--skip-brillig-constraints-check --skip-underconstrained-check" }
- project: { repo: AztecProtocol/aztec-packages, path: noir-projects/noir-protocol-circuits/crates/rollup-merge, num_runs: 5 }
- project: { repo: AztecProtocol/aztec-packages, path: noir-projects/noir-protocol-circuits/crates/rollup-root, num_runs: 5 }

name: External repo compilation and execution reports - ${{ matrix.project.repo }}/${{ matrix.project.path }}
steps:
Expand Down Expand Up @@ -349,33 +374,17 @@ jobs:
touch parse_time.sh
chmod +x parse_time.sh
cp /home/runner/work/noir/noir/scripts/test_programs/parse_time.sh ./parse_time.sh
./compilation_report.sh 1
- name: Generate compilation report with averages
working-directory: ./test-repo/${{ matrix.project.path }}
if: ${{ matrix.project.take_average }}
run: |
mv /home/runner/work/noir/noir/scripts/test_programs/compilation_report.sh ./compilation_report.sh
touch parse_time.sh
chmod +x parse_time.sh
cp /home/runner/work/noir/noir/scripts/test_programs/parse_time.sh ./parse_time.sh
./compilation_report.sh 1 1
- name: Generate execution report without averages
working-directory: ./test-repo/${{ matrix.project.path }}
if: ${{ !matrix.project.is_library && !matrix.project.take_average }}
run: |
mv /home/runner/work/noir/noir/scripts/test_programs/execution_report.sh ./execution_report.sh
mv /home/runner/work/noir/noir/scripts/test_programs/parse_time.sh ./parse_time.sh
./execution_report.sh 1
./compilation_report.sh 1 ${{ matrix.project.num_runs }}
env:
FLAGS: ${{ matrix.project.flags }}

- name: Generate execution report with averages
- name: Generate execution report
working-directory: ./test-repo/${{ matrix.project.path }}
if: ${{ !matrix.project.is_library && matrix.project.take_average }}
if: ${{ !matrix.project.cannot_execute }}
run: |
mv /home/runner/work/noir/noir/scripts/test_programs/execution_report.sh ./execution_report.sh
mv /home/runner/work/noir/noir/scripts/test_programs/parse_time.sh ./parse_time.sh
./execution_report.sh 1 1
./execution_report.sh 1 ${{ matrix.project.num_runs }}
- name: Move compilation report
id: compilation_report
Expand All @@ -389,7 +398,7 @@ jobs:
- name: Move execution report
id: execution_report
shell: bash
if: ${{ !matrix.project.is_library }}
if: ${{ !matrix.project.cannot_execute }}
run: |
PACKAGE_NAME=${{ matrix.project.path }}
PACKAGE_NAME=$(basename $PACKAGE_NAME)
Expand Down Expand Up @@ -467,10 +476,16 @@ jobs:
# TODO: Bring this report back under a flag. The `noir-contracts` report takes just under 30 minutes.
# - project: { repo: AztecProtocol/aztec-packages, path: noir-projects/noir-contracts }
- project: { repo: AztecProtocol/aztec-packages, path: noir-projects/noir-protocol-circuits/crates/private-kernel-inner }
- project: { repo: AztecProtocol/aztec-packages, path: noir-projects/noir-protocol-circuits/crates/private-kernel-tail }
- project: { repo: AztecProtocol/aztec-packages, path: noir-projects/noir-protocol-circuits/crates/private-kernel-reset }
- project: { repo: AztecProtocol/aztec-packages, path: noir-projects/noir-protocol-circuits/crates/private-kernel-tail }
- project: { repo: AztecProtocol/aztec-packages, path: noir-projects/noir-protocol-circuits/crates/rollup-base-private }
- project: { repo: AztecProtocol/aztec-packages, path: noir-projects/noir-protocol-circuits/crates/rollup-base-public }
- project: { repo: AztecProtocol/aztec-packages, path: noir-projects/noir-protocol-circuits/crates/rollup-block-merge }
- project: { repo: AztecProtocol/aztec-packages, path: noir-projects/noir-protocol-circuits/crates/rollup-block-root-empty, cannot_execute: true }
- project: { repo: AztecProtocol/aztec-packages, path: noir-projects/noir-protocol-circuits/crates/rollup-block-root-single-tx, flags: "--skip-brillig-constraints-check --skip-underconstrained-check", cannot_execute: true }
- project: { repo: AztecProtocol/aztec-packages, path: noir-projects/noir-protocol-circuits/crates/rollup-block-root, flags: "--skip-brillig-constraints-check --skip-underconstrained-check" }
- project: { repo: AztecProtocol/aztec-packages, path: noir-projects/noir-protocol-circuits/crates/rollup-merge }
- project: { repo: AztecProtocol/aztec-packages, path: noir-projects/noir-protocol-circuits/crates/rollup-root }

name: External repo memory report - ${{ matrix.project.repo }}/${{ matrix.project.path }}
steps:
Expand Down Expand Up @@ -509,9 +524,12 @@ jobs:
./memory_report.sh 1
# Rename the memory report as the execution report is about to write to the same file
cp memory_report.json compilation_memory_report.json
env:
FLAGS: ${{ matrix.project.flags }}

- name: Generate execution memory report
working-directory: ./test-repo/${{ matrix.project.path }}
if: ${{ !matrix.project.cannot_execute }}
run: |
./memory_report.sh 1 1
Expand All @@ -534,6 +552,7 @@ jobs:

- name: Move execution report
id: execution_mem_report
if: ${{ !matrix.project.cannot_execute }}
shell: bash
run: |
PACKAGE_NAME=${{ matrix.project.path }}
Expand Down
1 change: 1 addition & 0 deletions noir/noir-repo/CRITICAL_NOIR_LIBRARIES
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
https://github.com/noir-lang/noir_check_shuffle
https://github.com/noir-lang/ec
https://github.com/noir-lang/eddsa
https://github.com/noir-lang/mimc
Expand Down
Loading

0 comments on commit 3ed22ed

Please sign in to comment.