/
spec-tmpl.k
180 lines (172 loc) · 6.31 KB
/
spec-tmpl.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
// {RULENAME} {COMMENT}
rule
<k> {K} </k>
<exit-code> 1 </exit-code>
<mode> NORMAL </mode>
<schedule> BYZANTIUM </schedule>
<analysis> .Map </analysis> // not part of evm
<ethereum>
<evm>
<output> {OUTPUT} </output>
<statusCode> {STATUSCODE} </statusCode>
<callStack> {CALLSTACK} </callStack>
<interimStates> _ </interimStates>
<touchedAccounts> _ => _ </touchedAccounts>
<callState>
<program> #asMapOpCodes(#dasmOpCodes(#parseByteStack({CODE}), BYZANTIUM)) </program>
<programBytes> #parseByteStack({CODE}) </programBytes>
<id> {THIS} </id> // this
<caller> {MSG_SENDER} </caller> // msg.sender
<callData> {CALLDATA} </callData> // msg.data
<callValue> {CALLVALUE} </callValue> // msg.value
<wordStack> {WORDSTACK} </wordStack>
<localMem> {LOCALMEM} </localMem>
<pc> {PC} </pc>
<gas> {GAS} </gas>
<memoryUsed> {MEMORYUSED} </memoryUsed>
<previousGas> _ => _ </previousGas>
<static> false </static> // NOTE: non-static call
<callDepth> {CALLDEPTH} </callDepth>
</callState>
<substate>
<selfDestruct> _ </selfDestruct>
<log> {LOG} </log>
<refund> {REFUND} </refund>
</substate>
<gasPrice> _ </gasPrice>
<origin> ORIGIN_ID </origin> // tx.origin
<previousHash> _ </previousHash>
<ommersHash> _ </ommersHash>
<coinbase> {COINBASE} </coinbase> // block.coinbase
<stateRoot> _ </stateRoot>
<transactionsRoot> _ </transactionsRoot>
<receiptsRoot> _ </receiptsRoot>
<logsBloom> _ </logsBloom>
<difficulty> _ </difficulty>
<number> BLOCK_NUM </number> // block.number
<gasLimit> _ </gasLimit>
<gasUsed> _ </gasUsed>
<timestamp> NOW </timestamp> // now = block.timestamp
<extraData> _ </extraData>
<mixHash> _ </mixHash>
<blockNonce> _ </blockNonce>
<ommerBlockHeaders> _ </ommerBlockHeaders>
<blockhash> BLOCK_HASHES </blockhash> // block.blockhash
</evm>
<network>
<activeAccounts> {ACTIVEACCOUNTS} </activeAccounts>
<accounts>
<account>
<acctID> #MASTER_COPY_ID </acctID>
<balance> {MASTER_COPY_BAL} </balance>
<code> #parseByteStack({MASTER_COPY_CODE}) </code>
<storage>
{MASTER_COPY_STORAGE}
</storage>
<origStorage>
{MASTER_COPY_ORIGSTORAGE}
</origStorage>
<nonce> {MASTER_COPY_NONCE} </nonce>
</account>
<account>
<acctID> #PROXY_ID </acctID>
<balance> {PROXY_BAL} </balance>
<code> #parseByteStack({PROXY_CODE}) </code>
<storage>
{PROXY_STORAGE}
</storage>
<origStorage>
{PROXY_ORIGSTORAGE}
</origStorage>
<nonce> {PROXY_NONCE} </nonce>
</account>
<account>
<acctID> #ORIGIN_ID </acctID>
<balance> {ORIGIN_BAL} </balance>
<code> {ORIGIN_CODE} </code>
<storage>
{ORIGIN_STORAGE}
</storage>
<origStorage>
{ORIGIN_ORIGSTORAGE}
</origStorage>
<nonce> {ORIGIN_NONCE} </nonce>
</account>
<account>
<acctID> #EXEC_ACCT_TO </acctID>
<balance> {ACCT_TO_BAL} </balance>
<code> {ACCT_TO_CODE} </code>
<storage>
{ACCT_TO_STORAGE}
</storage>
<origStorage>
{ACCT_TO_ORIGSTORAGE}
</origStorage>
<nonce> {ACCT_TO_NONCE} </nonce>
</account>
<account>
<acctID> #REFUND_RECEIVER </acctID>
<balance> {RECEIVER_BAL} </balance>
<code> {RECEIVER_CODE} </code>
<storage>
{RECEIVER_STORAGE}
</storage>
<origStorage>
{RECEIVER_ORIGSTORAGE}
</origStorage>
<nonce> {RECEIVER_NONCE} </nonce>
</account>
<account>
// precompiled account for ECCREC
<acctID> 1 </acctID>
<balance> 0 </balance>
<code> .WordStack </code>
<storage> .Map </storage>
<origStorage> .Map </origStorage>
<nonce> 0 </nonce>
</account>
<account>
// testing the external contract call in checkSignatures
<acctID> #parseHexWord(substrString({SIG_BYTES}, 0, 32)) </acctID>
<balance> _ </balance>
<code> #parseByteStack({EXTERNAL_CONTRACT_CODE}) </code>
<storage> _ </storage>
<origStorage> _ </origStorage>
<nonce> _ </nonce>
</account>
{ACCOUNTS}
...
</accounts>
<txOrder> _ </txOrder>
<txPending> _ </txPending>
<messages> _ </messages>
</network>
</ethereum>
requires #rangeAddress(ORIGIN_ID)
andBool #rangeAddress(#MASTER_COPY_ID)
andBool #rangeAddress(#PROXY_ID)
andBool #rangeAddress(#ORIGIN_ID)
andBool #rangeAddress(#EXEC_ACCT_TO)
andBool #rangeAddress(#REFUND_RECEIVER)
andBool #rangeUInt(256, NOW)
andBool #rangeUInt(128, BLOCK_NUM) // Solidity
andBool #MASTER_COPY_ID =/=Int #PROXY_ID
andBool #MASTER_COPY_ID =/=Int #ORIGIN_ID
andBool #MASTER_COPY_ID =/=Int #EXEC_ACCT_TO
andBool #MASTER_COPY_ID =/=Int #REFUND_RECEIVER
andBool #PROXY_ID =/=Int #ORIGIN_ID
andBool #PROXY_ID =/=Int #EXEC_ACCT_TO
andBool #PROXY_ID =/=Int #REFUND_RECEIVER
andBool #ORIGIN_ID =/=Int #EXEC_ACCT_TO
andBool #ORIGIN_ID =/=Int #REFUND_RECEIVER
andBool #EXEC_ACCT_TO =/=Int #REFUND_RECEIVER
// Account address normality
andBool #MASTER_COPY_ID >Int 0 andBool (notBool #MASTER_COPY_ID in #precompiledAccounts(BYZANTIUM))
andBool #PROXY_ID >Int 0 andBool (notBool #PROXY_ID in #precompiledAccounts(BYZANTIUM))
andBool #ORIGIN_ID >Int 0 andBool (notBool #ORIGIN_ID in #precompiledAccounts(BYZANTIUM))
andBool #EXEC_ACCT_TO >Int 0 andBool (notBool #EXEC_ACCT_TO in #precompiledAccounts(BYZANTIUM))
andBool #REFUND_RECEIVER >Int 0 andBool (notBool #REFUND_RECEIVER in #precompiledAccounts(BYZANTIUM))
{REQUIRES}
ensures true
{ENSURES}
{ATTRIBUTE}