Two-block masked agreement test
DefinitionCityLWE_AgreementTestThe two-block masked agreement test, which turns a search-LWE solver into a distinguisher.
Fix a modulus , dimension , block size , a solver step function that uses coins, and a mask length . The input is a transcript with and , split into column blocks and of samples each. The test reads coins (in this order). For it forms the mask whose -th coordinate is the -th base- digit of the number with binary digits (least significant first), shifts the labels to , runs the solver once on parameter with coins (exactly as in one adversary activation: the input is and the move is the second output field cut to bits), decodes the move into a vector block by block with width , and sets . It accepts iff .
agreeAccept is the acceptance probability of this test with fair coins on a given law of transcripts.
import Definitions.Def_CityLWE_DecisionExperiment
set_option autoImplicit false
open QAlgorithms.Complexity PPSLattice
namespace CityLWE
/-- The left block of columns `0, …, m - 1` of an `n × (m + m)` matrix. -/
def colL {q n m : ℕ} (A : Mat q n (m + m)) : Mat q n m :=
Matrix.of fun i j => A i (Fin.castAdd m j)
/-- The right block of columns `m, …, 2m - 1` of an `n × (m + m)` matrix. -/
def colR {q n m : ℕ} (A : Mat q n (m + m)) : Mat q n m :=
Matrix.of fun i j => A i (Fin.natAdd m j)
/-- The first `m` labels of a vector of length `m + m`. -/
def vecL {q m : ℕ} (b : Vec q (m + m)) : Vec q m := fun j => b (Fin.castAdd m j)
/-- The last `m` labels of a vector of length `m + m`. -/
def vecR {q m : ℕ} (b : Vec q (m + m)) : Vec q m := fun j => b (Fin.natAdd m j)
/-- The number whose binary digits, least significant first, are the given bits. -/
def bitsVal (w : List Bool) : ℕ := w.foldr (fun b acc => b.toNat + 2 * acc) 0
/-- The mask read off coins: the `i`-th coordinate is the `i`-th base-`q` digit of the coin value. -/
def maskOf (q n : ℕ) (c : List Bool) : Vec q n :=
fun i => ((bitsVal c / q ^ (i : ℕ) : ℕ) : ZMod q)
/-- Decoding a reply into a vector: coordinate `j` is the value of bits `j w, …, j w + w - 1`,
with `w = ⌈log₂ q⌉` the residue width of `encVec`. -/
def decodeVec (q n : ℕ) (o : Str) : Vec q n :=
fun j => ((bitsVal ((o.drop ((j : ℕ) * Nat.clog 2 q)).take (Nat.clog 2 q)) : ℕ) : ZMod q)
/-- One masked call of a search solver with step function `Sf` and `P` coins: the labels are
shifted to `b + Aᵀ r`, the solver is run once on parameter `n` (as in `Adversary.activate`), its
move is decoded, and the mask is removed. -/
def maskedGuess (q n m P : ℕ) (Sf : Str → Str) (A : Mat q n m) (b : Vec q m) (r : Vec q n)
(c : List Bool) : Vec q n :=
decodeVec q n
(((BeyondDS.untup (Sf (BeyondDS.tup
[encNat n, [], BeyondDS.tup [encMat q A, encVec q (rhs A r b)], c]))).getD 1 []).take P)
- r
/-- **The two-block masked agreement test.** The coins are split into the solver's coins for the
two blocks (`P` each) and the coins of the two masks (`L` each). The test accepts when the two
unmasked guesses agree. -/
def agreeBit (q n m P L : ℕ) (Sf : Str → Str) (A : Mat q n (m + m)) (b : Vec q (m + m))
(c : List Bool) : Bool :=
decide (maskedGuess q n m P Sf (colL A) (vecL b) (maskOf q n ((c.drop (2 * P)).take L))
(c.take P) =
maskedGuess q n m P Sf (colR A) (vecR b) (maskOf q n ((c.drop (2 * P + L)).take L))
((c.drop P).take P))
/-- `K` fair coins, as a bit list. -/
noncomputable def coinLaw (K : ℕ) : PMF (List Bool) :=
(PMF.uniformOfFintype (Fin K → Bool)).map List.ofFn
/-- Acceptance probability of the agreement test with `2P + 2L` fair coins on a law of
transcripts with `m + m` samples. -/
noncomputable def agreeAccept (q n m P L : ℕ) (Sf : Str → Str)
(views : PMF (Transcript q n (m + m))) : ℝ :=
((views.bind fun ab => (coinLaw (2 * P + 2 * L)).map (agreeBit q n m P L Sf ab.1 ab.2))
true).toReal
end CityLWE