aztec-nr - noir_aztec::state_vars::private_immutable

Struct PrivateImmutable

pub struct PrivateImmutable<Note, Context>
{ /* private fields */ }

PrivateImmutable is an owned state variable type that represents a private value that is set once and remains unchanged forever. Because it is "owned," you must wrap a PrivateImmutable inside an Owned state variable when storing it:

#[storage]
struct Storage<Context> {
    your_variable: Owned<PrivateImmutable<YourNote, Context>, Context>,
}

For more details on what "owned" means, see the documentation for the OwnedStateVariable trait.

The value of a PrivateImmutable is stored in the Aztec's private state and hence is represented as a note.

The PrivateImmutable type facilitates: inserting the permanent note during initialization, and reading that note.

Example.

A contract's configuration parameters can be represented as a PrivateImmutable. Once set during contract deployment or initial setup, these parameters remain constant for the lifetime of the contract. The owner in this case would be an account with admin privileges. TODO(F-187): Update this ^

Generic Parameters:

  • Note - A single note of this type will represent the PrivateImmutable's value at the given storage_slot.
  • Context - The execution context (PrivateContext or UtilityContext).

Implementations

impl<Note> PrivateImmutable<Note, UtilityContext>

pub unconstrained fn is_initialized(self) -> bool
where Note: NoteType, Note: NoteHash, Note: Eq

Returns whether this PrivateImmutable has been initialized.

pub unconstrained fn view_note(self) -> Note
where Note: Packable, Note: NoteType, Note: NoteHash, Note: Eq

Returns the permanent note in this PrivateImmutable without consuming it.

This function is only available in a UtilityContext (unconstrained environment) and is typically used for offchain queries, view functions, or testing.

Unlike the constrained get_note(), this function does not push read requests or perform validation. It simply reads the note from the PXE's database.

impl<Note> PrivateImmutable<Note, &mut PrivateContext>

pub fn initialize(self, note: Note) -> NoteMessage<Note>
where Note: NoteType, Note: NoteHash, Note: Packable

Initializes a PrivateImmutable state variable instance with a permanent note and returns a [NoteEmission] that allows you to decide whether to encrypt and send the note to someone.

This function inserts the single, permanent note for this state variable. It can only be called once per PrivateImmutable. Subsequent calls will fail because the initialization nullifier will already exist.

Unlike PrivateMutable, this note will never be nullified or replaced through the state variable interface

  • it persists for the lifetime of the state variable.
pub fn get_note(self) -> Note
where Note: NoteType, Note: NoteHash, Note: Packable

Reads the permanent note of a PrivateImmutable state variable instance.

If this PrivateImmutable state variable has not yet been initialized, no note will exist: the call will fail and the transaction will not be provable.

Since the note is immutable, there's no risk of reading stale data or race conditions - the note never changes after initialization.

impl<Context, Note> PrivateImmutable<Note, Context>

Trait implementations

impl<Context, Note> OwnedStateVariable<Context> for PrivateImmutable<Note, Context>

pub fn new(context: Context, storage_slot: Field, owner: AztecAddress) -> Self