@@ -448,6 +448,18 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64,
448
448
}
449
449
evm .StateDB .SetNonce (caller .Address (), nonce + 1 )
450
450
451
+ // Charge the contract creation init gas in verkle mode
452
+ if evm .chainRules .IsEIP4762 {
453
+ statelessGas := evm .AccessEvents .ContractCreatePreCheckGas (address )
454
+ if statelessGas > gas {
455
+ return nil , common.Address {}, 0 , ErrOutOfGas
456
+ }
457
+ if evm .Config .Tracer != nil && evm .Config .Tracer .OnGasChange != nil {
458
+ evm .Config .Tracer .OnGasChange (gas , gas - statelessGas , tracing .GasChangeWitnessContractCollisionCheck )
459
+ }
460
+ gas = gas - statelessGas
461
+ }
462
+
451
463
// We add this to the access list _before_ taking a snapshot. Even if the
452
464
// creation fails, the access-list change should not be rolled back.
453
465
if evm .chainRules .IsEIP2929 {
@@ -484,6 +496,17 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64,
484
496
if evm .chainRules .IsEIP158 {
485
497
evm .StateDB .SetNonce (address , 1 )
486
498
}
499
+ // Charge the contract creation init gas in verkle mode
500
+ if evm .chainRules .IsEIP4762 {
501
+ statelessGas := evm .AccessEvents .ContractCreateInitGas (address )
502
+ if statelessGas > gas {
503
+ return nil , common.Address {}, 0 , ErrOutOfGas
504
+ }
505
+ if evm .Config .Tracer != nil && evm .Config .Tracer .OnGasChange != nil {
506
+ evm .Config .Tracer .OnGasChange (gas , gas - statelessGas , tracing .GasChangeWitnessContractInit )
507
+ }
508
+ gas = gas - statelessGas
509
+ }
487
510
evm .Context .Transfer (evm .StateDB , caller .Address (), address , value )
488
511
489
512
// Initialise a new contract and set the code that is to be used by the EVM.
@@ -505,13 +528,6 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64,
505
528
// initNewContract runs a new contract's creation code, performs checks on the
506
529
// resulting code that is to be deployed, and consumes necessary gas.
507
530
func (evm * EVM ) initNewContract (contract * Contract , address common.Address , value * uint256.Int ) ([]byte , error ) {
508
- // Charge the contract creation init gas in verkle mode
509
- if evm .chainRules .IsEIP4762 {
510
- if ! contract .UseGas (evm .AccessEvents .ContractCreateInitGas (address , value .Sign () != 0 ), evm .Config .Tracer , tracing .GasChangeWitnessContractInit ) {
511
- return nil , ErrOutOfGas
512
- }
513
- }
514
-
515
531
ret , err := evm .interpreter .Run (contract , nil , false )
516
532
if err != nil {
517
533
return ret , err
@@ -533,11 +549,6 @@ func (evm *EVM) initNewContract(contract *Contract, address common.Address, valu
533
549
return ret , ErrCodeStoreOutOfGas
534
550
}
535
551
} else {
536
- // Contract creation completed, touch the missing fields in the contract
537
- if ! contract .UseGas (evm .AccessEvents .AddAccount (address , true ), evm .Config .Tracer , tracing .GasChangeWitnessContractCreation ) {
538
- return ret , ErrCodeStoreOutOfGas
539
- }
540
-
541
552
if len (ret ) > 0 && ! contract .UseGas (evm .AccessEvents .CodeChunksRangeGas (address , 0 , uint64 (len (ret )), uint64 (len (ret )), true ), evm .Config .Tracer , tracing .GasChangeWitnessCodeChunk ) {
542
553
return ret , ErrCodeStoreOutOfGas
543
554
}
0 commit comments