Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Transactions, public and private

A transaction delivers one root message and runs everything that message triggers. A public transaction is signed by its accounts and executed by the sequencer. A private transaction carries a proof that the private handlers ran correctly, and the sequencer executes only the public handlers.

Public transactions

A public transaction contains:

PartContent
Rootthe actor to deliver to, and the message bytes
Declared actorsevery public actor the execution may reach, each marked Authority::Signer (a grant at the root when its account signs, see Authorization) or Authority::None
Authorized accountsthe accounts that sign
Nonces and witnessesone witness entry per signer, in nonces order: its signature data and a commitment to the account’s next key. See Keys, nonces and rotation
Fee declarationpayer, gas limit, tip, maximum fee (How fees are priced)
Admission evidenceproof that a not-yet-existing account id is a real public address

The sequencer checks the signatures and nonces, reserves the fee, runs the root and everything it triggers, and applies the result. If execution fails, or its effects would write system state a user transaction may not (the clock, the fee accounts, the bridge account other than a rise in its balance, bridge state on any account, or the system upgrader’s registry), the state changes are dropped, but the payer still pays and every signer’s nonce still advances. A transaction malformed before execution (a bad signature, an undeclared root) is refused instead and pays nothing.

A failed execution is charged the full gas limit, except UnboundAsyncDestination and a nonzero guest exit code, which pay the cycles that ran (charged_cycles, lee/state_machine/src/validated_state_diff/mod.rs); a revert for writing system state also pays only the cycles that ran. The reference wallet declares the simulated cycles plus a margin, so a revert its simulation missed, such as a validity window, pays the simulated cycles plus that margin (25% by default), and a guest panic sent with --allow-revert pays the configured limit. The transaction receipt says only success: false and the fee, not why.

Declaring actors

The engine runs a public handler only for an actor the transaction declared. To an undeclared actor, a SyncMessage fails the transaction; an AsyncMessage is stored for later if the address is private (or, in a privacy-preserving transaction, delivered at once when it is one of the submitter’s own private actors and the submitter promotes it, AsyncMessage), and fails if it is public, since there is nowhere to store it.

So the builder of the transaction decides, by declaring or not, whether the destination is handled now.

Admission

Before any public actor receives a message, its account must be admitted: shown to derive from a public key or a PDA. It passes if one of these is true:

  • it already exists on chain;
  • it signed the transaction;
  • the transaction carries evidence for it: the public key or the program-and-seed that hashes to its id;
  • the sender granted a seed that derives it (a program-derived account, PDA).

Admission stops messages from creating state at ids nobody can ever control. In practice, the first payment to a fresh public account must carry that account’s public key, or the transaction reverts and the payer is still charged. The reference wallet simulates first, so it refuses to send such a transfer (declared public but not admitted) unless given --allow-revert; --to-initial-key attaches the key.

Fees

A public transaction pays for execution and for the bytes it adds to the block. The fee is reserved before execution and the unused part refunded after (How fees are priced). Exempt shapes: genesis transactions, sequencer injections with an empty witness set, meaning bridge deposits and system upgrades, and sequencer-stake operations. The clock and fee-distribution transactions are stripped before classification and never pay. Any other user transaction that omits its fee is rejected, with MissingFeeDeclaration for a public one and MissingPrivateFee for a private one.

Private transactions

A private transaction involves at least one private account. For each one, its owner hands the prover a private witness: the account’s keys and what is needed to spend its current version (PrivateWitness, lee/state_machine/core/src/circuit_io.rs). It stays on the machine that proves, which for the reference wallet is the owner’s. This is a different thing from a public witness entry, which is published signature data. An authorized private witness can mark actors of its account, listed in signer_programs, for a grant at the root (Authorization).

A private transaction’s public part is:

PartContent
Proofone receipt of the privacy circuit
Private actionsper private account touched: a nullifier, a new commitment, an encrypted note
Boundarythe messages that crossed between private and public actors, in order
Async messagesstored messages sent by private actors, each sealed to its recipient or published in the clear
Recovery bindingsnewly registered receive addresses
Public rootthe root message, if it targets a public actor
Validity windowsthe intersection of its private handlers’ windows; public handlers’ are checked at settlement
Program claimswhich program images the proof relied on
Proven feewhen the proof pays the fee: its tip, its refund target, and optionally a fee fallback (Private fees)

It may also carry signatures, when a public account in it must be authorized, and a signer can then pay through a fee declaration in place of the proven fee (Private fees).

Three runs of one engine

The same execution engine runs three times:

  1. Dry run, on the user’s machine. All handlers run, public and private, and the wallet learns which messages will cross between public and private actors.
  2. Private part, on the user’s machine and inside the circuit. Only private handlers run; each message that crosses to the public side is written to the boundary instead of being executed.
  3. Public part, on the sequencer. Only public handlers run; each time a message crosses, the sequencer compares it with the next boundary entry, and a mismatch fails the transaction.

The two halves check each other:

  • A message from private to public is a demand. The proof says “my handler sent exactly this”, and the sequencer carries it out.
  • A message from public to private is an assumption. The proof says “I assumed the public side would send exactly this”, and the sequencer confirms it did.

A demand runs against live state, so transactions prepared against the same public balance compose at settlement: two transfers prepared against a recipient balance of 400 settle, the first against 400 and the second against 437.

