diff --git a/core/state/state_object.go b/core/state/state_object.go index 55d416d0a1a7b256c903f7476736670662fe3c92..93ebedc36b22f83d2a57bfc2ce754a067d312311 100644 --- a/core/state/state_object.go +++ b/core/state/state_object.go @@ -99,7 +99,7 @@ type stateObject struct { // empty returns whether the account is considered empty. func (so *stateObject) empty() bool { - return so.data.Nonce == 0 && so.data.Balance.Sign() == 0 && bytes.Equal(so.data.CodeHash[:], emptyCodeHash) + return so.data.Nonce == 0 && so.data.Balance.IsZero() && bytes.Equal(so.data.CodeHash[:], emptyCodeHash) } // newObject creates a state object. diff --git a/core/types/transaction_signing_test.go b/core/types/transaction_signing_test.go index 90d0a67d195a676c7654d5d758c7aa7d420d8c87..15fc5dd7739a97c33ea2b2a45b7ecc6eb62afd73 100644 --- a/core/types/transaction_signing_test.go +++ b/core/types/transaction_signing_test.go @@ -94,7 +94,7 @@ func TestEIP155ChainId(t *testing.T) { t.Error("didn't expect tx to be protected") } - if tx.GetChainID().Sign() != 0 { + if !tx.GetChainID().IsZero() { t.Error("expected chain id to be 0 got", tx.GetChainID()) } } diff --git a/core/vm/evm.go b/core/vm/evm.go index 7ab04d7e8d446cf714bc3d718422780d9babff73..44255555ef2b3cc73b7150583cc4371a39e200ab 100644 --- a/core/vm/evm.go +++ b/core/vm/evm.go @@ -217,7 +217,7 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas return nil, gas, ErrDepth } // Fail if we're trying to transfer more than the available balance - if value.Sign() != 0 && !evm.Context.CanTransfer(evm.IntraBlockState, caller.Address(), value) { + if !value.IsZero() && !evm.Context.CanTransfer(evm.IntraBlockState, caller.Address(), value) { if !bailout { return nil, gas, ErrInsufficientBalance } @@ -240,7 +240,7 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas snapshot = evm.IntraBlockState.Snapshot() ) if !evm.IntraBlockState.Exist(addr) { - if !isPrecompile && evm.ChainRules.IsEIP158 && value.Sign() == 0 { + if !isPrecompile && evm.ChainRules.IsEIP158 && value.IsZero() { return nil, gas, nil } evm.IntraBlockState.CreateAccount(addr, false) diff --git a/core/vm/gas_table.go b/core/vm/gas_table.go index efd5fa7c2986c3c0821f682bc3467981c5a7cc68..2691471974a466c2fc98307acd118efe24fce62c 100644 --- a/core/vm/gas_table.go +++ b/core/vm/gas_table.go @@ -374,7 +374,7 @@ func gasCallCode(evm *EVM, contract *Contract, stack *stack.Stack, mem *Memory, gas uint64 overflow bool ) - if stack.Back(2).Sign() != 0 { + if !stack.Back(2).IsZero() { gas += params.CallValueTransferGas } if gas, overflow = math.SafeAdd(gas, memoryGas); overflow { @@ -431,7 +431,7 @@ func gasSelfdestruct(evm *EVM, contract *Contract, stack *stack.Stack, mem *Memo if evm.ChainRules.IsEIP158 { // if empty and transfers value - if evm.IntraBlockState.Empty(address) && evm.IntraBlockState.GetBalance(contract.Address()).Sign() != 0 { + if evm.IntraBlockState.Empty(address) && !evm.IntraBlockState.GetBalance(contract.Address()).IsZero() { gas += params.CreateBySelfdestructGas } } else if !evm.IntraBlockState.Exist(address) { diff --git a/core/vm/interpreter.go b/core/vm/interpreter.go index 07d0f5231ac6b6a866d6bc7fc25b60788c5fcc1f..a6694c2aaa68d1123928970e1469fca31392c1d9 100644 --- a/core/vm/interpreter.go +++ b/core/vm/interpreter.go @@ -268,7 +268,7 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) ( // for a call operation is the value. Transferring value from one // account to the others means the state is modified and should also // return with an error. - if operation.writes || (op == CALL && locStack.Back(2).Sign() != 0) { + if operation.writes || (op == CALL && !locStack.Back(2).IsZero()) { return nil, ErrWriteProtection } } diff --git a/turbo/trie/stream.go b/turbo/trie/stream.go index 684ab98578276b4e34039f0ae9337aa23801ba75..e2e773821dffa5a35cd02f38c8066d8a79b5b1a7 100644 --- a/turbo/trie/stream.go +++ b/turbo/trie/stream.go @@ -683,7 +683,7 @@ func StreamHash(it *StreamMergeIterator, storagePrefixLen int, hb *HashBuilder, aEmptyRoot = a.IsEmptyRoot() copy(aRoot[:], a.Root[:]) fieldSet = 0 - if a.Balance.Sign() != 0 { + if !a.Balance.IsZero() { fieldSet |= AccountFieldBalanceOnly } if a.Nonce != 0 { diff --git a/turbo/trie/trie_root.go b/turbo/trie/trie_root.go index 273a49eff6cb93d397a483fd1cfba1979c8fde9c..2e3ee867af5c43e06ed9529248f1377d7291781a 100644 --- a/turbo/trie/trie_root.go +++ b/turbo/trie/trie_root.go @@ -617,7 +617,7 @@ func (r *RootHashAggregator) genStructAccount() error { data = &r.hashData } else { r.accData.Balance.Set(&r.a.Balance) - if r.a.Balance.Sign() != 0 { + if !r.a.Balance.IsZero() { r.accData.FieldSet |= AccountFieldBalanceOnly } r.accData.Nonce = r.a.Nonce