core, core/vm: cleaned up compile errors

This commit is contained in:
Jeffrey Wilcke 2017-03-07 17:48:33 +01:00
parent e1598fa996
commit ca6d94b66c
2 changed files with 14 additions and 13 deletions

View file

@ -21,6 +21,7 @@ import (
"math/big" "math/big"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
@ -47,8 +48,8 @@ var PrecompiledContracts = map[common.Address]PrecompiledContract{
// for EIP198. // for EIP198.
var PrecompiledContractsEIP198 = map[common.Address]PrecompiledContract{ var PrecompiledContractsEIP198 = map[common.Address]PrecompiledContract{
common.BytesToAddress([]byte{1}): &ecrecover{}, common.BytesToAddress([]byte{1}): &ecrecover{},
common.BytesToAddress([]byte{2}): &sha256{}, common.BytesToAddress([]byte{2}): &sha256hash{},
common.BytesToAddress([]byte{3}): &ripemd160{}, common.BytesToAddress([]byte{3}): &ripemd160hash{},
common.BytesToAddress([]byte{4}): &dataCopy{}, common.BytesToAddress([]byte{4}): &dataCopy{},
common.BytesToAddress([]byte{5}): &bigModexp{}, common.BytesToAddress([]byte{5}): &bigModexp{},
} }
@ -159,11 +160,11 @@ func (c *bigModexp) RequiredGas(input []byte) uint64 {
input = append(input, make([]byte, 3*32-len(input))...) input = append(input, make([]byte, 3*32-len(input))...)
} }
var ( var (
baseLen = common.BytesToBig(input[:31]) baseLen = new(big.Int).SetBytes(input[:31])
expLen = common.BigMax(common.BytesToBig(input[32:64]), big.NewInt(1)) expLen = math.BigMax(new(big.Int).SetBytes(input[32:64]), big.NewInt(1))
modLen = common.BytesToBig(input[65:97]) modLen = new(big.Int).SetBytes(input[65:97])
) )
x := new(big.Int).Set(common.BigMax(baseLen, modLen)) x := new(big.Int).Set(math.BigMax(baseLen, modLen))
x.Mul(x, x) x.Mul(x, x)
x.Mul(x, expLen) x.Mul(x, expLen)
x.Div(x, new(big.Int).SetUint64(params.QuadCoeffDiv)) x.Div(x, new(big.Int).SetUint64(params.QuadCoeffDiv))
@ -177,28 +178,28 @@ func (c *bigModexp) Run(input []byte) []byte {
} }
// why 32-byte? These values won't fit anyway // why 32-byte? These values won't fit anyway
var ( var (
baseLen = common.BytesToBig(input[:32]).Uint64() baseLen = new(big.Int).SetBytes(input[:32]).Uint64()
expLen = common.BytesToBig(input[32:64]).Uint64() expLen = new(big.Int).SetBytes(input[32:64]).Uint64()
modLen = common.BytesToBig(input[64:96]).Uint64() modLen = new(big.Int).SetBytes(input[64:96]).Uint64()
) )
input = input[96:] input = input[96:]
if uint64(len(input)) < baseLen { if uint64(len(input)) < baseLen {
input = append(input, make([]byte, baseLen-uint64(len(input)))...) input = append(input, make([]byte, baseLen-uint64(len(input)))...)
} }
base := common.BytesToBig(input[:baseLen]) base := new(big.Int).SetBytes(input[:baseLen])
input = input[baseLen:] input = input[baseLen:]
if uint64(len(input)) < expLen { if uint64(len(input)) < expLen {
input = append(input, make([]byte, expLen-uint64(len(input)))...) input = append(input, make([]byte, expLen-uint64(len(input)))...)
} }
exp := common.BytesToBig(input[:expLen]) exp := new(big.Int).SetBytes(input[:expLen])
input = input[expLen:] input = input[expLen:]
if uint64(len(input)) < modLen { if uint64(len(input)) < modLen {
input = append(input, make([]byte, modLen-uint64(len(input)))...) input = append(input, make([]byte, modLen-uint64(len(input)))...)
} }
mod := common.BytesToBig(input[:modLen]) mod := new(big.Int).SetBytes(input[:modLen])
return base.Exp(base, exp, mod).Bytes() return base.Exp(base, exp, mod).Bytes()
} }

View file

@ -37,7 +37,7 @@ type (
func run(evm *EVM, contract *Contract, input []byte) ([]byte, error) { func run(evm *EVM, contract *Contract, input []byte) ([]byte, error) {
if contract.CodeAddr != nil { if contract.CodeAddr != nil {
precompiledContracts := PrecompiledContracts precompiledContracts := PrecompiledContracts
if evm.ChainConfig().IsEIP198(evm.BlockNumber) { if evm.ChainConfig().IsMetropolis(evm.BlockNumber) {
precompiledContracts = PrecompiledContractsEIP198 precompiledContracts = PrecompiledContractsEIP198
} }