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

Rate-limiting nullifiers

Shows: the seat (4) · the proof-carrying message (7) · pseudonym (8)

Goal

A rate-limiting nullifier (RLN) lets a network accept anonymous messages and still limit how many each member sends. Logos has an RLN membership registry program for LEZ (logos-co/logos-lez-rln).

Two halves:

  • On chain: a membership registry. A member pays a fee and registers a commitment to a secret. The registry keeps the commitments in a Merkle tree and publishes the root.
  • Off chain: the rate limit. Every message carries a zero-knowledge proof that its sender is in the tree, plus a small piece of the sender’s secret. A sender within their limit reveals nothing about their secret or which member they are; one who exceeds it reveals the whole secret, and anyone who learns the secret can have the member removed.

What follows is a toy version of the registry, cut down from the real one: the Logos program, an actor program built against LEZ v0.4.0.

Off chain, in brief

A member holds a secret a0. Their commitment is H(a0). They registered with a rate_limit: the number of messages they may send per epoch.

For each message they pick a slot number below their limit and compute:

a1 = H(a0, epoch, slot)      // a different line for each slot of each epoch
x  = H(message)
y  = a0 + a1 · x             // one point on that line
nullifier = H(a1)            // the same for every message that uses this slot

This nullifier is RLN’s own, unrelated to the nullifiers that spend LEZ private accounts.

The proof shows that the sender’s leaf is under the on-chain root, that slot is below the registered limit, and that the point and the nullifier were computed honestly. It does not show which member.

Sending more than rate_limit messages in an epoch forces a slot to be used twice. Two messages in one slot give two points on one line, and two points give a0. The network notices because the two messages carry the same nullifier.

None of this touches the chain: peers verify the proofs against the root they read from the registry. The arithmetic follows RLN v2 as this guide understands it; the guide has not examined the proving code (zerokit, which logos-lez-rln calls from lez-rln/src/proof_circuit.rs).

Actors

ActorWhat it holdsPlacement
(registry, rln)price, treasury, the members and their limits, the Merkle rootpublic PDA
(payer, rln): a seatnothingon the payer’s account, public or private

The registry stores commitment → rate_limit for each member. A leaf of the tree is H(commitment, rate_limit), so the off-chain proof can use the limit.

Messages

enum Message {
    /// To a seat, by its owner.
    Register { registry: Actor, id_commitment: [u8; 32], rate_limit: u64,
               fee: u128, treasury: AccountId },
    /// From a seat to the registry: "I paid `fee` to `treasury` for this member."
    Enroll { id_commitment: [u8; 32], rate_limit: u64, fee: u128, treasury: AccountId },
    /// To the registry, by anyone who knows a member's secret.
    Slash { identity_secret: [u8; 32] },
}

Handler

fn handle_message(input: &ReceiveInput, message: Message) -> Response {
    match message {
        // The seat: check the owner, pay the fee, tell the registry.
        Message::Register { registry, id_commitment, rate_limit, fee, treasury } => {
            assert!(input.is_authorized() && input.from.is_none(), "only the owner registers");
            let payer = Actor::native_balance(input.receiver.account_id);
            Response::keep_state()
                .send(
                    SyncMessage::new(payer, &native_token::Message::Transfer { to: treasury, amount: fee })
                        .with_grants([payer]),
                )
                .send_sync(registry, &Message::Enroll { id_commitment, rate_limit, fee, treasury })
        }

        // The registry: a seat of this program says it paid. Check the price, add the member.
        Message::Enroll { id_commitment, rate_limit, fee, treasury } => {
            assert!(input.from_own_program(), "only a seat enrolls");
            let mut reg = Registry::from_bytes(&input.pre_state);
            assert!((MIN_RATE..=MAX_RATE).contains(&rate_limit));
            assert_eq!(treasury, reg.treasury, "paid the wrong account");
            assert_eq!(fee, reg.price_per_unit * rate_limit as u128, "paid the wrong amount");
            assert!(reg.members.insert(id_commitment, rate_limit).is_none(), "already a member");
            reg.root = merkle_root(&reg.members);
            Response::set_state(reg.to_bytes())
        }

        // The registry: whoever knows the secret may remove the member.
        Message::Slash { identity_secret } => {
            let mut reg = Registry::from_bytes(&input.pre_state);
            reg.members.remove(&hash1(&identity_secret)).expect("not a member");
            reg.root = merkle_root(&reg.members);
            Response::set_state(reg.to_bytes())
        }
    }
}

