cfahlgren1's picture
download
raw
35.9 kB
17
inductive Work
body · 6 lines
  | transition (tape : TransitionArena.Tape)
  | validity (index : Fin 7)
  | cells (index : Fin 9)
  | finish (tape : CircuitFinish.Tape)
  | bootstrap
  deriving DecidableEq, Fintype
25
abbrev Tape (V : NPVerifier) := VerifierFront.Tape V ⊕ Work
26
abbrev Alphabet (V : NPVerifier) (_ : Tape V) := Bool
27
abbrev State := TermMachine.State
28
abbrev initialState : State := TermMachine.initialState
30
def frontPorts (V : NPVerifier) : VerifierFront.Tape V ↪ Tape V :=
body · 1 line
  ⟨Sum.inl, Sum.inl_injective⟩
33
def raw (V : NPVerifier) : Tape V := .inl (VerifierFront.raw V)
34
def framed (V : NPVerifier) : Tape V := .inl (VerifierFront.stream V)
35
def clock (V : NPVerifier) (c : ClockPreparation.Clock) : Tape V :=
body · 1 line
  .inl (VerifierFront.clockTape V c)
37
def q (V : NPVerifier) : Tape V := clock V .witness
38
def capacity (V : NPVerifier) : Tape V := clock V .capacity
39
def countdown (V : NPVerifier) : Tape V := clock V .horizon
40
def freeInputs (V : NPVerifier) : Tape V := clock V .inputCount
42
def shared (V : NPVerifier) (t : ForestStage.Tape) : Tape V :=
body · 1 line
  .inr (.transition (.inl t))
44
def current (V : NPVerifier) : Tape V := shared V (.lower .current)
45
def roots (V : NPVerifier) : Tape V := shared V .rootTable
46
def records (V : NPVerifier) : Tape V := shared V .records
47
def tokens (V : NPVerifier) : Tape V := shared V .tokens
48
def count (V : NPVerifier) : Tape V := shared V (.lower .remaining)
49
def cursor (V : NPVerifier) : Tape V := .inr (.transition (.inr .cursor))
50
def output (V : NPVerifier) : Tape V := .inr (.finish .output)
52
theorem clock_injective (V : NPVerifier) : Function.Injective (clock V) := by
proof · 4 lines
  intro a b h
  have hs := (VerifierFront.clockSlots V).injective (Sum.inl.inj h)
  have ho := ClockPreparation.outputSlot_injective _ hs
  cases a <;> cases b <;> simp_all [ClockPreparation.clockOutput] <;> cases ho
58
@[simp] theorem clock_eq_iff (V : NPVerifier) (a b : ClockPreparation.Clock) :
    clock V a = clock V b ↔ a = b := (clock_injective V).eq_iff
61
@[simp] theorem clock_ne_raw (V : NPVerifier) (c : ClockPreparation.Clock) :
    clock V c ≠ raw V := by
proof · 1 line
  simp [clock, raw, VerifierFront.clockTape, VerifierFront.clockSlots, VerifierFront.raw]
65
@[simp] theorem raw_ne_clock (V : NPVerifier) (c : ClockPreparation.Clock) :
    raw V ≠ clock V c := (clock_ne_raw V c).symm
68
@[simp] theorem clock_ne_framed (V : NPVerifier) (c : ClockPreparation.Clock) :
    clock V c ≠ framed V := by
proof · 1 line
  simp [clock, framed, VerifierFront.clockTape, VerifierFront.clockSlots, VerifierFront.stream]
72
@[simp] theorem framed_ne_clock (V : NPVerifier) (c : ClockPreparation.Clock) :
    framed V ≠ clock V c := (clock_ne_framed V c).symm
75
@[simp] theorem raw_ne_framed (V : NPVerifier) : raw V ≠ framed V := by
proof · 1 line
  simp [raw, framed, VerifierFront.raw, VerifierFront.stream]
78
def transitionTape (V : NPVerifier) : TransitionArena.Tape → Tape V
body · 5 lines
  | .inr .raw => raw V
  | .inr .q => q V
  | .inr .capacity => capacity V
  | .inr .countdown => countdown V
  | t => .inr (.transition t)
85
def transitionPorts (V : NPVerifier) : TransitionArena.Tape ↪ Tape V where
body · 21 lines
  toFun := transitionTape V
  inj' := by
    intro a b h
    cases a with
    | inl a =>
      cases b with
      | inl b => simpa [transitionTape] using h
      | inr b =>
        cases b <;>
          simp_all [transitionTape, raw, q, capacity, countdown, clock]
    | inr a =>
      cases b with
      | inl b =>
        cases a <;>
          simp_all [transitionTape, raw, q, capacity, countdown, clock]
      | inr b =>
        cases a <;> cases b <;>
          simp_all [transitionTape, q, capacity, countdown, raw, clock,
            VerifierFront.raw, VerifierFront.clockTape, VerifierFront.clockSlots,
            ClockPreparation.clockOutput] <;>
          cases h
108
@[simp] theorem transitionPorts_apply (V : NPVerifier) (t : TransitionArena.Tape) :
    transitionPorts V t = transitionTape V t := rfl
111
def forestPorts (V : NPVerifier) : ForestStage.Tape ↪ Tape V :=
body · 1 line
  TransitionArena.forestPorts.trans (transitionPorts V)
