Firebreak

Reference implementation

Bounty claims

The whistleblower claim flow: an anchored commitment, threshold decryption and two-tranche payout.

Source
4 files, 340 lines
Tests
1 files, 13 cases
Paper
sec:settlement

Whistleblower claim protocol

Purpose

An insider who reports a violation should be paid, should not be front-run (not even by a Council member who reads the evidence), and should never have to reveal who they are. This module implements the paper's bounty claim protocol (Appendix A, "Bounty claim protocol", and the settlement section) as pure transitions on the Council's state. It reuses the epoch ledger: commitments are ledger leaves.

Data formats

Object Definition
payout key pk_c a fresh x-only BIP340 key the claimant generates for this claim
ciphertext C the evidence M encrypted to the Council's threshold encryption key (outside this module)
commitment leaf value H(C) || pk_c (64 bytes); key taggedHash("Firebreak/bounty/commit", value)
delivery { epoch, proof, ciphertext, payoutKey, claimBond }
evidence digest SHA-256(M) after decryption; priority is decided among claims with the same digest
ownership proof BIP340 signature by pk_c over taggedHash("Firebreak/bounty/owner", challenge)

Parameters: claimWindow (in epochs), beta1, beta2. The Council's judgment is injected: assess(M) -> { operatorId, valid, knowinglyFalse? }. Decryption is injected too, as decrypt(C).

Message flow

  1. The claimant generates (sk_c, pk_c), encrypts the evidence to the Council's threshold key to get C, and posts commitmentLeaf(C, pk_c) to the ledger.

  2. The ledger closes the epoch; its root is anchored on Bitcoin and recorded with anchor(state, record). The record must chain to the previous one.

  3. The claimant delivers C, pk_c, the inclusion proof and an optional claim bond c through any channel: deliver(state, delivery, decrypt, assess). The Council checks:

    • that the epoch is anchored (otherwise not-anchored);
    • that the leaf for (C, pk_c) is in it (otherwise not-included: a delivery that does not match its commitment fails here);
    • that the current epoch is at most epoch + claimWindow (otherwise window-closed);
    • that the claim is new (otherwise duplicate), that it decrypts (otherwise undecryptable), and that its evidence has no winner yet (otherwise already-resolved).

    The Council then decrypts by threshold and assesses the evidence. If the evidence is unfounded, the claim bond is refunded at once. If it is knowingly false, the bond is forfeited to the pool. If it is credible, the claim waits for priority.

  4. orderInspection(state, digest): the Council orders an inspection on the evidence. The priority winner is fixed and paid beta1 from the pool. Rival claims for the same digest are marked superseded and their bonds refunded.

  5. confirm(state, digest): the inspection or a slash confirms the violation. The operator's bond is slashed into the pool, and beta2 is paid, drawn first from the slashed bond. The winner's claim bond is refunded. Or dismiss(state, digest): no violation is confirmed. The bond is refunded and no beta2 is paid.

  6. If the claimant later reveals themselves to seek protection, they sign a challenge with sk_c (proveOwnership / verifyOwnership).

Priority

Among credible claims with the same evidence digest, the commitment anchored in the earliest epoch wins. Within one epoch, the lowest commitment key (compared as bytes) wins. Commitment keys are hashes, so no claimant can choose a low one for evidence they did not already hold. A claim committed in epoch e may be delivered until epoch e + claimWindow, so the winner is final once the current epoch passes winner.epoch + claimWindow: no earlier commitment can still arrive. orderInspection refuses to pay before then (priority-not-final).

Claim stages

Stage Meaning Bond
credible waiting for priority held
unfounded the evidence was not valid refunded
false knowingly false forfeited to the pool
superseded lost on priority refunded
inspection won; beta1 paid held
confirmed beta2 paid refunded
dismissed not confirmed refunded

What the Council learns

The Council learns pk_c, a fresh key with no link to a person; the ciphertext and, by threshold decryption, the evidence; and the size of the claim bond. It never learns who the claimant is unless the claimant chooses to prove ownership of pk_c. The ledger learns only H(C) and pk_c.

Security properties and the tests that check them

The tests are in test/bounty/bounty.test.ts.

