Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ jobs:
lake env lean --run Scripts/CheckCiFilters.lean --self-test
lake env lean --run Scripts/CheckCiFilters.lean
- name: Run primary IxTests
run: lake env .lake/build/bin/IxTests
run: lake env .lake/build/bin/IxTests -j 16
- name: Test Ixon contracts and primitives
run: |
lake env .lake/build/bin/ixon-primitives
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ libc = "0.2"
memmap2 = "0.9"
# Bundle v3.5.1 to fix large-arena failures (microsoft/mimalloc#1309).
mimalloc = { git = "https://github.com/argumentcomputer/mimalloc_rust.git", rev = "616cc1f130d9ea2a1111a46b4e98c140e078f882", default-features = false }
multi-stark = { git = "https://github.com/argumentcomputer/CertiFRI.git", rev = "7712efe9ea14464519723599bba080ef3a6f2ff5" }
multi-stark = { git = "https://github.com/argumentcomputer/CertiFRI.git", rev = "14f7a315bf5bc46fb124b6f0e9bb53b1f23ea63b" }
nom = "7.1.3"
num-bigint = "0.4.6"
quickcheck = "1.0.3"
Expand Down
193 changes: 188 additions & 5 deletions Ix/Aiur/FriSecurity.lean
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,27 @@ structure Parameters where
digestBytes : Nat := 32
protocolVersion : Nat := 6
batching : Option Batching := none
/-- True internal hash state width in bits (`none` defaults to `256` for 32B/48B
BLAKE3 because BLAKE3's internal `cv` is fixed at 256 bits, and `512` for 64B
hashes such as RFC 7693 `BLAKE2b-512`). -/
hashStateBits : Option Nat := none
/-- Whether Stage-1 pinning (`CertiFRI` PR #9 `GoldilocksExt*JohnsonPinned`) is enabled. -/
stage1Pinning : Bool := false
/-- QROM RBR lifting constant `C₁` in `C₁ · Q² · ε_rbr` (default `4.0`, tight CFHL21/DFMS22). -/
qromC1 : Float := 4.0
/-- QROM compressed-oracle collision constant `C₂` in `C₂ · Q³ / 2^{stateBits}` (default `27.0`, Zhandry19). -/
qromC2 : Float := 27.0
/-- Log₂ of NIST `MAXDEPTH` circuit depth cap for Model Q2 (default `40`, i.e., `2^40`). -/
maxDepthBits : Nat := 40
deriving Inhabited

/-- Effective internal hash state width in bits.
For `digestBytes = 32` or `48` (BLAKE3-256 / BLAKE3-XOF48), BLAKE3's internal
chaining value `cv` is fixed at 256 bits; for `digestBytes ≥ 64` (`BLAKE2b-512` /
`SHA-512` / `SHA3-512`), the default internal state is 512 bits unless overridden. -/
def Parameters.effectiveHashStateBits (p : Parameters) : Nat :=
p.hashStateBits.getD (if p.digestBytes ≥ 64 then 512 else 256)

/-- Effective FRI batching mode: explicit override if set, otherwise `tensor`
(`FriBatching::Tensor`) for Protocol `v6` (`extensionDegree ≥ 3 ∧ protocolVersion ≥ 6`)
and `powers` (Horner) for legacy `v5` / `Fp^2` profiles. -/
Expand Down Expand Up @@ -317,6 +336,7 @@ def minLogTraceForUdBits (p : Parameters)
structure Regime where
name : String
terms : Array (String × Float)
deriving Inhabited

/-- The weakest term. -/
def Regime.limit (r : Regime) : String × Float :=
Expand Down Expand Up @@ -433,12 +453,17 @@ def terms (inst : Instance) (p : Parameters) : Array Regime := Id.run do
terms := #[("ALI", ali), ("DEEP", certDeep), ("lookup", certLookup),
("batching", certBatch), ("commit", certCommit),
("query", certQuery), ("collision", colBits)] }]
-- CertiFRI 4f563b7 Tier-2 BatchedLineListCA + GoldilocksExt3JohnsonStark regime
-- CertiFRI PR #9 Tier-2 BatchedLineListCA + GoldilocksExt*JohnsonStark/Pinned regime
let mut bestCertJ : Option (Float × Regime) := none
if p.logBlowup ≥ 1 then
let sqrtRho := Float.sqrt rho
for step in [2:120] do
let theta := (1.0 + 1.0 / nat step) * sqrtRho
let mut candidateThetas : Array Float := #[]
for step in [2:400] do
candidateThetas := candidateThetas.push ((1.0 + 1.0 / nat step) * sqrtRho)
for k in [1:40] do
let theta := sqrtRho + (nat k / 40.0) * (0.95 - sqrtRho)
candidateThetas := candidateThetas.push theta
for theta in candidateThetas do
if theta < 1.0 && rho < theta * theta then
let lJ := (theta - rho) / (theta * theta - rho)
if let some cT := certCurveListCoeff n k theta then
Expand All @@ -454,10 +479,20 @@ def terms (inst : Instance) (p : Parameters) : Array Regime := Id.run do
let jAli := F - log2 (max (lJ * max (nat inst.constraints) 1) 1)
let jDeep := F - log2 (max (lJ * certDegreeTerm + 2.0 * n) 1)
let jQuery := queryPow - queries * log2 theta
let baseTerms : Array (String × Float) :=
if p.stage1Pinning then
let lInt := Float.ceil lJ
let pinPairs := max (lInt * (lInt - 1.0) / 2.0) 1.0
let jPin := F - log2 (max (pinPairs * k) 1)
let jLookup := F - log2 (max (2.0 * (nat inst.lookupWidth + 2) * nat inst.lookupRows) 1)
#[("ALI", jAli), ("DEEP", jDeep), ("pinning", jPin), ("lookup", jLookup),
("batching", jBatch), ("commit", jCommit), ("query", jQuery), ("collision", colBits)]
else
#[("ALI", jAli), ("DEEP", jDeep), ("batching", jBatch),
("commit", jCommit), ("query", jQuery), ("collision", colBits)]
let r : Regime := {
name := "CertiFRI proven Johnson"
terms := #[("ALI", jAli), ("DEEP", jDeep), ("batching", jBatch),
("commit", jCommit), ("query", jQuery), ("collision", colBits)] }
terms := baseTerms }
match bestCertJ with
| some (_, b) => if r.betterThan b then bestCertJ := some (theta, r)
| none => bestCertJ := some (theta, r)
Expand Down Expand Up @@ -543,6 +578,154 @@ def report (source : String) (inst : Instance) (p : Parameters) : String := Id.r
lines := lines.push s!" {r.name}: {fmt bits} bits (limited by {name}) {detail}"
return "\n".intercalate lines.toList