How it runs

  1. Register. The member tells their seat to register. The seat pays the fee from the account it sits on and tells the registry, both SyncMessages in one transaction: if the registry refuses, the payment is undone. The member’s transaction marks both the seat and their native balance actor, or attaching the grant fails with UnheldGrant.
  2. Send messages. Off chain, with proofs against the registry’s root.
  3. Overspend. Two messages in one slot expose the secret.
  4. Slash. Anyone sends the secret to the registry; the member is gone and the root changes.

What to notice

The registry never sees the money move and does not read the treasury’s balance. It trusts Enroll { fee, treasury } because it comes from a seat of its own program, and the only code in this program that sends Enroll has just sent that transfer. It only checks that the amount and the destination are right.

Slashing needs no evidence, only the secret; the registry does not see the two offending messages. The protocol leaks a secret only when its member overspends.

The fee is the deterrent. The Logos program charges price_per_unit × rate_limit to a treasury and pays nothing back, so a slashed member loses a paid membership. There is no stake and no reward for the slasher.

In the toy, Slash carries only the secret, and the registry reads the rest from its state. The Logos program’s Slash also names the commitment and a leaf index hint.

What private actors bring

In this toy, the registration can be anonymous. The Logos program’s Register names its payer account in the clear and needs that account’s signature, so its registrations are not.

RLN hides which member sent a message, not who the members are. When the seat is on a public account, the registration is a signed transaction: everyone sees that this account paid for this commitment.

  • The membership list is a list of accounts that use the network.
  • When a member is slashed, the published secret gives the commitment, and the commitment gives the account that paid for it.

Put the seat on a private account, and pay the transaction’s fee privately too, and neither link is published.

  • The seat runs inside the member’s proof. Its payment and its Enroll cross to the public side from a blinded address.
  • The registry accepts it for the same reason as before: it comes from a seat of its own program. Here that fact is proven, not observed.
  • The chain sees a commitment enter the tree and the treasury receive a fee. It does not see who paid.
SeatChain sees at registrationA slash reveals
Publicpayer, commitment, rate limit, feethe commitment, and so the payer
Privatecommitment, rate limit, feethe commitment only

The handler has no code for this: the same three arms run, and the member chooses by which account they use.

What private actors do not bring.

  • A private registry. The members and the root must be public, because every peer verifies proofs against the root.
  • The rate limit itself: that is the off-chain proof, and no actor takes part in it.
  • A hidden rate limit: the limit is in the leaf and in the fee.

A commitment registered a minute before a burst of messages is easy to connect to that burst, so register early.

Going further

  • Expiry and renewal. The Logos program gives each membership an active period and a grace period, lets anyone renew it during the grace period by paying the registration price again, and lets anyone erase an expired one. Each needs the time: the Logos program takes the submitter’s reading now_ms and returns the timestamp validity window [now_ms, now_ms + CLOCK_CLAIM_TOLERANCE_MS) (pattern 16), since a claim that must equal the clock exactly fails whenever the clock moves.
  • A real tree. The toy recomputes the root from the member list; the Logos program keeps a fixed-depth incremental Poseidon tree and updates one path per change.
  • A cap. The Logos program limits the sum of all rate limits.
  • A reward for slashing. Keep fees on a PDA and send part as an async message to an address the slasher names. A private slasher stays unknown.
  • A private counter is not RLN: it limits only actions that go through the chain (Credentials), and RLN exists for messages that never do.