2016-04-14 18:18:24 +02:00
|
|
|
// Copyright 2015 The go-ethereum Authors
|
2015-07-17 23:09:36 +02: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 02:20:41 +02:00
|
|
|
|
2015-07-17 23:09:36 +02:00
|
|
|
package vm
|
|
|
|
|
|
|
|
import (
|
2024-02-19 20:03:58 +08:00
|
|
|
"math"
|
|
|
|
|
2015-07-17 23:09:36 +02:00
|
|
|
"github.com/ethereum/go-ethereum/common"
|
2017-01-05 14:03:50 +01:00
|
|
|
"github.com/ethereum/go-ethereum/core/types"
|
2022-09-28 13:21:54 +02:00
|
|
|
"github.com/ethereum/go-ethereum/crypto"
|
2015-07-17 23:09:36 +02:00
|
|
|
"github.com/ethereum/go-ethereum/params"
|
2020-06-08 14:24:40 +02:00
|
|
|
"github.com/holiman/uint256"
|
2015-07-17 23:09:36 +02:00
|
|
|
)
|
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opAdd(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
x, y := scope.Stack.pop(), scope.Stack.peek()
|
2020-06-08 14:24:40 +02:00
|
|
|
y.Add(&x, y)
|
2017-01-05 11:52:10 +01:00
|
|
|
return nil, nil
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opSub(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
x, y := scope.Stack.pop(), scope.Stack.peek()
|
2020-06-08 14:24:40 +02:00
|
|
|
y.Sub(&x, y)
|
2017-01-05 11:52:10 +01:00
|
|
|
return nil, nil
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opMul(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
x, y := scope.Stack.pop(), scope.Stack.peek()
|
2020-06-08 14:24:40 +02:00
|
|
|
y.Mul(&x, y)
|
2017-01-05 11:52:10 +01:00
|
|
|
return nil, nil
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opDiv(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
x, y := scope.Stack.pop(), scope.Stack.peek()
|
2020-06-08 14:24:40 +02:00
|
|
|
y.Div(&x, y)
|
2017-01-05 11:52:10 +01:00
|
|
|
return nil, nil
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opSdiv(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
x, y := scope.Stack.pop(), scope.Stack.peek()
|
2020-06-08 14:24:40 +02:00
|
|
|
y.SDiv(&x, y)
|
2017-01-05 11:52:10 +01:00
|
|
|
return nil, nil
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opMod(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
x, y := scope.Stack.pop(), scope.Stack.peek()
|
2020-06-08 14:24:40 +02:00
|
|
|
y.Mod(&x, y)
|
2017-01-05 11:52:10 +01:00
|
|
|
return nil, nil
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opSmod(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
x, y := scope.Stack.pop(), scope.Stack.peek()
|
2020-06-08 14:24:40 +02:00
|
|
|
y.SMod(&x, y)
|
2017-01-05 11:52:10 +01:00
|
|
|
return nil, nil
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opExp(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
base, exponent := scope.Stack.pop(), scope.Stack.peek()
|
2020-06-08 14:24:40 +02:00
|
|
|
exponent.Exp(&base, exponent)
|
2017-01-05 11:52:10 +01:00
|
|
|
return nil, nil
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opSignExtend(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
back, num := scope.Stack.pop(), scope.Stack.peek()
|
2020-06-08 14:24:40 +02:00
|
|
|
num.ExtendSign(num, &back)
|
2017-01-05 11:52:10 +01:00
|
|
|
return nil, nil
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opNot(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
x := scope.Stack.peek()
|
2020-06-08 14:24:40 +02:00
|
|
|
x.Not(x)
|
2017-01-05 11:52:10 +01:00
|
|
|
return nil, nil
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opLt(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
x, y := scope.Stack.pop(), scope.Stack.peek()
|
2020-06-08 14:24:40 +02:00
|
|
|
if x.Lt(y) {
|
|
|
|
y.SetOne()
|
2015-07-17 23:09:36 +02:00
|
|
|
} else {
|
2020-06-08 14:24:40 +02:00
|
|
|
y.Clear()
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
2017-01-05 11:52:10 +01:00
|
|
|
return nil, nil
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opGt(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
x, y := scope.Stack.pop(), scope.Stack.peek()
|
2020-06-08 14:24:40 +02:00
|
|
|
if x.Gt(y) {
|
|
|
|
y.SetOne()
|
2015-07-17 23:09:36 +02:00
|
|
|
} else {
|
2020-06-08 14:24:40 +02:00
|
|
|
y.Clear()
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
2017-01-05 11:52:10 +01:00
|
|
|
return nil, nil
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opSlt(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
x, y := scope.Stack.pop(), scope.Stack.peek()
|
2020-06-08 14:24:40 +02:00
|
|
|
if x.Slt(y) {
|
|
|
|
y.SetOne()
|
|
|
|
} else {
|
|
|
|
y.Clear()
|
2018-03-08 13:48:19 +01:00
|
|
|
}
|
2017-01-05 11:52:10 +01:00
|
|
|
return nil, nil
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opSgt(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
x, y := scope.Stack.pop(), scope.Stack.peek()
|
2020-06-08 14:24:40 +02:00
|
|
|
if x.Sgt(y) {
|
|
|
|
y.SetOne()
|
|
|
|
} else {
|
|
|
|
y.Clear()
|
2018-03-08 13:48:19 +01:00
|
|
|
}
|
2017-01-05 11:52:10 +01:00
|
|
|
return nil, nil
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opEq(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
x, y := scope.Stack.pop(), scope.Stack.peek()
|
2020-06-08 14:24:40 +02:00
|
|
|
if x.Eq(y) {
|
|
|
|
y.SetOne()
|
2015-07-17 23:09:36 +02:00
|
|
|
} else {
|
2020-06-08 14:24:40 +02:00
|
|
|
y.Clear()
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
2017-01-05 11:52:10 +01:00
|
|
|
return nil, nil
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opIszero(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
x := scope.Stack.peek()
|
2020-06-08 14:24:40 +02:00
|
|
|
if x.IsZero() {
|
|
|
|
x.SetOne()
|
2015-07-17 23:09:36 +02:00
|
|
|
} else {
|
2020-06-08 14:24:40 +02:00
|
|
|
x.Clear()
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
2017-01-05 11:52:10 +01:00
|
|
|
return nil, nil
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opAnd(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
x, y := scope.Stack.pop(), scope.Stack.peek()
|
2020-06-08 14:24:40 +02:00
|
|
|
y.And(&x, y)
|
2017-01-05 11:52:10 +01:00
|
|
|
return nil, nil
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
2017-08-16 13:36:48 +03:00
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opOr(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
x, y := scope.Stack.pop(), scope.Stack.peek()
|
2020-06-08 14:24:40 +02:00
|
|
|
y.Or(&x, y)
|
2017-01-05 11:52:10 +01:00
|
|
|
return nil, nil
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
2017-08-16 13:36:48 +03:00
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opXor(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
x, y := scope.Stack.pop(), scope.Stack.peek()
|
2020-06-08 14:24:40 +02:00
|
|
|
y.Xor(&x, y)
|
2017-01-05 11:52:10 +01:00
|
|
|
return nil, nil
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
2017-02-28 15:09:11 +01:00
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opByte(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
th, val := scope.Stack.pop(), scope.Stack.peek()
|
2020-06-08 14:24:40 +02:00
|
|
|
val.Byte(&th)
|
2017-01-05 11:52:10 +01:00
|
|
|
return nil, nil
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
2017-08-16 13:36:48 +03:00
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opAddmod(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
x, y, z := scope.Stack.pop(), scope.Stack.pop(), scope.Stack.peek()
|
2020-06-08 14:24:40 +02:00
|
|
|
if z.IsZero() {
|
|
|
|
z.Clear()
|
2015-08-06 23:06:47 +02:00
|
|
|
} else {
|
2020-06-08 14:24:40 +02:00
|
|
|
z.AddMod(&x, &y, z)
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
2017-01-05 11:52:10 +01:00
|
|
|
return nil, nil
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
2017-08-16 13:36:48 +03:00
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opMulmod(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
x, y, z := scope.Stack.pop(), scope.Stack.pop(), scope.Stack.peek()
|
2020-06-08 14:24:40 +02:00
|
|
|
z.MulMod(&x, &y, z)
|
2017-01-05 11:52:10 +01:00
|
|
|
return nil, nil
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
|
|
|
|
2018-02-23 11:32:57 +01:00
|
|
|
// opSHL implements Shift Left
|
|
|
|
// The SHL instruction (shift left) pops 2 values from the stack, first arg1 and then arg2,
|
|
|
|
// and pushes on the stack arg2 shifted to the left by arg1 number of bits.
|
2021-03-25 10:13:14 +01:00
|
|
|
func opSHL(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
2018-02-23 11:32:57 +01:00
|
|
|
// Note, second operand is left in the stack; accumulate result into it, and no need to push it afterwards
|
2021-03-25 10:13:14 +01:00
|
|
|
shift, value := scope.Stack.pop(), scope.Stack.peek()
|
2020-06-08 14:24:40 +02:00
|
|
|
if shift.LtUint64(256) {
|
|
|
|
value.Lsh(value, uint(shift.Uint64()))
|
|
|
|
} else {
|
|
|
|
value.Clear()
|
2018-02-23 11:32:57 +01:00
|
|
|
}
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// opSHR implements Logical Shift Right
|
|
|
|
// The SHR instruction (logical shift right) pops 2 values from the stack, first arg1 and then arg2,
|
|
|
|
// and pushes on the stack arg2 shifted to the right by arg1 number of bits with zero fill.
|
2021-03-25 10:13:14 +01:00
|
|
|
func opSHR(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
2018-02-23 11:32:57 +01:00
|
|
|
// Note, second operand is left in the stack; accumulate result into it, and no need to push it afterwards
|
2021-03-25 10:13:14 +01:00
|
|
|
shift, value := scope.Stack.pop(), scope.Stack.peek()
|
2020-06-08 14:24:40 +02:00
|
|
|
if shift.LtUint64(256) {
|
|
|
|
value.Rsh(value, uint(shift.Uint64()))
|
|
|
|
} else {
|
|
|
|
value.Clear()
|
2018-02-23 11:32:57 +01:00
|
|
|
}
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// opSAR implements Arithmetic Shift Right
|
|
|
|
// The SAR instruction (arithmetic shift right) pops 2 values from the stack, first arg1 and then arg2,
|
|
|
|
// and pushes on the stack arg2 shifted to the right by arg1 number of bits with sign extension.
|
2021-03-25 10:13:14 +01:00
|
|
|
func opSAR(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
shift, value := scope.Stack.pop(), scope.Stack.peek()
|
2020-06-08 14:24:40 +02:00
|
|
|
if shift.GtUint64(256) {
|
2018-09-04 10:49:18 +02:00
|
|
|
if value.Sign() >= 0 {
|
2020-06-08 14:24:40 +02:00
|
|
|
value.Clear()
|
2018-02-23 11:32:57 +01:00
|
|
|
} else {
|
2020-06-08 14:24:40 +02:00
|
|
|
// Max negative shift: all bits set
|
|
|
|
value.SetAllOne()
|
2018-02-23 11:32:57 +01:00
|
|
|
}
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
n := uint(shift.Uint64())
|
2020-06-08 14:24:40 +02:00
|
|
|
value.SRsh(value, n)
|
2018-02-23 11:32:57 +01:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2021-11-30 09:34:34 +00:00
|
|
|
func opKeccak256(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
2021-03-25 10:13:14 +01:00
|
|
|
offset, size := scope.Stack.pop(), scope.Stack.peek()
|
|
|
|
data := scope.Memory.GetPtr(int64(offset.Uint64()), int64(size.Uint64()))
|
2017-01-17 11:19:50 +00:00
|
|
|
|
2018-10-08 14:14:29 +03:00
|
|
|
if interpreter.hasher == nil {
|
2022-09-28 13:21:54 +02:00
|
|
|
interpreter.hasher = crypto.NewKeccakState()
|
2018-10-08 14:14:29 +03:00
|
|
|
} else {
|
|
|
|
interpreter.hasher.Reset()
|
|
|
|
}
|
|
|
|
interpreter.hasher.Write(data)
|
|
|
|
interpreter.hasher.Read(interpreter.hasherBuf[:])
|
|
|
|
|
|
|
|
evm := interpreter.evm
|
2021-06-10 08:02:51 +03:00
|
|
|
if evm.Config.EnablePreimageRecording {
|
2018-10-08 14:14:29 +03:00
|
|
|
evm.StateDB.AddPreimage(interpreter.hasherBuf, data)
|
2017-01-17 11:19:50 +00:00
|
|
|
}
|
2017-01-04 20:17:24 +01:00
|
|
|
|
2020-06-08 14:24:40 +02:00
|
|
|
size.SetBytes(interpreter.hasherBuf[:])
|
2017-01-05 11:52:10 +01:00
|
|
|
return nil, nil
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
2023-09-26 16:58:01 +08:00
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opAddress(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
scope.Stack.push(new(uint256.Int).SetBytes(scope.Contract.Address().Bytes()))
|
2017-01-05 11:52:10 +01:00
|
|
|
return nil, nil
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opBalance(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
slot := scope.Stack.peek()
|
2020-06-08 14:24:40 +02:00
|
|
|
address := common.Address(slot.Bytes20())
|
2024-01-23 14:51:58 +01:00
|
|
|
slot.Set(interpreter.evm.StateDB.GetBalance(address))
|
2017-01-05 11:52:10 +01:00
|
|
|
return nil, nil
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opOrigin(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
scope.Stack.push(new(uint256.Int).SetBytes(interpreter.evm.Origin.Bytes()))
|
2017-01-05 11:52:10 +01:00
|
|
|
return nil, nil
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
2023-09-26 16:58:01 +08:00
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opCaller(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
scope.Stack.push(new(uint256.Int).SetBytes(scope.Contract.Caller().Bytes()))
|
2017-01-05 11:52:10 +01:00
|
|
|
return nil, nil
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opCallValue(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
2024-01-23 14:51:58 +01:00
|
|
|
scope.Stack.push(scope.Contract.value)
|
2017-01-05 11:52:10 +01:00
|
|
|
return nil, nil
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opCallDataLoad(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
x := scope.Stack.peek()
|
2020-06-08 14:24:40 +02:00
|
|
|
if offset, overflow := x.Uint64WithOverflow(); !overflow {
|
2021-03-25 10:13:14 +01:00
|
|
|
data := getData(scope.Contract.Input, offset, 32)
|
2020-06-08 14:24:40 +02:00
|
|
|
x.SetBytes(data)
|
|
|
|
} else {
|
|
|
|
x.Clear()
|
|
|
|
}
|
2017-01-05 11:52:10 +01:00
|
|
|
return nil, nil
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opCallDataSize(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
scope.Stack.push(new(uint256.Int).SetUint64(uint64(len(scope.Contract.Input))))
|
2017-01-05 11:52:10 +01:00
|
|
|
return nil, nil
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opCallDataCopy(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
2015-07-17 23:09:36 +02:00
|
|
|
var (
|
2021-03-25 10:13:14 +01:00
|
|
|
memOffset = scope.Stack.pop()
|
|
|
|
dataOffset = scope.Stack.pop()
|
|
|
|
length = scope.Stack.pop()
|
2015-07-17 23:09:36 +02:00
|
|
|
)
|
2020-06-08 14:24:40 +02:00
|
|
|
dataOffset64, overflow := dataOffset.Uint64WithOverflow()
|
|
|
|
if overflow {
|
|
|
|
dataOffset64 = 0xffffffffffffffff
|
|
|
|
}
|
|
|
|
// These values are checked for overflow during gas cost calculation
|
|
|
|
memOffset64 := memOffset.Uint64()
|
|
|
|
length64 := length.Uint64()
|
2021-03-25 10:13:14 +01:00
|
|
|
scope.Memory.Set(memOffset64, length64, getData(scope.Contract.Input, dataOffset64, length64))
|
2017-01-04 20:17:24 +01:00
|
|
|
|
2017-01-05 11:52:10 +01:00
|
|
|
return nil, nil
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opReturnDataSize(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
scope.Stack.push(new(uint256.Int).SetUint64(uint64(len(interpreter.returnData))))
|
2017-08-16 13:07:33 +03:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opReturnDataCopy(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
2017-08-16 13:07:33 +03:00
|
|
|
var (
|
2021-03-25 10:13:14 +01:00
|
|
|
memOffset = scope.Stack.pop()
|
|
|
|
dataOffset = scope.Stack.pop()
|
|
|
|
length = scope.Stack.pop()
|
2017-08-16 13:07:33 +03:00
|
|
|
)
|
|
|
|
|
2020-06-08 14:24:40 +02:00
|
|
|
offset64, overflow := dataOffset.Uint64WithOverflow()
|
|
|
|
if overflow {
|
2020-04-22 16:25:36 +08:00
|
|
|
return nil, ErrReturnDataOutOfBounds
|
2017-08-16 13:07:33 +03:00
|
|
|
}
|
2020-06-08 14:24:40 +02:00
|
|
|
// we can reuse dataOffset now (aliasing it for clarity)
|
|
|
|
var end = dataOffset
|
|
|
|
end.Add(&dataOffset, &length)
|
|
|
|
end64, overflow := end.Uint64WithOverflow()
|
|
|
|
if overflow || uint64(len(interpreter.returnData)) < end64 {
|
|
|
|
return nil, ErrReturnDataOutOfBounds
|
|
|
|
}
|
2021-03-25 10:13:14 +01:00
|
|
|
scope.Memory.Set(memOffset.Uint64(), length.Uint64(), interpreter.returnData[offset64:end64])
|
2017-08-16 13:07:33 +03:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opExtCodeSize(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
slot := scope.Stack.peek()
|
2020-11-25 21:00:23 +01:00
|
|
|
slot.SetUint64(uint64(interpreter.evm.StateDB.GetCodeSize(slot.Bytes20())))
|
2017-01-05 11:52:10 +01:00
|
|
|
return nil, nil
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opCodeSize(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
2024-02-07 17:01:38 +01:00
|
|
|
scope.Stack.push(new(uint256.Int).SetUint64(uint64(len(scope.Contract.Code))))
|
2017-01-05 11:52:10 +01:00
|
|
|
return nil, nil
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opCodeCopy(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
2015-07-17 23:09:36 +02:00
|
|
|
var (
|
2021-03-25 10:13:14 +01:00
|
|
|
memOffset = scope.Stack.pop()
|
|
|
|
codeOffset = scope.Stack.pop()
|
|
|
|
length = scope.Stack.pop()
|
2015-07-17 23:09:36 +02:00
|
|
|
)
|
2020-06-08 14:24:40 +02:00
|
|
|
uint64CodeOffset, overflow := codeOffset.Uint64WithOverflow()
|
|
|
|
if overflow {
|
2024-02-19 20:03:58 +08:00
|
|
|
uint64CodeOffset = math.MaxUint64
|
2020-06-08 14:24:40 +02:00
|
|
|
}
|
2021-03-25 10:13:14 +01:00
|
|
|
codeCopy := getData(scope.Contract.Code, uint64CodeOffset, length.Uint64())
|
|
|
|
scope.Memory.Set(memOffset.Uint64(), length.Uint64(), codeCopy)
|
2017-01-04 20:17:24 +01:00
|
|
|
|
2017-01-05 11:52:10 +01:00
|
|
|
return nil, nil
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opExtCodeCopy(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
2015-07-17 23:09:36 +02:00
|
|
|
var (
|
2021-03-25 10:13:14 +01:00
|
|
|
stack = scope.Stack
|
2020-06-08 14:24:40 +02:00
|
|
|
a = stack.pop()
|
|
|
|
memOffset = stack.pop()
|
|
|
|
codeOffset = stack.pop()
|
|
|
|
length = stack.pop()
|
2015-07-17 23:09:36 +02:00
|
|
|
)
|
2020-06-08 14:24:40 +02:00
|
|
|
uint64CodeOffset, overflow := codeOffset.Uint64WithOverflow()
|
|
|
|
if overflow {
|
2024-02-19 20:03:58 +08:00
|
|
|
uint64CodeOffset = math.MaxUint64
|
2020-06-08 14:24:40 +02:00
|
|
|
}
|
|
|
|
addr := common.Address(a.Bytes20())
|
|
|
|
codeCopy := getData(interpreter.evm.StateDB.GetCode(addr), uint64CodeOffset, length.Uint64())
|
2021-03-25 10:13:14 +01:00
|
|
|
scope.Memory.Set(memOffset.Uint64(), length.Uint64(), codeCopy)
|
2017-01-04 20:17:24 +01:00
|
|
|
|
2017-01-05 11:52:10 +01:00
|
|
|
return nil, nil
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
|
|
|
|
2018-07-24 23:06:40 +08:00
|
|
|
// opExtCodeHash returns the code hash of a specified account.
|
|
|
|
// There are several cases when the function is called, while we can relay everything
|
|
|
|
// to `state.GetCodeHash` function to ensure the correctness.
|
|
|
|
//
|
2022-09-10 13:25:40 +02:00
|
|
|
// 1. Caller tries to get the code hash of a normal contract account, state
|
|
|
|
// should return the relative code hash and set it as the result.
|
2018-07-24 23:06:40 +08:00
|
|
|
//
|
2022-09-10 13:25:40 +02:00
|
|
|
// 2. Caller tries to get the code hash of a non-existent account, state should
|
|
|
|
// return common.Hash{} and zero will be set as the result.
|
2018-07-24 23:06:40 +08:00
|
|
|
//
|
2022-09-10 13:25:40 +02:00
|
|
|
// 3. Caller tries to get the code hash for an account without contract code, state
|
|
|
|
// should return emptyCodeHash(0xc5d246...) as the result.
|
2018-07-24 23:06:40 +08:00
|
|
|
//
|
2022-09-10 13:25:40 +02:00
|
|
|
// 4. Caller tries to get the code hash of a precompiled account, the result should be
|
|
|
|
// zero or emptyCodeHash.
|
|
|
|
//
|
|
|
|
// It is worth noting that in order to avoid unnecessary create and clean, all precompile
|
|
|
|
// accounts on mainnet have been transferred 1 wei, so the return here should be
|
|
|
|
// emptyCodeHash. If the precompile account is not transferred any amount on a private or
|
2018-07-24 23:06:40 +08:00
|
|
|
// customized chain, the return value will be zero.
|
|
|
|
//
|
2023-07-15 16:35:30 +02:00
|
|
|
// 5. Caller tries to get the code hash for an account which is marked as self-destructed
|
2022-09-10 13:25:40 +02:00
|
|
|
// in the current transaction, the code hash of this account should be returned.
|
2018-07-24 23:06:40 +08:00
|
|
|
//
|
2022-09-10 13:25:40 +02:00
|
|
|
// 6. Caller tries to get the code hash for an account which is marked as deleted, this
|
|
|
|
// account should be regarded as a non-existent account and zero should be returned.
|
2021-03-25 10:13:14 +01:00
|
|
|
func opExtCodeHash(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
slot := scope.Stack.peek()
|
2020-06-08 14:24:40 +02:00
|
|
|
address := common.Address(slot.Bytes20())
|
2018-10-26 08:52:41 +02:00
|
|
|
if interpreter.evm.StateDB.Empty(address) {
|
2020-06-08 14:24:40 +02:00
|
|
|
slot.Clear()
|
2018-10-26 08:52:41 +02:00
|
|
|
} else {
|
|
|
|
slot.SetBytes(interpreter.evm.StateDB.GetCodeHash(address).Bytes())
|
|
|
|
}
|
2018-07-24 23:06:40 +08:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opGasprice(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
2020-06-08 14:24:40 +02:00
|
|
|
v, _ := uint256.FromBig(interpreter.evm.GasPrice)
|
2021-03-25 10:13:14 +01:00
|
|
|
scope.Stack.push(v)
|
2017-01-05 11:52:10 +01:00
|
|
|
return nil, nil
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opBlockhash(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
num := scope.Stack.peek()
|
2020-06-08 14:24:40 +02:00
|
|
|
num64, overflow := num.Uint64WithOverflow()
|
|
|
|
if overflow {
|
|
|
|
num.Clear()
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
var upper, lower uint64
|
2020-11-13 13:42:19 +01:00
|
|
|
upper = interpreter.evm.Context.BlockNumber.Uint64()
|
2020-06-08 14:24:40 +02:00
|
|
|
if upper < 257 {
|
|
|
|
lower = 0
|
2015-07-17 23:09:36 +02:00
|
|
|
} else {
|
2020-06-08 14:24:40 +02:00
|
|
|
lower = upper - 256
|
|
|
|
}
|
|
|
|
if num64 >= lower && num64 < upper {
|
2020-11-13 13:42:19 +01:00
|
|
|
num.SetBytes(interpreter.evm.Context.GetHash(num64).Bytes())
|
2020-06-08 14:24:40 +02:00
|
|
|
} else {
|
|
|
|
num.Clear()
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
2017-01-05 11:52:10 +01:00
|
|
|
return nil, nil
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opCoinbase(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
scope.Stack.push(new(uint256.Int).SetBytes(interpreter.evm.Context.Coinbase.Bytes()))
|
2017-01-05 11:52:10 +01:00
|
|
|
return nil, nil
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opTimestamp(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
2023-01-25 06:12:28 -05:00
|
|
|
scope.Stack.push(new(uint256.Int).SetUint64(interpreter.evm.Context.Time))
|
2017-01-05 11:52:10 +01:00
|
|
|
return nil, nil
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opNumber(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
2020-11-13 13:42:19 +01:00
|
|
|
v, _ := uint256.FromBig(interpreter.evm.Context.BlockNumber)
|
2021-03-25 10:13:14 +01:00
|
|
|
scope.Stack.push(v)
|
2017-01-05 11:52:10 +01:00
|
|
|
return nil, nil
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opDifficulty(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
2020-11-13 13:42:19 +01:00
|
|
|
v, _ := uint256.FromBig(interpreter.evm.Context.Difficulty)
|
2021-03-25 10:13:14 +01:00
|
|
|
scope.Stack.push(v)
|
2017-01-05 11:52:10 +01:00
|
|
|
return nil, nil
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
|
|
|
|
2022-01-10 08:44:21 +01:00
|
|
|
func opRandom(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
2022-05-11 13:03:35 +08:00
|
|
|
v := new(uint256.Int).SetBytes(interpreter.evm.Context.Random.Bytes())
|
2022-01-10 08:44:21 +01:00
|
|
|
scope.Stack.push(v)
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opGasLimit(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
scope.Stack.push(new(uint256.Int).SetUint64(interpreter.evm.Context.GasLimit))
|
2017-01-05 11:52:10 +01:00
|
|
|
return nil, nil
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opPop(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
scope.Stack.pop()
|
2017-01-05 11:52:10 +01:00
|
|
|
return nil, nil
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opMload(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
v := scope.Stack.peek()
|
2020-06-08 14:24:40 +02:00
|
|
|
offset := int64(v.Uint64())
|
2021-03-25 10:13:14 +01:00
|
|
|
v.SetBytes(scope.Memory.GetPtr(offset, 32))
|
2017-01-05 11:52:10 +01:00
|
|
|
return nil, nil
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opMstore(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
2015-07-17 23:09:36 +02:00
|
|
|
// pop value of the stack
|
2021-03-25 10:13:14 +01:00
|
|
|
mStart, val := scope.Stack.pop(), scope.Stack.pop()
|
|
|
|
scope.Memory.Set32(mStart.Uint64(), &val)
|
2017-01-05 11:52:10 +01:00
|
|
|
return nil, nil
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opMstore8(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
off, val := scope.Stack.pop(), scope.Stack.pop()
|
|
|
|
scope.Memory.store[off.Uint64()] = byte(val.Uint64())
|
2017-01-05 11:52:10 +01:00
|
|
|
return nil, nil
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opSload(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
loc := scope.Stack.peek()
|
2020-06-08 14:24:40 +02:00
|
|
|
hash := common.Hash(loc.Bytes32())
|
2021-03-25 10:13:14 +01:00
|
|
|
val := interpreter.evm.StateDB.GetState(scope.Contract.Address(), hash)
|
2018-06-14 11:23:37 +02:00
|
|
|
loc.SetBytes(val.Bytes())
|
2017-01-05 11:52:10 +01:00
|
|
|
return nil, nil
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opSstore(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
2021-12-01 09:21:21 +00:00
|
|
|
if interpreter.readOnly {
|
|
|
|
return nil, ErrWriteProtection
|
|
|
|
}
|
2021-03-25 10:13:14 +01:00
|
|
|
loc := scope.Stack.pop()
|
|
|
|
val := scope.Stack.pop()
|
2022-11-16 01:18:52 -08:00
|
|
|
interpreter.evm.StateDB.SetState(scope.Contract.Address(), loc.Bytes32(), val.Bytes32())
|
2017-01-05 11:52:10 +01:00
|
|
|
return nil, nil
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opJump(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
2023-03-27 21:40:20 +08:00
|
|
|
if interpreter.evm.abort.Load() {
|
2021-12-03 11:10:26 +01:00
|
|
|
return nil, errStopToken
|
|
|
|
}
|
2021-03-25 10:13:14 +01:00
|
|
|
pos := scope.Stack.pop()
|
|
|
|
if !scope.Contract.validJumpdest(&pos) {
|
2020-04-22 16:25:36 +08:00
|
|
|
return nil, ErrInvalidJump
|
2017-01-05 11:52:10 +01:00
|
|
|
}
|
2021-11-29 14:46:24 +01:00
|
|
|
*pc = pos.Uint64() - 1 // pc will be increased by the interpreter loop
|
2017-01-05 11:52:10 +01:00
|
|
|
return nil, nil
|
2015-08-30 10:19:10 +02:00
|
|
|
}
|
2017-08-16 13:36:48 +03:00
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opJumpi(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
2023-03-27 21:40:20 +08:00
|
|
|
if interpreter.evm.abort.Load() {
|
2021-12-03 11:10:26 +01:00
|
|
|
return nil, errStopToken
|
|
|
|
}
|
2021-03-25 10:13:14 +01:00
|
|
|
pos, cond := scope.Stack.pop(), scope.Stack.pop()
|
2020-06-08 14:24:40 +02:00
|
|
|
if !cond.IsZero() {
|
2021-03-25 10:13:14 +01:00
|
|
|
if !scope.Contract.validJumpdest(&pos) {
|
2020-04-22 16:25:36 +08:00
|
|
|
return nil, ErrInvalidJump
|
2017-01-05 11:52:10 +01:00
|
|
|
}
|
2021-11-29 14:46:24 +01:00
|
|
|
*pc = pos.Uint64() - 1 // pc will be increased by the interpreter loop
|
2017-01-05 11:52:10 +01:00
|
|
|
}
|
|
|
|
return nil, nil
|
2015-08-30 10:19:10 +02:00
|
|
|
}
|
2017-08-16 13:36:48 +03:00
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opJumpdest(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
2017-01-05 11:52:10 +01:00
|
|
|
return nil, nil
|
2015-08-30 10:19:10 +02:00
|
|
|
}
|
2015-07-17 23:09:36 +02:00
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opPc(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
scope.Stack.push(new(uint256.Int).SetUint64(*pc))
|
2017-01-05 11:52:10 +01:00
|
|
|
return nil, nil
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opMsize(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
scope.Stack.push(new(uint256.Int).SetUint64(uint64(scope.Memory.Len())))
|
2017-01-05 11:52:10 +01:00
|
|
|
return nil, nil
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opGas(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
scope.Stack.push(new(uint256.Int).SetUint64(scope.Contract.Gas))
|
2017-01-05 11:52:10 +01:00
|
|
|
return nil, nil
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opCreate(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
2021-12-01 09:21:21 +00:00
|
|
|
if interpreter.readOnly {
|
|
|
|
return nil, ErrWriteProtection
|
|
|
|
}
|
2016-01-19 23:50:00 +01:00
|
|
|
var (
|
2021-03-25 10:13:14 +01:00
|
|
|
value = scope.Stack.pop()
|
|
|
|
offset, size = scope.Stack.pop(), scope.Stack.pop()
|
|
|
|
input = scope.Memory.GetCopy(int64(offset.Uint64()), int64(size.Uint64()))
|
|
|
|
gas = scope.Contract.Gas
|
2016-01-19 23:50:00 +01:00
|
|
|
)
|
2019-08-05 10:01:02 +02:00
|
|
|
if interpreter.evm.chainRules.IsEIP150 {
|
2017-01-04 20:17:24 +01:00
|
|
|
gas -= gas / 64
|
2016-10-08 00:23:45 +02:00
|
|
|
}
|
2020-06-08 14:24:40 +02:00
|
|
|
// reuse size int for stackvalue
|
|
|
|
stackvalue := size
|
2016-10-08 00:23:45 +02:00
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
scope.Contract.UseGas(gas)
|
2020-07-16 14:06:19 +02:00
|
|
|
|
2024-01-23 14:51:58 +01:00
|
|
|
res, addr, returnGas, suberr := interpreter.evm.Create(scope.Contract, input, gas, &value)
|
2016-01-19 23:50:00 +01: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.
|
2019-08-05 10:01:02 +02:00
|
|
|
if interpreter.evm.chainRules.IsHomestead && suberr == ErrCodeStoreOutOfGas {
|
2020-06-08 14:24:40 +02:00
|
|
|
stackvalue.Clear()
|
2017-01-05 11:52:10 +01:00
|
|
|
} else if suberr != nil && suberr != ErrCodeStoreOutOfGas {
|
2020-06-08 14:24:40 +02:00
|
|
|
stackvalue.Clear()
|
2016-01-19 23:50:00 +01:00
|
|
|
} else {
|
2020-06-08 14:24:40 +02:00
|
|
|
stackvalue.SetBytes(addr.Bytes())
|
2016-01-19 23:50:00 +01:00
|
|
|
}
|
2021-03-25 10:13:14 +01:00
|
|
|
scope.Stack.push(&stackvalue)
|
|
|
|
scope.Contract.Gas += returnGas
|
2017-01-04 20:17:24 +01:00
|
|
|
|
2020-04-22 16:25:36 +08:00
|
|
|
if suberr == ErrExecutionReverted {
|
2021-11-29 14:46:24 +01:00
|
|
|
interpreter.returnData = res // set REVERT data to return data buffer
|
2017-08-16 17:09:29 +03:00
|
|
|
return res, nil
|
|
|
|
}
|
2021-11-29 14:46:24 +01:00
|
|
|
interpreter.returnData = nil // clear dirty return data buffer
|
2017-01-05 11:52:10 +01:00
|
|
|
return nil, nil
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opCreate2(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
2021-12-01 09:21:21 +00:00
|
|
|
if interpreter.readOnly {
|
|
|
|
return nil, ErrWriteProtection
|
|
|
|
}
|
2018-07-24 22:22:03 +08:00
|
|
|
var (
|
2021-03-25 10:13:14 +01:00
|
|
|
endowment = scope.Stack.pop()
|
|
|
|
offset, size = scope.Stack.pop(), scope.Stack.pop()
|
|
|
|
salt = scope.Stack.pop()
|
|
|
|
input = scope.Memory.GetCopy(int64(offset.Uint64()), int64(size.Uint64()))
|
|
|
|
gas = scope.Contract.Gas
|
2018-07-24 22:22:03 +08:00
|
|
|
)
|
|
|
|
// Apply EIP150
|
|
|
|
gas -= gas / 64
|
2021-03-25 10:13:14 +01:00
|
|
|
scope.Contract.UseGas(gas)
|
2020-06-08 14:24:40 +02:00
|
|
|
// reuse size int for stackvalue
|
|
|
|
stackvalue := size
|
2021-03-25 10:13:14 +01:00
|
|
|
res, addr, returnGas, suberr := interpreter.evm.Create2(scope.Contract, input, gas,
|
2024-01-23 14:51:58 +01:00
|
|
|
&endowment, &salt)
|
2018-07-24 22:22:03 +08:00
|
|
|
// Push item on the stack based on the returned error.
|
|
|
|
if suberr != nil {
|
2020-06-08 14:24:40 +02:00
|
|
|
stackvalue.Clear()
|
2018-07-24 22:22:03 +08:00
|
|
|
} else {
|
2020-06-08 14:24:40 +02:00
|
|
|
stackvalue.SetBytes(addr.Bytes())
|
2018-07-24 22:22:03 +08:00
|
|
|
}
|
2021-03-25 10:13:14 +01:00
|
|
|
scope.Stack.push(&stackvalue)
|
|
|
|
scope.Contract.Gas += returnGas
|
2018-07-24 22:22:03 +08:00
|
|
|
|
2020-04-22 16:25:36 +08:00
|
|
|
if suberr == ErrExecutionReverted {
|
2021-11-29 14:46:24 +01:00
|
|
|
interpreter.returnData = res // set REVERT data to return data buffer
|
2018-07-24 22:22:03 +08:00
|
|
|
return res, nil
|
|
|
|
}
|
2021-11-29 14:46:24 +01:00
|
|
|
interpreter.returnData = nil // clear dirty return data buffer
|
2018-07-24 22:22:03 +08:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opCall(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
stack := scope.Stack
|
2018-09-25 18:26:35 +08:00
|
|
|
// Pop gas. The actual gas in interpreter.evm.callGasTemp.
|
2020-06-08 14:24:40 +02:00
|
|
|
// We can use this as a temporary value
|
|
|
|
temp := stack.pop()
|
2018-07-25 08:56:39 -04:00
|
|
|
gas := interpreter.evm.callGasTemp
|
2017-11-28 20:05:49 +01:00
|
|
|
// Pop other call parameters.
|
2020-06-08 14:24:40 +02:00
|
|
|
addr, value, inOffset, inSize, retOffset, retSize := stack.pop(), stack.pop(), stack.pop(), stack.pop(), stack.pop(), stack.pop()
|
|
|
|
toAddr := common.Address(addr.Bytes20())
|
2017-11-28 20:05:49 +01:00
|
|
|
// Get the arguments from the memory.
|
2021-03-25 10:13:14 +01:00
|
|
|
args := scope.Memory.GetPtr(int64(inOffset.Uint64()), int64(inSize.Uint64()))
|
2015-07-17 23:09:36 +02:00
|
|
|
|
2021-12-01 09:21:21 +00:00
|
|
|
if interpreter.readOnly && !value.IsZero() {
|
|
|
|
return nil, ErrWriteProtection
|
|
|
|
}
|
2020-06-08 14:24:40 +02:00
|
|
|
if !value.IsZero() {
|
2017-01-04 20:17:24 +01:00
|
|
|
gas += params.CallStipend
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
2024-01-23 14:51:58 +01:00
|
|
|
ret, returnGas, err := interpreter.evm.Call(scope.Contract, toAddr, args, gas, &value)
|
2020-07-16 14:06:19 +02:00
|
|
|
|
2015-07-17 23:09:36 +02:00
|
|
|
if err != nil {
|
2020-06-08 14:24:40 +02:00
|
|
|
temp.Clear()
|
2015-07-17 23:09:36 +02:00
|
|
|
} else {
|
2020-06-08 14:24:40 +02:00
|
|
|
temp.SetOne()
|
2017-08-16 17:09:29 +03:00
|
|
|
}
|
2020-06-08 14:24:40 +02:00
|
|
|
stack.push(&temp)
|
2020-04-22 16:25:36 +08:00
|
|
|
if err == nil || err == ErrExecutionReverted {
|
2021-03-25 10:13:14 +01:00
|
|
|
scope.Memory.Set(retOffset.Uint64(), retSize.Uint64(), ret)
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
2021-03-25 10:13:14 +01:00
|
|
|
scope.Contract.Gas += returnGas
|
2017-01-04 20:17:24 +01:00
|
|
|
|
2021-11-29 14:46:24 +01:00
|
|
|
interpreter.returnData = ret
|
2017-02-01 22:36:51 +01:00
|
|
|
return ret, nil
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opCallCode(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
2018-07-25 08:56:39 -04:00
|
|
|
// Pop gas. The actual gas is in interpreter.evm.callGasTemp.
|
2021-03-25 10:13:14 +01:00
|
|
|
stack := scope.Stack
|
2020-06-08 14:24:40 +02:00
|
|
|
// We use it as a temporary value
|
|
|
|
temp := stack.pop()
|
2018-07-25 08:56:39 -04:00
|
|
|
gas := interpreter.evm.callGasTemp
|
2017-11-28 20:05:49 +01:00
|
|
|
// Pop other call parameters.
|
2020-06-08 14:24:40 +02:00
|
|
|
addr, value, inOffset, inSize, retOffset, retSize := stack.pop(), stack.pop(), stack.pop(), stack.pop(), stack.pop(), stack.pop()
|
|
|
|
toAddr := common.Address(addr.Bytes20())
|
2017-11-28 20:05:49 +01:00
|
|
|
// Get arguments from the memory.
|
2021-03-25 10:13:14 +01:00
|
|
|
args := scope.Memory.GetPtr(int64(inOffset.Uint64()), int64(inSize.Uint64()))
|
2015-07-17 23:09:36 +02:00
|
|
|
|
2020-06-08 14:24:40 +02:00
|
|
|
if !value.IsZero() {
|
2017-01-04 20:17:24 +01:00
|
|
|
gas += params.CallStipend
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
2020-07-16 14:06:19 +02:00
|
|
|
|
2024-01-23 14:51:58 +01:00
|
|
|
ret, returnGas, err := interpreter.evm.CallCode(scope.Contract, toAddr, args, gas, &value)
|
2015-07-17 23:09:36 +02:00
|
|
|
if err != nil {
|
2020-06-08 14:24:40 +02:00
|
|
|
temp.Clear()
|
2015-07-17 23:09:36 +02:00
|
|
|
} else {
|
2020-06-08 14:24:40 +02:00
|
|
|
temp.SetOne()
|
2017-08-16 17:09:29 +03:00
|
|
|
}
|
2020-06-08 14:24:40 +02:00
|
|
|
stack.push(&temp)
|
2020-04-22 16:25:36 +08:00
|
|
|
if err == nil || err == ErrExecutionReverted {
|
2021-03-25 10:13:14 +01:00
|
|
|
scope.Memory.Set(retOffset.Uint64(), retSize.Uint64(), ret)
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
2021-03-25 10:13:14 +01:00
|
|
|
scope.Contract.Gas += returnGas
|
2017-01-04 20:17:24 +01:00
|
|
|
|
2021-11-29 14:46:24 +01:00
|
|
|
interpreter.returnData = ret
|
2017-02-01 22:36:51 +01:00
|
|
|
return ret, nil
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opDelegateCall(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
stack := scope.Stack
|
2018-07-25 08:56:39 -04:00
|
|
|
// Pop gas. The actual gas is in interpreter.evm.callGasTemp.
|
2020-06-08 14:24:40 +02:00
|
|
|
// We use it as a temporary value
|
|
|
|
temp := stack.pop()
|
2018-07-25 08:56:39 -04:00
|
|
|
gas := interpreter.evm.callGasTemp
|
2017-11-28 20:05:49 +01:00
|
|
|
// Pop other call parameters.
|
2020-06-08 14:24:40 +02:00
|
|
|
addr, inOffset, inSize, retOffset, retSize := stack.pop(), stack.pop(), stack.pop(), stack.pop(), stack.pop()
|
|
|
|
toAddr := common.Address(addr.Bytes20())
|
2017-11-28 20:05:49 +01:00
|
|
|
// Get arguments from the memory.
|
2021-03-25 10:13:14 +01:00
|
|
|
args := scope.Memory.GetPtr(int64(inOffset.Uint64()), int64(inSize.Uint64()))
|
2017-01-04 20:17:24 +01:00
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
ret, returnGas, err := interpreter.evm.DelegateCall(scope.Contract, toAddr, args, gas)
|
2015-11-27 15:40:29 +01:00
|
|
|
if err != nil {
|
2020-06-08 14:24:40 +02:00
|
|
|
temp.Clear()
|
2015-11-27 15:40:29 +01:00
|
|
|
} else {
|
2020-06-08 14:24:40 +02:00
|
|
|
temp.SetOne()
|
2017-08-16 17:09:29 +03:00
|
|
|
}
|
2020-06-08 14:24:40 +02:00
|
|
|
stack.push(&temp)
|
2020-04-22 16:25:36 +08:00
|
|
|
if err == nil || err == ErrExecutionReverted {
|
2021-03-25 10:13:14 +01:00
|
|
|
scope.Memory.Set(retOffset.Uint64(), retSize.Uint64(), ret)
|
2015-11-27 15:40:29 +01:00
|
|
|
}
|
2021-03-25 10:13:14 +01:00
|
|
|
scope.Contract.Gas += returnGas
|
2017-01-04 20:17:24 +01:00
|
|
|
|
2021-11-29 14:46:24 +01:00
|
|
|
interpreter.returnData = ret
|
2017-02-01 22:36:51 +01:00
|
|
|
return ret, nil
|
2015-11-27 15:40:29 +01:00
|
|
|
}
|
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opStaticCall(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
2018-07-25 08:56:39 -04:00
|
|
|
// Pop gas. The actual gas is in interpreter.evm.callGasTemp.
|
2021-03-25 10:13:14 +01:00
|
|
|
stack := scope.Stack
|
2020-06-08 14:24:40 +02:00
|
|
|
// We use it as a temporary value
|
|
|
|
temp := stack.pop()
|
2018-07-25 08:56:39 -04:00
|
|
|
gas := interpreter.evm.callGasTemp
|
2017-11-28 20:05:49 +01:00
|
|
|
// Pop other call parameters.
|
2020-06-08 14:24:40 +02:00
|
|
|
addr, inOffset, inSize, retOffset, retSize := stack.pop(), stack.pop(), stack.pop(), stack.pop(), stack.pop()
|
|
|
|
toAddr := common.Address(addr.Bytes20())
|
2017-11-28 20:05:49 +01:00
|
|
|
// Get arguments from the memory.
|
2021-03-25 10:13:14 +01:00
|
|
|
args := scope.Memory.GetPtr(int64(inOffset.Uint64()), int64(inSize.Uint64()))
|
2017-08-15 11:23:23 +03:00
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
ret, returnGas, err := interpreter.evm.StaticCall(scope.Contract, toAddr, args, gas)
|
2017-08-15 11:23:23 +03:00
|
|
|
if err != nil {
|
2020-06-08 14:24:40 +02:00
|
|
|
temp.Clear()
|
2017-08-15 11:23:23 +03:00
|
|
|
} else {
|
2020-06-08 14:24:40 +02:00
|
|
|
temp.SetOne()
|
2017-08-16 17:09:29 +03:00
|
|
|
}
|
2020-06-08 14:24:40 +02:00
|
|
|
stack.push(&temp)
|
2020-04-22 16:25:36 +08:00
|
|
|
if err == nil || err == ErrExecutionReverted {
|
2021-03-25 10:13:14 +01:00
|
|
|
scope.Memory.Set(retOffset.Uint64(), retSize.Uint64(), ret)
|
2017-08-15 11:23:23 +03:00
|
|
|
}
|
2021-03-25 10:13:14 +01:00
|
|
|
scope.Contract.Gas += returnGas
|
2017-08-15 11:23:23 +03:00
|
|
|
|
2021-11-29 14:46:24 +01:00
|
|
|
interpreter.returnData = ret
|
2017-08-15 11:23:23 +03:00
|
|
|
return ret, nil
|
|
|
|
}
|
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opReturn(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
offset, size := scope.Stack.pop(), scope.Stack.pop()
|
|
|
|
ret := scope.Memory.GetPtr(int64(offset.Uint64()), int64(size.Uint64()))
|
2017-01-05 11:52:10 +01:00
|
|
|
|
2021-11-29 14:46:24 +01:00
|
|
|
return ret, errStopToken
|
2017-08-16 15:32:59 +03:00
|
|
|
}
|
2017-02-01 22:36:51 +01:00
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opRevert(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
offset, size := scope.Stack.pop(), scope.Stack.pop()
|
|
|
|
ret := scope.Memory.GetPtr(int64(offset.Uint64()), int64(size.Uint64()))
|
2017-08-16 15:32:59 +03:00
|
|
|
|
2021-11-29 14:46:24 +01:00
|
|
|
interpreter.returnData = ret
|
|
|
|
return ret, ErrExecutionReverted
|
2015-08-30 10:19:10 +02:00
|
|
|
}
|
2017-01-05 11:52:10 +01:00
|
|
|
|
2021-12-03 11:04:54 +01:00
|
|
|
func opUndefined(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
return nil, &ErrInvalidOpCode{opcode: OpCode(scope.Contract.Code[*pc])}
|
|
|
|
}
|
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
func opStop(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
2021-11-29 14:46:24 +01:00
|
|
|
return nil, errStopToken
|
2015-08-30 10:19:10 +02:00
|
|
|
}
|
|
|
|
|
2021-12-01 09:33:29 +00:00
|
|
|
func opSelfdestruct(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
2021-12-01 09:21:21 +00:00
|
|
|
if interpreter.readOnly {
|
|
|
|
return nil, ErrWriteProtection
|
|
|
|
}
|
2021-03-25 10:13:14 +01:00
|
|
|
beneficiary := scope.Stack.pop()
|
|
|
|
balance := interpreter.evm.StateDB.GetBalance(scope.Contract.Address())
|
2020-11-25 21:00:23 +01:00
|
|
|
interpreter.evm.StateDB.AddBalance(beneficiary.Bytes20(), balance)
|
2023-07-15 16:35:30 +02:00
|
|
|
interpreter.evm.StateDB.SelfDestruct(scope.Contract.Address())
|
2023-04-04 09:50:13 -04:00
|
|
|
if tracer := interpreter.evm.Config.Tracer; tracer != nil {
|
2024-01-23 14:51:58 +01:00
|
|
|
tracer.CaptureEnter(SELFDESTRUCT, scope.Contract.Address(), beneficiary.Bytes20(), []byte{}, 0, balance.ToBig())
|
2023-04-04 09:50:13 -04:00
|
|
|
tracer.CaptureExit([]byte{}, 0, nil)
|
core,eth: call frame tracing (#23087)
This change introduces 2 new optional methods; `enter()` and `exit()` for js tracers, and makes `step()` optiona. The two new methods are invoked when entering and exiting a call frame (but not invoked for the outermost scope, which has it's own methods). Currently these are the data fields passed to each of them:
enter: type (opcode), from, to, input, gas, value
exit: output, gasUsed, error
The PR also comes with a re-write of the callTracer. As a backup we keep the previous tracing script under the name `callTracerLegacy`. Behaviour of both tracers are equivalent for the most part, although there are some small differences (improvements), where the new tracer is more correct / has more information.
2021-09-17 09:31:22 +02:00
|
|
|
}
|
2021-11-29 14:46:24 +01:00
|
|
|
return nil, errStopToken
|
2015-08-30 10:19:10 +02:00
|
|
|
}
|
|
|
|
|
2023-07-17 19:02:18 +02:00
|
|
|
func opSelfdestruct6780(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
if interpreter.readOnly {
|
|
|
|
return nil, ErrWriteProtection
|
|
|
|
}
|
|
|
|
beneficiary := scope.Stack.pop()
|
|
|
|
balance := interpreter.evm.StateDB.GetBalance(scope.Contract.Address())
|
|
|
|
interpreter.evm.StateDB.SubBalance(scope.Contract.Address(), balance)
|
|
|
|
interpreter.evm.StateDB.AddBalance(beneficiary.Bytes20(), balance)
|
|
|
|
interpreter.evm.StateDB.Selfdestruct6780(scope.Contract.Address())
|
|
|
|
if tracer := interpreter.evm.Config.Tracer; tracer != nil {
|
2024-01-23 14:51:58 +01:00
|
|
|
tracer.CaptureEnter(SELFDESTRUCT, scope.Contract.Address(), beneficiary.Bytes20(), []byte{}, 0, balance.ToBig())
|
2023-07-17 19:02:18 +02:00
|
|
|
tracer.CaptureExit([]byte{}, 0, nil)
|
|
|
|
}
|
|
|
|
return nil, errStopToken
|
|
|
|
}
|
|
|
|
|
2015-08-30 10:19:10 +02:00
|
|
|
// following functions are used by the instruction jump table
|
|
|
|
|
|
|
|
// make log instruction function
|
2017-01-05 11:52:10 +01:00
|
|
|
func makeLog(size int) executionFunc {
|
2021-03-25 10:13:14 +01:00
|
|
|
return func(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
2021-12-01 09:21:21 +00:00
|
|
|
if interpreter.readOnly {
|
|
|
|
return nil, ErrWriteProtection
|
|
|
|
}
|
2015-08-30 10:19:10 +02:00
|
|
|
topics := make([]common.Hash, size)
|
2021-03-25 10:13:14 +01:00
|
|
|
stack := scope.Stack
|
2020-06-08 14:24:40 +02:00
|
|
|
mStart, mSize := stack.pop(), stack.pop()
|
2015-08-30 10:19:10 +02:00
|
|
|
for i := 0; i < size; i++ {
|
2020-06-08 14:24:40 +02:00
|
|
|
addr := stack.pop()
|
2020-11-25 21:00:23 +01:00
|
|
|
topics[i] = addr.Bytes32()
|
2015-08-30 10:19:10 +02:00
|
|
|
}
|
|
|
|
|
2021-03-25 10:13:14 +01:00
|
|
|
d := scope.Memory.GetCopy(int64(mStart.Uint64()), int64(mSize.Uint64()))
|
2018-07-25 08:56:39 -04:00
|
|
|
interpreter.evm.StateDB.AddLog(&types.Log{
|
2021-03-25 10:13:14 +01:00
|
|
|
Address: scope.Contract.Address(),
|
2017-01-05 14:03:50 +01:00
|
|
|
Topics: topics,
|
|
|
|
Data: d,
|
|
|
|
// This is a non-consensus field, but assigned here because
|
|
|
|
// core/state doesn't know the current block number.
|
2020-11-13 13:42:19 +01:00
|
|
|
BlockNumber: interpreter.evm.Context.BlockNumber.Uint64(),
|
2017-01-05 14:03:50 +01:00
|
|
|
})
|
2017-01-04 20:17:24 +01:00
|
|
|
|
2017-01-05 11:52:10 +01:00
|
|
|
return nil, nil
|
2015-08-30 10:19:10 +02:00
|
|
|
}
|
|
|
|
}
|
2015-07-17 23:09:36 +02:00
|
|
|
|
2019-03-12 10:40:05 +01:00
|
|
|
// opPush1 is a specialized version of pushN
|
2021-03-25 10:13:14 +01:00
|
|
|
func opPush1(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
2019-03-12 10:40:05 +01:00
|
|
|
var (
|
2021-03-25 10:13:14 +01:00
|
|
|
codeLen = uint64(len(scope.Contract.Code))
|
2020-06-08 14:24:40 +02:00
|
|
|
integer = new(uint256.Int)
|
2019-03-12 10:40:05 +01:00
|
|
|
)
|
|
|
|
*pc += 1
|
|
|
|
if *pc < codeLen {
|
2021-03-25 10:13:14 +01:00
|
|
|
scope.Stack.push(integer.SetUint64(uint64(scope.Contract.Code[*pc])))
|
2019-03-12 10:40:05 +01:00
|
|
|
} else {
|
2021-03-25 10:13:14 +01:00
|
|
|
scope.Stack.push(integer.Clear())
|
2019-03-12 10:40:05 +01:00
|
|
|
}
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2015-08-30 10:19:10 +02:00
|
|
|
// make push instruction function
|
2017-05-23 10:39:53 +02:00
|
|
|
func makePush(size uint64, pushByteSize int) executionFunc {
|
2021-03-25 10:13:14 +01:00
|
|
|
return func(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
codeLen := len(scope.Contract.Code)
|
2017-05-23 10:39:53 +02:00
|
|
|
|
|
|
|
startMin := codeLen
|
|
|
|
if int(*pc+1) < startMin {
|
|
|
|
startMin = int(*pc + 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
endMin := codeLen
|
|
|
|
if startMin+pushByteSize < endMin {
|
|
|
|
endMin = startMin + pushByteSize
|
|
|
|
}
|
|
|
|
|
2020-06-08 14:24:40 +02:00
|
|
|
integer := new(uint256.Int)
|
2021-03-25 10:13:14 +01:00
|
|
|
scope.Stack.push(integer.SetBytes(common.RightPadBytes(
|
|
|
|
scope.Contract.Code[startMin:endMin], pushByteSize)))
|
2017-05-23 10:39:53 +02:00
|
|
|
|
2015-08-30 10:19:10 +02:00
|
|
|
*pc += size
|
2017-01-05 11:52:10 +01:00
|
|
|
return nil, nil
|
2015-08-30 10:19:10 +02:00
|
|
|
}
|
|
|
|
}
|
2015-07-17 23:09:36 +02:00
|
|
|
|
2018-05-23 14:02:10 +02:00
|
|
|
// make dup instruction function
|
2017-01-05 11:52:10 +01:00
|
|
|
func makeDup(size int64) executionFunc {
|
2021-03-25 10:13:14 +01:00
|
|
|
return func(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
scope.Stack.dup(int(size))
|
2017-01-05 11:52:10 +01:00
|
|
|
return nil, nil
|
2015-08-30 10:19:10 +02:00
|
|
|
}
|
|
|
|
}
|
2015-07-17 23:09:36 +02:00
|
|
|
|
2015-08-30 10:19:10 +02:00
|
|
|
// make swap instruction function
|
2017-01-05 11:52:10 +01:00
|
|
|
func makeSwap(size int64) executionFunc {
|
2015-08-30 10:19:10 +02:00
|
|
|
// switch n + 1 otherwise n would be swapped with n
|
2018-06-26 08:56:25 -04:00
|
|
|
size++
|
2021-03-25 10:13:14 +01:00
|
|
|
return func(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
scope.Stack.swap(int(size))
|
2017-01-05 11:52:10 +01:00
|
|
|
return nil, nil
|
2015-08-30 10:19:10 +02:00
|
|
|
}
|
2015-07-17 23:09:36 +02:00
|
|
|
}
|