Skip to content

Commit

Permalink
feat: Sync from noir (#11138)
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
feat!: require trait primitive functions/calls to have their trait in
scope (noir-lang/noir#6901)
feat(lsp): use trait method docs for trait impl method docs on hover
(noir-lang/noir#7003)
chore: turn on averaging for protocol circuits metrics in CI
(noir-lang/noir#6999)
feat(comptime): Implement to_be_bits and to_le_bits in the interpreter
(noir-lang/noir#7008)
chore: Add short circuit in ssa-gen for known if conditions
(noir-lang/noir#7007)
chore: Only resolved globals monomorphization
(noir-lang/noir#7006)
chore: Remove resolve_is_unconstrained pass
(noir-lang/noir#7004)
chore: require safety doc comment for unsafe instead of `//@safety`
(noir-lang/noir#6992)
fix: Reproduce and fix bytecode blowup
(noir-lang/noir#6972)
chore: mark casts as able to be deduplicated
(noir-lang/noir#6996)
fix: return trait impl method as FuncId if there's only one
(noir-lang/noir#6989)
chore(ci): fail properly in `external-repo-checks`
(noir-lang/noir#6988)
fix: allow multiple trait impls for the same trait as long as one is in
scope (noir-lang/noir#6987)
chore: Use DFG in SSA printer
(noir-lang/noir#6986)
chore!: Reserve `enum` and `match` keywords
(noir-lang/noir#6961)
END_COMMIT_OVERRIDE

---------

Co-authored-by: Tom French <[email protected]>
  • Loading branch information
AztecBot and TomAFrench authored Jan 11, 2025
1 parent 9b99126 commit 9189120
Show file tree
Hide file tree
Showing 1,069 changed files with 2,526 additions and 90,888 deletions.
2 changes: 1 addition & 1 deletion .noir-sync-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3c488f4b272f460383341c51270b87bfe2b94468
db28cb9ffb710c286b54dbfcf57292ae3dffb03d
4 changes: 2 additions & 2 deletions noir-projects/aztec-nr/authwit/src/cheatcodes.nr
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ where
C: CallInterface<M>,
{
let target = call_interface.get_contract_address();
let inputs = cheatcodes::get_private_context_inputs(get_block_number());
let inputs = unsafe { cheatcodes::get_private_context_inputs(get_block_number()) };
let chain_id = inputs.tx_context.chain_id;
let version = inputs.tx_context.version;
let args_hash = hash_args(call_interface.get_args());
let selector = call_interface.get_selector();
let inner_hash =
compute_inner_authwit_hash([caller.to_field(), selector.to_field(), args_hash]);
let message_hash = compute_authwit_message_hash(target, chain_id, version, inner_hash);
cheatcodes::add_authwit(on_behalf_of, message_hash);
unsafe { cheatcodes::add_authwit(on_behalf_of, message_hash) };
}

pub unconstrained fn add_public_authwit_from_call_interface<C, let M: u32>(
Expand Down
32 changes: 18 additions & 14 deletions noir-projects/aztec-nr/aztec/src/context/private_context.nr
Original file line number Diff line number Diff line change
Expand Up @@ -494,13 +494,15 @@ impl PrivateContext {
// new_args = [selector, ...old_args], so as to make it suitable to call the public dispatch function.
// We don't validate or compute it in the circuit because a) it's harder to do with slices, and
// b) this is only temporary.
let args_hash = enqueue_public_function_call_internal(
contract_address,
function_selector,
args_hash,
counter,
is_static_call,
);
let args_hash = unsafe {
enqueue_public_function_call_internal(
contract_address,
function_selector,
args_hash,
counter,
is_static_call,
)
};

// Public calls are rerouted through the dispatch function.
let function_selector = comptime { FunctionSelector::from_field(PUBLIC_DISPATCH_SELECTOR) };
Expand Down Expand Up @@ -548,13 +550,15 @@ impl PrivateContext {
// new_args = [selector, ...old_args], so as to make it suitable to call the public dispatch function.
// We don't validate or compute it in the circuit because a) it's harder to do with slices, and
// b) this is only temporary.
let args_hash = set_public_teardown_function_call_internal(
contract_address,
function_selector,
args_hash,
counter,
is_static_call,
);
let args_hash = unsafe {
set_public_teardown_function_call_internal(
contract_address,
function_selector,
args_hash,
counter,
is_static_call,
)
};

let function_selector = comptime { FunctionSelector::from_field(PUBLIC_DISPATCH_SELECTOR) };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,24 @@ pub unconstrained fn get_contract_instance_initialization_hash_internal_avm(
}

pub fn get_contract_instance_deployer_avm(address: AztecAddress) -> Option<AztecAddress> {
let (member, exists) = get_contract_instance_deployer_internal_avm(address);
let (member, exists) = unsafe { get_contract_instance_deployer_internal_avm(address) };
if exists {
Option::some(AztecAddress::from_field(member))
} else {
Option::none()
}
}
pub fn get_contract_instance_class_id_avm(address: AztecAddress) -> Option<ContractClassId> {
let (member, exists) = get_contract_instance_class_id_internal_avm(address);
let (member, exists) = unsafe { get_contract_instance_class_id_internal_avm(address) };
if exists {
Option::some(ContractClassId::from_field(member))
} else {
Option::none()
}
}
pub fn get_contract_instance_initialization_hash_avm(address: AztecAddress) -> Option<Field> {
let (member, exists) = get_contract_instance_initialization_hash_internal_avm(address);
let (member, exists) =
unsafe { get_contract_instance_initialization_hash_internal_avm(address) };
if exists {
Option::some(member)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ contract ContractClassRegisterer {
// TODO: We should be able to remove public_bytecode_commitment from the input if it's calculated in this function
// docs:start:pop_capsule
let packed_public_bytecode: [Field; MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS] =
pop_capsule();
unsafe { pop_capsule() };
// docs:end:pop_capsule
// First field element contains the length of the bytecode
let bytecode_length_in_bytes: u32 = packed_public_bytecode[0] as u32;
Expand Down Expand Up @@ -121,7 +121,7 @@ contract ContractClassRegisterer {
function_data: InnerPrivateFunction,
) {
let private_bytecode: [Field; MAX_PACKED_BYTECODE_SIZE_PER_PRIVATE_FUNCTION_IN_FIELDS] =
pop_capsule();
unsafe { pop_capsule() };

let event = ClassPrivateFunctionBroadcasted {
contract_class_id,
Expand Down Expand Up @@ -162,7 +162,7 @@ contract ContractClassRegisterer {
function_data: InnerUnconstrainedFunction,
) {
let unconstrained_bytecode: [Field; MAX_PACKED_BYTECODE_SIZE_PER_UNCONSTRAINED_FUNCTION_IN_FIELDS] =
pop_capsule();
unsafe { pop_capsule() };
let event = ClassUnconstrainedFunctionBroadcasted {
contract_class_id,
artifact_metadata_hash,
Expand Down Expand Up @@ -203,7 +203,8 @@ contract ContractClassRegisterer {
// cannot prove non-registration. Therefore, it is possible that a malicious oracle might prevent sequencers
// from including transactions with calls to certain badly-broadcasted contracts.
// TODO(#8978): review correctness
let log_hash = emit_contract_class_unencrypted_log_private(contract_address, log, counter);
let log_hash =
unsafe { emit_contract_class_unencrypted_log_private(contract_address, log, counter) };

// 40 = addr (32) + raw log len (4) + processed log len (4)
context.contract_class_logs_hashes.push(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
use dep::aztec::{
note::{note_getter::{MAX_NOTES_PER_PAGE, view_notes}, note_viewer_options::NoteViewerOptions},
prelude::AztecAddress,
protocol_types::storage::map::derive_storage_slot_in_map,
test::helpers::test_environment::TestEnvironment,
};
use dep::aztec::{prelude::AztecAddress, test::helpers::test_environment::TestEnvironment};

use crate::EasyPrivateVoting;

pub fn setup() -> (&mut TestEnvironment, AztecAddress, AztecAddress) {
let mut env = TestEnvironment::new();
let mut env = unsafe { TestEnvironment::new() };

let admin = env.create_account();
let admin = unsafe { env.create_account() };

let initializer_call_interface = EasyPrivateVoting::interface().constructor(admin);
let voting_contract = env.deploy_self("EasyPrivateVoting").with_public_void_initializer(
initializer_call_interface,
);
let voting_contract = unsafe {
env.deploy_self("EasyPrivateVoting").with_public_void_initializer(initializer_call_interface)
};
// std::println(voting_contract);
(&mut env, voting_contract.to_address(), admin)
}
3 changes: 2 additions & 1 deletion noir/noir-repo/.github/scripts/check_test_results.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ if [ -f $1 ] && [ -f $2 ]; then
echo "Error: test failures don't match expected failures"
echo "Lines prefixed with '>' are new test failures (you could add them to '$1')"
echo "Lines prefixed with '<' are tests that were expected to fail but passed (you could remove them from '$1')"
exit -1
fi
elif [ -f $1 ]; then
# Only the expected file exists, which means the actual test couldn't be compiled.
Expand All @@ -35,4 +36,4 @@ else
# Both files don't exists, which means we are expecting the external library not
# to compile, and it didn't, so all is good.
exit 0
fi
fi
20 changes: 11 additions & 9 deletions noir/noir-repo/.github/workflows/reports.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:
./rebuild.sh
./gates_report.sh
mv gates_report.json ../gates_report.json
- name: Compare gates reports
id: gates_diff
uses: noir-lang/noir-gates-diff@7e4ddaa91c69380f15ccba514eac17bc7432a8cc
Expand Down Expand Up @@ -139,7 +139,7 @@ jobs:
message: ${{ steps.brillig_bytecode_diff.outputs.markdown }}

compare_brillig_execution_reports:
name: Brillig execution trace sizes
name: Brillig execution trace sizes
needs: [build-nargo]
runs-on: ubuntu-22.04
permissions:
Expand Down Expand Up @@ -188,7 +188,7 @@ jobs:
message: ${{ steps.brillig_execution_diff.outputs.markdown }}

generate_memory_report:
name: Peak memory usage
name: Peak memory usage
needs: [build-nargo]
runs-on: ubuntu-22.04
permissions:
Expand Down Expand Up @@ -303,11 +303,11 @@ jobs:
- 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 }
- 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 }
- 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, 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 }

name: External repo compilation and execution reports - ${{ matrix.project.repo }}/${{ matrix.project.path }}
steps:
Expand Down Expand Up @@ -576,17 +576,19 @@ jobs:
run: |
mv ./.github/scripts/merge-bench-reports.sh merge-bench-reports.sh
./merge-bench-reports.sh memory_report
# Rename the memory report as to not clash with the compilation memory report file name
cp memory_report.json execution_memory_report.json
- name: Parse compilation memory report
id: compilation_mem_report
uses: noir-lang/noir-bench-report@6ba151d7795042c4ff51864fbeb13c0a6a79246c
with:
report: memory_report.json
report: execution_memory_report.json
header: |
Compilation Memory Report
memory_report: true

- name: Add memory report to sticky comment
- name: Add execution memory report to sticky comment
if: github.event_name == 'pull_request' || github.event_name == 'pull_request_target'
uses: marocchino/sticky-pull-request-comment@v2
with:
Expand Down
17 changes: 11 additions & 6 deletions noir/noir-repo/.github/workflows/test-js-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
yarn-lock:
runs-on: ubuntu-22.04
timeout-minutes: 30

steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down Expand Up @@ -492,7 +492,7 @@ jobs:
uses: foundry-rs/[email protected]
with:
version: nightly-8660e5b941fe7f4d67e246cfd3dafea330fb53b1


- name: Install `bb`
run: |
Expand Down Expand Up @@ -530,10 +530,10 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Build list of libraries
id: get_critical_libraries
run: |
run: |
LIBRARIES=$(grep -Po "^https://github.com/\K.+" ./CRITICAL_NOIR_LIBRARIES | jq -R -s -c 'split("\n") | map(select(. != "")) | map({ repo: ., path: ""})')
echo "libraries=$LIBRARIES"
echo "libraries=$LIBRARIES" >> $GITHUB_OUTPUT
Expand Down Expand Up @@ -593,11 +593,16 @@ jobs:
# Github actions seems to not expand "**" in globs by default.
shopt -s globstar
sed -i '/^compiler_version/d' ./**/Nargo.toml
- name: Run nargo test
working-directory: ./test-repo/${{ matrix.project.path }}
run: |
nargo test --silence-warnings --skip-brillig-constraints-check --format json ${{ matrix.project.nargo_args }} | tee ${{ github.workspace }}/noir-repo/.github/critical_libraries_status/${{ matrix.project.repo }}/${{ matrix.project.path }}.actual.jsonl
output_file=${{ github.workspace }}/noir-repo/.github/critical_libraries_status/${{ matrix.project.repo }}/${{ matrix.project.path }}.actual.jsonl
nargo test --silence-warnings --skip-brillig-constraints-check --format json ${{ matrix.project.nargo_args }} | tee $output_file
if [ ! -s $output_file ]; then
# The file is empty so we delete it to signal that `nargo test` failed before it could run any tests
rm -f $output_file
fi
env:
NARGO_IGNORE_TEST_FAILURES_FROM_FOREIGN_CALLS: true

Expand Down
4 changes: 2 additions & 2 deletions noir/noir-repo/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 20 additions & 3 deletions noir/noir-repo/compiler/noirc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ pub struct CompileOptions {
/// Only show SSA passes whose name contains the provided string.
/// This setting takes precedence over `show_ssa` if it's not empty.
#[arg(long, hide = true)]
pub show_ssa_pass_name: Option<String>,
pub show_ssa_pass: Option<String>,

/// Only show the SSA and ACIR for the contract function with a given name.
#[arg(long, hide = true)]
pub show_contract_fn: Option<String>,

/// Emit the unoptimized SSA IR to file.
/// The IR will be dumped into the workspace target directory,
Expand Down Expand Up @@ -442,6 +446,11 @@ pub fn compile_contract(

if options.print_acir {
for contract_function in &compiled_contract.functions {
if let Some(ref name) = options.show_contract_fn {
if name != &contract_function.name {
continue;
}
}
println!(
"Compiled ACIR for {}::{} (unoptimized):",
compiled_contract.name, contract_function.name
Expand Down Expand Up @@ -486,7 +495,15 @@ fn compile_contract_inner(
continue;
}

let function = match compile_no_check(context, options, function_id, None, true) {
let mut options = options.clone();

if let Some(ref name_filter) = options.show_contract_fn {
let show = name == *name_filter;
options.show_ssa &= show;
options.show_ssa_pass = options.show_ssa_pass.filter(|_| show);
};

let function = match compile_no_check(context, &options, function_id, None, true) {
Ok(function) => function,
Err(new_error) => {
errors.push(FileDiagnostic::from(new_error));
Expand Down Expand Up @@ -642,7 +659,7 @@ pub fn compile_no_check(

let return_visibility = program.return_visibility;
let ssa_evaluator_options = noirc_evaluator::ssa::SsaEvaluatorOptions {
ssa_logging: match &options.show_ssa_pass_name {
ssa_logging: match &options.show_ssa_pass {
Some(string) => SsaLogging::Contains(string.clone()),
None => {
if options.show_ssa {
Expand Down
Loading

0 comments on commit 9189120

Please sign in to comment.