Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Binary codes of symbols, words, oracle inputs and proofs

Definition
CertRandQROM_Supplement_proofBits

by iris · Nov 22, 2026 · Mathlib 0df444a (Lean v4.33.1)

certified-randomnesscryptographyp2o-gran-per-chapterp2o-plan-paperp2o-v1quantum-informationquery-complexityrandom-oracle-model

Given a code enc:K→{0,1}e\mathrm{enc}:K\to\{0,1\}^eenc:K→{0,1}e of field elements:

  1. a symbol s∈Σ=Kms\in\Sigma=K^ms∈Σ=Km is written as the m⋅em\cdot em⋅e bits enc(s0)⋯enc(sm−1)\mathrm{enc}(s_0)\cdots\mathrm{enc}(s_{m-1})enc(s0​)⋯enc(sm−1​);
  2. a word x∈Σnx\in\Sigma^nx∈Σn as the concatenation of its nnn symbols;
  3. an index i∈[n]i\in[n]i∈[n] in binary, least significant bit first, on as many bits as nnn has binary digits;
  4. an oracle input (i,x)∈[n]×Σ(i,x)\in[n]\times\Sigma(i,x)∈[n]×Σ as the index followed by the symbol;
  5. a proof π∈Σn∪{⊥}\pi\in\Sigma^n\cup\{\bot\}π∈Σn∪{⊥} as a flag bit followed by n⋅m⋅en\cdot m\cdot en⋅m⋅e bits: 000 and the word for π=x\pi=xπ=x, 111 and zeros for π=⊥\pi=\botπ=⊥.

A string is parsed as the word xxx if it is 000 followed by the code of xxx, and as ⊥\bot⊥ otherwise (flag 111, wrong length, or not a code).

These codes are how the classical proof and the oracle queries of the protocol appear on wires and tapes in the syntax property.

Formalization Note symBits, wordBits, idxBits, domBits, proofBits are the five codes and proofOfBits the parser, which picks the word by choice; it is unique when enc is injective.

Definition code
import Mathlib

set_option autoImplicit false

namespace CertRandQROM.Supplement

variable {K : Type} {e n m : ℕ}

/-- The bit string of a symbol `s ∈ Σ = F_q^m`: the codes `enc (s_0), …, enc (s_{m−1})` of its
`m` field coordinates, concatenated (`m·e` bits). Coladangelo et al., arXiv:2608.31112
(sha256 b75095a2…), §5.2, p.23 (`Σ = F_q^m`); Definition 6.1, p.27 (classical proofs and oracle
queries are strings). -/
def symBits (enc : K → Fin e → Bool) (s : Fin m → K) : List Bool :=
  (List.ofFn fun j : Fin m => List.ofFn (enc (s j))).flatten

/-- The bit string of a word `x ∈ Σ^n`: the strings of `x_0, …, x_{n−1}`, concatenated
(`n·m·e` bits). -/
def wordBits (enc : K → Fin e → Bool) (x : Fin n → Fin m → K) : List Bool :=
  (List.ofFn fun i : Fin n => symBits enc (x i)).flatten

/-- The index `i ∈ [n]` (0-based) in binary, least significant bit first, on `Nat.size n` bits
(the number of binary digits of `n`, so that every `i < n` fits). -/
def idxBits (n : ℕ) (i : Fin n) : List Bool :=
  List.ofFn fun j : Fin (Nat.size n) => i.val.testBit j.val

/-- The bit string of an oracle input `(i, x) ∈ [n] × Σ` (§6.2, p.28: "functions mapping
`[n] × Σ → {0,1}`"): the index in binary followed by the symbol. -/
def domBits (enc : K → Fin e → Bool) (u : Fin n × (Fin m → K)) : List Bool :=
  idxBits n u.1 ++ symBits enc u.2

/-- **The bit string of a proof `π ∈ Σ^n ∪ {⊥}`** (Construction 6.2, pp.28–29): one flag bit
(`true` = `⊥`) followed by `n·m·e` bits, the word for `π = x` and zeros for `π = ⊥`. -/
def proofBits (enc : K → Fin e → Bool) : Option (Fin n → Fin m → K) → List Bool
  | none => true :: List.replicate (n * m * e) false
  | some x => false :: wordBits enc x

open Classical in
/-- **Parsing a proof** (Construction 6.2, Verify, step 1, p.29: "If `π = ⊥`, then output `⊥` and
halt. Otherwise, parse `π = x = (x_1, …, x_n)`"): a string `0 ++ wordBits x` is the word `x`;
every other string (flag `1`, wrong length, or not the string of a word) is `⊥` (`none`).

**Formalization Note** The word is chosen with `Classical.choose`; when `enc` is injective
(as for a `FieldPres` at `λ ≥ 2`) it is unique. -/
noncomputable def proofOfBits (enc : K → Fin e → Bool) (s : List Bool) :
    Option (Fin n → Fin m → K) :=
  if h : ∃ x : Fin n → Fin m → K, s = false :: wordBits enc x then some h.choose else none

end CertRandQROM.Supplement
Source
Coladangelo, Khurana, Mutreja, Roberts, Slote, Tal, Unconditional Certified Randomness without Structure, arXiv:2608.31112 (sha256 b75095a2…), Definition 6.1, Syntax, p.27 (PDF p.29); Construction 6.2, Verify, step 1, p.29 (PDF p.31); §6.2, Biased Random Oracle, p.28 (PDF p.30)

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me