Skip to content

Commit 34aac1d

Browse files
authored
all: use big.Sign to compare with zero (#29490)
1 parent f202dfd commit 34aac1d

File tree

6 files changed

+6
-7
lines changed

6 files changed

+6
-7
lines changed

core/evm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func NewEVMBlockContext(header *types.Header, chain ChainContext, author *common
5959
if header.ExcessBlobGas != nil {
6060
blobBaseFee = eip4844.CalcBlobFee(*header.ExcessBlobGas)
6161
}
62-
if header.Difficulty.Cmp(common.Big0) == 0 {
62+
if header.Difficulty.Sign() == 0 {
6363
random = &header.MixDigest
6464
}
6565
return vm.BlockContext{

eth/backend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
111111
if !config.SyncMode.IsValid() {
112112
return nil, fmt.Errorf("invalid sync mode %d", config.SyncMode)
113113
}
114-
if config.Miner.GasPrice == nil || config.Miner.GasPrice.Cmp(common.Big0) <= 0 {
114+
if config.Miner.GasPrice == nil || config.Miner.GasPrice.Sign() <= 0 {
115115
log.Warn("Sanitizing invalid miner gas price", "provided", config.Miner.GasPrice, "updated", ethconfig.Defaults.Miner.GasPrice)
116116
config.Miner.GasPrice = new(big.Int).Set(ethconfig.Defaults.Miner.GasPrice)
117117
}

ethclient/gethclient/gethclient_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ func testGetProofNonExistent(t *testing.T, client *rpc.Client) {
299299
t.Fatalf("invalid nonce, want: %v got: %v", 0, result.Nonce)
300300
}
301301
// test balance
302-
if result.Balance.Cmp(big.NewInt(0)) != 0 {
302+
if result.Balance.Sign() != 0 {
303303
t.Fatalf("invalid balance, want: %v got: %v", 0, result.Balance)
304304
}
305305
// test storage

ethclient/simulated/options.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func WithCallGasLimit(gaslimit uint64) func(nodeConf *node.Config, ethConf *ethc
4646
// 0 is not possible as a live Geth node would reject that due to DoS protection,
4747
// so the simulated backend will replicate that behavior for consistency.
4848
func WithMinerMinTip(tip *big.Int) func(nodeConf *node.Config, ethConf *ethconfig.Config) {
49-
if tip == nil || tip.Cmp(new(big.Int)) <= 0 {
49+
if tip == nil || tip.Sign() <= 0 {
5050
panic("invalid miner minimum tip")
5151
}
5252
return func(nodeConf *node.Config, ethConf *ethconfig.Config) {

internal/ethapi/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1497,7 +1497,7 @@ func AccessList(ctx context.Context, b Backend, blockNrOrHash rpc.BlockNumberOrH
14971497
} else {
14981498
to = crypto.CreateAddress(args.from(), uint64(*args.Nonce))
14991499
}
1500-
isPostMerge := header.Difficulty.Cmp(common.Big0) == 0
1500+
isPostMerge := header.Difficulty.Sign() == 0
15011501
// Retrieve the precompiles since they don't need to be added to the access list
15021502
precompiles := vm.ActivePrecompiles(b.ChainConfig().Rules(header.Number, isPostMerge, header.Time))
15031503

signer/fourbyte/validation.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"bytes"
2121
"errors"
2222
"fmt"
23-
"math/big"
2423

2524
"github.com/ethereum/go-ethereum/common"
2625
"github.com/ethereum/go-ethereum/signer/core/apitypes"
@@ -57,7 +56,7 @@ func (db *Database) ValidateTransaction(selector *string, tx *apitypes.SendTxArg
5756
// e.g. https://github.com/ethereum/go-ethereum/issues/16106.
5857
if len(data) == 0 {
5958
// Prevent sending ether into black hole (show stopper)
60-
if tx.Value.ToInt().Cmp(big.NewInt(0)) > 0 {
59+
if tx.Value.ToInt().Sign() > 0 {
6160
return nil, errors.New("transaction will create a contract with value but empty code")
6261
}
6362
// No value submitted at least, critically Warn, but don't blow up

0 commit comments

Comments
 (0)