diff --git a/common/big.go b/common/big.go index 464f8f2820..c813632618 100644 --- a/common/big.go +++ b/common/big.go @@ -30,10 +30,6 @@ var ( Big257 = big.NewInt(257) ) -func Bytes2Big(data []byte) *big.Int { - return new(big.Int).SetBytes(data) -} - func String2Big(num string) *big.Int { n := new(big.Int) n.SetString(num, 0) diff --git a/common/types.go b/common/types.go index 8a456e965e..d38ea73064 100644 --- a/common/types.go +++ b/common/types.go @@ -52,7 +52,7 @@ func HexToHash(s string) Hash { return BytesToHash(FromHex(s)) } // Get the string representation of the underlying hash func (h Hash) Str() string { return string(h[:]) } func (h Hash) Bytes() []byte { return h[:] } -func (h Hash) Big() *big.Int { return Bytes2Big(h[:]) } +func (h Hash) Big() *big.Int { return new(big.Int).SetBytes(h[:]) } func (h Hash) Hex() string { return hexutil.Encode(h[:]) } // UnmarshalJSON parses a hash in its hex from to a hash. @@ -122,7 +122,7 @@ func IsHexAddress(s string) bool { // Get the string representation of the underlying address func (a Address) Str() string { return string(a[:]) } func (a Address) Bytes() []byte { return a[:] } -func (a Address) Big() *big.Int { return Bytes2Big(a[:]) } +func (a Address) Big() *big.Int { return new(big.Int).SetBytes(a[:]) } func (a Address) Hash() Hash { return BytesToHash(a[:]) } func (a Address) Hex() string { return hexutil.Encode(a[:]) } diff --git a/common/types_template.go b/common/types_template.go index 8048f9cc3f..9a8f29977b 100644 --- a/common/types_template.go +++ b/common/types_template.go @@ -37,7 +37,7 @@ func HexTo_N_(s string) _N_ { return BytesTo_N_(FromHex(s)) } // Get the string representation of the underlying hash func (h _N_) Str() string { return string(h[:]) } func (h _N_) Bytes() []byte { return h[:] } -func (h _N_) Big() *big.Int { return Bytes2Big(h[:]) } +func (h _N_) Big() *big.Int { return new(big.Int).SetBytes(h[:]) } func (h _N_) Hex() string { return "0x" + Bytes2Hex(h[:]) } // Sets the hash to the value of b. If b is larger than len(h) it will panic diff --git a/core/vm/common.go b/core/vm/common.go index f6a30bd15e..ef40c4a957 100644 --- a/core/vm/common.go +++ b/core/vm/common.go @@ -56,3 +56,12 @@ func toWordSize(size uint64) uint64 { return (size + 31) / 32 } + +func allZero(b []byte) bool { + for _, byte := range b { + if byte != 0 { + return false + } + } + return true +} diff --git a/core/vm/contracts.go b/core/vm/contracts.go index 640e9b9bf5..0479adfda0 100644 --- a/core/vm/contracts.go +++ b/core/vm/contracts.go @@ -75,8 +75,8 @@ func (c *ecrecover) Run(in []byte) []byte { v := in[63] - 27 // tighter sig s values in homestead only apply to tx sigs - if common.Bytes2Big(in[32:63]).BitLen() > 0 || !crypto.ValidateSignatureValues(v, r, s, false) { - log.Trace(fmt.Sprintf("ECRECOVER error: v, r or s value invalid")) + if !allZero(in[32:63]) || !crypto.ValidateSignatureValues(v, r, s, false) { + log.Trace("ECRECOVER error: v, r or s value invalid") return nil } // v needs to be at the end for libsecp256k1 diff --git a/core/vm/instructions.go b/core/vm/instructions.go index 1ce0108fcc..79f71ceaa9 100644 --- a/core/vm/instructions.go +++ b/core/vm/instructions.go @@ -307,7 +307,7 @@ func opSha3(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Sta } func opAddress(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { - stack.push(common.Bytes2Big(contract.Address().Bytes())) + stack.push(contract.Address().Big()) return nil, nil } @@ -335,7 +335,7 @@ func opCallValue(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack } func opCalldataLoad(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { - stack.push(common.Bytes2Big(getData(contract.Input, stack.pop(), common.Big32))) + stack.push(new(big.Int).SetBytes(getData(contract.Input, stack.pop(), common.Big32))) return nil, nil } @@ -711,7 +711,7 @@ func makeLog(size int) executionFunc { func makePush(size uint64, bsize *big.Int) executionFunc { return func(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) { byts := getData(contract.Code, evm.interpreter.intPool.get().SetUint64(*pc+1), bsize) - stack.push(common.Bytes2Big(byts)) + stack.push(new(big.Int).SetBytes(byts)) *pc += size return nil, nil }