Repository navigation
Expand file tree
/
Copy pathDispatch.lean
More file actions
92 lines (78 loc) · 4.14 KB
/
Copy pathDispatch.lean
File metadata and controls
92 lines (78 loc) · 4.14 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
import FeProofs.Constant.Common
import FeProofs.Constant.RuntimeBlocks_001
/-!
# FeConstant 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.Constant
set_option maxRecDepth 2000000
/-! ## Stele dispatch: which transition a selector reaches -/
theorem feConstantDispatch_answer {I : ExecutionEnv}
(hsel : selIs I (feConstantSelBytes 0)) :
dispatchMsg contract I.calldata = some answerTransition := by
refine dispatchMsg_eq_some_of_split (contract := contract)
(pre := []) (post := [])
(ti := answerTransition) (cd := I.calldata) (by rfl) ?_ ?_ ?_ (by rfl)
· exact transitions_eq
· intro u hu
simp at hu
· rw [answerSelectorOf]; exact hsel
theorem feConstantDispatch_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
· rw [answerSelectorOf]; rfl
theorem feConstantDispatch_none_nomatch {I : ExecutionEnv}
(hnm : ∀ i, i < 1 → (feConstantSelBytes 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
· rw [answerSelectorOf]; exact hnm 0 (by omega)
/-! ## Runtime dispatcher paths -/
/-- Dispatcher path to `answer()` (arm entry pc 26). -/
theorem feConstantReachAnswerBody {σ σ₀ A I} {g : Sat256}
(hcode : I.code = feConstantBytecode) (hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size)
(hsel : selIs I (feConstantSelBytes 0)) :
∃ k C, RD (feConstantBytecode) I g (initState σ σ₀ g A I) (UInt256.ofNat 26)
[(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 = ⟨2243657065⟩ :=
solcSelectorWord_eq_of_beq I hsz 0x85 0xbb 0x7d 0x69 ⟨2243657065⟩ (by native_decide)
(by simpa [feConstantSelBytes] using hsel)
have rd0 := RD.initState (g := g) (σ := σ) (σ₀ := σ₀) (A := A) hcode
rd_run rd0 to 26 using [lt_four_eq_zero_of_ge hsz hsize, selWord_eq hword]
exact ⟨_, _, rd0⟩
/-- Calldata shorter than a selector -/
theorem feConstantX_short {σ σ₀ A I} {g : Sat256}
(hcode : I.code = feConstantBytecode)
(hshort : I.calldata.size < 4) :
RDrev (feConstantBytecode) 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 feConstantX_noMatch {σ σ₀ A I} {g : Sat256}
(hcode : I.code = feConstantBytecode)
(hsz : 4 ≤ I.calldata.size) (hsize : I.calldata.size < UInt256.size)
(hnm : ∀ i, i < 1 → (feConstantSelBytes i == I.calldata.extract 0 4) = false) :
RDrev (feConstantBytecode) g (initState σ σ₀ g A I) := by
have rd0 := RD.initState (g := g) (σ := σ) (σ₀ := σ₀) (A := A) hcode
have rd1 := feConstantBlocks.feConstant_block_0_fallthrough (by simp) (lt_four_eq_zero_of_ge hsz hsize) rd0
have rd2 := feConstantBlocks.feConstant_block_8_fallthrough (by simp) (by
have e := answerEvmSelector 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 := feConstantBlocks.feConstant_block_23 (by simp [feConstantBlocks.feConstant_block_8_fallthrough_stack]) (by jump_dest) rd2
have rd4 := feConstantBlocks.feConstant_block_32 (by simp [feConstantBlocks.feConstant_block_8_fallthrough_stack]) rd3
simpa [feConstantBlocks.feConstant_block_8_fallthrough_stack] using rd4
end FeProofs.Constant