Programs, deployment and identity
What a program is
A program is a RISC Zero guest binary with one entry point: the handler. Its image id is a hash of the binary; its account id is where it is deployed, the id that appears in every Actor.
The same binary can be deployed at several addresses, and each deployment is a separate program: separate actors, separate PDAs.
Deployment
Programs are deployed through the program loader, a built-in program that runs as engine code, with no bytecode, at a fixed address (PROGRAM_LOADER_ACCOUNT_ID). The loader stores, as its own actor state:
- a header at the program’s address;
- the bytecode, split over a chain of segment accounts.
pub struct ProgramHeader {
pub image_id: ProgramId, // recomputed from the bytecode, never taken on trust
pub program_first_segment: AccountId,
pub immutable: bool, // once true, the header can never change
}
A program has at most 20 segments (MAX_PROGRAM_SEGMENTS). The wallet splits the user ELF at 96 KiB per segment (MAX_SEGMENT_DATA_LEN), but that is a client chunk size, not a limit the loader enforces: a segment is bounded only by the per-transaction cap of max_block_size less the block overhead. Deploying has the commands, the account rules and the errors.
Loader messages are allowed only in transactions that carry no proof, so a code change never lands inside a transaction whose proof already committed to specific program images.
Upgrades
A header that is not immutable can be pointed at new bytecode. For the author this has two consequences.
- State layout. The new code reads actor states written by the old code. Version the layout from the first release.
- Old messages. An AsyncMessage sent by the old version may sit in a mailbox for months and be collected after the upgrade. The new handler must still decode and accept every message the old version could have sent.
Marking a program immutable removes both problems and enables undisclosed execution, below.
Built-in programs
Built-in system programs live at ids derived from fixed names, as public PDAs of the system upgrader program (Sequencer stake):
AccountId::from_system_program_name(&SystemProgramName::new(b"clock"))
They are listed in System programs. The native token has a reserved id and no bytecode: the engine and the privacy circuit compute it directly, so it needs no inner proof.
Program identity in a private transaction
When a private handler runs, the proof must say which code it was. There are two ways (ProgramImageClaim, lee/state_machine/core/src/circuit_io.rs):
| Claim | What is published | Checked by the sequencer |
|---|---|---|
| Disclosed | the program’s account id and image id | that this image is deployed at this id |
| Undisclosed | a root of the commitment tree | that the root is a known one |
An undisclosed claim proves that the code is some immutable program, without saying which. An immutable program’s header is mirrored into the commitment tree, so membership can be proven in zero knowledge. Only immutable programs can run this way.
A third form is a shadow program: one never deployed, addressed at an id derived from its image id alone (AccountId::for_shadow_program), so the circuit resolves its code from that id and the proof publishes no claim for it (lee/privacy_preserving_circuit/src/main.rs). It can run only on private actors: the sequencer cannot load it, so a message reaching it in public execution fails with UnknownProgram. wallet pending receive --shadow-program <elf> runs one.
Choosing between the first two is a privacy decision:
- Disclosed: observers learn that your private transaction used this program.
- Undisclosed: they learn only that it used some immutable program, and only if that program never crosses the boundary in the transaction.
Every boundary entry names an Actor ({ account_id, program_account_id }), and blinding hides the account id but not the program account id (lee/state_machine/core/src/execution_state.rs). So a message across the boundary, in either direction, publishes the private actor’s program account id, the image resolves from it, and the undisclosed claim hides nothing.
Staying off the boundary is necessary but not sufficient. The claim proves membership of the set of immutable programs, and every deployment is public, so an observer guesses among only as many programs as are immutable on chain.
Undisclosed is also not a property of the program but a choice each prover makes per transaction (ProgramCatalog::with_undisclosed, lee/state_machine/src/privacy_preserving_transaction/circuit/mod.rs), and the default is Disclosed, which reveals the program. The wallet CLI never selects Undisclosed (the C ABI lets a caller choose it per program, FfiProgramKind). Marking a program immutable makes undisclosed available to a prover who wants it; it does not hide the program, and an author cannot choose for their users.
Where a program keeps its state
Three places, and most programs use more than one.
- On users’ accounts. One actor per user: balances, holdings, seats, badges.
- On PDAs. Shared state the program controls: vaults, pools, registries, configuration.
- On fixed accounts. For built-ins: the clock account, the fee state.
Where state lives compares them.