Repository navigation
Expand file tree
/
Copy pathDispatch.lean
More file actions
167 lines (149 loc) · 8.58 KB
/
Copy pathDispatch.lean
File metadata and controls
167 lines (149 loc) · 8.58 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import FeProofs.IndexedPackedStore.Common
import FeProofs.IndexedPackedStore.RuntimeBlocks_001
import FeProofs.IndexedPackedStore.RuntimeBlocks_002
/-!
# FeIndexedPackedStore dispatcher (generated by `scripts/proof_skeleton.py`)
Stele-side dispatch facts and the runtime dispatcher reach lemmas, composed from the block
summaries along the path the compiled dispatcher takes for each selector.
-/
open Stele ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach
namespace FeProofs.IndexedPackedStore
set_option maxRecDepth 2000000
/-! ## Stele dispatch: which transition a selector reaches -/
theorem feIndexedPackedStoreDispatch_set {I : ExecutionEnv}
(hsel : selIs I (feIndexedPackedStoreSelBytes 0)) :
dispatchMsg contract I.calldata = some setTransition := by
refine dispatchMsg_eq_some_of_split (contract := contract)
(pre := []) (post := [setTwoTransition, getTransition])
(ti := setTransition) (cd := I.calldata) (by rfl) ?_ ?_ ?_ (by rfl)
· exact transitions_eq
· intro u hu
simp at hu
· rw [setSelectorOf]; exact hsel
theorem feIndexedPackedStoreDispatch_setTwo {I : ExecutionEnv}
(hsel : selIs I (feIndexedPackedStoreSelBytes 1)) :
dispatchMsg contract I.calldata = some setTwoTransition := by
have h0 : ¬ selIs I (feIndexedPackedStoreSelBytes 0) := not_selIs_of_selIs hsel (by decide)
refine dispatchMsg_eq_some_of_split (contract := contract)
(pre := [setTransition]) (post := [getTransition])
(ti := setTwoTransition) (cd := I.calldata) (by rfl) ?_ ?_ ?_ (by rfl)
· exact transitions_eq
· intro u hu
simp only [List.mem_cons, List.not_mem_nil, or_false] at hu
rcases hu with rfl
· rw [setSelectorOf]; exact Bool.eq_false_of_not_eq_true h0
· rw [setTwoSelectorOf]; exact hsel
theorem feIndexedPackedStoreDispatch_get {I : ExecutionEnv}
(hsel : selIs I (feIndexedPackedStoreSelBytes 2)) :
dispatchMsg contract I.calldata = some getTransition := by
have h0 : ¬ selIs I (feIndexedPackedStoreSelBytes 0) := not_selIs_of_selIs hsel (by decide)
have h1 : ¬ selIs I (feIndexedPackedStoreSelBytes 1) := not_selIs_of_selIs hsel (by decide)
refine dispatchMsg_eq_some_of_split (contract := contract)
(pre := [setTransition, setTwoTransition]) (post := [])
(ti := getTransition) (cd := I.calldata) (by rfl) ?_ ?_ ?_ (by rfl)
· exact transitions_eq
· intro u hu
simp only [List.mem_cons, List.not_mem_nil, or_false] at hu
rcases hu with rfl | rfl
· rw [setSelectorOf]; exact Bool.eq_false_of_not_eq_true h0
· rw [setTwoSelectorOf]; exact Bool.eq_false_of_not_eq_true h1
· rw [getSelectorOf]; exact hsel
theorem feIndexedPackedStoreDispatch_none_short {cd : ByteArray} (h : cd.size < 4) :
dispatchMsg contract cd = none := by
rw [dispatchMsg_eq_dispatchList contract cd, transitions_eq]
refine dispatchList_none_short _ ?_ h
intro t ht
simp only [List.mem_cons, List.not_mem_nil, or_false] at ht
rcases ht with rfl | rfl | rfl
· rw [setSelectorOf]; rfl
· rw [setTwoSelectorOf]; rfl
· rw [getSelectorOf]; rfl
theorem feIndexedPackedStoreDispatch_none_nomatch {I : ExecutionEnv}
(hnm : ∀ i, i < 3 → (feIndexedPackedStoreSelBytes i == I.calldata.extract 0 4) = false) :
dispatchMsg contract I.calldata = none := by
refine dispatchMsg_none_of_all_ne (contract := contract) (cd := I.calldata) (by rfl) (by rfl) ?_
intro t ht
rw [transitions_eq] at ht
simp only [List.mem_cons, List.not_mem_nil, or_false] at ht
rcases ht with rfl | rfl | rfl
· rw [setSelectorOf]; exact hnm 0 (by omega)
· rw [setTwoSelectorOf]; exact hnm 1 (by omega)
· rw [getSelectorOf]; exact hnm 2 (by omega)
/-! ## Runtime dispatcher paths -/
/-- Dispatcher path to `set(uint256,uint256)` (arm entry pc 47). -/
theorem feIndexedPackedStoreReachSetBody {σ σ₀ A I} {g : Sat256}
(hcode : I.code = feIndexedPackedStoreBytecode) (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size)
(hsel : selIs I (feIndexedPackedStoreSelBytes 0)) :
∃ k C, RD (feIndexedPackedStoreBytecode) I g (initState σ σ₀ g A I) (UInt256.ofNat 47)
[(UInt256.shiftRight (uInt256OfByteArray (I.calldata.readBytes (⟨0⟩ : UInt256).toNat 32)) (UInt256.ofNat 224))]
ByteArray.empty
(UInt256.ofNat 0) ByteArray.empty σ k C := by
have hword : solcSelectorWord I = ⟨447770341⟩ :=
solcSelectorWord_eq_of_beq I hsz 0x1a 0xb0 0x6e 0xe5 ⟨447770341⟩ (by native_decide)
(by simpa [feIndexedPackedStoreSelBytes] using hsel)
have rd0 := RD.initState (g := g) (σ := σ) (σ₀ := σ₀) (A := A) hcode
rd_run rd0 to 47 using [lt_four_eq_zero_of_ge hsz hsize, selWord_eq hword]
exact ⟨_, _, rd0⟩
/-- Dispatcher path to `setTwo(uint256,uint256,uint256,uint256)` (arm entry pc 136). -/
theorem feIndexedPackedStoreReachSetTwoBody {σ σ₀ A I} {g : Sat256}
(hcode : I.code = feIndexedPackedStoreBytecode) (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size)
(hsel : selIs I (feIndexedPackedStoreSelBytes 1)) :
∃ k C, RD (feIndexedPackedStoreBytecode) I g (initState σ σ₀ g A I) (UInt256.ofNat 136)
[(UInt256.shiftRight (uInt256OfByteArray (I.calldata.readBytes (⟨0⟩ : UInt256).toNat 32)) (UInt256.ofNat 224))]
ByteArray.empty
(UInt256.ofNat 0) ByteArray.empty σ k C := by
have hword : solcSelectorWord I = ⟨1659099261⟩ :=
solcSelectorWord_eq_of_beq I hsz 0x62 0xe3 0xd8 0x7d ⟨1659099261⟩ (by native_decide)
(by simpa [feIndexedPackedStoreSelBytes] using hsel)
have rd0 := RD.initState (g := g) (σ := σ) (σ₀ := σ₀) (A := A) hcode
rd_run rd0 to 136 using [lt_four_eq_zero_of_ge hsz hsize, selWord_eq hword]
exact ⟨_, _, rd0⟩
/-- Dispatcher path to `get(uint256)` (arm entry pc 271). -/
theorem feIndexedPackedStoreReachGetBody {σ σ₀ A I} {g : Sat256}
(hcode : I.code = feIndexedPackedStoreBytecode) (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size)
(hsel : selIs I (feIndexedPackedStoreSelBytes 2)) :
∃ k C, RD (feIndexedPackedStoreBytecode) I g (initState σ σ₀ g A I) (UInt256.ofNat 271)
[(UInt256.shiftRight (uInt256OfByteArray (I.calldata.readBytes (⟨0⟩ : UInt256).toNat 32)) (UInt256.ofNat 224))]
ByteArray.empty
(UInt256.ofNat 0) ByteArray.empty σ k C := by
have hword : solcSelectorWord I = ⟨2500318106⟩ :=
solcSelectorWord_eq_of_beq I hsz 0x95 0x07 0xd3 0x9a ⟨2500318106⟩ (by native_decide)
(by simpa [feIndexedPackedStoreSelBytes] using hsel)
have rd0 := RD.initState (g := g) (σ := σ) (σ₀ := σ₀) (A := A) hcode
rd_run rd0 to 271 using [lt_four_eq_zero_of_ge hsz hsize, selWord_eq hword]
exact ⟨_, _, rd0⟩
/-- Calldata shorter than a selector -/
theorem feIndexedPackedStoreX_short {σ σ₀ A I} {g : Sat256}
(hcode : I.code = feIndexedPackedStoreBytecode)
(hshort : I.calldata.size < 4) :
RDrev (feIndexedPackedStoreBytecode) g (initState σ σ₀ g A I) := by
have rd0 := RD.initState (g := g) (σ := σ) (σ₀ := σ₀) (A := A) hcode
rd_run rd0 using [lt_four_ne_zero_of_lt hshort]
exact rd0
/-- No selector matches -/
theorem feIndexedPackedStoreX_noMatch {σ σ₀ A I} {g : Sat256}
(hcode : I.code = feIndexedPackedStoreBytecode)
(hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size)
(hnm : ∀ i, i < 3 → (feIndexedPackedStoreSelBytes i == I.calldata.extract 0 4) = false) :
RDrev (feIndexedPackedStoreBytecode) g (initState σ σ₀ g A I) := by
have rd0 := RD.initState (g := g) (σ := σ) (σ₀ := σ₀) (A := A) hcode
have rd1 := feIndexedPackedStoreBlocks.feIndexedPackedStore_block_0_fallthrough (by simp) (lt_four_eq_zero_of_ge hsz hsize) rd0
have rd2 := feIndexedPackedStoreBlocks.feIndexedPackedStore_block_8_fallthrough (by simp) (by
have e := setEvmSelector hsz
simp only [hnm 0 (by omega), Bool.false_eq_true, ite_false] at e
rw [uInt256_eq_comm] at e
exact e) rd1
have rd3 := feIndexedPackedStoreBlocks.feIndexedPackedStore_block_23_fallthrough (by simp) (by
have e := setTwoEvmSelector hsz
simp only [hnm 1 (by omega), Bool.false_eq_true, ite_false] at e
rw [uInt256_eq_comm] at e
exact e) rd2
have rd4 := feIndexedPackedStoreBlocks.feIndexedPackedStore_block_33_fallthrough (by simp) (by
have e := getEvmSelector hsz
simp only [hnm 2 (by omega), Bool.false_eq_true, ite_false] at e
rw [uInt256_eq_comm] at e
exact e) rd3
have rd5 := feIndexedPackedStoreBlocks.feIndexedPackedStore_block_44 (by simp) (by jump_dest) rd4
have rd6 := feIndexedPackedStoreBlocks.feIndexedPackedStore_block_54 (by simp) rd5
simpa [feIndexedPackedStoreBlocks.feIndexedPackedStore_block_8_fallthrough_stack] using rd6
end FeProofs.IndexedPackedStore