Repository navigation
Expand file tree
/
Copy pathCorrect.lean
More file actions
70 lines (58 loc) · 3.28 KB
/
Copy pathCorrect.lean
File metadata and controls
70 lines (58 loc) · 3.28 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
import FeProofs.Deposit.Constructor
import FeProofs.Deposit.SupportsInterface
import FeProofs.Deposit.Deposit
import FeProofs.Deposit.Get_deposit_count
import FeProofs.Deposit.Get_deposit_root
import Stele.Refine
/-!
# FeDeposit 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.Deposit
set_option maxRecDepth 2000000
theorem feDepositNoDispatch {σ σ₀ A I} {g : UInt256}
(hcode : I.code = feDepositBytecode) (hsize : I.calldata.size < UInt256.size)
(hnm : ∀ i, i < 4 → (feDepositSelBytes i == I.calldata.extract 0 4) = false) :
runtimeRefinementFor config contract σ σ₀ g A I := by
by_cases hsz : 4 ≤ I.calldata.size
· exact (feDepositX_noMatch (g := Sat256.ofUInt256 g) hcode hsz hsize hnm)
|>.reEquivNoDispatch hcode (feDepositDispatch_none_nomatch hnm)
· have hshort : I.calldata.size < 4 := by omega
exact (feDepositX_short (g := Sat256.ofUInt256 g) hcode hshort)
|>.reEquivNoDispatch hcode (feDepositDispatch_none_short hshort)
theorem feDepositNoSelectorMatches {I : ExecutionEnv}
(h0 : ¬ selIs I (feDepositSelBytes 0)) (h1 : ¬ selIs I (feDepositSelBytes 1)) (h2 : ¬ selIs I (feDepositSelBytes 2)) (h3 : ¬ selIs I (feDepositSelBytes 3)) :
∀ i, i < 4 → (feDepositSelBytes 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
/-- The calldata-size precondition of the runtime theorem.
Fe's Solidity ABI decoders rely on the Sonatina backend's bound `calldatasize < 2^62`: under it, the
`bytes` offset and length checks in `deposit` imply Solidity's `2^64` limits, so no separate check is
emitted (see Fe PR #1834). EquiVM models calldata of any size below `2^256`; for a conceptual
input of `2^64` bytes or more, `deposit` would accept a `bytes` offset Solidity rejects. Real
transactions cannot carry such calldata, so the theorem is stated for inputs below `2^64` bytes,
which Sonatina's bound implies. -/
def calldataBelow2pow64 : StorageWF := fun _ I => I.calldata.size < 2 ^ 64
theorem feDepositCorrect :
runtimeRefinementWithWF calldataBelow2pow64 noGasBound config feDepositBytecode contract := by
refine ⟨fun σ σ₀ g A I hcode hsize hsmall _ ↦ ?_⟩
by_cases h0 : selIs I (feDepositSelBytes 0)
· exact feDepositSupportsInterfaceBody hcode hsize h0
· by_cases h1 : selIs I (feDepositSelBytes 1)
· exact feDepositDepositBody hcode hsize hsmall h1
· by_cases h2 : selIs I (feDepositSelBytes 2)
· exact feDepositGet_deposit_countBody hcode hsize h2
· by_cases h3 : selIs I (feDepositSelBytes 3)
· exact feDepositGet_deposit_rootBody hcode hsize h3
· exact feDepositNoDispatch hcode hsize (feDepositNoSelectorMatches h0 h1 h2 h3)
theorem feDepositContractCorrect :
contractRefinementWF calldataBelow2pow64 noGasBound config feDepositCreationBytecode contract :=
contractRefinementWF.of_constant feDepositConstructorCorrect feDepositCorrect
end FeProofs.Deposit