Repository navigation
Expand file tree
/
Copy pathModel.lean
More file actions
57 lines (43 loc) · 1.5 KB
/
Copy pathModel.lean
File metadata and controls
57 lines (43 loc) · 1.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
import Fe.EVM.Storage
import Fe.EVM.Refine
/-!
# FeCodeScalar model
Written by hand, in the shape the exporter prints.
```fe
pub contract FeCodeScalar {
value: u256
init(initial: u256) uses (mut value) { value = initial }
recv FeCodeScalarMsg {
Get -> u256 uses (value) { value }
}
}
```
`value` is immutable: the deployed code is the runtime bytecode followed by its word.
-/
open Ethereum Ethereum.EVM Fe Fe.EVM
namespace FeProofs.CodeScalar.Model
/-- `Get -> u256 uses (value) { value }`: the one immutable word, at the end of the code. -/
def get : FeM UInt256 := do cload (← immutableAt 1 0)
/-- `sol("get()")` -/
def getSelector : ByteArray := ⟨#[0x6d, 0x4c, 0xe6, 0x3c]⟩
/-- The constructor: reject call value and decode one word from the argument bytes. `init`
sets `value` to it, so the word is the bytes the deployed code ends with. -/
def init (args : ByteArray) : FeM ByteArray := do
nonPayable
if args.size < 32 then
M.revert ByteArray.empty
else
return (uInt256OfByteArray (args.readBytes 0 32)).toByteArray
/-- The runtime entry. The arm rejects call value and takes no arguments. -/
def runtime : FeM ByteArray := do
let cd ← calldata
if cd.size < 4 then
M.revert ByteArray.empty
else if getSelector == cd.extract 0 4 then
nonPayable
let result ← get
return result.toByteArray
else
M.revert ByteArray.empty
def contract : ContractModel := { init := init, runtime := runtime, immutables := 32 }
end FeProofs.CodeScalar.Model