From b362fc9abd3dc3a46fe749d875fbb63de449d1b7 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Wed, 22 Feb 2017 12:55:58 +0100 Subject: [PATCH] common: remove BytesToBig --- common/big.go | 10 +--------- core/types/bloom9.go | 6 +++--- core/vm/contracts.go | 5 +++-- core/vm/instructions.go | 2 +- core/vm/runtime/runtime_test.go | 4 ++-- 5 files changed, 10 insertions(+), 17 deletions(-) diff --git a/common/big.go b/common/big.go index 935c2df5b7..464f8f2820 100644 --- a/common/big.go +++ b/common/big.go @@ -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 { diff --git a/core/types/bloom9.go b/core/types/bloom9.go index 32aa47a41b..2a37b5977c 100644 --- a/core/types/bloom9.go +++ b/core/types/bloom9.go @@ -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. diff --git a/core/vm/contracts.go b/core/vm/contracts.go index 2793d2aa76..640e9b9bf5 100644 --- a/core/vm/contracts.go +++ b/core/vm/contracts.go @@ -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 diff --git a/core/vm/instructions.go b/core/vm/instructions.go index fb49b5130a..1ce0108fcc 100644 --- a/core/vm/instructions.go +++ b/core/vm/instructions.go @@ -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 diff --git a/core/vm/runtime/runtime_test.go b/core/vm/runtime/runtime_test.go index 8ad74a89ab..fe39e97a01 100644 --- a/core/vm/runtime/runtime_test.go +++ b/core/vm/runtime/runtime_test.go @@ -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) }