114
def termPorts (V : NPVerifier) : TermMachine.Tape ↪ Tape V :=
body · 1 line
  TransitionArena.termPorts.trans (transitionPorts V)
117
def initializationTape (V : NPVerifier) : InitializationAssembly.Tape 9 → Tape V
body · 8 lines
  | .rawInput => raw V
  | .framedInput => framed V
  | .witnessBound => q V
  | .capacity => capacity V
  | .reversed => tokens V
  | .count => count V
  | .validityWork j => .inr (.validity j)
  | .cellWork j => .inr (.cells j)
127
def initializationPorts (V : NPVerifier) : InitializationAssembly.Tape 9 ↪ Tape V where
body · 11 lines
  toFun := initializationTape V
  inj' := by
    intro a b h
    cases a <;> cases b <;>
      simp_all [initializationTape, q, capacity, tokens, count, shared,
        raw, framed, clock, VerifierFront.raw, VerifierFront.stream,
        VerifierFront.clockTape, VerifierFront.clockSlots,
        ClockPreparation.clockOutput]
    all_goals
      have ho := ClockPreparation.outputSlot_injective (ClockPreparation.clockPolynomials V) h
      cases ho
140
@[simp] theorem initializationPorts_apply (V : NPVerifier) (t : InitializationAssembly.Tape 9) :
    initializationPorts V t = initializationTape V t := rfl
143
def finishTape (V : NPVerifier) : CircuitFinish.Tape → Tape V
body · 7 lines
  | .current => current V
  | .freeInputs => freeInputs V
  | .root => roots V
  | .reversedRecords => records V
  | .output => output V
  | .gateCount => .inr (.finish .gateCount)
  | .scratch => .inr (.finish .scratch)
152
def finishPorts (V : NPVerifier) : CircuitFinish.Tape ↪ Tape V where
body · 5 lines
  toFun := finishTape V
  inj' := by
    intro a b h
    cases a <;> cases b <;>
      simp_all [finishTape, current, freeInputs, roots, records, output, shared, clock]
159
@[simp] theorem finishPorts_apply (V : NPVerifier) (t : CircuitFinish.Tape) :
    finishPorts V t = finishTape V t := rfl
162
def bootstrapPorts (V : NPVerifier) : ProducerBootstrap.Ports (Tape V) where
body · 5 lines
  toFun := ![freeInputs V, current V, .inr .bootstrap, count V, cursor V]
  inj' := by
    intro a b h
    fin_cases a <;> fin_cases b <;>
      simp_all [freeInputs, current, count, cursor, shared, clock]
169
@[simp] theorem bootstrap_source (V : NPVerifier) : bootstrapPorts V 0 = freeInputs V := rfl
170
@[simp] theorem bootstrap_current (V : NPVerifier) : bootstrapPorts V 1 = current V := rfl
171
@[simp] theorem bootstrap_scratch (V : NPVerifier) :
    bootstrapPorts V 2 = .inr .bootstrap := rfl
173
@[simp] theorem bootstrap_count (V : NPVerifier) : bootstrapPorts V 3 = count V := rfl
174
@[simp] theorem bootstrap_cursor (V : NPVerifier) : bootstrapPorts V 4 = cursor V := rfl
176
def empty (V : NPVerifier) : Tape V → List Bool := fun _ => []
178
def frontTapes (V : NPVerifier) (contents : VerifierFront.Tape V → List Bool) :
    Tape V → List Bool
body · 2 lines
  | .inl t => contents t
  | .inr _ => []
183
@[simp] theorem frontTapes_at (V : NPVerifier)
    (contents : VerifierFront.Tape V → List Bool) (t : VerifierFront.Tape V) :
    frontTapes V contents (frontPorts V t) = contents t := rfl
187
@[simp] theorem frontTapes_work (V : NPVerifier)
    (contents : VerifierFront.Tape V → List Bool) (t : Work) :
    frontTapes V contents (.inr t) = [] := rfl
191
theorem front_fill (V : NPVerifier) (contents : VerifierFront.Tape V → List Bool) :
    ForestPlacement.fill (frontPorts V) (empty V) contents = frontTapes V contents := by
proof · 6 lines
  funext t
  cases t with
  | inl t => exact ForestPlacement.fill_at (frontPorts V) (empty V) contents t
  | inr t =>
    exact ForestPlacement.fill_other (frontPorts V) (empty V) contents _
      (by intro i; simp [frontPorts])
200
def initialTapes (V : NPVerifier) (input : List Bool) : Tape V → List Bool :=
body · 1 line
  frontTapes V (VerifierFront.frameTapes V input)
203
theorem initialTapes_eq (V : NPVerifier) (input : List Bool) :
    initialTapes V input = fun t => if t = raw V then input else [] := by
proof · 8 lines
  funext t
  cases t with
  | inl t =>
    cases t with
    | inl i => fin_cases i <;> simp [initialTapes, frontTapes, VerifierFront.frameTapes,
        raw, VerifierFront.raw]
    | inr t => simp [initialTapes, frontTapes, VerifierFront.frameTapes, raw, VerifierFront.raw]
  | inr t => simp [initialTapes, frontTapes, raw]
214
def frontendPrepared (V : NPVerifier) (input : List Bool) : Tape V → List Bool :=
body · 1 line
  frontTapes V (VerifierFront.preparedTapes V input)
217
@[simp] theorem frontendPrepared_raw (V : NPVerifier) (input : List Bool) :
    frontendPrepared V input (raw V) = input := VerifierFront.prepared_raw V input