/-- Post-quantum (Model Q1, unbounded-depth QROM) interactive bit-security for a
classical RBR soundness term `b = -log₂(ε_rbr)`:
`½ · (b - log₂ C₁)` from `C₁ · Q² · ε_rbr ≤ 1`. -/
def q1InteractiveBits (classicalBits c1 : Float) : Float :=
max 0.0 ((classicalBits - log2 (max c1 1.0)) / 2.0)

/-- Post-quantum (Model Q1, unbounded-depth QROM) hash collision bit-security for
an internal hash state width of `stateBits`:
`⅓ · (stateBits - log₂ C₂)` from `C₂ · Q³ / 2^{stateBits} ≤ 1` (BHT / Zhandry compressed oracle).
NOTE: For BLAKE3 (32B or XOF48/XOF64), `stateBits = 256` regardless of XOF output length. -/
def q1CollisionBits (stateBits : Nat) (c2 : Float) : Float :=
max 0.0 ((nat stateBits - log2 (max c2 1.0)) / 3.0)

/-- Combined Model Q1 security in bits (`log₂ N`) solving
`C₁ · N² · 2^{-iopBits} + C₂ · N³ · 2^{-stateBits} = 1` via bisection. -/
def q1CombinedBits (iopBits : Float) (stateBits : Nat) (c1 c2 : Float) : Float := Id.run do
let logC1 := log2 (max c1 1.0)
let logC2 := log2 (max c2 1.0)
let sb := nat stateBits
let mut lo : Float := 0.0
let mut hi : Float := 512.0
for _ in [0:64] do
let mid := (lo + hi) / 2.0
let t1 := pow2 (logC1 + 2.0 * mid - iopBits)
let t2 := pow2 (logC2 + 3.0 * mid - sb)
if t1 + t2 ≤ 1.0 then
lo := mid
else
hi := mid
return lo

/-- Post-quantum (Model Q2, depth-bounded NIST `MAXDEPTH = 2^d`) interactive bit-security
for a classical RBR soundness term `b`:
`max(½(b - log₂ C₁), b - log₂ C₁ - d)` (parallel Grover search capped at circuit depth `2^d`). -/
def q2InteractiveBits (classicalBits c1 : Float) (maxDepthBits : Nat) : Float :=
let cBits := log2 (max c1 1.0)
max 0.0 (max ((classicalBits - cBits) / 2.0) (classicalBits - cBits - nat maxDepthBits))

/-- Post-quantum (Model Q2, CNS17 non-qRAM) hash collision bit-security:
`⅖ · stateBits` from `Q⁵ / 2^{2 · stateBits} ≤ 1` (`102.4b` for 256b state, `204.8b` for 512b). -/
def q2CnsCollisionBits (stateBits : Nat) : Float :=
(2.0 / 5.0) * nat stateBits

/-- Convert a classical `Regime` into a Model Q1 (unbounded-depth QROM) `Regime`,
replacing each interactive term `b` with `q1InteractiveBits b c1` and `collision`
with `q1CollisionBits stateBits c2`, plus an explicit `combined` term solving
`C₁·N²·ε_max + C₂·N³ / 2^{stateBits} = 1`. -/
def Regime.toQ1 (r : Regime) (prefixLabel : String) (stateBits : Nat) (c1 c2 : Float) : Regime :=
let iopClassical := r.iopLimit.2
let colQ1 := q1CollisionBits stateBits c2
let combined := q1CombinedBits iopClassical stateBits c1 c2
let mapped := r.terms.map fun (t, b) =>
if t == "collision" then ("collision(BHT)", colQ1)
else (t, q1InteractiveBits b c1)
{ name := s!"{prefixLabel} {r.name}"
terms := mapped.push ("combined", combined) }

/-- Convert a classical `Regime` into a Model Q2 (CNS17 non-qRAM + NIST `MAXDEPTH`) `Regime`. -/
def Regime.toQ2 (r : Regime) (prefixLabel : String) (stateBits : Nat)
(c1 : Float) (maxDepthBits : Nat) : Regime :=
let colQ2 := q2CnsCollisionBits stateBits
let mapped := r.terms.map fun (t, b) =>
if t == "collision" then ("collision(CNS)", colQ2)
else (t, q2InteractiveBits b c1 maxDepthBits)
{ name := s!"{prefixLabel} {r.name}"
terms := mapped }

/-- Every post-quantum regime (Model Q1 unbounded-depth QROM and Model Q2 CNS+MAXDEPTH)
for `inst` under `p`. -/
def pqTerms (inst : Instance) (p : Parameters) : Array Regime := Id.run do
let classical := terms inst p
let stateBits := p.effectiveHashStateBits
let c1 := p.qromC1
let c2 := p.qromC2
let dMax := p.maxDepthBits
let mut out : Array Regime := #[]
for r in classical do
if r.name == "CertiFRI proven UD" ||
r.name.startsWith "CertiFRI proven Johnson" ||
r.name.startsWith "Johnson, BCHKS25" ||
r.name.startsWith "Johnson, DKT26" ||
r.name.startsWith "conjectured" then
out := out.push (r.toQ1 "QROM-Q1" stateBits c1 c2)
for r in classical do
if r.name.startsWith "CertiFRI proven Johnson" ||
r.name.startsWith "Johnson, BCHKS25" then
out := out.push (r.toQ2 s!"Model-Q2(CNS,D=2^{dMax})" stateBits c1 dMax)
return out

/-- One parameter set's post-quantum report (Model Q1 QROM and Model Q2 CNS+MAXDEPTH). -/
def pqReport (source : String) (inst : Instance) (p : Parameters) : String := Id.run do
let ellMin := inst.effectiveMinLogTrace
let stateBits := p.effectiveHashStateBits
let tensorDetail := match inst.effectiveKCol, inst.effectiveKOpen with
| some kc, some ko => s!"kCol+kOpen = {kc + ko} (kCol={kc}, kOpen={ko})"
| _, _ => s!"kTensor = {inst.effectiveTensorChallenges} (from claimRefs)"
let mut lines := #[
s!"[PQ] key: {source}, proto v{p.protocolVersion}, ext Fp^{p.extensionDegree} ({fmt (fieldBitsFor p.extensionDegree)}b), " ++
s!"batching {p.effectiveBatching.label}, pinning {p.stage1Pinning}, " ++
s!"digest {p.digestBytes}B (internal state {stateBits}b), blowup 2^{p.logBlowup}, " ++
s!"{p.queries} queries, query pow {p.queryPow}, commit pow {p.commitPow}, arity 2^{p.logArity}",
s!"[PQ] QROM constants: C1={fmt p.qromC1} (Q²·ε_rbr), C2={fmt p.qromC2} (Q³/2^{stateBits}), " ++
s!"Model-Q2 MAXDEPTH=2^{p.maxDepthBits}",
s!"[PQ] instance: trace 2^{inst.logTrace} (min trace 2^{ellMin}), {inst.columns} batched columns " ++
s!"({inst.effectiveClaimRefs} FRI claim refs), {inst.constraints} constraints, " ++
s!"max degree {inst.maxDegree} (quotient {inst.effectiveQuotient}), " ++
s!"lookup rows {inst.lookupRows}, lookup width {inst.lookupWidth}; " ++
s!"{tensorDetail}, tensorCapOk = {tensorCapOk inst p}"]
for r in pqTerms inst p do
let (name, bits) := r.limit
let detail := " ".intercalate (r.terms.toList.map fun (t, b) => s!"{t} {fmt b}")
lines := lines.push s!" {r.name}: {fmt bits} bits PQ (limited by {name}) {detail}"
return "\n".intercalate lines.toList

