Documentation

GaudisCrypt.Logic.EqualOutside

States equal except on a lens #

Lens.equal_outside L g₁ g₂ (Language/Lens.lean): g₂ is g₁ with L overwritten. The relation EasyCrypt's sim keeps when the two programs differ only in variables the rest of the code does not read (a local module's variable written on one side only, or written on both sides at different times). prhlProc_self_equal_outside is the call rule for it: a procedure that does not touch L, on both sides.

L.equal_outside g₁ g₂ (the states agree except on L) is agreement of the complement lens.

theorem GaudisCrypt.prhlProc_self_equal_outside {Ω : Type} (L : Lens Ω VariableAssignment) {sig : ProcedureSignature} (p : Procedure sig) (hp : FVP.fvP_proc p ≤ L.footprintᶜ) (I : Ω → Ω → Prop) :
prhlProc (fun (a₁ : sig.ParamType) (g₁ : VariableAssignment) (a₂ : sig.ParamType) (g₂ : VariableAssignment) => a₁ = a₂ ∧ L.equal_outside g₁ g₂ ∧ I (L.get g₁) (L.get g₂)) p p fun (r₁ : sig.ret) (g₁ : VariableAssignment) (r₂ : sig.ret) (g₂ : VariableAssignment) => r₁ = r₂ ∧ L.equal_outside g₁ g₂ ∧ I (L.get g₁) (L.get g₂)

EasyCrypt's sim across a call, the states equal except on L: a procedure that does not touch L, called on both sides with equal arguments, keeps the states equal outside L and any relation I of the two contents of L (prhlProc_abstract_callF without holes).

theorem GaudisCrypt.prhlProc_self_equal_outside_module {Ω : Type} (L : Lens Ω VariableAssignment) {sig : ProcedureSignature} (M : Module.Proc sig) (hM : FVP.fvP M ≤ L.footprintᶜ) (I : Ω → Ω → Prop) :
prhlProc (fun (a₁ : sig.ParamType) (g₁ : VariableAssignment) (a₂ : sig.ParamType) (g₂ : VariableAssignment) => a₁ = a₂ ∧ L.equal_outside g₁ g₂ ∧ I (L.get g₁) (L.get g₂)) M.procedure M.procedure fun (r₁ : sig.ret) (g₁ : VariableAssignment) (r₂ : sig.ret) (g₂ : VariableAssignment) => r₁ = r₂ ∧ L.equal_outside g₁ g₂ ∧ I (L.get g₁) (L.get g₂)

prhlProc_self_equal_outside for a module's procedure, bounded by the module's footprint.

theorem GaudisCrypt.prhlProc_abstract_call_equal_outside_module {Ω : Type} (L : Lens Ω VariableAssignment) {T : Type 1} [IsModule T] {sig : ProcedureSignature} {holes : HoleSigs} (D : Module.Arr T (Module.Proc sig)) (ext : T → holes.Instantiation) (hD : Module.Representable D ext) (hdisj : FVP.fvP D ≤ L.footprintᶜ) (I : Ω → Ω → Prop) (hc : ∀ {sig' : ProcedureSignature} (a : HoleIndex holes sig'), Countable sig'.ParamType) (O₁ O₂ : T) (horacle : ∀ {sig' : ProcedureSignature} (n : HoleIndex holes sig'), prhlProc (fun (a₁ : sig'.ParamType) (g₁ : VariableAssignment) (a₂ : sig'.ParamType) (g₂ : VariableAssignment) => a₁ = a₂ ∧ L.equal_outside g₁ g₂ ∧ I (L.get g₁) (L.get g₂)) ((ext O₁).lookup n) ((ext O₂).lookup n) fun (r₁ : sig'.ret) (g₁ : VariableAssignment) (r₂ : sig'.ret) (g₂ : VariableAssignment) => r₁ = r₂ ∧ L.equal_outside g₁ g₂ ∧ I (L.get g₁) (L.get g₂)) :
prhlProc (fun (a₁ : sig.ParamType) (g₁ : VariableAssignment) (a₂ : sig.ParamType) (g₂ : VariableAssignment) => a₁ = a₂ ∧ L.equal_outside g₁ g₂ ∧ I (L.get g₁) (L.get g₂)) (Module.app D O₁).procedure (Module.app D O₂).procedure fun (r₁ : sig.ret) (g₁ : VariableAssignment) (r₂ : sig.ret) (g₂ : VariableAssignment) => r₁ = r₂ ∧ L.equal_outside g₁ g₂ ∧ I (L.get g₁) (L.get g₂)

EasyCrypt's call (: inv) for an abstract module, the states equal except on L: D outside L, applied to two oracles that keep the states equal outside L and the relation I of the two contents of L, keeps them too (prhlProc_abstract_callF at the complement of L). With I equality, the states are equal (Lens.equal_outside_and_get_eq_iff): EC's sim across a call of an adversary whose oracles differ in code but not in behaviour.

theorem GaudisCrypt.Lens.equal_outside.set_disjoint {Ω : Type} {L : Lens Ω VariableAssignment} {β : Type} {X : Lens β VariableAssignment} [hd : X.Disjoint L] {g₁ g₂ : VariableAssignment} (h : L.equal_outside g₁ g₂) (v : β) :
L.equal_outside (X.set v g₁) (X.set v g₂)

The same write of a lens disjoint from L keeps the states equal outside L.

theorem GaudisCrypt.Lens.equal_outside.get_disjoint {Ω : Type} {L : Lens Ω VariableAssignment} {β : Type} {X : Lens β VariableAssignment} [hd : X.Disjoint L] {g₁ g₂ : VariableAssignment} (h : L.equal_outside g₁ g₂) :
X.get g₁ = X.get g₂

States equal outside L agree on every lens disjoint from L.

theorem GaudisCrypt.Lens.equal_outside.set_right {Ω : Type} {L : Lens Ω VariableAssignment} {g₁ g₂ : VariableAssignment} (h : L.equal_outside g₁ g₂) (v : Ω) :
L.equal_outside g₁ (L.set v g₂)

A write of L on one side keeps the states equal outside L.

Every state is equal to itself outside L.

theorem GaudisCrypt.Lens.equal_outside.set_left {Ω : Type} {L : Lens Ω VariableAssignment} {g₁ g₂ : VariableAssignment} (h : L.equal_outside g₁ g₂) (v : Ω) :
L.equal_outside (L.set v g₁) g₂

A write of L on the left keeps the states equal outside L.

theorem GaudisCrypt.Lens.equal_outside.symm {Ω : Type} {L : Lens Ω VariableAssignment} {g₁ g₂ : VariableAssignment} (h : L.equal_outside g₁ g₂) :
L.equal_outside g₂ g₁

equal_outside is symmetric.

theorem GaudisCrypt.Lens.equal_outside.trans {Ω : Type} {L : Lens Ω VariableAssignment} {g₁ g₂ g₃ : VariableAssignment} (h : L.equal_outside g₁ g₂) (h' : L.equal_outside g₂ g₃) :
L.equal_outside g₁ g₃

equal_outside is transitive.

A write of L keeps a state equal to itself outside L.

States equal outside A are equal outside Lens.pair A B.

States equal outside B are equal outside Lens.pair A B.

theorem GaudisCrypt.Lens.equal_outside_and_get_eq_iff {Ω : Type} {L : Lens Ω VariableAssignment} {g₁ g₂ : VariableAssignment} :
L.equal_outside g₁ g₂ ∧ L.get g₁ = L.get g₂ ↔ g₁ = g₂

States equal outside L and on L are equal.