Repository navigation
Expand file tree
/
Copy pathSet0.lean
More file actions
66 lines (59 loc) · 3.28 KB
/
Copy pathSet0.lean
File metadata and controls
66 lines (59 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
import FeProofs.PackedStore.Dispatch
import FeProofs.PackedStore.Lanes
import FeProofs.Common.Basic
/-!
# FePackedStore `set0(uint256)`
Arm entry pc 188: call-value check, head-size check (pc 193), then one read-modify-write of word
`packedSlot` replacing lane 0 with the argument's low byte (pc 205). Under `STATICCALL` the
`SSTORE` halts, matching Stele's static violation at the storage assignment.
-/
open Stele ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach
namespace FeProofs.PackedStore
set_option maxRecDepth 2000000
theorem fePackedStoreSet0Body {σ σ₀ A I} {g : UInt256}
(hcode : I.code = fePackedStoreBytecode) (hsize : I.calldata.size < UInt256.size)
(hsel : selIs I (fePackedStoreSelBytes 4)) :
runtimeRefinementFor config contract σ σ₀ g A I := by
have hsz : 4 ≤ I.calldata.size := calldata_size_ge_of_selIs I (fePackedStoreSelBytes 4) rfl hsel
have hd := fePackedStoreDispatch_set0 hsel
obtain ⟨k, C, rd⟩ := fePackedStoreReachSet0Body (g := Sat256.ofUInt256 g) (σ := σ)
(σ₀ := σ₀) (A := A) hcode hsz hsize hsel
by_cases hwv : I.weiValue = ⟨0⟩
swap
· nonpayable_revert rd hcode hd hwv
by_cases hok : 36 ≤ I.calldata.size ∧ I.calldata.size < 2 ^ 255 + 4
swap
· have hbad : I.calldata.size < 36 ∨ 2 ^ 255 + 4 ≤ I.calldata.size := by omega
rd_run rd using [hwv, solcDecodeLenCheckBad 1 hsz hsize hbad]
exact RDrev.reEquivDecodingFailed hcode rd hd
(hbad.elim decodeCalldata_uint256_none_short decodeCalldata_uint256_none_huge)
obtain ⟨hlen, hhi⟩ := hok
rd_run rd to 205 using [hwv, solcDecodeLenCheckOk_4_32 hlen hhi hsize]
have hdec : config.externalABI.decodeCalldata? (set0Transition.params.map Param.name)
(transitionSignature set0Transition).paramTypes I.calldata = some (valueStore I) := by
show decodeCalldata ["value"] [abiUInt256] I.calldata = _
exact decodeCalldata_uint256_ok hlen hhi
have hval := evalCast8 (stele := { contract := contract, locals := valueStore I })
(evm := initState σ σ₀ (Sat256.ofUInt256 g) A I) (store_get_self _ _ _)
have hasg := assignLane (stele := { contract := contract, locals := valueStore I })
(evm := initState σ σ₀ (Sat256.ofUInt256 g) A I) "lane0" 0 (calldataWord I.calldata 4)
(by simp) rfl rfl
have hreq := ExecStmt.requireTrue (cfg := config)
(stele := { contract := contract, locals := valueStore I })
(evalCallvalueEq_true (evm := initState σ σ₀ (Sat256.ofUInt256 g) A I)
(by simp only [initState]; exact hwv))
by_cases hperm : I.perm = true
· rd_step rd
rw [keccak_packedSlot] at rd
exact (RDret.of_output_eq rd (byteArray_readWithPadding_zero _ _)).reEquivExecutionGen hcode hd
hdec (ExecFuncBody.execBlockOK (ExecBlock.consNormal hreq (ExecBlock.consNormal
(ExecStmt.assign (Or.inr (by simp only [initState]; exact hperm)) hval hasg)
ExecBlock.nil)))
(by rw [storeLane_accountMap, setPackedByte_lane0]; try rfl)
(returnEquiv.fallthrough rfl rfl (by native_decide))
· have hpf : I.perm = false := by simpa using hperm
rd_step rd
exact RDstatic.reEquivStaticHalt hcode rd hd hdec
(ExecFuncBody.execBlockStatic (ExecBlock.consNormal hreq (ExecBlock.consStatic
(ExecStmt.assignStatic hval hasg (by simp only [initState]; exact hpf)))))
end FeProofs.PackedStore