220
@[simp] theorem frontendPrepared_framed (V : NPVerifier) (input : List Bool) :
    frontendPrepared V input (framed V) = encodeWord input.length ++ input :=
proof · 1 line
  VerifierFront.prepared_stream V input
224
@[simp] theorem frontendPrepared_clock (V : NPVerifier) (input : List Bool)
    (c : ClockPreparation.Clock) : frontendPrepared V input (clock V c) =
      encodeWord (ClockPreparation.clockValue V input.length c) :=
proof · 1 line
  VerifierFront.prepared_clock V input c
229
@[simp] theorem frontendPrepared_work (V : NPVerifier) (input : List Bool) (t : Work) :
    frontendPrepared V input (.inr t) = [] := rfl
232
theorem bootstrapReady (V : NPVerifier) (input : List Bool) :
    ProducerBootstrap.Ready (bootstrapPorts V) (frontendPrepared V input)
      (2 * V.witnessBound.eval input.length + 1) := by
proof · 1 line
  exact ⟨frontendPrepared_clock V input .inputCount, rfl, rfl, rfl, rfl⟩
237
def bootstrapPrepared (V : NPVerifier) (input : List Bool) : Tape V → List Bool :=
body · 1 line
  ProducerBootstrap.prepared (bootstrapPorts V) (frontendPrepared V input)
240
@[simp] theorem bootstrapPrepared_front (V : NPVerifier) (input : List Bool)
    (t : VerifierFront.Tape V) :
    bootstrapPrepared V input (frontPorts V t) = VerifierFront.preparedTapes V input t := by
proof · 2 lines
  apply ProducerBootstrap.prepared_other
  all_goals simp [frontPorts, bootstrapPorts, current, count, cursor, shared]
246
@[simp] theorem bootstrapPrepared_current (V : NPVerifier) (input : List Bool) :
    bootstrapPrepared V input (current V) =
      encodeWord (2 * V.witnessBound.eval input.length + 1) :=
proof · 2 lines
  ProducerBootstrap.prepared_current (bootstrapPorts V) (frontendPrepared V input) _
    (bootstrapReady V input)
252
@[simp] theorem bootstrapPrepared_count (V : NPVerifier) (input : List Bool) :
    bootstrapPrepared V input (count V) = encodeWord 0 :=
proof · 2 lines
  ProducerBootstrap.prepared_count (bootstrapPorts V) (frontendPrepared V input) _
    (bootstrapReady V input)
257
@[simp] theorem bootstrapPrepared_cursor (V : NPVerifier) (input : List Bool) :
    bootstrapPrepared V input (cursor V) = encodeWord 0 :=
proof · 2 lines
  ProducerBootstrap.prepared_cursor (bootstrapPorts V) (frontendPrepared V input) _
    (bootstrapReady V input)
262
theorem bootstrapPrepared_other (V : NPVerifier) (input : List Bool) (t : Tape V)
    (hc : t ≠ current V) (ht : t ≠ count V) (hz : t ≠ cursor V) :
    bootstrapPrepared V input t = frontendPrepared V input t :=
proof · 1 line
  ProducerBootstrap.prepared_other (bootstrapPorts V) (frontendPrepared V input) t hc ht hz
267
def initializationBase (V : NPVerifier) (input : List Bool) :
    InitializationAssembly.Tape 9 → List Bool
body · 6 lines
  | .rawInput => input
  | .framedInput => encodeWord input.length ++ input
  | .witnessBound => encodeWord (V.witnessBound.eval input.length)
  | .capacity => encodeWord (VerifierCircuit.capacity V input.length)
  | .count => encodeWord 0
  | _ => []
276
theorem bootstrap_initialization_view (V : NPVerifier) (input : List Bool) :
    (fun t => bootstrapPrepared V input (initializationPorts V t)) =
      initializationBase V input := by
proof · 8 lines
  funext t
  cases t <;>
    simp [initializationTape, initializationBase, bootstrapPrepared,
      ProducerBootstrap.prepared, ProducerBootstrap.copied,
      frontendPrepared, frontTapes, current, count, cursor, tokens, shared,
      raw, framed, q, capacity, freeInputs, clock,
      VerifierFront.prepared_raw, VerifierFront.prepared_stream, VerifierFront.prepared_clock,
      ClockPreparation.clockValue, encodeWord]
288
theorem initializationValidityReady (V : NPVerifier) (input : List Bool) :
    ClashMachine.Full.Ready (InitializationAssembly.validitySlots 9)
      (fun t => bootstrapPrepared V input (initializationPorts V t))
      (V.witnessBound.eval input.length) := by
proof · 2 lines
  rw [bootstrap_initialization_view]
  exact InitializationAssembly.validityReady _ _ rfl (fun _ => rfl)
302
abbrev Label (V : NPVerifier) := VerifierFront.Label V ⊕ ProducerBootstrap.Label
304
def entry (V : NPVerifier) : Label V := .inl (.inl 0)
306
def statement {Λ : Type} (V : NPVerifier) (labels : Label V → Λ) (exit : Option Λ) :
    Label V → TM2.Stmt (Alphabet V) Λ State
body · 3 lines
  | .inl l => ForestPlacement.statement (frontPorts V) (fun l => labels (.inl l))
      (some (labels (.inr .copy))) (VerifierFront.program (A := Unit × Bool) V l)
  | .inr l => ProducerBootstrap.statement (bootstrapPorts V) (fun l => labels (.inr l)) exit l
312
def timePolynomial (V : NPVerifier) : Polynomial Nat :=
body · 2 lines
  VerifierFront.timePolynomial V +
    Polynomial.C 2 * WitnessEncoding.freeInputPolynomial V.witnessBound + Polynomial.C 5
316
theorem timePolynomial_eval (V : NPVerifier) (n : Nat) :
    (timePolynomial V).eval n = (VerifierFront.timePolynomial V).eval n +
      (2 * (2 * V.witnessBound.eval n + 1) + 5) := by
proof · 1 line
  simp [timePolynomial, Nat.add_assoc]
321
def inTime {Λ : Type} (V : NPVerifier) (labels : Label V → Λ) (exit : Option Λ)
    (program : Λ → TM2.Stmt (Alphabet V) Λ State)
    (code : ∀ l, program (labels l) = statement V labels exit l)
    (input : List Bool) :
    StateTransition.EvalsToInTime (TM2.step program)
      ⟨some (labels (entry V)), initialState, initialTapes V input⟩
      (some ⟨exit, initialState, bootstrapPrepared V input⟩)
      ((timePolynomial V).eval input.length) := by
body · 17 lines
  have front := ForestPlacement.execution (frontPorts V)
    (fun l => labels (.inl l)) (some (labels (.inr .copy))) (empty V)
    (VerifierFront.program (A := Unit × Bool) V) program (fun l => code (.inl l))
    (VerifierFront.prepareInTime V input ((), false))
  have front' : StateTransition.EvalsToInTime (TM2.step program)
      ⟨some (labels (entry V)), initialState, initialTapes V input⟩
      (some ⟨some (labels (.inr .copy)), initialState, frontendPrepared V input⟩)
      ((VerifierFront.timePolynomial V).eval input.length) := by
    simpa only [ForestPlacement.configuration, ForestPlacement.placedLabel,
      front_fill, entry, initialTapes, frontendPrepared, initialState,
      TermMachine.initialState] using front
  have boot := ProducerBootstrap.inTime (bootstrapPorts V) (fun l => labels (.inr l))
    exit program (fun l => code (.inr l)) (frontendPrepared V input)
    (2 * V.witnessBound.eval input.length + 1) (bootstrapReady V input) ((), false) none
  have combined := StateTransition.EvalsToInTime.trans _ _ _ _ _ _ front' boot
  simpa only [timePolynomial_eval, bootstrapPrepared, initialState,
    TermMachine.initialState, Nat.add_comm] using combined
347
def program (V : NPVerifier) : Label V → TM2.Stmt (Alphabet V) (Label V) State :=
body · 1 line
  statement V id none
350
def programInTime (V : NPVerifier) (input : List Bool) :
    StateTransition.EvalsToInTime (TM2.step (program V))
      ⟨some (entry V), initialState, initialTapes V input⟩
      (some ⟨none, initialState, bootstrapPrepared V input⟩)
      ((timePolynomial V).eval input.length) :=
body · 1 line
  inTime V id none (program V) (fun _ => rfl) input
365
def localBase (V : NPVerifier) (input : List Bool) : TransitionArena.Tape → List Bool :=
body · 1 line
  fun t => bootstrapPrepared V input (transitionPorts V t)
368
def boundary (V : NPVerifier) (input : List Bool) (remaining : Nat) (s : Snapshot) : Tape V → List Bool :=
body · 2 lines
  ForestPlacement.fill (transitionPorts V) (bootstrapPrepared V input)
    (TransitionArena.tapes (localBase V input) (VerifierCircuit.capacity V input.length) remaining s)
372
def finished (V : NPVerifier) (input : List Bool) (s : Snapshot) : Tape V → List Bool :=
body · 2 lines
  ForestPlacement.fill (transitionPorts V) (bootstrapPrepared V input)
    (TransitionArena.finishTapes (localBase V input) (VerifierCircuit.capacity V input.length) s)
376
theorem fill_fill {I K : Type} (ports : I ↪ K) (base : K → List Bool)
    (first second : I → List Bool) :
    ForestPlacement.fill ports (ForestPlacement.fill ports base first) second =
      ForestPlacement.fill ports base second := by
proof · 8 lines
  classical
  funext k
  by_cases hin : ∃ i, ports i = k
  · obtain ⟨i, rfl⟩ := hin
    simp only [ForestPlacement.fill_at]
  · rw [ForestPlacement.fill_other ports _ _ k (not_exists.mp hin),
      ForestPlacement.fill_other ports _ _ k (not_exists.mp hin),
      ForestPlacement.fill_other ports _ _ k (not_exists.mp hin)]
389
theorem boundary_view (V : NPVerifier) (input : List Bool) (remaining : Nat) (s : Snapshot) :
    (fun t => boundary V input remaining s (transitionPorts V t)) =
      TransitionArena.tapes (localBase V input) (VerifierCircuit.capacity V input.length) remaining s := by
proof · 2 lines
  funext t
  exact ForestPlacement.fill_at _ _ _ t
395
theorem finished_view (V : NPVerifier) (input : List Bool) (s : Snapshot) :
    (fun t => finished V input s (transitionPorts V t)) =
      TransitionArena.finishTapes (localBase V input) (VerifierCircuit.capacity V input.length) s := by
