-
Notifications
You must be signed in to change notification settings - Fork 106
/
test_op_misc.nim
287 lines (267 loc) · 6.23 KB
/
test_op_misc.nim
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
# Nimbus
# Copyright (c) 2019-2024 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
# http:https://www.apache.org/licenses/LICENSE-2.0)
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or
# http:https://opensource.org/licenses/MIT)
# at your option. This file may not be copied, modified, or distributed except
# according to those terms.
import
macro_assembler,
unittest2,
eth/common
proc opMiscMain*() =
suite "Misc Opcodes":
assembler: # Log0 OP
title: "Log0"
code:
Push2 "0x1234"
Push1 "0x00"
Mstore
Push1 "0x20"
Push1 "0x00"
Log0
memory:
"0x1234"
logs:
(
address: "0x460121576cc7df020759730751f92bd62fd78dd6",
data: "0x0000000000000000000000000000000000000000000000000000000000001234"
)
assembler: # Log1 OP
title: "Log1"
code:
Push2 "0x1234"
Push1 "0x00"
Mstore
Push2 "0x9999"
Push1 "0x20"
Push1 "0x00"
Log1
memory:
"0x1234"
logs:
(
address: "0x460121576cc7df020759730751f92bd62fd78dd6",
topics: ["0x9999"],
data: "0x0000000000000000000000000000000000000000000000000000000000001234"
)
assembler: # Log2 OP
title: "Log2"
code:
Push2 "0x1234"
Push1 "0x00"
Mstore
Push2 "0x9999"
Push2 "0x6666"
Push1 "0x20"
Push1 "0x00"
Log2
memory:
"0x1234"
logs:
(
address: "0x460121576cc7df020759730751f92bd62fd78dd6",
topics: ["0x6666", "0x9999"],
data: "0x0000000000000000000000000000000000000000000000000000000000001234"
)
assembler: # Log3 OP
title: "Log3"
code:
Push2 "0x1234"
Push1 "0x00"
Mstore
Push2 "0x9999"
Push2 "0x6666"
Push2 "0x3333"
Push1 "0x20"
Push1 "0x00"
Log3
memory:
"0x1234"
logs:
(
address: "0x460121576cc7df020759730751f92bd62fd78dd6",
topics: ["0x3333", "0x6666", "0x9999"],
data: "0x0000000000000000000000000000000000000000000000000000000000001234"
)
assembler: # Log4 OP
title: "Log4"
code:
Push2 "0x1234"
Push1 "0x00"
Mstore
Push2 "0x9999"
Push2 "0x6666"
Push2 "0x3333"
Push2 "0x5555"
Push1 "0x20"
Push1 "0x00"
Log4
memory:
"0x1234"
logs:
(
address: "0x460121576cc7df020759730751f92bd62fd78dd6",
topics: ["0x5555", "0x3333", "0x6666", "0x9999"],
data: "0x0000000000000000000000000000000000000000000000000000000000001234"
)
assembler: # Stop OP
title: "Stop_1"
code:
Push1 "0x20"
Push1 "0x30"
Push1 "0x10"
Push1 "0x30"
Push1 "0x11"
Push1 "0x23"
Stop
stack:
"0x20"
"0x30"
"0x10"
"0x30"
"0x11"
"0x23"
assembler: # Return OP
title: "Return_1"
code:
Push2 "0x1234"
Push1 "0x00"
Mstore
Push1 "0x20"
Push1 "0x00"
Return
memory: "0x1234"
output: "0x0000000000000000000000000000000000000000000000000000000000001234"
assembler: # Return OP
title: "Return_2"
code:
Push2 "0x1234"
Push1 "0x00"
Mstore
Push1 "0x20"
Push1 "0x1F"
Return
memory:
"0x1234"
"0x00"
output: "0x3400000000000000000000000000000000000000000000000000000000000000"
assembler: # Return OP
title: "Return_3"
code:
Push32 "0xA0B0C0D0E0F0A1B1C1D1E1F1A2B2C2D2E2F2A3B3C3D3E3F3A4B4C4D4E4F4A1B1"
Push1 "0x00"
Mstore
Push1 "0x20"
Push1 "0x00"
Return
memory: "0xa0b0c0d0e0f0a1b1c1d1e1f1a2b2c2d2e2f2a3b3c3d3e3f3a4b4c4d4e4f4a1b1"
output: "0xA0B0C0D0E0F0A1B1C1D1E1F1A2B2C2D2E2F2A3B3C3D3E3F3A4B4C4D4E4F4A1B1"
assembler: # Return OP
title: "Return_4"
code:
Push32 "0xA0B0C0D0E0F0A1B1C1D1E1F1A2B2C2D2E2F2A3B3C3D3E3F3A4B4C4D4E4F4A1B1"
Push1 "0x00"
Mstore
Push1 "0x20"
Push1 "0x10"
Return
output: "0xE2F2A3B3C3D3E3F3A4B4C4D4E4F4A1B100000000000000000000000000000000"
memory:
"0xA0B0C0D0E0F0A1B1C1D1E1F1A2B2C2D2E2F2A3B3C3D3E3F3A4B4C4D4E4F4A1B1"
"0x00"
#[
EIP-2315: Simple Subroutines for the EVM
disabled reason: not included in Berlin hard fork
assembler:
title: "Simple routine"
code:
Push1 "0x04"
JUMPSUB
Stop
BEGINSUB
ReturnSUB
gasUsed: 18
fork: berlin
assembler:
title: "Two levels of subroutines"
code:
Push9 "0x00000000000000000C"
JUMPSUB
Stop
BEGINSUB
Push1 "0x11"
JUMPSUB
ReturnSUB
BEGINSUB
ReturnSUB
gasUsed: 36
fork: berlin
assembler:
title: "Failure 1: invalid jump"
code:
Push9 "0x01000000000000000C"
JUMPSUB
Stop
BEGINSUB
Push1 "0x11"
JUMPSUB
ReturnSUB
BEGINSUB
ReturnSUB
success: false
fork: berlin
assembler:
title: "Failure 2: shallow return stack"
code:
ReturnSUB
PC
PC
success: false
fork: berlin
assembler:
title: "Subroutine at end of code"
code:
Push1 "0x05"
JUMP
BEGINSUB
ReturnSUB
JUMPDEST
Push1 "0x03"
JUMPSUB
gasUsed: 30
fork: berlin
assembler:
title: "Error on 'walk-into-subroutine'"
code:
BEGINSUB
ReturnSUB
Stop
success: false
fork: berlin
assembler:
title: "sol test"
code:
Push1 "0x02"
Push1 "0x03"
Push1 "0x08" # jumpdest
JUMPSUB
Stop
# 0x08
BEGINSUB
Push1 "0x0D" # jumpdest
JUMPSUB
ReturnSUB
# 0x0D
BEGINSUB
MUL
ReturnSUB
gasUsed: 47
fork: berlin
stack:
"0x06"
]#
when isMainModule:
opMiscMain()