Skip to content

Commit 14d69c4

Browse files
Abraxas1010Richard Goodman
andauthored
fix(ProtocolSpec): prove the partial-transcript splitters and index equivalences for seqCompose (6 sorries removed) (#641)
- Transcript.fst / Transcript.snd: uniform cast-based definitions along two new transport lemmas append_Type_castAdd / append_Type_natAdd (no if-split, no Nat subtraction in types; signatures unchanged) - FullTranscript.rtake_append_right: dissolve the eqRec/cast residue via HEq - seqComposeChallengeEquiv.left_inv / seqComposeMessageEquiv.left_inv: rw! (castMode := .all) [Fin.splitSum_embedSum] + rfl Verified: full lake build ArkLib (4048 jobs) green; file now sorry-free. Co-authored-by: Richard Goodman <rgoodman@apoth3osis.io>
1 parent 2149367 commit 14d69c4

1 file changed

Lines changed: 33 additions & 17 deletions

File tree

ArkLib/OracleReduction/ProtocolSpec/SeqCompose.lean

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,18 @@ theorem rtake_append_right :
109109
simp only [rtake, Fin.vappend_eq_append]
110110
ext i : 2 <;> simp [Fin.rtake, Fin.append_right]
111111

112+
/-- Left type transport for `++ₚ` at a `castAdd` index: the appended spec's type
113+
at an index in the first half is the left spec's type. -/
114+
theorem append_Type_castAdd (i : Fin m) :
115+
(pSpec₁ ++ₚ pSpec₂).«Type» (Fin.castAdd n i) = pSpec₁.«Type» i := by
116+
simp only [Fin.vappend_eq_append, Fin.append_left]
117+
118+
/-- Right type transport for `++ₚ` at a `natAdd` index: the appended spec's type
119+
at an index in the second half is the right spec's type. -/
120+
theorem append_Type_natAdd (i : Fin n) :
121+
(pSpec₁ ++ₚ pSpec₂).«Type» (Fin.natAdd m i) = pSpec₂.«Type» i := by
122+
simp only [Fin.vappend_eq_append, Fin.append_right]
123+
112124
namespace Transcript
113125

114126
variable {k : Fin (m + n + 1)}
@@ -117,21 +129,20 @@ variable {k : Fin (m + n + 1)}
117129
118130
This is defined to be the full transcript for the first half if `k ≥ m`. -/
119131
def fst (T : (pSpec₁ ++ₚ pSpec₂).Transcript k) : pSpec₁.Transcript ⟨min k m, by omega⟩ :=
120-
if hk : k ≤ m then
121-
fun i => by
122-
dsimp [take]; have := T ⟨i, lt_of_lt_of_le i.isLt (inf_le_left)⟩; simp at this; sorry
123-
-- dcast (by sorry) (T ⟨i, lt_of_lt_of_le i.isLt (inf_le_left)⟩)
124-
else
125-
fun i => sorry
126-
-- dcast (by sorry) (T ⟨i, by omega⟩)
132+
fun i => by
133+
have him : (i : ℕ) < min (k : ℕ) m := i.isLt
134+
exact _root_.cast
135+
(append_Type_castAdd (pSpec₁ := pSpec₁) (pSpec₂ := pSpec₂) ⟨i.val, by omega⟩)
136+
(T ⟨i.val, by omega⟩)
127137

128138
/-- The second half of a partial transcript for a concatenated protocol. -/
129139
def snd (T : (pSpec₁ ++ₚ pSpec₂).Transcript k) : pSpec₂.Transcript ⟨k - m, by omega⟩ :=
130-
if hk : k ≤ m then
131-
fun i => Fin.elim0 (by simpa [hk] using i)
132-
else
133-
fun i => sorry
134-
-- dcast (by sorry) (T ⟨m + i, by simp_all; dsimp at i; have := i.isLt; omega⟩)
140+
fun i => by
141+
have him : (i : ℕ) < (k : ℕ) - m := i.isLt
142+
have hk := k.isLt
143+
exact _root_.cast
144+
(append_Type_natAdd (pSpec₁ := pSpec₁) (pSpec₂ := pSpec₂) ⟨i.val, by omega⟩)
145+
(T ⟨m + i.val, by omega⟩)
135146

136147
end Transcript
137148

@@ -186,7 +197,8 @@ theorem rtake_append_right (T : FullTranscript pSpec₁) (T' : FullTranscript pS
186197
simp [rtake, Fin.rtake, append, Fin.cast, FullTranscript.cast, Transcript.cast]
187198
have : ⟨m + n - n + i.val, by omega⟩ = Fin.natAdd m i := by ext; simp
188199
rw! (castMode := .all) [this, Fin.happend_right]
189-
sorry
200+
apply eq_of_heq
201+
exact ((eqRec_heq _ _).trans (cast_heq _ _)).trans (cast_heq _ _).symm
190202

191203
/-- The first half of a transcript for a concatenated protocol -/
192204
def fst (T : FullTranscript (pSpec₁ ++ₚ pSpec₂)) : FullTranscript pSpec₁ :=
@@ -496,8 +508,10 @@ def seqComposeChallengeEquiv {m : ℕ} {n : Fin m → ℕ} (pSpec : ∀ i, Proto
496508
toFun := fun ⟨i, j⟩ => sigmaChallengeIdxToSeqCompose i j
497509
invFun := seqComposeChallengeIdxToSigma
498510
left_inv := by
499-
intro ⟨_, _⟩; simp [seqComposeChallengeIdxToSigma, sigmaChallengeIdxToSeqCompose]
500-
sorry
511+
intro ⟨i, j⟩
512+
simp only [seqComposeChallengeIdxToSigma, sigmaChallengeIdxToSeqCompose]
513+
rw! (castMode := .all) [Fin.splitSum_embedSum i j.1]
514+
rfl
501515
right_inv := by intro; simp [seqComposeChallengeIdxToSigma, sigmaChallengeIdxToSeqCompose]
502516

503517
def sigmaMessageIdxToSeqCompose {m : ℕ} {n : Fin m → ℕ} {pSpec : ∀ i, ProtocolSpec (n i)}
@@ -520,8 +534,10 @@ def seqComposeMessageEquiv {m : ℕ} {n : Fin m → ℕ} {pSpec : ∀ i, Protoco
520534
toFun := fun ⟨i, msgIdx⟩ => sigmaMessageIdxToSeqCompose i msgIdx
521535
invFun := seqComposeMessageIdxToSigma
522536
left_inv := by
523-
intro ⟨i, ⟨j, h⟩⟩ ; simp [seqComposeMessageIdxToSigma, sigmaMessageIdxToSeqCompose]
524-
sorry
537+
intro ⟨i, j⟩
538+
simp only [seqComposeMessageIdxToSigma, sigmaMessageIdxToSeqCompose]
539+
rw! (castMode := .all) [Fin.splitSum_embedSum i j.1]
540+
rfl
525541
right_inv := by intro; simp [seqComposeMessageIdxToSigma, sigmaMessageIdxToSeqCompose]
526542

527543
instance {m : ℕ} {n : Fin m → ℕ} {pSpec : ∀ i, ProtocolSpec (n i)}

0 commit comments

Comments
 (0)