Skip to content

Commit

Permalink
feat: Sync from noir (#9332)
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(ssa): Various mem2reg reverts to reduce memory and compilation time
(noir-lang/noir#6307)
chore: update `noir-edwards` repo to point at `noir-lang` org
(noir-lang/noir#6323)
feat: Sha256 refactoring and benchmark with longer input
(noir-lang/noir#6318)
chore: Release Noir(0.36.0)
(noir-lang/noir#6213)
chore: remove usage of slices in pedersen hash
(noir-lang/noir#6295)
chore: remove dead function
(noir-lang/noir#6308)
feat: new formatter (noir-lang/noir#6300)
feat: Sync from aztec-packages
(noir-lang/noir#6301)
fix: Allow array map on empty arrays
(noir-lang/noir#6305)
fix: Display function name and body when inlining recursion limit hit
(noir-lang/noir#6291)
feat(interpreter): Comptime derive generators
(noir-lang/noir#6303)
fix: enforce correctness of decompositions performed at compile time
(noir-lang/noir#6278)
feat: Warn about private types leaking in public functions and struct
fields (noir-lang/noir#6296)
chore(docs): refactoring guides and some other nits
(noir-lang/noir#6175)
fix: Do not warn on unused self in traits
(noir-lang/noir#6298)
fix: Reject invalid expression with in CLI parser
(noir-lang/noir#6287)
END_COMMIT_OVERRIDE

---------

Co-authored-by: Tom French <tom@tomfren.ch>
  • Loading branch information
AztecBot and TomAFrench authored Oct 23, 2024
1 parent c8e4260 commit a166203
Show file tree
Hide file tree
Showing 965 changed files with 42,732 additions and 13,254 deletions.
2 changes: 1 addition & 1 deletion .noir-sync-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ae87d287ab1fae0f999dfd0d1166fbddb927ba97
b82032888819eac82b2bfce8300c2c8b66507c64
20 changes: 10 additions & 10 deletions avm-transpiler/Cargo.lock

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

36 changes: 19 additions & 17 deletions noir-projects/aztec-nr/address-note/src/address_note.nr
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
use dep::aztec::{
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
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 All @@ -18,26 +24,24 @@ pub struct AddressNote {

impl NullifiableNote for AddressNote {

fn compute_nullifier(self, context: &mut PrivateContext, note_hash_for_nullify: Field) -> Field {
fn compute_nullifier(
self,
context: &mut PrivateContext,
note_hash_for_nullify: Field,
) -> Field {
let secret = context.request_nsk_app(self.npk_m_hash);
poseidon2_hash_with_separator(
[
note_hash_for_nullify,
secret
],
GENERATOR_INDEX__NOTE_NULLIFIER as Field
[note_hash_for_nullify, secret],
GENERATOR_INDEX__NOTE_NULLIFIER as Field,
)
}

unconstrained fn compute_nullifier_without_context(self) -> Field {
let note_hash_for_nullify = compute_note_hash_for_nullify(self);
let secret = get_nsk_app(self.npk_m_hash);
poseidon2_hash_with_separator(
[
note_hash_for_nullify,
secret
],
GENERATOR_INDEX__NOTE_NULLIFIER as Field
[note_hash_for_nullify, secret],
GENERATOR_INDEX__NOTE_NULLIFIER as Field,
)
}
}
Expand All @@ -48,9 +52,7 @@ impl AddressNote {
// malicious sender could use non-random values to make the note less private. But they already know the full
// note pre-image anyway, and so the recipient already trusts them to not disclose this information. We can
// therefore assume that the sender will cooperate in the random value generation.
let randomness = unsafe {
random()
};
let randomness = unsafe { random() };
AddressNote { address, npk_m_hash, randomness, header: NoteHeader::empty() }
}
// docs:end:address_note_def
Expand Down
13 changes: 7 additions & 6 deletions noir-projects/aztec-nr/authwit/src/account.nr
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use dep::aztec::{
context::PrivateContext,
protocol_types::constants::{GENERATOR_INDEX__COMBINED_PAYLOAD, GENERATOR_INDEX__TX_NULLIFIER},
hash::poseidon2_hash_with_separator
hash::poseidon2_hash_with_separator,
};

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

pub struct AccountActions<Context> {
context: Context,
is_valid_impl: fn(&mut PrivateContext, Field) -> bool,
context: Context,
is_valid_impl: fn(&mut PrivateContext, Field) -> bool,
}

impl<Context> AccountActions<Context> {
Expand Down Expand Up @@ -40,15 +40,16 @@ impl AccountActions<&mut PrivateContext> {

let combined_payload_hash = poseidon2_hash_with_separator(
[app_payload.hash(), fee_payload.hash()],
GENERATOR_INDEX__COMBINED_PAYLOAD
GENERATOR_INDEX__COMBINED_PAYLOAD,
);
assert(valid_fn(self.context, combined_payload_hash));

fee_payload.execute_calls(self.context);
self.context.end_setup();
app_payload.execute_calls(self.context);
if cancellable {
let tx_nullifier = poseidon2_hash_with_separator([app_payload.nonce], GENERATOR_INDEX__TX_NULLIFIER);
let tx_nullifier =
poseidon2_hash_with_separator([app_payload.nonce], GENERATOR_INDEX__TX_NULLIFIER);
self.context.push_nullifier(tx_nullifier);
}
}
Expand All @@ -73,7 +74,7 @@ impl AccountActions<&mut PrivateContext> {
self.context.msg_sender(),
self.context.chain_id(),
self.context.version(),
inner_hash
inner_hash,
);
let valid_fn = self.is_valid_impl;
assert(valid_fn(self.context, message_hash) == true, "Message not authorized by account");
Expand Down
120 changes: 67 additions & 53 deletions noir-projects/aztec-nr/authwit/src/auth.nr
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use dep::aztec::protocol_types::{
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
GENERATOR_INDEX__AUTHWIT_INNER, GENERATOR_INDEX__AUTHWIT_OUTER,
GENERATOR_INDEX__AUTHWIT_NULLIFIER, CANONICAL_AUTH_REGISTRY_ADDRESS,
}, hash::poseidon2_hash_with_separator,
};
use dep::aztec::{context::{PrivateContext, PublicContext, gas::GasOpts}, hash::hash_args_array};

Expand Down Expand Up @@ -201,7 +200,11 @@ global IS_VALID_SELECTOR = 0x47dacd73; // 4 last bytes of poseidon2_hash_bytes("
*/
// docs:start:assert_current_call_valid_authwit
pub fn assert_current_call_valid_authwit(context: &mut PrivateContext, on_behalf_of: AztecAddress) {
let inner_hash = compute_inner_authwit_hash([context.msg_sender().to_field(), context.selector().to_field(), context.args_hash]);
let inner_hash = compute_inner_authwit_hash([
context.msg_sender().to_field(),
context.selector().to_field(),
context.args_hash,
]);
assert_inner_hash_valid_authwit(context, on_behalf_of, inner_hash);
}
// docs:end:assert_current_call_valid_authwit
Expand All @@ -215,15 +218,19 @@ pub fn assert_current_call_valid_authwit(context: &mut PrivateContext, on_behalf
* @param on_behalf_of The address that have authorized the current call
* @param inner_hash The hash of the message to authorize
*/
pub fn assert_inner_hash_valid_authwit(context: &mut PrivateContext, on_behalf_of: AztecAddress, inner_hash: Field) {
pub fn assert_inner_hash_valid_authwit(
context: &mut PrivateContext,
on_behalf_of: AztecAddress,
inner_hash: Field,
) {
// We perform a static call here and not a standard one to ensure that the account contract cannot re-enter.
let result: Field = context.static_call_private_function(
on_behalf_of,
comptime {
FunctionSelector::from_signature("verify_private_authwit(Field)")
},
[inner_hash]
).unpack_into();
let result: Field = context
.static_call_private_function(
on_behalf_of,
comptime { FunctionSelector::from_signature("verify_private_authwit(Field)") },
[inner_hash],
)
.unpack_into();
assert(result == IS_VALID_SELECTOR, "Message not authorized by account");
// Compute the nullifier, similar computation to the outer hash, but without the chain_id and version.
// Those should already be handled in the verification, so we just need something to nullify, that allow same inner_hash for multiple actors.
Expand All @@ -245,11 +252,13 @@ pub fn assert_inner_hash_valid_authwit(context: &mut PrivateContext, on_behalf_o
// docs:start:assert_current_call_valid_authwit_public
pub fn assert_current_call_valid_authwit_public(
context: &mut PublicContext,
on_behalf_of: AztecAddress
on_behalf_of: AztecAddress,
) {
let inner_hash = compute_inner_authwit_hash(
[(*context).msg_sender().to_field(), (*context).selector().to_field(), (*context).get_args_hash()]
);
let inner_hash = compute_inner_authwit_hash([
(*context).msg_sender().to_field(),
(*context).selector().to_field(),
(*context).get_args_hash(),
]);
assert_inner_hash_valid_authwit_public(context, on_behalf_of, inner_hash);
}
// docs:end:assert_current_call_valid_authwit_public
Expand All @@ -265,15 +274,19 @@ pub fn assert_current_call_valid_authwit_public(
*
* @param on_behalf_of The address that have authorized the `inner_hash`
*/
pub fn assert_inner_hash_valid_authwit_public(context: &mut PublicContext, on_behalf_of: AztecAddress, inner_hash: Field) {
let result: Field = context.call_public_function(
CANONICAL_AUTH_REGISTRY_ADDRESS,
comptime {
FunctionSelector::from_signature("consume((Field),Field)")
},
[on_behalf_of.to_field(), inner_hash].as_slice(),
GasOpts::default()
).deserialize_into();
pub fn assert_inner_hash_valid_authwit_public(
context: &mut PublicContext,
on_behalf_of: AztecAddress,
inner_hash: Field,
) {
let result: Field = context
.call_public_function(
CANONICAL_AUTH_REGISTRY_ADDRESS,
comptime { FunctionSelector::from_signature("consume((Field),Field)") },
[on_behalf_of.to_field(), inner_hash].as_slice(),
GasOpts::default(),
)
.deserialize_into();
assert(result == IS_VALID_SELECTOR, "Message not authorized by account");
}

Expand All @@ -298,10 +311,11 @@ pub fn compute_authwit_message_hash_from_call<let N: u32>(
chain_id: Field,
version: Field,
selector: FunctionSelector,
args: [Field; N]
args: [Field; N],
) -> Field {
let args_hash = hash_args_array(args);
let inner_hash = compute_inner_authwit_hash([caller.to_field(), selector.to_field(), args_hash]);
let inner_hash =
compute_inner_authwit_hash([caller.to_field(), selector.to_field(), args_hash]);
compute_authwit_message_hash(consumer, chain_id, version, inner_hash)
}
// docs:end:compute_authwit_message_hash_from_call
Expand Down Expand Up @@ -329,7 +343,7 @@ pub fn compute_inner_authwit_hash<let N: u32>(args: [Field; N]) -> Field {
pub fn compute_authwit_nullifier(on_behalf_of: AztecAddress, inner_hash: Field) -> Field {
poseidon2_hash_with_separator(
[on_behalf_of.to_field(), inner_hash],
GENERATOR_INDEX__AUTHWIT_NULLIFIER
GENERATOR_INDEX__AUTHWIT_NULLIFIER,
)
}

Expand All @@ -341,15 +355,15 @@ pub fn compute_authwit_nullifier(on_behalf_of: AztecAddress, inner_hash: Field)
* @param version The version of the chain that the message is being consumed on
* @param inner_hash The hash of the "inner" message that is being consumed
*/
pub fn compute_authwit_message_hash(consumer: AztecAddress, chain_id: Field, version: Field, inner_hash: Field) -> Field {
pub fn compute_authwit_message_hash(
consumer: AztecAddress,
chain_id: Field,
version: Field,
inner_hash: Field,
) -> Field {
poseidon2_hash_with_separator(
[
consumer.to_field(),
chain_id,
version,
inner_hash
],
GENERATOR_INDEX__AUTHWIT_OUTER
[consumer.to_field(), chain_id, version, inner_hash],
GENERATOR_INDEX__AUTHWIT_OUTER,
)
}

Expand All @@ -362,14 +376,14 @@ pub fn compute_authwit_message_hash(consumer: AztecAddress, chain_id: Field, ver
* @param authorize True if the message should be authorized, false if it should be revoked
*/
pub fn set_authorized(context: &mut PublicContext, message_hash: Field, authorize: bool) {
context.call_public_function(
CANONICAL_AUTH_REGISTRY_ADDRESS,
comptime {
FunctionSelector::from_signature("set_authorized(Field,bool)")
},
[message_hash, authorize as Field].as_slice(),
GasOpts::default()
).assert_empty();
context
.call_public_function(
CANONICAL_AUTH_REGISTRY_ADDRESS,
comptime { FunctionSelector::from_signature("set_authorized(Field,bool)") },
[message_hash, authorize as Field].as_slice(),
GasOpts::default(),
)
.assert_empty();
}

/**
Expand All @@ -380,12 +394,12 @@ pub fn set_authorized(context: &mut PublicContext, message_hash: Field, authoriz
* @param reject True if all authwits should be rejected, false otherwise
*/
pub fn set_reject_all(context: &mut PublicContext, reject: bool) {
context.call_public_function(
CANONICAL_AUTH_REGISTRY_ADDRESS,
comptime {
FunctionSelector::from_signature("set_reject_all(bool)")
},
[context.this_address().to_field(), reject as Field].as_slice(),
GasOpts::default()
).assert_empty();
context
.call_public_function(
CANONICAL_AUTH_REGISTRY_ADDRESS,
comptime { FunctionSelector::from_signature("set_reject_all(bool)") },
[context.this_address().to_field(), reject as Field].as_slice(),
GasOpts::default(),
)
.assert_empty();
}
Loading

0 comments on commit a166203

Please sign in to comment.