/-- Self-test verifying Phase 0 invariants:
1. Baseline `P0` (`Fp^3`, 32B BLAKE3-256, `(2,128,0,20)`) lands in ~65–71b Q1 PQ on representative IxVM scale.
2. `BLAKE3-XOF48` (`digestBytes=48`, default `stateBits=256`) still caps at `< 86b` BHT.
3. Candidate `P3` (`Fp^5`, 64B BLAKE2b-512, Stage-1 pinning, `(2,246,0,28)`) clears `≥ 128b` Q1 PQ across BCHKS25 & DKT26. -/
def pqSelfTest : Except String String := do
let ixvmInst : Instance := {
logTrace := 23, columns := 22663, constraints := 49086, maxDegree := 5,
lookupRows := 32372164352, lookupWidth := 140, minLogTrace := some 8,
claimRefs := some 43508, maxQuotient := some 4, maxWidth := some 2382,
maxOpeningsPerHeight := some 1600 }
let p0 : Parameters := {
logBlowup := 2, queries := 128, queryPow := 20, commitPow := 0, logArity := 1,
extensionDegree := 3, digestBytes := 32, protocolVersion := 6,
qromC1 := 1.0, qromC2 := 1.0 }
let p0Bchks := ((pqTerms ixvmInst p0).find? (·.name.startsWith "QROM-Q1 Johnson, BCHKS25")).get!
let p0Bits := p0Bchks.limit.2
if !(67.0 ≤ p0Bits && p0Bits ≤ 72.0) then
throw s!"P0 BCHKS25 Q1 expected in [67, 72], got {fmt p0Bits}"
let xof48 : Parameters := { p0 with digestBytes := 48 }
let xofCol := q1CollisionBits xof48.effectiveHashStateBits 1.0
if !(xofCol < 86.0) then
throw s!"BLAKE3-XOF48 BHT collision expected < 86b, got {fmt xofCol}"
let p3 : Parameters := {
logBlowup := 2, queries := 246, queryPow := 28, commitPow := 0, logArity := 1,
extensionDegree := 5, digestBytes := 64, protocolVersion := 7,
stage1Pinning := true, qromC1 := 4.0, qromC2 := 27.0 }
let p3Bchks := ((pqTerms ixvmInst p3).find? (·.name.startsWith "QROM-Q1 Johnson, BCHKS25")).get!
let p3Bits := p3Bchks.limit.2
if !(p3Bits ≥ 128.0) then
throw s!"P3 BCHKS25 Q1 expected ≥ 128b, got {fmt p3Bits} (limited by {p3Bchks.limit.1})"
let p3Cert := ((pqTerms ixvmInst p3).find? (·.name.startsWith "QROM-Q1 CertiFRI proven Johnson")).get!
return s!"pqSelfTest PASS: P0(C1=1)={fmt p0Bits}b, XOF48_BHT={fmt xofCol}b, " ++
s!"P3(C1=4,C2=27) BCHKS25={fmt p3Bits}b, CertiFRI_Johnson={fmt p3Cert.limit.2}b (lim={p3Cert.limit.1})"

/-- Security regime targeted by `--require-min-bits` / `--regime`. -/
inductive RegimeKind where
| proven
Expand Down
5 changes: 5 additions & 0 deletions Ix/Aiur/Parameters.lean
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ def extensionDegreeV6 : Nat := 3
/-- Protocol version tag for the `v6` `Fp^3` + BLAKE3 `derive_key` profile. -/
def protocolVersionV6 : Nat := 6

/-- Stage-1 pinning flag required for production Release 0.5 Protocol `v6` keys
(`1` = enabled, pinning stage-1 & active preprocessed columns at `z0` before
sampling lookup challenges `beta`, `gamma`). -/
def stage1PinningV6 : Nat := 1

