Skip to content

Commit

Permalink
feat: Sync from noir (AztecProtocol/aztec-packages#6986)
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: avoid `bn254_blackbox_solver` polluting feature flags
(#5141)
chore!: remove `distinct` keyword
(#5219)
feat: Sync from aztec-packages
(#5222)
chore: add some property tests to ACVM crates
(#5215)
chore: inline `FieldElement.is_negative` and document
(#5214)
chore!: remove `param_witnesses` and `return_witnesses` from ABI
(#5154)
chore: move implementation of bitwise operations into `blackbox_solver`
(#5209)
chore: remove stale comment
(#5179)
chore: make `nargo` crate and debug info generic
(#5184)
feat!: add session id to foreign call RPC requests
(#5205)
chore(docs): fix incorrect docs github link in footer
(#5206)
fix: error for allocate instructions in acir-gen
(#5200)
feat: Implement println in the comptime interpreter
(#5197)
chore(docs): Supplement Noir Debugger's dependency versions
(#5199)
chore(docs): Update docs homepage
(#5198)
chore: add more lints related to oracle calls
(#5193)
feat: standardize pedersen functions to return `EmbeddedCurvePoint`
(#5190)
END_COMMIT_OVERRIDE

---------

Co-authored-by: Tom French <[email protected]>
Co-authored-by: Tom French <[email protected]>
Co-authored-by: Maxim Vezenov <[email protected]>
  • Loading branch information
4 people committed Jun 13, 2024
1 parent ff67e14 commit 7c0d30f
Show file tree
Hide file tree
Showing 41 changed files with 154 additions and 191 deletions.
2 changes: 1 addition & 1 deletion .aztec-sync-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
86a33140f9a65e518003b3f4c60f97d132f85b89
12af650f0d27c37dca06bb329bf76a5574534d78
1 change: 1 addition & 0 deletions Cargo.lock

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

8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ noirc_abi = { path = "tooling/noirc_abi" }
bb_abstraction_leaks = { path = "tooling/bb_abstraction_leaks" }
acvm_cli = { path = "tooling/acvm_cli" }

# Arkworks
ark-bn254 = { version = "^0.4.0", default-features = false, features = ["curve"] }
ark-bls12-381 = { version = "^0.4.0", default-features = false, features = ["curve"] }
grumpkin = { version = "0.1.0", package = "noir_grumpkin", features = ["std"] }
ark-ec = { version = "^0.4.0", default-features = false }
ark-ff = { version = "^0.4.0", default-features = false }
ark-std = { version = "^0.4.0", default-features = false }

# Misc utils crates
iter-extended = { path = "utils/iter-extended" }

Expand Down
6 changes: 3 additions & 3 deletions acvm-repo/acir_field/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ hex.workspace = true
num-bigint.workspace = true
serde.workspace = true

ark-bn254 = { version = "^0.4.0", default-features = false, features = ["curve"] }
ark-bls12-381 = { version = "^0.4.0", optional = true, default-features = false, features = ["curve"] }
ark-ff = { version = "^0.4.0", default-features = false }
ark-bn254.workspace = true
ark-bls12-381 = { workspace = true, optional = true }
ark-ff.workspace = true

cfg-if = "1.0.0"

Expand Down
2 changes: 1 addition & 1 deletion acvm-repo/acvm_js/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function run_if_available {
require_command jq
require_command cargo
require_command wasm-bindgen
require_command wasm-opt
#require_command wasm-opt

self_path=$(dirname "$(readlink -f "$0")")
pname=$(cargo read-manifest | jq -r '.name')
Expand Down
14 changes: 5 additions & 9 deletions acvm-repo/bn254_blackbox_solver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ acvm_blackbox_solver.workspace = true
hex.workspace = true
lazy_static = "1.4"

# BN254 fixed base scalar multiplication solver
grumpkin = { version = "0.1.0", package = "noir_grumpkin", features = ["std"] }
ark-ec = { version = "^0.4.0", default-features = false }
ark-ff = { version = "^0.4.0", default-features = false }
ark-bn254.workspace = true
grumpkin.workspace = true
ark-ec.workspace = true
ark-ff.workspace = true
num-bigint.workspace = true

[dev-dependencies]
ark-std = { version = "^0.4.0", default-features = false }
ark-std.workspace = true
criterion = "0.5.0"
pprof = { version = "0.12", features = [
"flamegraph",
Expand All @@ -36,7 +36,3 @@ pprof = { version = "0.12", features = [
[[bench]]
name = "criterion"
harness = false

[features]
default = ["bn254"]
bn254 = ["acir/bn254"]
3 changes: 2 additions & 1 deletion acvm-repo/bn254_blackbox_solver/src/embedded_curve_ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ use ark_ec::AffineRepr;
use ark_ff::MontConfig;
use num_bigint::BigUint;

use crate::FieldElement;
use acir::AcirField;
use acir::BlackBoxFunc;
use acir::{AcirField, FieldElement};

use crate::BlackBoxResolutionError;

Expand Down
5 changes: 4 additions & 1 deletion acvm-repo/bn254_blackbox_solver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#![warn(clippy::semicolon_if_nothing_returned)]
#![cfg_attr(not(test), warn(unused_crate_dependencies, unused_extern_crates))]

use acir::FieldElement;
use acvm_blackbox_solver::{BlackBoxFunctionSolver, BlackBoxResolutionError};

mod embedded_curve_ops;
Expand All @@ -15,6 +14,10 @@ use ark_ec::AffineRepr;
pub use embedded_curve_ops::{embedded_curve_add, multi_scalar_mul};
pub use poseidon2::poseidon2_permutation;

// Temporary hack, this ensure that we always use a bn254 field here
// without polluting the feature flags of the `acir_field` crate.
type FieldElement = acir::acir_field::GenericFieldElement<ark_bn254::Fr>;

#[derive(Default)]
pub struct Bn254BlackBoxSolver;

Expand Down
3 changes: 2 additions & 1 deletion acvm-repo/bn254_blackbox_solver/src/pedersen/commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ pub(crate) fn commit_native_with_index(
#[cfg(test)]
mod test {

use acir::{AcirField, FieldElement};
use acir::AcirField;
use ark_ec::short_weierstrass::Affine;
use ark_std::{One, Zero};
use grumpkin::Fq;

use crate::pedersen::commitment::commit_native_with_index;
use crate::FieldElement;

#[test]
fn commitment() {
Expand Down
3 changes: 2 additions & 1 deletion acvm-repo/bn254_blackbox_solver/src/pedersen/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ fn length_generator() -> &'static Affine<GrumpkinParameters> {
pub(crate) mod test {

use super::*;
use crate::FieldElement;

use acir::{AcirField, FieldElement};
use acir::AcirField;
use ark_std::One;
use grumpkin::Fq;

Expand Down
8 changes: 5 additions & 3 deletions acvm-repo/bn254_blackbox_solver/src/poseidon2.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use acir::{AcirField, FieldElement};
use acir::AcirField;
use acvm_blackbox_solver::BlackBoxResolutionError;
use lazy_static::lazy_static;

use crate::FieldElement;

pub fn poseidon2_permutation(
inputs: &[FieldElement],
len: u32,
Expand Down Expand Up @@ -543,9 +545,9 @@ impl<'a> Poseidon2<'a> {

#[cfg(test)]
mod test {
use acir::{AcirField, FieldElement};
use acir::AcirField;

use super::{field_from_hex, poseidon2_permutation};
use super::{field_from_hex, poseidon2_permutation, FieldElement};

#[test]
fn smoke_test() {
Expand Down
3 changes: 2 additions & 1 deletion acvm-repo/bn254_blackbox_solver/src/schnorr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@ fn schnorr_generate_challenge(

#[cfg(test)]
mod schnorr_tests {
use acir::{AcirField, FieldElement};
use acir::AcirField;

use super::verify_signature;
use crate::FieldElement;

#[test]
fn verifies_valid_signature() {
Expand Down
4 changes: 2 additions & 2 deletions aztec_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mod utils;

use noirc_errors::Location;
use transforms::{
compute_note_hash_and_nullifier::inject_compute_note_hash_and_nullifier,
compute_note_hash_and_optionally_a_nullifier::inject_compute_note_hash_and_optionally_a_nullifier,
contract_interface::{
generate_contract_interface, stub_function, update_fn_signatures_in_contract_interface,
},
Expand Down Expand Up @@ -236,7 +236,7 @@ fn transform_hir(
) -> Result<(), (AztecMacroError, FileId)> {
if has_aztec_dependency(crate_id, context) {
transform_events(crate_id, context)?;
inject_compute_note_hash_and_nullifier(crate_id, context)?;
inject_compute_note_hash_and_optionally_a_nullifier(crate_id, context)?;
assign_storage_slots(crate_id, context)?;
inject_note_exports(crate_id, context)?;
update_fn_signatures_in_contract_interface(crate_id, context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,26 @@ use crate::utils::{
},
};

// Check if "compute_note_hash_and_nullifier(AztecAddress,Field,Field,Field,[Field; N]) -> [Field; 4]" is defined
fn check_for_compute_note_hash_and_nullifier_definition(
// Check if "compute_note_hash_and_optionally_a_nullifier(AztecAddress,Field,Field,Field,bool,[Field; N]) -> [Field; 4]" is defined
fn check_for_compute_note_hash_and_optionally_a_nullifier_definition(
crate_id: &CrateId,
context: &HirContext,
) -> bool {
collect_crate_functions(crate_id, context).iter().any(|funct_id| {
let func_data = context.def_interner.function_meta(funct_id);
let func_name = context.def_interner.function_name(funct_id);
func_name == "compute_note_hash_and_nullifier"
&& func_data.parameters.len() == 5
func_name == "compute_note_hash_and_optionally_a_nullifier"
&& func_data.parameters.len() == 6
&& func_data.parameters.0.first().is_some_and(| (_, typ, _) | match typ {
Type::Struct(struct_typ, _) => struct_typ.borrow().name.0.contents == "AztecAddress",
_ => false
})
&& func_data.parameters.0.get(1).is_some_and(|(_, typ, _)| typ.is_field())
&& func_data.parameters.0.get(2).is_some_and(|(_, typ, _)| typ.is_field())
&& func_data.parameters.0.get(3).is_some_and(|(_, typ, _)| typ.is_field())
// checks if the 5th parameter is an array and contains only fields
&& func_data.parameters.0.get(4).is_some_and(|(_, typ, _)| match typ {
&& func_data.parameters.0.get(4).is_some_and(|(_, typ, _)| typ.is_bool())
// checks if the 6th parameter is an array and contains only fields
&& func_data.parameters.0.get(5).is_some_and(|(_, typ, _)| match typ {
Type::Array(_, inner_type) => inner_type.to_owned().is_field(),
_ => false
})
Expand All @@ -49,16 +50,16 @@ fn check_for_compute_note_hash_and_nullifier_definition(
})
}

pub fn inject_compute_note_hash_and_nullifier(
pub fn inject_compute_note_hash_and_optionally_a_nullifier(
crate_id: &CrateId,
context: &mut HirContext,
) -> Result<(), (AztecMacroError, FileId)> {
if let Some((_, module_id, file_id)) = get_contract_module_data(context, crate_id) {
// If compute_note_hash_and_nullifier is already defined by the user, we skip auto-generation in order to provide an
// If compute_note_hash_and_optionally_a_nullifier is already defined by the user, we skip auto-generation in order to provide an
// escape hatch for this mechanism.
// TODO(#4647): improve this diagnosis and error messaging.
if context.crate_graph.root_crate_id() != crate_id
|| check_for_compute_note_hash_and_nullifier_definition(crate_id, context)
|| check_for_compute_note_hash_and_optionally_a_nullifier_definition(crate_id, context)
{
return Ok(());
}
Expand All @@ -69,14 +70,14 @@ pub fn inject_compute_note_hash_and_nullifier(
let max_note_length_const = get_global_numberic_const(context, "MAX_NOTE_FIELDS_LENGTH")
.map_err(|err| {
(
AztecMacroError::CouldNotImplementComputeNoteHashAndNullifier {
AztecMacroError::CouldNotImplementComputeNoteHashAndOptionallyANullifier {
secondary_message: Some(err.primary_message),
},
file_id,
)
})?;

// In order to implement compute_note_hash_and_nullifier, we need to know all of the different note types the
// In order to implement compute_note_hash_and_optionally_a_nullifier, we need to know all of the different note types the
// contract might use and their serialized lengths. These are the types that are marked as #[aztec(note)].
let mut notes_and_lengths = vec![];

Expand All @@ -89,7 +90,7 @@ pub fn inject_compute_note_hash_and_nullifier(
)
.map_err(|_err| {
(
AztecMacroError::CouldNotImplementComputeNoteHashAndNullifier {
AztecMacroError::CouldNotImplementComputeNoteHashAndOptionallyANullifier {
secondary_message: Some(format!(
"Failed to get serialized length for note type {}",
path
Expand All @@ -102,7 +103,7 @@ pub fn inject_compute_note_hash_and_nullifier(

if serialized_len > max_note_length_const {
return Err((
AztecMacroError::CouldNotImplementComputeNoteHashAndNullifier {
AztecMacroError::CouldNotImplementComputeNoteHashAndOptionallyANullifier {
secondary_message: Some(format!(
"Note type {} as {} fields, which is more than the maximum allowed length of {}.",
path,
Expand All @@ -120,11 +121,12 @@ pub fn inject_compute_note_hash_and_nullifier(
let max_note_length: u128 =
*notes_and_lengths.iter().map(|(_, serialized_len)| serialized_len).max().unwrap_or(&0);

let note_types =
let note_types: Vec<String> =
notes_and_lengths.iter().map(|(note_type, _)| note_type.clone()).collect::<Vec<_>>();

// We can now generate a version of compute_note_hash_and_nullifier tailored for the contract in this crate.
let func = generate_compute_note_hash_and_nullifier(&note_types, max_note_length);
// We can now generate a version of compute_note_hash_and_optionally_a_nullifier tailored for the contract in this crate.
let func =
generate_compute_note_hash_and_optionally_a_nullifier(&note_types, max_note_length);

// And inject the newly created function into the contract.

Expand All @@ -134,7 +136,7 @@ pub fn inject_compute_note_hash_and_nullifier(

inject_fn(crate_id, context, func, location, module_id, file_id).map_err(|err| {
(
AztecMacroError::CouldNotImplementComputeNoteHashAndNullifier {
AztecMacroError::CouldNotImplementComputeNoteHashAndOptionallyANullifier {
secondary_message: err.secondary_message,
},
file_id,
Expand All @@ -144,12 +146,12 @@ pub fn inject_compute_note_hash_and_nullifier(
Ok(())
}

fn generate_compute_note_hash_and_nullifier(
fn generate_compute_note_hash_and_optionally_a_nullifier(
note_types: &[String],
max_note_length: u128,
) -> NoirFunction {
let function_source =
generate_compute_note_hash_and_nullifier_source(note_types, max_note_length);
generate_compute_note_hash_and_optionally_a_nullifier_source(note_types, max_note_length);

let (function_ast, errors) = parse_program(&function_source);
if !errors.is_empty() {
Expand All @@ -161,7 +163,7 @@ fn generate_compute_note_hash_and_nullifier(
function_ast.functions.remove(0)
}

fn generate_compute_note_hash_and_nullifier_source(
fn generate_compute_note_hash_and_optionally_a_nullifier_source(
note_types: &[String],
max_note_length: u128,
) -> String {
Expand All @@ -173,12 +175,13 @@ fn generate_compute_note_hash_and_nullifier_source(
// so we include a dummy version.
format!(
"
unconstrained fn compute_note_hash_and_nullifier(
unconstrained fn compute_note_hash_and_optionally_a_nullifier(
contract_address: dep::aztec::protocol_types::address::AztecAddress,
nonce: Field,
storage_slot: Field,
note_type_id: Field,
serialized_note: [Field; {}]
compute_nullifier: bool,
serialized_note: [Field; {}],
) -> pub [Field; 4] {{
assert(false, \"This contract does not use private notes\");
[0, 0, 0, 0]
Expand All @@ -191,7 +194,7 @@ fn generate_compute_note_hash_and_nullifier_source(

let if_statements: Vec<String> = note_types.iter().map(|note_type| format!(
"if (note_type_id == {0}::get_note_type_id()) {{
dep::aztec::note::utils::compute_note_hash_and_nullifier({0}::deserialize_content, note_header, serialized_note)
dep::aztec::note::utils::compute_note_hash_and_optionally_a_nullifier({0}::deserialize_content, note_header, compute_nullifier, serialized_note)
}}"
, note_type)).collect();

Expand All @@ -204,12 +207,13 @@ fn generate_compute_note_hash_and_nullifier_source(

format!(
"
unconstrained fn compute_note_hash_and_nullifier(
unconstrained fn compute_note_hash_and_optionally_a_nullifier(
contract_address: dep::aztec::protocol_types::address::AztecAddress,
nonce: Field,
storage_slot: Field,
note_type_id: Field,
serialized_note: [Field; {}]
compute_nullifier: bool,
serialized_note: [Field; {}],
) -> pub [Field; 4] {{
let note_header = dep::aztec::prelude::NoteHeader::new(contract_address, nonce, storage_slot);
Expand Down
2 changes: 1 addition & 1 deletion aztec_macros/src/transforms/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub mod compute_note_hash_and_nullifier;
pub mod compute_note_hash_and_optionally_a_nullifier;
pub mod contract_interface;
pub mod events;
pub mod functions;
Expand Down
6 changes: 3 additions & 3 deletions aztec_macros/src/utils/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub enum AztecMacroError {
UnsupportedFunctionReturnType { span: Span, typ: ast::UnresolvedTypeData },
UnsupportedStorageType { span: Option<Span>, typ: ast::UnresolvedTypeData },
CouldNotAssignStorageSlots { secondary_message: Option<String> },
CouldNotImplementComputeNoteHashAndNullifier { secondary_message: Option<String> },
CouldNotImplementComputeNoteHashAndOptionallyANullifier { secondary_message: Option<String> },
CouldNotImplementNoteInterface { span: Option<Span>, secondary_message: Option<String> },
MultipleStorageDefinitions { span: Option<Span> },
CouldNotExportStorageLayout { span: Option<Span>, secondary_message: Option<String> },
Expand Down Expand Up @@ -57,8 +57,8 @@ impl From<AztecMacroError> for MacroError {
secondary_message,
span: None,
},
AztecMacroError::CouldNotImplementComputeNoteHashAndNullifier { secondary_message } => MacroError {
primary_message: "Could not implement compute_note_hash_and_nullifier automatically, please provide an implementation".to_string(),
AztecMacroError::CouldNotImplementComputeNoteHashAndOptionallyANullifier { secondary_message } => MacroError {
primary_message: "Could not implement compute_note_hash_and_optionally_a_nullifier automatically, please provide an implementation".to_string(),
secondary_message,
span: None,
},
Expand Down
2 changes: 1 addition & 1 deletion compiler/integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"build": "echo Integration Test build step",
"test": "yarn test:browser && yarn test:node",
"test:node": "bash ./scripts/setup.sh && hardhat test test/node/**/*",
"test:node": "bash ./scripts/setup.sh && hardhat test test/node/prove_and_verify.test.ts && hardhat test test/node/smart_contract_verifier.test.ts && hardhat test test/node/onchain_recursive_verification.test.ts",
"test:browser": "web-test-runner",
"test:integration:browser": "web-test-runner test/browser/**/*.test.ts",
"test:integration:browser:watch": "web-test-runner test/browser/**/*.test.ts --watch",
Expand Down
Loading

0 comments on commit 7c0d30f

Please sign in to comment.