proof · 2 lines
  funext t
  exact ForestPlacement.fill_at _ _ _ t
401
theorem boundary_other (V : NPVerifier) (input : List Bool) (remaining : Nat) (s : Snapshot)
    (k : Tape V) (outside : ∀ t, transitionPorts V t ≠ k) :
    boundary V input remaining s k = bootstrapPrepared V input k :=
proof · 1 line
  ForestPlacement.fill_other _ _ _ k outside
406
theorem finished_other (V : NPVerifier) (input : List Bool) (s : Snapshot)
    (k : Tape V) (outside : ∀ t, transitionPorts V t ≠ k) :
    finished V input s k = bootstrapPrepared V input k :=
proof · 1 line
  ForestPlacement.fill_other _ _ _ k outside
411
theorem fill_boundary (V : NPVerifier) (input : List Bool) (remaining : Nat) (s : Snapshot)
    (contents : TransitionArena.Tape → List Bool) :
    ForestPlacement.fill (transitionPorts V) (boundary V input remaining s) contents =
      ForestPlacement.fill (transitionPorts V) (bootstrapPrepared V input) contents :=
proof · 1 line
  fill_fill _ _ _ _
417
theorem fill_finished (V : NPVerifier) (input : List Bool) (s : Snapshot)
    (contents : TransitionArena.Tape → List Bool) :
    ForestPlacement.fill (transitionPorts V) (finished V input s) contents =
      ForestPlacement.fill (transitionPorts V) (bootstrapPrepared V input) contents :=
proof · 1 line
  fill_fill _ _ _ _
423
theorem iteration_handoff (V : NPVerifier) (input : List Bool) (remaining : Nat) (s next : Snapshot) :
    ForestPlacement.fill (transitionPorts V) (boundary V input remaining s)
      (TransitionArena.finishTapes (localBase V input) (VerifierCircuit.capacity V input.length) next) =
      finished V input next := fill_boundary V input remaining s _
428
theorem acceptance_handoff (V : NPVerifier) (input : List Bool) (s next : Snapshot) :
    ForestPlacement.fill (transitionPorts V) (finished V input s)
      (TransitionArena.finishTapes (localBase V input) (VerifierCircuit.capacity V input.length) next) =
      finished V input next := fill_finished V input s _
433
@[simp] theorem boundary_current (V : NPVerifier) (input : List Bool) (remaining : Nat) (s : Snapshot) :
    boundary V input remaining s (current V) = s.currentBits := by
proof · 4 lines
  change ForestPlacement.fill (transitionPorts V) _ _
    (transitionPorts V (.inl (.lower .current))) = _
  rw [ForestPlacement.fill_at]
  rfl
440
@[simp] theorem boundary_roots (V : NPVerifier) (input : List Bool) (remaining : Nat) (s : Snapshot) :
    boundary V input remaining s (roots V) = s.rootBits := by
proof · 3 lines
  change ForestPlacement.fill (transitionPorts V) _ _ (transitionPorts V (.inl .rootTable)) = _
  rw [ForestPlacement.fill_at]
  rfl
446
@[simp] theorem boundary_records (V : NPVerifier) (input : List Bool) (remaining : Nat) (s : Snapshot) :
    boundary V input remaining s (records V) = s.reversedRecords := by
proof · 3 lines
  change ForestPlacement.fill (transitionPorts V) _ _ (transitionPorts V (.inl .records)) = _
  rw [ForestPlacement.fill_at]
  rfl
452
@[simp] theorem boundary_countdown (V : NPVerifier) (input : List Bool) (remaining : Nat) (s : Snapshot) :
    boundary V input remaining s (countdown V) = encodeWord remaining := by
proof · 3 lines
  change ForestPlacement.fill (transitionPorts V) _ _ (transitionPorts V (.inr .countdown)) = _
  rw [ForestPlacement.fill_at]
  rfl
458
@[simp] theorem finished_current (V : NPVerifier) (input : List Bool) (s : Snapshot) :
    finished V input s (current V) = s.currentBits := by
proof · 4 lines
  change ForestPlacement.fill (transitionPorts V) _ _
    (transitionPorts V (.inl (.lower .current))) = _
  rw [ForestPlacement.fill_at]
  rfl
465
@[simp] theorem finished_roots (V : NPVerifier) (input : List Bool) (s : Snapshot) :
    finished V input s (roots V) = s.rootBits := by
proof · 3 lines
  change ForestPlacement.fill (transitionPorts V) _ _ (transitionPorts V (.inl .rootTable)) = _
  rw [ForestPlacement.fill_at]
  rfl
471
@[simp] theorem finished_records (V : NPVerifier) (input : List Bool) (s : Snapshot) :
    finished V input s (records V) = s.reversedRecords := by
proof · 3 lines
  change ForestPlacement.fill (transitionPorts V) _ _ (transitionPorts V (.inl .records)) = _
  rw [ForestPlacement.fill_at]
  rfl
477
@[simp] theorem finished_countdown (V : NPVerifier) (input : List Bool) (s : Snapshot) :
    finished V input s (countdown V) = [] := by
proof · 3 lines
  change ForestPlacement.fill (transitionPorts V) _ _ (transitionPorts V (.inr .countdown)) = _
  rw [ForestPlacement.fill_at]
  simp [TransitionArena.finishTapes]
483
theorem boundary_private (V : NPVerifier) (input : List Bool) (remaining : Nat) (s : Snapshot)
    (w : Work) (outside : ∀ t, transitionPorts V t ≠ .inr w) :
    boundary V input remaining s (.inr w) = [] := by
proof · 6 lines
  rw [boundary_other V input remaining s _ outside,
    bootstrapPrepared_other V input _
      (Ne.symm (outside (.inl (.lower .current))))
      (Ne.symm (outside (.inl (.lower .remaining))))
      (Ne.symm (outside (.inr .cursor)))]
  rfl
493
theorem finished_private (V : NPVerifier) (input : List Bool) (s : Snapshot)
    (w : Work) (outside : ∀ t, transitionPorts V t ≠ .inr w) :
    finished V input s (.inr w) = [] := by
proof · 6 lines
  rw [finished_other V input s _ outside,
    bootstrapPrepared_other V input _
      (Ne.symm (outside (.inl (.lower .current))))
      (Ne.symm (outside (.inl (.lower .remaining))))
      (Ne.symm (outside (.inr .cursor)))]
  rfl
503
theorem private_finish_outside (V : NPVerifier) (f : CircuitFinish.Tape) :
    ∀ t, transitionPorts V t ≠ .inr (.finish f) := by
proof · 4 lines
  intro t
  cases t with
  | inl t => simp [transitionTape]
  | inr t => cases t <;> simp [transitionTape, raw, q, capacity, countdown, clock]
510
theorem private_validity_outside (V : NPVerifier) (j : Fin 7) :
    ∀ t, transitionPorts V t ≠ .inr (.validity j) := by
proof · 4 lines
  intro t
  cases t with
  | inl t => simp [transitionTape]
  | inr t => cases t <;> simp [transitionTape, raw, q, capacity, countdown, clock]
517
theorem private_cells_outside (V : NPVerifier) (j : Fin 9) :
    ∀ t, transitionPorts V t ≠ .inr (.cells j) := by
proof · 4 lines
  intro t
  cases t with
  | inl t => simp [transitionTape]
  | inr t => cases t <;> simp [transitionTape, raw, q, capacity, countdown, clock]
524
theorem bootstrap_clock (V : NPVerifier) (input : List Bool) (c : ClockPreparation.Clock) :
    bootstrapPrepared V input (clock V c) = encodeWord (ClockPreparation.clockValue V input.length c) := by
proof · 3 lines
  change bootstrapPrepared V input (frontPorts V (VerifierFront.clockTape V c)) = _
  rw [bootstrapPrepared_front]
  exact VerifierFront.prepared_clock V input c
530
theorem bootstrap_raw (V : NPVerifier) (input : List Bool) :
    bootstrapPrepared V input (raw V) = input := by
proof · 3 lines
  change bootstrapPrepared V input (frontPorts V (VerifierFront.raw V)) = _
  rw [bootstrapPrepared_front]
  exact VerifierFront.prepared_raw V input
536
theorem bootstrap_work (V : NPVerifier) (input : List Bool) (w : Work)
    (hc : (.inr w : Tape V) ≠ current V) (hn : (.inr w : Tape V) ≠ count V)
    (hz : (.inr w : Tape V) ≠ cursor V) : bootstrapPrepared V input (.inr w) = [] := by
proof · 2 lines
  rw [bootstrapPrepared_other V input _ hc hn hz]
  rfl
542
theorem bootstrap_extra (V : NPVerifier) (input : List Bool) (s : Snapshot)
    (e : TransitionArena.Extra) :
    localBase V input (.inr e) =
      TransitionArena.tapes (localBase V input) (VerifierCircuit.capacity V input.length)
        (V.horizon input.length) s (.inr e) := by
proof · 6 lines
  cases e <;> simp only [TransitionArena.tapes]
  all_goals first
    | rfl
    | exact bootstrapPrepared_cursor V input
    | exact bootstrap_clock V input .capacity
    | exact bootstrap_clock V input .horizon
554
@[simp] theorem boundary_raw (V : NPVerifier) (input : List Bool) (remaining : Nat) (s : Snapshot) :
    boundary V input remaining s (raw V) = input := by
proof · 3 lines
  change ForestPlacement.fill (transitionPorts V) _ _ (transitionPorts V (.inr .raw)) = _
  rw [ForestPlacement.fill_at]
  exact bootstrap_raw V input
560
@[simp] theorem boundary_q (V : NPVerifier) (input : List Bool) (remaining : Nat) (s : Snapshot) :
    boundary V input remaining s (q V) = encodeWord (V.witnessBound.eval input.length) := by
proof · 3 lines
  change ForestPlacement.fill (transitionPorts V) _ _ (transitionPorts V (.inr .q)) = _
  rw [ForestPlacement.fill_at]
  exact bootstrap_clock V input .witness
566
@[simp] theorem boundary_capacity (V : NPVerifier) (input : List Bool) (remaining : Nat) (s : Snapshot) :
    boundary V input remaining s (capacity V) = encodeWord (VerifierCircuit.capacity V input.length) := by
proof · 3 lines
  change ForestPlacement.fill (transitionPorts V) _ _ (transitionPorts V (.inr .capacity)) = _
  rw [ForestPlacement.fill_at]
  rfl
572
theorem initial_result_view (V : NPVerifier) (input : List Bool) :
    (fun t => InitializationStage.result (forestPorts V) (bootstrapPrepared V input) V input
      (transitionPorts V t)) =
      TransitionArena.tapes (localBase V input) (VerifierCircuit.capacity V input.length)
        (V.horizon input.length) (snapshot (VerifierCircuit.initialFrame V input)) := by
