-
Notifications
You must be signed in to change notification settings - Fork 655
/
Copy pathopcode.rs
940 lines (916 loc) · 30.3 KB
/
opcode.rs
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
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
use crate::gas;
use crate::primitives::SpecId;
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub struct OpCode(u8);
pub const STOP: u8 = 0x00;
pub const ADD: u8 = 0x01;
pub const MUL: u8 = 0x02;
pub const SUB: u8 = 0x03;
pub const DIV: u8 = 0x04;
pub const SDIV: u8 = 0x05;
pub const MOD: u8 = 0x06;
pub const SMOD: u8 = 0x07;
pub const ADDMOD: u8 = 0x08;
pub const MULMOD: u8 = 0x09;
pub const EXP: u8 = 0x0a;
pub const SIGNEXTEND: u8 = 0x0b;
pub const LT: u8 = 0x10;
pub const GT: u8 = 0x11;
pub const SLT: u8 = 0x12;
pub const SGT: u8 = 0x13;
pub const EQ: u8 = 0x14;
pub const ISZERO: u8 = 0x15;
pub const AND: u8 = 0x16;
pub const OR: u8 = 0x17;
pub const XOR: u8 = 0x18;
pub const NOT: u8 = 0x19;
pub const BYTE: u8 = 0x1a;
pub const CALLDATALOAD: u8 = 0x35;
pub const CALLDATASIZE: u8 = 0x36;
pub const CALLDATACOPY: u8 = 0x37;
pub const CODESIZE: u8 = 0x38;
pub const CODECOPY: u8 = 0x39;
pub const SHL: u8 = 0x1b;
pub const SHR: u8 = 0x1c;
pub const SAR: u8 = 0x1d;
pub const KECCAK256: u8 = 0x20;
pub const POP: u8 = 0x50;
pub const MLOAD: u8 = 0x51;
pub const MSTORE: u8 = 0x52;
pub const MSTORE8: u8 = 0x53;
pub const JUMP: u8 = 0x56;
pub const JUMPI: u8 = 0x57;
pub const PC: u8 = 0x58;
pub const MSIZE: u8 = 0x59;
pub const JUMPDEST: u8 = 0x5b;
pub const TLOAD: u8 = 0x5c;
pub const TSTORE: u8 = 0x5d;
pub const MCOPY: u8 = 0x5e;
pub const PUSH0: u8 = 0x5f;
pub const PUSH1: u8 = 0x60;
pub const PUSH2: u8 = 0x61;
pub const PUSH3: u8 = 0x62;
pub const PUSH4: u8 = 0x63;
pub const PUSH5: u8 = 0x64;
pub const PUSH6: u8 = 0x65;
pub const PUSH7: u8 = 0x66;
pub const PUSH8: u8 = 0x67;
pub const PUSH9: u8 = 0x68;
pub const PUSH10: u8 = 0x69;
pub const PUSH11: u8 = 0x6a;
pub const PUSH12: u8 = 0x6b;
pub const PUSH13: u8 = 0x6c;
pub const PUSH14: u8 = 0x6d;
pub const PUSH15: u8 = 0x6e;
pub const PUSH16: u8 = 0x6f;
pub const PUSH17: u8 = 0x70;
pub const PUSH18: u8 = 0x71;
pub const PUSH19: u8 = 0x72;
pub const PUSH20: u8 = 0x73;
pub const PUSH21: u8 = 0x74;
pub const PUSH22: u8 = 0x75;
pub const PUSH23: u8 = 0x76;
pub const PUSH24: u8 = 0x77;
pub const PUSH25: u8 = 0x78;
pub const PUSH26: u8 = 0x79;
pub const PUSH27: u8 = 0x7a;
pub const PUSH28: u8 = 0x7b;
pub const PUSH29: u8 = 0x7c;
pub const PUSH30: u8 = 0x7d;
pub const PUSH31: u8 = 0x7e;
pub const PUSH32: u8 = 0x7f;
pub const DUP1: u8 = 0x80;
pub const DUP2: u8 = 0x81;
pub const DUP3: u8 = 0x82;
pub const DUP4: u8 = 0x83;
pub const DUP5: u8 = 0x84;
pub const DUP6: u8 = 0x85;
pub const DUP7: u8 = 0x86;
pub const DUP8: u8 = 0x87;
pub const DUP9: u8 = 0x88;
pub const DUP10: u8 = 0x89;
pub const DUP11: u8 = 0x8a;
pub const DUP12: u8 = 0x8b;
pub const DUP13: u8 = 0x8c;
pub const DUP14: u8 = 0x8d;
pub const DUP15: u8 = 0x8e;
pub const DUP16: u8 = 0x8f;
pub const SWAP1: u8 = 0x90;
pub const SWAP2: u8 = 0x91;
pub const SWAP3: u8 = 0x92;
pub const SWAP4: u8 = 0x93;
pub const SWAP5: u8 = 0x94;
pub const SWAP6: u8 = 0x95;
pub const SWAP7: u8 = 0x96;
pub const SWAP8: u8 = 0x97;
pub const SWAP9: u8 = 0x98;
pub const SWAP10: u8 = 0x99;
pub const SWAP11: u8 = 0x9a;
pub const SWAP12: u8 = 0x9b;
pub const SWAP13: u8 = 0x9c;
pub const SWAP14: u8 = 0x9d;
pub const SWAP15: u8 = 0x9e;
pub const SWAP16: u8 = 0x9f;
pub const RETURN: u8 = 0xf3;
pub const REVERT: u8 = 0xfd;
pub const INVALID: u8 = 0xfe;
pub const ADDRESS: u8 = 0x30;
pub const BALANCE: u8 = 0x31;
pub const BASEFEE: u8 = 0x48;
pub const ORIGIN: u8 = 0x32;
pub const CALLER: u8 = 0x33;
pub const CALLVALUE: u8 = 0x34;
pub const GASPRICE: u8 = 0x3a;
pub const EXTCODESIZE: u8 = 0x3b;
pub const EXTCODECOPY: u8 = 0x3c;
pub const EXTCODEHASH: u8 = 0x3f;
pub const RETURNDATASIZE: u8 = 0x3d;
pub const RETURNDATACOPY: u8 = 0x3e;
pub const BLOCKHASH: u8 = 0x40;
pub const COINBASE: u8 = 0x41;
pub const TIMESTAMP: u8 = 0x42;
pub const NUMBER: u8 = 0x43;
pub const DIFFICULTY: u8 = 0x44;
pub const GASLIMIT: u8 = 0x45;
pub const SELFBALANCE: u8 = 0x47;
pub const BLOBHASH: u8 = 0x49;
pub const BLOBFEE: u8 = 0x4a;
pub const SLOAD: u8 = 0x54;
pub const SSTORE: u8 = 0x55;
pub const GAS: u8 = 0x5a;
pub const LOG0: u8 = 0xa0;
pub const LOG1: u8 = 0xa1;
pub const LOG2: u8 = 0xa2;
pub const LOG3: u8 = 0xa3;
pub const LOG4: u8 = 0xa4;
pub const CREATE: u8 = 0xf0;
pub const CREATE2: u8 = 0xf5;
pub const CALL: u8 = 0xf1;
pub const CALLCODE: u8 = 0xf2;
pub const DELEGATECALL: u8 = 0xf4;
pub const STATICCALL: u8 = 0xfa;
pub const SELFDESTRUCT: u8 = 0xff;
pub const CHAINID: u8 = 0x46;
impl OpCode {
pub fn try_from_u8(opcode: u8) -> Option<OpCode> {
OPCODE_JUMPMAP[opcode as usize].map(|_| OpCode(opcode))
}
pub const fn as_str(&self) -> &'static str {
if let Some(str) = OPCODE_JUMPMAP[self.0 as usize] {
str
} else {
"unknown"
}
}
#[inline(always)]
pub const fn u8(&self) -> u8 {
self.0
}
}
impl core::fmt::Display for OpCode {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
if let Some(val) = OPCODE_JUMPMAP[self.0 as usize] {
f.write_str(val)
} else {
write!(f, "UNKNOWN(0x{:02x})", self.0)
}
}
}
pub const OPCODE_JUMPMAP: [Option<&'static str>; 256] = [
/* 0x00 */ Some("STOP"),
/* 0x01 */ Some("ADD"),
/* 0x02 */ Some("MUL"),
/* 0x03 */ Some("SUB"),
/* 0x04 */ Some("DIV"),
/* 0x05 */ Some("SDIV"),
/* 0x06 */ Some("MOD"),
/* 0x07 */ Some("SMOD"),
/* 0x08 */ Some("ADDMOD"),
/* 0x09 */ Some("MULMOD"),
/* 0x0a */ Some("EXP"),
/* 0x0b */ Some("SIGNEXTEND"),
/* 0x0c */ None,
/* 0x0d */ None,
/* 0x0e */ None,
/* 0x0f */ None,
/* 0x10 */ Some("LT"),
/* 0x11 */ Some("GT"),
/* 0x12 */ Some("SLT"),
/* 0x13 */ Some("SGT"),
/* 0x14 */ Some("EQ"),
/* 0x15 */ Some("ISZERO"),
/* 0x16 */ Some("AND"),
/* 0x17 */ Some("OR"),
/* 0x18 */ Some("XOR"),
/* 0x19 */ Some("NOT"),
/* 0x1a */ Some("BYTE"),
/* 0x1b */ Some("SHL"),
/* 0x1c */ Some("SHR"),
/* 0x1d */ Some("SAR"),
/* 0x1e */ None,
/* 0x1f */ None,
/* 0x20 */ Some("KECCAK256"),
/* 0x21 */ None,
/* 0x22 */ None,
/* 0x23 */ None,
/* 0x24 */ None,
/* 0x25 */ None,
/* 0x26 */ None,
/* 0x27 */ None,
/* 0x28 */ None,
/* 0x29 */ None,
/* 0x2a */ None,
/* 0x2b */ None,
/* 0x2c */ None,
/* 0x2d */ None,
/* 0x2e */ None,
/* 0x2f */ None,
/* 0x30 */ Some("ADDRESS"),
/* 0x31 */ Some("BALANCE"),
/* 0x32 */ Some("ORIGIN"),
/* 0x33 */ Some("CALLER"),
/* 0x34 */ Some("CALLVALUE"),
/* 0x35 */ Some("CALLDATALOAD"),
/* 0x36 */ Some("CALLDATASIZE"),
/* 0x37 */ Some("CALLDATACOPY"),
/* 0x38 */ Some("CODESIZE"),
/* 0x39 */ Some("CODECOPY"),
/* 0x3a */ Some("GASPRICE"),
/* 0x3b */ Some("EXTCODESIZE"),
/* 0x3c */ Some("EXTCODECOPY"),
/* 0x3d */ Some("RETURNDATASIZE"),
/* 0x3e */ Some("RETURNDATACOPY"),
/* 0x3f */ Some("EXTCODEHASH"),
/* 0x40 */ Some("BLOCKHASH"),
/* 0x41 */ Some("COINBASE"),
/* 0x42 */ Some("TIMESTAMP"),
/* 0x43 */ Some("NUMBER"),
/* 0x44 */ Some("DIFFICULTY"),
/* 0x45 */ Some("GASLIMIT"),
/* 0x46 */ Some("CHAINID"),
/* 0x47 */ Some("SELFBALANCE"),
/* 0x48 */ Some("BASEFEE"),
/* 0x49 */ Some("BLOBHASH"),
/* 0x4a */ Some("BLOBFEE"),
/* 0x4b */ None,
/* 0x4c */ None,
/* 0x4d */ None,
/* 0x4e */ None,
/* 0x4f */ None,
/* 0x50 */ Some("POP"),
/* 0x51 */ Some("MLOAD"),
/* 0x52 */ Some("MSTORE"),
/* 0x53 */ Some("MSTORE8"),
/* 0x54 */ Some("SLOAD"),
/* 0x55 */ Some("SSTORE"),
/* 0x56 */ Some("JUMP"),
/* 0x57 */ Some("JUMPI"),
/* 0x58 */ Some("PC"),
/* 0x59 */ Some("MSIZE"),
/* 0x5a */ Some("GAS"),
/* 0x5b */ Some("JUMPDEST"),
/* 0x5c */ Some("TLOAD"),
/* 0x5d */ Some("TSTORE"),
/* 0x5e */ Some("MCOPY"),
/* 0x5f */ Some("PUSH0"),
/* 0x60 */ Some("PUSH1"),
/* 0x61 */ Some("PUSH2"),
/* 0x62 */ Some("PUSH3"),
/* 0x63 */ Some("PUSH4"),
/* 0x64 */ Some("PUSH5"),
/* 0x65 */ Some("PUSH6"),
/* 0x66 */ Some("PUSH7"),
/* 0x67 */ Some("PUSH8"),
/* 0x68 */ Some("PUSH9"),
/* 0x69 */ Some("PUSH10"),
/* 0x6a */ Some("PUSH11"),
/* 0x6b */ Some("PUSH12"),
/* 0x6c */ Some("PUSH13"),
/* 0x6d */ Some("PUSH14"),
/* 0x6e */ Some("PUSH15"),
/* 0x6f */ Some("PUSH16"),
/* 0x70 */ Some("PUSH17"),
/* 0x71 */ Some("PUSH18"),
/* 0x72 */ Some("PUSH19"),
/* 0x73 */ Some("PUSH20"),
/* 0x74 */ Some("PUSH21"),
/* 0x75 */ Some("PUSH22"),
/* 0x76 */ Some("PUSH23"),
/* 0x77 */ Some("PUSH24"),
/* 0x78 */ Some("PUSH25"),
/* 0x79 */ Some("PUSH26"),
/* 0x7a */ Some("PUSH27"),
/* 0x7b */ Some("PUSH28"),
/* 0x7c */ Some("PUSH29"),
/* 0x7d */ Some("PUSH30"),
/* 0x7e */ Some("PUSH31"),
/* 0x7f */ Some("PUSH32"),
/* 0x80 */ Some("DUP1"),
/* 0x81 */ Some("DUP2"),
/* 0x82 */ Some("DUP3"),
/* 0x83 */ Some("DUP4"),
/* 0x84 */ Some("DUP5"),
/* 0x85 */ Some("DUP6"),
/* 0x86 */ Some("DUP7"),
/* 0x87 */ Some("DUP8"),
/* 0x88 */ Some("DUP9"),
/* 0x89 */ Some("DUP10"),
/* 0x8a */ Some("DUP11"),
/* 0x8b */ Some("DUP12"),
/* 0x8c */ Some("DUP13"),
/* 0x8d */ Some("DUP14"),
/* 0x8e */ Some("DUP15"),
/* 0x8f */ Some("DUP16"),
/* 0x90 */ Some("SWAP1"),
/* 0x91 */ Some("SWAP2"),
/* 0x92 */ Some("SWAP3"),
/* 0x93 */ Some("SWAP4"),
/* 0x94 */ Some("SWAP5"),
/* 0x95 */ Some("SWAP6"),
/* 0x96 */ Some("SWAP7"),
/* 0x97 */ Some("SWAP8"),
/* 0x98 */ Some("SWAP9"),
/* 0x99 */ Some("SWAP10"),
/* 0x9a */ Some("SWAP11"),
/* 0x9b */ Some("SWAP12"),
/* 0x9c */ Some("SWAP13"),
/* 0x9d */ Some("SWAP14"),
/* 0x9e */ Some("SWAP15"),
/* 0x9f */ Some("SWAP16"),
/* 0xa0 */ Some("LOG0"),
/* 0xa1 */ Some("LOG1"),
/* 0xa2 */ Some("LOG2"),
/* 0xa3 */ Some("LOG3"),
/* 0xa4 */ Some("LOG4"),
/* 0xa5 */ None,
/* 0xa6 */ None,
/* 0xa7 */ None,
/* 0xa8 */ None,
/* 0xa9 */ None,
/* 0xaa */ None,
/* 0xab */ None,
/* 0xac */ None,
/* 0xad */ None,
/* 0xae */ None,
/* 0xaf */ None,
/* 0xb0 */ None,
/* 0xb1 */ None,
/* 0xb2 */ None,
/* 0xb3 */ None,
/* 0xb4 */ None,
/* 0xb5 */ None,
/* 0xb6 */ None,
/* 0xb7 */ None,
/* 0xb8 */ None,
/* 0xb9 */ None,
/* 0xba */ None,
/* 0xbb */ None,
/* 0xbc */ None,
/* 0xbd */ None,
/* 0xbe */ None,
/* 0xbf */ None,
/* 0xc0 */ None,
/* 0xc1 */ None,
/* 0xc2 */ None,
/* 0xc3 */ None,
/* 0xc4 */ None,
/* 0xc5 */ None,
/* 0xc6 */ None,
/* 0xc7 */ None,
/* 0xc8 */ None,
/* 0xc9 */ None,
/* 0xca */ None,
/* 0xcb */ None,
/* 0xcc */ None,
/* 0xcd */ None,
/* 0xce */ None,
/* 0xcf */ None,
/* 0xd0 */ None,
/* 0xd1 */ None,
/* 0xd2 */ None,
/* 0xd3 */ None,
/* 0xd4 */ None,
/* 0xd5 */ None,
/* 0xd6 */ None,
/* 0xd7 */ None,
/* 0xd8 */ None,
/* 0xd9 */ None,
/* 0xda */ None,
/* 0xdb */ None,
/* 0xdc */ None,
/* 0xdd */ None,
/* 0xde */ None,
/* 0xdf */ None,
/* 0xe0 */ None,
/* 0xe1 */ None,
/* 0xe2 */ None,
/* 0xe3 */ None,
/* 0xe4 */ None,
/* 0xe5 */ None,
/* 0xe6 */ None,
/* 0xe7 */ None,
/* 0xe8 */ None,
/* 0xe9 */ None,
/* 0xea */ None,
/* 0xeb */ None,
/* 0xec */ None,
/* 0xed */ None,
/* 0xee */ None,
/* 0xef */ None,
/* 0xf0 */ Some("CREATE"),
/* 0xf1 */ Some("CALL"),
/* 0xf2 */ Some("CALLCODE"),
/* 0xf3 */ Some("RETURN"),
/* 0xf4 */ Some("DELEGATECALL"),
/* 0xf5 */ Some("CREATE2"),
/* 0xf6 */ None,
/* 0xf7 */ None,
/* 0xf8 */ None,
/* 0xf9 */ None,
/* 0xfa */ Some("STATICCALL"),
/* 0xfb */ None,
/* 0xfc */ None,
/* 0xfd */ Some("REVERT"),
/* 0xfe */ Some("INVALID"),
/* 0xff */ Some("SELFDESTRUCT"),
];
#[derive(Debug)]
pub struct OpInfo {
/// Data contains few information packed inside u32:
/// IS_JUMP (1bit) | IS_GAS_BLOCK_END (1bit) | IS_PUSH (1bit) | gas (29bits)
data: u32,
}
const JUMP_MASK: u32 = 0x80000000;
const GAS_BLOCK_END_MASK: u32 = 0x40000000;
const IS_PUSH_MASK: u32 = 0x20000000;
const GAS_MASK: u32 = 0x1FFFFFFF;
impl OpInfo {
#[inline(always)]
pub fn is_jump(&self) -> bool {
self.data & JUMP_MASK == JUMP_MASK
}
#[inline(always)]
pub fn is_gas_block_end(&self) -> bool {
self.data & GAS_BLOCK_END_MASK == GAS_BLOCK_END_MASK
}
#[inline(always)]
pub fn is_push(&self) -> bool {
self.data & IS_PUSH_MASK == IS_PUSH_MASK
}
#[inline(always)]
pub fn get_gas(&self) -> u32 {
self.data & GAS_MASK
}
pub const fn none() -> Self {
Self { data: 0 }
}
pub const fn gas_block_end(gas: u64) -> Self {
Self {
data: gas as u32 | GAS_BLOCK_END_MASK,
}
}
pub const fn dynamic_gas() -> Self {
Self { data: 0 }
}
pub const fn gas(gas: u64) -> Self {
Self { data: gas as u32 }
}
pub const fn push_opcode() -> Self {
Self {
data: gas::VERYLOW as u32 | IS_PUSH_MASK,
}
}
pub const fn jumpdest() -> Self {
Self {
data: JUMP_MASK | GAS_BLOCK_END_MASK,
}
}
}
macro_rules! gas_opcodee {
($name:ident, $spec_id:expr) => {
const $name: &'static [OpInfo; 256] = &[
/* 0x00 STOP */ OpInfo::gas_block_end(0),
/* 0x01 ADD */ OpInfo::gas(gas::VERYLOW),
/* 0x02 MUL */ OpInfo::gas(gas::LOW),
/* 0x03 SUB */ OpInfo::gas(gas::VERYLOW),
/* 0x04 DIV */ OpInfo::gas(gas::LOW),
/* 0x05 SDIV */ OpInfo::gas(gas::LOW),
/* 0x06 MOD */ OpInfo::gas(gas::LOW),
/* 0x07 SMOD */ OpInfo::gas(gas::LOW),
/* 0x08 ADDMOD */ OpInfo::gas(gas::MID),
/* 0x09 MULMOD */ OpInfo::gas(gas::MID),
/* 0x0a EXP */ OpInfo::dynamic_gas(),
/* 0x0b SIGNEXTEND */ OpInfo::gas(gas::LOW),
/* 0x0c */ OpInfo::none(),
/* 0x0d */ OpInfo::none(),
/* 0x0e */ OpInfo::none(),
/* 0x0f */ OpInfo::none(),
/* 0x10 LT */ OpInfo::gas(gas::VERYLOW),
/* 0x11 GT */ OpInfo::gas(gas::VERYLOW),
/* 0x12 SLT */ OpInfo::gas(gas::VERYLOW),
/* 0x13 SGT */ OpInfo::gas(gas::VERYLOW),
/* 0x14 EQ */ OpInfo::gas(gas::VERYLOW),
/* 0x15 ISZERO */ OpInfo::gas(gas::VERYLOW),
/* 0x16 AND */ OpInfo::gas(gas::VERYLOW),
/* 0x17 OR */ OpInfo::gas(gas::VERYLOW),
/* 0x18 XOR */ OpInfo::gas(gas::VERYLOW),
/* 0x19 NOT */ OpInfo::gas(gas::VERYLOW),
/* 0x1a BYTE */ OpInfo::gas(gas::VERYLOW),
/* 0x1b SHL */
OpInfo::gas(if SpecId::enabled($spec_id, SpecId::CONSTANTINOPLE) {
gas::VERYLOW
} else {
0
}),
/* 0x1c SHR */
OpInfo::gas(if SpecId::enabled($spec_id, SpecId::CONSTANTINOPLE) {
gas::VERYLOW
} else {
0
}),
/* 0x1d SAR */
OpInfo::gas(if SpecId::enabled($spec_id, SpecId::CONSTANTINOPLE) {
gas::VERYLOW
} else {
0
}),
/* 0x1e */ OpInfo::none(),
/* 0x1f */ OpInfo::none(),
/* 0x20 KECCAK256 */ OpInfo::dynamic_gas(),
/* 0x21 */ OpInfo::none(),
/* 0x22 */ OpInfo::none(),
/* 0x23 */ OpInfo::none(),
/* 0x24 */ OpInfo::none(),
/* 0x25 */ OpInfo::none(),
/* 0x26 */ OpInfo::none(),
/* 0x27 */ OpInfo::none(),
/* 0x28 */ OpInfo::none(),
/* 0x29 */ OpInfo::none(),
/* 0x2a */ OpInfo::none(),
/* 0x2b */ OpInfo::none(),
/* 0x2c */ OpInfo::none(),
/* 0x2d */ OpInfo::none(),
/* 0x2e */ OpInfo::none(),
/* 0x2f */ OpInfo::none(),
/* 0x30 ADDRESS */ OpInfo::gas(gas::BASE),
/* 0x31 BALANCE */ OpInfo::dynamic_gas(),
/* 0x32 ORIGIN */ OpInfo::gas(gas::BASE),
/* 0x33 CALLER */ OpInfo::gas(gas::BASE),
/* 0x34 CALLVALUE */ OpInfo::gas(gas::BASE),
/* 0x35 CALLDATALOAD */ OpInfo::gas(gas::VERYLOW),
/* 0x36 CALLDATASIZE */ OpInfo::gas(gas::BASE),
/* 0x37 CALLDATACOPY */ OpInfo::dynamic_gas(),
/* 0x38 CODESIZE */ OpInfo::gas(gas::BASE),
/* 0x39 CODECOPY */ OpInfo::dynamic_gas(),
/* 0x3a GASPRICE */ OpInfo::gas(gas::BASE),
/* 0x3b EXTCODESIZE */
OpInfo::gas(if SpecId::enabled($spec_id, SpecId::BERLIN) {
gas::WARM_STORAGE_READ_COST // add only part of gas
} else if SpecId::enabled($spec_id, SpecId::TANGERINE) {
700
} else {
20
}),
/* 0x3c EXTCODECOPY */
OpInfo::gas(if SpecId::enabled($spec_id, SpecId::BERLIN) {
gas::WARM_STORAGE_READ_COST // add only part of gas
} else if SpecId::enabled($spec_id, SpecId::TANGERINE) {
700
} else {
20
}),
/* 0x3d RETURNDATASIZE */
OpInfo::gas(if SpecId::enabled($spec_id, SpecId::BYZANTIUM) {
gas::BASE
} else {
0
}),
/* 0x3e RETURNDATACOPY */ OpInfo::dynamic_gas(),
/* 0x3f EXTCODEHASH */
OpInfo::gas(if SpecId::enabled($spec_id, SpecId::BERLIN) {
gas::WARM_STORAGE_READ_COST // add only part of gas
} else if SpecId::enabled($spec_id, SpecId::ISTANBUL) {
700
} else if SpecId::enabled($spec_id, SpecId::PETERSBURG) {
// constantinople
400
} else {
0 // not enabled
}),
/* 0x40 BLOCKHASH */ OpInfo::gas(gas::BLOCKHASH),
/* 0x41 COINBASE */ OpInfo::gas(gas::BASE),
/* 0x42 TIMESTAMP */ OpInfo::gas(gas::BASE),
/* 0x43 NUMBER */ OpInfo::gas(gas::BASE),
/* 0x44 DIFFICULTY */ OpInfo::gas(gas::BASE),
/* 0x45 GASLIMIT */ OpInfo::gas(gas::BASE),
/* 0x46 CHAINID */
OpInfo::gas(if SpecId::enabled($spec_id, SpecId::ISTANBUL) {
gas::BASE
} else {
0
}),
/* 0x47 SELFBALANCE */
OpInfo::gas(if SpecId::enabled($spec_id, SpecId::ISTANBUL) {
gas::LOW
} else {
0
}),
/* 0x48 BASEFEE */
OpInfo::gas(if SpecId::enabled($spec_id, SpecId::LONDON) {
gas::BASE
} else {
0
}),
/* 0x49 BLOBHASH */
OpInfo::gas(if SpecId::enabled($spec_id, SpecId::CANCUN) {
gas::VERYLOW
} else {
0
}),
/* 0x4a BLOBFEE */
OpInfo::gas(if SpecId::enabled($spec_id, SpecId::CANCUN) {
gas::BASE
} else {
0
}),
/* 0x4b */ OpInfo::none(),
/* 0x4c */ OpInfo::none(),
/* 0x4d */ OpInfo::none(),
/* 0x4e */ OpInfo::none(),
/* 0x4f */ OpInfo::none(),
/* 0x50 POP */ OpInfo::gas(gas::BASE),
/* 0x51 MLOAD */ OpInfo::gas(gas::VERYLOW),
/* 0x52 MSTORE */ OpInfo::gas(gas::VERYLOW),
/* 0x53 MSTORE8 */ OpInfo::gas(gas::VERYLOW),
/* 0x54 SLOAD */ OpInfo::dynamic_gas(),
/* 0x55 SSTORE */ OpInfo::gas_block_end(0),
/* 0x56 JUMP */ OpInfo::gas_block_end(gas::MID),
/* 0x57 JUMPI */ OpInfo::gas_block_end(gas::HIGH),
/* 0x58 PC */ OpInfo::gas(gas::BASE),
/* 0x59 MSIZE */ OpInfo::gas(gas::BASE),
/* 0x5a GAS */ OpInfo::gas_block_end(gas::BASE),
/* 0x5b JUMPDEST */
// gas::JUMPDEST gas is calculated in function call,
OpInfo::jumpdest(),
/* 0x5c TLOAD */
OpInfo::gas(if SpecId::enabled($spec_id, SpecId::CANCUN) {
gas::WARM_STORAGE_READ_COST
} else {
0
}),
/* 0x5d TSTORE */
OpInfo::gas(if SpecId::enabled($spec_id, SpecId::CANCUN) {
gas::WARM_STORAGE_READ_COST
} else {
0
}),
/* 0x5e MCOPY */ OpInfo::dynamic_gas(),
/* 0x5f PUSH0 */
OpInfo::gas(if SpecId::enabled($spec_id, SpecId::SHANGHAI) {
gas::BASE
} else {
0
}),
/* 0x60 PUSH1 */ OpInfo::push_opcode(),
/* 0x61 PUSH2 */ OpInfo::push_opcode(),
/* 0x62 PUSH3 */ OpInfo::push_opcode(),
/* 0x63 PUSH4 */ OpInfo::push_opcode(),
/* 0x64 PUSH5 */ OpInfo::push_opcode(),
/* 0x65 PUSH6 */ OpInfo::push_opcode(),
/* 0x66 PUSH7 */ OpInfo::push_opcode(),
/* 0x67 PUSH8 */ OpInfo::push_opcode(),
/* 0x68 PUSH9 */ OpInfo::push_opcode(),
/* 0x69 PUSH10 */ OpInfo::push_opcode(),
/* 0x6a PUSH11 */ OpInfo::push_opcode(),
/* 0x6b PUSH12 */ OpInfo::push_opcode(),
/* 0x6c PUSH13 */ OpInfo::push_opcode(),
/* 0x6d PUSH14 */ OpInfo::push_opcode(),
/* 0x6e PUSH15 */ OpInfo::push_opcode(),
/* 0x6f PUSH16 */ OpInfo::push_opcode(),
/* 0x70 PUSH17 */ OpInfo::push_opcode(),
/* 0x71 PUSH18 */ OpInfo::push_opcode(),
/* 0x72 PUSH19 */ OpInfo::push_opcode(),
/* 0x73 PUSH20 */ OpInfo::push_opcode(),
/* 0x74 PUSH21 */ OpInfo::push_opcode(),
/* 0x75 PUSH22 */ OpInfo::push_opcode(),
/* 0x76 PUSH23 */ OpInfo::push_opcode(),
/* 0x77 PUSH24 */ OpInfo::push_opcode(),
/* 0x78 PUSH25 */ OpInfo::push_opcode(),
/* 0x79 PUSH26 */ OpInfo::push_opcode(),
/* 0x7a PUSH27 */ OpInfo::push_opcode(),
/* 0x7b PUSH28 */ OpInfo::push_opcode(),
/* 0x7c PUSH29 */ OpInfo::push_opcode(),
/* 0x7d PUSH30 */ OpInfo::push_opcode(),
/* 0x7e PUSH31 */ OpInfo::push_opcode(),
/* 0x7f PUSH32 */ OpInfo::push_opcode(),
/* 0x80 DUP1 */ OpInfo::gas(gas::VERYLOW),
/* 0x81 DUP2 */ OpInfo::gas(gas::VERYLOW),
/* 0x82 DUP3 */ OpInfo::gas(gas::VERYLOW),
/* 0x83 DUP4 */ OpInfo::gas(gas::VERYLOW),
/* 0x84 DUP5 */ OpInfo::gas(gas::VERYLOW),
/* 0x85 DUP6 */ OpInfo::gas(gas::VERYLOW),
/* 0x86 DUP7 */ OpInfo::gas(gas::VERYLOW),
/* 0x87 DUP8 */ OpInfo::gas(gas::VERYLOW),
/* 0x88 DUP9 */ OpInfo::gas(gas::VERYLOW),
/* 0x89 DUP10 */ OpInfo::gas(gas::VERYLOW),
/* 0x8a DUP11 */ OpInfo::gas(gas::VERYLOW),
/* 0x8b DUP12 */ OpInfo::gas(gas::VERYLOW),
/* 0x8c DUP13 */ OpInfo::gas(gas::VERYLOW),
/* 0x8d DUP14 */ OpInfo::gas(gas::VERYLOW),
/* 0x8e DUP15 */ OpInfo::gas(gas::VERYLOW),
/* 0x8f DUP16 */ OpInfo::gas(gas::VERYLOW),
/* 0x90 SWAP1 */ OpInfo::gas(gas::VERYLOW),
/* 0x91 SWAP2 */ OpInfo::gas(gas::VERYLOW),
/* 0x92 SWAP3 */ OpInfo::gas(gas::VERYLOW),
/* 0x93 SWAP4 */ OpInfo::gas(gas::VERYLOW),
/* 0x94 SWAP5 */ OpInfo::gas(gas::VERYLOW),
/* 0x95 SWAP6 */ OpInfo::gas(gas::VERYLOW),
/* 0x96 SWAP7 */ OpInfo::gas(gas::VERYLOW),
/* 0x97 SWAP8 */ OpInfo::gas(gas::VERYLOW),
/* 0x98 SWAP9 */ OpInfo::gas(gas::VERYLOW),
/* 0x99 SWAP10 */ OpInfo::gas(gas::VERYLOW),
/* 0x9a SWAP11 */ OpInfo::gas(gas::VERYLOW),
/* 0x9b SWAP12 */ OpInfo::gas(gas::VERYLOW),
/* 0x9c SWAP13 */ OpInfo::gas(gas::VERYLOW),
/* 0x9d SWAP14 */ OpInfo::gas(gas::VERYLOW),
/* 0x9e SWAP15 */ OpInfo::gas(gas::VERYLOW),
/* 0x9f SWAP16 */ OpInfo::gas(gas::VERYLOW),
/* 0xa0 LOG0 */ OpInfo::dynamic_gas(),
/* 0xa1 LOG1 */ OpInfo::dynamic_gas(),
/* 0xa2 LOG2 */ OpInfo::dynamic_gas(),
/* 0xa3 LOG3 */ OpInfo::dynamic_gas(),
/* 0xa4 LOG4 */ OpInfo::dynamic_gas(),
/* 0xa5 */ OpInfo::none(),
/* 0xa6 */ OpInfo::none(),
/* 0xa7 */ OpInfo::none(),
/* 0xa8 */ OpInfo::none(),
/* 0xa9 */ OpInfo::none(),
/* 0xaa */ OpInfo::none(),
/* 0xab */ OpInfo::none(),
/* 0xac */ OpInfo::none(),
/* 0xad */ OpInfo::none(),
/* 0xae */ OpInfo::none(),
/* 0xaf */ OpInfo::none(),
/* 0xb0 */ OpInfo::none(),
/* 0xb1 */ OpInfo::none(),
/* 0xb2 */ OpInfo::none(),
/* 0xb3 */ OpInfo::none(),
/* 0xb4 */ OpInfo::none(),
/* 0xb5 */ OpInfo::none(),
/* 0xb6 */ OpInfo::none(),
/* 0xb7 */ OpInfo::none(),
/* 0xb8 */ OpInfo::none(),
/* 0xb9 */ OpInfo::none(),
/* 0xba */ OpInfo::none(),
/* 0xbb */ OpInfo::none(),
/* 0xbc */ OpInfo::none(),
/* 0xbd */ OpInfo::none(),
/* 0xbe */ OpInfo::none(),
/* 0xbf */ OpInfo::none(),
/* 0xc0 */ OpInfo::none(),
/* 0xc1 */ OpInfo::none(),
/* 0xc2 */ OpInfo::none(),
/* 0xc3 */ OpInfo::none(),
/* 0xc4 */ OpInfo::none(),
/* 0xc5 */ OpInfo::none(),
/* 0xc6 */ OpInfo::none(),
/* 0xc7 */ OpInfo::none(),
/* 0xc8 */ OpInfo::none(),
/* 0xc9 */ OpInfo::none(),
/* 0xca */ OpInfo::none(),
/* 0xcb */ OpInfo::none(),
/* 0xcc */ OpInfo::none(),
/* 0xcd */ OpInfo::none(),
/* 0xce */ OpInfo::none(),
/* 0xcf */ OpInfo::none(),
/* 0xd0 */ OpInfo::none(),
/* 0xd1 */ OpInfo::none(),
/* 0xd2 */ OpInfo::none(),
/* 0xd3 */ OpInfo::none(),
/* 0xd4 */ OpInfo::none(),
/* 0xd5 */ OpInfo::none(),
/* 0xd6 */ OpInfo::none(),
/* 0xd7 */ OpInfo::none(),
/* 0xd8 */ OpInfo::none(),
/* 0xd9 */ OpInfo::none(),
/* 0xda */ OpInfo::none(),
/* 0xdb */ OpInfo::none(),
/* 0xdc */ OpInfo::none(),
/* 0xdd */ OpInfo::none(),
/* 0xde */ OpInfo::none(),
/* 0xdf */ OpInfo::none(),
/* 0xe0 */ OpInfo::none(),
/* 0xe1 */ OpInfo::none(),
/* 0xe2 */ OpInfo::none(),
/* 0xe3 */ OpInfo::none(),
/* 0xe4 */ OpInfo::none(),
/* 0xe5 */ OpInfo::none(),
/* 0xe6 */ OpInfo::none(),
/* 0xe7 */ OpInfo::none(),
/* 0xe8 */ OpInfo::none(),
/* 0xe9 */ OpInfo::none(),
/* 0xea */ OpInfo::none(),
/* 0xeb */ OpInfo::none(),
/* 0xec */ OpInfo::none(),
/* 0xed */ OpInfo::none(),
/* 0xee */ OpInfo::none(),
/* 0xef */ OpInfo::none(),
/* 0xf0 CREATE */ OpInfo::gas_block_end(0),
/* 0xf1 CALL */ OpInfo::gas_block_end(0),
/* 0xf2 CALLCODE */ OpInfo::gas_block_end(0),
/* 0xf3 RETURN */ OpInfo::gas_block_end(0),
/* 0xf4 DELEGATECALL */ OpInfo::gas_block_end(0),
/* 0xf5 CREATE2 */ OpInfo::gas_block_end(0),
/* 0xf6 */ OpInfo::none(),
/* 0xf7 */ OpInfo::none(),
/* 0xf8 */ OpInfo::none(),
/* 0xf9 */ OpInfo::none(),
/* 0xfa STATICCALL */ OpInfo::gas_block_end(0),
/* 0xfb */ OpInfo::none(),
/* 0xfc */ OpInfo::none(),
/* 0xfd REVERT */ OpInfo::gas_block_end(0),
/* 0xfe INVALID */ OpInfo::gas_block_end(0),
/* 0xff SELFDESTRUCT */ OpInfo::gas_block_end(0),
];
};
}
pub const fn spec_opcode_gas(spec_id: SpecId) -> &'static [OpInfo; 256] {
match spec_id {
SpecId::FRONTIER => {
gas_opcodee!(FRONTIER, SpecId::FRONTIER);
FRONTIER
}
SpecId::FRONTIER_THAWING => {
gas_opcodee!(FRONTIER_THAWING, SpecId::FRONTIER_THAWING);
FRONTIER_THAWING
}
SpecId::HOMESTEAD => {
gas_opcodee!(HOMESTEAD, SpecId::HOMESTEAD);
HOMESTEAD
}
SpecId::DAO_FORK => {
gas_opcodee!(DAO_FORK, SpecId::DAO_FORK);
DAO_FORK
}
SpecId::TANGERINE => {
gas_opcodee!(TANGERINE, SpecId::TANGERINE);
TANGERINE
}
SpecId::SPURIOUS_DRAGON => {
gas_opcodee!(SPURIOUS_DRAGON, SpecId::SPURIOUS_DRAGON);
SPURIOUS_DRAGON
}
SpecId::BYZANTIUM => {
gas_opcodee!(BYZANTIUM, SpecId::BYZANTIUM);
BYZANTIUM
}
SpecId::CONSTANTINOPLE => {
gas_opcodee!(CONSTANTINOPLE, SpecId::CONSTANTINOPLE);
CONSTANTINOPLE
}
SpecId::PETERSBURG => {
gas_opcodee!(PETERSBURG, SpecId::PETERSBURG);
PETERSBURG
}
SpecId::ISTANBUL => {
gas_opcodee!(ISTANBUL, SpecId::ISTANBUL);
ISTANBUL
}
SpecId::MUIR_GLACIER => {
gas_opcodee!(MUIRGLACIER, SpecId::MUIR_GLACIER);
MUIRGLACIER
}
SpecId::BERLIN => {
gas_opcodee!(BERLIN, SpecId::BERLIN);
BERLIN
}
SpecId::LONDON => {
gas_opcodee!(LONDON, SpecId::LONDON);
LONDON
}
SpecId::ARROW_GLACIER => {
gas_opcodee!(ARROW_GLACIER, SpecId::ARROW_GLACIER);
ARROW_GLACIER
}
SpecId::GRAY_GLACIER => {
gas_opcodee!(GRAY_GLACIER, SpecId::GRAY_GLACIER);
GRAY_GLACIER
}
SpecId::MERGE => {
gas_opcodee!(MERGE, SpecId::MERGE);
MERGE
}
SpecId::SHANGHAI => {
gas_opcodee!(SHANGAI, SpecId::SHANGHAI);
SHANGAI
}
SpecId::CANCUN => {
gas_opcodee!(CANCUN, SpecId::CANCUN);
CANCUN
}
SpecId::LATEST => {
gas_opcodee!(LATEST, SpecId::LATEST);
LATEST
}
}
}