/-- Target provable security floor (in bits) for the `v6` 128-bit profile. -/
def minProvableSecurityBits128 : Nat := 128

Expand Down
10 changes: 6 additions & 4 deletions Ix/Cert/Aggr/FixedIxvmKey.lean
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,9 @@ theorem parseIxvmKey_invariants {bytes : ByteArray} {pk : ParsedIxvmKey}
obtain ⟨⟨_, q5⟩, _, hq5⟩ := except_bind_ok' hq4
obtain ⟨⟨_, q6⟩, _, hq6⟩ := except_bind_ok' hq5
obtain ⟨⟨_, q7⟩, _, hq7⟩ := except_bind_ok' hq6
obtain ⟨⟨n, q8⟩, _, hq8⟩ := except_bind_ok' hq7
obtain ⟨⟨_, q7b⟩, _, hq7b⟩ := except_bind_ok' hq7
obtain ⟨_, hq7c⟩ := except_unless_bool_ok hq7b
obtain ⟨⟨n, q8⟩, _, hq8⟩ := except_bind_ok' hq7c
obtain ⟨⟨circuits, q9⟩, hcircs, hq9⟩ := except_bind_ok' hq8
obtain ⟨⟨commit, q10⟩, hcom, hq10⟩ := except_bind_ok' hq9
obtain ⟨⟨indices, q11⟩, hidx, hq11⟩ := except_bind_ok' hq10
Expand Down Expand Up @@ -761,7 +763,7 @@ theorem flatTables_sizes (pk : ParsedIxvmKey) (digestBytes : ByteArray) :
let tbl := FlatIxvmTables.ofParsed pk digestBytes
tbl.circuits.size = pk.circuits.size ∧
tbl.circuitSpans.size = pk.circuits.size ∧
tbl.tlimbs.size = 18 + 7 * pk.circuits.size ∧
tbl.tlimbs.size = 19 + 7 * pk.circuits.size ∧
tbl.digestWords.size = 8 ∧
tbl.hasCommit = (if pk.preprocessedCommit.isSome then 1 else 0) ∧
tbl.prepCap.size = (if pk.preprocessedCommit.isSome then 4 else 0) := by
Expand All @@ -772,7 +774,7 @@ theorem flatTables_sizes (pk : ParsedIxvmKey) (digestBytes : ByteArray) :
have hlen : (zipCircuitsWithPrep pk.circuits.toList pk.preprocessedIndices.toList).length =
pk.circuits.size := by
rw [zipCircuitsWithPrep_length, Array.length_toList]
have htlimbs : (buildTlimbs pk).size = 18 + 7 * pk.circuits.size := by
have htlimbs : (buildTlimbs pk).size = 19 + 7 * pk.circuits.size := by
unfold buildTlimbs
have hflat : (pk.circuits.toList.flatMap circuitShapeLimbs).length = 7 * pk.circuits.size := by
have hlen7 : ∀ cs : List SysCircuitData, (cs.flatMap circuitShapeLimbs).length = 7 * cs.length := by
Expand Down Expand Up @@ -1542,7 +1544,7 @@ theorem tabledSys_eq_readSystem {vkBytes : ByteArray} {pk : ParsedIxvmKey}
(∀ i : Fin 8, ((tbl.digestWords.getD i.val 0 : Nat) : Fp) =
packDigest8 (Address.blake3Pure vkBytes) i) ∧
tbl.circuits.size = pk.circuits.size ∧
tbl.tlimbs.size = 18 + 7 * pk.circuits.size ∧
tbl.tlimbs.size = 19 + 7 * pk.circuits.size ∧
pk.preprocessedIndices.size = pk.circuits.size ∧
(∀ (ci : Nat) (hci : ci < pk.circuits.size),
let c := pk.circuits[ci]
Expand Down
2 changes: 1 addition & 1 deletion Ix/Cert/Aggr/Shapes.lean
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ theorem aggregateSource_core_helpers_present :
Any edit to any module in `MultiStark.aggregateSource` changes this digest and forces an
explicit audit review. -/
def pinnedAggregateDigest : String :=
"6f9f5bd75db2cd3b1ba23d5026b794e96c94caa2bb4b5ab0994745fb2a0926c9"
"25ff49a5b852f47f41e8c21a82dd9f550e7c497b94072eefac45795f65b985f8"

theorem aggregateDigest_eq : MultiStark.aggregateDigest = pinnedAggregateDigest := rfl

Expand Down
Loading
Loading