The dry run meters the public part against DEFAULT_PUBLIC_CYCLE_BUDGET (32M cycles), but settlement allows at most MAX_GAS_EXEC (10M), so a public part between the two passes the dry run and fails at settlement out of gas, charged or dropped as any failure is (What the handler returns).

An example

Alice pays 10 from her private balance to Bob’s public balance.

  1. Root: Transfer { to: bob, amount: 10 } to (alice_private, native). This actor is private, so the root is not published.
  2. In the proof: Alice’s handler debits her and sends Credit(10) to (bob, native) as an async message. Bob’s actor is public and declared, so the message crosses.
  3. Boundary: one private-to-public entry holding the credit, plus the fee credit into the fee inbox (Private fees).
  4. On the sequencer: the proof verifies. Bob’s handler runs with Credit(10) from the boundary and his balance grows.

An observer sees Bob receive 10 from “some private balance actor” and a new commitment, but not Alice’s account, her balance or her other activity.

Collecting a stored message

A stored message is collected by a private transaction, as its root or as a claim (Order of execution). The proof shows the message is in the chain’s commitment tree and spends a nullifier only the receiver can derive, so it is collected at most once (Collecting). Nothing crosses to the public side unless the handler sends something there.

Proving cost

The user’s machine produces one inner proof per message delivered to a private actor, and one proof for the circuit that checks them all. Two things reduce the count:

  • Public handlers are never proven; the sequencer runs them.
  • The native token needs no inner proof; the circuit computes it directly.

So collecting a native credit is one proof. A token transfer between two of your own private accounts is three when the credit is delivered in the same transaction: two handler runs and the circuit.

Private fees

A private transaction pays through a reserve proven inside itself: one native credit crossing into the fee inbox, settled at the block’s base fees. The reserve is an upper bound rather than the fee: a surplus above MIN_PRIVATE_REFUND is refunded to the proof’s refund target, or else to the payer’s alias (the blinded address the payer presents) when a recovery binding for it is on chain, and a smaller or unrefundable one is kept as tip (lez/chain_state/src/apply.rs). A refund to the payer’s alias is a stored credit, collected like any other (Collecting); a refund target is a public account and is credited at once. A private transaction with a public signer can instead pay through that signer’s fee declaration, as a public one does (lez/chain_state/src/classify.rs). Use --dry-run on a wallet command to price one before sending.

A proof can also carry a fee fallback: the payer’s private state after the fee transfer alone, which it can build only when the payer’s pre-state covers the reserve by itself (ProvenFee, FeeFallback, lee/state_machine/core/src/circuit_io.rs). If the public part then fails, settlement applies the fallback instead of the private actions, so the transaction reverts and still pays. A proof without one has no such revert: unless a public signer declares the fee, its failure drops the transaction unpaid.

How fees are priced

Two resources are priced: execution gas, the cycles public handlers run, and storage gas, the transaction’s serialized bytes, with a private transaction’s proof always counted as PROOF_BYTES (223,047). Each has a base fee per unit, held by the fee program; a dry run prints both on its base fees: line, as exec 8 / stor 8, and 8 is the floor of each (BASE_FEE_EXEC_MIN, BASE_FEE_STOR_MIN, lez/programs/fee/core/src/market.rs). After every block each base fee moves toward a target use per block, 5M cycles and 500,000 bytes: up when the block used more, down when it used less, by at most an eighth per block (next_base_fee, market.rs; FeeState::apply_block, lez/programs/fee/core/src/state.rs). A block holds at most twice the target, MAX_GAS_EXEC (10M cycles) and MAX_GAS_STOR (1M bytes).

A fee is execution gas × exec base fee + bytes × stor base fee + tip, at the base fees the block opens with (fee_for, lez/programs/fee/core/src/assess.rs). The tip goes to the block’s producer, the rest to the fee escrow (Fee).

  • Public. The reserve prices the declared gas limit. The transaction is invalid if that reserve exceeds its maximum fee or the gas limit exceeds MAX_GAS_EXEC (validate_static_tx, lez/programs/fee/core/src/validity.rs). It is charged for the cycles that ran, at most its gas limit, or the whole limit on most failures (Public transactions), and the rest of the reserve is refunded.
  • Private, paid in the proof. Execution gas is a fixed proof verification charge (PRIVATE_VERIFY_GAS, 409,764) plus the public part’s cycles, and the public part may run only as many cycles as the reserve pays for past the tip and the block has left. Paid by a signer’s declaration, it is priced as a public one.

Base fees can rise between pricing and inclusion. The reference wallet reads the quote (the head’s base fees) and prices at the base fees after --fee-headroom blocks (5 by default) of the steepest climb, every block full: about 80% above the quote, 62.5% from the floor of 8, where the steps round down (base_fee_ceilings, lez/wallet/src/lib.rs). For a public transaction that sets the default --max-fee; for a private one it sets the reserve, clamped to the payer’s balance. Either way the fee is charged at the block’s base fees; a private transaction also loses a surplus too small to refund (Private fees). The flags are in Setting up the wallet.

Choosing the form

You do not choose it in the program. The wallet builds a public transaction when every account involved is public, and a private one otherwise. A program written with AsyncMessages for payouts and SyncMessages for atomic steps works in both without changes.