forked from ethereum/go-ethereum
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathassemblyTester.sol
More file actions
621 lines (619 loc) · 17.7 KB
/
Copy pathassemblyTester.sol
File metadata and controls
621 lines (619 loc) · 17.7 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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.13;
contract assemblyTester {
/*
1: STOP
2: ADD
3: MUL
4: SUB
5: DIV
6: SDIV
7: MOD
8: SMOD
9: EXP
10: NOT
11: LT
12: GT
13: SLT
14: SGT
15: EQ
16: ISZERO
17: SIGNEXTEND
18: AND
19: OR
20: XOR
21: BYTE
22: SHL
23: SHR
24: SAR
25: ADDMOD
26: MULMOD
27: KECCAK256
28: ADDRESS
29: BALANCE
30: ORIGIN
31: CALLER
32: CALLVALUE
33: CALLDATALOAD
34: CALLDATASIZE
35: CALLDATACOPY
36: CHAINID
37: BASEFEE
38: DELEGATECALL
39: STATICCALL
40: CODESIZE
41: CODECOPY
42: GASPRICE
43: EXTCODESIZE
44: EXTCODECOPY
45: RETURNDATASIZE
46: RETURNDATACOPY
47: EXTCODEHASH
48: BLOCKHASH
49: COINBASE
50: TIMESTAMP
51: NUMBER
52: DIFFICULTY
53: GASLIMIT
54: SELFBALANCE
55: POP
56: MLOAD
57: MSTORE
58: MSTORE8
59: SLOAD
60: SSTORE
61: MSIZE
62: GAS
63: JUMPDEST
64: LOG0
65: LOG1
66: LOG2
67: LOG3
68: LOG4
69: CREATE
70: CREATE2
71: CALL
72: RETURN
73: CALLCODE
74: REVERT
75: INVALID
76: SELFDESTRUCT
*/
function run(uint32 cmd, uint32 samples) public {
if(cmd == 1) {
// Opcode: STOP
for (uint32 i = 0; i < samples; i++) {
assembly {
stop()
}
}
} else if(cmd == 2) {
// Opcode: ADD
for (uint32 i = 0; i < samples; i++) {
assembly {
let x := add(5, 0x42)
}
}
} else if(cmd == 3) {
// Opcode: MUL
for (uint32 i = 0; i < samples; i++) {
assembly {
let x := mul(5, 0x42)
}
}
} else if(cmd == 4) {
// Opcode: SUB
for (uint32 i = 0; i < samples; i++) {
assembly {
let x := sub(5, 0x42)
}
}
} else if(cmd == 5) {
// Opcode: DIV
for (uint32 i = 0; i < samples; i++) {
assembly {
let x := div(5, 0x42)
}
}
} else if(cmd == 6) {
// Opcode: SDIV
for (uint32 i = 0; i < samples; i++) {
assembly {
let x := sdiv(5, 0x42)
}
}
} else if(cmd == 7) {
// Opcode: MOD
for (uint32 i = 0; i < samples; i++) {
assembly {
let x := mod(0x42, 5)
}
}
} else if(cmd == 8) {
// Opcode: SMOD
for (uint32 i = 0; i < samples; i++) {
assembly {
let x := smod(0x42, 5)
}
}
} else if(cmd == 9) {
// Opcode: EXP
for (uint32 i = 0; i < samples; i++) {
assembly {
let x := exp(5, 0x42)
}
}
} else if(cmd == 10) {
// Opcode: NOT
for (uint32 i = 0; i < samples; i++) {
assembly {
let x := not(0x42)
}
}
} else if(cmd == 11) {
// Opcode: LT
for (uint32 i = 0; i < samples; i++) {
assembly {
let x := lt(5, 0x42)
}
}
} else if(cmd == 12) {
// Opcode: GT
for (uint32 i = 0; i < samples; i++) {
assembly {
let x := gt(5, 0x42)
}
}
} else if(cmd == 13) {
// Opcode: SLT
for (uint32 i = 0; i < samples; i++) {
assembly {
let x := slt(5, 0x42)
}
}
} else if(cmd == 14) {
// Opcode: SGT
for (uint32 i = 0; i < samples; i++) {
assembly {
let x := sgt(5, 0x42)
}
}
} else if(cmd == 15) {
// Opcode: EQ
for (uint32 i = 0; i < samples; i++) {
assembly {
let x := eq(0x42, 0x42)
}
}
} else if(cmd == 16) {
// Opcode: ISZERO
for (uint32 i = 0; i < samples; i++) {
assembly {
let x := iszero(0x42)
}
}
} else if(cmd == 17) {
// Opcode: SIGNEXTEND
for (uint32 i = 0; i < samples; i++) {
assembly {
let x := signextend(5, 0x42)
}
}
} else if(cmd == 18) {
// Opcode: AND
for (uint32 i = 0; i < samples; i++) {
assembly {
let x := and(5, 0x42)
}
}
} else if(cmd == 19) {
// Opcode: OR
for (uint32 i = 0; i < samples; i++) {
assembly {
let x := or(5, 0x42)
}
}
} else if(cmd == 20) {
// Opcode: XOR
for (uint32 i = 0; i < samples; i++) {
assembly {
let x := xor(5, 0x42)
}
}
} else if(cmd == 21) {
// Opcode: BYTE
for (uint32 i = 0; i < samples; i++) {
assembly {
let x := byte(5, 0x42)
}
}
} else if(cmd == 22) {
// Opcode: SHL
for (uint32 i = 0; i < samples; i++) {
assembly {
let x := shl(5, 0x42)
}
}
} else if(cmd == 23) {
// Opcode: SHR
for (uint32 i = 0; i < samples; i++) {
assembly {
let x := shr(5, 0x42)
}
}
} else if(cmd == 24) {
// Opcode: SAR
for (uint32 i = 0; i < samples; i++) {
assembly {
let x := sar(5, 0x42)
}
}
} else if(cmd == 25) {
// Opcode: ADDMOD
for (uint32 i = 0; i < samples; i++) {
assembly {
let x := addmod(5, 0x42, 7)
}
}
} else if(cmd == 26) {
// Opcode: MULMOD
for (uint32 i = 0; i < samples; i++) {
assembly {
let x := mulmod(5, 0x42, 7)
}
}
} else if(cmd == 27) {
// Opcode: KECCAK256
for (uint32 i = 0; i < samples; i++) {
assembly {
let x := keccak256(0, 0)
}
}
} else if(cmd == 28) {
// Opcode: ADDRESS
for (uint32 i = 0; i < samples; i++) {
assembly {
let x := address()
}
}
} else if(cmd == 29) {
// Opcode: BALANCE
for (uint32 i = 0; i < samples; i++) {
assembly {
let x := balance(0x42)
}
}
} else if(cmd == 30) {
// Opcode: ORIGIN
for (uint32 i = 0; i < samples; i++) {
assembly {
let x := origin()
}
}
} else if(cmd == 31) {
// Opcode: CALLER
for (uint32 i = 0; i < samples; i++) {
assembly {
let x := caller()
}
}
} else if(cmd == 32) {
// Opcode: CALLVALUE
for (uint32 i = 0; i < samples; i++) {
assembly {
let x := callvalue()
}
}
} else if(cmd == 33) {
// Opcode: CALLDATALOAD
for (uint32 i = 0; i < samples; i++) {
assembly {
let x := calldataload(0x42)
}
}
} else if(cmd == 34) {
// Opcode: CALLDATASIZE
for (uint32 i = 0; i < samples; i++) {
assembly {
let x := calldatasize()
}
}
} else if(cmd == 35) {
// Opcode: CALLDATACOPY
for (uint32 i = 0; i < samples; i++) {
assembly {
calldatacopy(5, 0x42, 7)
}
}
} else if(cmd == 36) {
// Opcode: CHAINID
for (uint32 i = 0; i < samples; i++) {
assembly {
let x := chainid()
}
}
} else if(cmd == 37) {
// Opcode: BASEFEE
for (uint32 i = 0; i < samples; i++) {
assembly {
let x := basefee()
}
}
} else if(cmd == 38) {
// Opcode: DELEGATECALL
for (uint32 i = 0; i < samples; i++) {
assembly {
let x := delegatecall(5000, 0x42, 0, 0x44, 0, 0x20)
}
}
} else if(cmd == 39) {
// Opcode: STATICCALL
for (uint32 i = 0; i < samples; i++) {
assembly {
let x := staticcall(5000, 0x42, 0, 0x44, 0, 0x20)
}
}
} else if(cmd == 40) {
// Opcode: CODESIZE
for (uint32 i = 0; i < samples; i++) {
assembly {
let x := codesize()
}
}
} else if(cmd == 41) {
// Opcode: CODECOPY
for (uint32 i = 0; i < samples; i++) {
assembly {
codecopy(5, 0x42, 7)
}
}
} else if(cmd == 42) {
// Opcode: GASPRICE
for (uint32 i = 0; i < samples; i++) {
assembly {
let x := gasprice()
}
}
} else if(cmd == 43) {
// Opcode: EXTCODESIZE
for (uint32 i = 0; i < samples; i++) {
assembly {
let x := extcodesize(0x42)
}
}
} else if(cmd == 44) {
// Opcode: EXTCODECOPY
for (uint32 i = 0; i < samples; i++) {
assembly {
extcodecopy(0x42, 4, 0, 0x20)
}
}
} else if(cmd == 45) {
// Opcode: RETURNDATASIZE
for (uint32 i = 0; i < samples; i++) {
assembly {
let x := returndatasize()
}
}
} else if(cmd == 46) {
// Opcode: RETURNDATACOPY
for (uint32 i = 0; i < samples; i++) {
assembly {
returndatacopy(5, 0x42, 7)
}
}
} else if(cmd == 47) {
// Opcode: EXTCODEHASH
for (uint32 i = 0; i < samples; i++) {
assembly {
let x := extcodehash(0x42)
}
}
} else if(cmd == 48) {
// Opcode: BLOCKHASH
for (uint32 i = 0; i < samples; i++) {
assembly {
let x := blockhash(0x42)
}
}
} else if(cmd == 49) {
// Opcode: COINBASE
for (uint32 i = 0; i < samples; i++) {
assembly {
let x := coinbase()
}
}
} else if(cmd == 50) {
// Opcode: TIMESTAMP
for (uint32 i = 0; i < samples; i++) {
assembly {
let x := timestamp()
}
}
} else if(cmd == 51) {
// Opcode: NUMBER
for (uint32 i = 0; i < samples; i++) {
assembly {
let x := number()
}
}
} else if(cmd == 52) {
// Opcode: DIFFICULTY
for (uint32 i = 0; i < samples; i++) {
assembly {
let x := difficulty()
}
}
} else if(cmd == 53) {
// Opcode: GASLIMIT
for (uint32 i = 0; i < samples; i++) {
assembly {
let x := gaslimit()
}
}
} else if(cmd == 54) {
// Opcode: SELFBALANCE
for (uint32 i = 0; i < samples; i++) {
assembly {
let x := selfbalance()
}
}
} else if(cmd == 55) {
// Opcode: POP
for (uint32 i = 0; i < samples; i++) {
assembly {
pop(0x42)
}
}
} else if(cmd == 56) {
// Opcode: MLOAD
for (uint32 i = 0; i < samples; i++) {
assembly {
let x := mload(0x42)
}
}
} else if(cmd == 57) {
// Opcode: MSTORE
for (uint32 i = 0; i < samples; i++) {
assembly {
mstore(5, 0x42)
}
}
} else if(cmd == 58) {
// Opcode: MSTORE8
for (uint32 i = 0; i < samples; i++) {
assembly {
mstore8(5, 0x42)
}
}
} else if(cmd == 59) {
// Opcode: SLOAD
for (uint32 i = 0; i < samples; i++) {
assembly {
let x := sload(0x42)
}
}
} else if(cmd == 60) {
// Opcode: SSTORE
for (uint32 i = 0; i < samples; i++) {
assembly {
sstore(5, 0x42)
}
}
} else if(cmd == 61) {
// Opcode: MSIZE
for (uint32 i = 0; i < samples; i++) {
assembly {
let x := msize()
}
}
} else if(cmd == 62) {
// Opcode: GAS
for (uint32 i = 0; i < samples; i++) {
assembly {
let x := gas()
}
}
} else if(cmd == 63) {
// Opcode: JUMPDEST
for (uint32 i = 0; i < samples; i++) {
assembly {
//let x := jumpdest()
}
}
} else if(cmd == 64) {
// Opcode: LOG0
for (uint32 i = 0; i < samples; i++) {
assembly {
log0(0x42, 0x42)
}
}
} else if(cmd == 65) {
// Opcode: LOG1
for (uint32 i = 0; i < samples; i++) {
assembly {
log1(0x42, 0x42, 0x42)
}
}
} else if(cmd == 66) {
// Opcode: LOG2
for (uint32 i = 0; i < samples; i++) {
assembly {
log2(0x42, 0x42, 0x42, 0x42)
}
}
} else if(cmd == 67) {
// Opcode: LOG3
for (uint32 i = 0; i < samples; i++) {
assembly {
log3(0x42, 0x42, 0x42, 0x42, 0x42)
}
}
} else if(cmd == 68) {
// Opcode: LOG4
for (uint32 i = 0; i < samples; i++) {
assembly {
log4(0x42, 0x42, 0x42, 0x42, 0x42, 0x42)
}
}
} else if(cmd == 69) {
// Opcode: CREATE
for (uint32 i = 0; i < samples; i++) {
assembly {
let x := create(5, 0x42, 7)
}
}
} else if(cmd == 70) {
// Opcode: CREATE2
for (uint32 i = 0; i < samples; i++) {
assembly {
let x := create2(5, 0x42, 7, 64)
}
}
} else if(cmd == 71) {
// Opcode: CALL
for (uint32 i = 0; i < samples; i++) {
assembly {
let x := call(5, 0x42, 0, 0, 0x44, 0, 0x20)
}
}
} else if(cmd == 72) {
// Opcode: RETURN
for (uint32 i = 0; i < samples; i++) {
assembly {
return(5, 0x42)
}
}
} else if(cmd == 73) {
// Opcode: CALLCODE
for (uint32 i = 0; i < samples; i++) {
assembly {
let x := callcode(5, 0x42, 0, 0, 0x44, 0, 0x20)
}
}
} else if(cmd == 74) {
// Opcode: REVERT
for (uint32 i = 0; i < samples; i++) {
assembly {
revert(5, 0x42)
}
}
} else if(cmd == 75) {
// Opcode: INVALID
for (uint32 i = 0; i < samples; i++) {
assembly {
invalid()
}
}
} else if(cmd == 76) {
// Opcode: SELFDESTRUCT
for (uint32 i = 0; i < samples; i++) {
assembly {
selfdestruct(0x42)
}
}
} else {
revert('Please enter a valid command.');
}
}
}