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

Credentials and tickets

Shows: the proof-carrying message (7) · pseudonym (8) · async message for strangers (9) · write once (15)

Goal

An issuer gives a person a badge, which the person later shows to a venue. The venue learns that the badge is real and which issuer gave it, and nothing else about who shows it: the holder hides among everyone that issuer gave a badge to.

Actors

ActorWhat it holdsPlacement
(issuer, badges)nothing; it only issuespublic
(holder, badges): a badgewhich issuer gave itprivate, on the holder’s account
a venueits own businesspublic, any program

Messages

enum Message {
    /// To the issuer's actor, by the issuer.
    Issue { to: AccountId },
    /// Between badge actors: "you now hold a badge from me".
    Badge,
    /// To a badge, by its holder.
    Show { venue: Actor },
}

/// What the venue receives.
struct Attested { issuer: AccountId }

Handler

fn handle_message(input: &ReceiveInput, message: Message) -> Response {
    let me = input.receiver;
    match message {
        Message::Issue { to } => {
            assert!(input.is_authorized() && input.from.is_none(), "only the issuer issues");
            Response::keep_state().send_async(Actor::new(to, me.program_account_id), &Message::Badge)
        }
        Message::Badge => {
            let issuer = input.from.filter(|_| input.from_own_program()).expect("not a badge");
            Response::set_state(write_once(&input.pre_state, encode(&issuer.account_id)))
        }
        Message::Show { venue } => {
            assert!(input.is_authorized() && input.from.is_none(), "only the holder shows");
            let issuer: AccountId = decode(&input.pre_state);
            Response::keep_state().send_sync(venue, &Attested { issuer })
        }
    }
}

The venue’s side is two checks. Anyone can run Issue on their own account and become an issuer, so the venue decides which issuers it trusts:

let badge = input.from.expect("an attestation has a sender");
assert_eq!(badge.program_account_id, BADGES_PROGRAM, "not from a badge");
let Attested { issuer } = decode(&input.message);
assert!(TRUSTED_ISSUERS.contains(&issuer), "not an issuer this venue trusts");

How it runs

  1. Issue. The issuer’s actor sends Badge to the holder’s address as an async message. The issuer is public, so the message is published in the clear, and the holder’s address needs its recovery binding on chain first, or the issue is charged and reverted with UnboundAsyncDestination.
  2. Collect. The holder’s badge actor stores the issuer. It accepts Badge only from the badges program.
  3. Show. The holder sends Show in a private transaction. The badge sends a SyncMessage to the venue under a blinded address, which the reference wallet draws fresh for each message.
  4. Admit. The venue sees a message from the badges program naming an issuer it trusts.

Why the venue can believe it

The only code that sends Attested is the Show arm, and it sends the issuer it read from its own state. That state can only have been written by the Badge arm, which only accepts the badges program as sender. The issue ran publicly on the sequencer; for a private holder, the collection and the show ran inside the holder’s proofs.

The venue checked no signature and no membership proof, only which program spoke, so any program can accept badges without knowing how they are stored.

Public and private

HolderWhat the venue learns
Private“a badge from this issuer”, from a one-time address
Publicthe same, and who you are

What leaks

  • At issue time: that the issuer gave a badge to an address.
  • At show time: the venue, the issuer, the time.
  • Not revealed: which badge it was, or a link between two visits, since the reference wallet presents a fresh blinded address for each show (timing aside). A holder that presents the same address twice links those visits.

Going further

  • Tickets. Add a used flag to the badge state and set it in Show, so the badge works once.
  • Rate limits. Keep a counter per day in the badge state and refuse Show past the limit. Because every run starts from the account’s real latest state, the limit cannot be exceeded, however the holder arranges their transactions. This limits actions that go through the chain. For messages that never touch it, see Rate-limiting nullifiers.
  • Attributes. Store a birth date in the badge and have Show send only AgeAtLeast(18), computed inside the proof.
  • What does not work: asking about someone else. A venue cannot query whether a private holder holds a badge; only the holder can show it.