proof · 18 lines
  funext t
  cases t with
  | inl t =>
    change InitializationStage.result (forestPorts V) _ V input (forestPorts V t) = _
    rw [InitializationStage.result_at]
    cases t with
    | lower t => cases t <;> rfl
    | tokens => rfl
    | records => rfl
    | rootTable => rfl
  | inr e =>
    have outside : ∀ t, forestPorts V t ≠ transitionPorts V (.inr e) := by
      intro t h
      change transitionPorts V (.inl t) = transitionPorts V (.inr e) at h
      have impossible := (transitionPorts V).injective h
      cases impossible
    rw [InitializationStage.result_other _ _ _ _ _ outside]
    exact bootstrap_extra V input _ e
596
theorem initial_result_eq_boundary (V : NPVerifier) (input : List Bool) :
    InitializationStage.result (forestPorts V) (bootstrapPrepared V input) V input =
      boundary V input (V.horizon input.length) (snapshot (VerifierCircuit.initialFrame V input)) := by
proof · 10 lines
  classical
  funext k
  by_cases inside : ∃ t, transitionPorts V t = k
  · obtain ⟨t, rfl⟩ := inside
    exact (congrFun (initial_result_view V input) t).trans
      (congrFun (boundary_view V input _ _) t).symm
  · have outside := not_exists.mp inside
    have outsideForest : ∀ t, forestPorts V t ≠ k := fun t => outside (.inl t)
    rw [InitializationStage.result_other _ _ _ _ _ outsideForest,
      boundary_other V input _ _ _ outside]
610
theorem initialization_emitted_fill (V : NPVerifier) (input : List Bool) :
    ForestPlacement.fill (initializationPorts V) (bootstrapPrepared V input)
      (ClashMachine.emitted InitializationAssembly.Tape.reversed InitializationAssembly.Tape.count
        (initializationBase V input) (InitializationTemplate.initializationTokens V input)) =
      ClashMachine.emitted (tokens V) (count V) (bootstrapPrepared V input)
        (InitializationTemplate.initializationTokens V input) := by
proof · 3 lines
  rw [← bootstrap_initialization_view V input]
  simp only [ClashMachine.emitted, ForestPlacement.fill_update, ForestPlacement.fill_self]
  rfl
620
theorem initialization_lowering_handoff (V : NPVerifier) (input : List Bool) :
    InitializationStage.result (forestPorts V)
      (ForestPlacement.fill (initializationPorts V) (bootstrapPrepared V input)
        (ClashMachine.emitted InitializationAssembly.Tape.reversed InitializationAssembly.Tape.count
          (initializationBase V input) (InitializationTemplate.initializationTokens V input))) V input =
      boundary V input (V.horizon input.length) (snapshot (VerifierCircuit.initialFrame V input)) := by
proof · 5 lines
  rw [initialization_emitted_fill]
  change InitializationStage.result (forestPorts V)
    (ClashMachine.emitted (forestPorts V .tokens) (forestPorts V (.lower .remaining))
      (bootstrapPrepared V input) (InitializationTemplate.initializationTokens V input)) V input = _
  rw [InitializationStage.result_emitted, initial_result_eq_boundary]
632
theorem clock_outside (V : NPVerifier) (c : ClockPreparation.Clock)
    (hq : c ≠ .witness) (hS : c ≠ .capacity) (hT : c ≠ .horizon) :
    ∀ t, transitionPorts V t ≠ clock V c := by
proof · 11 lines
  intro t
  cases t with
  | inl t => simp [transitionTape, clock]
  | inr e =>
    cases e with
    | q => change clock V .witness ≠ clock V c; simpa only [ne_eq, clock_eq_iff] using Ne.symm hq
    | capacity => change clock V .capacity ≠ clock V c; simpa only [ne_eq, clock_eq_iff] using Ne.symm hS
    | countdown => change clock V .horizon ≠ clock V c; simpa only [ne_eq, clock_eq_iff] using Ne.symm hT
    | raw => exact raw_ne_clock V c
    | cursor | position | address | value | scratch | copy | saveLeft | saveRight =>
      simp [transitionTape, clock]
647
theorem freeInputs_outside (V : NPVerifier) : ∀ t, transitionPorts V t ≠ freeInputs V :=
proof · 1 line
  clock_outside V .inputCount (by decide) (by decide) (by decide)
650
theorem framed_outside (V : NPVerifier) : ∀ t, transitionPorts V t ≠ framed V := by
proof · 11 lines
  intro t
  cases t with
  | inl t => simp [transitionTape, framed]
  | inr e =>
    cases e with
    | q => exact clock_ne_framed V .witness
    | capacity => exact clock_ne_framed V .capacity
    | countdown => exact clock_ne_framed V .horizon
    | raw => exact raw_ne_framed V
    | cursor | position | address | value | scratch | copy | saveLeft | saveRight =>
      simp [transitionTape, framed]
663
theorem boundary_clock (V : NPVerifier) (input : List Bool) (remaining : Nat) (s : Snapshot)
    (c : ClockPreparation.Clock) (hq : c ≠ .witness) (hS : c ≠ .capacity) (hT : c ≠ .horizon) :
    boundary V input remaining s (clock V c) = encodeWord (ClockPreparation.clockValue V input.length c) := by
