-
Notifications
You must be signed in to change notification settings - Fork 15
/
erc20.k
184 lines (165 loc) · 6.21 KB
/
erc20.k
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
/* Ahthor: Grigore Rosu
Date 2 December 2017
ERC20-K is a formalization of the informal ERC20 standard at
https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20-token-standard.md
See erc20.md for comments. */
module ERC20
syntax Value ::= Int // this can be changed
syntax Address ::= Int // this can be changed
syntax AExp ::= Value | Address
| "totalSupply" "(" ")"
| "balanceOf" "(" AExp ")" [strict]
| "allowance" "(" AExp "," AExp ")" [strict]
syntax BExp ::= Bool
| "approve" "(" AExp "," AExp ")" [strict]
| "transfer" "(" AExp "," AExp ")" [strict]
| "transferFrom" "(" AExp "," AExp "," AExp ")" [strict]
| "throw"
syntax Event ::= "Transfer" "(" Address "," Address "," Value ")"
| "Approval" "(" Address "," Address "," Value ")"
syntax EventLog ::= "Events:"
| EventLog Event
configuration <ERC20>
<caller> 0 </caller>
<k> $PGM:K </k>
<accounts>
<account multiplicity="*">
<id> 0 </id>
<balance> 0 </balance>
</account>
</accounts>
<allowances>
<allowance multiplicity="*">
<owner> 0 </owner>
<spenders>
<allow multiplicity="*">
<spender> 0 </spender>
<amount> 0 </amount>
</allow>
</spenders>
</allowance>
</allowances>
<log> Events: </log>
<supply> 0 </supply>
</ERC20>
syntax Int ::= "MAXVALUE" [function]
rule MAXVALUE => 2 ^Int 256 -Int 1
rule <k> totalSupply() => Total ...</k>
<supply> Total </supply>
rule <k> balanceOf(Id) => Value ...</k>
<id> Id </id>
<balance> Value </balance>
rule <k> allowance(Owner, Spender) => Allowance ...</k>
<owner> Owner </owner>
<spender> Spender </spender>
<amount> Allowance </amount>
rule <k> approve(Spender, Allowance) => true ...</k>
<caller> Owner </caller>
<owner> Owner </owner>
<spender> Spender </spender>
<amount> _ => Allowance </amount>
<log> Log => Log Approval(Owner, Spender, Allowance) </log>
requires Allowance >=Int 0
rule <k> approve(_, Allowance) => throw ...</k>
requires Allowance <Int 0
rule <k> transfer(To, Value) => true ...</k>
<caller> From </caller>
<account>
<id> From </id>
<balance> BalanceFrom => BalanceFrom -Int Value </balance>
</account>
<account>
<id> To </id>
<balance> BalanceTo => BalanceTo +Int Value </balance>
</account>
<log> Log => Log Transfer(From, To, Value) </log>
requires To =/=Int From // sanity check
andBool Value >=Int 0
andBool Value <=Int BalanceFrom
andBool BalanceTo +Int Value <=Int MAXVALUE
rule <k> transfer(From, Value) => true ...</k>
<caller> From </caller>
<id> From </id>
<balance> BalanceFrom </balance>
<log> Log => Log Transfer(From, From, Value) </log>
requires Value >=Int 0
andBool Value <=Int BalanceFrom
rule <k> transfer(To, Value) => throw ...</k>
<caller> From </caller>
<account>
<id> From </id>
<balance> BalanceFrom </balance>
</account>
<account>
<id> To </id>
<balance> BalanceTo </balance>
</account>
requires To =/=Int From // sanity check
andBool (Value <Int 0
orBool Value >Int BalanceFrom
orBool BalanceTo +Int Value >Int MAXVALUE)
rule <k> transfer(From, Value) => throw ...</k>
<caller> From </caller>
<id> From </id>
<balance> BalanceFrom </balance>
requires Value <Int 0
orBool Value >Int BalanceFrom
rule <k> transferFrom(From, To, Value) => true ...</k>
<caller> Caller </caller>
<owner> From </owner>
<spender> Caller </spender>
<amount> Allowance => Allowance -Int Value </amount>
<account>
<id> From </id>
<balance> BalanceFrom => BalanceFrom -Int Value </balance>
</account>
<account>
<id> To </id>
<balance> BalanceTo => BalanceTo +Int Value </balance>
</account>
<log> Log => Log Transfer(From, To, Value) </log>
requires To =/=Int From // sanity check
andBool Value >=Int 0
andBool Value <=Int BalanceFrom
andBool Value <=Int Allowance // `transfer` does not check allowance
andBool BalanceTo +Int Value <=Int MAXVALUE
rule <k> transferFrom(From, From, Value) => true ...</k>
<caller> Caller </caller>
<owner> From </owner>
<spender> Caller </spender>
<amount> Allowance => Allowance -Int Value </amount>
<id> From </id>
<balance> BalanceFrom </balance>
<log> Log => Log Transfer(From, From, Value) </log>
requires Value >=Int 0
andBool Value <=Int BalanceFrom
andBool Value <=Int Allowance // `transfer` does not check allowance
rule <k> transferFrom(From, To, Value) => throw ...</k>
<caller> Caller </caller>
<owner> From </owner>
<spender> Caller </spender>
<amount> Allowance </amount>
<account>
<id> From </id>
<balance> BalanceFrom </balance>
</account>
<account>
<id> To </id>
<balance> BalanceTo </balance>
</account>
requires To =/=Int From // sanity check
andBool (Value <Int 0
orBool Value >Int BalanceFrom
orBool Value >Int Allowance
orBool BalanceTo +Int Value >Int MAXVALUE)
rule <k> transferFrom(From, From, Value) => throw ...</k>
<caller> Caller </caller>
<owner> From </owner>
<spender> Caller </spender>
<amount> Allowance </amount>
<id> From </id>
<balance> BalanceFrom </balance>
requires Value <Int 0
orBool Value >Int BalanceFrom
orBool Value >Int Allowance // `transfer` does not check allowance
endmodule