@@ -67,11 +67,17 @@ func (result *ExecutionResult) Revert() []byte {
6767}
6868
6969// IntrinsicGas computes the 'intrinsic gas' for a message with the given data.
70- func IntrinsicGas (data []byte , accessList types.AccessList , authList []types.SetCodeAuthorization , isContractCreation , isHomestead , isEIP2028 , isEIP3860 bool ) (uint64 , error ) {
70+ // costPerStateByte needs to be set post-Amsterdam.
71+ func IntrinsicGas (data []byte , accessList types.AccessList , authList []types.SetCodeAuthorization , isContractCreation bool , rules params.Rules , costPerStateByte uint64 ) (uint64 , error ) {
7172 // Set the starting gas for the raw transaction
7273 var gas uint64
73- if isContractCreation && isHomestead {
74- gas = params .TxGasContractCreation
74+ if isContractCreation && rules .IsHomestead {
75+ if rules .IsAmsterdam {
76+ // TODO fix EIP-8037
77+ gas = params .AccountCreationSize * costPerStateByte
78+ } else {
79+ gas = params .TxGasContractCreation
80+ }
7581 } else {
7682 gas = params .TxGas
7783 }
@@ -84,7 +90,7 @@ func IntrinsicGas(data []byte, accessList types.AccessList, authList []types.Set
8490
8591 // Make sure we don't exceed uint64 for all data combinations
8692 nonZeroGas := params .TxDataNonZeroGasFrontier
87- if isEIP2028 {
93+ if rules . IsIstanbul {
8894 nonZeroGas = params .TxDataNonZeroGasEIP2028
8995 }
9096 if (math .MaxUint64 - gas )/ nonZeroGas < nz {
@@ -97,7 +103,7 @@ func IntrinsicGas(data []byte, accessList types.AccessList, authList []types.Set
97103 }
98104 gas += z * params .TxDataZeroGas
99105
100- if isContractCreation && isEIP3860 {
106+ if isContractCreation && rules . IsShanghai {
101107 lenWords := toWordSize (dataLen )
102108 if (math .MaxUint64 - gas )/ params .InitCodeWordGas < lenWords {
103109 return 0 , ErrGasUintOverflow
@@ -110,7 +116,11 @@ func IntrinsicGas(data []byte, accessList types.AccessList, authList []types.Set
110116 gas += uint64 (accessList .StorageKeys ()) * params .TxAccessListStorageKeyGas
111117 }
112118 if authList != nil {
113- gas += uint64 (len (authList )) * params .CallNewAccountGas
119+ if rules .IsAmsterdam {
120+ gas += uint64 (len (authList )) * costPerStateByte
121+ } else {
122+ gas += uint64 (len (authList )) * params .CallNewAccountGas
123+ }
114124 }
115125 return gas , nil
116126}
@@ -447,7 +457,7 @@ func (st *stateTransition) execute() (*ExecutionResult, error) {
447457 )
448458
449459 // Check clauses 4-5, subtract intrinsic gas if everything is correct
450- gas , err := IntrinsicGas (msg .Data , msg .AccessList , msg .SetCodeAuthorizations , contractCreation , rules . IsHomestead , rules . IsIstanbul , rules . IsShanghai )
460+ gas , err := IntrinsicGas (msg .Data , msg .AccessList , msg .SetCodeAuthorizations , contractCreation , rules , st . evm . Context . CostPerGasByte )
451461 if err != nil {
452462 return nil , err
453463 }
@@ -512,7 +522,7 @@ func (st *stateTransition) execute() (*ExecutionResult, error) {
512522 if msg .SetCodeAuthorizations != nil {
513523 for _ , auth := range msg .SetCodeAuthorizations {
514524 // Note errors are ignored, we simply skip invalid authorizations here.
515- st .applyAuthorization (& auth )
525+ st .applyAuthorization (rules , & auth )
516526 }
517527 }
518528
@@ -626,7 +636,7 @@ func (st *stateTransition) validateAuthorization(auth *types.SetCodeAuthorizatio
626636}
627637
628638// applyAuthorization applies an EIP-7702 code delegation to the state.
629- func (st * stateTransition ) applyAuthorization (auth * types.SetCodeAuthorization ) error {
639+ func (st * stateTransition ) applyAuthorization (rules params. Rules , auth * types.SetCodeAuthorization ) error {
630640 authority , err := st .validateAuthorization (auth )
631641 if err != nil {
632642 return err
@@ -635,7 +645,13 @@ func (st *stateTransition) applyAuthorization(auth *types.SetCodeAuthorization)
635645 // If the account already exists in state, refund the new account cost
636646 // charged in the intrinsic calculation.
637647 if st .state .Exist (authority ) {
638- st .state .AddRefund (params .CallNewAccountGas - params .TxAuthTupleGas )
648+ if rules .IsAmsterdam {
649+ newAccountCost := params .AccountCreationSize * st .evm .Context .CostPerGasByte
650+ perAuthBasCost := params .AuthorizationCreationSize * st .evm .Context .CostPerGasByte
651+ st .state .AddRefund (newAccountCost - perAuthBasCost )
652+ } else {
653+ st .state .AddRefund (params .CallNewAccountGas - params .TxAuthTupleGas )
654+ }
639655 }
640656
641657 prevDelegation , isDelegated := types .ParseDelegation (st .state .GetCode (authority ))
0 commit comments