proof · 2 lines
  rw [boundary_other V input remaining s _ (clock_outside V c hq hS hT)]
  exact bootstrap_clock V input c
669
theorem finished_clock (V : NPVerifier) (input : List Bool) (s : Snapshot)
    (c : ClockPreparation.Clock) (hq : c ≠ .witness) (hS : c ≠ .capacity) (hT : c ≠ .horizon) :
    finished V input s (clock V c) = encodeWord (ClockPreparation.clockValue V input.length c) := by
proof · 2 lines
  rw [finished_other V input s _ (clock_outside V c hq hS hT)]
  exact bootstrap_clock V input c
675
theorem boundary_framed (V : NPVerifier) (input : List Bool) (remaining : Nat) (s : Snapshot) :
    boundary V input remaining s (framed V) = encodeWord input.length ++ input := by
proof · 4 lines
  rw [boundary_other V input remaining s _ (framed_outside V)]
  change bootstrapPrepared V input (frontPorts V (VerifierFront.stream V)) = _
  rw [bootstrapPrepared_front]
  exact VerifierFront.prepared_stream V input
682
theorem finished_framed (V : NPVerifier) (input : List Bool) (s : Snapshot) :
    finished V input s (framed V) = encodeWord input.length ++ input := by
proof · 4 lines
  rw [finished_other V input s _ (framed_outside V)]
  change bootstrapPrepared V input (frontPorts V (VerifierFront.stream V)) = _
  rw [bootstrapPrepared_front]
  exact VerifierFront.prepared_stream V input
689
@[simp] theorem finished_freeInputs (V : NPVerifier) (input : List Bool) (s : Snapshot) :
    finished V input s (freeInputs V) = encodeWord (2 * V.witnessBound.eval input.length + 1) := by
proof · 2 lines
  rw [finished_other V input s _ (freeInputs_outside V)]
  exact bootstrap_clock V input .inputCount
694
theorem finish_view (V : NPVerifier) (input : List Bool) (s : Snapshot) :
    (fun t => finished V input s (finishPorts V t)) =
      CircuitFinish.memory s.currentBits
        (encodeWord (2 * V.witnessBound.eval input.length + 1)) s.rootBits s.reversedRecords [] [] [] := by
proof · 9 lines
  funext t
  cases t with
  | current => exact finished_current V input s
  | freeInputs => exact finished_freeInputs V input s
  | root => exact finished_roots V input s
  | reversedRecords => exact finished_records V input s
  | output => exact finished_private V input s _ (private_finish_outside V .output)
  | gateCount => exact finished_private V input s _ (private_finish_outside V .gateCount)
  | scratch => exact finished_private V input s _ (private_finish_outside V .scratch)
708
theorem circuitFinish_view (V : NPVerifier) (input : List Bool) :
    (fun t => finished V input (snapshot (finalFrame V input)) (finishPorts V t)) =
      CircuitFinish.initialTapes (VerifierCircuit.circuitOfVerifier V input).wires
        (VerifierCircuit.circuitOfVerifier V input).inputs
        (VerifierCircuit.circuitOfVerifier V input).output.val
        (recordsBits (VerifierCircuit.circuitOfVerifier V input).records) := by
proof · 5 lines
  rw [finish_view]
  rw [← finalFrame_circuit V input]
  simp [CircuitFinish.initialTapes, snapshot, Snapshot.currentBits, Snapshot.rootBits,
    CircuitBatch.Frame.toCircuit, CircuitBatch.Fragment.toCircuit, Circuit.wires,
    List.ofFn_succ, Circuit.records, encodeWords]
720
theorem bootstrap_emitter_ready (V : NPVerifier) (input : List Bool) :
    InitializationAssembly.Ready V (initializationPorts V)
      (bootstrapPrepared V input) input := by
proof · 9 lines
  constructor
  · exact congrFun (bootstrap_initialization_view V input) .rawInput
  · exact congrFun (bootstrap_initialization_view V input) .framedInput
  · exact congrFun (bootstrap_initialization_view V input) .witnessBound
  · exact congrFun (bootstrap_initialization_view V input) .capacity
  · intro j
    exact congrFun (bootstrap_initialization_view V input) (.cellWork j)
  · intro j
    exact congrFun (bootstrap_initialization_view V input) (.validityWork j)
733
theorem bootstrap_lowerer_ready (V : NPVerifier) (input : List Bool) :
    InitializationStage.Ready (forestPorts V) (bootstrapPrepared V input) V input := by
proof · 14 lines
  intro t
  cases t with
  | lower t =>
    cases t <;> simp only [ForestStage.initialLocal]
    all_goals first
      | exact bootstrapPrepared_current V input
      | exact bootstrapPrepared_count V input
      | apply bootstrap_work <;> simp [current, count, cursor, shared, TransitionArena.forestPorts]
  | tokens =>
    apply bootstrap_work <;> simp [current, count, cursor, shared, TransitionArena.forestPorts]
  | records =>
    apply bootstrap_work <;> simp [current, count, cursor, shared, TransitionArena.forestPorts]
  | rootTable =>
    apply bootstrap_work <;> simp [current, count, cursor, shared, TransitionArena.forestPorts]

Xet Storage Details

Size:
35.9 kB
·
Xet hash:
fb4a75e151e5f27928a98e57f24fdbbe9d4a3b08f726b9bb0d16c3095e94673b

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.