Skip to content

Commit 238e88a

Browse files
committed
Merge remote-tracking branch 'origin/Ferinko/ElijahVlasov/johnson' into ElijahVlasov/johnson
2 parents 3be455c + eb2cbd0 commit 238e88a

85 files changed

Lines changed: 9453 additions & 3350 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@
1616

1717
# LaTeX PDF files for blueprint
1818
# *print.pdf
19-
/blueprint/src/web.pdf
19+
/blueprint/src/web.pdf
20+
21+
.nvim.lua

.vscode/settings.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"editor.insertSpaces": true,
3+
"editor.tabSize": 2,
4+
"editor.rulers" : [100],
5+
"editor.acceptSuggestionOnEnter": "smart",
6+
"files.encoding": "utf8",
7+
"files.eol": "\n",
8+
"files.insertFinalNewline": true,
9+
"files.trimFinalNewlines": true,
10+
"files.trimTrailingWhitespace": true,
11+
"git.ignoreLimitWarning": true,
12+
"files.readonlyInclude": {
13+
"**/.elan/**": true,
14+
"**/.lake/**": true
15+
}
16+
}

ArkLib.lean

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ import ArkLib.Data.CodingTheory.JohnsonBound
1010
import ArkLib.Data.CodingTheory.ProximityGap
1111
import ArkLib.Data.CodingTheory.ReedMuller
1212
import ArkLib.Data.CodingTheory.ReedSolomon
13+
import ArkLib.Data.CodingTheory
1314
import ArkLib.Data.EllipticCurve.BN254
1415
import ArkLib.Data.FieldTheory.BinaryTowerField.Basic
1516
import ArkLib.Data.FieldTheory.BinaryTowerField.Prelude
16-
import ArkLib.Data.FieldTheory.FFT
1717
import ArkLib.Data.FieldTheory.NonBinaryField.BLS12_377
1818
import ArkLib.Data.FieldTheory.NonBinaryField.BLS12_381
1919
import ArkLib.Data.FieldTheory.NonBinaryField.BN254
@@ -23,9 +23,9 @@ import ArkLib.Data.FieldTheory.NonBinaryField.Goldilocks
2323
import ArkLib.Data.FieldTheory.NonBinaryField.Mersenne
2424
import ArkLib.Data.FieldTheory.NonBinaryField.Secp256k1
2525
import ArkLib.Data.Fin.Basic
26-
import ArkLib.Data.Math.Fin
26+
import ArkLib.Data.Math.Basic
27+
import ArkLib.Data.Math.DepCast
2728
import ArkLib.Data.Math.HList
28-
import ArkLib.Data.Math.Operations
2929
import ArkLib.Data.MlPoly.Basic
3030
import ArkLib.Data.MlPoly.Equiv
3131
import ArkLib.Data.MvPolynomial.Degrees
@@ -40,15 +40,24 @@ import ArkLib.Data.UniPoly.Basic
4040
import ArkLib.Data.UniPoly.BasicOld
4141
import ArkLib.Data.UniPoly.PolynomialReflection
4242
import ArkLib.OracleReduction.Basic
43-
import ArkLib.OracleReduction.Composition.Sequential
44-
import ArkLib.OracleReduction.Composition.Virtual
43+
import ArkLib.OracleReduction.Cast
44+
import ArkLib.OracleReduction.Composition.Parallel.Basic
45+
import ArkLib.OracleReduction.Composition.Sequential.Append
46+
import ArkLib.OracleReduction.Composition.Sequential.General
47+
import ArkLib.OracleReduction.Composition.Sequential.ProtocolSpec
4548
import ArkLib.OracleReduction.Equiv
4649
import ArkLib.OracleReduction.Execution
50+
import ArkLib.OracleReduction.LiftContext.Basic
4751
import ArkLib.OracleReduction.OracleInterface
4852
import ArkLib.OracleReduction.Prelude
4953
import ArkLib.OracleReduction.Security.Basic
54+
import ArkLib.OracleReduction.Transform.BCS
55+
import ArkLib.OracleReduction.Transform.FiatShamir
5056
import ArkLib.OracleReduction.VectorIOR
51-
import ArkLib.ProofSystem.Components
57+
import ArkLib.ProofSystem.Component.CheckPred
58+
import ArkLib.ProofSystem.Component.RandomQuery
59+
import ArkLib.ProofSystem.Component.SendClaim
60+
import ArkLib.ProofSystem.Component.SendWitness
5261
import ArkLib.ProofSystem.ConstraintSystem.IndexedLookup
5362
import ArkLib.ProofSystem.ConstraintSystem.Plonk
5463
import ArkLib.ProofSystem.ConstraintSystem.R1CS
@@ -57,11 +66,11 @@ import ArkLib.ProofSystem.Fri.RoundConsistency
5766
import ArkLib.ProofSystem.Plonk.Basic
5867
import ArkLib.ProofSystem.Spartan.Basic
5968
import ArkLib.ProofSystem.Sumcheck.Basic
69+
import ArkLib.ProofSystem.Sumcheck.SingleRound
70+
import ArkLib.ToMathlib.BigOperators.Fin
6071
import ArkLib.ToMathlib.Finset.Basic
6172
import ArkLib.ToMathlib.Finsupp.Fin
6273
import ArkLib.ToMathlib.MvPolynomial.Equiv
6374
import ArkLib.ToMathlib.NumberTheory.PrattCertificate
6475
import ArkLib.ToMathlib.UInt.Equiv
6576
import ArkLib.ToVCVio.Oracle
66-
import ArkLib.Transform.BCS
67-
import ArkLib.Transform.FiatShamir

ArkLib/CommitmentScheme/Fold.lean

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import ArkLib.Data.CodingTheory.ProximityGap
1414
/-!
1515
# Folding-based Polynomial Commitment Schemes
1616
17+
NOTE: this file should be deprecated now in favor of newer developments on FRI/STIR/WHIR in
18+
`ProofSystem`
19+
1720
We define the folding IOP underlying polynomial commitment schemes such as FRI, Circle-FRI,
1821
BaseFold, FRI-Binius, and so on.
1922
@@ -75,13 +78,13 @@ instance : IsSingleRound (pSpec R n) where
7578
/-- Recognize that the (only) message from the prover to the verifier has type `Vector R (2 ^ n)`,
7679
and hence can be turned into an oracle for evaluating the polynomial -/
7780
instance instOracleInterfaceMessagePSpec : OracleInterface ((pSpec R n).Message default) := by
78-
simp only [pSpec, default, Matrix.cons_val_zero, Message, getType]
81+
simp [pSpec, default, Message, getType]
7982
exact instOracleInterfaceVector
8083

8184
/-- Recognize that the challenge from the verifier to the prover has type `R`, and hence can be
8285
sampled uniformly at random -/
8386
instance instSampleableChallengePSpec : Sampleable ((pSpec R n).Challenge default) := by
84-
simp only [pSpec, default, Matrix.cons_val_one, Matrix.head_cons, Challenge, getType]
87+
simp [Challenge, pSpec, default]
8588
infer_instance
8689

8790
structure PrvState (k : Fin n) where

ArkLib/CommitmentScheme/MerkleTree.lean

Lines changed: 101 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Authors: Quang Dao
55
-/
66

77
import VCVio
8-
import ArkLib.Data.Math.Operations
8+
import ArkLib.Data.Math.Basic
99
import ArkLib.CommitmentScheme.Basic
1010
import Mathlib.Data.Vector.Snoc
1111