Property Test
The honest flow pays beta1 on inspection and beta2 on confirmation to pk_c, with beta2 drawn from the slashed bond "pays the honest claimant..."
A front-runner who copies the evidence (re-encrypted, or the same ciphertext under its own key) and commits later loses, and gets only its bond back "a front-runner who copies the evidence and commits later loses"
Ties within an epoch go to the lowest commitment key "breaks a tie within one epoch by the lowest commitment key"
A delivery that does not match its commitment (other key, other ciphertext, wrong epoch) is rejected "rejects a delivery that does not match its commitment"
A delivery before its epoch is anchored is rejected "rejects a delivery before its commitment's epoch is anchored"
A delivery after the claim window is rejected "rejects a delivery after the claim window"
No double payout: repeated orders, confirmations, deliveries and late claims are refused "never pays twice..."
Over arbitrary epochs of commits, deliveries (some tampered) and Council actions: value is conserved (pool + bonds + held claim bonds + paid out = initial + deposits); the pool never goes negative; each evidence digest receives at most one beta1 and one beta2, only to its winner; the winner is the earliest timely commitment, as computed by the test itself; and once there is a winner, no rival is left with its bond stuck "conserves value, pays each evidence at most one beta_1 and one beta_2..." (property)

Interpretations

  • When each tranche is paid. beta1 is paid when the Council orders an inspection, and beta2 on confirmation, following the settlement section. Appendix A says beta1 is paid "on a finding".
  • "Drawn first from the slashed bond." The slashed bond enters the pool when the violation is confirmed. beta2 is recorded as coming from it, up to its size. beta1 precedes any slash, so it comes from the pool.
  • Short pool. If the pool holds less than a tranche, the claimant is paid what the pool holds. The paper does not say what happens.
  • Priority is decided per evidence digest. The paper says only that the anchored commitment fixes priority.

Out of scope

  • Retaliation against claimants, and the protection the treaty promises once a claimant reveals themselves.
  • Evidence authenticity beyond the injected assess. The protocol decides who is paid, not whether the evidence is true.
  • Threshold encryption and decryption of C, which are injected.
  • Censorship of commitments by the ledger operator. A claimant should be able to post through any party that can anchor.

Open questions for the paper's authors

  • Evidence malleability. Priority compares evidence digests. Someone who reads the evidence (a Council member, after decryption) can change one byte and commit it as "new" evidence. That claim cannot win this digest, but it can compete as a separate claim against the same operator. Priority should probably be keyed by (operator, offense) as the Council's assessment identifies them, not by bytes.
  • Several honest claimants with different evidence of one violation. After the first confirmation the operator's bond is gone. The paper does not say whether later claims are paid from the pool.
  • The decision period. The paper gives the Council a fixed period to decide whether to order an inspection. The priority wait (claimWindow epochs) must fit inside it.

Source

The code

src/bounty/commit.ts37 lines
/**
 * The claimant's side: the ledger commitment and the later proof of key ownership.
 */
import { schnorr } from "@noble/curves/secp256k1.js";
import { sha256 } from "@noble/hashes/sha2.js";
import { concatBytes } from "@noble/hashes/utils.js";
import type { Entry } from "../ledger";

/** BIP340 tag for commitment keys. */
export const COMMIT_TAG = "Firebreak/bounty/commit";
/** BIP340 tag for ownership challenges. */
export const OWNER_TAG = "Firebreak/bounty/owner";

/**
 * The ledger entry a claimant posts: value = H(C) || pk_c, key = taggedHash(COMMIT_TAG, value).
 * It reveals nothing about the evidence and nothing that links pk_c to a person.
 */
export function commitmentLeaf(ciphertext: Uint8Array, payoutKey: Uint8Array): Entry {
  if (payoutKey.length !== 32) throw new RangeError("payout key must be a 32-byte x-only key");
  const value = concatBytes(sha256(ciphertext), payoutKey);
  return { key: schnorr.utils.taggedHash(COMMIT_TAG, value), value };
}

/** Signs a challenge with the payout secret key, for a claimant who later reveals themselves to seek protection. */
export function proveOwnership(challenge: Uint8Array, payoutSecret: Uint8Array, auxRand?: Uint8Array): Uint8Array {
  return schnorr.sign(schnorr.utils.taggedHash(OWNER_TAG, challenge), payoutSecret, auxRand);
}

/** Checks a proof of ownership of a payout key. */
export function verifyOwnership(payoutKey: Uint8Array, challenge: Uint8Array, sig: Uint8Array): boolean {
  try {
    return schnorr.verify(sig, schnorr.utils.taggedHash(OWNER_TAG, challenge), payoutKey);
  } catch {
    return false;
  }
}

View on GitHub

src/bounty/machine.ts161 lines
/**
 * The Council's side of the claim protocol, as pure transitions (Appendix A, "Bounty claim protocol").
 *
 *   deliver   C arrives; its commitment (H(C), pk_c) must be in an anchored epoch; the Council
 *             decrypts by threshold and judges the evidence.
 *   find      On a finding, pay beta_1 to pk_c, drawing first on the violator's slashed bond.
 *   slash     The violator's bond is slashed into the pool (adjudicated or cryptographic).
 *   confirm   After the confirming inspection or slash, pay beta_2; return the claim bond.
 *   dismiss   The inspection did not confirm; return the claim bond. No beta_2.
 *
 * Interpretation: priority. The paper states no rule for several claims carrying the same evidence.
 * Here the commitment anchored in the earliest epoch wins, and within one epoch the lowest commitment key
 * (compared as bytes). A claim committed in epoch e may be delivered until epoch e + claimWindow, so the
 * winner is final once the current epoch passes winner.epoch + claimWindow: no earlier commitment can
 * still arrive. A finding is made only then.
 */
import { sha256 } from "@noble/hashes/sha2.js";
import { bytesToHex, hexToBytes } from "@noble/hashes/utils.js";
import { compareBytes, type EpochRecord, linksTo, verifyInclusion } from "../ledger";
import { commitmentLeaf } from "./commit";
import type { Assessment, BountyParams, BountyState, Claim, Delivery, Payout, Step, ThresholdDecryptor } from "./types";

/** The Council's starting state: no epochs, the pool's balance and the operators' bonds. */
export function open(params: BountyParams, pool: bigint, bonds: ReadonlyMap<string, bigint>): BountyState {
  return { params, epochs: [], pool, bonds, slashed: new Map(), claims: new Map(), winners: new Map(), payouts: [] };
}

/** The latest anchored epoch number, or -1 before the first anchor. */
export function currentEpoch(s: BountyState): number {
  return s.epochs.length - 1;
}

/** Records an epoch anchored on Bitcoin; it must chain to the previous anchored record. */
export function anchor(s: BountyState, record: EpochRecord): Step {
  if (!linksTo(s.epochs[s.epochs.length - 1] ?? null, record)) return { ok: false, reason: "not-chained" };
  return { ok: true, state: { ...s, epochs: [...s.epochs, record] } };
}

/**
 * Receives a claimant's delivery: checks the commitment's inclusion in an anchored epoch and the claim
 * window, decrypts the evidence by threshold and records the Council's assessment. The claim bond is
 * held, returned at once if the evidence is unfounded, or forfeited to the pool if it is knowingly false.
 */
export function deliver(s: BountyState, d: Delivery, council: ThresholdDecryptor, assess: (evidence: Uint8Array) => Assessment): Step {
  if (!(d.payoutKey instanceof Uint8Array) || d.payoutKey.length !== 32 || typeof d.claimBond !== "bigint" || d.claimBond < 0n) {
    return { ok: false, reason: "malformed" };
  }
  const record = s.epochs[d.epoch];
  if (!record) return { ok: false, reason: "not-anchored" };
  const leaf = commitmentLeaf(d.ciphertext, d.payoutKey);
  if (!verifyInclusion(record.root, record.size, leaf.key, leaf.value, d.proof)) return { ok: false, reason: "not-included" };
  if (currentEpoch(s) > d.epoch + s.params.claimWindow) return { ok: false, reason: "window-closed" };
  const id = bytesToHex(leaf.key);
  if (s.claims.has(id)) return { ok: false, reason: "duplicate" };
  const evidence = council.decrypt(d.ciphertext);
  if (!evidence) return { ok: false, reason: "undecryptable" };
  const digest = bytesToHex(sha256(evidence));
  if (s.winners.has(digest)) return { ok: false, reason: "already-resolved" };

  const a = assess(evidence);
  const claim: Claim = {
    id,
    epoch: d.epoch,
    payoutKey: d.payoutKey,
    digest,
    operatorId: a.operatorId,
    claimBond: d.claimBond,
    held: d.claimBond,
    stage: a.valid ? "credible" : a.knowinglyFalse ? "false" : "unfounded",
  };
  const next = withClaim(s, claim);
  if (claim.stage === "unfounded") return { ok: true, state: refund(next, claim) };
  if (claim.stage === "false") return { ok: true, state: withClaim({ ...next, pool: next.pool + claim.held }, { ...claim, held: 0n }) };
  return { ok: true, state: next };
}

/**
 * A finding on the evidence with this digest: fixes the priority winner, pays it beta_1 (drawing first on
 * the violator's slashed bond) and orders the confirming inspection. Rival claims are superseded and
 * their bonds returned.
 */
