Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: can't use self.field in trait default implementations #11004

Merged
merged 6 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
178 changes: 152 additions & 26 deletions noir-projects/aztec-nr/aztec/src/context/call_interfaces.nr
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,11 @@ use crate::hash::hash_args;
use crate::oracle::arguments::pack_arguments;

pub trait CallInterface<let N: u32> {
fn get_args(self) -> [Field] {
self.args
}

fn get_selector(self) -> FunctionSelector {
self.selector
}

fn get_name(self) -> str<N> {
self.name
}

fn get_contract_address(self) -> AztecAddress {
self.target_contract
}

fn get_is_static(self) -> bool {
self.is_static
}
fn get_args(self) -> [Field];
fn get_selector(self) -> FunctionSelector;
fn get_name(self) -> str<N>;
fn get_contract_address(self) -> AztecAddress;
fn get_is_static(self) -> bool;
}

pub struct PrivateCallInterface<let N: u32, T> {
Expand Down Expand Up @@ -70,7 +56,27 @@ impl<let N: u32, T> PrivateCallInterface<N, T> {
}
}

impl<let N: u32> CallInterface<N> for PrivateVoidCallInterface<N> {}
impl<let N: u32> CallInterface<N> for PrivateVoidCallInterface<N> {
fn get_args(self) -> [Field] {
self.args
}

fn get_selector(self) -> FunctionSelector {
self.selector
}

fn get_name(self) -> str<N> {
self.name
}

fn get_contract_address(self) -> AztecAddress {
self.target_contract
}

fn get_is_static(self) -> bool {
self.is_static
}
}

pub struct PrivateVoidCallInterface<let N: u32> {
pub target_contract: AztecAddress,
Expand Down Expand Up @@ -108,7 +114,27 @@ impl<let N: u32> PrivateVoidCallInterface<N> {
}
}

impl<let N: u32, T> CallInterface<N> for PrivateStaticCallInterface<N, T> {}
impl<let N: u32, T> CallInterface<N> for PrivateStaticCallInterface<N, T> {
fn get_args(self) -> [Field] {
self.args
}

fn get_selector(self) -> FunctionSelector {
self.selector
}

fn get_name(self) -> str<N> {
self.name
}

fn get_contract_address(self) -> AztecAddress {
self.target_contract
}

fn get_is_static(self) -> bool {
self.is_static
}
}

pub struct PrivateStaticCallInterface<let N: u32, T> {
pub target_contract: AztecAddress,
Expand Down Expand Up @@ -136,7 +162,27 @@ impl<let N: u32, T> PrivateStaticCallInterface<N, T> {
}
}

impl<let N: u32> CallInterface<N> for PrivateStaticVoidCallInterface<N> {}
impl<let N: u32> CallInterface<N> for PrivateStaticVoidCallInterface<N> {
fn get_args(self) -> [Field] {
self.args
}

fn get_selector(self) -> FunctionSelector {
self.selector
}

fn get_name(self) -> str<N> {
self.name
}

fn get_contract_address(self) -> AztecAddress {
self.target_contract
}

fn get_is_static(self) -> bool {
self.is_static
}
}

pub struct PrivateStaticVoidCallInterface<let N: u32> {
pub target_contract: AztecAddress,
Expand All @@ -162,7 +208,27 @@ impl<let N: u32> PrivateStaticVoidCallInterface<N> {
}
}

impl<let N: u32, T> CallInterface<N> for PublicCallInterface<N, T> {}
impl<let N: u32, T> CallInterface<N> for PublicCallInterface<N, T> {
fn get_args(self) -> [Field] {
self.args
}

fn get_selector(self) -> FunctionSelector {
self.selector
}

fn get_name(self) -> str<N> {
self.name
}

fn get_contract_address(self) -> AztecAddress {
self.target_contract
}

fn get_is_static(self) -> bool {
self.is_static
}
}

pub struct PublicCallInterface<let N: u32, T> {
pub target_contract: AztecAddress,
Expand Down Expand Up @@ -231,7 +297,27 @@ impl<let N: u32, T> PublicCallInterface<N, T> {
}
}

impl<let N: u32> CallInterface<N> for PublicVoidCallInterface<N> {}
impl<let N: u32> CallInterface<N> for PublicVoidCallInterface<N> {
fn get_args(self) -> [Field] {
self.args
}

fn get_selector(self) -> FunctionSelector {
self.selector
}

fn get_name(self) -> str<N> {
self.name
}

fn get_contract_address(self) -> AztecAddress {
self.target_contract
}

fn get_is_static(self) -> bool {
self.is_static
}
}

