State Management
Aztec has a hybrid public/private state model. Contract developers can specify which data is public and which is private, as well as the functions that operate on that data.
Private and public data are stored in two separate trees: a public data tree and a note hashes tree. Both trees store state for all accounts on the network directly as leaves, unlike Ethereum where a state trie contains smaller tries for individual accounts.
This means storage must be carefully allocated to prevent collisions. Storage is siloed to each contract, though the exact siloing mechanism differs slightly between public and private storage.
Public State
Public state in Aztec works similarly to other blockchains. It is transparent and managed by smart contract logic.
The sequencer stores and updates public state. It executes state transitions, generates proofs of correct execution (or delegates to the prover network), and publishes data to Ethereum.
Private State
Private state is encrypted and owned by users who hold the decryption keys. It uses an append-only data structure since updating records directly would leak information about the transaction graph.
To "delete" private state, you add an associated nullifier to a nullifier set. The nullifier is computed such that observers cannot link a state record to its nullifier without the owner's keys.
Modifying state is accomplished by nullifying the existing record and creating a new one. This gives private state an intrinsic UTXO (unspent transaction output) structure.
Notes
Private state uses UTXOs, commonly called notes. Notes are encrypted pieces of data that only their owner can decrypt.
How Notes Work
In Ethereum's account-based model, each account maps to a specific storage location. In Aztec's UTXO model, notes specify their owner and have no fixed relationship between accounts and data locations.
Rather than storing entire notes, the protocol stores note commitments (hashes) in a Merkle tree called the note hash tree. Users prove they know the note preimage when updating private state.
When a note is consumed, Aztec creates a nullifier from the note data and may create new notes with updated information. This decouples the actions of creating, updating, and deleting private state.
Notes work like cash. To spend a 5 dollar note on a $3.50 purchase, you nullify the $5 note and create two new notes: $1.50 for yourself and $3.50 for the recipient. Only you and the recipient know about the $3.50 transfer.
Sending Notes
When creating notes for a recipient, you need a way to deliver them:
Onchain (encrypted logs): The standard method. Emit an encrypted log as part of your transaction. The encrypted note data is posted onchain, allowing recipients to find notes through note discovery.
Offchain: If you know the recipient directly, share the note data with them. They store it in their PXE and can spend it later.
Self-created notes: Notes you create for yourself don't need broadcasting. Store them in your PXE to prove ownership and spend them later.
Abstracting Notes
Users don't need to think about individual notes. The Aztec.nr library abstracts notes by letting developers define custom note types that specify how notes are created, nullified, transferred, and displayed. Aztec.nr also handles note discovery for notes encrypted to a user's account.