export function find(s: BountyState, digest: string): Step {
  if (s.winners.has(digest)) return { ok: false, reason: "already-resolved" };
  const rivals = [...s.claims.values()].filter((c) => c.digest === digest && c.stage === "credible").sort(byPriority);
  const winner = rivals[0];
  if (!winner) return { ok: false, reason: "no-claim" };
  if (currentEpoch(s) <= winner.epoch + s.params.claimWindow) return { ok: false, reason: "priority-not-final" };

  let next: BountyState = { ...s, winners: new Map(s.winners).set(digest, winner.id) };
  for (const loser of rivals.slice(1)) next = refund(withClaim(next, { ...loser, stage: "superseded" }), loser);
  next = withClaim(next, { ...winner, stage: "found" });
  return { ok: true, state: pay(next, winner, "beta1", s.params.beta1) };
}

/** Slashes an operator's whole bond into the pool, where it is drawn on first for claims against that operator. */
export function slash(s: BountyState, operatorId: string): Step {
  const bond = s.bonds.get(operatorId) ?? 0n;
  if (bond === 0n) return { ok: false, reason: "no-bond" };
  return {
    ok: true,
    state: {
      ...s,
      pool: s.pool + bond,
      bonds: new Map(s.bonds).set(operatorId, 0n),
      slashed: new Map(s.slashed).set(operatorId, (s.slashed.get(operatorId) ?? 0n) + bond),
    },
  };
}

/** The confirming inspection or slash: pay beta_2 (drawing first on the slashed bond) and return the claim bond. */
export function confirm(s: BountyState, digest: string): Step {
  const winner = found(s, digest);
  if (!winner) return { ok: false, reason: "not-found" };
  const next = pay(withClaim(s, { ...winner, stage: "confirmed" }), winner, "beta2", s.params.beta2);
  return { ok: true, state: refund(next, winner) };
}

/** The inspection did not confirm a violation: close the claim and return its bond. No beta_2. */
export function dismiss(s: BountyState, digest: string): Step {
  const winner = found(s, digest);
  if (!winner) return { ok: false, reason: "not-found" };
  return { ok: true, state: refund(withClaim(s, { ...winner, stage: "dismissed" }), winner) };
}

/** Orders claims by priority: earliest epoch, then lowest commitment key (Interpretation; see above). */
export function byPriority(a: Claim, b: Claim): number {
  return a.epoch - b.epoch || compareBytes(hexToBytes(a.id), hexToBytes(b.id));
}

function found(s: BountyState, digest: string): Claim | null {
  const id = s.winners.get(digest);
  const c = id === undefined ? undefined : s.claims.get(id);
  return c && c.stage === "found" ? c : null;
}

function withClaim(s: BountyState, c: Claim): BountyState {
  return { ...s, claims: new Map(s.claims).set(c.id, c) };
}

/** Pays up to `amount` from the pool (never more than it holds), counting the violator's slashed bond first. */
function pay(s: BountyState, c: Claim, kind: "beta1" | "beta2", amount: bigint): BountyState {
  const paid = amount < s.pool ? amount : s.pool;
  const reserve = s.slashed.get(c.operatorId) ?? 0n;
  const fromSlashedBond = paid < reserve ? paid : reserve;
  const payout: Payout = { claimId: c.id, payoutKey: c.payoutKey, kind, amount: paid, fromSlashedBond };
  return {
    ...s,
    pool: s.pool - paid,
    slashed: fromSlashedBond === 0n ? s.slashed : new Map(s.slashed).set(c.operatorId, reserve - fromSlashedBond),
    payouts: [...s.payouts, payout],
  };
}

/** Returns whatever is still held of a claim's bond to its payout key. */
function refund(s: BountyState, c: Claim): BountyState {
  const current = s.claims.get(c.id) ?? c;
  if (current.held === 0n) return s;
  const payout: Payout = { claimId: c.id, payoutKey: c.payoutKey, kind: "bond-refund", amount: current.held, fromSlashedBond: 0n };
  return { ...withClaim(s, { ...current, held: 0n }), payouts: [...s.payouts, payout] };
}

View on GitHub

src/bounty/types.ts124 lines
/**
 * Types for the whistleblower claim protocol (paper Appendix A, "Bounty claim
 * protocol", and the settlement section's "bounty pool and whistleblower protocol").
 */
import type { EpochRecord, InclusionProof } from "../ledger";

/** Parameters from the Technical Annex. */
export interface BountyParams {
  /** Epochs after its commitment's epoch during which a claim may still be delivered. */
  readonly claimWindow: number;
  /** beta_1: the first tranche, paid on a finding. */
  readonly beta1: bigint;
  /** beta_2: the second tranche, paid after the confirming inspection or slash. */
  readonly beta2: bigint;
}

/**
 * Threshold decryption by the Council: a threshold of members jointly decrypts C. Injected, so the protocol
 * does not depend on one scheme; returns null when C is not a valid ciphertext to the Council's key.
 */
