common: remove BytesToBig

This commit is contained in:
Felix Lange 2017-02-22 12:55:58 +01:00
parent 746e59c1e2
commit b362fc9abd
5 changed files with 10 additions and 17 deletions

View file

@ -30,16 +30,8 @@ var (
Big257 = big.NewInt(257)
)
// Bytes2Big
func BytesToBig(data []byte) *big.Int {
n := new(big.Int)
n.SetBytes(data)
return n
}
func Bytes2Big(data []byte) *big.Int {
return BytesToBig(data)
return new(big.Int).SetBytes(data)
}
func String2Big(num string) *big.Int {

View file

@ -20,7 +20,6 @@ import (
"fmt"
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/crypto"
)
@ -60,7 +59,7 @@ func (b *Bloom) Add(d *big.Int) {
// Big converts b to a big integer.
func (b Bloom) Big() *big.Int {
return common.Bytes2Big(b[:])
return new(big.Int).SetBytes(b[:])
}
func (b Bloom) Bytes() []byte {
@ -72,7 +71,8 @@ func (b Bloom) Test(test *big.Int) bool {
}
func (b Bloom) TestBytes(test []byte) bool {
return b.Test(common.BytesToBig(test))
return b.Test(new(big.Int).SetBytes(test))
}
// MarshalJSON encodes b as a hex string with 0x prefix.

View file

@ -19,6 +19,7 @@ package vm
import (
"crypto/sha256"
"fmt"
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
@ -69,8 +70,8 @@ func (c *ecrecover) Run(in []byte) []byte {
// "in" is (hash, v, r, s), each 32 bytes
// but for ecrecover we want (r, s, v)
r := common.BytesToBig(in[64:96])
s := common.BytesToBig(in[96:128])
r := new(big.Int).SetBytes(in[64:96])
s := new(big.Int).SetBytes(in[96:128])
v := in[63] - 27
// tighter sig s values in homestead only apply to tx sigs

View file

@ -300,7 +300,7 @@ func opSha3(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Sta
evm.StateDB.AddPreimage(common.BytesToHash(hash), data)
}
stack.push(common.BytesToBig(hash))
stack.push(new(big.Int).SetBytes(hash))
evm.interpreter.intPool.put(offset, size)
return nil, nil

View file

@ -87,7 +87,7 @@ func TestExecute(t *testing.T) {
t.Fatal("didn't expect error", err)
}
num := common.BytesToBig(ret)
num := new(big.Int).SetBytes(ret)
if num.Cmp(big.NewInt(10)) != 0 {
t.Error("Expected 10, got", num)
}
@ -111,7 +111,7 @@ func TestCall(t *testing.T) {
t.Fatal("didn't expect error", err)
}
num := common.BytesToBig(ret)
num := new(big.Int).SetBytes(ret)
if num.Cmp(big.NewInt(10)) != 0 {
t.Error("Expected 10, got", num)
}