Repository navigation
Expand file tree
/
Copy pathCorrect.lean
More file actions
64 lines (54 loc) · 2.84 KB
/
Copy pathCorrect.lean
File metadata and controls
64 lines (54 loc) · 2.84 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
import FeProofs.PackedStore.Constructor
import FeProofs.PackedStore.Get1
import FeProofs.PackedStore.Get0
import FeProofs.PackedStore.SetBoth
import FeProofs.PackedStore.Set1
import FeProofs.PackedStore.Set0
import Stele.Refine
/-!
# FePackedStore correctness capstone (generated by `scripts/proof_skeleton.py`)
Thin top-level: the selector case split routes each selector to its per-function `…Body`
lemma, the shared revert paths close the rest, and the constructor is packaged into the
whole-contract refinement.
-/
open Stele ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach
namespace FeProofs.PackedStore
set_option maxRecDepth 2000000
theorem fePackedStoreNoDispatch {σ σ₀ A I} {g : UInt256}
(hcode : I.code = fePackedStoreBytecode) (hsize : I.calldata.size < UInt256.size)
(hnm : ∀ i, i < 5 → (fePackedStoreSelBytes i == I.calldata.extract 0 4) = false) :
runtimeRefinementFor config contract σ σ₀ g A I := by
by_cases hsz : 4 ≤ I.calldata.size
· exact (fePackedStoreX_noMatch (g := Sat256.ofUInt256 g) hcode hsz hsize hnm)
|>.reEquivNoDispatch hcode (fePackedStoreDispatch_none_nomatch hnm)
· have hshort : I.calldata.size < 4 := by omega
exact (fePackedStoreX_short (g := Sat256.ofUInt256 g) hcode hshort)
|>.reEquivNoDispatch hcode (fePackedStoreDispatch_none_short hshort)
theorem fePackedStoreNoSelectorMatches {I : ExecutionEnv}
(h0 : ¬ selIs I (fePackedStoreSelBytes 0)) (h1 : ¬ selIs I (fePackedStoreSelBytes 1)) (h2 : ¬ selIs I (fePackedStoreSelBytes 2)) (h3 : ¬ selIs I (fePackedStoreSelBytes 3)) (h4 : ¬ selIs I (fePackedStoreSelBytes 4)) :
∀ i, i < 5 → (fePackedStoreSelBytes i == I.calldata.extract 0 4) = false := by
intro i hi
interval_cases i
· simpa [selIs] using h0
· simpa [selIs] using h1
· simpa [selIs] using h2
· simpa [selIs] using h3
· simpa [selIs] using h4
theorem fePackedStoreCorrect :
runtimeRefinement config (fePackedStoreBytecode) contract := by
refine ⟨fun σ σ₀ g A I hcode hsize ↦ ?_⟩
by_cases h0 : selIs I (fePackedStoreSelBytes 0)
· exact fePackedStoreGet1Body hcode hsize h0
· by_cases h1 : selIs I (fePackedStoreSelBytes 1)
· exact fePackedStoreGet0Body hcode hsize h1
· by_cases h2 : selIs I (fePackedStoreSelBytes 2)
· exact fePackedStoreSetBothBody hcode hsize h2
· by_cases h3 : selIs I (fePackedStoreSelBytes 3)
· exact fePackedStoreSet1Body hcode hsize h3
· by_cases h4 : selIs I (fePackedStoreSelBytes 4)
· exact fePackedStoreSet0Body hcode hsize h4
· exact fePackedStoreNoDispatch hcode hsize (fePackedStoreNoSelectorMatches h0 h1 h2 h3 h4)
theorem fePackedStoreContractCorrect :
contractRefinement config fePackedStoreCreationBytecode contract :=
contractRefinement.of_constant fePackedStoreConstructorCorrect fePackedStoreCorrect
end FeProofs.PackedStore