@@ -27,32 +27,36 @@ import (
27
27
"github.com/holiman/uint256"
28
28
)
29
29
30
- var activators = map [int ]func (* JumpTable ){
31
- 5656 : enable5656 ,
32
- 6780 : enable6780 ,
33
- 3855 : enable3855 ,
34
- 3860 : enable3860 ,
35
- 3529 : enable3529 ,
36
- 3198 : enable3198 ,
37
- 2929 : enable2929 ,
38
- 2200 : enable2200 ,
39
- 1884 : enable1884 ,
40
- 1344 : enable1344 ,
41
- 1153 : enable1153 ,
42
- 4762 : enable4762 ,
43
- 7702 : enable7702 ,
44
- 7939 : enable7939 ,
30
+ var activators = map [int ][ 2 ] func (* JumpTable ){
31
+ 5656 : { enable5656 } ,
32
+ 6780 : { enable6780 } ,
33
+ 3855 : { enable3855 } ,
34
+ 3860 : { enable3860 } ,
35
+ 3529 : { enable3529 } ,
36
+ 3198 : { enable3198 } ,
37
+ 2929 : { enable2929 [ TracingEnabled ], enable2929 [ TracingDisabled ]} ,
38
+ 2200 : { enable2200 } ,
39
+ 1884 : { enable1884 } ,
40
+ 1344 : { enable1344 } ,
41
+ 1153 : { enable1153 } ,
42
+ 4762 : { enable4762 [ TracingEnabled ], enable4762 [ TracingDisabled ]} ,
43
+ 7702 : { enable7702 [ TracingEnabled ], enable7702 [ TracingDisabled ]} ,
44
+ 7939 : { enable7939 } ,
45
45
}
46
46
47
47
// EnableEIP enables the given EIP on the config.
48
48
// This operation writes in-place, and callers need to ensure that the globally
49
49
// defined jump tables are not polluted.
50
- func EnableEIP (eipNum int , jt * JumpTable ) error {
51
- enablerFn , ok := activators [eipNum ]
50
+ func EnableEIP (eipNum int , jt * JumpTable , traced bool ) error {
51
+ enablerFns , ok := activators [eipNum ]
52
52
if ! ok {
53
53
return fmt .Errorf ("undefined eip %d" , eipNum )
54
54
}
55
- enablerFn (jt )
55
+ if traced || enablerFns [1 ] == nil {
56
+ enablerFns [0 ](jt )
57
+ } else {
58
+ enablerFns [1 ](jt )
59
+ }
56
60
return nil
57
61
}
58
62
@@ -122,7 +126,7 @@ func enable2200(jt *JumpTable) {
122
126
123
127
// enable2929 enables "EIP-2929: Gas cost increases for state access opcodes"
124
128
// https://eips.ethereum.org/EIPS/eip-2929
125
- func enable2929 (jt * JumpTable ) {
129
+ func enable2929 [ TS TracingSwitch ] (jt * JumpTable ) {
126
130
jt [SSTORE ].dynamicGas = gasSStoreEIP2929
127
131
128
132
jt [SLOAD ].constantGas = 0
@@ -141,16 +145,16 @@ func enable2929(jt *JumpTable) {
141
145
jt [BALANCE ].dynamicGas = gasEip2929AccountCheck
142
146
143
147
jt [CALL ].constantGas = params .WarmStorageReadCostEIP2929
144
- jt [CALL ].dynamicGas = gasCallEIP2929
148
+ jt [CALL ].dynamicGas = makeCallVariantGasCallEIP2929 [ TS ]( gasCall , 1 )
145
149
146
150
jt [CALLCODE ].constantGas = params .WarmStorageReadCostEIP2929
147
- jt [CALLCODE ].dynamicGas = gasCallCodeEIP2929
151
+ jt [CALLCODE ].dynamicGas = makeCallVariantGasCallEIP2929 [ TS ]( gasCallCode , 1 )
148
152
149
153
jt [STATICCALL ].constantGas = params .WarmStorageReadCostEIP2929
150
- jt [STATICCALL ].dynamicGas = gasStaticCallEIP2929
154
+ jt [STATICCALL ].dynamicGas = makeCallVariantGasCallEIP2929 [ TS ]( gasStaticCall , 1 )
151
155
152
156
jt [DELEGATECALL ].constantGas = params .WarmStorageReadCostEIP2929
153
- jt [DELEGATECALL ].dynamicGas = gasDelegateCallEIP2929
157
+ jt [DELEGATECALL ].dynamicGas = makeCallVariantGasCallEIP2929 [ TS ]( gasDelegateCall , 1 )
154
158
155
159
// This was previously part of the dynamic cost, but we're using it as a constantGas
156
160
// factor here
@@ -342,7 +346,7 @@ func enable6780(jt *JumpTable) {
342
346
}
343
347
}
344
348
345
- func opExtCodeCopyEIP4762 (pc * uint64 , evm * EVM , scope * ScopeContext ) ([]byte , error ) {
349
+ func opExtCodeCopyEIP4762 [ TS TracingSwitch ] (pc * uint64 , evm * EVM , scope * ScopeContext ) ([]byte , error ) {
346
350
var (
347
351
stack = scope .Stack
348
352
a = stack .pop ()
@@ -358,7 +362,7 @@ func opExtCodeCopyEIP4762(pc *uint64, evm *EVM, scope *ScopeContext) ([]byte, er
358
362
code := evm .StateDB .GetCode (addr )
359
363
paddedCodeCopy , copyOffset , nonPaddedCopyLength := getDataAndAdjustedBounds (code , uint64CodeOffset , length .Uint64 ())
360
364
consumed , wanted := evm .AccessEvents .CodeChunksRangeGas (addr , copyOffset , nonPaddedCopyLength , uint64 (len (code )), false , scope .Contract .Gas )
361
- scope .Contract . UseGas ( consumed , evm .Config .Tracer , tracing .GasChangeUnspecified )
365
+ useGas [ TS ]( scope .Contract , consumed , evm .Config .Tracer , tracing .GasChangeUnspecified )
362
366
if consumed < wanted {
363
367
return nil , ErrOutOfGas
364
368
}
@@ -370,7 +374,7 @@ func opExtCodeCopyEIP4762(pc *uint64, evm *EVM, scope *ScopeContext) ([]byte, er
370
374
// opPush1EIP4762 handles the special case of PUSH1 opcode for EIP-4762, which
371
375
// need not worry about the adjusted bound logic when adding the PUSHDATA to
372
376
// the list of access events.
373
- func opPush1EIP4762 (pc * uint64 , evm * EVM , scope * ScopeContext ) ([]byte , error ) {
377
+ func opPush1EIP4762 [ TS TracingSwitch ] (pc * uint64 , evm * EVM , scope * ScopeContext ) ([]byte , error ) {
374
378
var (
375
379
codeLen = uint64 (len (scope .Contract .Code ))
376
380
integer = new (uint256.Int )
@@ -384,7 +388,7 @@ func opPush1EIP4762(pc *uint64, evm *EVM, scope *ScopeContext) ([]byte, error) {
384
388
// advanced past this boundary.
385
389
contractAddr := scope .Contract .Address ()
386
390
consumed , wanted := evm .AccessEvents .CodeChunksRangeGas (contractAddr , * pc + 1 , uint64 (1 ), uint64 (len (scope .Contract .Code )), false , scope .Contract .Gas )
387
- scope .Contract . UseGas ( wanted , evm .Config .Tracer , tracing .GasChangeUnspecified )
391
+ useGas [ TS ]( scope .Contract , wanted , evm .Config .Tracer , tracing .GasChangeUnspecified )
388
392
if consumed < wanted {
389
393
return nil , ErrOutOfGas
390
394
}
@@ -395,7 +399,7 @@ func opPush1EIP4762(pc *uint64, evm *EVM, scope *ScopeContext) ([]byte, error) {
395
399
return nil , nil
396
400
}
397
401
398
- func makePushEIP4762 (size uint64 , pushByteSize int ) executionFunc {
402
+ func makePushEIP4762 [ TS TracingSwitch ] (size uint64 , pushByteSize int ) executionFunc {
399
403
return func (pc * uint64 , evm * EVM , scope * ScopeContext ) ([]byte , error ) {
400
404
var (
401
405
codeLen = len (scope .Contract .Code )
@@ -412,7 +416,7 @@ func makePushEIP4762(size uint64, pushByteSize int) executionFunc {
412
416
if ! scope .Contract .IsDeployment && ! scope .Contract .IsSystemCall {
413
417
contractAddr := scope .Contract .Address ()
414
418
consumed , wanted := evm .AccessEvents .CodeChunksRangeGas (contractAddr , uint64 (start ), uint64 (pushByteSize ), uint64 (len (scope .Contract .Code )), false , scope .Contract .Gas )
415
- scope .Contract . UseGas ( consumed , evm .Config .Tracer , tracing .GasChangeUnspecified )
419
+ useGas [ TS ]( scope .Contract , consumed , evm .Config .Tracer , tracing .GasChangeUnspecified )
416
420
if consumed < wanted {
417
421
return nil , ErrOutOfGas
418
422
}
@@ -423,7 +427,7 @@ func makePushEIP4762(size uint64, pushByteSize int) executionFunc {
423
427
}
424
428
}
425
429
426
- func enable4762 (jt * JumpTable ) {
430
+ func enable4762 [ TS TracingSwitch ] (jt * JumpTable ) {
427
431
jt [SSTORE ] = & operation {
428
432
dynamicGas : gasSStore4762 ,
429
433
execute : opSstore ,
@@ -459,7 +463,7 @@ func enable4762(jt *JumpTable) {
459
463
}
460
464
461
465
jt [EXTCODECOPY ] = & operation {
462
- execute : opExtCodeCopyEIP4762 ,
466
+ execute : opExtCodeCopyEIP4762 [ TS ] ,
463
467
dynamicGas : gasExtCodeCopyEIP4762 ,
464
468
minStack : minStack (4 , 0 ),
465
469
maxStack : maxStack (4 , 0 ),
@@ -484,7 +488,7 @@ func enable4762(jt *JumpTable) {
484
488
}
485
489
486
490
jt [CREATE ] = & operation {
487
- execute : opCreate ,
491
+ execute : opCreate [ TS ] ,
488
492
constantGas : params .CreateNGasEip4762 ,
489
493
dynamicGas : gasCreateEip3860 ,
490
494
minStack : minStack (3 , 1 ),
@@ -493,7 +497,7 @@ func enable4762(jt *JumpTable) {
493
497
}
494
498
495
499
jt [CREATE2 ] = & operation {
496
- execute : opCreate2 ,
500
+ execute : opCreate2 [ TS ] ,
497
501
constantGas : params .CreateNGasEip4762 ,
498
502
dynamicGas : gasCreate2Eip3860 ,
499
503
minStack : minStack (4 , 1 ),
@@ -502,46 +506,46 @@ func enable4762(jt *JumpTable) {
502
506
}
503
507
504
508
jt [CALL ] = & operation {
505
- execute : opCall ,
509
+ execute : opCall [ TS ] ,
506
510
dynamicGas : gasCallEIP4762 ,
507
511
minStack : minStack (7 , 1 ),
508
512
maxStack : maxStack (7 , 1 ),
509
513
memorySize : memoryCall ,
510
514
}
511
515
512
516
jt [CALLCODE ] = & operation {
513
- execute : opCallCode ,
517
+ execute : opCallCode [ TS ] ,
514
518
dynamicGas : gasCallCodeEIP4762 ,
515
519
minStack : minStack (7 , 1 ),
516
520
maxStack : maxStack (7 , 1 ),
517
521
memorySize : memoryCall ,
518
522
}
519
523
520
524
jt [STATICCALL ] = & operation {
521
- execute : opStaticCall ,
525
+ execute : opStaticCall [ TS ] ,
522
526
dynamicGas : gasStaticCallEIP4762 ,
523
527
minStack : minStack (6 , 1 ),
524
528
maxStack : maxStack (6 , 1 ),
525
529
memorySize : memoryStaticCall ,
526
530
}
527
531
528
532
jt [DELEGATECALL ] = & operation {
529
- execute : opDelegateCall ,
533
+ execute : opDelegateCall [ TS ] ,
530
534
dynamicGas : gasDelegateCallEIP4762 ,
531
535
minStack : minStack (6 , 1 ),
532
536
maxStack : maxStack (6 , 1 ),
533
537
memorySize : memoryDelegateCall ,
534
538
}
535
539
536
540
jt [PUSH1 ] = & operation {
537
- execute : opPush1EIP4762 ,
541
+ execute : opPush1EIP4762 [ TS ] ,
538
542
constantGas : GasFastestStep ,
539
543
minStack : minStack (0 , 1 ),
540
544
maxStack : maxStack (0 , 1 ),
541
545
}
542
546
for i := 1 ; i < 32 ; i ++ {
543
547
jt [PUSH1 + OpCode (i )] = & operation {
544
- execute : makePushEIP4762 (uint64 (i + 1 ), i + 1 ),
548
+ execute : makePushEIP4762 [ TS ] (uint64 (i + 1 ), i + 1 ),
545
549
constantGas : GasFastestStep ,
546
550
minStack : minStack (0 , 1 ),
547
551
maxStack : maxStack (0 , 1 ),
@@ -550,9 +554,9 @@ func enable4762(jt *JumpTable) {
550
554
}
551
555
552
556
// enable7702 the EIP-7702 changes to support delegation designators.
553
- func enable7702 (jt * JumpTable ) {
554
- jt [CALL ].dynamicGas = gasCallEIP7702
555
- jt [CALLCODE ].dynamicGas = gasCallCodeEIP7702
556
- jt [STATICCALL ].dynamicGas = gasStaticCallEIP7702
557
- jt [DELEGATECALL ].dynamicGas = gasDelegateCallEIP7702
557
+ func enable7702 [ TS TracingSwitch ] (jt * JumpTable ) {
558
+ jt [CALL ].dynamicGas = makeCallVariantGasCallEIP7702 [ TS ]( gasCall )
559
+ jt [CALLCODE ].dynamicGas = makeCallVariantGasCallEIP7702 [ TS ]( gasCallCode )
560
+ jt [STATICCALL ].dynamicGas = makeCallVariantGasCallEIP7702 [ TS ]( gasStaticCall )
561
+ jt [DELEGATECALL ].dynamicGas = makeCallVariantGasCallEIP7702 [ TS ]( gasDelegateCall )
558
562
}
0 commit comments