Documentation

Complexity.Crypto.Computational.GMW.Protocol

Three-copy masked-3SAT commitment protocol for GMW zero-knowledge #

This module defines the two-round interactive protocol used to prove Goldreich, Micali, and Wigderson's theorem [GMW91] that every language in NP has a computational zero-knowledge interactive proof system from one-way functions (via Naor's bit commitment scheme [Nao91] and ThreeSAT_npHard).

Rather than GMW's original 3-coloring protocol, we formalize a direct 3-copy masked-3SAT truth-table commitment protocol: in each of 3 parallel copies, the prover samples a random mask m for the variables of the 3CNF formula φ and commits (via naorCommit) to copyLen φ bits consisting of m, the XOR-masked assignment v = w ⊕ m, and the 8-bit truth table of each clause under inputs t ⊕ m. A 3-bit challenge ch selects for each copy whether to open m and the full clause truth tables (ch[j] = false) or v and the active truth-table entries (ch[j] = true).

Main definitions #

Main results #

References #

Masked 3SAT truth-table gadgets #

Bit 0 of a 3-bit truth-table row index t < 8.

Instances For

    Bit 1 of a 3-bit truth-table row index t < 8.

    Instances For

      Bit 2 of a 3-bit truth-table row index t < 8.

      Instances For
        def Cslib.Crypto.GMW.gmwActiveIdx (b₀ b₁ b₂ : Bool) :

        Pack three literal-variable bits into an active truth-table row index in 0..7.

        Instances For
          theorem Cslib.Crypto.GMW.gmwActiveIdx_lt_eight (b₀ b₁ b₂ : Bool) :
          gmwActiveIdx b₀ b₁ b₂ < 8
          @[simp]
          theorem Cslib.Crypto.GMW.gmwBit0Of8_gmwActiveIdx (b₀ b₁ b₂ : Bool) :
          gmwBit0Of8 (gmwActiveIdx b₀ b₁ b₂) = b₀
          @[simp]
          theorem Cslib.Crypto.GMW.gmwBit1Of8_gmwActiveIdx (b₀ b₁ b₂ : Bool) :
          gmwBit1Of8 (gmwActiveIdx b₀ b₁ b₂) = b₁
          @[simp]
          theorem Cslib.Crypto.GMW.gmwBit2Of8_gmwActiveIdx (b₀ b₁ b₂ : Bool) :
          gmwBit2Of8 (gmwActiveIdx b₀ b₁ b₂) = b₂

          Evaluate a clause of length at most 3 given the truth values of its first three literals' variables.

          Instances For

            Look up the bit for variable v in vec at its first occurrence in φ.vars, returning false when v ∉ φ.vars.

            Instances For
              @[simp]
              theorem Cslib.Crypto.GMW.varBit_listXor (φ : Logic.PL.CNF ℕ) (w m : List Bool) (v : ℕ) :
              varBit φ (BitString.listXor φ.vars.length [w, m]) v = (varBit φ w v ^^ varBit φ m v)
              @[simp]
              theorem Cslib.Crypto.GMW.varBit_listRow (φ : Logic.PL.CNF ℕ) (vec : List Bool) (v : ℕ) :
              varBit φ (BitString.listRow φ.vars.length 0 vec) v = varBit φ vec v

              The 8-bit masked truth table of clause c under variable mask m.

              Instances For

                The 8-bit indicator of the active row of clause c under masked assignment v.

                Instances For
                  theorem Cslib.Crypto.GMW.getD_clauseActiveRow (φ : Logic.PL.CNF ℕ) (v : List Bool) (c : Logic.PL.Clause ℕ) {t : ℕ} (ht : t < 8) :
                  (clauseActiveRow φ v c).getD t false = decide (t = gmwActiveIdx (varBit φ v (List.getD c 0 (0, false)).1) (varBit φ v (List.getD c 1 (0, false)).1) (varBit φ v (List.getD c 2 (0, false)).1))

                  The 8 * φ.length-bit concatenation of all clause truth tables of φ under mask m.

                  Instances For

                    The 8 * φ.length-bit concatenation of all active-row indicators of φ under v.

                    Instances For

                      Single-copy and three-copy bit layouts #

                      Number of committed bits in one copy of the masked 3SAT gadget: φ.vars.length mask bits, φ.vars.length masked assignment bits, and 8 * φ.length table bits.

                      Instances For

                        Number of committed bits across all three parallel copies.

                        Instances For

                          Extract the m segment (first φ.vars.length bits) of a copy.

                          Instances For

                            Extract the v segment (second φ.vars.length bits) of a copy.

                            Instances For

                              Extract the truth-table segment (8 * φ.length bits) of a copy.

                              Instances For

                                Honest committed bits for one copy given witness w and mask m.

                                Instances For

                                  Simulated (and selectively opened) bits for one copy given challenge bit b and random word rand of length φ.vars.length.

                                  Instances For

                                    Selective-opening flags for one copy under challenge bit b.

                                    Instances For
                                      @[simp]
                                      @[simp]

                                      Check the opened bits of one copy against challenge bit b.

                                      Instances For

                                        Three-copy protocol messages and verification #

                                        Extract copy 0 (copyLen φ bits) from a 3-copy GMW bit vector.

                                        Instances For

                                          Extract copy 1 (copyLen φ bits) from a 3-copy GMW bit vector.

                                          Instances For

                                            Extract copy 2 (copyLen φ bits) from a 3-copy GMW bit vector.

                                            Instances For
                                              def Cslib.Crypto.GMW.realBits (φ : Logic.PL.CNF ℕ) (w m₀ m₁ m₂ : List Bool) :

                                              Honest committed bits across all three copies.

                                              Instances For
                                                def Cslib.Crypto.GMW.simBits (φ : Logic.PL.CNF ℕ) (ch r₀ r₁ r₂ : List Bool) :

                                                Simulated (and selectively opened) bits across all three copies.

                                                Instances For

                                                  Selective-opening flags across all three copies under challenge word ch.

                                                  Instances For
                                                    @[simp]
                                                    theorem Cslib.Crypto.GMW.length_realBits (φ : Logic.PL.CNF ℕ) (w m₀ m₁ m₂ : List Bool) :
                                                    (realBits φ w m₀ m₁ m₂).length = totalLen φ
                                                    @[simp]
                                                    theorem Cslib.Crypto.GMW.length_simBits (φ : Logic.PL.CNF ℕ) (ch r₀ r₁ r₂ : List Bool) :
                                                    (simBits φ ch r₀ r₁ r₂).length = totalLen φ
                                                    @[simp]
                                                    theorem Cslib.Crypto.GMW.gmwCopy0_realBits (φ : Logic.PL.CNF ℕ) (w m₀ m₁ m₂ : List Bool) :
                                                    gmwCopy0 φ (realBits φ w m₀ m₁ m₂) = realCopyBits φ w m₀
                                                    @[simp]
                                                    theorem Cslib.Crypto.GMW.gmwCopy1_realBits (φ : Logic.PL.CNF ℕ) (w m₀ m₁ m₂ : List Bool) :
                                                    gmwCopy1 φ (realBits φ w m₀ m₁ m₂) = realCopyBits φ w m₁
                                                    @[simp]
                                                    theorem Cslib.Crypto.GMW.gmwCopy2_realBits (φ : Logic.PL.CNF ℕ) (w m₀ m₁ m₂ : List Bool) :
                                                    gmwCopy2 φ (realBits φ w m₀ m₁ m₂) = realCopyBits φ w m₂
                                                    @[simp]
                                                    theorem Cslib.Crypto.GMW.gmwCopy0_simBits (φ : Logic.PL.CNF ℕ) (ch r₀ r₁ r₂ : List Bool) :
                                                    gmwCopy0 φ (simBits φ ch r₀ r₁ r₂) = simCopyBits φ (ch.getD 0 false) r₀
                                                    @[simp]
                                                    theorem Cslib.Crypto.GMW.gmwCopy1_simBits (φ : Logic.PL.CNF ℕ) (ch r₀ r₁ r₂ : List Bool) :
                                                    gmwCopy1 φ (simBits φ ch r₀ r₁ r₂) = simCopyBits φ (ch.getD 1 false) r₁
                                                    @[simp]
                                                    theorem Cslib.Crypto.GMW.gmwCopy2_simBits (φ : Logic.PL.CNF ℕ) (ch r₀ r₁ r₂ : List Bool) :
                                                    gmwCopy2 φ (simBits φ ch r₀ r₁ r₂) = simCopyBits φ (ch.getD 2 false) r₂
                                                    theorem Cslib.Crypto.GMW.naorMaskBits_realBits {φ : Logic.PL.CNF ℕ} {w m₀ m₁ m₂ : List Bool} (ch : List Bool) (hw : Complexity.ThreeSAT.verifier (φ, w) = true) :
                                                    naorMaskBits (allOpenFlags φ ch (realBits φ w m₀ m₁ m₂)) (realBits φ w m₀ m₁ m₂) = simBits φ ch (if ch.getD 0 false = true then BitString.listXor φ.vars.length [w, m₀] else m₀) (if ch.getD 1 false = true then BitString.listXor φ.vars.length [w, m₁] else m₁) (if ch.getD 2 false = true then BitString.listXor φ.vars.length [w, m₂] else m₂)
                                                    theorem Cslib.Crypto.GMW.allOpenFlags_realBits (φ : Logic.PL.CNF ℕ) (ch w m₀ m₁ m₂ : List Bool) :
                                                    allOpenFlags φ ch (realBits φ w m₀ m₁ m₂) = allOpenFlags φ ch (simBits φ ch (if ch.getD 0 false = true then BitString.listXor φ.vars.length [w, m₀] else m₀) (if ch.getD 1 false = true then BitString.listXor φ.vars.length [w, m₁] else m₁) (if ch.getD 2 false = true then BitString.listXor φ.vars.length [w, m₂] else m₂))
                                                    @[simp]
                                                    theorem Cslib.Crypto.GMW.naorMaskBits_simBits (φ : Logic.PL.CNF ℕ) (ch r₀ r₁ r₂ : List Bool) :
                                                    naorMaskBits (allOpenFlags φ ch (simBits φ ch r₀ r₁ r₂)) (simBits φ ch r₀ r₁ r₂) = simBits φ ch r₀ r₁ r₂
                                                    def Cslib.Crypto.GMW.proverReply1 (generator : List Bool → List Bool) (m : ℕ) (r openFlags bits : List Bool) (seeds pads : List (List Bool)) :

                                                    Prover's first-round message: flat list of totalLen φ Naor commitments.

                                                    Instances For
                                                      def Cslib.Crypto.GMW.proverReply2 (s : ℕ) (φ : Logic.PL.CNF ℕ) (ch bits : List Bool) (seeds : List (List Bool)) :

                                                      Prover's second-round message: masked bits followed by flat selected seeds.

                                                      Instances For
                                                        def Cslib.Crypto.GMW.verifyCommitments (generator : List Bool → List Bool) (s m : ℕ) (φ : Logic.PL.CNF ℕ) (r flags commitReply openedBits openSeedsFlat : List Bool) :

                                                        Check that every active position i < totalLen φ opens to the committed word in commitReply.

                                                        Instances For
                                                          def Cslib.Crypto.GMW.verifyTranscript (generator : List Bool → List Bool) (s m : ℕ) (φ : Logic.PL.CNF ℕ) (r commitReply ch openReply : List Bool) :

                                                          Verifier's complete check on the two-round interaction transcript.

                                                          Instances For
                                                            theorem Cslib.Crypto.GMW.length_proverReply2_any (s : ℕ) (φ : Logic.PL.CNF ℕ) (ch bits : List Bool) (seeds : List (List Bool)) :
                                                            (proverReply2 s φ ch bits seeds).length = bits.length * (s + 1)

                                                            Two-round deterministic state handler, honest prover, and honest verifier #

                                                            Deterministic two-round state transition answering the first query with reply1 q, the second query with reply2 (BitString.listRow 3 0 q) while recording the 3-bit challenge in the state, and subsequent queries with [].

                                                            Instances For

                                                              Run a WordOracleComp Unit program against twoRoundStep inside ProbComp.

                                                              Instances For
                                                                @[simp]
                                                                theorem Cslib.Crypto.GMW.runTwoRound_pure {α : Type} (reply1 reply2 : List Bool → List Bool) (a : α) (s : ℕ × List Bool) :
                                                                runTwoRound reply1 reply2 (pure a) s = pure (a, s)
                                                                theorem Cslib.Crypto.GMW.runTwoRound_bind {α β : Type} (reply1 reply2 : List Bool → List Bool) (prog : Probability.WordOracleComp Unit α) (next : α → Probability.WordOracleComp Unit β) (s : ℕ × List Bool) :
                                                                runTwoRound reply1 reply2 (prog >>= next) s = do let x ← runTwoRound reply1 reply2 prog s runTwoRound reply1 reply2 (next x.1) x.2
                                                                theorem Cslib.Crypto.GMW.runTwoRound_map {α β : Type} (reply1 reply2 : List Bool → List Bool) (f : α → β) (prog : Probability.WordOracleComp Unit α) (s : ℕ × List Bool) :
                                                                runTwoRound reply1 reply2 (f <$> prog) s = Prod.map f id <$> runTwoRound reply1 reply2 prog s
                                                                @[simp]
                                                                theorem Cslib.Crypto.GMW.runTwoRound_sample {α : Type} (reply1 reply2 : List Bool → List Bool) (prog : ProbComp α) (s : ℕ × List Bool) :
                                                                runTwoRound reply1 reply2 (ProbOracleComp.sample prog) s = (fun (x : α) => (x, s)) <$> prog
                                                                @[simp]
                                                                theorem Cslib.Crypto.GMW.runTwoRound_query (reply1 reply2 : List Bool → List Bool) (q : Unit × List Bool) (s : ℕ × List Bool) :
                                                                runTwoRound reply1 reply2 (ProbOracleComp.query q) s = pure (twoRoundStep reply1 reply2 q.2 s)
                                                                theorem Cslib.Crypto.GMW.eval_runTwoRound {α : Type} (reply1 reply2 : List Bool → List Bool) (prog : Probability.WordOracleComp Unit α) (s : ℕ × List Bool) :
                                                                (runTwoRound reply1 reply2 prog s).eval = ProbOracleComp.runWith (fun (q : Unit × List Bool) (state : ℕ × List Bool) => PMF.pure (twoRoundStep reply1 reply2 q.2 state)) prog s

                                                                Sample the honest prover's random masks and commitment seeds, returning (bits, seeds).

                                                                Instances For
                                                                  def Cslib.Crypto.GMW.honestReply1 (generator : List Bool → List Bool) (m : ℕ) (φ : Logic.PL.CNF ℕ) (coins : List Bool × List (List Bool)) (r : List Bool) :

                                                                  Honest first-round reply function for pre-sampled (bits, seeds).

                                                                  Instances For

                                                                    Honest second-round reply function for pre-sampled (bits, seeds).

                                                                    Instances For
                                                                      noncomputable def Cslib.Crypto.GMW.gmwProver (generator : List Bool → List Bool) (s m : ℕ) (φ : Logic.PL.CNF ℕ) (w : List Bool) :

                                                                      The honest GMW prover for a 3SAT formula φ and witness w. It samples its masks and commitment seeds on the first query and answers the two rounds via honestReply1 and honestReply2.

                                                                      Instances For
                                                                        theorem Cslib.Crypto.GMW.run_gmwProver_fst {α : Type} (generator : List Bool → List Bool) (s m : ℕ) (φ : Logic.PL.CNF ℕ) (w : List Bool) (prog : Probability.WordOracleComp Unit α) :
                                                                        PMF.map Prod.fst ((gmwProver generator s m φ w).run prog (gmwProver generator s m φ w).init) = (do let coins ← sampleHonestCoins s φ w Prod.fst <$> runTwoRound (honestReply1 generator m φ coins) (honestReply2 s φ coins) prog (0, [false, false, false])).eval
                                                                        noncomputable def Cslib.Crypto.GMW.gmwInteract (generator : List Bool → List Bool) (s m : ℕ) (φ : Logic.PL.CNF ℕ) (w : List Bool) (prog : Probability.WordOracleComp Unit (List Bool)) :

                                                                        The PPT program realizing the honest GMW prover's interaction with a verifier prog.

                                                                        Instances For
                                                                          theorem Cslib.Crypto.GMW.eval_gmwInteract (generator : List Bool → List Bool) (s m : ℕ) (φ : Logic.PL.CNF ℕ) (w : List Bool) (prog : Probability.WordOracleComp Unit (List Bool)) :
                                                                          (gmwInteract generator s m φ w prog).eval = PMF.map Prod.fst ((gmwProver generator s m φ w).run prog (gmwProver generator s m φ w).init)
                                                                          noncomputable def Cslib.Crypto.GMW.gmwVerifier {α : Type} (generator : List Bool → List Bool) (length : ℕ → ℕ) (f : α → Logic.PL.CNF ℕ) (n : ℕ) (a : α) :

                                                                          The two-round GMW verifier for a problem reduced to ThreeSAT by f, at security parameter n (using Naor commitments with seed length n + 7).

                                                                          Instances For