Repository navigation
Expand file tree
/
Copy pathMapStorage.lean
More file actions
98 lines (84 loc) · 5.13 KB
/
Copy pathMapStorage.lean
File metadata and controls
98 lines (84 loc) · 5.13 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
import FeProofs.WETH9.Common
import FeProofs.Common.Glue
import FeProofs.Common.Storage
/-!
# FeWETH9 mapping facts
`Common/Storage.lean`'s mapping lemmas for `balanceOf` (slot 3) and the map of maps `allowance`
(slot 4), for key expressions that evaluate to addresses. FeWETH9 hashes the 64-byte preimage in
freshly allocated memory (`keccakWord_mapSlotAt`).
-/
open Stele ABI Ethereum Ethereum.EVM Reasoning.Theory Reasoning.Reach
namespace FeProofs.WETH9
set_option maxRecDepth 2000000
section
variable {L : Store} {evm : EVM.State} {e f : Expr} {a b : AccountAddress}
/-- `balanceOf[e]`, for a key `e` evaluating to the address `a`, reads the word at
`mapSlot a 3`. -/
theorem balanceOf_read (hL : L.get? "balanceOf" = none)
(he : evalExpr? config { contract := contract, locals := L } evm e = .ok (.address a)) :
evalExpr? config { contract := contract, locals := L } evm
(.storage { base := "balanceOf", steps := [.mindex e] }) =
.ok (.int (Int.ofNat (Stele.EVM.storageLoad evm evm.executionEnv.codeOwner
(mapSlot (keyValueToWord (.address a)) ⟨3⟩)).toNat)) :=
map_read (layout := solidityLayout! [contract.structs] [contract.storage]) rfl
(fun _ => rfl) (fun _ => rfl) hL he
/-- Writing `w` to `balanceOf[e]` stores it at `mapSlot a 3`. -/
theorem balanceOf_assign (hL : L.get? "balanceOf" = none)
(he : evalExpr? config { contract := contract, locals := L } evm e = .ok (.address a))
(w : UInt256) :
assignStorageRef? config { contract := contract, locals := L } evm .storage
{ base := "balanceOf", steps := [.mindex e] } (.int (Int.ofNat w.toNat)) =
.ok ({ contract := contract, locals := L }, Stele.EVM.storageStore evm
evm.executionEnv.codeOwner (mapSlot (keyValueToWord (.address a)) ⟨3⟩) w) :=
map_assign (layout := solidityLayout! [contract.structs] [contract.storage]) rfl
(fun _ => rfl) (fun _ => rfl) hL he w
/-- Writing the integer `n` to `balanceOf[e]` stores its wrapped word at `mapSlot a 3`. -/
theorem balanceOf_assign_int (hL : L.get? "balanceOf" = none)
(he : evalExpr? config { contract := contract, locals := L } evm e = .ok (.address a))
(n : Int) :
assignStorageRef? config { contract := contract, locals := L } evm .storage
{ base := "balanceOf", steps := [.mindex e] } (.int n) =
.ok ({ contract := contract, locals := L }, Stele.EVM.storageStore evm
evm.executionEnv.codeOwner (mapSlot (keyValueToWord (.address a)) ⟨3⟩) (EVM.wordOfInt n)) :=
map_assign_int (layout := solidityLayout! [contract.structs] [contract.storage]) rfl
(fun _ => rfl) (fun _ => rfl) hL he n
/-- `allowance[e][f]`, for keys evaluating to the addresses `a` and `b`, reads the word at
`mapSlot b (mapSlot a 4)`. -/
theorem allowance_read (hL : L.get? "allowance" = none)
(he : evalExpr? config { contract := contract, locals := L } evm e = .ok (.address a))
(hf : evalExpr? config { contract := contract, locals := L } evm f = .ok (.address b)) :
evalExpr? config { contract := contract, locals := L } evm
(.storage { base := "allowance", steps := [.mindex e, .mindex f] }) =
.ok (.int (Int.ofNat (Stele.EVM.storageLoad evm evm.executionEnv.codeOwner
(mapSlot (keyValueToWord (.address b))
(mapSlot (keyValueToWord (.address a)) ⟨4⟩))).toNat)) :=
map2_read (layout := solidityLayout! [contract.structs] [contract.storage]) rfl
(fun _ _ => rfl) (fun _ _ => rfl) hL he hf
/-- Writing `w` to `allowance[e][f]` stores it at `mapSlot b (mapSlot a 4)`. -/
theorem allowance_assign (hL : L.get? "allowance" = none)
(he : evalExpr? config { contract := contract, locals := L } evm e = .ok (.address a))
(hf : evalExpr? config { contract := contract, locals := L } evm f = .ok (.address b))
(w : UInt256) :
assignStorageRef? config { contract := contract, locals := L } evm .storage
{ base := "allowance", steps := [.mindex e, .mindex f] } (.int (Int.ofNat w.toNat)) =
.ok ({ contract := contract, locals := L }, Stele.EVM.storageStore evm
evm.executionEnv.codeOwner
(mapSlot (keyValueToWord (.address b)) (mapSlot (keyValueToWord (.address a)) ⟨4⟩)) w) :=
map2_assign (layout := solidityLayout! [contract.structs] [contract.storage]) rfl
(fun _ _ => rfl) (fun _ _ => rfl) hL he hf w
/-- Writing the integer `n` to `allowance[e][f]` stores its wrapped word at
`mapSlot b (mapSlot a 4)`. -/
theorem allowance_assign_int (hL : L.get? "allowance" = none)
(he : evalExpr? config { contract := contract, locals := L } evm e = .ok (.address a))
(hf : evalExpr? config { contract := contract, locals := L } evm f = .ok (.address b))
(n : Int) :
assignStorageRef? config { contract := contract, locals := L } evm .storage
{ base := "allowance", steps := [.mindex e, .mindex f] } (.int n) =
.ok ({ contract := contract, locals := L }, Stele.EVM.storageStore evm
evm.executionEnv.codeOwner
(mapSlot (keyValueToWord (.address b)) (mapSlot (keyValueToWord (.address a)) ⟨4⟩))
(EVM.wordOfInt n)) :=
map2_assign_int (layout := solidityLayout! [contract.structs] [contract.storage]) rfl
(fun _ _ => rfl) (fun _ _ => rfl) hL he hf n
end
end FeProofs.WETH9