Skip to content

Commit

Permalink
feat: Sync from noir (#9410)
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: formatter didn't format `>>=` well
(noir-lang/noir#6337)
chore: Update title from feedback
(noir-lang/noir#6334)
feat: Reject programs with unconditional recursion
(noir-lang/noir#6292)
fix: (formatter) indent after infix lhs
(noir-lang/noir#6331)
feat: merge and sort imports
(noir-lang/noir#6322)
fix: mutable global pattern didn't have a span
(noir-lang/noir#6328)
END_COMMIT_OVERRIDE

---------

Co-authored-by: Tom French <tom@tomfren.ch>
  • Loading branch information
AztecBot and TomAFrench committed Oct 25, 2024
1 parent c8015d1 commit 40263b4
Show file tree
Hide file tree
Showing 78 changed files with 300 additions and 219 deletions.
13 changes: 8 additions & 5 deletions address-note/src/address_note.nr
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
use dep::aztec::{
context::PrivateContext,
keys::getters::get_nsk_app,
macros::notes::note,
note::{
note_header::NoteHeader, note_interface::NullifiableNote,
utils::compute_note_hash_for_nullify,
},
oracle::random::random,
protocol_types::{
address::AztecAddress, constants::GENERATOR_INDEX__NOTE_NULLIFIER,
hash::poseidon2_hash_with_separator,
},
note::{
note_header::NoteHeader, note_interface::NullifiableNote,
utils::compute_note_hash_for_nullify,
}, oracle::random::random, keys::getters::get_nsk_app, context::PrivateContext,
macros::notes::note,
};

// docs:start:address_note_def
Expand Down
4 changes: 2 additions & 2 deletions authwit/src/account.nr
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use dep::aztec::{
context::PrivateContext,
protocol_types::constants::{GENERATOR_INDEX__COMBINED_PAYLOAD, GENERATOR_INDEX__TX_NULLIFIER},
hash::poseidon2_hash_with_separator,
protocol_types::constants::{GENERATOR_INDEX__COMBINED_PAYLOAD, GENERATOR_INDEX__TX_NULLIFIER},
};

use crate::auth::{compute_authwit_message_hash, IS_VALID_SELECTOR};
use crate::entrypoint::{app::AppPayload, fee::FeePayload};
use crate::auth::{IS_VALID_SELECTOR, compute_authwit_message_hash};

pub struct AccountActions<Context> {
context: Context,
Expand Down
12 changes: 7 additions & 5 deletions authwit/src/auth.nr
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use dep::aztec::{context::{gas::GasOpts, PrivateContext, PublicContext}, hash::hash_args_array};
use dep::aztec::protocol_types::{
abis::function_selector::FunctionSelector, address::AztecAddress,
abis::function_selector::FunctionSelector,
address::AztecAddress,
constants::{
GENERATOR_INDEX__AUTHWIT_INNER, GENERATOR_INDEX__AUTHWIT_OUTER,
GENERATOR_INDEX__AUTHWIT_NULLIFIER, CANONICAL_AUTH_REGISTRY_ADDRESS,
}, hash::poseidon2_hash_with_separator,
CANONICAL_AUTH_REGISTRY_ADDRESS, GENERATOR_INDEX__AUTHWIT_INNER,
GENERATOR_INDEX__AUTHWIT_NULLIFIER, GENERATOR_INDEX__AUTHWIT_OUTER,
},
hash::poseidon2_hash_with_separator,
};
use dep::aztec::{context::{PrivateContext, PublicContext, gas::GasOpts}, hash::hash_args_array};

/**
* Authenticaion witness helper library
Expand Down
9 changes: 5 additions & 4 deletions authwit/src/cheatcodes.nr
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use dep::aztec::{
protocol_types::address::AztecAddress,
context::{public_context::PublicContext, call_interfaces::CallInterface},
test::helpers::cheatcodes, oracle::execution::{get_block_number, get_contract_address},
context::{call_interfaces::CallInterface, public_context::PublicContext},
hash::hash_args,
oracle::execution::{get_block_number, get_contract_address},
protocol_types::address::AztecAddress,
test::helpers::cheatcodes,
};

use crate::auth::{compute_inner_authwit_hash, compute_authwit_message_hash, set_authorized};
use crate::auth::{compute_authwit_message_hash, compute_inner_authwit_hash, set_authorized};

pub fn add_private_authwit_from_call_interface<C, let M: u32>(
on_behalf_of: AztecAddress,
Expand Down
3 changes: 2 additions & 1 deletion authwit/src/entrypoint/app.nr
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use dep::aztec::prelude::PrivateContext;
use dep::aztec::protocol_types::{
constants::GENERATOR_INDEX__SIGNATURE_PAYLOAD, hash::poseidon2_hash_with_separator,
constants::GENERATOR_INDEX__SIGNATURE_PAYLOAD,
hash::poseidon2_hash_with_separator,
traits::{Hash, Serialize},
};

Expand Down
5 changes: 3 additions & 2 deletions authwit/src/entrypoint/fee.nr
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use crate::entrypoint::function_call::FunctionCall;
use dep::aztec::prelude::PrivateContext;
use dep::aztec::protocol_types::{
constants::GENERATOR_INDEX__FEE_PAYLOAD, hash::poseidon2_hash_with_separator,
constants::GENERATOR_INDEX__FEE_PAYLOAD,
hash::poseidon2_hash_with_separator,
traits::{Hash, Serialize},
};
use crate::entrypoint::function_call::FunctionCall;

// 2 * 5 (FUNCTION_CALL_SIZE) + 2
global FEE_PAYLOAD_SIZE: u32 = 12;
Expand Down
6 changes: 3 additions & 3 deletions aztec/src/context/call_interfaces.nr
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ use dep::protocol_types::{
};

use crate::context::{
private_context::PrivateContext, public_context::PublicContext, gas::GasOpts,
inputs::PrivateContextInputs,
gas::GasOpts, inputs::PrivateContextInputs, private_context::PrivateContext,
public_context::PublicContext,
};

use crate::oracle::arguments::pack_arguments;
use crate::hash::hash_args;
use crate::oracle::arguments::pack_arguments;

pub trait CallInterface<let N: u32> {
fn get_args(self) -> [Field] {
Expand Down
4 changes: 2 additions & 2 deletions aztec/src/context/inputs/private_context_inputs.nr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use dep::protocol_types::{
transaction::tx_context::TxContext, abis::call_context::CallContext, header::Header,
traits::Empty,
abis::call_context::CallContext, header::Header, traits::Empty,
transaction::tx_context::TxContext,
};

// PrivateContextInputs are expected to be provided to each private function
Expand Down
10 changes: 5 additions & 5 deletions aztec/src/context/mod.nr
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ mod call_interfaces;
mod gas;

pub use call_interfaces::{
PrivateCallInterface, PrivateStaticCallInterface, PublicCallInterface,
PublicStaticCallInterface, PrivateVoidCallInterface, PrivateStaticVoidCallInterface,
PublicVoidCallInterface, PublicStaticVoidCallInterface,
PrivateCallInterface, PrivateStaticCallInterface, PrivateStaticVoidCallInterface,
PrivateVoidCallInterface, PublicCallInterface, PublicStaticCallInterface,
PublicStaticVoidCallInterface, PublicVoidCallInterface,
};
pub use private_context::PrivateContext;
pub use packed_returns::PackedReturns;
pub use public_context::PublicContext;
pub use private_context::PrivateContext;
pub use public_context::FunctionReturns;
pub use public_context::PublicContext;
pub use unconstrained_context::UnconstrainedContext;
43 changes: 28 additions & 15 deletions aztec/src/context/private_context.nr
Original file line number Diff line number Diff line change
@@ -1,34 +1,47 @@
use crate::{
context::{inputs::PrivateContextInputs, packed_returns::PackedReturns},
messaging::process_l1_to_l2_message, hash::{hash_args_array, ArgsHasher},
keys::constants::{NULLIFIER_INDEX, OUTGOING_INDEX, NUM_KEY_TYPES, sk_generators},
hash::{ArgsHasher, hash_args_array},
keys::constants::{NULLIFIER_INDEX, NUM_KEY_TYPES, OUTGOING_INDEX, sk_generators},
messaging::process_l1_to_l2_message,
oracle::{
key_validation_request::get_key_validation_request, arguments, returns::pack_returns,
call_private_function::call_private_function_internal, header::get_header_at,
logs::{emit_encrypted_note_log, emit_encrypted_event_log},
arguments,
call_private_function::call_private_function_internal,
enqueue_public_function_call::{
enqueue_public_function_call_internal, notify_set_min_revertible_side_effect_counter,
set_public_teardown_function_call_internal,
},
header::get_header_at,
key_validation_request::get_key_validation_request,
logs::{emit_encrypted_event_log, emit_encrypted_note_log},
returns::pack_returns,
},
};
use dep::protocol_types::{
abis::{
call_context::CallContext, function_selector::FunctionSelector,
call_context::CallContext,
function_selector::FunctionSelector,
log_hash::{EncryptedLogHash, LogHash, NoteLogHash},
max_block_number::MaxBlockNumber,
validation_requests::{KeyValidationRequest, KeyValidationRequestAndGenerator},
note_hash::NoteHash,
nullifier::Nullifier,
private_call_request::PrivateCallRequest,
private_circuit_public_inputs::PrivateCircuitPublicInputs,
public_call_request::PublicCallRequest, read_request::ReadRequest, note_hash::NoteHash,
nullifier::Nullifier, log_hash::{LogHash, NoteLogHash, EncryptedLogHash},
}, address::{AztecAddress, EthAddress},
public_call_request::PublicCallRequest,
read_request::ReadRequest,
validation_requests::{KeyValidationRequest, KeyValidationRequestAndGenerator},
},
address::{AztecAddress, EthAddress},
constants::{
MAX_NOTE_HASHES_PER_CALL, MAX_L2_TO_L1_MSGS_PER_CALL, MAX_NULLIFIERS_PER_CALL,
MAX_ENCRYPTED_LOGS_PER_CALL, MAX_KEY_VALIDATION_REQUESTS_PER_CALL,
MAX_L2_TO_L1_MSGS_PER_CALL, MAX_NOTE_ENCRYPTED_LOGS_PER_CALL,
MAX_NOTE_HASH_READ_REQUESTS_PER_CALL, MAX_NOTE_HASHES_PER_CALL,
MAX_NULLIFIER_READ_REQUESTS_PER_CALL, MAX_NULLIFIERS_PER_CALL,
MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL, MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL,
MAX_NOTE_HASH_READ_REQUESTS_PER_CALL, MAX_NULLIFIER_READ_REQUESTS_PER_CALL,
MAX_KEY_VALIDATION_REQUESTS_PER_CALL, MAX_ENCRYPTED_LOGS_PER_CALL,
MAX_UNENCRYPTED_LOGS_PER_CALL, MAX_NOTE_ENCRYPTED_LOGS_PER_CALL, PUBLIC_DISPATCH_SELECTOR,
}, header::Header, messaging::l2_to_l1_message::L2ToL1Message, traits::Empty,
MAX_UNENCRYPTED_LOGS_PER_CALL, PUBLIC_DISPATCH_SELECTOR,
},
header::Header,
messaging::l2_to_l1_message::L2ToL1Message,
traits::Empty,
};

// When finished, one can call .finish() to convert back to the abi
Expand Down
8 changes: 4 additions & 4 deletions aztec/src/context/public_context.nr
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::hash::{compute_secret_hash, compute_message_hash, compute_message_nullifier};
use crate::context::gas::GasOpts;
use crate::hash::{compute_message_hash, compute_message_nullifier, compute_secret_hash};
use dep::protocol_types::abis::function_selector::FunctionSelector;
use dep::protocol_types::address::{AztecAddress, EthAddress};
use dep::protocol_types::constants::{MAX_FIELD_VALUE, PUBLIC_DISPATCH_SELECTOR};
use dep::protocol_types::traits::{Serialize, Deserialize, Empty};
use dep::protocol_types::abis::function_selector::FunctionSelector;
use crate::context::gas::GasOpts;
use dep::protocol_types::traits::{Deserialize, Empty, Serialize};

pub struct PublicContext {
args_hash: Option<Field>,
Expand Down
4 changes: 2 additions & 2 deletions aztec/src/context/unconstrained_context.nr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use dep::protocol_types::{address::AztecAddress, traits::Deserialize};
use crate::oracle::{
execution::{get_chain_id, get_version, get_contract_address, get_block_number},
execution::{get_block_number, get_chain_id, get_contract_address, get_version},
storage::storage_read,
};
use dep::protocol_types::{address::AztecAddress, traits::Deserialize};

pub struct UnconstrainedContext {
block_number: u32,
Expand Down
2 changes: 1 addition & 1 deletion aztec/src/deploy.nr
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{context::PrivateContext, oracle::get_contract_instance::get_contract_instance};

use dep::protocol_types::{
address::AztecAddress, abis::function_selector::FunctionSelector,
abis::function_selector::FunctionSelector, address::AztecAddress,
constants::DEPLOYER_CONTRACT_ADDRESS,
};

Expand Down
9 changes: 5 additions & 4 deletions aztec/src/encrypted_logs/encrypted_event_emission.nr
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use crate::{
context::PrivateContext, event::event_interface::EventInterface,
encrypted_logs::payload::compute_encrypted_log, keys::getters::get_ovsk_app,
oracle::random::random,
context::PrivateContext, encrypted_logs::payload::compute_encrypted_log,
event::event_interface::EventInterface, keys::getters::get_ovsk_app, oracle::random::random,
};
use dep::protocol_types::{
address::AztecAddress, public_keys::{OvpkM, IvpkM}, hash::sha256_to_field,
address::AztecAddress,
hash::sha256_to_field,
public_keys::{IvpkM, OvpkM},
};

fn compute_raw_event_log<Event, let N: u32>(
Expand Down
10 changes: 7 additions & 3 deletions aztec/src/encrypted_logs/encrypted_note_emission.nr
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
use crate::{
context::PrivateContext, note::{note_emission::NoteEmission, note_interface::NoteInterface},
keys::getters::get_ovsk_app, encrypted_logs::payload::compute_encrypted_log,
context::PrivateContext,
encrypted_logs::payload::compute_encrypted_log,
keys::getters::get_ovsk_app,
note::{note_emission::NoteEmission, note_interface::NoteInterface},
};
use dep::protocol_types::{
address::AztecAddress, public_keys::{PublicKeys, OvpkM, IvpkM}, hash::sha256_to_field,
abis::note_hash::NoteHash,
address::AztecAddress,
hash::sha256_to_field,
public_keys::{IvpkM, OvpkM, PublicKeys},
};

fn compute_raw_note_log<Note, let N: u32>(
Expand Down
5 changes: 4 additions & 1 deletion aztec/src/encrypted_logs/header.nr
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use dep::protocol_types::{
address::AztecAddress, public_keys::{PublicKeys, IvpkM, ToPoint}, scalar::Scalar, point::Point,
address::AztecAddress,
point::Point,
public_keys::{IvpkM, PublicKeys, ToPoint},
scalar::Scalar,
};

use crate::keys::point_to_symmetric_key::point_to_symmetric_key;
Expand Down
21 changes: 14 additions & 7 deletions aztec/src/encrypted_logs/payload.nr
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
use dep::protocol_types::{
address::AztecAddress, scalar::Scalar, point::Point, public_keys::{OvpkM, IvpkM},
constants::GENERATOR_INDEX__SYMMETRIC_KEY, hash::poseidon2_hash_with_separator,
address::AztecAddress,
constants::GENERATOR_INDEX__SYMMETRIC_KEY,
hash::poseidon2_hash_with_separator,
point::Point,
public_keys::{IvpkM, OvpkM},
scalar::Scalar,
};
use std::{
aes128::aes128_encrypt, embedded_curve_ops::fixed_base_scalar_mul as derive_public_key,
hash::from_field_unsafe as fr_to_fq_unsafe, field::bn254::decompose,
field::bn254::decompose, hash::from_field_unsafe as fr_to_fq_unsafe,
};

use crate::{
oracle::random::random, utils::point::point_to_bytes,
encrypted_logs::header::EncryptedLogHeader,
keys::point_to_symmetric_key::point_to_symmetric_key,
keys::point_to_symmetric_key::point_to_symmetric_key, oracle::random::random,
utils::point::point_to_bytes,
};

pub fn compute_encrypted_log<let P: u32, let M: u32>(
Expand Down Expand Up @@ -152,10 +156,13 @@ mod test {
use crate::encrypted_logs::payload::{
compute_encrypted_log, compute_incoming_body_ciphertext, compute_outgoing_body_ciphertext,
};
use std::embedded_curve_ops::fixed_base_scalar_mul as derive_public_key;
use dep::protocol_types::{
address::AztecAddress, public_keys::{OvpkM, IvpkM}, point::Point, scalar::Scalar,
address::AztecAddress,
point::Point,
public_keys::{IvpkM, OvpkM},
scalar::Scalar,
};
use std::embedded_curve_ops::fixed_base_scalar_mul as derive_public_key;
use std::test::OracleMock;

#[test]
Expand Down
2 changes: 1 addition & 1 deletion aztec/src/generators.nr
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ global G_slot = Point {
};

mod test {
use crate::generators::{Ga1, Ga2, Ga3, Ga4, Ga5, G_slot};
use crate::generators::{G_slot, Ga1, Ga2, Ga3, Ga4, Ga5};
use dep::protocol_types::point::Point;
use std::hash::derive_generators;

Expand Down
12 changes: 7 additions & 5 deletions aztec/src/hash.nr
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use crate::utils::to_bytes::{arr_to_be_bytes_arr, str_to_be_bytes_arr};
use dep::protocol_types::{
address::{AztecAddress, EthAddress},
constants::{
GENERATOR_INDEX__SECRET_HASH, GENERATOR_INDEX__MESSAGE_NULLIFIER,
GENERATOR_INDEX__FUNCTION_ARGS,
}, point::Point, traits::Hash,
hash::{sha256_to_field, poseidon2_hash_with_separator, poseidon2_hash_with_separator_slice},
GENERATOR_INDEX__FUNCTION_ARGS, GENERATOR_INDEX__MESSAGE_NULLIFIER,
GENERATOR_INDEX__SECRET_HASH,
},
hash::{poseidon2_hash_with_separator, poseidon2_hash_with_separator_slice, sha256_to_field},
point::Point,
traits::Hash,
};
use crate::utils::to_bytes::{arr_to_be_bytes_arr, str_to_be_bytes_arr};

pub use dep::protocol_types::hash::{compute_siloed_nullifier, pedersen_hash};

Expand Down
4 changes: 2 additions & 2 deletions aztec/src/history/contract_inclusion.nr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use dep::protocol_types::{
header::Header, address::AztecAddress, hash::compute_siloed_nullifier,
constants::DEPLOYER_CONTRACT_ADDRESS,
address::AztecAddress, constants::DEPLOYER_CONTRACT_ADDRESS, hash::compute_siloed_nullifier,
header::Header,
};

trait ProveContractDeployment {
Expand Down
4 changes: 2 additions & 2 deletions aztec/src/history/note_inclusion.nr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use dep::protocol_types::merkle_tree::root::root_from_sibling_path;
use dep::protocol_types::header::Header;
use dep::protocol_types::merkle_tree::root::root_from_sibling_path;

use crate::{
note::{utils::compute_note_hash_for_nullify, note_interface::{NoteInterface, NullifiableNote}},
note::{note_interface::{NoteInterface, NullifiableNote}, utils::compute_note_hash_for_nullify},
oracle::get_membership_witness::get_note_hash_membership_witness,
};

Expand Down
4 changes: 2 additions & 2 deletions aztec/src/history/nullifier_inclusion.nr
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use dep::protocol_types::merkle_tree::root::root_from_sibling_path;
use dep::protocol_types::header::Header;
use dep::protocol_types::merkle_tree::root::root_from_sibling_path;

use crate::{
context::PrivateContext,
note::{note_interface::{NoteInterface, NullifiableNote}, utils::compute_siloed_nullifier},
oracle::get_nullifier_membership_witness::get_nullifier_membership_witness,
note::{utils::compute_siloed_nullifier, note_interface::{NoteInterface, NullifiableNote}},
};

trait ProveNullifierInclusion {
Expand Down
Loading

0 comments on commit 40263b4

Please sign in to comment.