Repository navigation
Expand file tree
/
Copy pathInvariant.lean
More file actions
69 lines (60 loc) · 2.72 KB
/
Copy pathInvariant.lean
File metadata and controls
69 lines (60 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import FeProofs.Constant.ModelCorrect
import Fe.EVM.RefineInvariant
/-!
# FeConstant: no message call changes the contract's storage
An instance of `Fe.EVM.refines_keeps`: the account at `a` running the FeConstant bytecode keeps
whatever storage it has, through every message call and creation, at every depth, whoever makes
them. The model never writes storage and makes no call, so `ModelKeeps` is immediate, and
nothing is asked of the calls its frames make (`callsAt := fun _ _ _ _ _ _ => True`) or of how
they are entered (`Enters := fun _ _ _ => True`).
-/
open Ethereum Ethereum.EVM Ethereum.EVM.Invariant Fe Fe.EVM
namespace FeProofs.Constant
/-- The account runs the FeConstant bytecode and has storage `st`. -/
def Fixed (st : Storage) (acc : Account) : Prop :=
acc.code = feConstantBytecode ∧ acc.storage = st
theorem fixed_admissible (st : Storage) : Admissible (Fixed st) (· = feConstantBytecode) where
balance _ _ h _ := h
code acc h := by
rw [h.1]
decide
trusted _ h := h.1
theorem model_keeps (a : AccountAddress) (st : Storage) :
ModelKeeps a (Fixed st) (· = feConstantBytecode) (fun _ _ _ => True) (fun _ _ => True)
(fun _ _ _ _ _ _ => True) Model.contract := by
intro I _ _ σ _ _ A feed out w _ _ _ _ _ _ _ _ _ _ _ hH hrun acc acc' hacc hacc' _
have hsame : ∀ r, Model.runtime.exec I (World.init σ A feed) = r →
Succeeds r out w → w.accounts = σ := by
intro r hr hr'
by_cases hsel : selIs I (feConstantSelBytes 0)
· by_cases hwv : I.weiValue = ⟨0⟩
· rw [runtime_answer hsel hwv] at hr
subst hr
rcases hr' with h | h <;> cases h
rfl
· rw [runtime_answer_value hsel hwv] at hr
subst hr
rcases hr' with h | h <;> cases h
· by_cases hsz : 4 ≤ I.calldata.size
· rw [runtime_noMatch hsz hsel] at hr
subst hr
rcases hr' with h | h <;> cases h
· rw [runtime_short (by omega)] at hr
subst hr
rcases hr' with h | h <;> cases h
rw [hsame _ rfl hrun, hacc] at hacc'
cases hacc'
obtain ⟨acc0, h0, hP⟩ := hH
rw [hacc] at h0
cases h0
exact hP
/-- Every message call and creation, at any depth, keeps the storage of an account that runs the
FeConstant bytecode. -/
theorem feConstantKeepsStorage (a : AccountAddress) (st : Storage) (e : Fin 1025) :
ThetaGood a (Fixed st) (· = feConstantBytecode) (fun _ _ _ => True) (fun _ _ => True)
(fun _ _ _ _ _ _ => True) e
∧ LambdaGood a (Fixed st) (fun _ _ => True) (fun _ _ _ _ _ _ => True) e :=
refines_keeps feConstantRefinesModel (fixed_admissible st) (fun _ _ _ _ _ => trivial)
(fun code h => ⟨ByteArray.empty, by rw [h, ByteArray.append_empty], rfl⟩)
(model_keeps a st) e
end FeProofs.Constant