Skip to content

Commit

Permalink
chore: remove dummy arrays (#7246)
Browse files Browse the repository at this point in the history
With noir-lang/noir#4633 merged we can now use
the new `let` syntax to mark parameters as numeric. I'm not entirely
sure why we need to specify it both on the type and the impl, @vezenovm
could you expand on this a little bit?
  • Loading branch information
nventuro authored and AztecBot committed Jul 17, 2024
1 parent 04cd2b0 commit 50b26b6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
10 changes: 3 additions & 7 deletions aztec/src/state_vars/shared_mutable/scheduled_delay_change.nr
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mod test;
// is performed via `schedule_change` in order to satisfy ScheduleValueChange constraints: if e.g. we allowed for the
// delay to be decreased immediately then it'd be possible for the state variable to schedule a value change with a
// reduced delay, invalidating prior private reads.
struct ScheduledDelayChange<INITIAL_DELAY> {
struct ScheduledDelayChange<let INITIAL_DELAY: u32> {
// Both pre and post are stored in public storage, so by default they are zeroed. By wrapping them in an Option,
// they default to Option::none(), which we detect and replace with INITIAL_DELAY. The end result is that a
// ScheduledDelayChange that has not been initialized has a delay equal to INITIAL_DELAY, which is the desired
Expand All @@ -18,14 +18,11 @@ struct ScheduledDelayChange<INITIAL_DELAY> {
post: Option<u32>,
// Block at which `post` value is used instead of `pre`
block_of_change: u32,
// The _dummy variable forces INITIAL_DELAY to be interpreted as a numeric value. This is a workaround to
// https://github.com/noir-lang/noir/issues/4633. Remove once resolved.
_dummy: [Field; INITIAL_DELAY],
}

impl<INITIAL_DELAY> ScheduledDelayChange<INITIAL_DELAY> {
impl<let INITIAL_DELAY: u32> ScheduledDelayChange<INITIAL_DELAY> {
pub fn new(pre: Option<u32>, post: Option<u32>, block_of_change: u32) -> Self {
Self { pre, post, block_of_change, _dummy: [0; INITIAL_DELAY] }
Self { pre, post, block_of_change }
}

/// Returns the current value of the delay stored in the data structure.
Expand Down Expand Up @@ -167,7 +164,6 @@ impl<INITIAL_DELAY> Deserialize<1> for ScheduledDelayChange<INITIAL_DELAY> {
pre: if pre_is_some { Option::some(pre_inner) } else { Option::none() },
post: if post_is_some { Option::some(post_inner) } else { Option::none() },
block_of_change,
_dummy: [0; INITIAL_DELAY],
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ struct SharedMutablePrivateGetter<T, INITIAL_DELAY> {
other_contract_address: AztecAddress,
// The storage slot where the SharedMutable is stored on the other contract
storage_slot: Field,
// The _dummy variable forces INITIAL_DELAY to be interpreted as a numberic value. This is a workaround to
// https://github.com/noir-lang/noir/issues/4633. Remove once resolved.
_dummy: [Field; INITIAL_DELAY],
}

// We have this as a view-only interface to reading Shared Mutables in other contracts.
Expand All @@ -33,7 +30,7 @@ impl<T, INITIAL_DELAY> SharedMutablePrivateGetter<T, INITIAL_DELAY> where T: Fr
) -> Self {
assert(storage_slot != 0, "Storage slot 0 not allowed. Storage slots must start from 1.");
assert(other_contract_address.to_field() != 0, "Other contract address cannot be 0");
Self { context, other_contract_address, storage_slot, _dummy: [0; INITIAL_DELAY] }
Self { context, other_contract_address, storage_slot }
}

pub fn get_value_in_private(self, header: Header) -> T {
Expand Down

0 comments on commit 50b26b6

Please sign in to comment.