aztec-nr - noir_aztec::state_vars

Struct DelayedPublicMutable

pub struct DelayedPublicMutable<T, let InitialDelay: u64, Context>
{ /* private fields */ }

Public mutable values with private read access.

Implementations

impl<let InitialDelay: u64, T> DelayedPublicMutable<T, InitialDelay, UtilityContext>

pub unconstrained fn get_current_value(self) -> T
where T: Packable, T: Eq

impl<let InitialDelay: u64, T> DelayedPublicMutable<T, InitialDelay, &mut PrivateContext>

pub fn get_current_value(self) -> T
where T: Packable, T: Eq

This function performs a historical public storage read (which is in the order of 4k gates), regardless of T's packed length. This is because DelayedPublicMutable::schedule_value_change stores not just the value but also its hash: this function obtains the preimage from an oracle and proves that it matches the hash from public storage.

Because of this reason, if two mutable values are often privately read together it can be convenient to group them in a single type T. Note however that this will result in them sharing the mutation delay:

// Bad: reading both `paused` and `fee` will require two historical public storage reads
#[storage]
struct Storage<C> {
    paused: DelayedPublicMutable<bool, INITIAL_DELAY_S, C>,
    fee: DelayedPublicMutable<Field, INITIAL_DELAY_S, C>,
}

// Good: both `paused` and `fee` are retrieved in a single historical public storage read
#[derive(Packable)]
struct Config {
    paused: bool,
    fee: Field,
}

#[storage]
struct Storage<Context> {
    config: DelayedPublicMutable<Config, INITIAL_DELAY_S, Context>,
}

impl<let InitialDelay: u64, T> DelayedPublicMutable<T, InitialDelay, PublicContext>

pub fn schedule_value_change(self, new_value: T)
where T: Packable, T: Eq
pub fn schedule_and_return_value_change(self, new_value: T) -> ScheduledValueChange<T>
where T: Packable, T: Eq
pub fn schedule_delay_change(self, new_delay: u64)
where T: Packable, T: Eq
pub fn get_current_value(self) -> T
where T: Packable, T: Eq
pub fn get_current_delay(self) -> u64
where T: Packable, T: Eq
pub fn get_scheduled_value(self) -> (T, u64)
where T: Packable, T: Eq
pub fn get_scheduled_delay(self) -> (u64, u64)
where T: Packable, T: Eq

Trait implementations

impl<Context, let InitialDelay: u64, let M: u32, T> StateVariable<M + 1, Context> for DelayedPublicMutable<T, InitialDelay, Context>
where DelayedPublicMutableValues<T, InitialDelay>: Packable<N = M>

pub fn new(context: Context, storage_slot: Field) -> Self pub fn get_storage_slot(self) -> Field