Skip to content

Commit

Permalink
core/tx_pool: remove 2718 fork info from intrinsic gas
Browse files Browse the repository at this point in the history
  • Loading branch information
lightclient committed Nov 24, 2020
1 parent 4857b32 commit 7a22d84
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 18 deletions.
2 changes: 1 addition & 1 deletion core/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func genValueTx(nbytes int) func(int, *BlockGen) {
return func(i int, gen *BlockGen) {
toaddr := common.Address{}
data := make([]byte, nbytes)
gas, _ := IntrinsicGas(data, nil, false, false, false, false)
gas, _ := IntrinsicGas(data, nil, false, false, false)
tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(benchRootAddr), toaddr, big.NewInt(1), gas, nil, data), types.HomesteadSigner{}, benchRootKey)
gen.AddTx(tx)
}
Expand Down
7 changes: 3 additions & 4 deletions core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (result *ExecutionResult) Revert() []byte {
}

// IntrinsicGas computes the 'intrinsic gas' for a message with the given data.
func IntrinsicGas(data []byte, accessList *types.AccessList, isContractCreation bool, isHomestead, isEIP2028, isEIP2718 bool) (uint64, error) {
func IntrinsicGas(data []byte, accessList *types.AccessList, isContractCreation bool, isHomestead, isEIP2028 bool) (uint64, error) {
// Set the starting gas for the raw transaction
var gas uint64
if isContractCreation && isHomestead {
Expand Down Expand Up @@ -139,7 +139,7 @@ func IntrinsicGas(data []byte, accessList *types.AccessList, isContractCreation
}
gas += z * params.TxDataZeroGas
}
if isEIP2718 && accessList != nil {
if accessList != nil {
gas += uint64(accessList.Addresses()) * params.TxAccessListAddressGas
gas += uint64(accessList.StorageKeys()) * params.TxAccessListStorageKeyGas
}
Expand Down Expand Up @@ -238,11 +238,10 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
sender := vm.AccountRef(msg.From())
homestead := st.evm.ChainConfig().IsHomestead(st.evm.Context.BlockNumber)
istanbul := st.evm.ChainConfig().IsIstanbul(st.evm.Context.BlockNumber)
yoloV2 := st.evm.ChainConfig().IsYoloV2(st.evm.Context.BlockNumber)
contractCreation := msg.To() == nil

// Check clauses 4-5, subtract intrinsic gas if everything is correct
gas, err := IntrinsicGas(st.data, st.msg.AccessList(), contractCreation, homestead, istanbul, yoloV2)
gas, err := IntrinsicGas(st.data, st.msg.AccessList(), contractCreation, homestead, istanbul)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion core/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
return ErrInsufficientFunds
}
// Ensure the transaction has more gas than the basic tx fee.
intrGas, err := IntrinsicGas(tx.Data(), tx.AccessList(), tx.To() == nil, true, pool.istanbul, pool.yoloV2)
intrGas, err := IntrinsicGas(tx.Data(), tx.AccessList(), tx.To() == nil, true, pool.istanbul)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion light/txpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ func (pool *TxPool) validateTx(ctx context.Context, tx *types.Transaction) error
}

// Should supply enough intrinsic gas
gas, err := core.IntrinsicGas(tx.Data(), tx.AccessList(), tx.To() == nil, true, pool.istanbul, pool.yoloV2)
gas, err := core.IntrinsicGas(tx.Data(), tx.AccessList(), tx.To() == nil, true, pool.istanbul)
if err != nil {
return err
}
Expand Down
21 changes: 10 additions & 11 deletions tests/transaction_test_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type ttFork struct {
}

func (tt *TransactionTest) Run(config *params.ChainConfig) error {
validateTx := func(rlpData hexutil.Bytes, signer types.Signer, isHomestead bool, isIstanbul bool, isYoloV2 bool) (*common.Address, *common.Hash, error) {
validateTx := func(rlpData hexutil.Bytes, signer types.Signer, isHomestead bool, isIstanbul bool) (*common.Address, *common.Hash, error) {
tx := new(types.Transaction)
if err := rlp.DecodeBytes(rlpData, tx); err != nil {
return nil, nil, err
Expand All @@ -55,7 +55,7 @@ func (tt *TransactionTest) Run(config *params.ChainConfig) error {
return nil, nil, err
}
// Intrinsic gas
requiredGas, err := core.IntrinsicGas(tx.Data(), tx.AccessList(), tx.To() == nil, isHomestead, isIstanbul, isYoloV2)
requiredGas, err := core.IntrinsicGas(tx.Data(), tx.AccessList(), tx.To() == nil, isHomestead, isIstanbul)
if err != nil {
return nil, nil, err
}
Expand All @@ -72,17 +72,16 @@ func (tt *TransactionTest) Run(config *params.ChainConfig) error {
fork ttFork
isHomestead bool
isIstanbul bool
isYoloV2 bool
}{
{"Frontier", types.FrontierSigner{}, tt.Frontier, false, false, false},
{"Homestead", types.HomesteadSigner{}, tt.Homestead, true, false, false},
{"EIP150", types.HomesteadSigner{}, tt.EIP150, true, false, false},
{"EIP158", types.NewEIP155Signer(config.ChainID), tt.EIP158, true, false, false},
{"Byzantium", types.NewEIP155Signer(config.ChainID), tt.Byzantium, true, false, false},
{"Constantinople", types.NewEIP155Signer(config.ChainID), tt.Constantinople, true, false, false},
{"Istanbul", types.NewEIP155Signer(config.ChainID), tt.Istanbul, true, true, false},
{"Frontier", types.FrontierSigner{}, tt.Frontier, false, false},
{"Homestead", types.HomesteadSigner{}, tt.Homestead, true, false},
{"EIP150", types.HomesteadSigner{}, tt.EIP150, true, false},
{"EIP158", types.NewEIP155Signer(config.ChainID), tt.EIP158, true, false},
{"Byzantium", types.NewEIP155Signer(config.ChainID), tt.Byzantium, true, false},
{"Constantinople", types.NewEIP155Signer(config.ChainID), tt.Constantinople, true, false},
{"Istanbul", types.NewEIP155Signer(config.ChainID), tt.Istanbul, true, true},
} {
sender, txhash, err := validateTx(tt.RLP, testcase.signer, testcase.isHomestead, testcase.isIstanbul, testcase.isYoloV2)
sender, txhash, err := validateTx(tt.RLP, testcase.signer, testcase.isHomestead, testcase.isIstanbul)

if testcase.fork.Sender == (common.UnprefixedAddress{}) {
if err == nil {
Expand Down

0 comments on commit 7a22d84

Please sign in to comment.