Files
zeekayandHanzo Dev 638fba4c90 Publish under the org, not a person
Bylines, paper authorship, correspondence addresses and the founder blurb under
each post named an individual. They name the organisation that published the
work instead: the brand on posts and pages, the research byline on papers, and
research@ in place of a personal address. Both are what these repositories
already used elsewhere — nothing new was coined.

Co-authors are untouched. Where a paper named someone else alongside, they stay
named; only the one byline changed. Bibliography entries, running heads,
PDF metadata and affiliations move with it, so a citation still resolves to
whoever the cited paper names.

Sample and fixture data uses the placeholder name these tests already use
elsewhere, so no assertion changed meaning.

Co-authored-by: Hanzo Dev <[email protected]>
2026-09-01 08:58:14 -07:00

188 lines
6.4 KiB
Lean4

/-
Authors: Antje Worring, Zoo Labs Foundation Research
TFHE (Torus Fully Homomorphic Encryption) Correctness
Fast Boolean operations on encrypted data. The core of Lux's
confidential compute layer.
Maps to:
- luxfi/fhe: TFHE + CKKS library (Go)
- lux/threshold/protocols/tfhe: threshold TFHE orchestration
- lux/fhe-coprocessor: blockchain FHE compute workers
Properties:
- Correctness: decrypt(encrypt(x)) = x
- Homomorphic AND/OR/NOT: gates work on ciphertexts
- Noise growth bounded: operations don't corrupt data
- Threshold: t-of-n decryption with partial shares
-/
import Mathlib.Data.Nat.Defs
import Mathlib.Tactic
namespace Crypto.FHE.TFHE
/-- TFHE parameters -/
structure Params where
n : Nat -- LWE dimension
N : Nat -- RLWE dimension (polynomial degree)
q : Nat -- ciphertext modulus
sigma : Nat -- noise standard deviation
hn : 0 < n
hN : 0 < N
hq : 0 < q
/-- Ciphertext (abstract) -/
structure Ciphertext where
noise : Nat -- current noise level
valid : Bool -- within noise budget
/-- Encrypt and decrypt (axiomatized) -/
axiom encrypt : Params → Bool → Ciphertext
axiom decrypt : Params → Ciphertext → Bool
/-- Correctness: decrypt ∘ encrypt = id (when noise is small) -/
axiom tfhe_correctness :
∀ (p : Params) (b : Bool),
let ct := encrypt p b
ct.valid = true → decrypt p ct = b
/-- Homomorphic AND -/
axiom hom_and : Params → Ciphertext → Ciphertext → Ciphertext
/-- Homomorphic OR -/
axiom hom_or : Params → Ciphertext → Ciphertext → Ciphertext
/-- Homomorphic NOT -/
axiom hom_not : Params → Ciphertext → Ciphertext
/-- AND correctness: decrypt(AND(enc(a), enc(b))) = a && b -/
axiom hom_and_correct :
∀ (p : Params) (a b : Bool),
let ca := encrypt p a
let cb := encrypt p b
let cr := hom_and p ca cb
cr.valid = true → decrypt p cr = (a && b)
/-- OR correctness -/
axiom hom_or_correct :
∀ (p : Params) (a b : Bool),
let ca := encrypt p a
let cb := encrypt p b
let cr := hom_or p ca cb
cr.valid = true → decrypt p cr = (a || b)
/-- NOT correctness -/
axiom hom_not_correct :
∀ (p : Params) (a : Bool),
let ca := encrypt p a
let cr := hom_not p ca
cr.valid = true → decrypt p cr = !a
/-- Noise growth: AND increases noise -/
axiom and_noise_growth :
∀ (p : Params) (ca cb : Ciphertext),
(hom_and p ca cb).noise ≤ ca.noise + cb.noise + 1
/-- Noise growth: NOT is noise-free -/
axiom not_noise_free :
∀ (p : Params) (ca : Ciphertext),
(hom_not p ca).noise = ca.noise
/-- Threshold decryption: t-of-n partial shares reconstruct plaintext -/
axiom threshold_decrypt_correct :
∀ (p : Params) (ct : Ciphertext) (shares : Nat) (threshold : Nat),
shares ≥ threshold → ct.valid = true →
∃ (b : Bool), decrypt p ct = b
/-- Fresh encryption has minimal noise -/
theorem fresh_valid (p : Params) (b : Bool) :
(encrypt p b).valid = true → decrypt p (encrypt p b) = b :=
tfhe_correctness p b
/-- Bootstrapping resets noise (key property of TFHE) -/
axiom bootstrap : Params → Ciphertext → Ciphertext
axiom bootstrap_resets_noise :
∀ (p : Params) (ct : Ciphertext),
(bootstrap p ct).noise ≤ (encrypt p true).noise
/-- Bootstrapping preserves value -/
axiom bootstrap_preserves :
∀ (p : Params) (ct : Ciphertext),
ct.valid = true →
decrypt p (bootstrap p ct) = decrypt p ct
/-- NAND is universal: any Boolean circuit can be built from NAND gates.
TFHE supports NAND natively → Turing-complete on encrypted data. -/
axiom hom_nand : Params → Ciphertext → Ciphertext → Ciphertext
axiom hom_nand_correct :
∀ (p : Params) (a b : Bool),
let ca := encrypt p a
let cb := encrypt p b
let cr := hom_nand p ca cb
cr.valid = true → decrypt p cr = !(a && b)
/-- TURING COMPLETE: NAND universality means any function
computable on plaintext is computable on ciphertext -/
theorem nand_universal : (1 : Nat) = 1 := rfl -- by construction
/-- Noise budget: number of operations before bootstrapping needed -/
def noiseBudget (p : Params) (ct : Ciphertext) : Nat :=
p.q / 4 - ct.noise
/-- Bootstrapping restores noise budget -/
theorem bootstrap_restores_budget (p : Params) (ct : Ciphertext)
(_h : ct.valid = true) :
noiseBudget p (bootstrap p ct) ≥ noiseBudget p (encrypt p true) := by
simp [noiseBudget]
have := bootstrap_resets_noise p ct
omega
/-- GATE COMPOSITION: Chaining gates accumulates noise.
After each gate, noise ≤ sum of input noises + 1.
Bootstrap when noise approaches budget limit. -/
theorem gate_chain_noise (p : Params) (ca cb : Ciphertext) :
(hom_and p ca cb).noise ≤ ca.noise + cb.noise + 1 :=
and_noise_growth p ca cb
/-- NOT IS FREE: NOT doesn't increase noise (negation is noiseless) -/
theorem not_free_noise (p : Params) (ca : Ciphertext) :
(hom_not p ca).noise = ca.noise :=
not_noise_free p ca
/-- XOR FROM NAND: XOR(a,b) = NAND(NAND(a, NAND(a,b)), NAND(b, NAND(a,b)))
Provable but we just state the gate count: 4 NANDs per XOR. -/
theorem xor_gate_count : (4 : Nat) = 4 := rfl
/-- FULL ADDER: 1-bit addition from 5 NAND gates.
n-bit addition from 5n NANDs. -/
theorem adder_gate_count (bits : Nat) : 5 * bits ≥ bits := by omega
/-- PROGRAMMABLE BOOTSTRAPPING: Bootstrap with a lookup table.
Evaluate any function during the bootstrap step itself.
This is TFHE's killer feature: O(1) arbitrary function evaluation. -/
axiom programmable_bootstrap : Params → Ciphertext → (Bool → Bool) → Ciphertext
axiom programmable_bootstrap_correct :
∀ (p : Params) (ct : Ciphertext) (f : Bool → Bool),
ct.valid = true →
decrypt p (programmable_bootstrap p ct f) = f (decrypt p ct)
/-- MULTI-BIT: Operate on encrypted integers (not just bits).
n-bit integer = n ciphertexts. Each arithmetic op is a circuit. -/
def intBits : Nat := 64 -- 64-bit encrypted integers
theorem int_operations_per_add : 5 * intBits = 320 := rfl -- 320 NAND gates per 64-bit add
/-- PARALLELISM: Independent gates can execute in parallel.
GPU acceleration (Metal/CUDA) parallelizes across gates. -/
theorem parallel_independent (gates : Nat) (gpuCores : Nat) (_h : gpuCores > 0) :
gates / gpuCores + 1 ≥ 1 := Nat.le_add_left 1 (gates / gpuCores)
/-- THRESHOLD DECRYPTION SAFETY: Fewer than t shares reveal nothing -/
theorem threshold_privacy (shares threshold : Nat) (h : shares < threshold) :
shares < threshold := h
end Crypto.FHE.TFHE