Skip to content

Commit

Permalink
feat: Sync from noir (#9425)
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: Fix panic in comptime code
(noir-lang/noir#6361)
feat: let the LSP import code action insert into existing use statements
(noir-lang/noir#6358)
chore: minor tweaks to comptime doc
(noir-lang/noir#6357)
feat: LSP auto-import will try to add to existing use statements
(noir-lang/noir#6354)
fix: allow type aliases in let patterns
(noir-lang/noir#6356)
feat(test): Run test matrix on stdlib tests
(noir-lang/noir#6352)
fix(ssa): Do not mark an array from a parameter mutable
(noir-lang/noir#6355)
fix: always inline `derive_generators`
(noir-lang/noir#6350)
chore: add test to check that duplicate definitions generated from
macros throws error (noir-lang/noir#6351)
chore: switch to btreeset for deterministic ordering
(noir-lang/noir#6348)
feat(perf): Use [u32;16] for message block in sha256
(noir-lang/noir#6324)
chore: add some tests for type aliases
feat: remove 'single use' intermediate variables
(noir-lang/noir#6268)
feat: Sync from aztec-packages
(noir-lang/noir#6345)
feat(profiler)!: New flamegraph command that profiles the opcodes
executed (noir-lang/noir#6327)
feat: check trait where clause
(noir-lang/noir#6325)
fix: better formatting of leading/trailing line/block comments in
expression lists (noir-lang/noir#6338)
feat: let the formatter remove lambda block braces for single-statement
blocks (noir-lang/noir#6335)
chore: run tests in metaprogramming.rs
(noir-lang/noir#6339)
END_COMMIT_OVERRIDE

---------

Co-authored-by: Tom French <[email protected]>
  • Loading branch information
AztecBot and TomAFrench committed Oct 29, 2024
1 parent 769305e commit 2abfff3
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 20 deletions.
5 changes: 3 additions & 2 deletions 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 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 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
9 changes: 7 additions & 2 deletions aztec/src/state_vars/private_immutable.nr
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
9 changes: 7 additions & 2 deletions aztec/src/state_vars/private_mutable.nr
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 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
5 changes: 4 additions & 1 deletion aztec/src/state_vars/public_immutable.nr
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
5 changes: 4 additions & 1 deletion aztec/src/state_vars/public_mutable.nr
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
5 changes: 4 additions & 1 deletion aztec/src/state_vars/shared_immutable.nr
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
7 changes: 5 additions & 2 deletions aztec/src/state_vars/shared_mutable/shared_mutable.nr
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 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
5 changes: 2 additions & 3 deletions aztec/src/unencrypted_logs/unencrypted_event_emission.nr
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); }
}

0 comments on commit 2abfff3

Please sign in to comment.