Handle.eca's CF_G1 in EC's form — the tactic experiment #
EC's CF_G1 (the game-level equivalence of CF and G1 up to the bad events, through EC's
up-to-bad call (_: bad, inv, inv') over the distinguisher's three oracle procedures), stated and
proven as EC does, over the old port's declarations (section FirstPort below). It drove the
tactics the SmartCounter files need (notes/SHA3/Refactor.md, phase 3): equiv_call (_ : bad, I, J), glob D in conditions, equiv_conseq H, phoare_while I V, sp keeping the precondition,
glob_simp. The declarations move to EC's form with the port of SLCommon, ConcreteF,
Handle.
Deviations from EC's proof:
- the oracles' steps
eq_f,eq_fi,PFf_Cfare the old port's (with its footprint hypothesis forD, discharged byfp_disjoint), and so isINV_CF_G1_init(EC's 18smtcalls); - the right oracles' losslessness is one more goal each (exception E11);
- EC splits the right
C.f's judgment in ahoare(bad kept) and a losslessphoare(conseq (: _ ==> true) (: _ ==> G1.bcol \/ G1.bext)): here onephoare_whilewith the bad event andJin the invariant; - EC's closers (
smt,/#,progress) aresimp,split_ifs,omega.
Declarations of the first port #
Definitions and plain lemmas of the first port of this file (2026-10/11) that the proofs below use; its program-logic proofs are gone.
The first port's translation notes (some mention declarations that went with its proofs):
clone export PROM.FullRO as ROhandle with type in_t <- handle, type out_t <- capacity …is the namespaceROhandle; its exportedFRO.mis the aliasFRO.mhere.clone export ConcreteF as ConcreteF1clones a theory without parameters: it isConcreteFitself, opened.G1's inner modulesM,Sdo not depend onD: they are the modulesG1.M,G1.S.G1 Dis the game, withDa Lean parameter.- The equivalences relate procedures of modules: they are
prhlProcstatements, with the section'sdeclare module Dand its restrictions as hypotheses.
Instances For
The clone's module variable ROhandle.RO.m.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The clone's module variable ROhandle.FRO.m.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
The exported FRO.m of the ROhandle clone.
Instances For
EC's G1.m.
Equations
- GaudisCrypt.SHA3.Handle.G1.m = GaudisCrypt.varLens (GaudisCrypt.VariableName.mk "GaudisCrypt.SHA3.Handle.G1.m" GaudisCrypt.SHA3.SLCommon.smap)
Instances For
EC's G1.mi.
Equations
- GaudisCrypt.SHA3.Handle.G1.mi = GaudisCrypt.varLens (GaudisCrypt.VariableName.mk "GaudisCrypt.SHA3.Handle.G1.mi" GaudisCrypt.SHA3.SLCommon.smap)
Instances For
EC's G1.mh.
Equations
- GaudisCrypt.SHA3.Handle.G1.mh = GaudisCrypt.varLens (GaudisCrypt.VariableName.mk "GaudisCrypt.SHA3.Handle.G1.mh" GaudisCrypt.SHA3.SLCommon.hsmap)
Instances For
EC's G1.mhi.
Equations
- GaudisCrypt.SHA3.Handle.G1.mhi = GaudisCrypt.varLens (GaudisCrypt.VariableName.mk "GaudisCrypt.SHA3.Handle.G1.mhi" GaudisCrypt.SHA3.SLCommon.hsmap)
Instances For
EC's G1.chandle.
Equations
- GaudisCrypt.SHA3.Handle.G1.chandle = GaudisCrypt.varLens (GaudisCrypt.VariableName.mk "GaudisCrypt.SHA3.Handle.G1.chandle" ℤ)
Instances For
EC's G1.paths.
Equations
- One or more equations did not get rendered due to their size.
Instances For
EC's G1.bext.
Equations
- GaudisCrypt.SHA3.Handle.G1.bext = GaudisCrypt.varLens (GaudisCrypt.VariableName.mk "GaudisCrypt.SHA3.Handle.G1.bext" Bool)
Instances For
EC's G1.bcol.
Equations
- GaudisCrypt.SHA3.Handle.G1.bcol = GaudisCrypt.varLens (GaudisCrypt.VariableName.mk "GaudisCrypt.SHA3.Handle.G1.bcol" Bool)
Instances For
The body of proc f of module G1.M, as a procedure of its own: it calls no module parameter, so it has no holes.
A hole stands for a call whose callee is not known here — a module parameter is supplied only when the module is applied — so the body is a ProcedureWithHoles, to be instantiated (see G1.M.f.procedure.apply_simp) rather than run. Use G1.M.f for this procedure as a module.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Instantiating the holes of G1.M.f.procedure with a tuple holeArgs of procedures: the body of proc f as written, with each hole call replaced by the matching holeArgs.lookup (HoleIndex.zero being the first hole the body declared). True by rfl.
Deliberately not @[simp], unlike the other apply_simp lemmas: its right-hand side is the whole body written out, so letting it fire on its own would turn any goal mentioning an instantiated procedure into that body. Inlining a procedure is a step to ask for by name (simp [G1.M.f.procedure.apply_simp]).
The module declared by module G1.M: the record of its procedures G1.M.f.
The declaration has no parameter list, so no procedure of it can call one either and the module is not a function — it is the plain record itself, and there is no G1.M.apply_simp to apply it with.
Instances For
@[simp]: G1.M.f = Module.proc G1.M.f.procedure — true by definition, proc f using no module parameter and so having no holes to fill.
proc f of module G1.M as a module: Module.proc G1.M.f.procedure, of type Module.Proc (procsig …). It uses no module parameter, so it is not a function — G1.M.f.apply_simp says exactly that.
Equations
Instances For
@[simp]: G1.S.fi = Module.proc G1.S.fi.procedure — true by definition, proc fi using no module parameter and so having no holes to fill.
proc f of module G1.S as a module: Module.proc G1.S.f.procedure, of type Module.Proc (procsig …). It uses no module parameter, so it is not a function — G1.S.f.apply_simp says exactly that.
Equations
Instances For
Instantiating the holes of G1.S.fi.procedure with a tuple holeArgs of procedures: the body of proc fi as written, with each hole call replaced by the matching holeArgs.lookup (HoleIndex.zero being the first hole the body declared). True by rfl.
Deliberately not @[simp], unlike the other apply_simp lemmas: its right-hand side is the whole body written out, so letting it fire on its own would turn any goal mentioning an instantiated procedure into that body. Inlining a procedure is a step to ask for by name (simp [G1.S.fi.procedure.apply_simp]).
proc fi of module G1.S as a module: Module.proc G1.S.fi.procedure, of type Module.Proc (procsig …). It uses no module parameter, so it is not a function — G1.S.fi.apply_simp says exactly that.
Equations
Instances For
Instantiating the holes of G1.S.f.procedure with a tuple holeArgs of procedures: the body of proc f as written, with each hole call replaced by the matching holeArgs.lookup (HoleIndex.zero being the first hole the body declared). True by rfl.
Deliberately not @[simp], unlike the other apply_simp lemmas: its right-hand side is the whole body written out, so letting it fire on its own would turn any goal mentioning an instantiated procedure into that body. Inlining a procedure is a step to ask for by name (simp [G1.S.f.procedure.apply_simp]).
The module declared by module G1.S: the record of its procedures G1.S.f, G1.S.fi.
The declaration has no parameter list, so no procedure of it can call one either and the module is not a function — it is the plain record itself, and there is no G1.S.apply_simp to apply it with.
Equations
Instances For
The body of proc f of module G1.S, as a procedure of its own: it calls no module parameter, so it has no holes.
A hole stands for a call whose callee is not known here — a module parameter is supplied only when the module is applied — so the body is a ProcedureWithHoles, to be instantiated (see G1.S.f.procedure.apply_simp) rather than run. Use G1.S.f for this procedure as a module.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The body of proc fi of module G1.S, as a procedure of its own: it calls no module parameter, so it has no holes.
A hole stands for a call whose callee is not known here — a module parameter is supplied only when the module is applied — so the body is a ProcedureWithHoles, to be instantiated (see G1.S.fi.procedure.apply_simp) rather than run. Use G1.S.fi for this procedure as a module.
Equations
- One or more equations did not get rendered due to their size.
Instances For
@[simp]: G1.S.f = Module.proc G1.S.f.procedure — true by definition, proc f using no module parameter and so having no holes to fill.
proc main of module G1 as a module: Module.proc G1.main.procedure, of type Module.Proc (procsig …). It uses no module parameter, so it is not a function — G1.main.apply_simp says exactly that.
Equations
Instances For
Instantiating the holes of G1.main.procedure with a tuple holeArgs of procedures: the body of proc main as written, with each hole call replaced by the matching holeArgs.lookup (HoleIndex.zero being the first hole the body declared). True by rfl.
Deliberately not @[simp], unlike the other apply_simp lemmas: its right-hand side is the whole body written out, so letting it fire on its own would turn any goal mentioning an instantiated procedure into that body. Inlining a procedure is a step to ask for by name (simp [G1.main.procedure.apply_simp]).
@[simp]: G1.main = Module.proc G1.main.procedure — true by definition, proc main using no module parameter and so having no holes to fill.
The body of proc main of module G1, as a procedure of its own: it calls no module parameter, so it has no holes.
A hole stands for a call whose callee is not known here — a module parameter is supplied only when the module is applied — so the body is a ProcedureWithHoles, to be instantiated (see G1.main.procedure.apply_simp) rather than run. Use G1.main for this procedure as a module.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The module declared by module G1: the record of its procedures G1.main.
The declaration has no parameter list, so no procedure of it can call one either and the module is not a function — it is the plain record itself, and there is no G1.apply_simp to apply it with.
Equations
Instances For
The invariant #
The state of CF contains the map PF.m (the primitive's map) and Redo.prefixes (all the prefix
computations of the sponge construction). The state of G1 contains the map hs from handles to
flagged capacities, G1.m (the public view of PF.m), G1.mh (PF.m with handle-based
indirection), the functionality ro, and pi, the known path to a capacity if it exists.
Relational: map, handle-map and handles are compatible.
- INV_m_mh [SLCommon.Params] {hs : SLCommon.handles} {m : SLCommon.smap} {mh : SLCommon.hsmap} : (∀ (xa : Common.block) (xc : Common.capacity) (ya : Common.block) (yc : Common.capacity), EC.FMap.get m (xa, xc) = some (ya, yc) → ∃ (hx : SLCommon.handle) (fx : EC.PROM.flag) (hy : SLCommon.handle) (fy : EC.PROM.flag), EC.FMap.get hs hx = some (xc, fx) ∧ EC.FMap.get hs hy = some (yc, fy) ∧ EC.FMap.get mh (xa, hx) = some (ya, hy)) → (∀ (xa : Common.block) (hx : SLCommon.handle) (ya : Common.block) (hy : SLCommon.handle), EC.FMap.get mh (xa, hx) = some (ya, hy) → ∃ (xc : Common.capacity) (fx : EC.PROM.flag) (yc : Common.capacity) (fy : EC.PROM.flag), EC.FMap.get hs hx = some (xc, fx) ∧ EC.FMap.get hs hy = some (yc, fy) ∧ EC.FMap.get m (xa, xc) = some (ya, yc)) → m_mh hs m mh
Instances For
Well-formedness: map and prefixes are compatible.
- INV_m_p [SLCommon.Params] {m : SLCommon.smap} {p : EC.FMap (List Common.block) state} {q : EC.FMap (List Common.block) Common.block} : p.get [] = some (Common.b0, Common.c0) → q.get [] = some Common.b0 → (∀ (l : List Common.block), p.dom l → ∀ (i : ℤ), 0 ≤ i ∧ i < EC.size l → ∃ (sa : Common.block) (sc : Common.capacity), p.get (EC.take i l) = some (sa, sc) ∧ EC.FMap.get m (sa +^ EC.nth default l i, sc) = p.get (EC.take (i + 1) l)) → (∀ (l : List Common.block), q.dom l → ∃ (c : Common.capacity), p.get l = some (EC.oget (q.get l), c)) → (∀ (l : List Common.block), p.dom l → ∃ (l2 : List Common.block), q.dom (l ++ l2)) → m_p m p q
Instances For
Relational: prefixes and the random oracle are compatible.
- INV_ro_p [SLCommon.Params] {ro : EC.FMap (List Common.block) Common.block} {p : EC.FMap (List Common.block) state} : ro = EC.FMap.map (SLCommon.«[+]» fun (a : state) => a.1) p → ro_p ro p
Instances For
Well-formedness: handles, map, handle-map and random oracle are compatible.
- INV_mh [SLCommon.Params] {hs : SLCommon.handles} {Gm : SLCommon.smap} {mh : SLCommon.hsmap} {ro : EC.FMap (List Common.block) Common.block} : (∀ (xa : Common.block) (hx : SLCommon.handle) (ya : Common.block) (hy : SLCommon.handle), EC.FMap.get mh (xa, hx) = some (ya, hy) → ∃ (xc : Common.capacity) (fx : EC.PROM.flag) (yc : Common.capacity) (fy : EC.PROM.flag), EC.FMap.get hs hx = some (xc, fx) ∧ EC.FMap.get hs hy = some (yc, fy) ∧ if fy = EC.PROM.Known then EC.FMap.get Gm (xa, xc) = some (ya, yc) ∧ fx = EC.PROM.Known else ∃ (p : List Common.block) (v : EC.BitWord.word Common.r), ro.get (EC.rcons p (v +^ xa)) = some ya ∧ SLCommon.build_hpath mh p = some (v, hx)) → (∀ (p : List Common.block) (bn b : Common.block), ro.get (EC.rcons p bn) = some b ↔ ∃ (v : Common.block) (hx : SLCommon.handle) (hy : SLCommon.handle), SLCommon.build_hpath mh p = some (v, hx) ∧ EC.FMap.get mh (v +^ bn, hx) = some (b, hy)) → (∀ (p : List Common.block) (v : Common.block) (p' : List Common.block) (v' : Common.block) (hx : SLCommon.handle), SLCommon.build_hpath mh p = some (v, hx) → SLCommon.build_hpath mh p' = some (v', hx) → p = p' ∧ v = v') → mh_spec hs Gm mh ro
Instances For
Well-formedness: handles, handle-map and paths are compatible.
- INV_pi [SLCommon.Params] {hs : SLCommon.handles} {mh : SLCommon.hsmap} {pi : EC.FMap Common.capacity (List Common.block × Common.block)} : (∀ (c : Common.capacity) (p : List Common.block) (v : Common.block), pi.get c = some (p, v) ↔ ∃ (h : SLCommon.handle), SLCommon.build_hpath mh p = some (v, h) ∧ EC.FMap.get hs h = some (c, EC.PROM.Known)) → pi_spec hs mh pi
Instances For
Well-formedness: handles are well formed.
- INV_hs [SLCommon.Params] {hs : SLCommon.handles} {ch : SLCommon.handle} : SLCommon.huniq hs → EC.FMap.get hs 0 = some (Common.c0, EC.PROM.Known) → (∀ (cf : SLCommon.ccapacity) (h : SLCommon.handle), EC.FMap.get hs h = some cf → h < ch) → hs_spec hs ch
Instances For
- INV_inv {α β : Type} [DecidableEq α] [DecidableEq β] {m : EC.FMap α β} {mi : EC.FMap β α} : (∀ (x : α) (y : β), m.get x = some y ↔ mi.get y = some x) → inv_spec m mi
Instances For
- HCF_G1 [SLCommon.Params] {hs : SLCommon.handles} {ch : SLCommon.handle} {Pm Pmi Gm Gmi : SLCommon.smap} {mh mhi : SLCommon.hsmap} {ro : EC.FMap (List Common.block) Common.block} {pi : EC.FMap Common.capacity (List Common.block × Common.block)} {p : EC.FMap (List Common.block) state} {q : EC.FMap (List Common.block) Common.block} : hs_spec hs ch → inv_spec Gm Gmi → inv_spec mh mhi → m_mh hs Pm mh → m_mh hs Pmi mhi → SLCommon.incl Gm Pm → SLCommon.incl Gmi Pmi → mh_spec hs Gm mh ro → pi_spec hs mh pi → m_p Pm p q → INV_CF_G1 hs ch Pm Pmi Gm Gmi mh mhi ro pi p q
Instances For
Structural projections #
Handles #
Equations
- GaudisCrypt.SHA3.Handle.getflag hs xc = Option.map Prod.snd ((GaudisCrypt.SHA3.SLCommon.hinv hs xc).bind (GaudisCrypt.EC.FMap.get hs))
Instances For
Handle paths #
Preservation of the invariant #
Block xor cancels on the left: a +^ (a +^ b) = b.
In the path case of eq_f the query rcons p0 (v0 +^ x1) is fresh for ro.
The path case of EC's eq_f: x2 has a known path (p0, v0), the oracle answers the
fresh query rcons p0 (v0 +^ x1) with y1.
The longest prefix of p in the queries Q, EC's prefix p (get_max_prefix p (elems (fdom C.queries))). An abbreviation, not an EC declaration.
Equations
Instances For
The invariant of PFf_Cf's first loop (the blocks of p already queried): EC's
while (…) invariant of the first splitwhile half, without the bad event (which this loop does
not touch). pref is Redo.prefixes{1}; (sa, sc) the left state, (sa, h) the right one.
Equations
- One or more equations did not get rendered due to their size.
Instances For
The left-hand part of the invariant of PFf_Cf's second loop (the new blocks), which holds
whatever the bad event: pref0 is Redo.prefixes{1} before the loop (EC's alias).
Equations
- One or more equations did not get rendered due to their size.
Instances For
The invariant of PFf_Cf's second loop before the bad event (EC's !(G1.bcol{2} \/ G1.bext{2}) => …): INV_CF_G1 with the query take i p answered sa.
Equations
- One or more equations did not get rendered due to their size.
Instances For
m_p's third component at a step: Pm maps the state recorded for take i p, xored with
the next block, to the state recorded for take (i + 1) p.
A step of the first loop: both sides find the block known.
From the first loop to the second: at i = qpre p Q.
The left-hand part of the second loop's invariant, through a step (whatever the bad
event): the new prefix take (i + 1) p gets the state (a, b). Needs pref0 closed under
prefixes.
A step of the second loop on a known block: PF.m and G1.mh both know it (lemma5').
m_p survives adding a fresh entry to the map: every prefix step PF.m already answers.
The fresh-block step of G1.M.f (EC's PFf_Cf, second loop): the block x1 after the
known path (p0, v0) to the handle hx2 is unknown to PF.m; the oracle answers the fresh
query rcons p0 (v0 +^ x1) with y1, the new handle ch gets the unknown capacity y2. The
prefix part m_p of the invariant is a hypothesis (the prefixes change with the caller).
A step of the second loop on a fresh block: neither PF.m nor G1.mh know it, nor ro the
query take (i + 1) p; the new block gets (y1, y2) on both sides (EC's big inline proof).
The invariant holds of the initial states. Not an EC lemma: EC proves it inline in CF_G1
(smt (get_setE emptyE build_hpath_map0)).
EC's Block.DBlock.dunifin_ll, as the expectation of 1 (what auto leaves).
EC's Capacity.DCapacity.dunifin_ll, as the expectation of 1.
Equations
- One or more equations did not get rendered due to their size.
EC's equiv eq_fi (D <: DISTINGUISHER {-PF, -RO, -G1}) : DPRestr(PF).fi ~ DPRestr(G1(DRestr(D)).S).fi : …, its proof EC's: the call with its invariant, exists*, the
ambient cases on INV_CF_G1, PF.mi, G1.mi and the handle's flag, EC's rcondt/rcondf
positions, and EC's closers (lemma1', lemma2', m_p_of_INV; EC's smt as smt_close).
D is not a parameter: neither procedure calls it (EC's restriction only frames the call).
EC's equiv eq_f (D <: DISTINGUISHER {-PF, -RO, -G1}) : DPRestr(PF).f ~ DPRestr(G1(DRestr(D)).S).f : …, its proof EC's: the call with its invariant, exists*, the
ambient cases, seq 2 2/seq 0 3/seq 0 1 with EC's conditions, swap{2} 3 -2, EC's
rcondt/rcondf positions (inline F.RO.get between them), and EC's closers (lemma1,
lemma2, lemma3, m_p_of_INV; EC's smt as smt_close). Deviations: EC's inline closer of
the path case (~100 lines) is the old port's f_path_inv; one conseq to G1.bext{2} before
the last auto of the Unknown branch (auto with INV_CF_G1 through the inlined oracle is
too slow).
Equations
- One or more equations did not get rendered due to their size.
EC's first bullet of PFf_Cf's first loop body (prefix_gt0_mem, prefix_take_leq, the
m_p part of the invariant): the next prefix of a queried path is known.
Gap list (batch-fix later, see TRANSFER_SKILL.md §1.6):
- GAP 2 (closed 2026-11-23): the second loop used the older
equiv_while_raw(four goals, no frame); both loops are now EC'swhile I(equiv_while) with EC'sauto; progress. - GAP 5: the pilot's oracle lemmas (
eq_f,eq_fi,PFf_Cf, in EC's paths throughmodule_subtypecoercions) matchCF_G1's oracles (the old port'sCF/G1views) only by heavy unfolding (~2M heartbeats perconseq): goes away with EC-formCF/G1declarations.
EC's equiv PFf_Cf (D <: DISTINGUISHER) : DFRestr(SqueezelessSponge(PF)).f ~ DFRestr(G1(DRestr(D)).M).f : …, its proof EC's, block by block (EC's lines as comments): proc; sp; inline*, the ifs with 1,3:auto, swap, wp 1 5, conseq, seq 1 1, splitwhile,
the two loops with EC's invariants, alias, case, rcondt/rcondf at EC's positions.
Deviations: hand closers where smt_close fails (EC's smt); EC's long inline closers are the
old port's lemmas (PJ1_step, PJ1_PJ2, PJ2_known, PJ2_fresh, PJ2L_step); ={bs} added
to the first loop's invariant and the left's samplings swapped for EC's swap{2} -3 (the gaps
listed above).
EC's equiv CF_G1 : CF(DRestr(D)).main ~ G1(DRestr(D)).main : ={glob D} ==> !(G1.bcol \/ G1.bext){2} => ={res}, its proof EC's (see the module docstring).
EC's lemma Real_G1 &m : Pr[GReal(D).main() @ &m: res /\ C.c <= max_size] <= Pr[G1(DRestr(D)).main() @ &m: res] + (max_size ^ 2 - max_size)%r * inv 2%r * mu dstate (pred1 witness) + Pr[G1(DRestr(D)).main() @&m: G1.bcol] + Pr[G1(DRestr(D)).main() @&m: G1.bext].