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

Private accounts, addresses and the mailbox

What is on chain

For a private account the chain holds no plaintext contents, only:

  • commitments: one per version of the account, a hash of the account id and its contents;
  • nullifiers: one per version that has been replaced;
  • encrypted notes: the new contents, encrypted to the owner’s viewing key.

An update spends the old version (publishing its nullifier) and creates a new one (publishing a commitment and a note). An observer cannot link a nullifier to the commitment it spends.

Keys

KeyLets the holder
Nullifier secret key (nsk)spend a version, so update the account and collect messages
Viewing keydecrypt notes, so read the account and find incoming messages
Authorization secret key (ask)supply an authorized private witness, which can then mark the actors it authorizes

The commands that make these: wallet account new private for a regular one, wallet account new private-accounts-key to print an npk and vpk pair for a sender who will address you by keys rather than by id, and wallet account new private-gms for a shared one (Shared private accounts).

The witness a user supplies for a regular private account comes in three strengths (lee/state_machine/core/src/circuit_io.rs):

pub enum RegularKey {
    Authorized(AuthorizationSecretKey),  // can spend
    Nullifying(NullifierSecretKey),      // can only receive and update
    FeeOnly(AuthorizationSecretKey),     // authorizes only the fee entry
}

Only Authorized lets the witness mark actors, which then hold grants at the sync root. Nullifying can update the account and collect messages, so it suffices for receiving, but authorizes nothing.

Kinds of private account

  • Regular. Id derived from the public keys. Authorized by ask.
  • Private PDA. Id derived from a program, a seed and the holder’s public keys. It has no ask: only a seed grant from the program authorizes it. The holder can operate it but cannot spend from it alone.

Addresses and pseudonyms

A private account can receive at a blinded address instead of its account id:

account_id.blinded(&factor)   // a hash of the id and a 32-byte secret factor

Each factor gives a different address. From the addresses alone, an observer cannot link two of them to each other or to the account, though the program account id beside an address stays public. The owner proves in zero knowledge that an address opens to their account.

Blinded addresses work in both directions:

  • Receiving. An async message sent to the address is collected by the account behind it.
  • Sending. A private actor can present an address instead of its account id as the sender; the receiver sees a stable pseudonym and can reply to it.

Use a fresh address per counterparty, per campaign or per conversation.

Who a blinded address hides you from depends on who writes to it:

  • Observers and public senders see only the address, and a public sender needs nothing else.
  • A private sender seals the message to you, and for that it needs your public keys and the factor (seal_message, lee/state_machine/core/src/sealing.rs). Those keys give your account id, so a private counterparty you hand an address to knows which account it is, and can link every address of yours it was given.

So a blinded address hides you from the public, not from private senders. The wallet CLI seals to a blinded address only for an account it holds the keys of, when a handler run by a collection sends a message onward (--seal-destination with --address-opening on wallet pending receive), and to a counterparty given by its npk and vpk it seals at the plain account id. The C ABI takes openings (the factors that open an address) for any mention (an actor the client lists for the transaction), a foreign one included (FfiAccountMention).

Recovery bindings

An address can receive stored messages in the clear (from a public sender, or a private one that publishes in the clear) only once a recovery binding for it is on chain, or is introduced by the same privacy-preserving transaction. Registration publishes a recovery binding (lee/state_machine/core/src/recovery.rs):

pub struct RecoveryBinding {
    pub address: AccountId,
    pub note: EncryptedNote,
}

The note, encrypted to the owner’s viewing key, tells the owner which of their accounts the address belongs to and with which factor. This is how a wallet restored from a seed finds the messages sent to its addresses.

