all: use big.Sign to compare with zero (#29490)

pull/29499/head
Aaron Chen 8 months ago committed by GitHub
parent f202dfdd47
commit 34aac1d756
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      core/evm.go
  2. 2
      eth/backend.go
  3. 2
      ethclient/gethclient/gethclient_test.go
  4. 2
      ethclient/simulated/options.go
  5. 2
      internal/ethapi/api.go
  6. 3
      signer/fourbyte/validation.go

@ -59,7 +59,7 @@ func NewEVMBlockContext(header *types.Header, chain ChainContext, author *common
if header.ExcessBlobGas != nil { if header.ExcessBlobGas != nil {
blobBaseFee = eip4844.CalcBlobFee(*header.ExcessBlobGas) blobBaseFee = eip4844.CalcBlobFee(*header.ExcessBlobGas)
} }
if header.Difficulty.Cmp(common.Big0) == 0 { if header.Difficulty.Sign() == 0 {
random = &header.MixDigest random = &header.MixDigest
} }
return vm.BlockContext{ return vm.BlockContext{

@ -111,7 +111,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
if !config.SyncMode.IsValid() { if !config.SyncMode.IsValid() {
return nil, fmt.Errorf("invalid sync mode %d", config.SyncMode) 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) 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) config.Miner.GasPrice = new(big.Int).Set(ethconfig.Defaults.Miner.GasPrice)
} }

@ -299,7 +299,7 @@ func testGetProofNonExistent(t *testing.T, client *rpc.Client) {
t.Fatalf("invalid nonce, want: %v got: %v", 0, result.Nonce) t.Fatalf("invalid nonce, want: %v got: %v", 0, result.Nonce)
} }
// test balance // 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) t.Fatalf("invalid balance, want: %v got: %v", 0, result.Balance)
} }
// test storage // test storage

@ -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, // 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. // so the simulated backend will replicate that behavior for consistency.
func WithMinerMinTip(tip *big.Int) func(nodeConf *node.Config, ethConf *ethconfig.Config) { 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") panic("invalid miner minimum tip")
} }
return func(nodeConf *node.Config, ethConf *ethconfig.Config) { return func(nodeConf *node.Config, ethConf *ethconfig.Config) {

@ -1497,7 +1497,7 @@ func AccessList(ctx context.Context, b Backend, blockNrOrHash rpc.BlockNumberOrH
} else { } else {
to = crypto.CreateAddress(args.from(), uint64(*args.Nonce)) 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 // 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)) precompiles := vm.ActivePrecompiles(b.ChainConfig().Rules(header.Number, isPostMerge, header.Time))

@ -20,7 +20,6 @@ import (
"bytes" "bytes"
"errors" "errors"
"fmt" "fmt"
"math/big"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/signer/core/apitypes" "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. // e.g. https://github.com/ethereum/go-ethereum/issues/16106.
if len(data) == 0 { if len(data) == 0 {
// Prevent sending ether into black hole (show stopper) // 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") 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 // No value submitted at least, critically Warn, but don't blow up

Loading…
Cancel
Save