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 (
|
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-01-04 22:17:24 +03:00
|
|
|
var bigZero = new(big.Int)
|
|
|
|
|
|
|
|
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()
|
2015-08-07 00:06:47 +03:00
|
|
|
stack.push(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()
|
2015-08-07 00:06:47 +03:00
|
|
|
stack.push(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()
|
2015-08-07 00:06:47 +03:00
|
|
|
stack.push(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()
|
|
|
|
if y.Cmp(common.Big0) != 0 {
|
2015-08-07 00:06:47 +03:00
|
|
|
stack.push(U256(x.Div(x, y)))
|
|
|
|
} 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) {
|
2015-07-18 00:09:36 +03:00
|
|
|
x, y := S256(stack.pop()), S256(stack.pop())
|
|
|
|
if y.Cmp(common.Big0) == 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-01-04 22:17:24 +03:00
|
|
|
if evm.interpreter.intPool.get().Mul(x, y).Cmp(common.Big0) < 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
|
|
|
|
2015-08-07 00:06:47 +03:00
|
|
|
stack.push(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()
|
|
|
|
if y.Cmp(common.Big0) == 0 {
|
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(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) {
|
2015-07-18 00:09:36 +03:00
|
|
|
x, y := S256(stack.pop()), S256(stack.pop())
|
|
|
|
|
|
|
|
if y.Cmp(common.Big0) == 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)
|
|
|
|
if x.Cmp(common.Big0) < 0 {
|
|
|
|
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
|
|
|
|
2015-08-07 00:06:47 +03:00
|
|
|
stack.push(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)
|
|
|
|
if common.BitTest(num, int(bit)) {
|
|
|
|
num.Or(num, mask.Not(mask))
|
|
|
|
} else {
|
|
|
|
num.And(num, mask)
|
|
|
|
}
|
|
|
|
|
2015-08-07 00:06:47 +03:00
|
|
|
stack.push(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()
|
|
|
|
stack.push(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) {
|
2015-07-18 00:09:36 +03:00
|
|
|
x, y := S256(stack.pop()), S256(stack.pop())
|
|
|
|
if x.Cmp(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) {
|
2015-07-18 00:09:36 +03:00
|
|
|
x, y := S256(stack.pop()), S256(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 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()
|
2015-08-07 00:06:47 +03:00
|
|
|
if x.Cmp(common.Big0) > 0 {
|
|
|
|
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-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-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-01-04 22:17:24 +03:00
|
|
|
func opByte(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
2015-07-18 00:09:36 +03:00
|
|
|
th, val := stack.pop(), stack.pop()
|
|
|
|
if th.Cmp(big.NewInt(32)) < 0 {
|
2017-01-04 22:17:24 +03:00
|
|
|
byte := evm.interpreter.intPool.get().SetInt64(int64(common.LeftPadBytes(val.Bytes(), 32)[th.Int64()]))
|
2015-08-07 00:06:47 +03:00
|
|
|
stack.push(byte)
|
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(th, 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 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)
|
|
|
|
stack.push(U256(add))
|
|
|
|
} 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 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)
|
|
|
|
stack.push(U256(mul))
|
|
|
|
} 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
|
|
|
|
2015-08-07 00:06:47 +03:00
|
|
|
stack.push(common.BytesToBig(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) {
|
2015-08-30 11:19:10 +03:00
|
|
|
stack.push(common.Bytes2Big(contract.Address().Bytes()))
|
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-01-04 22:17:24 +03:00
|
|
|
func opCalldataLoad(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
2015-08-30 11:19:10 +03:00
|
|
|
stack.push(common.Bytes2Big(getData(contract.Input, stack.pop(), common.Big32)))
|
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 opCalldataSize(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
|
|
|
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-01-04 22:17:24 +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 (
|
|
|
|
mOff = stack.pop()
|
|
|
|
cOff = stack.pop()
|
|
|
|
l = stack.pop()
|
|
|
|
)
|
2015-08-30 11:19:10 +03:00
|
|
|
memory.Set(mOff.Uint64(), l.Uint64(), getData(contract.Input, cOff, l))
|
2017-01-04 22:17:24 +03:00
|
|
|
|
|
|
|
evm.interpreter.intPool.put(mOff, cOff, 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 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 (
|
|
|
|
mOff = stack.pop()
|
|
|
|
cOff = stack.pop()
|
|
|
|
l = stack.pop()
|
|
|
|
)
|
2015-08-30 11:19:10 +03:00
|
|
|
codeCopy := getData(contract.Code, cOff, l)
|
2015-07-18 00:09:36 +03:00
|
|
|
|
|
|
|
memory.Set(mOff.Uint64(), l.Uint64(), codeCopy)
|
2017-01-04 22:17:24 +03:00
|
|
|
|
|
|
|
evm.interpreter.intPool.put(mOff, cOff, 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 opExtCodeCopy(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
2015-07-18 00:09:36 +03:00
|
|
|
var (
|
|
|
|
addr = common.BigToAddress(stack.pop())
|
|
|
|
mOff = stack.pop()
|
|
|
|
cOff = stack.pop()
|
|
|
|
l = stack.pop()
|
|
|
|
)
|
2017-01-04 22:17:24 +03:00
|
|
|
codeCopy := getData(evm.StateDB.GetCode(addr), cOff, l)
|
2015-07-18 00:09:36 +03:00
|
|
|
|
|
|
|
memory.Set(mOff.Uint64(), l.Uint64(), codeCopy)
|
2017-01-04 22:17:24 +03:00
|
|
|
|
|
|
|
evm.interpreter.intPool.put(mOff, cOff, 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 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) {
|
|
|
|
stack.push(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) {
|
|
|
|
stack.push(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) {
|
|
|
|
stack.push(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) {
|
|
|
|
stack.push(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()
|
|
|
|
val := common.BigD(memory.Get(offset.Int64(), 32))
|
|
|
|
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()
|
|
|
|
memory.Set(mStart.Uint64(), 32, common.BigToBytes(val, 256))
|
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-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()
|
|
|
|
if cond.Cmp(common.BigTrue) >= 0 {
|
|
|
|
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-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-01-04 22:17:24 +03:00
|
|
|
_, 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-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()
|
|
|
|
value = U256(value)
|
|
|
|
// 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-01-04 22:17:24 +03:00
|
|
|
if value.BitLen() > 0 {
|
|
|
|
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))
|
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-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 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()
|
|
|
|
value = U256(value)
|
|
|
|
// 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-01-04 22:17:24 +03:00
|
|
|
if value.BitLen() > 0 {
|
|
|
|
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))
|
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-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 opDelegateCall(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
2017-01-05 13:52:10 +03:00
|
|
|
// if not homestead return an error. DELEGATECALL is not supported
|
|
|
|
// during pre-homestead.
|
2017-01-04 22:17:24 +03:00
|
|
|
if !evm.ChainConfig().IsHomestead(evm.BlockNumber) {
|
2017-01-05 13:52:10 +03:00
|
|
|
return nil, fmt.Errorf("invalid opcode %x", DELEGATECALL)
|
|
|
|
}
|
|
|
|
|
2017-01-04 22:17:24 +03:00
|
|
|
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))
|
|
|
|
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-01-05 13:52:10 +03:00
|
|
|
return nil, nil
|
2015-11-27 16:40:29 +02:00
|
|
|
}
|
|
|
|
|
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-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-01-05 13:52:10 +03:00
|
|
|
func makePush(size uint64, bsize *big.Int) executionFunc {
|
2017-01-04 22:17:24 +03:00
|
|
|
return func(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
|
|
|
|
byts := getData(contract.Code, evm.interpreter.intPool.get().SetUint64(*pc+1), bsize)
|
2015-08-30 11:19:10 +03:00
|
|
|
stack.push(common.Bytes2Big(byts))
|
|
|
|
*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) {
|
2015-08-30 11:19:10 +03:00
|
|
|
stack.dup(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
|
|
|
}
|