The binding is created from the recipient’s public keys and factor, so the recipient or anyone holding those can publish it, in a private transaction, and once on chain it is reused.

  • A sender holding the recipient’s keys can introduce the binding in the same transaction and needs no prior registration, but only a privacy-preserving transaction can carry one (PublicExecution holds only the root call). So a wallet sending from a public account to a key pair whose address has no binding on chain yet builds a privacy-preserving transaction and pays for a proof, rather than failing.
  • A clear publication to an address with no binding, and none introduced alongside it, fails with UnboundAsyncDestination on the terms of any failure, and when charged pays only the cycles that ran.
  • The reference wallet checks the destinations it is given: it introduces the binding when it holds the recipient’s keys and otherwise refuses to build. Its simulation does not check a publication a handler makes to any other address.
  • A sealed message from a private sender needs no binding, because its own note tells the recipient which address it was for.

The mailbox

An AsyncMessage that is not delivered in its own transaction becomes a publication:

pub enum Publication {
    Clear(MessageBody),
    Sealed(SealedMessage),
}
  • Clear. Sent by a public actor, which always publishes in the clear, or by a private one that chose to. Sender, destination address and message bytes are readable by everyone. The owner finds it through the address’s recovery binding.
  • Sealed. Sent by a private actor. The chain holds a commitment and an encrypted note that only the recipient (and the sender, who wrote it) can read.

Every publication is added to the chain’s commitment tree.

Collecting

The owner’s wallet scans publications, decrypts what it can, and lists what belongs to it:

wallet pending list
wallet pending receive --position <n>

Collecting is a private transaction whose root is the stored message. The handler of the receiving actor runs with from set to the original sender. The proof publishes a nullifier for the message, a hash of the receiver’s nullifier secret key, the message’s commitment and its position (Nullifier::for_message, lee/state_machine/core/src/nullifier.rs), and settlement refuses one already spent, so it cannot be collected twice.

  • Collection is voluntary: a message never collected has no effect, and it never expires.
  • One message is the root. A transaction may claim others before it. The reference wallet sweeps up to four pending native credits into any privacy-preserving transaction it builds, for the private accounts it authorizes and its fee payer, fewer when the transaction’s own accounts and root leave fewer of its padded action slots, and none when it is synced more than 64 blocks behind the head (MAX_SWEPT_CLAIMS, MAX_SWEEP_SCAN_BLOCKS, lez/wallet/src/lib.rs).
  • The owner sees the message first. wallet pending list shows each message’s destination, sender and size, and wallet pending receive runs the message through the destination actor’s program.
  • Collecting never authorizes: a claim arrives with no grants, so a collected message cannot debit its recipient whatever keys the collection used (Authorization).

Shared private accounts

A group can own private accounts together (lee/key_protocol/src/key_management/group_key_holder.rs). The group shares one 32-byte secret, the Group Master Secret, from which every member derives the same keys for:

  • a shared regular account, which every member can spend;
  • a private PDA of a given program and seed, which every member can operate and only the program can authorize. The keys are derived from the program’s image id, so they stay the same wherever that program is deployed.

The secret is passed to a new member sealed to their sealing key, a separate key pair of the viewing key’s kind that wallet group new-sealing-key makes once per wallet. The member shares its public half, the inviter runs wallet group invite --key, and the member runs wallet group join --sealed (SealingSecretKey, group_key_holder.rs).

wallet account new private-gms makes either form: a shared regular account with --derivation-id (a value every co-owner must supply to derive the same account; random if omitted), or a group PDA with --pda --seed --program-id. A group PDA’s keys come from the program’s image id and the seed, but its account id from the program’s account id, the seed and those keys. The CLI takes only the image id and assumes the program sits at the image id’s own bytes (AccountId::from_builtin_program, lez/wallet/src/lib.rs), where only programs seeded into test states sit, so for a deployed program the account id it derives does not match the chain (What works with the reference wallet today). The second form is the basis of hidden shared vaults: see Multisig.

Two limits: every member sees everything in a shared account, and a member cannot be removed without moving to a new group secret.

What the owner must keep

The chain has the notes, so a wallet restored from its seed can find its own accounts and its mailbox again by scanning. Shared accounts are the exception: their keys come from the group secret, which is random rather than derived from the seed. Keep the seed and each group secret.