2016-04-14 19:18:24 +03:00
|
|
|
// Copyright 2015 The go-ethereum Authors
|
2015-07-18 00:09:36 +03:00
|
|
|
// This file is part of the go-ethereum library.
|
|
|
|
//
|
|
|
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
2015-08-02 03:20:41 +03:00
|
|
|
|
2015-07-18 00:09:36 +03:00
|
|
|
package vm
|
|
|
|
|
|
|
|
import (
|
2017-08-15 11:23:23 +03:00
|
|
|
"errors"
|
2015-10-06 19:16:03 +03:00
|
|
|
"fmt"
|
2015-07-18 00:09:36 +03:00
|
|
|
"math/big"
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
2016-11-02 14:43:15 +03:00
|
|
|
"github.com/ethereum/go-ethereum/common/math"
|
2017-01-05 16:03:50 +03:00
|
|
|
"github.com/ethereum/go-ethereum/core/types"
|
2015-07-18 00:09:36 +03:00
|
|
|
"github.com/ethereum/go-ethereum/crypto"
|
|
|
|
"github.com/ethereum/go-ethereum/params"
|
|
|
|
)
|
|
|
|
|
2017-02-02 00:36:51 +03:00
|
|
|
var (
|
2017-08-16 13:36:48 +03:00
|
|
|
bigZero = new(big.Int)
|
|
|
|
errWriteProtection = errors.New("evm: write protection")
|
|
|
|
errReturnDataOutOfBounds = errors.New("evm: return data out of bounds")
|
2017-08-16 17:09:29 +03:00
|
|
|
errExecutionReverted = errors.New("evm: execution reverted")
|
2017-02-02 00:36:51 +03:00
|
|
|
)
|
2017-01-04 22:17:24 +03:00
|
|
|
|
|
|
|
func opAdd(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
2015-07-18 00:09:36 +03:00
|
|
|
x, y := stack.pop(), stack.pop()
|
common: move big integer math to common/math (#3699)
* common: remove CurrencyToString
Move denomination values to params instead.
* common: delete dead code
* common: move big integer operations to common/math
This commit consolidates all big integer operations into common/math and
adds tests and documentation.
There should be no change in semantics for BigPow, BigMin, BigMax, S256,
U256, Exp and their behaviour is now locked in by tests.
The BigD, BytesToBig and Bytes2Big functions don't provide additional
value, all uses are replaced by new(big.Int).SetBytes().
BigToBytes is now called PaddedBigBytes, its minimum output size
parameter is now specified as the number of bytes instead of bits. The
single use of this function is in the EVM's MSTORE instruction.
Big and String2Big are replaced by ParseBig, which is slightly stricter.
It previously accepted leading zeros for hexadecimal inputs but treated
decimal inputs as octal if a leading zero digit was present.
ParseUint64 is used in places where String2Big was used to decode a
uint64.
The new functions MustParseBig and MustParseUint64 are now used in many
places where parsing errors were previously ignored.
* common: delete unused big integer variables
* accounts/abi: replace uses of BytesToBig with use of encoding/binary
* common: remove BytesToBig
* common: remove Bytes2Big
* common: remove BigTrue
* cmd/utils: add BigFlag and use it for error-checked integer flags
While here, remove environment variable processing for DirectoryFlag
because we don't use it.
* core: add missing error checks in genesis block parser
* common: remove String2Big
* cmd/evm: use utils.BigFlag
* common/math: check for 256 bit overflow in ParseBig
This is supposed to prevent silent overflow/truncation of values in the
genesis block JSON. Without this check, a genesis block that set a
balance larger than 256 bits would lead to weird behaviour in the VM.
* cmd/utils: fixup import
2017-02-27 00:21:51 +03:00
|
|
|
stack.push(math.U256(x.Add(x, y)))
|
2017-01-04 22:17:24 +03:00
|
|
|
|
|
|
|
evm.interpreter.intPool.put(y)
|
|
|
|
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
func opSub(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
2015-07-18 00:09:36 +03:00
|
|
|
x, y := stack.pop(), stack.pop()
|
common: move big integer math to common/math (#3699)
* common: remove CurrencyToString
Move denomination values to params instead.
* common: delete dead code
* common: move big integer operations to common/math
This commit consolidates all big integer operations into common/math and
adds tests and documentation.
There should be no change in semantics for BigPow, BigMin, BigMax, S256,
U256, Exp and their behaviour is now locked in by tests.
The BigD, BytesToBig and Bytes2Big functions don't provide additional
value, all uses are replaced by new(big.Int).SetBytes().
BigToBytes is now called PaddedBigBytes, its minimum output size
parameter is now specified as the number of bytes instead of bits. The
single use of this function is in the EVM's MSTORE instruction.
Big and String2Big are replaced by ParseBig, which is slightly stricter.
It previously accepted leading zeros for hexadecimal inputs but treated
decimal inputs as octal if a leading zero digit was present.
ParseUint64 is used in places where String2Big was used to decode a
uint64.
The new functions MustParseBig and MustParseUint64 are now used in many
places where parsing errors were previously ignored.
* common: delete unused big integer variables
* accounts/abi: replace uses of BytesToBig with use of encoding/binary
* common: remove BytesToBig
* common: remove Bytes2Big
* common: remove BigTrue
* cmd/utils: add BigFlag and use it for error-checked integer flags
While here, remove environment variable processing for DirectoryFlag
because we don't use it.
* core: add missing error checks in genesis block parser
* common: remove String2Big
* cmd/evm: use utils.BigFlag
* common/math: check for 256 bit overflow in ParseBig
This is supposed to prevent silent overflow/truncation of values in the
genesis block JSON. Without this check, a genesis block that set a
balance larger than 256 bits would lead to weird behaviour in the VM.
* cmd/utils: fixup import
2017-02-27 00:21:51 +03:00
|
|
|
stack.push(math.U256(x.Sub(x, y)))
|
2017-01-04 22:17:24 +03:00
|
|
|
|
|
|
|
evm.interpreter.intPool.put(y)
|
|
|
|
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
func opMul(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
2015-07-18 00:09:36 +03:00
|
|
|
x, y := stack.pop(), stack.pop()
|
common: move big integer math to common/math (#3699)
* common: remove CurrencyToString
Move denomination values to params instead.
* common: delete dead code
* common: move big integer operations to common/math
This commit consolidates all big integer operations into common/math and
adds tests and documentation.
There should be no change in semantics for BigPow, BigMin, BigMax, S256,
U256, Exp and their behaviour is now locked in by tests.
The BigD, BytesToBig and Bytes2Big functions don't provide additional
value, all uses are replaced by new(big.Int).SetBytes().
BigToBytes is now called PaddedBigBytes, its minimum output size
parameter is now specified as the number of bytes instead of bits. The
single use of this function is in the EVM's MSTORE instruction.
Big and String2Big are replaced by ParseBig, which is slightly stricter.
It previously accepted leading zeros for hexadecimal inputs but treated
decimal inputs as octal if a leading zero digit was present.
ParseUint64 is used in places where String2Big was used to decode a
uint64.
The new functions MustParseBig and MustParseUint64 are now used in many
places where parsing errors were previously ignored.
* common: delete unused big integer variables
* accounts/abi: replace uses of BytesToBig with use of encoding/binary
* common: remove BytesToBig
* common: remove Bytes2Big
* common: remove BigTrue
* cmd/utils: add BigFlag and use it for error-checked integer flags
While here, remove environment variable processing for DirectoryFlag
because we don't use it.
* core: add missing error checks in genesis block parser
* common: remove String2Big
* cmd/evm: use utils.BigFlag
* common/math: check for 256 bit overflow in ParseBig
This is supposed to prevent silent overflow/truncation of values in the
genesis block JSON. Without this check, a genesis block that set a
balance larger than 256 bits would lead to weird behaviour in the VM.
* cmd/utils: fixup import
2017-02-27 00:21:51 +03:00
|
|
|
stack.push(math.U256(x.Mul(x, y)))
|
2017-01-04 22:17:24 +03:00
|
|
|
|
|
|
|
evm.interpreter.intPool.put(y)
|
|
|
|
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
func opDiv(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
2015-07-18 00:09:36 +03:00
|
|
|
x, y := stack.pop(), stack.pop()
|
2017-02-28 17:09:11 +03:00
|
|
|
if y.Sign() != 0 {
|
common: move big integer math to common/math (#3699)
* common: remove CurrencyToString
Move denomination values to params instead.
* common: delete dead code
* common: move big integer operations to common/math
This commit consolidates all big integer operations into common/math and
adds tests and documentation.
There should be no change in semantics for BigPow, BigMin, BigMax, S256,
U256, Exp and their behaviour is now locked in by tests.
The BigD, BytesToBig and Bytes2Big functions don't provide additional
value, all uses are replaced by new(big.Int).SetBytes().
BigToBytes is now called PaddedBigBytes, its minimum output size
parameter is now specified as the number of bytes instead of bits. The
single use of this function is in the EVM's MSTORE instruction.
Big and String2Big are replaced by ParseBig, which is slightly stricter.
It previously accepted leading zeros for hexadecimal inputs but treated
decimal inputs as octal if a leading zero digit was present.
ParseUint64 is used in places where String2Big was used to decode a
uint64.
The new functions MustParseBig and MustParseUint64 are now used in many
places where parsing errors were previously ignored.
* common: delete unused big integer variables
* accounts/abi: replace uses of BytesToBig with use of encoding/binary
* common: remove BytesToBig
* common: remove Bytes2Big
* common: remove BigTrue
* cmd/utils: add BigFlag and use it for error-checked integer flags
While here, remove environment variable processing for DirectoryFlag
because we don't use it.
* core: add missing error checks in genesis block parser
* common: remove String2Big
* cmd/evm: use utils.BigFlag
* common/math: check for 256 bit overflow in ParseBig
This is supposed to prevent silent overflow/truncation of values in the
genesis block JSON. Without this check, a genesis block that set a
balance larger than 256 bits would lead to weird behaviour in the VM.
* cmd/utils: fixup import
2017-02-27 00:21:51 +03:00
|
|
|
stack.push(math.U256(x.Div(x, y)))
|
2015-08-07 00:06:47 +03:00
|
|
|
} else {
|
|
|
|
stack.push(new(big.Int))
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
2017-01-04 22:17:24 +03:00
|
|
|
|
|
|
|
evm.interpreter.intPool.put(y)
|
|
|
|
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
func opSdiv(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
common: move big integer math to common/math (#3699)
* common: remove CurrencyToString
Move denomination values to params instead.
* common: delete dead code
* common: move big integer operations to common/math
This commit consolidates all big integer operations into common/math and
adds tests and documentation.
There should be no change in semantics for BigPow, BigMin, BigMax, S256,
U256, Exp and their behaviour is now locked in by tests.
The BigD, BytesToBig and Bytes2Big functions don't provide additional
value, all uses are replaced by new(big.Int).SetBytes().
BigToBytes is now called PaddedBigBytes, its minimum output size
parameter is now specified as the number of bytes instead of bits. The
single use of this function is in the EVM's MSTORE instruction.
Big and String2Big are replaced by ParseBig, which is slightly stricter.
It previously accepted leading zeros for hexadecimal inputs but treated
decimal inputs as octal if a leading zero digit was present.
ParseUint64 is used in places where String2Big was used to decode a
uint64.
The new functions MustParseBig and MustParseUint64 are now used in many
places where parsing errors were previously ignored.
* common: delete unused big integer variables
* accounts/abi: replace uses of BytesToBig with use of encoding/binary
* common: remove BytesToBig
* common: remove Bytes2Big
* common: remove BigTrue
* cmd/utils: add BigFlag and use it for error-checked integer flags
While here, remove environment variable processing for DirectoryFlag
because we don't use it.
* core: add missing error checks in genesis block parser
* common: remove String2Big
* cmd/evm: use utils.BigFlag
* common/math: check for 256 bit overflow in ParseBig
This is supposed to prevent silent overflow/truncation of values in the
genesis block JSON. Without this check, a genesis block that set a
balance larger than 256 bits would lead to weird behaviour in the VM.
* cmd/utils: fixup import
2017-02-27 00:21:51 +03:00
|
|
|
x, y := math.S256(stack.pop()), math.S256(stack.pop())
|
2017-02-28 17:09:11 +03:00
|
|
|
if y.Sign() == 0 {
|
2015-08-07 00:06:47 +03:00
|
|
|
stack.push(new(big.Int))
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-07-18 00:09:36 +03:00
|
|
|
} else {
|
|
|
|
n := new(big.Int)
|
2017-02-28 17:09:11 +03:00
|
|
|
if evm.interpreter.intPool.get().Mul(x, y).Sign() < 0 {
|
2015-07-18 00:09:36 +03:00
|
|
|
n.SetInt64(-1)
|
|
|
|
} else {
|
|
|
|
n.SetInt64(1)
|
|
|
|
}
|
|
|
|
|
2015-08-07 00:06:47 +03:00
|
|
|
res := x.Div(x.Abs(x), y.Abs(y))
|
|
|
|
res.Mul(res, n)
|
2015-07-18 00:09:36 +03:00
|
|
|
|
common: move big integer math to common/math (#3699)
* common: remove CurrencyToString
Move denomination values to params instead.
* common: delete dead code
* common: move big integer operations to common/math
This commit consolidates all big integer operations into common/math and
adds tests and documentation.
There should be no change in semantics for BigPow, BigMin, BigMax, S256,
U256, Exp and their behaviour is now locked in by tests.
The BigD, BytesToBig and Bytes2Big functions don't provide additional
value, all uses are replaced by new(big.Int).SetBytes().
BigToBytes is now called PaddedBigBytes, its minimum output size
parameter is now specified as the number of bytes instead of bits. The
single use of this function is in the EVM's MSTORE instruction.
Big and String2Big are replaced by ParseBig, which is slightly stricter.
It previously accepted leading zeros for hexadecimal inputs but treated
decimal inputs as octal if a leading zero digit was present.
ParseUint64 is used in places where String2Big was used to decode a
uint64.
The new functions MustParseBig and MustParseUint64 are now used in many
places where parsing errors were previously ignored.
* common: delete unused big integer variables
* accounts/abi: replace uses of BytesToBig with use of encoding/binary
* common: remove BytesToBig
* common: remove Bytes2Big
* common: remove BigTrue
* cmd/utils: add BigFlag and use it for error-checked integer flags
While here, remove environment variable processing for DirectoryFlag
because we don't use it.
* core: add missing error checks in genesis block parser
* common: remove String2Big
* cmd/evm: use utils.BigFlag
* common/math: check for 256 bit overflow in ParseBig
This is supposed to prevent silent overflow/truncation of values in the
genesis block JSON. Without this check, a genesis block that set a
balance larger than 256 bits would lead to weird behaviour in the VM.
* cmd/utils: fixup import
2017-02-27 00:21:51 +03:00
|
|
|
stack.push(math.U256(res))
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
2017-01-04 22:17:24 +03:00
|
|
|
evm.interpreter.intPool.put(y)
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
func opMod(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
2015-07-18 00:09:36 +03:00
|
|
|
x, y := stack.pop(), stack.pop()
|
2017-02-28 17:09:11 +03:00
|
|
|
if y.Sign() == 0 {
|
2015-08-07 00:06:47 +03:00
|
|
|
stack.push(new(big.Int))
|
2015-07-18 00:09:36 +03:00
|
|
|
} else {
|
common: move big integer math to common/math (#3699)
* common: remove CurrencyToString
Move denomination values to params instead.
* common: delete dead code
* common: move big integer operations to common/math
This commit consolidates all big integer operations into common/math and
adds tests and documentation.
There should be no change in semantics for BigPow, BigMin, BigMax, S256,
U256, Exp and their behaviour is now locked in by tests.
The BigD, BytesToBig and Bytes2Big functions don't provide additional
value, all uses are replaced by new(big.Int).SetBytes().
BigToBytes is now called PaddedBigBytes, its minimum output size
parameter is now specified as the number of bytes instead of bits. The
single use of this function is in the EVM's MSTORE instruction.
Big and String2Big are replaced by ParseBig, which is slightly stricter.
It previously accepted leading zeros for hexadecimal inputs but treated
decimal inputs as octal if a leading zero digit was present.
ParseUint64 is used in places where String2Big was used to decode a
uint64.
The new functions MustParseBig and MustParseUint64 are now used in many
places where parsing errors were previously ignored.
* common: delete unused big integer variables
* accounts/abi: replace uses of BytesToBig with use of encoding/binary
* common: remove BytesToBig
* common: remove Bytes2Big
* common: remove BigTrue
* cmd/utils: add BigFlag and use it for error-checked integer flags
While here, remove environment variable processing for DirectoryFlag
because we don't use it.
* core: add missing error checks in genesis block parser
* common: remove String2Big
* cmd/evm: use utils.BigFlag
* common/math: check for 256 bit overflow in ParseBig
This is supposed to prevent silent overflow/truncation of values in the
genesis block JSON. Without this check, a genesis block that set a
balance larger than 256 bits would lead to weird behaviour in the VM.
* cmd/utils: fixup import
2017-02-27 00:21:51 +03:00
|
|
|
stack.push(math.U256(x.Mod(x, y)))
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
2017-01-04 22:17:24 +03:00
|
|
|
evm.interpreter.intPool.put(y)
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
func opSmod(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
common: move big integer math to common/math (#3699)
* common: remove CurrencyToString
Move denomination values to params instead.
* common: delete dead code
* common: move big integer operations to common/math
This commit consolidates all big integer operations into common/math and
adds tests and documentation.
There should be no change in semantics for BigPow, BigMin, BigMax, S256,
U256, Exp and their behaviour is now locked in by tests.
The BigD, BytesToBig and Bytes2Big functions don't provide additional
value, all uses are replaced by new(big.Int).SetBytes().
BigToBytes is now called PaddedBigBytes, its minimum output size
parameter is now specified as the number of bytes instead of bits. The
single use of this function is in the EVM's MSTORE instruction.
Big and String2Big are replaced by ParseBig, which is slightly stricter.
It previously accepted leading zeros for hexadecimal inputs but treated
decimal inputs as octal if a leading zero digit was present.
ParseUint64 is used in places where String2Big was used to decode a
uint64.
The new functions MustParseBig and MustParseUint64 are now used in many
places where parsing errors were previously ignored.
* common: delete unused big integer variables
* accounts/abi: replace uses of BytesToBig with use of encoding/binary
* common: remove BytesToBig
* common: remove Bytes2Big
* common: remove BigTrue
* cmd/utils: add BigFlag and use it for error-checked integer flags
While here, remove environment variable processing for DirectoryFlag
because we don't use it.
* core: add missing error checks in genesis block parser
* common: remove String2Big
* cmd/evm: use utils.BigFlag
* common/math: check for 256 bit overflow in ParseBig
This is supposed to prevent silent overflow/truncation of values in the
genesis block JSON. Without this check, a genesis block that set a
balance larger than 256 bits would lead to weird behaviour in the VM.
* cmd/utils: fixup import
2017-02-27 00:21:51 +03:00
|
|
|
x, y := math.S256(stack.pop()), math.S256(stack.pop())
|
2015-07-18 00:09:36 +03:00
|
|
|
|
2017-02-28 17:09:11 +03:00
|
|
|
if y.Sign() == 0 {
|
2015-08-07 00:06:47 +03:00
|
|
|
stack.push(new(big.Int))
|
2015-07-18 00:09:36 +03:00
|
|
|
} else {
|
|
|
|
n := new(big.Int)
|
2017-02-28 17:09:11 +03:00
|
|
|
if x.Sign() < 0 {
|
2015-07-18 00:09:36 +03:00
|
|
|
n.SetInt64(-1)
|
|
|
|
} else {
|
|
|
|
n.SetInt64(1)
|
|
|
|
}
|
|
|
|
|
2015-08-07 00:06:47 +03:00
|
|
|
res := x.Mod(x.Abs(x), y.Abs(y))
|
|
|
|
res.Mul(res, n)
|
2015-07-18 00:09:36 +03:00
|
|
|
|
common: move big integer math to common/math (#3699)
* common: remove CurrencyToString
Move denomination values to params instead.
* common: delete dead code
* common: move big integer operations to common/math
This commit consolidates all big integer operations into common/math and
adds tests and documentation.
There should be no change in semantics for BigPow, BigMin, BigMax, S256,
U256, Exp and their behaviour is now locked in by tests.
The BigD, BytesToBig and Bytes2Big functions don't provide additional
value, all uses are replaced by new(big.Int).SetBytes().
BigToBytes is now called PaddedBigBytes, its minimum output size
parameter is now specified as the number of bytes instead of bits. The
single use of this function is in the EVM's MSTORE instruction.
Big and String2Big are replaced by ParseBig, which is slightly stricter.
It previously accepted leading zeros for hexadecimal inputs but treated
decimal inputs as octal if a leading zero digit was present.
ParseUint64 is used in places where String2Big was used to decode a
uint64.
The new functions MustParseBig and MustParseUint64 are now used in many
places where parsing errors were previously ignored.
* common: delete unused big integer variables
* accounts/abi: replace uses of BytesToBig with use of encoding/binary
* common: remove BytesToBig
* common: remove Bytes2Big
* common: remove BigTrue
* cmd/utils: add BigFlag and use it for error-checked integer flags
While here, remove environment variable processing for DirectoryFlag
because we don't use it.
* core: add missing error checks in genesis block parser
* common: remove String2Big
* cmd/evm: use utils.BigFlag
* common/math: check for 256 bit overflow in ParseBig
This is supposed to prevent silent overflow/truncation of values in the
genesis block JSON. Without this check, a genesis block that set a
balance larger than 256 bits would lead to weird behaviour in the VM.
* cmd/utils: fixup import
2017-02-27 00:21:51 +03:00
|
|
|
stack.push(math.U256(res))
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
2017-01-04 22:17:24 +03:00
|
|
|
evm.interpreter.intPool.put(y)
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
func opExp(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
2016-11-02 14:43:15 +03:00
|
|
|
base, exponent := stack.pop(), stack.pop()
|
|
|
|
stack.push(math.Exp(base, exponent))
|
2017-01-04 22:17:24 +03:00
|
|
|
|
|
|
|
evm.interpreter.intPool.put(base, exponent)
|
|
|
|
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
func opSignExtend(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
2015-07-18 00:09:36 +03:00
|
|
|
back := stack.pop()
|
|
|
|
if back.Cmp(big.NewInt(31)) < 0 {
|
|
|
|
bit := uint(back.Uint64()*8 + 7)
|
|
|
|
num := stack.pop()
|
2015-08-07 00:06:47 +03:00
|
|
|
mask := back.Lsh(common.Big1, bit)
|
2015-07-18 00:09:36 +03:00
|
|
|
mask.Sub(mask, common.Big1)
|
common: move big integer math to common/math (#3699)
* common: remove CurrencyToString
Move denomination values to params instead.
* common: delete dead code
* common: move big integer operations to common/math
This commit consolidates all big integer operations into common/math and
adds tests and documentation.
There should be no change in semantics for BigPow, BigMin, BigMax, S256,
U256, Exp and their behaviour is now locked in by tests.
The BigD, BytesToBig and Bytes2Big functions don't provide additional
value, all uses are replaced by new(big.Int).SetBytes().
BigToBytes is now called PaddedBigBytes, its minimum output size
parameter is now specified as the number of bytes instead of bits. The
single use of this function is in the EVM's MSTORE instruction.
Big and String2Big are replaced by ParseBig, which is slightly stricter.
It previously accepted leading zeros for hexadecimal inputs but treated
decimal inputs as octal if a leading zero digit was present.
ParseUint64 is used in places where String2Big was used to decode a
uint64.
The new functions MustParseBig and MustParseUint64 are now used in many
places where parsing errors were previously ignored.
* common: delete unused big integer variables
* accounts/abi: replace uses of BytesToBig with use of encoding/binary
* common: remove BytesToBig
* common: remove Bytes2Big
* common: remove BigTrue
* cmd/utils: add BigFlag and use it for error-checked integer flags
While here, remove environment variable processing for DirectoryFlag
because we don't use it.
* core: add missing error checks in genesis block parser
* common: remove String2Big
* cmd/evm: use utils.BigFlag
* common/math: check for 256 bit overflow in ParseBig
This is supposed to prevent silent overflow/truncation of values in the
genesis block JSON. Without this check, a genesis block that set a
balance larger than 256 bits would lead to weird behaviour in the VM.
* cmd/utils: fixup import
2017-02-27 00:21:51 +03:00
|
|
|
if num.Bit(int(bit)) > 0 {
|
2015-07-18 00:09:36 +03:00
|
|
|
num.Or(num, mask.Not(mask))
|
|
|
|
} else {
|
|
|
|
num.And(num, mask)
|
|
|
|
}
|
|
|
|
|
common: move big integer math to common/math (#3699)
* common: remove CurrencyToString
Move denomination values to params instead.
* common: delete dead code
* common: move big integer operations to common/math
This commit consolidates all big integer operations into common/math and
adds tests and documentation.
There should be no change in semantics for BigPow, BigMin, BigMax, S256,
U256, Exp and their behaviour is now locked in by tests.
The BigD, BytesToBig and Bytes2Big functions don't provide additional
value, all uses are replaced by new(big.Int).SetBytes().
BigToBytes is now called PaddedBigBytes, its minimum output size
parameter is now specified as the number of bytes instead of bits. The
single use of this function is in the EVM's MSTORE instruction.
Big and String2Big are replaced by ParseBig, which is slightly stricter.
It previously accepted leading zeros for hexadecimal inputs but treated
decimal inputs as octal if a leading zero digit was present.
ParseUint64 is used in places where String2Big was used to decode a
uint64.
The new functions MustParseBig and MustParseUint64 are now used in many
places where parsing errors were previously ignored.
* common: delete unused big integer variables
* accounts/abi: replace uses of BytesToBig with use of encoding/binary
* common: remove BytesToBig
* common: remove Bytes2Big
* common: remove BigTrue
* cmd/utils: add BigFlag and use it for error-checked integer flags
While here, remove environment variable processing for DirectoryFlag
because we don't use it.
* core: add missing error checks in genesis block parser
* common: remove String2Big
* cmd/evm: use utils.BigFlag
* common/math: check for 256 bit overflow in ParseBig
This is supposed to prevent silent overflow/truncation of values in the
genesis block JSON. Without this check, a genesis block that set a
balance larger than 256 bits would lead to weird behaviour in the VM.
* cmd/utils: fixup import
2017-02-27 00:21:51 +03:00
|
|
|
stack.push(math.U256(num))
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
2017-01-04 22:17:24 +03:00
|
|
|
|
|
|
|
evm.interpreter.intPool.put(back)
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
func opNot(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
2015-08-07 00:06:47 +03:00
|
|
|
x := stack.pop()
|
common: move big integer math to common/math (#3699)
* common: remove CurrencyToString
Move denomination values to params instead.
* common: delete dead code
* common: move big integer operations to common/math
This commit consolidates all big integer operations into common/math and
adds tests and documentation.
There should be no change in semantics for BigPow, BigMin, BigMax, S256,
U256, Exp and their behaviour is now locked in by tests.
The BigD, BytesToBig and Bytes2Big functions don't provide additional
value, all uses are replaced by new(big.Int).SetBytes().
BigToBytes is now called PaddedBigBytes, its minimum output size
parameter is now specified as the number of bytes instead of bits. The
single use of this function is in the EVM's MSTORE instruction.
Big and String2Big are replaced by ParseBig, which is slightly stricter.
It previously accepted leading zeros for hexadecimal inputs but treated
decimal inputs as octal if a leading zero digit was present.
ParseUint64 is used in places where String2Big was used to decode a
uint64.
The new functions MustParseBig and MustParseUint64 are now used in many
places where parsing errors were previously ignored.
* common: delete unused big integer variables
* accounts/abi: replace uses of BytesToBig with use of encoding/binary
* common: remove BytesToBig
* common: remove Bytes2Big
* common: remove BigTrue
* cmd/utils: add BigFlag and use it for error-checked integer flags
While here, remove environment variable processing for DirectoryFlag
because we don't use it.
* core: add missing error checks in genesis block parser
* common: remove String2Big
* cmd/evm: use utils.BigFlag
* common/math: check for 256 bit overflow in ParseBig
This is supposed to prevent silent overflow/truncation of values in the
genesis block JSON. Without this check, a genesis block that set a
balance larger than 256 bits would lead to weird behaviour in the VM.
* cmd/utils: fixup import
2017-02-27 00:21:51 +03:00
|
|
|
stack.push(math.U256(x.Not(x)))
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
func opLt(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
2015-07-18 00:09:36 +03:00
|
|
|
x, y := stack.pop(), stack.pop()
|
|
|
|
if x.Cmp(y) < 0 {
|
2017-01-04 22:17:24 +03:00
|
|
|
stack.push(evm.interpreter.intPool.get().SetUint64(1))
|
2015-07-18 00:09:36 +03:00
|
|
|
} else {
|
2015-08-07 00:06:47 +03:00
|
|
|
stack.push(new(big.Int))
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
2017-01-04 22:17:24 +03:00
|
|
|
|
|
|
|
evm.interpreter.intPool.put(x, y)
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
func opGt(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
2015-07-18 00:09:36 +03:00
|
|
|
x, y := stack.pop(), stack.pop()
|
|
|
|
if x.Cmp(y) > 0 {
|
2017-01-04 22:17:24 +03:00
|
|
|
stack.push(evm.interpreter.intPool.get().SetUint64(1))
|
2015-07-18 00:09:36 +03:00
|
|
|
} else {
|
2015-08-07 00:06:47 +03:00
|
|
|
stack.push(new(big.Int))
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
2017-01-04 22:17:24 +03:00
|
|
|
|
|
|
|
evm.interpreter.intPool.put(x, y)
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
func opSlt(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
common: move big integer math to common/math (#3699)
* common: remove CurrencyToString
Move denomination values to params instead.
* common: delete dead code
* common: move big integer operations to common/math
This commit consolidates all big integer operations into common/math and
adds tests and documentation.
There should be no change in semantics for BigPow, BigMin, BigMax, S256,
U256, Exp and their behaviour is now locked in by tests.
The BigD, BytesToBig and Bytes2Big functions don't provide additional
value, all uses are replaced by new(big.Int).SetBytes().
BigToBytes is now called PaddedBigBytes, its minimum output size
parameter is now specified as the number of bytes instead of bits. The
single use of this function is in the EVM's MSTORE instruction.
Big and String2Big are replaced by ParseBig, which is slightly stricter.
It previously accepted leading zeros for hexadecimal inputs but treated
decimal inputs as octal if a leading zero digit was present.
ParseUint64 is used in places where String2Big was used to decode a
uint64.
The new functions MustParseBig and MustParseUint64 are now used in many
places where parsing errors were previously ignored.
* common: delete unused big integer variables
* accounts/abi: replace uses of BytesToBig with use of encoding/binary
* common: remove BytesToBig
* common: remove Bytes2Big
* common: remove BigTrue
* cmd/utils: add BigFlag and use it for error-checked integer flags
While here, remove environment variable processing for DirectoryFlag
because we don't use it.
* core: add missing error checks in genesis block parser
* common: remove String2Big
* cmd/evm: use utils.BigFlag
* common/math: check for 256 bit overflow in ParseBig
This is supposed to prevent silent overflow/truncation of values in the
genesis block JSON. Without this check, a genesis block that set a
balance larger than 256 bits would lead to weird behaviour in the VM.
* cmd/utils: fixup import
2017-02-27 00:21:51 +03:00
|
|
|
x, y := math.S256(stack.pop()), math.S256(stack.pop())
|
|
|
|
if x.Cmp(math.S256(y)) < 0 {
|
2017-01-04 22:17:24 +03:00
|
|
|
stack.push(evm.interpreter.intPool.get().SetUint64(1))
|
2015-07-18 00:09:36 +03:00
|
|
|
} else {
|
2015-08-07 00:06:47 +03:00
|
|
|
stack.push(new(big.Int))
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
2017-01-04 22:17:24 +03:00
|
|
|
|
|
|
|
evm.interpreter.intPool.put(x, y)
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
func opSgt(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
common: move big integer math to common/math (#3699)
* common: remove CurrencyToString
Move denomination values to params instead.
* common: delete dead code
* common: move big integer operations to common/math
This commit consolidates all big integer operations into common/math and
adds tests and documentation.
There should be no change in semantics for BigPow, BigMin, BigMax, S256,
U256, Exp and their behaviour is now locked in by tests.
The BigD, BytesToBig and Bytes2Big functions don't provide additional
value, all uses are replaced by new(big.Int).SetBytes().
BigToBytes is now called PaddedBigBytes, its minimum output size
parameter is now specified as the number of bytes instead of bits. The
single use of this function is in the EVM's MSTORE instruction.
Big and String2Big are replaced by ParseBig, which is slightly stricter.
It previously accepted leading zeros for hexadecimal inputs but treated
decimal inputs as octal if a leading zero digit was present.
ParseUint64 is used in places where String2Big was used to decode a
uint64.
The new functions MustParseBig and MustParseUint64 are now used in many
places where parsing errors were previously ignored.
* common: delete unused big integer variables
* accounts/abi: replace uses of BytesToBig with use of encoding/binary
* common: remove BytesToBig
* common: remove Bytes2Big
* common: remove BigTrue
* cmd/utils: add BigFlag and use it for error-checked integer flags
While here, remove environment variable processing for DirectoryFlag
because we don't use it.
* core: add missing error checks in genesis block parser
* common: remove String2Big
* cmd/evm: use utils.BigFlag
* common/math: check for 256 bit overflow in ParseBig
This is supposed to prevent silent overflow/truncation of values in the
genesis block JSON. Without this check, a genesis block that set a
balance larger than 256 bits would lead to weird behaviour in the VM.
* cmd/utils: fixup import
2017-02-27 00:21:51 +03:00
|
|
|
x, y := math.S256(stack.pop()), math.S256(stack.pop())
|
2015-07-18 00:09:36 +03:00
|
|
|
if x.Cmp(y) > 0 {
|
2017-01-04 22:17:24 +03:00
|
|
|
stack.push(evm.interpreter.intPool.get().SetUint64(1))
|
2015-07-18 00:09:36 +03:00
|
|
|
} else {
|
2015-08-07 00:06:47 +03:00
|
|
|
stack.push(new(big.Int))
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
2017-01-04 22:17:24 +03:00
|
|
|
|
|
|
|
evm.interpreter.intPool.put(x, y)
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
func opEq(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
2015-07-18 00:09:36 +03:00
|
|
|
x, y := stack.pop(), stack.pop()
|
|
|
|
if x.Cmp(y) == 0 {
|
2017-01-04 22:17:24 +03:00
|
|
|
stack.push(evm.interpreter.intPool.get().SetUint64(1))
|
2015-07-18 00:09:36 +03:00
|
|
|
} else {
|
2015-08-07 00:06:47 +03:00
|
|
|
stack.push(new(big.Int))
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
2017-01-04 22:17:24 +03:00
|
|
|
|
|
|
|
evm.interpreter.intPool.put(x, y)
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
func opIszero(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
2015-07-18 00:09:36 +03:00
|
|
|
x := stack.pop()
|
2017-02-28 17:09:11 +03:00
|
|
|
if x.Sign() > 0 {
|
2015-08-07 00:06:47 +03:00
|
|
|
stack.push(new(big.Int))
|
2015-07-18 00:09:36 +03:00
|
|
|
} else {
|
2017-01-04 22:17:24 +03:00
|
|
|
stack.push(evm.interpreter.intPool.get().SetUint64(1))
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
2017-01-04 22:17:24 +03:00
|
|
|
|
|
|
|
evm.interpreter.intPool.put(x)
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
func opAnd(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
2015-07-18 00:09:36 +03:00
|
|
|
x, y := stack.pop(), stack.pop()
|
2015-08-07 00:06:47 +03:00
|
|
|
stack.push(x.And(x, y))
|
2017-01-04 22:17:24 +03:00
|
|
|
|
|
|
|
evm.interpreter.intPool.put(y)
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
2017-08-16 13:36:48 +03:00
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
func opOr(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
2015-07-18 00:09:36 +03:00
|
|
|
x, y := stack.pop(), stack.pop()
|
2015-08-07 00:06:47 +03:00
|
|
|
stack.push(x.Or(x, y))
|
2017-01-04 22:17:24 +03:00
|
|
|
|
|
|
|
evm.interpreter.intPool.put(y)
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
2017-08-16 13:36:48 +03:00
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
func opXor(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
2015-07-18 00:09:36 +03:00
|
|
|
x, y := stack.pop(), stack.pop()
|
2015-08-07 00:06:47 +03:00
|
|
|
stack.push(x.Xor(x, y))
|
2017-01-04 22:17:24 +03:00
|
|
|
|
|
|
|
evm.interpreter.intPool.put(y)
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
2017-02-28 17:09:11 +03:00
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
func opByte(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
2017-05-29 00:39:33 +03:00
|
|
|
th, val := stack.pop(), stack.peek()
|
|
|
|
if th.Cmp(common.Big32) < 0 {
|
2017-06-06 19:38:38 +03:00
|
|
|
b := math.Byte(val, 32, int(th.Int64()))
|
|
|
|
val.SetUint64(uint64(b))
|
2015-07-18 00:09:36 +03:00
|
|
|
} else {
|
2017-05-29 00:39:33 +03:00
|
|
|
val.SetUint64(0)
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
2017-05-29 00:39:33 +03:00
|
|
|
evm.interpreter.intPool.put(th)
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
2017-08-16 13:36:48 +03:00
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
func opAddmod(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
2015-08-07 00:06:47 +03:00
|
|
|
x, y, z := stack.pop(), stack.pop(), stack.pop()
|
2017-01-04 22:17:24 +03:00
|
|
|
if z.Cmp(bigZero) > 0 {
|
2015-08-07 00:06:47 +03:00
|
|
|
add := x.Add(x, y)
|
|
|
|
add.Mod(add, z)
|
common: move big integer math to common/math (#3699)
* common: remove CurrencyToString
Move denomination values to params instead.
* common: delete dead code
* common: move big integer operations to common/math
This commit consolidates all big integer operations into common/math and
adds tests and documentation.
There should be no change in semantics for BigPow, BigMin, BigMax, S256,
U256, Exp and their behaviour is now locked in by tests.
The BigD, BytesToBig and Bytes2Big functions don't provide additional
value, all uses are replaced by new(big.Int).SetBytes().
BigToBytes is now called PaddedBigBytes, its minimum output size
parameter is now specified as the number of bytes instead of bits. The
single use of this function is in the EVM's MSTORE instruction.
Big and String2Big are replaced by ParseBig, which is slightly stricter.
It previously accepted leading zeros for hexadecimal inputs but treated
decimal inputs as octal if a leading zero digit was present.
ParseUint64 is used in places where String2Big was used to decode a
uint64.
The new functions MustParseBig and MustParseUint64 are now used in many
places where parsing errors were previously ignored.
* common: delete unused big integer variables
* accounts/abi: replace uses of BytesToBig with use of encoding/binary
* common: remove BytesToBig
* common: remove Bytes2Big
* common: remove BigTrue
* cmd/utils: add BigFlag and use it for error-checked integer flags
While here, remove environment variable processing for DirectoryFlag
because we don't use it.
* core: add missing error checks in genesis block parser
* common: remove String2Big
* cmd/evm: use utils.BigFlag
* common/math: check for 256 bit overflow in ParseBig
This is supposed to prevent silent overflow/truncation of values in the
genesis block JSON. Without this check, a genesis block that set a
balance larger than 256 bits would lead to weird behaviour in the VM.
* cmd/utils: fixup import
2017-02-27 00:21:51 +03:00
|
|
|
stack.push(math.U256(add))
|
2015-08-07 00:06:47 +03:00
|
|
|
} else {
|
|
|
|
stack.push(new(big.Int))
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
2017-01-04 22:17:24 +03:00
|
|
|
|
|
|
|
evm.interpreter.intPool.put(y, z)
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
2017-08-16 13:36:48 +03:00
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
func opMulmod(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
2015-08-07 00:06:47 +03:00
|
|
|
x, y, z := stack.pop(), stack.pop(), stack.pop()
|
2017-01-04 22:17:24 +03:00
|
|
|
if z.Cmp(bigZero) > 0 {
|
2015-08-07 00:06:47 +03:00
|
|
|
mul := x.Mul(x, y)
|
|
|
|
mul.Mod(mul, z)
|
common: move big integer math to common/math (#3699)
* common: remove CurrencyToString
Move denomination values to params instead.
* common: delete dead code
* common: move big integer operations to common/math
This commit consolidates all big integer operations into common/math and
adds tests and documentation.
There should be no change in semantics for BigPow, BigMin, BigMax, S256,
U256, Exp and their behaviour is now locked in by tests.
The BigD, BytesToBig and Bytes2Big functions don't provide additional
value, all uses are replaced by new(big.Int).SetBytes().
BigToBytes is now called PaddedBigBytes, its minimum output size
parameter is now specified as the number of bytes instead of bits. The
single use of this function is in the EVM's MSTORE instruction.
Big and String2Big are replaced by ParseBig, which is slightly stricter.
It previously accepted leading zeros for hexadecimal inputs but treated
decimal inputs as octal if a leading zero digit was present.
ParseUint64 is used in places where String2Big was used to decode a
uint64.
The new functions MustParseBig and MustParseUint64 are now used in many
places where parsing errors were previously ignored.
* common: delete unused big integer variables
* accounts/abi: replace uses of BytesToBig with use of encoding/binary
* common: remove BytesToBig
* common: remove Bytes2Big
* common: remove BigTrue
* cmd/utils: add BigFlag and use it for error-checked integer flags
While here, remove environment variable processing for DirectoryFlag
because we don't use it.
* core: add missing error checks in genesis block parser
* common: remove String2Big
* cmd/evm: use utils.BigFlag
* common/math: check for 256 bit overflow in ParseBig
This is supposed to prevent silent overflow/truncation of values in the
genesis block JSON. Without this check, a genesis block that set a
balance larger than 256 bits would lead to weird behaviour in the VM.
* cmd/utils: fixup import
2017-02-27 00:21:51 +03:00
|
|
|
stack.push(math.U256(mul))
|
2015-08-07 00:06:47 +03:00
|
|
|
} else {
|
|
|
|
stack.push(new(big.Int))
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
2017-01-04 22:17:24 +03:00
|
|
|
|
|
|
|
evm.interpreter.intPool.put(y, z)
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
func opSha3(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
2015-07-18 00:09:36 +03:00
|
|
|
offset, size := stack.pop(), stack.pop()
|
2017-01-17 14:19:50 +03:00
|
|
|
data := memory.Get(offset.Int64(), size.Int64())
|
|
|
|
hash := crypto.Keccak256(data)
|
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
if evm.vmConfig.EnablePreimageRecording {
|
|
|
|
evm.StateDB.AddPreimage(common.BytesToHash(hash), data)
|
2017-01-17 14:19:50 +03:00
|
|
|
}
|
2015-07-18 00:09:36 +03:00
|
|
|
|
common: move big integer math to common/math (#3699)
* common: remove CurrencyToString
Move denomination values to params instead.
* common: delete dead code
* common: move big integer operations to common/math
This commit consolidates all big integer operations into common/math and
adds tests and documentation.
There should be no change in semantics for BigPow, BigMin, BigMax, S256,
U256, Exp and their behaviour is now locked in by tests.
The BigD, BytesToBig and Bytes2Big functions don't provide additional
value, all uses are replaced by new(big.Int).SetBytes().
BigToBytes is now called PaddedBigBytes, its minimum output size
parameter is now specified as the number of bytes instead of bits. The
single use of this function is in the EVM's MSTORE instruction.
Big and String2Big are replaced by ParseBig, which is slightly stricter.
It previously accepted leading zeros for hexadecimal inputs but treated
decimal inputs as octal if a leading zero digit was present.
ParseUint64 is used in places where String2Big was used to decode a
uint64.
The new functions MustParseBig and MustParseUint64 are now used in many
places where parsing errors were previously ignored.
* common: delete unused big integer variables
* accounts/abi: replace uses of BytesToBig with use of encoding/binary
* common: remove BytesToBig
* common: remove Bytes2Big
* common: remove BigTrue
* cmd/utils: add BigFlag and use it for error-checked integer flags
While here, remove environment variable processing for DirectoryFlag
because we don't use it.
* core: add missing error checks in genesis block parser
* common: remove String2Big
* cmd/evm: use utils.BigFlag
* common/math: check for 256 bit overflow in ParseBig
This is supposed to prevent silent overflow/truncation of values in the
genesis block JSON. Without this check, a genesis block that set a
balance larger than 256 bits would lead to weird behaviour in the VM.
* cmd/utils: fixup import
2017-02-27 00:21:51 +03:00
|
|
|
stack.push(new(big.Int).SetBytes(hash))
|
2017-01-04 22:17:24 +03:00
|
|
|
|
|
|
|
evm.interpreter.intPool.put(offset, size)
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
func opAddress(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
common: move big integer math to common/math (#3699)
* common: remove CurrencyToString
Move denomination values to params instead.
* common: delete dead code
* common: move big integer operations to common/math
This commit consolidates all big integer operations into common/math and
adds tests and documentation.
There should be no change in semantics for BigPow, BigMin, BigMax, S256,
U256, Exp and their behaviour is now locked in by tests.
The BigD, BytesToBig and Bytes2Big functions don't provide additional
value, all uses are replaced by new(big.Int).SetBytes().
BigToBytes is now called PaddedBigBytes, its minimum output size
parameter is now specified as the number of bytes instead of bits. The
single use of this function is in the EVM's MSTORE instruction.
Big and String2Big are replaced by ParseBig, which is slightly stricter.
It previously accepted leading zeros for hexadecimal inputs but treated
decimal inputs as octal if a leading zero digit was present.
ParseUint64 is used in places where String2Big was used to decode a
uint64.
The new functions MustParseBig and MustParseUint64 are now used in many
places where parsing errors were previously ignored.
* common: delete unused big integer variables
* accounts/abi: replace uses of BytesToBig with use of encoding/binary
* common: remove BytesToBig
* common: remove Bytes2Big
* common: remove BigTrue
* cmd/utils: add BigFlag and use it for error-checked integer flags
While here, remove environment variable processing for DirectoryFlag
because we don't use it.
* core: add missing error checks in genesis block parser
* common: remove String2Big
* cmd/evm: use utils.BigFlag
* common/math: check for 256 bit overflow in ParseBig
This is supposed to prevent silent overflow/truncation of values in the
genesis block JSON. Without this check, a genesis block that set a
balance larger than 256 bits would lead to weird behaviour in the VM.
* cmd/utils: fixup import
2017-02-27 00:21:51 +03:00
|
|
|
stack.push(contract.Address().Big())
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
func opBalance(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
2015-07-18 00:09:36 +03:00
|
|
|
addr := common.BigToAddress(stack.pop())
|
2017-01-04 22:17:24 +03:00
|
|
|
balance := evm.StateDB.GetBalance(addr)
|
2015-07-18 00:09:36 +03:00
|
|
|
|
|
|
|
stack.push(new(big.Int).Set(balance))
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
func opOrigin(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
|
|
|
stack.push(evm.Origin.Big())
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
func opCaller(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
2016-01-20 00:50:00 +02:00
|
|
|
stack.push(contract.Caller().Big())
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
func opCallValue(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
|
|
|
stack.push(evm.interpreter.intPool.get().Set(contract.value))
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
|
|
|
|
2017-08-16 13:36:48 +03:00
|
|
|
func opCallDataLoad(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
2017-08-14 17:08:49 +03:00
|
|
|
stack.push(new(big.Int).SetBytes(getDataBig(contract.Input, stack.pop(), big32)))
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
|
|
|
|
2017-08-16 13:36:48 +03:00
|
|
|
func opCallDataSize(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
2017-01-04 22:17:24 +03:00
|
|
|
stack.push(evm.interpreter.intPool.get().SetInt64(int64(len(contract.Input))))
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
|
|
|
|
2017-08-16 13:36:48 +03:00
|
|
|
func opCallDataCopy(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
2015-07-18 00:09:36 +03:00
|
|
|
var (
|
2017-08-16 13:36:48 +03:00
|
|
|
memOffset = stack.pop()
|
|
|
|
dataOffset = stack.pop()
|
|
|
|
length = stack.pop()
|
2015-07-18 00:09:36 +03:00
|
|
|
)
|
2017-08-16 13:36:48 +03:00
|
|
|
memory.Set(memOffset.Uint64(), length.Uint64(), getDataBig(contract.Input, dataOffset, length))
|
2017-01-04 22:17:24 +03:00
|
|
|
|
2017-08-16 13:36:48 +03:00
|
|
|
evm.interpreter.intPool.put(memOffset, dataOffset, length)
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
|
|
|
|
2017-08-16 13:07:33 +03:00
|
|
|
func opReturnDataSize(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
|
|
|
stack.push(evm.interpreter.intPool.get().SetUint64(uint64(len(evm.interpreter.returnData))))
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func opReturnDataCopy(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
|
|
|
var (
|
2017-08-16 13:36:48 +03:00
|
|
|
memOffset = stack.pop()
|
|
|
|
dataOffset = stack.pop()
|
|
|
|
length = stack.pop()
|
2017-08-16 13:07:33 +03:00
|
|
|
)
|
2017-08-16 13:36:48 +03:00
|
|
|
defer evm.interpreter.intPool.put(memOffset, dataOffset, length)
|
2017-08-16 13:07:33 +03:00
|
|
|
|
2017-08-16 13:36:48 +03:00
|
|
|
end := new(big.Int).Add(dataOffset, length)
|
|
|
|
if end.BitLen() > 64 || uint64(len(evm.interpreter.returnData)) < end.Uint64() {
|
|
|
|
return nil, errReturnDataOutOfBounds
|
2017-08-16 13:07:33 +03:00
|
|
|
}
|
2017-08-16 13:36:48 +03:00
|
|
|
memory.Set(memOffset.Uint64(), length.Uint64(), evm.interpreter.returnData[dataOffset.Uint64():end.Uint64()])
|
2017-08-16 13:07:33 +03:00
|
|
|
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
func opExtCodeSize(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
|
|
|
a := stack.pop()
|
|
|
|
|
|
|
|
addr := common.BigToAddress(a)
|
|
|
|
a.SetInt64(int64(evm.StateDB.GetCodeSize(addr)))
|
|
|
|
stack.push(a)
|
|
|
|
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
func opCodeSize(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
|
|
|
l := evm.interpreter.intPool.get().SetInt64(int64(len(contract.Code)))
|
2015-07-18 00:09:36 +03:00
|
|
|
stack.push(l)
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
func opCodeCopy(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
2015-07-18 00:09:36 +03:00
|
|
|
var (
|
2017-08-16 13:36:48 +03:00
|
|
|
memOffset = stack.pop()
|
|
|
|
codeOffset = stack.pop()
|
|
|
|
length = stack.pop()
|
2015-07-18 00:09:36 +03:00
|
|
|
)
|
2017-08-16 13:36:48 +03:00
|
|
|
codeCopy := getDataBig(contract.Code, codeOffset, length)
|
|
|
|
memory.Set(memOffset.Uint64(), length.Uint64(), codeCopy)
|
2017-01-04 22:17:24 +03:00
|
|
|
|
2017-08-16 13:36:48 +03:00
|
|
|
evm.interpreter.intPool.put(memOffset, codeOffset, length)
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
func opExtCodeCopy(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
2015-07-18 00:09:36 +03:00
|
|
|
var (
|
2017-08-16 13:36:48 +03:00
|
|
|
addr = common.BigToAddress(stack.pop())
|
|
|
|
memOffset = stack.pop()
|
|
|
|
codeOffset = stack.pop()
|
|
|
|
length = stack.pop()
|
2015-07-18 00:09:36 +03:00
|
|
|
)
|
2017-08-16 13:36:48 +03:00
|
|
|
codeCopy := getDataBig(evm.StateDB.GetCode(addr), codeOffset, length)
|
|
|
|
memory.Set(memOffset.Uint64(), length.Uint64(), codeCopy)
|
2017-01-04 22:17:24 +03:00
|
|
|
|
2017-08-16 13:36:48 +03:00
|
|
|
evm.interpreter.intPool.put(memOffset, codeOffset, length)
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
func opGasprice(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
|
|
|
stack.push(evm.interpreter.intPool.get().Set(evm.GasPrice))
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
func opBlockhash(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
2015-07-18 00:09:36 +03:00
|
|
|
num := stack.pop()
|
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
n := evm.interpreter.intPool.get().Sub(evm.BlockNumber, common.Big257)
|
|
|
|
if num.Cmp(n) > 0 && num.Cmp(evm.BlockNumber) < 0 {
|
|
|
|
stack.push(evm.GetHash(num.Uint64()).Big())
|
2015-07-18 00:09:36 +03:00
|
|
|
} else {
|
2015-08-07 00:06:47 +03:00
|
|
|
stack.push(new(big.Int))
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
2017-01-04 22:17:24 +03:00
|
|
|
|
|
|
|
evm.interpreter.intPool.put(num, n)
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
func opCoinbase(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
|
|
|
stack.push(evm.Coinbase.Big())
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
func opTimestamp(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
common: move big integer math to common/math (#3699)
* common: remove CurrencyToString
Move denomination values to params instead.
* common: delete dead code
* common: move big integer operations to common/math
This commit consolidates all big integer operations into common/math and
adds tests and documentation.
There should be no change in semantics for BigPow, BigMin, BigMax, S256,
U256, Exp and their behaviour is now locked in by tests.
The BigD, BytesToBig and Bytes2Big functions don't provide additional
value, all uses are replaced by new(big.Int).SetBytes().
BigToBytes is now called PaddedBigBytes, its minimum output size
parameter is now specified as the number of bytes instead of bits. The
single use of this function is in the EVM's MSTORE instruction.
Big and String2Big are replaced by ParseBig, which is slightly stricter.
It previously accepted leading zeros for hexadecimal inputs but treated
decimal inputs as octal if a leading zero digit was present.
ParseUint64 is used in places where String2Big was used to decode a
uint64.
The new functions MustParseBig and MustParseUint64 are now used in many
places where parsing errors were previously ignored.
* common: delete unused big integer variables
* accounts/abi: replace uses of BytesToBig with use of encoding/binary
* common: remove BytesToBig
* common: remove Bytes2Big
* common: remove BigTrue
* cmd/utils: add BigFlag and use it for error-checked integer flags
While here, remove environment variable processing for DirectoryFlag
because we don't use it.
* core: add missing error checks in genesis block parser
* common: remove String2Big
* cmd/evm: use utils.BigFlag
* common/math: check for 256 bit overflow in ParseBig
This is supposed to prevent silent overflow/truncation of values in the
genesis block JSON. Without this check, a genesis block that set a
balance larger than 256 bits would lead to weird behaviour in the VM.
* cmd/utils: fixup import
2017-02-27 00:21:51 +03:00
|
|
|
stack.push(math.U256(new(big.Int).Set(evm.Time)))
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
func opNumber(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
common: move big integer math to common/math (#3699)
* common: remove CurrencyToString
Move denomination values to params instead.
* common: delete dead code
* common: move big integer operations to common/math
This commit consolidates all big integer operations into common/math and
adds tests and documentation.
There should be no change in semantics for BigPow, BigMin, BigMax, S256,
U256, Exp and their behaviour is now locked in by tests.
The BigD, BytesToBig and Bytes2Big functions don't provide additional
value, all uses are replaced by new(big.Int).SetBytes().
BigToBytes is now called PaddedBigBytes, its minimum output size
parameter is now specified as the number of bytes instead of bits. The
single use of this function is in the EVM's MSTORE instruction.
Big and String2Big are replaced by ParseBig, which is slightly stricter.
It previously accepted leading zeros for hexadecimal inputs but treated
decimal inputs as octal if a leading zero digit was present.
ParseUint64 is used in places where String2Big was used to decode a
uint64.
The new functions MustParseBig and MustParseUint64 are now used in many
places where parsing errors were previously ignored.
* common: delete unused big integer variables
* accounts/abi: replace uses of BytesToBig with use of encoding/binary
* common: remove BytesToBig
* common: remove Bytes2Big
* common: remove BigTrue
* cmd/utils: add BigFlag and use it for error-checked integer flags
While here, remove environment variable processing for DirectoryFlag
because we don't use it.
* core: add missing error checks in genesis block parser
* common: remove String2Big
* cmd/evm: use utils.BigFlag
* common/math: check for 256 bit overflow in ParseBig
This is supposed to prevent silent overflow/truncation of values in the
genesis block JSON. Without this check, a genesis block that set a
balance larger than 256 bits would lead to weird behaviour in the VM.
* cmd/utils: fixup import
2017-02-27 00:21:51 +03:00
|
|
|
stack.push(math.U256(new(big.Int).Set(evm.BlockNumber)))
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
func opDifficulty(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
common: move big integer math to common/math (#3699)
* common: remove CurrencyToString
Move denomination values to params instead.
* common: delete dead code
* common: move big integer operations to common/math
This commit consolidates all big integer operations into common/math and
adds tests and documentation.
There should be no change in semantics for BigPow, BigMin, BigMax, S256,
U256, Exp and their behaviour is now locked in by tests.
The BigD, BytesToBig and Bytes2Big functions don't provide additional
value, all uses are replaced by new(big.Int).SetBytes().
BigToBytes is now called PaddedBigBytes, its minimum output size
parameter is now specified as the number of bytes instead of bits. The
single use of this function is in the EVM's MSTORE instruction.
Big and String2Big are replaced by ParseBig, which is slightly stricter.
It previously accepted leading zeros for hexadecimal inputs but treated
decimal inputs as octal if a leading zero digit was present.
ParseUint64 is used in places where String2Big was used to decode a
uint64.
The new functions MustParseBig and MustParseUint64 are now used in many
places where parsing errors were previously ignored.
* common: delete unused big integer variables
* accounts/abi: replace uses of BytesToBig with use of encoding/binary
* common: remove BytesToBig
* common: remove Bytes2Big
* common: remove BigTrue
* cmd/utils: add BigFlag and use it for error-checked integer flags
While here, remove environment variable processing for DirectoryFlag
because we don't use it.
* core: add missing error checks in genesis block parser
* common: remove String2Big
* cmd/evm: use utils.BigFlag
* common/math: check for 256 bit overflow in ParseBig
This is supposed to prevent silent overflow/truncation of values in the
genesis block JSON. Without this check, a genesis block that set a
balance larger than 256 bits would lead to weird behaviour in the VM.
* cmd/utils: fixup import
2017-02-27 00:21:51 +03:00
|
|
|
stack.push(math.U256(new(big.Int).Set(evm.Difficulty)))
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
func opGasLimit(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
common: move big integer math to common/math (#3699)
* common: remove CurrencyToString
Move denomination values to params instead.
* common: delete dead code
* common: move big integer operations to common/math
This commit consolidates all big integer operations into common/math and
adds tests and documentation.
There should be no change in semantics for BigPow, BigMin, BigMax, S256,
U256, Exp and their behaviour is now locked in by tests.
The BigD, BytesToBig and Bytes2Big functions don't provide additional
value, all uses are replaced by new(big.Int).SetBytes().
BigToBytes is now called PaddedBigBytes, its minimum output size
parameter is now specified as the number of bytes instead of bits. The
single use of this function is in the EVM's MSTORE instruction.
Big and String2Big are replaced by ParseBig, which is slightly stricter.
It previously accepted leading zeros for hexadecimal inputs but treated
decimal inputs as octal if a leading zero digit was present.
ParseUint64 is used in places where String2Big was used to decode a
uint64.
The new functions MustParseBig and MustParseUint64 are now used in many
places where parsing errors were previously ignored.
* common: delete unused big integer variables
* accounts/abi: replace uses of BytesToBig with use of encoding/binary
* common: remove BytesToBig
* common: remove Bytes2Big
* common: remove BigTrue
* cmd/utils: add BigFlag and use it for error-checked integer flags
While here, remove environment variable processing for DirectoryFlag
because we don't use it.
* core: add missing error checks in genesis block parser
* common: remove String2Big
* cmd/evm: use utils.BigFlag
* common/math: check for 256 bit overflow in ParseBig
This is supposed to prevent silent overflow/truncation of values in the
genesis block JSON. Without this check, a genesis block that set a
balance larger than 256 bits would lead to weird behaviour in the VM.
* cmd/utils: fixup import
2017-02-27 00:21:51 +03:00
|
|
|
stack.push(math.U256(new(big.Int).Set(evm.GasLimit)))
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
func opPop(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
|
|
|
evm.interpreter.intPool.put(stack.pop())
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
func opMload(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
2015-07-18 00:09:36 +03:00
|
|
|
offset := stack.pop()
|
common: move big integer math to common/math (#3699)
* common: remove CurrencyToString
Move denomination values to params instead.
* common: delete dead code
* common: move big integer operations to common/math
This commit consolidates all big integer operations into common/math and
adds tests and documentation.
There should be no change in semantics for BigPow, BigMin, BigMax, S256,
U256, Exp and their behaviour is now locked in by tests.
The BigD, BytesToBig and Bytes2Big functions don't provide additional
value, all uses are replaced by new(big.Int).SetBytes().
BigToBytes is now called PaddedBigBytes, its minimum output size
parameter is now specified as the number of bytes instead of bits. The
single use of this function is in the EVM's MSTORE instruction.
Big and String2Big are replaced by ParseBig, which is slightly stricter.
It previously accepted leading zeros for hexadecimal inputs but treated
decimal inputs as octal if a leading zero digit was present.
ParseUint64 is used in places where String2Big was used to decode a
uint64.
The new functions MustParseBig and MustParseUint64 are now used in many
places where parsing errors were previously ignored.
* common: delete unused big integer variables
* accounts/abi: replace uses of BytesToBig with use of encoding/binary
* common: remove BytesToBig
* common: remove Bytes2Big
* common: remove BigTrue
* cmd/utils: add BigFlag and use it for error-checked integer flags
While here, remove environment variable processing for DirectoryFlag
because we don't use it.
* core: add missing error checks in genesis block parser
* common: remove String2Big
* cmd/evm: use utils.BigFlag
* common/math: check for 256 bit overflow in ParseBig
This is supposed to prevent silent overflow/truncation of values in the
genesis block JSON. Without this check, a genesis block that set a
balance larger than 256 bits would lead to weird behaviour in the VM.
* cmd/utils: fixup import
2017-02-27 00:21:51 +03:00
|
|
|
val := new(big.Int).SetBytes(memory.Get(offset.Int64(), 32))
|
2015-07-18 00:09:36 +03:00
|
|
|
stack.push(val)
|
2017-01-04 22:17:24 +03:00
|
|
|
|
|
|
|
evm.interpreter.intPool.put(offset)
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
func opMstore(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
2015-07-18 00:09:36 +03:00
|
|
|
// pop value of the stack
|
|
|
|
mStart, val := stack.pop(), stack.pop()
|
common: move big integer math to common/math (#3699)
* common: remove CurrencyToString
Move denomination values to params instead.
* common: delete dead code
* common: move big integer operations to common/math
This commit consolidates all big integer operations into common/math and
adds tests and documentation.
There should be no change in semantics for BigPow, BigMin, BigMax, S256,
U256, Exp and their behaviour is now locked in by tests.
The BigD, BytesToBig and Bytes2Big functions don't provide additional
value, all uses are replaced by new(big.Int).SetBytes().
BigToBytes is now called PaddedBigBytes, its minimum output size
parameter is now specified as the number of bytes instead of bits. The
single use of this function is in the EVM's MSTORE instruction.
Big and String2Big are replaced by ParseBig, which is slightly stricter.
It previously accepted leading zeros for hexadecimal inputs but treated
decimal inputs as octal if a leading zero digit was present.
ParseUint64 is used in places where String2Big was used to decode a
uint64.
The new functions MustParseBig and MustParseUint64 are now used in many
places where parsing errors were previously ignored.
* common: delete unused big integer variables
* accounts/abi: replace uses of BytesToBig with use of encoding/binary
* common: remove BytesToBig
* common: remove Bytes2Big
* common: remove BigTrue
* cmd/utils: add BigFlag and use it for error-checked integer flags
While here, remove environment variable processing for DirectoryFlag
because we don't use it.
* core: add missing error checks in genesis block parser
* common: remove String2Big
* cmd/evm: use utils.BigFlag
* common/math: check for 256 bit overflow in ParseBig
This is supposed to prevent silent overflow/truncation of values in the
genesis block JSON. Without this check, a genesis block that set a
balance larger than 256 bits would lead to weird behaviour in the VM.
* cmd/utils: fixup import
2017-02-27 00:21:51 +03:00
|
|
|
memory.Set(mStart.Uint64(), 32, math.PaddedBigBytes(val, 32))
|
2017-01-04 22:17:24 +03:00
|
|
|
|
|
|
|
evm.interpreter.intPool.put(mStart, val)
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
func opMstore8(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
2015-07-18 00:09:36 +03:00
|
|
|
off, val := stack.pop().Int64(), stack.pop().Int64()
|
|
|
|
memory.store[off] = byte(val & 0xff)
|
2017-01-04 22:17:24 +03:00
|
|
|
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
func opSload(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
2015-07-18 00:09:36 +03:00
|
|
|
loc := common.BigToHash(stack.pop())
|
2017-01-04 22:17:24 +03:00
|
|
|
val := evm.StateDB.GetState(contract.Address(), loc).Big()
|
2015-07-18 00:09:36 +03:00
|
|
|
stack.push(val)
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
func opSstore(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
2015-07-18 00:09:36 +03:00
|
|
|
loc := common.BigToHash(stack.pop())
|
|
|
|
val := stack.pop()
|
2017-01-04 22:17:24 +03:00
|
|
|
evm.StateDB.SetState(contract.Address(), loc, common.BigToHash(val))
|
|
|
|
|
|
|
|
evm.interpreter.intPool.put(val)
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
func opJump(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
2017-01-05 13:52:10 +03:00
|
|
|
pos := stack.pop()
|
|
|
|
if !contract.jumpdests.has(contract.CodeHash, contract.Code, pos) {
|
|
|
|
nop := contract.GetOp(pos.Uint64())
|
|
|
|
return nil, fmt.Errorf("invalid jump destination (%v) %v", nop, pos)
|
|
|
|
}
|
|
|
|
*pc = pos.Uint64()
|
2017-01-04 22:17:24 +03:00
|
|
|
|
|
|
|
evm.interpreter.intPool.put(pos)
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-08-30 11:19:10 +03:00
|
|
|
}
|
2017-08-16 13:36:48 +03:00
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
func opJumpi(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
2017-01-05 13:52:10 +03:00
|
|
|
pos, cond := stack.pop(), stack.pop()
|
2017-02-28 17:09:11 +03:00
|
|
|
if cond.Sign() != 0 {
|
2017-01-05 13:52:10 +03:00
|
|
|
if !contract.jumpdests.has(contract.CodeHash, contract.Code, pos) {
|
|
|
|
nop := contract.GetOp(pos.Uint64())
|
|
|
|
return nil, fmt.Errorf("invalid jump destination (%v) %v", nop, pos)
|
|
|
|
}
|
|
|
|
*pc = pos.Uint64()
|
|
|
|
} else {
|
|
|
|
*pc++
|
|
|
|
}
|
2017-01-04 22:17:24 +03:00
|
|
|
|
|
|
|
evm.interpreter.intPool.put(pos, cond)
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-08-30 11:19:10 +03:00
|
|
|
}
|
2017-08-16 13:36:48 +03:00
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
func opJumpdest(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-08-30 11:19:10 +03:00
|
|
|
}
|
2015-07-18 00:09:36 +03:00
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
func opPc(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
|
|
|
stack.push(evm.interpreter.intPool.get().SetUint64(*pc))
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
func opMsize(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
|
|
|
stack.push(evm.interpreter.intPool.get().SetInt64(int64(memory.Len())))
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
func opGas(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
|
|
|
stack.push(evm.interpreter.intPool.get().SetUint64(contract.Gas))
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
func opCreate(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
2016-01-20 00:50:00 +02:00
|
|
|
var (
|
|
|
|
value = stack.pop()
|
|
|
|
offset, size = stack.pop(), stack.pop()
|
|
|
|
input = memory.Get(offset.Int64(), size.Int64())
|
2017-01-04 22:17:24 +03:00
|
|
|
gas = contract.Gas
|
2016-01-20 00:50:00 +02:00
|
|
|
)
|
2017-01-04 22:17:24 +03:00
|
|
|
if evm.ChainConfig().IsEIP150(evm.BlockNumber) {
|
|
|
|
gas -= gas / 64
|
2016-10-08 01:23:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
contract.UseGas(gas)
|
2017-08-16 17:09:29 +03:00
|
|
|
res, addr, returnGas, suberr := evm.Create(contract, input, gas, value)
|
2016-01-20 00:50:00 +02:00
|
|
|
// Push item on the stack based on the returned error. If the ruleset is
|
|
|
|
// homestead we must check for CodeStoreOutOfGasError (homestead only
|
|
|
|
// rule) and treat as an error, if the ruleset is frontier we must
|
|
|
|
// ignore this error and pretend the operation was successful.
|
2017-01-04 22:17:24 +03:00
|
|
|
if evm.ChainConfig().IsHomestead(evm.BlockNumber) && suberr == ErrCodeStoreOutOfGas {
|
2016-01-20 00:50:00 +02:00
|
|
|
stack.push(new(big.Int))
|
2017-01-05 13:52:10 +03:00
|
|
|
} else if suberr != nil && suberr != ErrCodeStoreOutOfGas {
|
2016-01-20 00:50:00 +02:00
|
|
|
stack.push(new(big.Int))
|
|
|
|
} else {
|
|
|
|
stack.push(addr.Big())
|
|
|
|
}
|
2017-01-04 22:17:24 +03:00
|
|
|
contract.Gas += returnGas
|
|
|
|
evm.interpreter.intPool.put(value, offset, size)
|
|
|
|
|
2017-08-16 17:09:29 +03:00
|
|
|
if suberr == errExecutionReverted {
|
|
|
|
return res, nil
|
|
|
|
}
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
func opCall(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
|
|
|
gas := stack.pop().Uint64()
|
2015-07-18 00:09:36 +03:00
|
|
|
// pop gas and value of the stack.
|
|
|
|
addr, value := stack.pop(), stack.pop()
|
common: move big integer math to common/math (#3699)
* common: remove CurrencyToString
Move denomination values to params instead.
* common: delete dead code
* common: move big integer operations to common/math
This commit consolidates all big integer operations into common/math and
adds tests and documentation.
There should be no change in semantics for BigPow, BigMin, BigMax, S256,
U256, Exp and their behaviour is now locked in by tests.
The BigD, BytesToBig and Bytes2Big functions don't provide additional
value, all uses are replaced by new(big.Int).SetBytes().
BigToBytes is now called PaddedBigBytes, its minimum output size
parameter is now specified as the number of bytes instead of bits. The
single use of this function is in the EVM's MSTORE instruction.
Big and String2Big are replaced by ParseBig, which is slightly stricter.
It previously accepted leading zeros for hexadecimal inputs but treated
decimal inputs as octal if a leading zero digit was present.
ParseUint64 is used in places where String2Big was used to decode a
uint64.
The new functions MustParseBig and MustParseUint64 are now used in many
places where parsing errors were previously ignored.
* common: delete unused big integer variables
* accounts/abi: replace uses of BytesToBig with use of encoding/binary
* common: remove BytesToBig
* common: remove Bytes2Big
* common: remove BigTrue
* cmd/utils: add BigFlag and use it for error-checked integer flags
While here, remove environment variable processing for DirectoryFlag
because we don't use it.
* core: add missing error checks in genesis block parser
* common: remove String2Big
* cmd/evm: use utils.BigFlag
* common/math: check for 256 bit overflow in ParseBig
This is supposed to prevent silent overflow/truncation of values in the
genesis block JSON. Without this check, a genesis block that set a
balance larger than 256 bits would lead to weird behaviour in the VM.
* cmd/utils: fixup import
2017-02-27 00:21:51 +03:00
|
|
|
value = math.U256(value)
|
2015-07-18 00:09:36 +03:00
|
|
|
// pop input size and offset
|
|
|
|
inOffset, inSize := stack.pop(), stack.pop()
|
|
|
|
// pop return size and offset
|
|
|
|
retOffset, retSize := stack.pop(), stack.pop()
|
|
|
|
|
|
|
|
address := common.BigToAddress(addr)
|
|
|
|
|
|
|
|
// Get the arguments from the memory
|
|
|
|
args := memory.Get(inOffset.Int64(), inSize.Int64())
|
|
|
|
|
2017-02-28 17:09:11 +03:00
|
|
|
if value.Sign() != 0 {
|
2017-01-04 22:17:24 +03:00
|
|
|
gas += params.CallStipend
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
ret, returnGas, err := evm.Call(contract, address, args, gas, value)
|
2015-07-18 00:09:36 +03:00
|
|
|
if err != nil {
|
2015-08-07 00:06:47 +03:00
|
|
|
stack.push(new(big.Int))
|
2015-07-18 00:09:36 +03:00
|
|
|
} else {
|
2015-08-07 00:06:47 +03:00
|
|
|
stack.push(big.NewInt(1))
|
2017-08-16 17:09:29 +03:00
|
|
|
}
|
|
|
|
if err == nil || err == errExecutionReverted {
|
2015-07-18 00:09:36 +03:00
|
|
|
memory.Set(retOffset.Uint64(), retSize.Uint64(), ret)
|
|
|
|
}
|
2017-01-04 22:17:24 +03:00
|
|
|
contract.Gas += returnGas
|
|
|
|
|
|
|
|
evm.interpreter.intPool.put(addr, value, inOffset, inSize, retOffset, retSize)
|
2017-02-02 00:36:51 +03:00
|
|
|
return ret, nil
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
func opCallCode(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
|
|
|
gas := stack.pop().Uint64()
|
2015-07-18 00:09:36 +03:00
|
|
|
// pop gas and value of the stack.
|
|
|
|
addr, value := stack.pop(), stack.pop()
|
common: move big integer math to common/math (#3699)
* common: remove CurrencyToString
Move denomination values to params instead.
* common: delete dead code
* common: move big integer operations to common/math
This commit consolidates all big integer operations into common/math and
adds tests and documentation.
There should be no change in semantics for BigPow, BigMin, BigMax, S256,
U256, Exp and their behaviour is now locked in by tests.
The BigD, BytesToBig and Bytes2Big functions don't provide additional
value, all uses are replaced by new(big.Int).SetBytes().
BigToBytes is now called PaddedBigBytes, its minimum output size
parameter is now specified as the number of bytes instead of bits. The
single use of this function is in the EVM's MSTORE instruction.
Big and String2Big are replaced by ParseBig, which is slightly stricter.
It previously accepted leading zeros for hexadecimal inputs but treated
decimal inputs as octal if a leading zero digit was present.
ParseUint64 is used in places where String2Big was used to decode a
uint64.
The new functions MustParseBig and MustParseUint64 are now used in many
places where parsing errors were previously ignored.
* common: delete unused big integer variables
* accounts/abi: replace uses of BytesToBig with use of encoding/binary
* common: remove BytesToBig
* common: remove Bytes2Big
* common: remove BigTrue
* cmd/utils: add BigFlag and use it for error-checked integer flags
While here, remove environment variable processing for DirectoryFlag
because we don't use it.
* core: add missing error checks in genesis block parser
* common: remove String2Big
* cmd/evm: use utils.BigFlag
* common/math: check for 256 bit overflow in ParseBig
This is supposed to prevent silent overflow/truncation of values in the
genesis block JSON. Without this check, a genesis block that set a
balance larger than 256 bits would lead to weird behaviour in the VM.
* cmd/utils: fixup import
2017-02-27 00:21:51 +03:00
|
|
|
value = math.U256(value)
|
2015-07-18 00:09:36 +03:00
|
|
|
// pop input size and offset
|
|
|
|
inOffset, inSize := stack.pop(), stack.pop()
|
|
|
|
// pop return size and offset
|
|
|
|
retOffset, retSize := stack.pop(), stack.pop()
|
|
|
|
|
|
|
|
address := common.BigToAddress(addr)
|
|
|
|
|
|
|
|
// Get the arguments from the memory
|
|
|
|
args := memory.Get(inOffset.Int64(), inSize.Int64())
|
|
|
|
|
2017-02-28 17:09:11 +03:00
|
|
|
if value.Sign() != 0 {
|
2017-01-04 22:17:24 +03:00
|
|
|
gas += params.CallStipend
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
ret, returnGas, err := evm.CallCode(contract, address, args, gas, value)
|
2015-07-18 00:09:36 +03:00
|
|
|
if err != nil {
|
2015-08-07 00:06:47 +03:00
|
|
|
stack.push(new(big.Int))
|
2015-07-18 00:09:36 +03:00
|
|
|
} else {
|
2015-08-07 00:06:47 +03:00
|
|
|
stack.push(big.NewInt(1))
|
2017-08-16 17:09:29 +03:00
|
|
|
}
|
|
|
|
if err == nil || err == errExecutionReverted {
|
2015-07-18 00:09:36 +03:00
|
|
|
memory.Set(retOffset.Uint64(), retSize.Uint64(), ret)
|
|
|
|
}
|
2017-01-04 22:17:24 +03:00
|
|
|
contract.Gas += returnGas
|
|
|
|
|
|
|
|
evm.interpreter.intPool.put(addr, value, inOffset, inSize, retOffset, retSize)
|
2017-02-02 00:36:51 +03:00
|
|
|
return ret, nil
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
func opDelegateCall(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
|
|
|
gas, to, inOffset, inSize, outOffset, outSize := stack.pop().Uint64(), stack.pop(), stack.pop(), stack.pop(), stack.pop(), stack.pop()
|
2015-11-27 16:40:29 +02:00
|
|
|
|
|
|
|
toAddr := common.BigToAddress(to)
|
|
|
|
args := memory.Get(inOffset.Int64(), inSize.Int64())
|
2017-01-04 22:17:24 +03:00
|
|
|
|
|
|
|
ret, returnGas, err := evm.DelegateCall(contract, toAddr, args, gas)
|
2015-11-27 16:40:29 +02:00
|
|
|
if err != nil {
|
|
|
|
stack.push(new(big.Int))
|
|
|
|
} else {
|
|
|
|
stack.push(big.NewInt(1))
|
2017-08-16 17:09:29 +03:00
|
|
|
}
|
|
|
|
if err == nil || err == errExecutionReverted {
|
2015-11-27 16:40:29 +02:00
|
|
|
memory.Set(outOffset.Uint64(), outSize.Uint64(), ret)
|
|
|
|
}
|
2017-01-04 22:17:24 +03:00
|
|
|
contract.Gas += returnGas
|
|
|
|
|
|
|
|
evm.interpreter.intPool.put(to, inOffset, inSize, outOffset, outSize)
|
2017-02-02 00:36:51 +03:00
|
|
|
return ret, nil
|
2015-11-27 16:40:29 +02:00
|
|
|
}
|
|
|
|
|
2017-08-15 11:23:23 +03:00
|
|
|
func opStaticCall(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
|
|
|
// pop gas
|
|
|
|
gas := stack.pop().Uint64()
|
|
|
|
// pop address
|
|
|
|
addr := stack.pop()
|
|
|
|
// pop input size and offset
|
|
|
|
inOffset, inSize := stack.pop(), stack.pop()
|
|
|
|
// pop return size and offset
|
|
|
|
retOffset, retSize := stack.pop(), stack.pop()
|
|
|
|
|
|
|
|
address := common.BigToAddress(addr)
|
|
|
|
|
|
|
|
// Get the arguments from the memory
|
|
|
|
args := memory.Get(inOffset.Int64(), inSize.Int64())
|
|
|
|
|
|
|
|
ret, returnGas, err := evm.StaticCall(contract, address, args, gas)
|
|
|
|
if err != nil {
|
|
|
|
stack.push(new(big.Int))
|
|
|
|
} else {
|
|
|
|
stack.push(big.NewInt(1))
|
2017-08-16 17:09:29 +03:00
|
|
|
}
|
|
|
|
if err == nil || err == errExecutionReverted {
|
2017-08-15 11:23:23 +03:00
|
|
|
memory.Set(retOffset.Uint64(), retSize.Uint64(), ret)
|
|
|
|
}
|
|
|
|
contract.Gas += returnGas
|
|
|
|
|
|
|
|
evm.interpreter.intPool.put(addr, inOffset, inSize, retOffset, retSize)
|
|
|
|
return ret, nil
|
|
|
|
}
|
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
func opReturn(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
2017-01-05 13:52:10 +03:00
|
|
|
offset, size := stack.pop(), stack.pop()
|
|
|
|
ret := memory.GetPtr(offset.Int64(), size.Int64())
|
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
evm.interpreter.intPool.put(offset, size)
|
2017-08-16 15:32:59 +03:00
|
|
|
return ret, nil
|
|
|
|
}
|
2017-02-02 00:36:51 +03:00
|
|
|
|
2017-08-16 15:32:59 +03:00
|
|
|
func opRevert(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
|
|
|
offset, size := stack.pop(), stack.pop()
|
|
|
|
ret := memory.GetPtr(offset.Int64(), size.Int64())
|
|
|
|
|
|
|
|
evm.interpreter.intPool.put(offset, size)
|
2017-01-05 13:52:10 +03:00
|
|
|
return ret, nil
|
2015-08-30 11:19:10 +03:00
|
|
|
}
|
2017-01-05 13:52:10 +03:00
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
func opStop(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-08-30 11:19:10 +03:00
|
|
|
}
|
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
func opSuicide(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
|
|
|
balance := evm.StateDB.GetBalance(contract.Address())
|
|
|
|
evm.StateDB.AddBalance(common.BigToAddress(stack.pop()), balance)
|
2015-08-30 11:19:10 +03:00
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
evm.StateDB.Suicide(contract.Address())
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-08-30 11:19:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// following functions are used by the instruction jump table
|
|
|
|
|
|
|
|
// make log instruction function
|
2017-01-05 13:52:10 +03:00
|
|
|
func makeLog(size int) executionFunc {
|
2017-01-04 22:17:24 +03:00
|
|
|
return func(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
2015-08-30 11:19:10 +03:00
|
|
|
topics := make([]common.Hash, size)
|
|
|
|
mStart, mSize := stack.pop(), stack.pop()
|
|
|
|
for i := 0; i < size; i++ {
|
|
|
|
topics[i] = common.BigToHash(stack.pop())
|
|
|
|
}
|
|
|
|
|
|
|
|
d := memory.Get(mStart.Int64(), mSize.Int64())
|
2017-01-04 22:17:24 +03:00
|
|
|
evm.StateDB.AddLog(&types.Log{
|
2017-01-05 16:03:50 +03:00
|
|
|
Address: contract.Address(),
|
|
|
|
Topics: topics,
|
|
|
|
Data: d,
|
|
|
|
// This is a non-consensus field, but assigned here because
|
|
|
|
// core/state doesn't know the current block number.
|
2017-01-04 22:17:24 +03:00
|
|
|
BlockNumber: evm.BlockNumber.Uint64(),
|
2017-01-05 16:03:50 +03:00
|
|
|
})
|
2017-01-04 22:17:24 +03:00
|
|
|
|
|
|
|
evm.interpreter.intPool.put(mStart, mSize)
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-08-30 11:19:10 +03:00
|
|
|
}
|
|
|
|
}
|
2015-07-18 00:09:36 +03:00
|
|
|
|
2015-08-30 11:19:10 +03:00
|
|
|
// make push instruction function
|
2017-05-23 11:39:53 +03:00
|
|
|
func makePush(size uint64, pushByteSize int) executionFunc {
|
2017-01-04 22:17:24 +03:00
|
|
|
return func(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
2017-05-23 11:39:53 +03:00
|
|
|
codeLen := len(contract.Code)
|
|
|
|
|
|
|
|
startMin := codeLen
|
|
|
|
if int(*pc+1) < startMin {
|
|
|
|
startMin = int(*pc + 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
endMin := codeLen
|
|
|
|
if startMin+pushByteSize < endMin {
|
|
|
|
endMin = startMin + pushByteSize
|
|
|
|
}
|
|
|
|
|
|
|
|
integer := evm.interpreter.intPool.get()
|
|
|
|
stack.push(integer.SetBytes(common.RightPadBytes(contract.Code[startMin:endMin], pushByteSize)))
|
|
|
|
|
2015-08-30 11:19:10 +03:00
|
|
|
*pc += size
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-08-30 11:19:10 +03:00
|
|
|
}
|
|
|
|
}
|
2015-07-18 00:09:36 +03:00
|
|
|
|
2015-08-30 11:19:10 +03:00
|
|
|
// make push instruction function
|
2017-01-05 13:52:10 +03:00
|
|
|
func makeDup(size int64) executionFunc {
|
2017-01-04 22:17:24 +03:00
|
|
|
return func(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
2017-05-23 11:52:11 +03:00
|
|
|
stack.dup(evm.interpreter.intPool, int(size))
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-08-30 11:19:10 +03:00
|
|
|
}
|
|
|
|
}
|
2015-07-18 00:09:36 +03:00
|
|
|
|
2015-08-30 11:19:10 +03:00
|
|
|
// make swap instruction function
|
2017-01-05 13:52:10 +03:00
|
|
|
func makeSwap(size int64) executionFunc {
|
2015-08-30 11:19:10 +03:00
|
|
|
// switch n + 1 otherwise n would be swapped with n
|
|
|
|
size += 1
|
2017-01-04 22:17:24 +03:00
|
|
|
return func(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
2015-08-30 11:19:10 +03:00
|
|
|
stack.swap(int(size))
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-08-30 11:19:10 +03:00
|
|
|
}
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|