Documentation

CslibFrontier.Crypto.Protocols.AnonymousToken.CRTHazard

FAEST v3 CRT witness-reuse hazard and witness-order repair for VOLE-ACT #

This module formalizes the linear-algebraic parity leakage arising when FAEST-style CRT VOLE masks reuse the first lam bits of a prover's witness as Free-XOR garbled-circuit label offsets, together with the Issue-to-Spend and Spend-prefix unlinkability breaks under draft witness ordering and the witness-order repair that places fresh uniform opening randomness first.

In [VOLEACT2026] (Protocol Specification / Initial Issuance and Spending), the Issuance witness is listed as (nf, r) and the Spend witness as (t, r, x, s, nf', t', r'), without mandating witness byte offsets or addressing CRT mask reuse ([VOLEACT2026] #proof-status leaves the unlinkability proof open). When FAEST-style CRT VOLE masks ([BaumEtAl2026FAEST], §§3.1–3.3 pp. 13–18, §6 pp. 35–43 / Figs. 6.1–6.3, and §10.10 Games G6–G11 pp. 115–121 as background) reuse the first lam witness bits as Free-XOR garbled-circuit label offsets, an H5-style garbling mask check compressing nMult gate tables across nMask masks introduces an F : Matrix (Fin nMult) (Fin lam) (ZMod 2) linear map. Whenever F.rank < nMult (in particular whenever lam < nMult), Fᵀ has a nontrivial kernel of dimension at least nMult - lam, exposing linear parity equations satisfied identically by any valid witness prefix and rejecting independent random guesses with probability (2 : ℝ≥0∞)⁻¹ ^ (nMask * r) across r independent parity checks (for example, nMult = 312, lam = 128, nMask = 12, r = 14, kGates = 27 in illustrative CRT parameters; FAEST-128s uses nmult = 312 and nmask = dzk + 3).

This formalization, its matrix bounds, random-oracle H5 distinguishers, query bounds, unlinkability games, and witness-order repair statements are original to this library as finite, query-bounded steps (#7068); asymptotic PPT certificates and concrete circuit lookup tables are outside this module's scope. Empty/zero-width parameterizations (nMask = 0, rSub = 0, or nMult ≤ lam) are admitted and degenerate to trivial 0 ≤ advantage or 0 ≤ leftKernelDim bounds.

Main definitions #

Main results #

References #

Uniform parity rejection over surjective parity-check matrices #

Pushing a uniform input vector through a surjective matrix gives the uniform output law.

theorem Cslib.Crypto.AnonymousToken.CRTHazard.multiMask_parityCheck_map_uniformOfFintype {K : Type u_1} [Field K] {m r : ℕ} [Fintype K] {nMask : ℕ} {H : Matrix (Fin r) (Fin m) K} (hsurj : Function.Surjective ⇑H.mulVecLin) :
PMF.map (fun (y : Fin nMask → Fin m → K) (mask : Fin nMask) => H.mulVec (y mask)) (Probability.PMF.uniformOfFintype (Fin nMask → Fin m → K)) = Probability.PMF.uniformOfFintype (Fin nMask → Fin r → K)

Pushing nMask i.i.d. uniform vectors through a surjective matrix gives nMask i.i.d. uniform syndromes.

theorem Cslib.Crypto.AnonymousToken.CRTHazard.parityCheck_uniform_zero_prob {K : Type u_1} [Field K] {m r : ℕ} [Fintype K] [DecidableEq K] {H : Matrix (Fin r) (Fin m) K} (hsurj : Function.Surjective ⇑H.mulVecLin) :
(PMF.map (fun (y : Fin m → K) => decide (H.mulVec y = 0)) (Probability.PMF.uniformOfFintype (Fin m → K))) true = (↑(Fintype.card K))⁻¹ ^ r

A uniform vector passes r independent parity checks with probability (|K|⁻¹) ^ r.

theorem Cslib.Crypto.AnonymousToken.CRTHazard.multiMask_parityCheck_uniform_zero_prob {m r nMask : ℕ} {H : Matrix (Fin r) (Fin m) (ZMod 2)} (hsurj : Function.Surjective ⇑H.mulVecLin) :
(PMF.map (fun (y : Fin nMask → Fin m → ZMod 2) => decide (∀ (mask : Fin nMask), H.mulVec (y mask) = 0)) (Probability.PMF.uniformOfFintype (Fin nMask → Fin m → ZMod 2))) true = 2⁻¹ ^ (nMask * r)

Across nMask i.i.d. uniform vectors over ZMod 2, all nMask * r parity checks pass simultaneously with probability 2⁻¹ ^ (nMask * r).

CRT garbled mask tables and query-bounded H5 distinguishers #

Query record for the H5 random oracle (iv, gate, label) ↦ maskBits.

  • iv : IV

    Per-proof initialization vector iv.

  • gate : Fin nMult

    CRT multiplication gate index e.

  • label : Fin lam → ZMod 2

    Candidate Free-XOR wire label L.

Instances For
    @[instance_reducible]
    instance Cslib.Crypto.AnonymousToken.CRTHazard.instDecidableEqH5Query {IV✝ : Type} {nMult✝ lam✝ : ℕ} [DecidableEq IV✝] :
    DecidableEq (H5Query IV✝ nMult✝ lam✝)
    def Cslib.Crypto.AnonymousToken.CRTHazard.instDecidableEqH5Query.decEq {IV✝ : Type} {nMult✝ lam✝ : ℕ} [DecidableEq IV✝] (x✝ x✝¹ : H5Query IV✝ nMult✝ lam✝) :
    Decidable (x✝ = x✝¹)
    def Cslib.Crypto.AnonymousToken.CRTHazard.H5Query.equivProd (IV : Type) (nMult lam : ℕ) :
    H5Query IV nMult lam ≃ IV × Fin nMult × (Fin lam → ZMod 2)

    Equivalence between H5Query and its flat tuple, for Fintype enumeration.

    @[instance_reducible]
    instance Cslib.Crypto.AnonymousToken.CRTHazard.instFintypeH5Query (IV : Type) [Fintype IV] (nMult lam : ℕ) :
    Fintype (H5Query IV nMult lam)
    @[reducible, inline]
    abbrev Cslib.Crypto.AnonymousToken.CRTHazard.H5Spec (IV : Type) (nMult lam nMask : ℕ) :
    OracleSpec (H5Query IV nMult lam)

    Oracle specification for H5.

    structure Cslib.Crypto.AnonymousToken.CRTHazard.CRTMaskTable (IV : Type) (nMult lam nMask : ℕ) :

    A CRT garbled mask table generated under witness prefix wPrefix.

    • iv : IV

      Per-proof initialization vector iv.

    • activeLabel : Fin nMult → Fin lam → ZMod 2

      Verifier-reconstructed active Free-XOR label L'_e for each gate e.

    • dPrefix : Fin lam → ZMod 2

      Prefix correction string d[0..lam) = w[0..lam) ⊕ u[0..lam).

    • cmult : Fin nMask → Fin nMult → ZMod 2

      Encrypted CRT multiplication-mask rows cmult[m, e].

    def Cslib.Crypto.AnonymousToken.CRTHazard.honestCRTMaskTable {IV : Type} {nMult lam nMask : ℕ} (iv : IV) (L0 : Fin nMult → Fin lam → ZMod 2) (uPrefix wPrefix : Fin lam → ZMod 2) (active : Fin nMult → Bool) (F : Matrix (Fin nMult) (Fin lam) (ZMod 2)) (maskInput : Fin nMask → Fin lam → ZMod 2) (h5 : H5Query IV nMult lam → Fin nMask → ZMod 2) :
    CRTMaskTable IV nMult lam nMask

    Construct an honest CRT mask table from zero-labels L0, offset uPrefix, witness prefix wPrefix, active gate bits active, CRT gate matrix F, mask inputs maskInput, and H5.

    def Cslib.Crypto.AnonymousToken.CRTHazard.candidateLabel {IV : Type} {nMult lam nMask : ℕ} (tbl : CRTMaskTable IV nMult lam nMask) (wStar : Fin lam → ZMod 2) (e : Fin nMult) :
    Fin lam → ZMod 2

    Candidate complementary Free-XOR label derived from tbl and prefix guess wStar.

    theorem Cslib.Crypto.AnonymousToken.CRTHazard.honestCRTMaskTable_reconstruct_true {IV : Type} {nMult lam nMask : ℕ} (iv : IV) (L0 : Fin nMult → Fin lam → ZMod 2) (uPrefix wPrefix : Fin lam → ZMod 2) (active : Fin nMult → Bool) (F : Matrix (Fin nMult) (Fin lam) (ZMod 2)) (maskInput : Fin nMask → Fin lam → ZMod 2) (h5 : H5Query IV nMult lam → Fin nMask → ZMod 2) (mask : Fin nMask) (e : Fin nMult) :
    have tbl := honestCRTMaskTable iv L0 uPrefix wPrefix active F maskInput h5; tbl.cmult mask e + h5 { iv := iv, gate := e, label := tbl.activeLabel e } mask + h5 { iv := iv, gate := e, label := candidateLabel tbl wPrefix e } mask = F.mulVec (maskInput mask) e

    For wStar = wPrefix, the candidate label equals the complementary label of honestCRTMaskTable, so active and candidate H5 values recover F *ᵥ maskInput mask exactly.

    theorem Cslib.Crypto.AnonymousToken.CRTHazard.candidateLabel_ne_of_ne {IV : Type} {nMult lam nMask : ℕ} (iv : IV) (L0 : Fin nMult → Fin lam → ZMod 2) (uPrefix wPrefix wStar : Fin lam → ZMod 2) (active : Fin nMult → Bool) (F : Matrix (Fin nMult) (Fin lam) (ZMod 2)) (maskInput : Fin nMask → Fin lam → ZMod 2) (h5 : H5Query IV nMult lam → Fin nMask → ZMod 2) (hne : wStar ≠ wPrefix) (hnonzero : (honestCRTMaskTable iv L0 uPrefix wPrefix active F maskInput h5).dPrefix + wStar ≠ 0) (e : Fin nMult) :
    have tbl := honestCRTMaskTable iv L0 uPrefix wPrefix active F maskInput h5; candidateLabel tbl wStar e ≠ L0 e ∧ candidateLabel tbl wStar e ≠ L0 e + uPrefix

    Whenever a guess wStar ≠ wPrefix and tbl.dPrefix + wStar ≠ 0, its candidate label differs from both L0 e and L0 e + uPrefix at every gate e.

    def Cslib.Crypto.AnonymousToken.CRTHazard.crtPrefixEval {IV : Type} {nMult lam nMask kGates rSub : ℕ} (sub : Fin kGates ↪ Fin nMult) (Hsub : Matrix (Fin rSub) (Fin kGates) (ZMod 2)) (tbl : CRTMaskTable IV nMult lam nMask) (hActive : Fin kGates → Fin nMask → ZMod 2) (h5 : H5Query IV nMult lam → Fin nMask → ZMod 2) (wStar : Fin lam → ZMod 2) :

    Deterministic parity evaluation of a candidate prefix wStar against kGates subcircuit gates given an H5 oracle function.

    def Cslib.Crypto.AnonymousToken.CRTHazard.crtPrefixTest {IV : Type} {nMult lam nMask kGates rSub : ℕ} (sub : Fin kGates ↪ Fin nMult) (Hsub : Matrix (Fin rSub) (Fin kGates) (ZMod 2)) (tbl : CRTMaskTable IV nMult lam nMask) (hActive : Fin kGates → Fin nMask → ZMod 2) (wStar : Fin lam → ZMod 2) :
    ProbOracleComp (H5Spec IV nMult lam nMask) Bool

    The kGates-query H5 prefix distinguisher: queries H5 on each gate sub i with candidate label candidateLabel tbl wStar (sub i) and checks all nMask * rSub parities.

    theorem Cslib.Crypto.AnonymousToken.CRTHazard.crtPrefixTest_isQueryBounded {IV : Type} {nMult lam nMask kGates rSub : ℕ} (sub : Fin kGates ↪ Fin nMult) (Hsub : Matrix (Fin rSub) (Fin kGates) (ZMod 2)) (tbl : CRTMaskTable IV nMult lam nMask) (hActive : Fin kGates → Fin nMask → ZMod 2) (wStar : Fin lam → ZMod 2) :
    (crtPrefixTest sub Hsub tbl hActive wStar).IsQueryBounded kGates

    crtPrefixTest makes at most kGates queries to H5.

    theorem Cslib.Crypto.AnonymousToken.CRTHazard.crtPrefixTest_run {IV : Type} {nMult lam nMask kGates rSub : ℕ} (sub : Fin kGates ↪ Fin nMult) (Hsub : Matrix (Fin rSub) (Fin kGates) (ZMod 2)) (tbl : CRTMaskTable IV nMult lam nMask) (hActive : Fin kGates → Fin nMask → ZMod 2) (h5 : H5Query IV nMult lam → Fin nMask → ZMod 2) (wStar : Fin lam → ZMod 2) :
    ((crtPrefixTest sub Hsub tbl hActive wStar).run fun (q : H5Query IV nMult lam) => pure (h5 q)) = pure (crtPrefixEval sub Hsub tbl hActive h5 wStar)

    Deterministic execution of crtPrefixTest against h5 computes crtPrefixEval.

    theorem Cslib.Crypto.AnonymousToken.CRTHazard.crtPrefixTest_honest_true {IV : Type} {nMult lam nMask kGates rSub : ℕ} (sub : Fin kGates ↪ Fin nMult) (Hsub : Matrix (Fin rSub) (Fin kGates) (ZMod 2)) (F : Matrix (Fin nMult) (Fin lam) (ZMod 2)) (hHF : Hsub * F.submatrix (⇑sub) id = 0) (iv : IV) (L0 : Fin nMult → Fin lam → ZMod 2) (uPrefix wPrefix : Fin lam → ZMod 2) (active : Fin nMult → Bool) (maskInput : Fin nMask → Fin lam → ZMod 2) (h5 : H5Query IV nMult lam → Fin nMask → ZMod 2) :
    have tbl := honestCRTMaskTable iv L0 uPrefix wPrefix active F maskInput h5; have hActive := fun (i : Fin kGates) => h5 { iv := iv, gate := sub i, label := tbl.activeLabel (sub i) }; ((crtPrefixTest sub Hsub tbl hActive wPrefix).run fun (q : H5Query IV nMult lam) => pure (h5 q)).eval = PMF.pure true

    Completeness: on the true witness prefix wPrefix, crtPrefixTest accepts with probability 1 under any H5 function provided Hsub annihilates F.submatrix sub id.

    theorem Cslib.Crypto.AnonymousToken.CRTHazard.crtPrefixTest_wrong_guess_prob {IV : Type} [Fintype IV] [DecidableEq IV] {nMult lam nMask kGates rSub : ℕ} (sub : Fin kGates ↪ Fin nMult) (Hsub : Matrix (Fin rSub) (Fin kGates) (ZMod 2)) (hsurj : Function.Surjective ⇑Hsub.mulVecLin) (iv : IV) (L0 : Fin nMult → Fin lam → ZMod 2) (uPrefix wPrefix wStar : Fin lam → ZMod 2) (active : Fin nMult → Bool) (F : Matrix (Fin nMult) (Fin lam) (ZMod 2)) (maskInput : Fin nMask → Fin lam → ZMod 2) (hne : wStar ≠ wPrefix) (hnonzero : wPrefix + uPrefix + wStar ≠ 0) :
    ((Probability.PMF.uniformOfFintype (H5Query IV nMult lam → Fin nMask → ZMod 2)).bind fun (h5 : H5Query IV nMult lam → Fin nMask → ZMod 2) => have tbl := honestCRTMaskTable iv L0 uPrefix wPrefix active F maskInput h5; have hActive := fun (i : Fin kGates) => h5 { iv := iv, gate := sub i, label := tbl.activeLabel (sub i) }; ((crtPrefixTest sub Hsub tbl hActive wStar).run fun (q : H5Query IV nMult lam) => pure (h5 q)).eval) true = 2⁻¹ ^ (nMask * rSub)

    Soundness against wrong guesses: in the uniform H5 random-oracle model, conditioned on fixed non-queried entries (outside the candidate labels), a wrong guess wStar ≠ wPrefix with dPrefix + wStar ≠ 0 passes all nMask * rSub parity checks with probability 2⁻¹ ^ (nMask * rSub).

    Issue-to-Spend & Spend-prefix unlinkability breaks, and r-first repair #

    noncomputable def Cslib.Crypto.AnonymousToken.CRTHazard.crtIssueSpendGame {IV : Type} [Fintype IV] [DecidableEq IV] {nMult lam nMask kGates : ℕ} (sub : Fin kGates ↪ Fin nMult) (iv₀ iv₁ : IV) (L0₀ L0₁ : Fin nMult → Fin lam → ZMod 2) (active₀ active₁ : Fin nMult → Bool) (F : Matrix (Fin nMult) (Fin lam) (ZMod 2)) (maskInput₀ maskInput₁ : Fin nMask → Fin lam → ZMod 2) (nf₀ nf₁ : Fin lam → ZMod 2) (A : CRTMaskTable IV nMult lam nMask → (Fin kGates → Fin nMask → ZMod 2) → CRTMaskTable IV nMult lam nMask → (Fin kGates → Fin nMask → ZMod 2) → (Fin lam → ZMod 2) → ProbOracleComp (H5Spec IV nMult lam nMask) Bool) (b : Bool) :

    The Issue-to-Spend prefix-leakage experiment when nf sits in the first lam bits of the issuance witness: two distinct nullifiers nf₀ ≠ nf₁ are issued using random u₀, u₁ and H5; then nf_b (nf₀ when b = false, nf₁ when b = true) is revealed to the adversary together with both issuance CRT tables and verifier active-label hashes.

    def Cslib.Crypto.AnonymousToken.CRTHazard.crtIssueSpendAdversary {IV : Type} {nMult lam nMask kGates rSub : ℕ} (sub : Fin kGates ↪ Fin nMult) (Hsub : Matrix (Fin rSub) (Fin kGates) (ZMod 2)) :
    CRTMaskTable IV nMult lam nMask → (Fin kGates → Fin nMask → ZMod 2) → CRTMaskTable IV nMult lam nMask → (Fin kGates → Fin nMask → ZMod 2) → (Fin lam → ZMod 2) → ProbOracleComp (H5Spec IV nMult lam nMask) Bool

    The kGates-query Issue-to-Spend distinguisher testing the revealed spend nullifier nf against client 0's issuance CRT table tbl₀.

    theorem Cslib.Crypto.AnonymousToken.CRTHazard.crtIssueSpendAdversary_isQueryBounded {IV : Type} {nMult lam nMask kGates rSub : ℕ} (sub : Fin kGates ↪ Fin nMult) (Hsub : Matrix (Fin rSub) (Fin kGates) (ZMod 2)) (tbl₀ : CRTMaskTable IV nMult lam nMask) (hAct₀ : Fin kGates → Fin nMask → ZMod 2) (tbl₁ : CRTMaskTable IV nMult lam nMask) (hAct₁ : Fin kGates → Fin nMask → ZMod 2) (nf : Fin lam → ZMod 2) :
    (crtIssueSpendAdversary sub Hsub tbl₀ hAct₀ tbl₁ hAct₁ nf).IsQueryBounded kGates

    crtIssueSpendAdversary makes at most kGates queries to H5.

    theorem Cslib.Crypto.AnonymousToken.CRTHazard.crtIssueSpendAdversary_advantage_ge {IV : Type} [Fintype IV] [DecidableEq IV] {nMult lam nMask kGates rSub : ℕ} (sub : Fin kGates ↪ Fin nMult) (Hsub : Matrix (Fin rSub) (Fin kGates) (ZMod 2)) (F : Matrix (Fin nMult) (Fin lam) (ZMod 2)) (hHF : Hsub * F.submatrix (⇑sub) id = 0) (hsurj : Function.Surjective ⇑Hsub.mulVecLin) (iv₀ iv₁ : IV) (L0₀ L0₁ : Fin nMult → Fin lam → ZMod 2) (active₀ active₁ : Fin nMult → Bool) (maskInput₀ maskInput₁ : Fin nMask → Fin lam → ZMod 2) {nf₀ nf₁ : Fin lam → ZMod 2} (hne : nf₁ ≠ nf₀) :
    have g := crtIssueSpendGame sub iv₀ iv₁ L0₀ L0₁ active₀ active₁ F maskInput₀ maskInput₁ nf₀ nf₁ (crtIssueSpendAdversary sub Hsub); 1 - (2⁻¹ ^ (nMask * rSub) + 2⁻¹ ^ lam) ≤ ↑((g false).advantage (g true))

    Issue-to-Spend CRT prefix break: whenever nf₀ ≠ nf₁ and Hsub * (F.submatrix sub id) = 0 with surjective Hsub.mulVecLin, crtIssueSpendAdversary accepts b = false with probability 1 and accepts b = true with probability at most (2⁻¹) ^ (nMask * rSub) + (2⁻¹) ^ lam, achieving two-world advantage at least 1 - ((2⁻¹) ^ (nMask * rSub) + (2⁻¹) ^ lam).

    def Cslib.Crypto.AnonymousToken.CRTHazard.packBalancePrefix {wBal wRand : ℕ} (tBits : Fin wBal → ZMod 2) (rBits : Fin wRand → ZMod 2) :
    Fin (wBal + wRand) → ZMod 2

    Pack a wBal-bit balance prefix tBits and a wRand-bit randomness slice rBits into (wBal + wRand) CRT witness prefix bits.

    theorem Cslib.Crypto.AnonymousToken.CRTHazard.packBalancePrefix_inj_left {wBal wRand : ℕ} {t₀ t₁ : Fin wBal → ZMod 2} {r₀ r₁ : Fin wRand → ZMod 2} (h : packBalancePrefix t₀ r₀ = packBalancePrefix t₁ r₁) :
    t₀ = t₁

    Left-injectivity of packBalancePrefix: equal encodings imply t₀ = t₁.

    def Cslib.Crypto.AnonymousToken.CRTHazard.crtSpendPrefixTest {IV : Type} {nMult lam nMask kGates rSub : ℕ} (sub : Fin kGates ↪ Fin nMult) (Hsub : Matrix (Fin rSub) (Fin kGates) (ZMod 2)) (tbl : CRTMaskTable IV nMult lam nMask) (hActive : Fin kGates → Fin nMask → ZMod 2) :
    List (Fin lam → ZMod 2) → ProbOracleComp (H5Spec IV nMult lam nMask) Bool

    Exhaustive Spend-prefix parity test across a list of lam-bit prefix guesses guesses.

    theorem Cslib.Crypto.AnonymousToken.CRTHazard.crtSpendPrefixTest_isQueryBounded {IV : Type} {nMult lam nMask kGates rSub : ℕ} (sub : Fin kGates ↪ Fin nMult) (Hsub : Matrix (Fin rSub) (Fin kGates) (ZMod 2)) (tbl : CRTMaskTable IV nMult lam nMask) (hActive : Fin kGates → Fin nMask → ZMod 2) (guesses : List (Fin lam → ZMod 2)) :
    (crtSpendPrefixTest sub Hsub tbl hActive guesses).IsQueryBounded (guesses.length * kGates)

    crtSpendPrefixTest issues at most guesses.length * kGates H5 queries.

    theorem Cslib.Crypto.AnonymousToken.CRTHazard.crtSpendPrefixTest_run {IV : Type} {nMult lam nMask kGates rSub : ℕ} (sub : Fin kGates ↪ Fin nMult) (Hsub : Matrix (Fin rSub) (Fin kGates) (ZMod 2)) (tbl : CRTMaskTable IV nMult lam nMask) (hActive : Fin kGates → Fin nMask → ZMod 2) (h5 : H5Query IV nMult lam → Fin nMask → ZMod 2) (guesses : List (Fin lam → ZMod 2)) :
    ((crtSpendPrefixTest sub Hsub tbl hActive guesses).run fun (q : H5Query IV nMult lam) => pure (h5 q)) = pure (guesses.any fun (w : Fin lam → ZMod 2) => crtPrefixEval sub Hsub tbl hActive h5 w)

    Deterministic execution of crtSpendPrefixTest returns guesses.any (crtPrefixEval ...).

    noncomputable def Cslib.Crypto.AnonymousToken.CRTHazard.balancePrefixGuesses (wBal wRand : ℕ) (tStar : Fin wBal → ZMod 2) :
    List (Fin (wBal + wRand) → ZMod 2)

    Enumerate all 2 ^ wRand guesses packBalancePrefix tStar r in deterministic order.

    @[simp]
    theorem Cslib.Crypto.AnonymousToken.CRTHazard.length_balancePrefixGuesses (wBal wRand : ℕ) (tStar : Fin wBal → ZMod 2) :
    (balancePrefixGuesses wBal wRand tStar).length = 2 ^ wRand

    balancePrefixGuesses wBal wRand tStar has length 2 ^ wRand.

    theorem Cslib.Crypto.AnonymousToken.CRTHazard.mem_balancePrefixGuesses {wBal wRand : ℕ} (tStar : Fin wBal → ZMod 2) (r : Fin wRand → ZMod 2) :
    packBalancePrefix tStar r ∈ balancePrefixGuesses wBal wRand tStar

    Every packBalancePrefix tStar r is listed in balancePrefixGuesses wBal wRand tStar.

    theorem Cslib.Crypto.AnonymousToken.CRTHazard.mem_balancePrefixGuesses_ne {wBal wRand : ℕ} {tStar tReal : Fin wBal → ZMod 2} (hne : tStar ≠ tReal) (rReal : Fin wRand → ZMod 2) (w : Fin (wBal + wRand) → ZMod 2) :
    w ∈ balancePrefixGuesses wBal wRand tStar → w ≠ packBalancePrefix tReal rReal

    Candidates in balancePrefixGuesses wBal wRand tStar are disjoint from packBalancePrefix tReal rReal whenever tStar ≠ tReal.

    theorem Cslib.Crypto.AnonymousToken.CRTHazard.crtSpendPrefixTest_correct {IV : Type} {nMult wBal wRand nMask kGates rSub : ℕ} (sub : Fin kGates ↪ Fin nMult) (Hsub : Matrix (Fin rSub) (Fin kGates) (ZMod 2)) (F : Matrix (Fin nMult) (Fin (wBal + wRand)) (ZMod 2)) (hHF : Hsub * F.submatrix (⇑sub) id = 0) (iv : IV) (L0 : Fin nMult → Fin (wBal + wRand) → ZMod 2) (uPrefix : Fin (wBal + wRand) → ZMod 2) (tReal : Fin wBal → ZMod 2) (rReal : Fin wRand → ZMod 2) (active : Fin nMult → Bool) (maskInput : Fin nMask → Fin (wBal + wRand) → ZMod 2) (h5 : H5Query IV nMult (wBal + wRand) → Fin nMask → ZMod 2) :
    have wPrefix := packBalancePrefix tReal rReal; have tbl := honestCRTMaskTable iv L0 uPrefix wPrefix active F maskInput h5; have hActive := fun (i : Fin kGates) => h5 { iv := iv, gate := sub i, label := tbl.activeLabel (sub i) }; ((crtSpendPrefixTest sub Hsub tbl hActive (balancePrefixGuesses wBal wRand tReal)).run fun (q : H5Query IV nMult (wBal + wRand)) => pure (h5 q)).eval = PMF.pure true

    When tStar = tReal, crtSpendPrefixTest over balancePrefixGuesses succeeds with probability 1 in at most 2 ^ wRand * kGates queries.

    theorem Cslib.Crypto.AnonymousToken.CRTHazard.crtSpendPrefixTest_wrong_t_le {IV : Type} [Fintype IV] [DecidableEq IV] {nMult wBal wRand nMask kGates rSub : ℕ} (sub : Fin kGates ↪ Fin nMult) (Hsub : Matrix (Fin rSub) (Fin kGates) (ZMod 2)) (hsurj : Function.Surjective ⇑Hsub.mulVecLin) (iv : IV) (L0 : Fin nMult → Fin (wBal + wRand) → ZMod 2) (tReal : Fin wBal → ZMod 2) (rReal : Fin wRand → ZMod 2) (active : Fin nMult → Bool) (F : Matrix (Fin nMult) (Fin (wBal + wRand)) (ZMod 2)) (maskInput : Fin nMask → Fin (wBal + wRand) → ZMod 2) (guesses : List (Fin (wBal + wRand) → ZMod 2)) (hguesses : ∀ w ∈ guesses, w ≠ packBalancePrefix tReal rReal) :
    ((Probability.PMF.uniformOfFintype (H5Query IV nMult (wBal + wRand) → Fin nMask → ZMod 2)).bind fun (h5 : H5Query IV nMult (wBal + wRand) → Fin nMask → ZMod 2) => (Probability.PMF.uniformOfFintype (Fin (wBal + wRand) → ZMod 2)).bind fun (uPrefix : Fin (wBal + wRand) → ZMod 2) => have wPrefix := packBalancePrefix tReal rReal; have tbl := honestCRTMaskTable iv L0 uPrefix wPrefix active F maskInput h5; have hActive := fun (i : Fin kGates) => h5 { iv := iv, gate := sub i, label := tbl.activeLabel (sub i) }; ((crtSpendPrefixTest sub Hsub tbl hActive guesses).run fun (q : H5Query IV nMult (wBal + wRand)) => pure (h5 q)).eval) true ≤ ↑guesses.length * (2⁻¹ ^ (nMask * rSub) + 2⁻¹ ^ (wBal + wRand))

    When tReal differs from every balance candidate in guesses, a crtSpendPrefixTest scan false-accepts with probability at most guesses.length * ((2⁻¹) ^ (nMask * rSub) + (2⁻¹) ^ (wBal + wRand)) in the random uPrefix + H5 model.

    noncomputable def Cslib.Crypto.AnonymousToken.CRTHazard.crtSpendBalancePrefixGame {IV : Type} [Fintype IV] [DecidableEq IV] {nMult wBal wRand nMask kGates rSub : ℕ} (sub : Fin kGates ↪ Fin nMult) (Hsub : Matrix (Fin rSub) (Fin kGates) (ZMod 2)) (iv : IV) (L0 : Fin nMult → Fin (wBal + wRand) → ZMod 2) (active : Fin nMult → Bool) (F : Matrix (Fin nMult) (Fin (wBal + wRand)) (ZMod 2)) (maskInput : Fin nMask → Fin (wBal + wRand) → ZMod 2) (t₀ t₁ : Fin wBal → ZMod 2) (rReal : Fin wRand → ZMod 2) (b : Bool) :

    Spend-balance CRT prefix experiment: two distinct candidate balances t₀ ≠ t₁ pack into the leading wBal bits of (t_b, r) (wBal + wRand prefix bits), and the distinguisher receives the resulting Spend CRT table and tests t₀ by enumerating all 2 ^ wRand trailing randomness slices.

    theorem Cslib.Crypto.AnonymousToken.CRTHazard.crtSpendBalancePrefix_advantage_ge {IV : Type} [Fintype IV] [DecidableEq IV] {nMult wBal wRand nMask kGates rSub : ℕ} (sub : Fin kGates ↪ Fin nMult) (Hsub : Matrix (Fin rSub) (Fin kGates) (ZMod 2)) (F : Matrix (Fin nMult) (Fin (wBal + wRand)) (ZMod 2)) (hHF : Hsub * F.submatrix (⇑sub) id = 0) (hsurj : Function.Surjective ⇑Hsub.mulVecLin) (iv : IV) (L0 : Fin nMult → Fin (wBal + wRand) → ZMod 2) (active : Fin nMult → Bool) (maskInput : Fin nMask → Fin (wBal + wRand) → ZMod 2) {t₀ t₁ : Fin wBal → ZMod 2} (hne : t₀ ≠ t₁) (rReal : Fin wRand → ZMod 2) :
    have g := crtSpendBalancePrefixGame sub Hsub iv L0 active F maskInput t₀ t₁ rReal; 1 - 2 ^ wRand * (2⁻¹ ^ (nMask * rSub) + 2⁻¹ ^ (wBal + wRand)) ≤ ↑((g false).advantage (g true))

    When t₀ ≠ t₁, testing balancePrefixGuesses wBal wRand t₀ (2 ^ wRand * kGates H5 queries) accepts b = false with probability 1 and false-accepts b = true with probability at most 2 ^ wRand * ((2⁻¹) ^ (nMask * rSub) + (2⁻¹) ^ (wBal + wRand)).

    noncomputable def Cslib.Crypto.AnonymousToken.CRTHazard.rFirstCRTMaskView {IV Meta : Type} {nMult lam nMask : ℕ} (iv : IV) (L0 : Fin nMult → Fin lam → ZMod 2) (active : Fin nMult → Bool) (F : Matrix (Fin nMult) (Fin lam) (ZMod 2)) (maskInput : Meta → Fin nMask → Fin lam → ZMod 2) (metaData : Meta) :
    PMF (CRTMaskTable IV nMult lam nMask)

    Witness-order repair view (in the witness-reuse CRT mode that reuses the witness prefix as the CRT mask offset, placing fresh uniform opening r at bytes 0..lam and H5 unqueried on complementary labels): given public L0 and active, the uniform opening r, uniform VOLE secret u, and uniform H5 mask padding hXor produce dPrefix := r + u and cmult shifted by F *ᵥ maskInput metaData.

    noncomputable def Cslib.Crypto.AnonymousToken.CRTHazard.rFirstDecoupledView {IV : Type} {nMult lam nMask : ℕ} (iv : IV) (activeLabel : Fin nMult → Fin lam → ZMod 2) :
    PMF (CRTMaskTable IV nMult lam nMask)

    Idealized decoupled CRT table distribution (G8.5, this library's intermediate hop between FAEST v3.0 Theorem 10.42's G8 and G9 in [BBB+26c]) with uniform dPrefix and cmult, independent of the witness opening r.

    theorem Cslib.Crypto.AnonymousToken.CRTHazard.rFirstCRTMaskView_eq_decoupled {IV Meta : Type} {nMult lam nMask : ℕ} (iv : IV) (L0 : Fin nMult → Fin lam → ZMod 2) (active : Fin nMult → Bool) (F : Matrix (Fin nMult) (Fin lam) (ZMod 2)) (maskInput : Meta → Fin nMask → Fin lam → ZMod 2) (metaData : Meta) :
    rFirstCRTMaskView iv L0 active F maskInput metaData = (Probability.PMF.uniformOfFintype (Fin lam → ZMod 2)).bind fun (u : Fin lam → ZMod 2) => rFirstDecoupledView iv fun (e : Fin nMult) => if active e = true then L0 e + u else L0 e

    When H5 answers on active and complementary labels are uniform and fresh uniform opening r is placed first, both r ↦ r + u and hXor ↦ hXor + F *ᵥ maskInput metaData are uniform bijections, so rFirstCRTMaskView equals (uniformOfFintype _).bind (fun u => rFirstDecoupledView ...), completely decoupling (dPrefix, cmult) from u and metaData.

    theorem Cslib.Crypto.AnonymousToken.CRTHazard.rFirstCRTMaskView_eq {IV Meta : Type} {nMult lam nMask : ℕ} (iv : IV) (L0 : Fin nMult → Fin lam → ZMod 2) (active : Fin nMult → Bool) (F : Matrix (Fin nMult) (Fin lam) (ZMod 2)) (maskInput : Meta → Fin nMask → Fin lam → ZMod 2) (meta₀ meta₁ : Meta) :
    rFirstCRTMaskView iv L0 active F maskInput meta₀ = rFirstCRTMaskView iv L0 active F maskInput meta₁

    Corollary: rFirstCRTMaskView is identically distributed across arbitrary semantic metadata meta₀ and meta₁ once r is placed first and H5 answers are unqueried.

    theorem Cslib.Crypto.AnonymousToken.CRTHazard.rFirst_breaks_witnessKnowingZK {IV : Type} [Fintype IV] [DecidableEq IV] {nMult lam nMask kGates rSub : ℕ} (sub : Fin kGates ↪ Fin nMult) (Hsub : Matrix (Fin rSub) (Fin kGates) (ZMod 2)) (F : Matrix (Fin nMult) (Fin lam) (ZMod 2)) (hHF : Hsub * F.submatrix (⇑sub) id = 0) (hsurj : Function.Surjective ⇑Hsub.mulVecLin) (iv : IV) (L0 : Fin nMult → Fin lam → ZMod 2) (uPrefix r : Fin lam → ZMod 2) (active : Fin nMult → Bool) (maskInput : Fin nMask → Fin lam → ZMod 2) :
    have gReal := (Probability.PMF.uniformOfFintype (H5Query IV nMult lam → Fin nMask → ZMod 2)).bind fun (h5 : H5Query IV nMult lam → Fin nMask → ZMod 2) => have tbl := honestCRTMaskTable iv L0 uPrefix r active F maskInput h5; have hActive := fun (i : Fin kGates) => h5 { iv := iv, gate := sub i, label := tbl.activeLabel (sub i) }; ((crtPrefixTest sub Hsub tbl hActive r).run fun (q : H5Query IV nMult lam) => pure (h5 q)).eval; have gSim := (Probability.PMF.uniformOfFintype (Fin nMask → Fin nMult → ZMod 2)).bind fun (cmultSim : Fin nMask → Fin nMult → ZMod 2) => (Probability.PMF.uniformOfFintype (Fin lam → ZMod 2)).bind fun (dSim : Fin lam → ZMod 2) => (Probability.PMF.uniformOfFintype (H5Query IV nMult lam → Fin nMask → ZMod 2)).bind fun (h5 : H5Query IV nMult lam → Fin nMask → ZMod 2) => have actL := fun (e : Fin nMult) => if active e = true then L0 e + uPrefix else L0 e; have tbl := { iv := iv, activeLabel := actL, dPrefix := dSim, cmult := cmultSim }; have hActive := fun (i : Fin kGates) => h5 { iv := iv, gate := sub i, label := actL (sub i) }; ((crtPrefixTest sub Hsub tbl hActive r).run fun (q : H5Query IV nMult lam) => pure (h5 q)).eval; 1 - 2⁻¹ ^ (nMask * rSub) ≤ ↑(gReal.advantage gSim)

    Even when r is placed first, a witness-knowing ZK distinguisher (supplied with r) runs crtPrefixTest on w* = r and distinguishes real honestCRTMaskTable tables from uniform cmult simulations with probability 1 vs 2⁻¹ ^ (nMask * rSub) (advantage = 1 - ...).