pub struct PublicVoidCallInterface<let N: u32> {
pub target_contract: AztecAddress,
Expand Down Expand Up @@ -294,7 +380,27 @@ impl<let N: u32> PublicVoidCallInterface<N> {
}
}

impl<let N: u32, T> CallInterface<N> for PublicStaticCallInterface<N, T> {}
impl<let N: u32, T> CallInterface<N> for PublicStaticCallInterface<N, T> {
fn get_args(self) -> [Field] {
self.args
}

fn get_selector(self) -> FunctionSelector {
self.selector
}

fn get_name(self) -> str<N> {
self.name
}

fn get_contract_address(self) -> AztecAddress {
self.target_contract
}

fn get_is_static(self) -> bool {
self.is_static
}
}

pub struct PublicStaticCallInterface<let N: u32, T> {
pub target_contract: AztecAddress,
Expand Down Expand Up @@ -338,7 +444,27 @@ impl<let N: u32, T> PublicStaticCallInterface<N, T> {
}
}

impl<let N: u32> CallInterface<N> for PublicStaticVoidCallInterface<N> {}
impl<let N: u32> CallInterface<N> for PublicStaticVoidCallInterface<N> {
fn get_args(self) -> [Field] {
self.args
}

fn get_selector(self) -> FunctionSelector {
self.selector
}

fn get_name(self) -> str<N> {
self.name
}

fn get_contract_address(self) -> AztecAddress {
self.target_contract
}

fn get_is_static(self) -> bool {
self.is_static
}
}

pub struct PublicStaticVoidCallInterface<let N: u32> {
target_contract: AztecAddress,
Expand Down
6 changes: 5 additions & 1 deletion noir-projects/aztec-nr/aztec/src/state_vars/map.nr
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ pub struct Map<K, V, Context> {
impl<K, T, Context, let N: u32> Storage<T, N> for Map<K, T, Context>
where
T: Serialize<N> + Deserialize<N>,
{}
{
fn get_storage_slot(self) -> Field {
self.storage_slot
}
}

impl<K, V, Context> Map<K, V, Context> {
// docs:start:new
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ pub struct PrivateImmutable<Note, Context> {
impl<T, Context, let N: u32> Storage<T, N> for PrivateImmutable<T, Context>
where
T: Serialize<N> + Deserialize<N>,
{}
{
fn get_storage_slot(self) -> Field {
self.storage_slot
}
}

impl<Note, Context> PrivateImmutable<Note, Context> {
// docs:start:new
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ mod test;
impl<T, Context, let N: u32> Storage<T, N> for PrivateMutable<T, Context>
where
T: Serialize<N> + Deserialize<N>,
{}
{
fn get_storage_slot(self) -> Field {
self.storage_slot
}
}

impl<Note, Context> PrivateMutable<Note, Context> {
// docs:start:new
Expand Down
6 changes: 5 additions & 1 deletion noir-projects/aztec-nr/aztec/src/state_vars/private_set.nr
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ pub struct PrivateSet<Note, Context> {
impl<T, Context, let N: u32> Storage<T, N> for PrivateSet<T, Context>
where
T: Serialize<N> + Deserialize<N>,
{}
{
fn get_storage_slot(self) -> Field {
self.storage_slot
}
}

impl<Note, Context> PrivateSet<Note, Context> {
// docs:start:new
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ pub struct PublicImmutable<T, Context> {
impl<T, Context, let N: u32> Storage<T, N> for PublicImmutable<T, Context>
where
T: Serialize<N> + Deserialize<N>,
{}
{
fn get_storage_slot(self) -> Field {
self.storage_slot
}
}

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 @@ -12,7 +12,11 @@ pub struct PublicMutable<T, Context> {
impl<T, Context, let N: u32> Storage<T, N> for PublicMutable<T, Context>
where
T: Serialize<N> + Deserialize<N>,
{}
{
fn get_storage_slot(self) -> Field {
self.storage_slot
}
}

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 @@ -39,7 +39,11 @@ global HASH_SEPARATOR: u32 = 2;
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>,
{}
{
fn get_storage_slot(self) -> Field {
self.storage_slot
}
}

// SharedMutable<T> stores a value of type T that is:
// - publicly known (i.e. unencrypted)
Expand Down
4 changes: 1 addition & 3 deletions noir-projects/aztec-nr/aztec/src/state_vars/storage.nr
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ pub trait Storage<T, let N: u32>
where
T: Serialize<N> + Deserialize<N>,
{
fn get_storage_slot(self) -> Field {
self.storage_slot
}
fn get_storage_slot(self) -> Field;
}

// Struct representing an exportable storage variable in the contract
Expand Down
Loading