Repository navigation
Expand file tree
/
Copy pathExported.lean
More file actions
351 lines (297 loc) · 12.5 KB
/
Copy pathExported.lean
File metadata and controls
351 lines (297 loc) · 12.5 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
import FeProofs.Lib.Exported
/-!
# FePackedStore: exported code
The definitions between the markers are the output of `fe-lean-export` on `FePackedStore.fe`
(Fe branch `lean-export`, golden file `tests/golden/packed_store.lean`), copied in by
`scripts/sync_exported.py`. The std functions the arms call, `StoragePackedArray<8>::get` and
`set`, and the constants those read are shared with the other exported contracts, in
`FeProofs/Lib/Exported.lean`.
`ExportedCorrect.lean` evaluates the arms; `HandEntry.lean` and `RuntimeCorrect.lean` prove that
the bytecode refines them, under a hand-written entry and under the exported one.
The definitions end with the runtime entry: one `recv_<Variant>_entry` per arm and `runtime`, with
the std decoders at the contract's message types. `RuntimeCorrect.lean` proves that `fePackedStoreBytecode`,
built by the Fe commit the exporter ran on (`22b156fff`), refines the contract whose runtime is
that entry.
-/
open Ethereum Ethereum.EVM Fe Fe.EVM
namespace FeProofs.PackedStore.Exported
section
set_option linter.unusedVariables false
-- BEGIN fe-lean-export: packed_store
export Lib (CallData Evm_input Evm_return_value_Sol_u256 Sol_SELECTOR_SIZE Sol_validate_runtime_head StoragePackedArray_get_8 StoragePackedArray_set_8 abi_field_head_size_u256 decode_msg_field_from_Sol_u256_CallData len_CallData)
def Field.pack : Place :=
.storage (UInt256.ofNat 0)
structure Get0 where
deriving Inhabited
structure Get1 where
deriving Inhabited
structure Set0 where
value : UInt256
deriving Inhabited
structure Set1 where
value : UInt256
deriving Inhabited
structure SetBoth where
first : UInt256
second : UInt256
deriving Inhabited
/-- The `init` of contract `FePackedStore`, which its source leaves out -/
def init : FeM Unit := do
return ()
/-- `Get0 -> u256`, selector `0x90bb7b44` (`get0()`) -/
def recv_Get0 : FeM UInt256 := do
-- pack.get(0)
let v1 := Field.pack
let v3 ← StoragePackedArray_get_8 v1 (UInt256.ofNat 0)
return v3
/-- `Get1 -> u256`, selector `0x054c1a75` (`get1()`) -/
def recv_Get1 : FeM UInt256 := do
-- pack.get(1)
let v1 := Field.pack
let v3 ← StoragePackedArray_get_8 v1 (UInt256.ofNat 1)
return v3
/-- `Set0 { value }`, selector `0xf26feec9` (`set0(uint256)`) -/
def recv_Set0 (value : UInt256) : FeM Unit := do
-- pack.set(i: 0, value)
let v2 := Field.pack
let _ ← StoragePackedArray_set_8 v2 (UInt256.ofNat 0) value
return ()
/-- `Set1 { value }`, selector `0x9bc39d3c` (`set1(uint256)`) -/
def recv_Set1 (value : UInt256) : FeM Unit := do
-- pack.set(i: 1, value)
let v2 := Field.pack
let _ ← StoragePackedArray_set_8 v2 (UInt256.ofNat 1) value
return ()
/-- `SetBoth { first, second }`, selector `0x92cf1ef5` (`setBoth(uint256,uint256)`) -/
def recv_SetBoth (first : UInt256) (second : UInt256) : FeM Unit := do
-- pack.set(i: 0, value: first)
let v3 := Field.pack
let _ ← StoragePackedArray_set_8 v3 (UInt256.ofNat 0) first
-- pack.set(i: 1, value: second)
let v6 := Field.pack
let _ ← StoragePackedArray_set_8 v6 (UInt256.ofNat 1) second
return ()
/-- `<Get0 as AbiSize>::HEAD_SIZE` -/
def Get0_HEAD_SIZE : FeM UInt256 := do
return UInt256.ofNat 0
/-- `<Get0 as Decode>::decode_from<CallData>` -/
def Get0_decode_from_CallData (v0 : CallData) (v1 : UInt256) : FeM Get0 := do
return Get0.mk
/-- `core::abi::Decode::decode_from_prechecked_head<Get0, Sol, CallData>` -/
def decode_from_prechecked_head_Get0_Sol_CallData (input : CallData) (pos : UInt256) (input_len : UInt256) : FeM Get0 := do
-- Self::decode_from(input, pos)
let v3 ← Get0_decode_from_CallData input pos
return v3
/-- `core::contracts::decode_runtime_args<Evm, Sol, Get0>` -/
def decode_runtime_args_Evm_Sol_Get0 : FeM Get0 := do
let mut input : CallData := default
-- let input = host.input()
let input_2 ← Evm_input
input := input_2
-- let base = A::SELECTOR_SIZE
let base ← Sol_SELECTOR_SIZE
-- let len = input.len()
let len ← len_CallData input
-- A::validate_runtime_head(input_len: len, base, head_size: T::HEAD_SIZE)
let v9 ← Get0_HEAD_SIZE
let _ ← Sol_validate_runtime_head len base v9
-- T::decode_from_prechecked_head(input, base, len)
let v12 ← decode_from_prechecked_head_Get0_Sol_CallData input base len
return v12
/-- The entry of `recv_Get0`, for `packed_store::FePackedStoreMsg::Get0` -/
def recv_Get0_entry : FeM Empty := do
nonPayable
let message ← decode_runtime_args_Evm_Sol_Get0
let result ← recv_Get0
Evm_return_value_Sol_u256 result
/-- `<Get1 as AbiSize>::HEAD_SIZE` -/
def Get1_HEAD_SIZE : FeM UInt256 := do
return UInt256.ofNat 0
/-- `<Get1 as Decode>::decode_from<CallData>` -/
def Get1_decode_from_CallData (v0 : CallData) (v1 : UInt256) : FeM Get1 := do
return Get1.mk
/-- `core::abi::Decode::decode_from_prechecked_head<Get1, Sol, CallData>` -/
def decode_from_prechecked_head_Get1_Sol_CallData (input : CallData) (pos : UInt256) (input_len : UInt256) : FeM Get1 := do
-- Self::decode_from(input, pos)
let v3 ← Get1_decode_from_CallData input pos
return v3
/-- `core::contracts::decode_runtime_args<Evm, Sol, Get1>` -/
def decode_runtime_args_Evm_Sol_Get1 : FeM Get1 := do
let mut input : CallData := default
-- let input = host.input()
let input_2 ← Evm_input
input := input_2
-- let base = A::SELECTOR_SIZE
let base ← Sol_SELECTOR_SIZE
-- let len = input.len()
let len ← len_CallData input
-- A::validate_runtime_head(input_len: len, base, head_size: T::HEAD_SIZE)
let v9 ← Get1_HEAD_SIZE
let _ ← Sol_validate_runtime_head len base v9
-- T::decode_from_prechecked_head(input, base, len)
let v12 ← decode_from_prechecked_head_Get1_Sol_CallData input base len
return v12
/-- The entry of `recv_Get1`, for `packed_store::FePackedStoreMsg::Get1` -/
def recv_Get1_entry : FeM Empty := do
nonPayable
let message ← decode_runtime_args_Evm_Sol_Get1
let result ← recv_Get1
Evm_return_value_Sol_u256 result
/-- `<Set0 as AbiSize>::HEAD_SIZE` -/
def Set0_HEAD_SIZE : FeM UInt256 := do
let v1 ← abi_field_head_size_u256
let v2 ← checkedAdd (UInt256.ofNat 0) v1
return v2
/-- `<Set0 as Decode>::decode_from<CallData>` -/
def Set0_decode_from_CallData (v0 : CallData) (v1 : UInt256) : FeM Set0 := do
let v2 ← len_CallData v0
let v4 ← decode_msg_field_from_Sol_u256_CallData v0 v1 v1 v2
return Set0.mk v4
/-- `core::abi::Decode::decode_from_prechecked_head<Set0, Sol, CallData>` -/
def decode_from_prechecked_head_Set0_Sol_CallData (input : CallData) (pos : UInt256) (input_len : UInt256) : FeM Set0 := do
-- Self::decode_from(input, pos)
let v3 ← Set0_decode_from_CallData input pos
return v3
/-- `core::contracts::decode_runtime_args<Evm, Sol, Set0>` -/
def decode_runtime_args_Evm_Sol_Set0 : FeM Set0 := do
let mut input : CallData := default
-- let input = host.input()
let input_2 ← Evm_input
input := input_2
-- let base = A::SELECTOR_SIZE
let base ← Sol_SELECTOR_SIZE
-- let len = input.len()
let len ← len_CallData input
-- A::validate_runtime_head(input_len: len, base, head_size: T::HEAD_SIZE)
let v9 ← Set0_HEAD_SIZE
let _ ← Sol_validate_runtime_head len base v9
-- T::decode_from_prechecked_head(input, base, len)
let v12 ← decode_from_prechecked_head_Set0_Sol_CallData input base len
return v12
/-- The entry of `recv_Set0`, for `packed_store::FePackedStoreMsg::Set0` -/
def recv_Set0_entry : FeM Empty := do
nonPayable
let message ← decode_runtime_args_Evm_Sol_Set0
let _ ← recv_Set0 message.value
returnData (UInt256.ofNat 0) (UInt256.ofNat 0)
/-- `<Set1 as AbiSize>::HEAD_SIZE` -/
def Set1_HEAD_SIZE : FeM UInt256 := do
let v1 ← abi_field_head_size_u256
let v2 ← checkedAdd (UInt256.ofNat 0) v1
return v2
/-- `<Set1 as Decode>::decode_from<CallData>` -/
def Set1_decode_from_CallData (v0 : CallData) (v1 : UInt256) : FeM Set1 := do
let v2 ← len_CallData v0
let v4 ← decode_msg_field_from_Sol_u256_CallData v0 v1 v1 v2
return Set1.mk v4
/-- `core::abi::Decode::decode_from_prechecked_head<Set1, Sol, CallData>` -/
def decode_from_prechecked_head_Set1_Sol_CallData (input : CallData) (pos : UInt256) (input_len : UInt256) : FeM Set1 := do
-- Self::decode_from(input, pos)
let v3 ← Set1_decode_from_CallData input pos
return v3
/-- `core::contracts::decode_runtime_args<Evm, Sol, Set1>` -/
def decode_runtime_args_Evm_Sol_Set1 : FeM Set1 := do
let mut input : CallData := default
-- let input = host.input()
let input_2 ← Evm_input
input := input_2
-- let base = A::SELECTOR_SIZE
let base ← Sol_SELECTOR_SIZE
-- let len = input.len()
let len ← len_CallData input
-- A::validate_runtime_head(input_len: len, base, head_size: T::HEAD_SIZE)
let v9 ← Set1_HEAD_SIZE
let _ ← Sol_validate_runtime_head len base v9
-- T::decode_from_prechecked_head(input, base, len)
let v12 ← decode_from_prechecked_head_Set1_Sol_CallData input base len
return v12
/-- The entry of `recv_Set1`, for `packed_store::FePackedStoreMsg::Set1` -/
def recv_Set1_entry : FeM Empty := do
nonPayable
let message ← decode_runtime_args_Evm_Sol_Set1
let _ ← recv_Set1 message.value
returnData (UInt256.ofNat 0) (UInt256.ofNat 0)
/-- `<SetBoth as AbiSize>::HEAD_SIZE` -/
def SetBoth_HEAD_SIZE : FeM UInt256 := do
let v1 ← abi_field_head_size_u256
let v2 ← checkedAdd (UInt256.ofNat 0) v1
let v3 ← abi_field_head_size_u256
let v4 ← checkedAdd v2 v3
return v4
/-- `<SetBoth as Decode>::decode_from<CallData>` -/
def SetBoth_decode_from_CallData (v0 : CallData) (v1 : UInt256) : FeM SetBoth := do
let v2 ← len_CallData v0
let v4 ← decode_msg_field_from_Sol_u256_CallData v0 v1 v1 v2
let v7 ← abi_field_head_size_u256
let v8 ← checkedAdd v1 v7
let v9 ← decode_msg_field_from_Sol_u256_CallData v0 v1 v8 v2
return SetBoth.mk v4 v9
/-- `core::abi::Decode::decode_from_prechecked_head<SetBoth, Sol, CallData>` -/
def decode_from_prechecked_head_SetBoth_Sol_CallData (input : CallData) (pos : UInt256) (input_len : UInt256) : FeM SetBoth := do
-- Self::decode_from(input, pos)
let v3 ← SetBoth_decode_from_CallData input pos
return v3
/-- `core::contracts::decode_runtime_args<Evm, Sol, SetBoth>` -/
def decode_runtime_args_Evm_Sol_SetBoth : FeM SetBoth := do
let mut input : CallData := default
-- let input = host.input()
let input_2 ← Evm_input
input := input_2
-- let base = A::SELECTOR_SIZE
let base ← Sol_SELECTOR_SIZE
-- let len = input.len()
let len ← len_CallData input
-- A::validate_runtime_head(input_len: len, base, head_size: T::HEAD_SIZE)
let v9 ← SetBoth_HEAD_SIZE
let _ ← Sol_validate_runtime_head len base v9
-- T::decode_from_prechecked_head(input, base, len)
let v12 ← decode_from_prechecked_head_SetBoth_Sol_CallData input base len
return v12
/-- The entry of `recv_SetBoth`, for `packed_store::FePackedStoreMsg::SetBoth` -/
def recv_SetBoth_entry : FeM Empty := do
nonPayable
let message ← decode_runtime_args_Evm_Sol_SetBoth
let _ ← recv_SetBoth message.first message.second
returnData (UInt256.ofNat 0) (UInt256.ofNat 0)
/-- The runtime entry of contract `FePackedStore`: the entry of the arm the call's selector picks -/
def runtime : FeM Empty := do
let size ← calldatasize
if size.toNat < 4 then
revertEmpty
else
let selector ← calldataSelector
if selector = UInt256.ofNat 0x054c1a75 then
recv_Get1_entry
else if selector = UInt256.ofNat 0x90bb7b44 then
recv_Get0_entry
else if selector = UInt256.ofNat 0x92cf1ef5 then
recv_SetBoth_entry
else if selector = UInt256.ofNat 0x9bc39d3c then
recv_Set1_entry
else if selector = UInt256.ofNat 0xf26feec9 then
recv_Set0_entry
else
revertEmpty
/-- The deployment entry of contract `FePackedStore`: `init` on the arguments after the creation code -/
def init_entry (args : ByteArray) : FeM ByteArray := do
nonPayable
let _ ← init
return ByteArray.empty
-- END fe-lean-export
end
/- The constants the compiler folded: each is the value the exporter printed in its place. -/
-- BEGIN fe-lean-export: packed_store.checks
set_option maxRecDepth 10000 in
example : Get0_HEAD_SIZE = pure (UInt256.ofNat 0) := rfl
set_option maxRecDepth 10000 in
example : Get1_HEAD_SIZE = pure (UInt256.ofNat 0) := rfl
set_option maxRecDepth 10000 in
example : Set0_HEAD_SIZE = pure (UInt256.ofNat 32) := rfl
set_option maxRecDepth 10000 in
example : Set1_HEAD_SIZE = pure (UInt256.ofNat 32) := rfl
set_option maxRecDepth 10000 in
example : SetBoth_HEAD_SIZE = pure (UInt256.ofNat 64) := rfl
-- END fe-lean-export
/- The proofs name the library's other definitions too. -/
export_all FeProofs.Lib
end FeProofs.PackedStore.Exported