diff --git a/core/bench_test.go b/core/bench_test.go index 141ce90d12..534b51acf8 100644 --- a/core/bench_test.go +++ b/core/bench_test.go @@ -96,23 +96,17 @@ func genValueTx(nbytes int) func(int, *BlockGen) { gasPrice = gen.header.BaseFee } rules := params.TestChainConfig.Rules(common.Big0, true, 0) - tx0 := types.NewTx(&types.LegacyTx{ + txdata := &types.LegacyTx{ Nonce: gen.TxNonce(benchRootAddr), To: &toaddr, Value: big.NewInt(1), Gas: params.TxGas, Data: data, GasPrice: gasPrice, - }) - gas, _ := tx0.IntrinsicGas(&rules) - tx, _ := types.SignNewTx(benchRootKey, signer, &types.LegacyTx{ - Nonce: gen.TxNonce(benchRootAddr), - To: &toaddr, - Value: big.NewInt(1), - Gas: gas, - Data: data, - GasPrice: gasPrice, - }) + } + gas, _ := types.IntrinsicGas(txdata, &rules) + txdata.Gas = gas + tx, _ := types.SignNewTx(benchRootKey, signer, txdata) gen.AddTx(tx) } } diff --git a/core/state_transition.go b/core/state_transition.go index 5ce6d89b60..2544fc0ece 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -82,15 +82,6 @@ func FloorDataGas(data []byte) (uint64, error) { return params.TxGas + tokens*params.TxCostFloorPerToken, nil } -// toWordSize returns the ceiled word size required for init code payment calculation. -func toWordSize(size uint64) uint64 { - if size > math.MaxUint64-31 { - return math.MaxUint64/32 + 1 - } - - return (size + 31) / 32 -} - // A Message contains the data derived from a single transaction that is relevant to state // processing. type Message struct { diff --git a/core/types/transaction.go b/core/types/transaction.go index 3dd02c76de..82ca0d6f1a 100644 --- a/core/types/transaction.go +++ b/core/types/transaction.go @@ -89,6 +89,7 @@ type TxData interface { value() *big.Int nonce() uint64 to() *common.Address + setCodeAuthorizations() []SetCodeAuthorization rawSignatureValues() (v, r, s *big.Int) setSignatureValues(chainID, v, r, s *big.Int) @@ -482,11 +483,7 @@ func (tx *Transaction) WithBlobTxSidecar(sideCar *BlobTxSidecar) *Transaction { // SetCodeAuthorizations returns the authorizations list of the transaction. func (tx *Transaction) SetCodeAuthorizations() []SetCodeAuthorization { - setcodetx, ok := tx.inner.(*SetCodeTx) - if !ok { - return nil - } - return setcodetx.AuthList + return tx.inner.setCodeAuthorizations() } // SetCodeAuthorities returns a list of unique authorities from the @@ -584,13 +581,18 @@ func (tx *Transaction) WithSignature(signer Signer, sig []byte) (*Transaction, e return &Transaction{inner: cpy, time: tx.time}, nil } -// IntrinsicGas computes the 'intrinsic gas' for a message with the given data. +// IntrinsicGas returns the 'intrinsic gas' computed for a message with the given data. func (tx *Transaction) IntrinsicGas(rules *params.Rules) (uint64, error) { + return IntrinsicGas(tx.inner, rules) +} + +// IntrinsicGas computes the 'intrinsic gas' for a message with the given data. +func IntrinsicGas(txdata TxData, rules *params.Rules) (uint64, error) { var ( - data = tx.Data() - accessList = tx.AccessList() - authList = tx.SetCodeAuthorizations() - isContractCreation = tx.To() == nil + data = txdata.data() + accessList = txdata.accessList() + authList = txdata.setCodeAuthorizations() + isContractCreation = txdata.to() == nil ) // Set the starting gas for the raw transaction diff --git a/core/types/tx_access_list.go b/core/types/tx_access_list.go index 915de9a8ab..6955461a0a 100644 --- a/core/types/tx_access_list.go +++ b/core/types/tx_access_list.go @@ -107,6 +107,9 @@ func (tx *AccessListTx) gasFeeCap() *big.Int { return tx.GasPrice } func (tx *AccessListTx) value() *big.Int { return tx.Value } func (tx *AccessListTx) nonce() uint64 { return tx.Nonce } func (tx *AccessListTx) to() *common.Address { return tx.To } +func (tx *AccessListTx) setCodeAuthorizations() []SetCodeAuthorization { + return nil +} func (tx *AccessListTx) effectiveGasPrice(dst *big.Int, baseFee *big.Int) *big.Int { return dst.Set(tx.GasPrice) diff --git a/core/types/tx_blob.go b/core/types/tx_blob.go index 9b1d53958f..823a4facdf 100644 --- a/core/types/tx_blob.go +++ b/core/types/tx_blob.go @@ -179,6 +179,9 @@ func (tx *BlobTx) value() *big.Int { return tx.Value.ToBig() } func (tx *BlobTx) nonce() uint64 { return tx.Nonce } func (tx *BlobTx) to() *common.Address { tmp := tx.To; return &tmp } func (tx *BlobTx) blobGas() uint64 { return params.BlobTxBlobGasPerBlob * uint64(len(tx.BlobHashes)) } +func (tx *BlobTx) setCodeAuthorizations() []SetCodeAuthorization { + return nil +} func (tx *BlobTx) effectiveGasPrice(dst *big.Int, baseFee *big.Int) *big.Int { if baseFee == nil { diff --git a/core/types/tx_dynamic_fee.go b/core/types/tx_dynamic_fee.go index bba81464f8..3ff0bd3846 100644 --- a/core/types/tx_dynamic_fee.go +++ b/core/types/tx_dynamic_fee.go @@ -96,6 +96,9 @@ func (tx *DynamicFeeTx) gasPrice() *big.Int { return tx.GasFeeCap } func (tx *DynamicFeeTx) value() *big.Int { return tx.Value } func (tx *DynamicFeeTx) nonce() uint64 { return tx.Nonce } func (tx *DynamicFeeTx) to() *common.Address { return tx.To } +func (tx *DynamicFeeTx) setCodeAuthorizations() []SetCodeAuthorization { + return nil +} func (tx *DynamicFeeTx) effectiveGasPrice(dst *big.Int, baseFee *big.Int) *big.Int { if baseFee == nil { diff --git a/core/types/tx_legacy.go b/core/types/tx_legacy.go index 49f0a98809..26f02aeed0 100644 --- a/core/types/tx_legacy.go +++ b/core/types/tx_legacy.go @@ -103,6 +103,9 @@ func (tx *LegacyTx) gasFeeCap() *big.Int { return tx.GasPrice } func (tx *LegacyTx) value() *big.Int { return tx.Value } func (tx *LegacyTx) nonce() uint64 { return tx.Nonce } func (tx *LegacyTx) to() *common.Address { return tx.To } +func (tx *LegacyTx) setCodeAuthorizations() []SetCodeAuthorization { + return nil +} func (tx *LegacyTx) effectiveGasPrice(dst *big.Int, baseFee *big.Int) *big.Int { return dst.Set(tx.GasPrice) diff --git a/core/types/tx_setcode.go b/core/types/tx_setcode.go index b8e38ef1f7..fefc697b7a 100644 --- a/core/types/tx_setcode.go +++ b/core/types/tx_setcode.go @@ -193,6 +193,9 @@ func (tx *SetCodeTx) gasPrice() *big.Int { return tx.GasFeeCap.ToBig() } func (tx *SetCodeTx) value() *big.Int { return tx.Value.ToBig() } func (tx *SetCodeTx) nonce() uint64 { return tx.Nonce } func (tx *SetCodeTx) to() *common.Address { tmp := tx.To; return &tmp } +func (tx *SetCodeTx) setCodeAuthorizations() []SetCodeAuthorization { + return tx.AuthList +} func (tx *SetCodeTx) effectiveGasPrice(dst *big.Int, baseFee *big.Int) *big.Int { if baseFee == nil {