From 34aac1d7562bf141fe6da1d4f3cdea8819e7b23b Mon Sep 17 00:00:00 2001 From: Aaron Chen Date: Tue, 9 Apr 2024 18:14:30 +0800 Subject: [PATCH] all: use big.Sign to compare with zero (#29490) --- core/evm.go | 2 +- eth/backend.go | 2 +- ethclient/gethclient/gethclient_test.go | 2 +- ethclient/simulated/options.go | 2 +- internal/ethapi/api.go | 2 +- signer/fourbyte/validation.go | 3 +-- 6 files changed, 6 insertions(+), 7 deletions(-) diff --git a/core/evm.go b/core/evm.go index 4c12e2aa02..5d3c454d7c 100644 --- a/core/evm.go +++ b/core/evm.go @@ -59,7 +59,7 @@ func NewEVMBlockContext(header *types.Header, chain ChainContext, author *common if header.ExcessBlobGas != nil { blobBaseFee = eip4844.CalcBlobFee(*header.ExcessBlobGas) } - if header.Difficulty.Cmp(common.Big0) == 0 { + if header.Difficulty.Sign() == 0 { random = &header.MixDigest } return vm.BlockContext{ diff --git a/eth/backend.go b/eth/backend.go index db3209aee2..04ee82efee 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -111,7 +111,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) { if !config.SyncMode.IsValid() { return nil, fmt.Errorf("invalid sync mode %d", config.SyncMode) } - if config.Miner.GasPrice == nil || config.Miner.GasPrice.Cmp(common.Big0) <= 0 { + if config.Miner.GasPrice == nil || config.Miner.GasPrice.Sign() <= 0 { log.Warn("Sanitizing invalid miner gas price", "provided", config.Miner.GasPrice, "updated", ethconfig.Defaults.Miner.GasPrice) config.Miner.GasPrice = new(big.Int).Set(ethconfig.Defaults.Miner.GasPrice) } diff --git a/ethclient/gethclient/gethclient_test.go b/ethclient/gethclient/gethclient_test.go index d562bcda1f..1cd9c5389b 100644 --- a/ethclient/gethclient/gethclient_test.go +++ b/ethclient/gethclient/gethclient_test.go @@ -299,7 +299,7 @@ func testGetProofNonExistent(t *testing.T, client *rpc.Client) { t.Fatalf("invalid nonce, want: %v got: %v", 0, result.Nonce) } // test balance - if result.Balance.Cmp(big.NewInt(0)) != 0 { + if result.Balance.Sign() != 0 { t.Fatalf("invalid balance, want: %v got: %v", 0, result.Balance) } // test storage diff --git a/ethclient/simulated/options.go b/ethclient/simulated/options.go index 6db995c917..40bcb37bd1 100644 --- a/ethclient/simulated/options.go +++ b/ethclient/simulated/options.go @@ -46,7 +46,7 @@ func WithCallGasLimit(gaslimit uint64) func(nodeConf *node.Config, ethConf *ethc // 0 is not possible as a live Geth node would reject that due to DoS protection, // so the simulated backend will replicate that behavior for consistency. func WithMinerMinTip(tip *big.Int) func(nodeConf *node.Config, ethConf *ethconfig.Config) { - if tip == nil || tip.Cmp(new(big.Int)) <= 0 { + if tip == nil || tip.Sign() <= 0 { panic("invalid miner minimum tip") } return func(nodeConf *node.Config, ethConf *ethconfig.Config) { diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index f682f27658..f965c91375 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1497,7 +1497,7 @@ func AccessList(ctx context.Context, b Backend, blockNrOrHash rpc.BlockNumberOrH } else { to = crypto.CreateAddress(args.from(), uint64(*args.Nonce)) } - isPostMerge := header.Difficulty.Cmp(common.Big0) == 0 + isPostMerge := header.Difficulty.Sign() == 0 // Retrieve the precompiles since they don't need to be added to the access list precompiles := vm.ActivePrecompiles(b.ChainConfig().Rules(header.Number, isPostMerge, header.Time)) diff --git a/signer/fourbyte/validation.go b/signer/fourbyte/validation.go index 0451bda91d..8bff011925 100644 --- a/signer/fourbyte/validation.go +++ b/signer/fourbyte/validation.go @@ -20,7 +20,6 @@ import ( "bytes" "errors" "fmt" - "math/big" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/signer/core/apitypes" @@ -57,7 +56,7 @@ func (db *Database) ValidateTransaction(selector *string, tx *apitypes.SendTxArg // e.g. https://github.com/ethereum/go-ethereum/issues/16106. if len(data) == 0 { // Prevent sending ether into black hole (show stopper) - if tx.Value.ToInt().Cmp(big.NewInt(0)) > 0 { + if tx.Value.ToInt().Sign() > 0 { return nil, errors.New("transaction will create a contract with value but empty code") } // No value submitted at least, critically Warn, but don't blow up