Skip to content

Commit

Permalink
Merge 3ffe6a1 into 8e07de8
Browse files Browse the repository at this point in the history
  • Loading branch information
AztecBot authored Oct 28, 2024
2 parents 8e07de8 + 3ffe6a1 commit 58c05aa
Show file tree
Hide file tree
Showing 83 changed files with 1,723 additions and 314 deletions.
2 changes: 1 addition & 1 deletion .noir-sync-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
598230d9427cf988fc6da8fe9e1eb2b7c00a2fa6
d8e549aad6bae0f96621c57b58a301693463f732
5 changes: 3 additions & 2 deletions noir-projects/aztec-nr/aztec/src/event/event_interface.nr
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use dep::protocol_types::abis::event_selector::EventSelector;
use dep::protocol_types::traits::{Deserialize, Serialize};

pub trait EventInterface<let N: u32> {
pub trait EventInterface<let N: u32>: Serialize<N> {
fn private_to_be_bytes(self, randomness: Field) -> [u8; N * 32 + 64];
fn to_be_bytes(self) -> [u8; N * 32 + 32];
fn get_event_type_id() -> EventSelector;
fn emit<Env>(self, _emit: fn[Env](Self) -> ());
fn emit<Env>(self, emit: fn[Env](Self) -> ());
}
7 changes: 6 additions & 1 deletion noir-projects/aztec-nr/aztec/src/note/note_interface.nr
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
use crate::context::PrivateContext;
use crate::note::note_header::NoteHeader;
use dep::protocol_types::traits::{Deserialize, Empty, Serialize};

pub trait NoteProperties<T> {
fn properties() -> T;
}

pub trait PartialNote<S, F> {
pub trait PartialNote<S, F>
where
S: Empty,
F: Empty,
{
fn setup_payload() -> S;

fn finalization_payload() -> F;
Expand Down
10 changes: 8 additions & 2 deletions noir-projects/aztec-nr/aztec/src/state_vars/map.nr
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use crate::state_vars::storage::Storage;
use dep::protocol_types::{storage::map::derive_storage_slot_in_map, traits::ToField};
use dep::protocol_types::{
storage::map::derive_storage_slot_in_map,
traits::{Deserialize, Serialize, ToField},
};

// docs:start:map
pub struct Map<K, V, Context> {
Expand All @@ -9,7 +12,10 @@ pub struct Map<K, V, Context> {
}
// docs:end:map

impl<K, T, Context> Storage<T> for Map<K, T, Context> {}
impl<K, T, Context, let N: u32> Storage<T, N> for Map<K, T, Context>
where
T: Serialize<N> + Deserialize<N>,
{}

impl<K, V, Context> Map<K, V, Context> {
// docs:start:new
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use dep::protocol_types::{
constants::GENERATOR_INDEX__INITIALIZATION_NULLIFIER, hash::poseidon2_hash_with_separator,
constants::GENERATOR_INDEX__INITIALIZATION_NULLIFIER,
hash::poseidon2_hash_with_separator,
traits::{Deserialize, Serialize},
};

use crate::context::{PrivateContext, UnconstrainedContext};
Expand All @@ -20,7 +22,10 @@ pub struct PrivateImmutable<Note, Context> {
}
// docs:end:struct

impl<T, Context> Storage<T> for PrivateImmutable<T, Context> {}
impl<T, Context, let N: u32> Storage<T, N> for PrivateImmutable<T, Context>
where
T: Serialize<N> + Deserialize<N>,
{}

impl<Note, Context> PrivateImmutable<Note, Context> {
// docs:start:new
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use dep::protocol_types::{
constants::GENERATOR_INDEX__INITIALIZATION_NULLIFIER, hash::poseidon2_hash_with_separator,
constants::GENERATOR_INDEX__INITIALIZATION_NULLIFIER,
hash::poseidon2_hash_with_separator,
traits::{Deserialize, Serialize},
};

use crate::context::{PrivateContext, UnconstrainedContext};
Expand All @@ -22,7 +24,10 @@ pub struct PrivateMutable<Note, Context> {

mod test;

impl<T, Context> Storage<T> for PrivateMutable<T, Context> {}
impl<T, Context, let N: u32> Storage<T, N> for PrivateMutable<T, Context>
where
T: Serialize<N> + Deserialize<N>,
{}

impl<Note, Context> PrivateMutable<Note, Context> {
// docs:start:new
Expand Down
9 changes: 7 additions & 2 deletions noir-projects/aztec-nr/aztec/src/state_vars/private_set.nr
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ use crate::note::{
};
use crate::state_vars::storage::Storage;
use dep::protocol_types::{
abis::read_request::ReadRequest, constants::MAX_NOTE_HASH_READ_REQUESTS_PER_CALL,
abis::read_request::ReadRequest,
constants::MAX_NOTE_HASH_READ_REQUESTS_PER_CALL,
traits::{Deserialize, Serialize},
};

// docs:start:struct
Expand All @@ -21,7 +23,10 @@ pub struct PrivateSet<Note, Context> {
}
// docs:end:struct

impl<T, Context> Storage<T> for PrivateSet<T, Context> {}
impl<T, Context, let N: u32> Storage<T, N> for PrivateSet<T, Context>
where
T: Serialize<N> + Deserialize<N>,
{}

impl<Note, Context> PrivateSet<Note, Context> {
// docs:start:new
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ pub struct PublicImmutable<T, Context> {
}
// docs:end:public_immutable_struct

impl<T, Context> Storage<T> for PublicImmutable<T, Context> {}
impl<T, Context, let N: u32> Storage<T, N> for PublicImmutable<T, Context>
where
T: Serialize<N> + Deserialize<N>,
{}

impl<T, Context> PublicImmutable<T, Context> {
// docs:start:public_immutable_struct_new
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ pub struct PublicMutable<T, Context> {
}
// docs:end:public_mutable_struct

impl<T, Context> Storage<T> for PublicMutable<T, Context> {}
impl<T, Context, let N: u32> Storage<T, N> for PublicMutable<T, Context>
where
T: Serialize<N> + Deserialize<N>,
{}

impl<T, Context> PublicMutable<T, Context> {
// docs:start:public_mutable_struct_new
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ pub struct SharedImmutable<T, Context> {
storage_slot: Field,
}

impl<T, Context> Storage<T> for SharedImmutable<T, Context> {}
impl<T, Context, let N: u32> Storage<T, N> for SharedImmutable<T, Context>
where
T: Serialize<N> + Deserialize<N>,
{}

impl<T, Context> SharedImmutable<T, Context> {
pub fn new(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use dep::protocol_types::{
address::AztecAddress,
hash::{poseidon2_hash, poseidon2_hash_with_separator},
traits::{FromField, ToField},
traits::{Deserialize, FromField, Serialize, ToField},
utils::arrays::array_concat,
};

Expand Down Expand Up @@ -34,7 +34,10 @@ global HASH_SEPARATOR: u32 = 2;
//
// TODO https://github.com/AztecProtocol/aztec-packages/issues/5736: change the storage allocation scheme so that we
// can actually use it here
impl<T, let INITIAL_DELAY: u32, Context> Storage<T> for SharedMutable<T, INITIAL_DELAY, Context> {}
impl<T, let INITIAL_DELAY: u32, Context, let N: u32> Storage<T, N> for SharedMutable<T, INITIAL_DELAY, Context>
where
T: Serialize<N> + Deserialize<N>,
{}

// SharedMutable<T> stores a value of type T that is:
// - publicly known (i.e. unencrypted)
Expand Down
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/aztec/src/state_vars/storage.nr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use dep::protocol_types::traits::{Deserialize, Serialize};

pub trait Storage<T>
pub trait Storage<T, let N: u32>
where
T: Serialize<N> + Deserialize<N>,
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use crate::{context::PublicContext, event::event_interface::EventInterface};
use dep::protocol_types::traits::Serialize;

fn emit<Event, let N: u32>(context: &mut PublicContext, event: Event)
where
Event: EventInterface<N> + Serialize<N>,
Event: EventInterface<N>,
{
let selector = Event::get_event_type_id();

Expand All @@ -24,7 +23,7 @@ pub fn encode_event<Event, let N: u32>(
context: &mut PublicContext,
) -> fn[(&mut PublicContext,)](Event) -> ()
where
Event: EventInterface<N> + Serialize<N>,
Event: EventInterface<N>,
{
|e: Event| { emit(context, e); }
}
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ contract AvmTest {

#[public]
fn to_radix_le(input: Field) -> [u8; 10] {
input.to_le_radix( /*base=*/ 2)
input.to_le_radix(/*base=*/ 2)
}

// Helper functions to demonstrate an internal call stack in error messages
Expand Down Expand Up @@ -292,7 +292,7 @@ contract AvmTest {

#[public]
fn pedersen_hash_with_index(data: [Field; 10]) -> Field {
std::hash::pedersen_hash_with_separator(data, /*index=*/ 20)
std::hash::pedersen_hash_with_separator(data, /*index=*/ 20)
}

/************************************************************************
Expand Down Expand Up @@ -425,11 +425,11 @@ contract AvmTest {

#[public]
fn emit_unencrypted_log() {
context.emit_unencrypted_log( /*message=*/ [10, 20, 30]);
context.emit_unencrypted_log( /*message=*/ "Hello, world!");
context.emit_unencrypted_log(/*message=*/ [10, 20, 30]);
context.emit_unencrypted_log(/*message=*/ "Hello, world!");
let s: CompressedString<2, 44> =
CompressedString::from_string("A long time ago, in a galaxy far far away...");
context.emit_unencrypted_log( /*message=*/ s);
context.emit_unencrypted_log(/*message=*/ s);
}

#[public]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ contract ContractInstanceDeployer {
use std::meta::derive;

#[event]
#[derive(Serialize)]
struct ContractInstanceDeployed {
DEPLOYER_CONTRACT_INSTANCE_DEPLOYED_MAGIC_VALUE: Field,
address: AztecAddress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::test::utils;
unconstrained fn access_control() {
// Setup without account contracts. We are not using authwits here, so dummy accounts are enough
let (env, nft_contract_address, owner, recipient) =
utils::setup( /* with_account_contracts */ false);
utils::setup(/* with_account_contracts */ false);

// Set a new admin
NFT::at(nft_contract_address).set_admin(recipient).call(&mut env.public());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::test::utils;
#[test]
unconstrained fn mint_success() {
// Setup without account contracts. We are not using authwits here, so dummy accounts are enough
let (env, nft_contract_address, owner, _) = utils::setup( /* with_account_contracts */ false);
let (env, nft_contract_address, owner, _) = utils::setup(/* with_account_contracts */ false);

let token_id = 10000;
NFT::at(nft_contract_address).mint(owner, token_id).call(&mut env.public());
Expand All @@ -16,7 +16,7 @@ unconstrained fn mint_success() {
unconstrained fn mint_failures() {
// Setup without account contracts. We are not using authwits here, so dummy accounts are enough
let (env, nft_contract_address, owner, recipient) =
utils::setup( /* with_account_contracts */ false);
utils::setup(/* with_account_contracts */ false);

// MINTING AS A NON-MINTER
let token_id = 10000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use aztec::oracle::random::random;
unconstrained fn transfer_in_private() {
// Setup without account contracts. We are not using authwits here, so dummy accounts are enough
let (env, nft_contract_address, sender, recipient, token_id) =
utils::setup_mint_and_transfer_to_private( /* with_account_contracts */ false);
utils::setup_mint_and_transfer_to_private(/* with_account_contracts */ false);

// Transfer the NFT to the recipient
NFT::at(nft_contract_address).transfer_in_private(sender, recipient, token_id, 0).call(
Expand All @@ -23,7 +23,7 @@ unconstrained fn transfer_in_private() {
unconstrained fn transfer_in_private_to_self() {
// Setup without account contracts. We are not using authwits here, so dummy accounts are enough
let (env, nft_contract_address, owner, _, token_id) =
utils::setup_mint_and_transfer_to_private( /* with_account_contracts */ false);
utils::setup_mint_and_transfer_to_private(/* with_account_contracts */ false);

// Transfer the NFT back to the owner
NFT::at(nft_contract_address).transfer_in_private(owner, owner, token_id, 0).call(
Expand All @@ -38,7 +38,7 @@ unconstrained fn transfer_in_private_to_self() {
unconstrained fn transfer_in_private_to_non_deployed_account() {
// Setup without account contracts. We are not using authwits here, so dummy accounts are enough
let (env, nft_contract_address, sender, _, token_id) =
utils::setup_mint_and_transfer_to_private( /* with_account_contracts */ false);
utils::setup_mint_and_transfer_to_private(/* with_account_contracts */ false);
let not_deployed = cheatcodes::create_account();

// Transfer the NFT to the recipient
Expand All @@ -54,7 +54,7 @@ unconstrained fn transfer_in_private_to_non_deployed_account() {
unconstrained fn transfer_in_private_on_behalf_of_other() {
// Setup with account contracts. Slower since we actually deploy them, but needed for authwits.
let (env, nft_contract_address, sender, recipient, token_id) =
utils::setup_mint_and_transfer_to_private( /* with_account_contracts */ true);
utils::setup_mint_and_transfer_to_private(/* with_account_contracts */ true);

// Transfer the NFT to the recipient
let transfer_in_private_call_interface =
Expand All @@ -78,7 +78,7 @@ unconstrained fn transfer_in_private_on_behalf_of_other() {
unconstrained fn transfer_in_private_failure_not_an_owner() {
// Setup without account contracts. We are not using authwits here, so dummy accounts are enough
let (env, nft_contract_address, owner, not_owner, token_id) =
utils::setup_mint_and_transfer_to_private( /* with_account_contracts */ false);
utils::setup_mint_and_transfer_to_private(/* with_account_contracts */ false);
// Try transferring the NFT from not_owner
env.impersonate(not_owner);
NFT::at(nft_contract_address).transfer_in_private(not_owner, owner, token_id, 0).call(
Expand All @@ -92,7 +92,7 @@ unconstrained fn transfer_in_private_failure_on_behalf_of_self_non_zero_nonce()
// The nonce check is in the beginning so we don't need to waste time on minting the NFT and transferring
// it to private.
let (env, nft_contract_address, sender, recipient) =
utils::setup( /* with_account_contracts */ false);
utils::setup(/* with_account_contracts */ false);

// We set random value for the token_id as the nonce check is before we use the value.
let token_id = random();
Expand All @@ -109,7 +109,7 @@ unconstrained fn transfer_in_private_failure_on_behalf_of_other_without_approval
// The authwit check is in the beginning so we don't need to waste time on minting the NFT and transferring
// it to private.
let (env, nft_contract_address, sender, recipient) =
utils::setup( /* with_account_contracts */ true);
utils::setup(/* with_account_contracts */ true);

// We set random value for the token_id as the nonce check is before we use the value.
let token_id = random();
Expand All @@ -128,7 +128,7 @@ unconstrained fn transfer_in_private_failure_on_behalf_of_other_wrong_caller() {
// The authwit check is in the beginning so we don't need to waste time on minting the NFT and transferring
// it to private.
let (env, nft_contract_address, sender, recipient) =
utils::setup( /* with_account_contracts */ true);
utils::setup(/* with_account_contracts */ true);

// We set random value for the token_id as the nonce check is before we use the value.
let token_id = random();
Expand Down
Loading

0 comments on commit 58c05aa

Please sign in to comment.