export interface ThresholdDecryptor {
  decrypt(ciphertext: Uint8Array): Uint8Array | null;
}

/** The Council's judgment of decrypted evidence. Injected: the protocol does not judge evidence itself. */
export interface Assessment {
  readonly operatorId: string;
  readonly valid: boolean;
  /** Found knowingly false: the claim bond is forfeited to the pool. */
  readonly knowinglyFalse?: boolean;
}

/** What a claimant hands the Council after its commitment is anchored. */
export interface Delivery {
  /** The epoch whose tree includes the commitment. */
  readonly epoch: number;
  readonly proof: InclusionProof;
  /** C: the evidence encrypted to the Council's threshold encryption key. */
  readonly ciphertext: Uint8Array;
  /** pk_c: the claimant's fresh x-only payout key, 32 bytes. */
  readonly payoutKey: Uint8Array;
  /** The optional refundable claim bond c (0 when not funded). */
  readonly claimBond: bigint;
}

/** Where a claim stands. */
export type ClaimStage =
  /** Delivered, decrypted and judged to show a violation; waiting for its priority to be final. */
  | "credible"
  /** Judged not to show a violation, in good faith. */
  | "unfounded"
  /** Judged knowingly false: the claim bond is forfeited. */
  | "false"
  /** Another claim on the same evidence had priority. */
  | "superseded"
  /** The Council made a finding on it (beta_1 paid) and ordered the confirming inspection. */
  | "found"
  /** The inspection or a slash confirmed the violation (beta_2 paid). */
  | "confirmed"
  /** The inspection did not confirm it. */
  | "dismissed";

/** A delivered claim as the Council records it. */
export interface Claim {
  /** The ledger key of the commitment, hex. */
  readonly id: string;
  readonly epoch: number;
  readonly payoutKey: Uint8Array;
  /** SHA-256 of the decrypted evidence, hex. Priority is decided among claims with the same digest. */
  readonly digest: string;
  readonly operatorId: string;
  readonly claimBond: bigint;
  /** The part of the claim bond still held (zero once refunded or forfeited). */
  readonly held: bigint;
  readonly stage: ClaimStage;
}

/** One transfer out of the regime to a claimant's payout key. */
export interface Payout {
  readonly claimId: string;
  readonly payoutKey: Uint8Array;
  readonly kind: "beta1" | "beta2" | "bond-refund";
  readonly amount: bigint;
  /** How much of the amount was drawn from the violator's slashed bond (the rest from the pool). */
  readonly fromSlashedBond: bigint;
}

/** The Council's ledger of claims, bonds and the pool. Every transition returns a new state. */
export interface BountyState {
  readonly params: BountyParams;
  /** Anchored epoch records, epoch i at index i. */
  readonly epochs: readonly EpochRecord[];
  readonly pool: bigint;
  /** Unslashed operator bonds by operator. */
  readonly bonds: ReadonlyMap<string, bigint>;
  /**
   * Slashed bond money now in the pool, by operator, not yet drawn on. A payout on a claim against an
   * operator counts against that operator's slashed bond first.
   */
  readonly slashed: ReadonlyMap<string, bigint>;
  readonly claims: ReadonlyMap<string, Claim>;
  /** Evidence digests that have a priority winner, mapped to the winning claim's id. */
  readonly winners: ReadonlyMap<string, string>;
  readonly payouts: readonly Payout[];
}

/** Why a transition was refused. */
export type BountyRejection =
  | "malformed"
  | "not-chained"
  | "not-anchored"
  | "not-included"
  | "window-closed"
  | "duplicate"
  | "undecryptable"
  | "already-resolved"
  | "no-claim"
  | "priority-not-final"
  | "not-found"
  | "no-bond";

/** The result of a transition: the new state, or the reason it was refused (the old state stands). */
export type Step = { readonly ok: true; readonly state: BountyState } | { readonly ok: false; readonly reason: BountyRejection };

View on GitHub

src/bounty/index.ts18 lines
/**
 * The whistleblower claim protocol: commitment, delivery, finding and payout. See SPEC.md.
 */
export type {
  Assessment,
  BountyParams,
  BountyRejection,
  BountyState,
  Claim,
  ClaimStage,
  Delivery,
  Payout,
  Step,
  ThresholdDecryptor,
} from "./types";
export { COMMIT_TAG, commitmentLeaf, OWNER_TAG, proveOwnership, verifyOwnership } from "./commit";
export { anchor, byPriority, confirm, currentEpoch, deliver, dismiss, find, open, slash } from "./machine";

View on GitHub