@@ -181,72 +181,112 @@ def verifyProof {n : ℕ} (i : Fin (2 ^ n)) (leaf : α) (root : α) (proof : Lis
181181
let putative_root ← getPutativeRoot α i leaf proof
182182
guard (putative_root = root)
183183

184-
-- Belongs in VCVio, not sure if its already there somewhwere
185-
def implement_with_function (hash : α × α -> α) : QueryImpl (spec α) (StateT Unit (OracleComp (emptySpec))) where
186-
impl q := match q with
187-
| ⟨_, ⟨left, right⟩⟩ =>
188-
do
189-
let out := hash (left, right)
190-
return out
191184

185+
theorem buildLayer_neverFails (α : Type) [inst : DecidableEq α] [inst_1 : SelectableType α]
186+
(preexisting_cache : (spec α).QueryCache) (n : ℕ)
187+
(leaves : List.Vector α (2 ^ (n + 1))) :
188+
((simulateQ randomOracle (buildLayer α n leaves)).run preexisting_cache).neverFails := by
189+
simp_rw [buildLayer]
190+
simp [neverFails_query_bind]
191+
-- I now require a "neverFails_mmap_iff" lemma, but I don't see one in VCVio.
192+
-- Feels like evidence for avoiding Vector-based merkle trees in favor of inductive-based ones.
193+
sorry
194+
195+
/--
196+
Building a Merkle tree never results in failure
197+
(no matter what queries have already been made to the oracle before it runs).
198+
-/
199+
theorem buildMerkleTree_neverFails (α : Type) [DecidableEq α] [SelectableType α] {n : ℕ}
200+
(leaves : List.Vector α (2 ^ n)) (preexisting_cache : (spec α).QueryCache) :
201+
((simulateQ randomOracle (buildMerkleTree α n leaves)).run preexisting_cache).neverFails := by
202+
-- It feels like there should be some kind of tactic that inspects the structure of the
203+
-- `buildMerkleTree` definition to see that it never even mentions failure,
204+
-- and therefore can't fail.
205+
induction n generalizing preexisting_cache with
206+
| zero =>
207+
simp [buildMerkleTree, getRoot, generateProof, verifyProof, getPutativeRoot]
208+
| succ n ih =>
209+
simp [buildMerkleTree, neverFails_bind_iff]
210+
constructor
211+
· exact buildLayer_neverFails α preexisting_cache n leaves
212+
· intro next_leaves next_cache h_mem_support
213+
apply ih
192214

193215
/-- Completeness theorem for Merkle trees: for any full binary tree with `2 ^ n` leaves, and for any
194-
index `i`, the verifier accepts the opening proof at index `i` generated by the prover. -/
195-
theorem completeness {n : ℕ} (leaves : List.Vector α (2 ^ n)) (i : Fin (2 ^ n)) (hash : α × α -> α) :
196-
((do
216+
index `i`, the verifier accepts the opening proof at index `i` generated by the prover.
217+
-/
218+
theorem completeness [SelectableType α] {n : ℕ}
219+
(leaves : List.Vector α (2 ^ n)) (i : Fin (2 ^ n)) (hash : α × α -> α)
220+
(preexisting_cache : (spec α).QueryCache) :
221+
(((do
197222
let cache ← buildMerkleTree α n leaves
198223
let proof := generateProof α i cache
199224
let verif ← verifyProof α i leaves[i] (getRoot α cache) proof).simulateQ
200-
(implement_with_function α hash)
201-
()).neverFails := by
202-
induction n with
203-
| zero =>
204-
simp [buildMerkleTree, getRoot, generateProof, verifyProof, getPutativeRoot]
205-
have : i = 0 := by aesop
206-
subst i
207-
simp [Fin.instGetElemFinVal]
208-
-- TODO: the below is not necessary once `neverFails` lemmas are (re-)added
209-
unfold neverFails neverFailsWhen allWhen OracleComp.construct FreeMonad.construct
210-
simp [pure, StateT.pure, OptionT.pure, OptionT.mk]
211-
| succ n ih =>
212-
-- simp_all [Fin.getElem_fin, Vector.getElem_eq_get, Fin.eta, getRoot, Fin.val_zero,
213-
-- Nat.pow_zero, Fin.zero_eta, Vector.get_zero, bind_pure_comp, id_map', probFailure_eq_zero_iff,
214-
-- neverFails_bind_iff, buildMerkleTree, generateProof, LawfulMonad.bind_assoc, bind_map_left,
215-
-- Cache.upper_cons, Cache.leaves_cons]
216-
-- refine ⟨?_, ?_
217-
-- ·
218-
simp [buildLayer, simulateQ, simulateQ, implement_with_function]
219-
sorry
220-
221-
-- · intro newLeaves h_newLeaves
222-
-- let i' : Fin (2 ^ n) := i.val / 2
223-
-- specialize ih newLeaves i'
224-
-- rcases ih with ⟨ih', ih⟩
225-
-- sorry
226-
-- refine ⟨?_, ?_
227-
-- · exact ih'
228-
-- · intro cache h_cache
229-
-- specialize ih cache h_cache
230-
-- unfold verifyProof
231-
-- simp only [guard_eq, neverFails_bind_iff]
232-
-- unfold verifyProof at ih
233-
-- simp only [guard_eq, neverFails_bind_iff] at ih
234-
-- rcases ih with ⟨ih_getroot, ih_cmp⟩
235-
-- refine ⟨?_, ?_
236-
-- · -- I think this just needs a simple lemma about `getPutativeRoot`
237-
-- sorry
238-
-- · intro root h_root
239-
-- specialize ih_cmp root
240-
-- have : root ∈ (getPutativeRoot α i'
241-
-- (newLeaves.get i') (generateProof α i' cache)).support := by
242-
243-
-- sorry
244-
-- specialize ih_cmp this
245-
-- simp [apply_ite] at ih_cmp
246-
-- rw [ih_cmp]
247-
-- simp [apply_ite]
248-
-- simp [Cache.cons]
249-
-- sorry
225+
(randomOracle)).run preexisting_cache).neverFails := by
226+
simp [neverFails_bind_iff]
227+
constructor
228+
· -- buildMerkleTree never fails
229+
exact buildMerkleTree_neverFails α leaves preexisting_cache
230+
· -- verifyProof never fails on the output of generateProof after buildMerkleTree
231+
intros merkle_tree_cache query_cache h_mem_support
232+
-- Need a theorem to characterize
233+
-- `((simulateQ randomOracle (buildMerkleTree α n leaves)).run preexisting_cache).support`
234+
-- i.e.
235+
-- - All merkle_tree_cache parent-child relationships are in the query_cache
236+
-- - Everything in the preexisting_cache is in the query_cache
237+
-- - Nothing else is in the query_cache
238+
sorry
239+
240+
241+
242+
243+
244+
245+
-- induction n with
246+
-- | zero =>
247+
-- simp [buildMerkleTree, getRoot, generateProof, verifyProof, getPutativeRoot]
248+
-- have : i = 0 := by aesop
249+
-- subst i
250+
-- simp [Fin.instGetElemFinVal]
251+
-- | succ n ih =>
252+
-- -- simp_all [Fin.getElem_fin, Vector.getElem_eq_get, Fin.eta, getRoot, Fin.val_zero,
253+
-- -- Nat.pow_zero, Fin.zero_eta, Vector.get_zero, bind_pure_comp, id_map', probFailure_eq_zero_iff,
254+
-- -- neverFails_bind_iff, buildMerkleTree, generateProof, LawfulMonad.bind_assoc, bind_map_left,
255+
-- -- Cache.upper_cons, Cache.leaves_cons]
256+
-- -- refine ⟨?_, ?_
257+
-- -- ·
258+
-- simp [buildLayer, simulateQ, simulateQ, implement_with_function]
259+
-- sorry
260+
261+
-- -- · intro newLeaves h_newLeaves
262+
-- -- let i' : Fin (2 ^ n) := i.val / 2
263+
-- -- specialize ih newLeaves i'
264+
-- -- rcases ih with ⟨ih', ih⟩
265+
-- -- sorry
266+
-- -- refine ⟨?_, ?_
267+
-- -- · exact ih'
268+
-- -- · intro cache h_cache
269+
-- -- specialize ih cache h_cache
270+
-- -- unfold verifyProof
271+
-- -- simp only [guard_eq, neverFails_bind_iff]
272+
-- -- unfold verifyProof at ih
273+
-- -- simp only [guard_eq, neverFails_bind_iff] at ih
274+
-- -- rcases ih with ⟨ih_getroot, ih_cmp⟩
275+
-- -- refine ⟨?_, ?_
276+
-- -- · -- I think this just needs a simple lemma about `getPutativeRoot`
277+
-- -- sorry
278+
-- -- · intro root h_root
279+
-- -- specialize ih_cmp root
280+
-- -- have : root ∈ (getPutativeRoot α i'
281+
-- -- (newLeaves.get i') (generateProof α i' cache)).support := by
282+
283+
-- -- sorry
284+
-- -- specialize ih_cmp this
285+
-- -- simp [apply_ite] at ih_cmp
286+
-- -- rw [ih_cmp]
287+
-- -- simp [apply_ite]
288+
-- -- simp [Cache.cons]
289+
-- -- sorry
250290

251291

252292
-- theorem soundness (i : Fin (2 ^ n)) (leaf : α) (proof : Vector α n) :

ArkLib/Data/CodingTheory.lean

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import ArkLib.Data.CodingTheory.Basic
2+
import ArkLib.Data.CodingTheory.BerlekampWelch
3+
import ArkLib.Data.CodingTheory.BivariatePoly
4+
import ArkLib.Data.CodingTheory.DivergenceOfSets
5+
import ArkLib.Data.CodingTheory.InterleavedCode
6+
import ArkLib.Data.CodingTheory.ListDecodability
7+
import ArkLib.Data.CodingTheory.Prelims
8+
import ArkLib.Data.CodingTheory.ProximityGap
9+
import ArkLib.Data.CodingTheory.PolishchukSpielman
10+
import ArkLib.Data.CodingTheory.ReedMuller
11+
import ArkLib.Data.CodingTheory.ReedSolomon

0 commit comments

Comments
 (0)