Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix extra } generated when ret ++ fargs is empty and remove extra }s from generated files #4

Open
wants to merge 3 commits into
base: erc20
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions Clear/Abstraction.lean
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Clear.ExecLemmas
import Clear.OutOfFuelLemmas
import Clear.JumpLemmas
import Clear.YulNotation
import Clear.Wheels

namespace Clear.Abstraction

Expand All @@ -18,7 +19,7 @@ variable {s s₀ s₁ sEnd : State}

-- | General form for relational specs (concrete and abstract).
@[aesop safe 0 unfold (rule_sets := [Clear.aesop_spec])]
def Spec (R : State → State → Prop) (s₀ s₁ : State) : Prop :=
def Spec (R : State → State → Prop) (s₀ s₁ : State) :=
match s₀ with
| OutOfFuel => ❓ s₁
| Checkpoint c => s₁.isJump c
Expand All @@ -31,6 +32,30 @@ lemma Spec_ok_unfold {P : State → State → Prop} :
unfold Spec
aesop

-- | Specs that are somewhat pure
@[aesop safe 0 unfold (rule_sets := [Clear.aesop_spec])]
def PureSpec (R : State → State → Prop) : State → State → Prop :=
Spec (R ∩ (preserved on evm))

lemma PureSpec_ok_unfold {P : State → State → Prop} :
∀ {s s' : State}, s.isOk → ¬ ❓ s' → PureSpec P s s' → (P ∩ (preserved on evm)) s s' := by
intros s s' h h'
unfold PureSpec Spec
aesop

-- | Specs for code that might result in hash collision
@[aesop safe 0 unfold (rule_sets := [Clear.aesop_spec])]
def CollidingSpec (R : State → State → Prop) (s₀ s₁ : State) : Prop :=
if s₀.evm.hash_collision
then ❓ s₁
else ¬ s₁.evm.hash_collision → Spec R s₀ s₁

lemma CollidingSpec_ok_unfold {P : State → State → Prop} :
∀ {s s' : State}, s.isOk → ¬ ❓ s' → ¬ s'.evm.hash_collision → CollidingSpec P s s' → P s s' := by
intros s s' h h' h''
unfold CollidingSpec Spec
aesop

open Lean Elab Tactic in
elab "clr_spec" "at" h:ident : tactic => do
evalTactic <| ← `(tactic| (
Expand All @@ -46,6 +71,12 @@ lemma not_isOutOfFuel_Spec (spec : Spec R s₀ s₁) (h : ¬ isOutOfFuel s₁) :
intros hs₀
aesop_spec

-- | No hash collision propagates backwards through specs.
-- lemma not_hashCollision_Spec
-- (spec : CollidingSpec R s₀ s₁) (h : ¬ s₁.evm.hasHashCollision) : ¬ s₀.evm.hasHashCollision := by
-- intros hs₀
-- aesop_spec

-- ============================================================================
-- TACTICS
-- ============================================================================
Expand Down Expand Up @@ -151,7 +182,7 @@ elab "clr_funargs" "at" h:ident : tactic => do
simp only [multifill_cons, multifill_nil', isOk_insert, isOk_Ok, isOutOfFuel_Ok,
not_false_eq_true, imp_false, Ok.injEq, and_imp, forall_apply_eq_imp_iff₂,
forall_apply_eq_imp_iff] at $h:ident
repeat (rw [←State.insert] at $h:ident)
repeat (rw [←State.insert] at $h:ident)
))

end Clear
Loading