mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 06:36:43 +00:00
common: remove Bytes2Big
This commit is contained in:
parent
b362fc9abd
commit
a894fe621e
6 changed files with 17 additions and 12 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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[:]) }
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue