2016-04-14 11:18:24 -05:00
|
|
|
// Copyright 2015 The go-ethereum Authors
|
2015-07-17 16:09:36 -05: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-01 19:20:41 -05:00
|
|
|
|
2015-07-17 16:09:36 -05:00
|
|
|
package vm
|
|
|
|
|
|
|
|
import (
|
2024-02-19 06:03:58 -06:00
|
|
|
"math"
|
|
|
|
|
2015-07-17 16:09:36 -05:00
|
|
|
"github.com/ethereum/go-ethereum/common"
|
2024-03-22 12:53:53 -05:00
|
|
|
"github.com/ethereum/go-ethereum/core/tracing"
|
2017-01-05 07:03:50 -06:00
|
|
|
"github.com/ethereum/go-ethereum/core/types"
|
2022-09-28 06:21:54 -05:00
|
|
|
"github.com/ethereum/go-ethereum/crypto"
|
2015-07-17 16:09:36 -05:00
|
|
|
"github.com/ethereum/go-ethereum/params"
|
2020-06-08 07:24:40 -05:00
|
|
|
"github.com/holiman/uint256"
|
2015-07-17 16:09:36 -05:00
|
|
|
)
|
|
|
|
|
2021-03-25 04:13:14 -05:00
|
|
|
func opAdd(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
x, y := scope.Stack.pop(), scope.Stack.peek()
|
2020-06-08 07:24:40 -05:00
|
|
|
y.Add(&x, y)
|
2017-01-05 04:52:10 -06:00
|
|
|
return nil, nil
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
|
|
|
|
2021-03-25 04:13:14 -05:00
|
|
|
func opSub(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
x, y := scope.Stack.pop(), scope.Stack.peek()
|
2020-06-08 07:24:40 -05:00
|
|
|
y.Sub(&x, y)
|
2017-01-05 04:52:10 -06:00
|
|
|
return nil, nil
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
|
|
|
|
2021-03-25 04:13:14 -05:00
|
|
|
func opMul(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
x, y := scope.Stack.pop(), scope.Stack.peek()
|
2020-06-08 07:24:40 -05:00
|
|
|
y.Mul(&x, y)
|
2017-01-05 04:52:10 -06:00
|
|
|
return nil, nil
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
|
|
|
|
2021-03-25 04:13:14 -05:00
|
|
|
func opDiv(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
x, y := scope.Stack.pop(), scope.Stack.peek()
|
2020-06-08 07:24:40 -05:00
|
|
|
y.Div(&x, y)
|
2017-01-05 04:52:10 -06:00
|
|
|
return nil, nil
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
|
|
|
|
2021-03-25 04:13:14 -05:00
|
|
|
func opSdiv(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
x, y := scope.Stack.pop(), scope.Stack.peek()
|
2020-06-08 07:24:40 -05:00
|
|
|
y.SDiv(&x, y)
|
2017-01-05 04:52:10 -06:00
|
|
|
return nil, nil
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
|
|
|
|
2021-03-25 04:13:14 -05:00
|
|
|
func opMod(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
x, y := scope.Stack.pop(), scope.Stack.peek()
|
2020-06-08 07:24:40 -05:00
|
|
|
y.Mod(&x, y)
|
2017-01-05 04:52:10 -06:00
|
|
|
return nil, nil
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
|
|
|
|
2021-03-25 04:13:14 -05:00
|
|
|
func opSmod(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
x, y := scope.Stack.pop(), scope.Stack.peek()
|
2020-06-08 07:24:40 -05:00
|
|
|
y.SMod(&x, y)
|
2017-01-05 04:52:10 -06:00
|
|
|
return nil, nil
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
|
|
|
|
2021-03-25 04:13:14 -05:00
|
|
|
func opExp(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
base, exponent := scope.Stack.pop(), scope.Stack.peek()
|
2020-06-08 07:24:40 -05:00
|
|
|
exponent.Exp(&base, exponent)
|
2017-01-05 04:52:10 -06:00
|
|
|
return nil, nil
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
|
|
|
|
2021-03-25 04:13:14 -05:00
|
|
|
func opSignExtend(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
back, num := scope.Stack.pop(), scope.Stack.peek()
|
2020-06-08 07:24:40 -05:00
|
|
|
num.ExtendSign(num, &back)
|
2017-01-05 04:52:10 -06:00
|
|
|
return nil, nil
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
|
|
|
|
2021-03-25 04:13:14 -05:00
|
|
|
func opNot(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
x := scope.Stack.peek()
|
2020-06-08 07:24:40 -05:00
|
|
|
x.Not(x)
|
2017-01-05 04:52:10 -06:00
|
|
|
return nil, nil
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
|
|
|
|
2021-03-25 04:13:14 -05:00
|
|
|
func opLt(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
x, y := scope.Stack.pop(), scope.Stack.peek()
|
2020-06-08 07:24:40 -05:00
|
|
|
if x.Lt(y) {
|
|
|
|
y.SetOne()
|
2015-07-17 16:09:36 -05:00
|
|
|
} else {
|
2020-06-08 07:24:40 -05:00
|
|
|
y.Clear()
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
2017-01-05 04:52:10 -06:00
|
|
|
return nil, nil
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
|
|
|
|
2021-03-25 04:13:14 -05:00
|
|
|
func opGt(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
x, y := scope.Stack.pop(), scope.Stack.peek()
|
2020-06-08 07:24:40 -05:00
|
|
|
if x.Gt(y) {
|
|
|
|
y.SetOne()
|
2015-07-17 16:09:36 -05:00
|
|
|
} else {
|
2020-06-08 07:24:40 -05:00
|
|
|
y.Clear()
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
2017-01-05 04:52:10 -06:00
|
|
|
return nil, nil
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
|
|
|
|
2021-03-25 04:13:14 -05:00
|
|
|
func opSlt(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
x, y := scope.Stack.pop(), scope.Stack.peek()
|
2020-06-08 07:24:40 -05:00
|
|
|
if x.Slt(y) {
|
|
|
|
y.SetOne()
|
|
|
|
} else {
|
|
|
|
y.Clear()
|
2018-03-08 06:48:19 -06:00
|
|
|
}
|
2017-01-05 04:52:10 -06:00
|
|
|
return nil, nil
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
|
|
|
|
2021-03-25 04:13:14 -05:00
|
|
|
func opSgt(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
x, y := scope.Stack.pop(), scope.Stack.peek()
|
2020-06-08 07:24:40 -05:00
|
|
|
if x.Sgt(y) {
|
|
|
|
y.SetOne()
|
|
|
|
} else {
|
|
|
|
y.Clear()
|
2018-03-08 06:48:19 -06:00
|
|
|
}
|
2017-01-05 04:52:10 -06:00
|
|
|
return nil, nil
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
|
|
|
|
2021-03-25 04:13:14 -05:00
|
|
|
func opEq(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
x, y := scope.Stack.pop(), scope.Stack.peek()
|
2020-06-08 07:24:40 -05:00
|
|
|
if x.Eq(y) {
|
|
|
|
y.SetOne()
|
2015-07-17 16:09:36 -05:00
|
|
|
} else {
|
2020-06-08 07:24:40 -05:00
|
|
|
y.Clear()
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
2017-01-05 04:52:10 -06:00
|
|
|
return nil, nil
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
|
|
|
|
2021-03-25 04:13:14 -05:00
|
|
|
func opIszero(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
x := scope.Stack.peek()
|
2020-06-08 07:24:40 -05:00
|
|
|
if x.IsZero() {
|
|
|
|
x.SetOne()
|
2015-07-17 16:09:36 -05:00
|
|
|
} else {
|
2020-06-08 07:24:40 -05:00
|
|
|
x.Clear()
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
2017-01-05 04:52:10 -06:00
|
|
|
return nil, nil
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
|
|
|
|
2021-03-25 04:13:14 -05:00
|
|
|
func opAnd(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
x, y := scope.Stack.pop(), scope.Stack.peek()
|
2020-06-08 07:24:40 -05:00
|
|
|
y.And(&x, y)
|
2017-01-05 04:52:10 -06:00
|
|
|
return nil, nil
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
2017-08-16 05:36:48 -05:00
|
|
|
|
2021-03-25 04:13:14 -05:00
|
|
|
func opOr(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
x, y := scope.Stack.pop(), scope.Stack.peek()
|
2020-06-08 07:24:40 -05:00
|
|
|
y.Or(&x, y)
|
2017-01-05 04:52:10 -06:00
|
|
|
return nil, nil
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
2017-08-16 05:36:48 -05:00
|
|
|
|
2021-03-25 04:13:14 -05:00
|
|
|
func opXor(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
x, y := scope.Stack.pop(), scope.Stack.peek()
|
2020-06-08 07:24:40 -05:00
|
|
|
y.Xor(&x, y)
|
2017-01-05 04:52:10 -06:00
|
|
|
return nil, nil
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
2017-02-28 08:09:11 -06:00
|
|
|
|
2021-03-25 04:13:14 -05:00
|
|
|
func opByte(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
th, val := scope.Stack.pop(), scope.Stack.peek()
|
2020-06-08 07:24:40 -05:00
|
|
|
val.Byte(&th)
|
2017-01-05 04:52:10 -06:00
|
|
|
return nil, nil
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
2017-08-16 05:36:48 -05:00
|
|
|
|
2021-03-25 04:13:14 -05:00
|
|
|
func opAddmod(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
x, y, z := scope.Stack.pop(), scope.Stack.pop(), scope.Stack.peek()
|
2024-04-30 07:08:13 -05:00
|
|
|
z.AddMod(&x, &y, z)
|
2017-01-05 04:52:10 -06:00
|
|
|
return nil, nil
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
2017-08-16 05:36:48 -05:00
|
|
|
|
2021-03-25 04:13:14 -05: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 07:24:40 -05:00
|
|
|
z.MulMod(&x, &y, z)
|
2017-01-05 04:52:10 -06:00
|
|
|
return nil, nil
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
|
|
|
|
2018-02-23 04:32:57 -06: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 04:13:14 -05:00
|
|
|
func opSHL(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
2018-02-23 04:32:57 -06:00
|
|
|
// Note, second operand is left in the stack; accumulate result into it, and no need to push it afterwards
|
2021-03-25 04:13:14 -05:00
|
|
|
shift, value := scope.Stack.pop(), scope.Stack.peek()
|
2020-06-08 07:24:40 -05:00
|
|
|
if shift.LtUint64(256) {
|
|
|
|
value.Lsh(value, uint(shift.Uint64()))
|
|
|
|
} else {
|
|
|
|
value.Clear()
|
2018-02-23 04:32:57 -06: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 04:13:14 -05:00
|
|
|
func opSHR(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
2018-02-23 04:32:57 -06:00
|
|
|
// Note, second operand is left in the stack; accumulate result into it, and no need to push it afterwards
|
2021-03-25 04:13:14 -05:00
|
|
|
shift, value := scope.Stack.pop(), scope.Stack.peek()
|
2020-06-08 07:24:40 -05:00
|
|
|
if shift.LtUint64(256) {
|
|
|
|
value.Rsh(value, uint(shift.Uint64()))
|
|
|
|
} else {
|
|
|
|
value.Clear()
|
2018-02-23 04:32:57 -06: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 04:13:14 -05:00
|
|
|
func opSAR(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
shift, value := scope.Stack.pop(), scope.Stack.peek()
|
2020-06-08 07:24:40 -05:00
|
|
|
if shift.GtUint64(256) {
|
2018-09-04 03:49:18 -05:00
|
|
|
if value.Sign() >= 0 {
|
2020-06-08 07:24:40 -05:00
|
|
|
value.Clear()
|
2018-02-23 04:32:57 -06:00
|
|
|
} else {
|
2020-06-08 07:24:40 -05:00
|
|
|
// Max negative shift: all bits set
|
|
|
|
value.SetAllOne()
|
2018-02-23 04:32:57 -06:00
|
|
|
}
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
n := uint(shift.Uint64())
|
2020-06-08 07:24:40 -05:00
|
|
|
value.SRsh(value, n)
|
2018-02-23 04:32:57 -06:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2021-11-30 03:34:34 -06:00
|
|
|
func opKeccak256(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
2021-03-25 04:13:14 -05:00
|
|
|
offset, size := scope.Stack.pop(), scope.Stack.peek()
|
2024-08-08 03:27:38 -05:00
|
|
|
data := scope.Memory.GetPtr(offset.Uint64(), size.Uint64())
|
2017-01-17 05:19:50 -06:00
|
|
|
|
2018-10-08 06:14:29 -05:00
|
|
|
if interpreter.hasher == nil {
|
2022-09-28 06:21:54 -05:00
|
|
|
interpreter.hasher = crypto.NewKeccakState()
|
2018-10-08 06:14:29 -05:00
|
|
|
} else {
|
|
|
|
interpreter.hasher.Reset()
|
|
|
|
}
|
|
|
|
interpreter.hasher.Write(data)
|
|
|
|
interpreter.hasher.Read(interpreter.hasherBuf[:])
|
|
|
|
|
|
|
|
evm := interpreter.evm
|
2021-06-10 00:02:51 -05:00
|
|
|
if evm.Config.EnablePreimageRecording {
|
2018-10-08 06:14:29 -05:00
|
|
|
evm.StateDB.AddPreimage(interpreter.hasherBuf, data)
|
2017-01-17 05:19:50 -06:00
|
|
|
}
|
2020-06-08 07:24:40 -05:00
|
|
|
size.SetBytes(interpreter.hasherBuf[:])
|
2017-01-05 04:52:10 -06:00
|
|
|
return nil, nil
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
2023-09-26 03:58:01 -05:00
|
|
|
|
2021-03-25 04:13:14 -05: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 04:52:10 -06:00
|
|
|
return nil, nil
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
|
|
|
|
2021-03-25 04:13:14 -05:00
|
|
|
func opBalance(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
slot := scope.Stack.peek()
|
2020-06-08 07:24:40 -05:00
|
|
|
address := common.Address(slot.Bytes20())
|
2024-01-23 07:51:58 -06:00
|
|
|
slot.Set(interpreter.evm.StateDB.GetBalance(address))
|
2017-01-05 04:52:10 -06:00
|
|
|
return nil, nil
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
|
|
|
|
2021-03-25 04:13:14 -05: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 04:52:10 -06:00
|
|
|
return nil, nil
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
2023-09-26 03:58:01 -05:00
|
|
|
|
2021-03-25 04:13:14 -05: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 04:52:10 -06:00
|
|
|
return nil, nil
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
|
|
|
|
2021-03-25 04:13:14 -05:00
|
|
|
func opCallValue(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
2024-01-23 07:51:58 -06:00
|
|
|
scope.Stack.push(scope.Contract.value)
|
2017-01-05 04:52:10 -06:00
|
|
|
return nil, nil
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
|
|
|
|
2021-03-25 04:13:14 -05:00
|
|
|
func opCallDataLoad(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
x := scope.Stack.peek()
|
2020-06-08 07:24:40 -05:00
|
|
|
if offset, overflow := x.Uint64WithOverflow(); !overflow {
|
2021-03-25 04:13:14 -05:00
|
|
|
data := getData(scope.Contract.Input, offset, 32)
|
2020-06-08 07:24:40 -05:00
|
|
|
x.SetBytes(data)
|
|
|
|
} else {
|
|
|
|
x.Clear()
|
|
|
|
}
|
2017-01-05 04:52:10 -06:00
|
|
|
return nil, nil
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
|
|
|
|
2021-03-25 04:13:14 -05: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 04:52:10 -06:00
|
|
|
return nil, nil
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
|
|
|
|
2021-03-25 04:13:14 -05:00
|
|
|
func opCallDataCopy(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
2015-07-17 16:09:36 -05:00
|
|
|
var (
|
2021-03-25 04:13:14 -05:00
|
|
|
memOffset = scope.Stack.pop()
|
|
|
|
dataOffset = scope.Stack.pop()
|
|
|
|
length = scope.Stack.pop()
|
2015-07-17 16:09:36 -05:00
|
|
|
)
|
2020-06-08 07:24:40 -05:00
|
|
|
dataOffset64, overflow := dataOffset.Uint64WithOverflow()
|
|
|
|
if overflow {
|
2024-02-28 01:25:12 -06:00
|
|
|
dataOffset64 = math.MaxUint64
|
2020-06-08 07:24:40 -05:00
|
|
|
}
|
|
|
|
// These values are checked for overflow during gas cost calculation
|
|
|
|
memOffset64 := memOffset.Uint64()
|
|
|
|
length64 := length.Uint64()
|
2021-03-25 04:13:14 -05:00
|
|
|
scope.Memory.Set(memOffset64, length64, getData(scope.Contract.Input, dataOffset64, length64))
|
2017-01-04 13:17:24 -06:00
|
|
|
|
2017-01-05 04:52:10 -06:00
|
|
|
return nil, nil
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
|
|
|
|
2021-03-25 04:13:14 -05: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 05:07:33 -05:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2021-03-25 04:13:14 -05:00
|
|
|
func opReturnDataCopy(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
2017-08-16 05:07:33 -05:00
|
|
|
var (
|
2021-03-25 04:13:14 -05:00
|
|
|
memOffset = scope.Stack.pop()
|
|
|
|
dataOffset = scope.Stack.pop()
|
|
|
|
length = scope.Stack.pop()
|
2017-08-16 05:07:33 -05:00
|
|
|
)
|
|
|
|
|
2020-06-08 07:24:40 -05:00
|
|
|
offset64, overflow := dataOffset.Uint64WithOverflow()
|
|
|
|
if overflow {
|
2020-04-22 03:25:36 -05:00
|
|
|
return nil, ErrReturnDataOutOfBounds
|
2017-08-16 05:07:33 -05:00
|
|
|
}
|
2020-06-08 07:24:40 -05: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 04:13:14 -05:00
|
|
|
scope.Memory.Set(memOffset.Uint64(), length.Uint64(), interpreter.returnData[offset64:end64])
|
2017-08-16 05:07:33 -05:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2021-03-25 04:13:14 -05:00
|
|
|
func opExtCodeSize(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
slot := scope.Stack.peek()
|
2020-11-25 14:00:23 -06:00
|
|
|
slot.SetUint64(uint64(interpreter.evm.StateDB.GetCodeSize(slot.Bytes20())))
|
2017-01-05 04:52:10 -06:00
|
|
|
return nil, nil
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
|
|
|
|
2021-03-25 04:13:14 -05:00
|
|
|
func opCodeSize(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
2024-02-07 10:01:38 -06:00
|
|
|
scope.Stack.push(new(uint256.Int).SetUint64(uint64(len(scope.Contract.Code))))
|
2017-01-05 04:52:10 -06:00
|
|
|
return nil, nil
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
|
|
|
|
2021-03-25 04:13:14 -05:00
|
|
|
func opCodeCopy(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
2015-07-17 16:09:36 -05:00
|
|
|
var (
|
2021-03-25 04:13:14 -05:00
|
|
|
memOffset = scope.Stack.pop()
|
|
|
|
codeOffset = scope.Stack.pop()
|
|
|
|
length = scope.Stack.pop()
|
2015-07-17 16:09:36 -05:00
|
|
|
)
|
2020-06-08 07:24:40 -05:00
|
|
|
uint64CodeOffset, overflow := codeOffset.Uint64WithOverflow()
|
|
|
|
if overflow {
|
2024-02-19 06:03:58 -06:00
|
|
|
uint64CodeOffset = math.MaxUint64
|
2020-06-08 07:24:40 -05:00
|
|
|
}
|
2024-05-10 13:13:11 -05:00
|
|
|
|
2021-03-25 04:13:14 -05:00
|
|
|
codeCopy := getData(scope.Contract.Code, uint64CodeOffset, length.Uint64())
|
|
|
|
scope.Memory.Set(memOffset.Uint64(), length.Uint64(), codeCopy)
|
2017-01-05 04:52:10 -06:00
|
|
|
return nil, nil
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
|
|
|
|
2021-03-25 04:13:14 -05:00
|
|
|
func opExtCodeCopy(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
2015-07-17 16:09:36 -05:00
|
|
|
var (
|
2021-03-25 04:13:14 -05:00
|
|
|
stack = scope.Stack
|
2020-06-08 07:24:40 -05:00
|
|
|
a = stack.pop()
|
|
|
|
memOffset = stack.pop()
|
|
|
|
codeOffset = stack.pop()
|
|
|
|
length = stack.pop()
|
2015-07-17 16:09:36 -05:00
|
|
|
)
|
2020-06-08 07:24:40 -05:00
|
|
|
uint64CodeOffset, overflow := codeOffset.Uint64WithOverflow()
|
|
|
|
if overflow {
|
2024-02-19 06:03:58 -06:00
|
|
|
uint64CodeOffset = math.MaxUint64
|
2020-06-08 07:24:40 -05:00
|
|
|
}
|
|
|
|
addr := common.Address(a.Bytes20())
|
2024-06-25 06:48:08 -05:00
|
|
|
code := interpreter.evm.StateDB.GetCode(addr)
|
|
|
|
codeCopy := getData(code, uint64CodeOffset, length.Uint64())
|
2021-03-25 04:13:14 -05:00
|
|
|
scope.Memory.Set(memOffset.Uint64(), length.Uint64(), codeCopy)
|
2017-01-04 13:17:24 -06:00
|
|
|
|
2017-01-05 04:52:10 -06:00
|
|
|
return nil, nil
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
|
|
|
|
2018-07-24 10:06:40 -05: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 06:25:40 -05: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 10:06:40 -05:00
|
|
|
//
|
2022-09-10 06:25:40 -05: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 10:06:40 -05:00
|
|
|
//
|
2022-09-10 06:25:40 -05: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 10:06:40 -05:00
|
|
|
//
|
2022-09-10 06:25:40 -05: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 10:06:40 -05:00
|
|
|
// customized chain, the return value will be zero.
|
|
|
|
//
|
2023-07-15 09:35:30 -05:00
|
|
|
// 5. Caller tries to get the code hash for an account which is marked as self-destructed
|
2022-09-10 06:25:40 -05:00
|
|
|
// in the current transaction, the code hash of this account should be returned.
|
2018-07-24 10:06:40 -05:00
|
|
|
//
|
2022-09-10 06:25:40 -05: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 04:13:14 -05:00
|
|
|
func opExtCodeHash(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
slot := scope.Stack.peek()
|
2020-06-08 07:24:40 -05:00
|
|
|
address := common.Address(slot.Bytes20())
|
2018-10-26 01:52:41 -05:00
|
|
|
if interpreter.evm.StateDB.Empty(address) {
|
2020-06-08 07:24:40 -05:00
|
|
|
slot.Clear()
|
2018-10-26 01:52:41 -05:00
|
|
|
} else {
|
|
|
|
slot.SetBytes(interpreter.evm.StateDB.GetCodeHash(address).Bytes())
|
|
|
|
}
|
2018-07-24 10:06:40 -05:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2021-03-25 04:13:14 -05:00
|
|
|
func opGasprice(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
2020-06-08 07:24:40 -05:00
|
|
|
v, _ := uint256.FromBig(interpreter.evm.GasPrice)
|
2021-03-25 04:13:14 -05:00
|
|
|
scope.Stack.push(v)
|
2017-01-05 04:52:10 -06:00
|
|
|
return nil, nil
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
|
|
|
|
2021-03-25 04:13:14 -05:00
|
|
|
func opBlockhash(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
num := scope.Stack.peek()
|
2020-06-08 07:24:40 -05:00
|
|
|
num64, overflow := num.Uint64WithOverflow()
|
|
|
|
if overflow {
|
|
|
|
num.Clear()
|
|
|
|
return nil, nil
|
|
|
|
}
|
2024-05-10 13:13:11 -05:00
|
|
|
|
2020-06-08 07:24:40 -05:00
|
|
|
var upper, lower uint64
|
2020-11-13 06:42:19 -06:00
|
|
|
upper = interpreter.evm.Context.BlockNumber.Uint64()
|
2020-06-08 07:24:40 -05:00
|
|
|
if upper < 257 {
|
|
|
|
lower = 0
|
2015-07-17 16:09:36 -05:00
|
|
|
} else {
|
2020-06-08 07:24:40 -05:00
|
|
|
lower = upper - 256
|
|
|
|
}
|
|
|
|
if num64 >= lower && num64 < upper {
|
2024-06-25 06:48:08 -05:00
|
|
|
res := interpreter.evm.Context.GetHash(num64)
|
|
|
|
if witness := interpreter.evm.StateDB.Witness(); witness != nil {
|
|
|
|
witness.AddBlockHash(num64)
|
|
|
|
}
|
|
|
|
num.SetBytes(res[:])
|
2020-06-08 07:24:40 -05:00
|
|
|
} else {
|
|
|
|
num.Clear()
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
2017-01-05 04:52:10 -06:00
|
|
|
return nil, nil
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
|
|
|
|
2021-03-25 04:13:14 -05: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 04:52:10 -06:00
|
|
|
return nil, nil
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
|
|
|
|
2021-03-25 04:13:14 -05:00
|
|
|
func opTimestamp(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
2023-01-25 05:12:28 -06:00
|
|
|
scope.Stack.push(new(uint256.Int).SetUint64(interpreter.evm.Context.Time))
|
2017-01-05 04:52:10 -06:00
|
|
|
return nil, nil
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
|
|
|
|
2021-03-25 04:13:14 -05:00
|
|
|
func opNumber(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
2020-11-13 06:42:19 -06:00
|
|
|
v, _ := uint256.FromBig(interpreter.evm.Context.BlockNumber)
|
2021-03-25 04:13:14 -05:00
|
|
|
scope.Stack.push(v)
|
2017-01-05 04:52:10 -06:00
|
|
|
return nil, nil
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
|
|
|
|
2021-03-25 04:13:14 -05:00
|
|
|
func opDifficulty(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
2020-11-13 06:42:19 -06:00
|
|
|
v, _ := uint256.FromBig(interpreter.evm.Context.Difficulty)
|
2021-03-25 04:13:14 -05:00
|
|
|
scope.Stack.push(v)
|
2017-01-05 04:52:10 -06:00
|
|
|
return nil, nil
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
|
|
|
|
2022-01-10 01:44:21 -06:00
|
|
|
func opRandom(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
2022-05-11 00:03:35 -05:00
|
|
|
v := new(uint256.Int).SetBytes(interpreter.evm.Context.Random.Bytes())
|
2022-01-10 01:44:21 -06:00
|
|
|
scope.Stack.push(v)
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2021-03-25 04:13:14 -05: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 04:52:10 -06:00
|
|
|
return nil, nil
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
|
|
|
|
2021-03-25 04:13:14 -05:00
|
|
|
func opPop(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
scope.Stack.pop()
|
2017-01-05 04:52:10 -06:00
|
|
|
return nil, nil
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
|
|
|
|
2021-03-25 04:13:14 -05:00
|
|
|
func opMload(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
v := scope.Stack.peek()
|
2024-08-08 03:27:38 -05:00
|
|
|
offset := v.Uint64()
|
2021-03-25 04:13:14 -05:00
|
|
|
v.SetBytes(scope.Memory.GetPtr(offset, 32))
|
2017-01-05 04:52:10 -06:00
|
|
|
return nil, nil
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
|
|
|
|
2021-03-25 04:13:14 -05:00
|
|
|
func opMstore(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
2015-07-17 16:09:36 -05:00
|
|
|
// pop value of the stack
|
2021-03-25 04:13:14 -05:00
|
|
|
mStart, val := scope.Stack.pop(), scope.Stack.pop()
|
|
|
|
scope.Memory.Set32(mStart.Uint64(), &val)
|
2017-01-05 04:52:10 -06:00
|
|
|
return nil, nil
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
|
|
|
|
2021-03-25 04:13:14 -05: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 04:52:10 -06:00
|
|
|
return nil, nil
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
|
|
|
|
2021-03-25 04:13:14 -05:00
|
|
|
func opSload(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
loc := scope.Stack.peek()
|
2020-06-08 07:24:40 -05:00
|
|
|
hash := common.Hash(loc.Bytes32())
|
2021-03-25 04:13:14 -05:00
|
|
|
val := interpreter.evm.StateDB.GetState(scope.Contract.Address(), hash)
|
2018-06-14 04:23:37 -05:00
|
|
|
loc.SetBytes(val.Bytes())
|
2017-01-05 04:52:10 -06:00
|
|
|
return nil, nil
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
|
|
|
|
2021-03-25 04:13:14 -05:00
|
|
|
func opSstore(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
2021-12-01 03:21:21 -06:00
|
|
|
if interpreter.readOnly {
|
|
|
|
return nil, ErrWriteProtection
|
|
|
|
}
|
2021-03-25 04:13:14 -05:00
|
|
|
loc := scope.Stack.pop()
|
|
|
|
val := scope.Stack.pop()
|
2022-11-16 03:18:52 -06:00
|
|
|
interpreter.evm.StateDB.SetState(scope.Contract.Address(), loc.Bytes32(), val.Bytes32())
|
2017-01-05 04:52:10 -06:00
|
|
|
return nil, nil
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
|
|
|
|
2021-03-25 04:13:14 -05:00
|
|
|
func opJump(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
2023-03-27 08:40:20 -05:00
|
|
|
if interpreter.evm.abort.Load() {
|
2021-12-03 04:10:26 -06:00
|
|
|
return nil, errStopToken
|
|
|
|
}
|
2021-03-25 04:13:14 -05:00
|
|
|
pos := scope.Stack.pop()
|
|
|
|
if !scope.Contract.validJumpdest(&pos) {
|
2020-04-22 03:25:36 -05:00
|
|
|
return nil, ErrInvalidJump
|
2017-01-05 04:52:10 -06:00
|
|
|
}
|
2021-11-29 07:46:24 -06:00
|
|
|
*pc = pos.Uint64() - 1 // pc will be increased by the interpreter loop
|
2017-01-05 04:52:10 -06:00
|
|
|
return nil, nil
|
2015-08-30 03:19:10 -05:00
|
|
|
}
|
2017-08-16 05:36:48 -05:00
|
|
|
|
2021-03-25 04:13:14 -05:00
|
|
|
func opJumpi(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
2023-03-27 08:40:20 -05:00
|
|
|
if interpreter.evm.abort.Load() {
|
2021-12-03 04:10:26 -06:00
|
|
|
return nil, errStopToken
|
|
|
|
}
|
2021-03-25 04:13:14 -05:00
|
|
|
pos, cond := scope.Stack.pop(), scope.Stack.pop()
|
2020-06-08 07:24:40 -05:00
|
|
|
if !cond.IsZero() {
|
2021-03-25 04:13:14 -05:00
|
|
|
if !scope.Contract.validJumpdest(&pos) {
|
2020-04-22 03:25:36 -05:00
|
|
|
return nil, ErrInvalidJump
|
2017-01-05 04:52:10 -06:00
|
|
|
}
|
2021-11-29 07:46:24 -06:00
|
|
|
*pc = pos.Uint64() - 1 // pc will be increased by the interpreter loop
|
2017-01-05 04:52:10 -06:00
|
|
|
}
|
|
|
|
return nil, nil
|
2015-08-30 03:19:10 -05:00
|
|
|
}
|
2017-08-16 05:36:48 -05:00
|
|
|
|
2021-03-25 04:13:14 -05:00
|
|
|
func opJumpdest(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
2017-01-05 04:52:10 -06:00
|
|
|
return nil, nil
|
2015-08-30 03:19:10 -05:00
|
|
|
}
|
2015-07-17 16:09:36 -05:00
|
|
|
|
2021-03-25 04:13:14 -05:00
|
|
|
func opPc(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
scope.Stack.push(new(uint256.Int).SetUint64(*pc))
|
2017-01-05 04:52:10 -06:00
|
|
|
return nil, nil
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
|
|
|
|
2021-03-25 04:13:14 -05: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 04:52:10 -06:00
|
|
|
return nil, nil
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
|
|
|
|
2021-03-25 04:13:14 -05:00
|
|
|
func opGas(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
scope.Stack.push(new(uint256.Int).SetUint64(scope.Contract.Gas))
|
2017-01-05 04:52:10 -06:00
|
|
|
return nil, nil
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
|
|
|
|
2024-08-06 07:38:47 -05:00
|
|
|
func opSwap1(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
scope.Stack.swap1()
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func opSwap2(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
scope.Stack.swap2()
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func opSwap3(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
scope.Stack.swap3()
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func opSwap4(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
scope.Stack.swap4()
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func opSwap5(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
scope.Stack.swap5()
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func opSwap6(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
scope.Stack.swap6()
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func opSwap7(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
scope.Stack.swap7()
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func opSwap8(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
scope.Stack.swap8()
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func opSwap9(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
scope.Stack.swap9()
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func opSwap10(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
scope.Stack.swap10()
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func opSwap11(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
scope.Stack.swap11()
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func opSwap12(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
scope.Stack.swap12()
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func opSwap13(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
scope.Stack.swap13()
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func opSwap14(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
scope.Stack.swap14()
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func opSwap15(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
scope.Stack.swap15()
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func opSwap16(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
scope.Stack.swap16()
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2021-03-25 04:13:14 -05:00
|
|
|
func opCreate(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
2021-12-01 03:21:21 -06:00
|
|
|
if interpreter.readOnly {
|
|
|
|
return nil, ErrWriteProtection
|
|
|
|
}
|
2016-01-19 16:50:00 -06:00
|
|
|
var (
|
2021-03-25 04:13:14 -05:00
|
|
|
value = scope.Stack.pop()
|
|
|
|
offset, size = scope.Stack.pop(), scope.Stack.pop()
|
2024-08-08 03:27:38 -05:00
|
|
|
input = scope.Memory.GetCopy(offset.Uint64(), size.Uint64())
|
2021-03-25 04:13:14 -05:00
|
|
|
gas = scope.Contract.Gas
|
2016-01-19 16:50:00 -06:00
|
|
|
)
|
2019-08-05 03:01:02 -05:00
|
|
|
if interpreter.evm.chainRules.IsEIP150 {
|
2017-01-04 13:17:24 -06:00
|
|
|
gas -= gas / 64
|
2016-10-07 17:23:45 -05:00
|
|
|
}
|
2024-05-10 13:13:11 -05:00
|
|
|
|
2020-06-08 07:24:40 -05:00
|
|
|
// reuse size int for stackvalue
|
|
|
|
stackvalue := size
|
2016-10-07 17:23:45 -05:00
|
|
|
|
2024-03-22 12:53:53 -05:00
|
|
|
scope.Contract.UseGas(gas, interpreter.evm.Config.Tracer, tracing.GasChangeCallContractCreation)
|
2020-07-16 07:06:19 -05:00
|
|
|
|
2024-01-23 07:51:58 -06:00
|
|
|
res, addr, returnGas, suberr := interpreter.evm.Create(scope.Contract, input, gas, &value)
|
2016-01-19 16:50:00 -06: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 03:01:02 -05:00
|
|
|
if interpreter.evm.chainRules.IsHomestead && suberr == ErrCodeStoreOutOfGas {
|
2020-06-08 07:24:40 -05:00
|
|
|
stackvalue.Clear()
|
2017-01-05 04:52:10 -06:00
|
|
|
} else if suberr != nil && suberr != ErrCodeStoreOutOfGas {
|
2020-06-08 07:24:40 -05:00
|
|
|
stackvalue.Clear()
|
2016-01-19 16:50:00 -06:00
|
|
|
} else {
|
2020-06-08 07:24:40 -05:00
|
|
|
stackvalue.SetBytes(addr.Bytes())
|
2016-01-19 16:50:00 -06:00
|
|
|
}
|
2021-03-25 04:13:14 -05:00
|
|
|
scope.Stack.push(&stackvalue)
|
2024-03-22 12:53:53 -05:00
|
|
|
|
|
|
|
scope.Contract.RefundGas(returnGas, interpreter.evm.Config.Tracer, tracing.GasChangeCallLeftOverRefunded)
|
2017-01-04 13:17:24 -06:00
|
|
|
|
2020-04-22 03:25:36 -05:00
|
|
|
if suberr == ErrExecutionReverted {
|
2021-11-29 07:46:24 -06:00
|
|
|
interpreter.returnData = res // set REVERT data to return data buffer
|
2017-08-16 09:09:29 -05:00
|
|
|
return res, nil
|
|
|
|
}
|
2021-11-29 07:46:24 -06:00
|
|
|
interpreter.returnData = nil // clear dirty return data buffer
|
2017-01-05 04:52:10 -06:00
|
|
|
return nil, nil
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
|
|
|
|
2021-03-25 04:13:14 -05:00
|
|
|
func opCreate2(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
2021-12-01 03:21:21 -06:00
|
|
|
if interpreter.readOnly {
|
|
|
|
return nil, ErrWriteProtection
|
|
|
|
}
|
2018-07-24 09:22:03 -05:00
|
|
|
var (
|
2021-03-25 04:13:14 -05:00
|
|
|
endowment = scope.Stack.pop()
|
|
|
|
offset, size = scope.Stack.pop(), scope.Stack.pop()
|
|
|
|
salt = scope.Stack.pop()
|
2024-08-08 03:27:38 -05:00
|
|
|
input = scope.Memory.GetCopy(offset.Uint64(), size.Uint64())
|
2021-03-25 04:13:14 -05:00
|
|
|
gas = scope.Contract.Gas
|
2018-07-24 09:22:03 -05:00
|
|
|
)
|
2024-05-10 13:13:11 -05:00
|
|
|
|
2018-07-24 09:22:03 -05:00
|
|
|
// Apply EIP150
|
|
|
|
gas -= gas / 64
|
2024-03-22 12:53:53 -05:00
|
|
|
scope.Contract.UseGas(gas, interpreter.evm.Config.Tracer, tracing.GasChangeCallContractCreation2)
|
2020-06-08 07:24:40 -05:00
|
|
|
// reuse size int for stackvalue
|
|
|
|
stackvalue := size
|
2021-03-25 04:13:14 -05:00
|
|
|
res, addr, returnGas, suberr := interpreter.evm.Create2(scope.Contract, input, gas,
|
2024-01-23 07:51:58 -06:00
|
|
|
&endowment, &salt)
|
2018-07-24 09:22:03 -05:00
|
|
|
// Push item on the stack based on the returned error.
|
|
|
|
if suberr != nil {
|
2020-06-08 07:24:40 -05:00
|
|
|
stackvalue.Clear()
|
2018-07-24 09:22:03 -05:00
|
|
|
} else {
|
2020-06-08 07:24:40 -05:00
|
|
|
stackvalue.SetBytes(addr.Bytes())
|
2018-07-24 09:22:03 -05:00
|
|
|
}
|
2021-03-25 04:13:14 -05:00
|
|
|
scope.Stack.push(&stackvalue)
|
2024-03-22 12:53:53 -05:00
|
|
|
scope.Contract.RefundGas(returnGas, interpreter.evm.Config.Tracer, tracing.GasChangeCallLeftOverRefunded)
|
2018-07-24 09:22:03 -05:00
|
|
|
|
2020-04-22 03:25:36 -05:00
|
|
|
if suberr == ErrExecutionReverted {
|
2021-11-29 07:46:24 -06:00
|
|
|
interpreter.returnData = res // set REVERT data to return data buffer
|
2018-07-24 09:22:03 -05:00
|
|
|
return res, nil
|
|
|
|
}
|
2021-11-29 07:46:24 -06:00
|
|
|
interpreter.returnData = nil // clear dirty return data buffer
|
2018-07-24 09:22:03 -05:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2021-03-25 04:13:14 -05:00
|
|
|
func opCall(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
stack := scope.Stack
|
2018-09-25 05:26:35 -05:00
|
|
|
// Pop gas. The actual gas in interpreter.evm.callGasTemp.
|
2020-06-08 07:24:40 -05:00
|
|
|
// We can use this as a temporary value
|
|
|
|
temp := stack.pop()
|
2018-07-25 07:56:39 -05:00
|
|
|
gas := interpreter.evm.callGasTemp
|
2017-11-28 13:05:49 -06:00
|
|
|
// Pop other call parameters.
|
2020-06-08 07:24:40 -05: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 13:05:49 -06:00
|
|
|
// Get the arguments from the memory.
|
2024-08-08 03:27:38 -05:00
|
|
|
args := scope.Memory.GetPtr(inOffset.Uint64(), inSize.Uint64())
|
2015-07-17 16:09:36 -05:00
|
|
|
|
2021-12-01 03:21:21 -06:00
|
|
|
if interpreter.readOnly && !value.IsZero() {
|
|
|
|
return nil, ErrWriteProtection
|
|
|
|
}
|
2020-06-08 07:24:40 -05:00
|
|
|
if !value.IsZero() {
|
2017-01-04 13:17:24 -06:00
|
|
|
gas += params.CallStipend
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
2024-01-23 07:51:58 -06:00
|
|
|
ret, returnGas, err := interpreter.evm.Call(scope.Contract, toAddr, args, gas, &value)
|
2020-07-16 07:06:19 -05:00
|
|
|
|
2015-07-17 16:09:36 -05:00
|
|
|
if err != nil {
|
2020-06-08 07:24:40 -05:00
|
|
|
temp.Clear()
|
2015-07-17 16:09:36 -05:00
|
|
|
} else {
|
2020-06-08 07:24:40 -05:00
|
|
|
temp.SetOne()
|
2017-08-16 09:09:29 -05:00
|
|
|
}
|
2020-06-08 07:24:40 -05:00
|
|
|
stack.push(&temp)
|
2020-04-22 03:25:36 -05:00
|
|
|
if err == nil || err == ErrExecutionReverted {
|
2021-03-25 04:13:14 -05:00
|
|
|
scope.Memory.Set(retOffset.Uint64(), retSize.Uint64(), ret)
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
2024-03-22 12:53:53 -05:00
|
|
|
|
|
|
|
scope.Contract.RefundGas(returnGas, interpreter.evm.Config.Tracer, tracing.GasChangeCallLeftOverRefunded)
|
2017-01-04 13:17:24 -06:00
|
|
|
|
2021-11-29 07:46:24 -06:00
|
|
|
interpreter.returnData = ret
|
2017-02-01 15:36:51 -06:00
|
|
|
return ret, nil
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
|
|
|
|
2021-03-25 04:13:14 -05:00
|
|
|
func opCallCode(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
2018-07-25 07:56:39 -05:00
|
|
|
// Pop gas. The actual gas is in interpreter.evm.callGasTemp.
|
2021-03-25 04:13:14 -05:00
|
|
|
stack := scope.Stack
|
2020-06-08 07:24:40 -05:00
|
|
|
// We use it as a temporary value
|
|
|
|
temp := stack.pop()
|
2018-07-25 07:56:39 -05:00
|
|
|
gas := interpreter.evm.callGasTemp
|
2017-11-28 13:05:49 -06:00
|
|
|
// Pop other call parameters.
|
2020-06-08 07:24:40 -05: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 13:05:49 -06:00
|
|
|
// Get arguments from the memory.
|
2024-08-08 03:27:38 -05:00
|
|
|
args := scope.Memory.GetPtr(inOffset.Uint64(), inSize.Uint64())
|
2015-07-17 16:09:36 -05:00
|
|
|
|
2020-06-08 07:24:40 -05:00
|
|
|
if !value.IsZero() {
|
2017-01-04 13:17:24 -06:00
|
|
|
gas += params.CallStipend
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
2020-07-16 07:06:19 -05:00
|
|
|
|
2024-01-23 07:51:58 -06:00
|
|
|
ret, returnGas, err := interpreter.evm.CallCode(scope.Contract, toAddr, args, gas, &value)
|
2015-07-17 16:09:36 -05:00
|
|
|
if err != nil {
|
2020-06-08 07:24:40 -05:00
|
|
|
temp.Clear()
|
2015-07-17 16:09:36 -05:00
|
|
|
} else {
|
2020-06-08 07:24:40 -05:00
|
|
|
temp.SetOne()
|
2017-08-16 09:09:29 -05:00
|
|
|
}
|
2020-06-08 07:24:40 -05:00
|
|
|
stack.push(&temp)
|
2020-04-22 03:25:36 -05:00
|
|
|
if err == nil || err == ErrExecutionReverted {
|
2021-03-25 04:13:14 -05:00
|
|
|
scope.Memory.Set(retOffset.Uint64(), retSize.Uint64(), ret)
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
2024-03-22 12:53:53 -05:00
|
|
|
|
|
|
|
scope.Contract.RefundGas(returnGas, interpreter.evm.Config.Tracer, tracing.GasChangeCallLeftOverRefunded)
|
2017-01-04 13:17:24 -06:00
|
|
|
|
2021-11-29 07:46:24 -06:00
|
|
|
interpreter.returnData = ret
|
2017-02-01 15:36:51 -06:00
|
|
|
return ret, nil
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
|
|
|
|
2021-03-25 04:13:14 -05:00
|
|
|
func opDelegateCall(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
stack := scope.Stack
|
2018-07-25 07:56:39 -05:00
|
|
|
// Pop gas. The actual gas is in interpreter.evm.callGasTemp.
|
2020-06-08 07:24:40 -05:00
|
|
|
// We use it as a temporary value
|
|
|
|
temp := stack.pop()
|
2018-07-25 07:56:39 -05:00
|
|
|
gas := interpreter.evm.callGasTemp
|
2017-11-28 13:05:49 -06:00
|
|
|
// Pop other call parameters.
|
2020-06-08 07:24:40 -05:00
|
|
|
addr, inOffset, inSize, retOffset, retSize := stack.pop(), stack.pop(), stack.pop(), stack.pop(), stack.pop()
|
|
|
|
toAddr := common.Address(addr.Bytes20())
|
2017-11-28 13:05:49 -06:00
|
|
|
// Get arguments from the memory.
|
2024-08-08 03:27:38 -05:00
|
|
|
args := scope.Memory.GetPtr(inOffset.Uint64(), inSize.Uint64())
|
2017-01-04 13:17:24 -06:00
|
|
|
|
2021-03-25 04:13:14 -05:00
|
|
|
ret, returnGas, err := interpreter.evm.DelegateCall(scope.Contract, toAddr, args, gas)
|
2015-11-27 08:40:29 -06:00
|
|
|
if err != nil {
|
2020-06-08 07:24:40 -05:00
|
|
|
temp.Clear()
|
2015-11-27 08:40:29 -06:00
|
|
|
} else {
|
2020-06-08 07:24:40 -05:00
|
|
|
temp.SetOne()
|
2017-08-16 09:09:29 -05:00
|
|
|
}
|
2020-06-08 07:24:40 -05:00
|
|
|
stack.push(&temp)
|
2020-04-22 03:25:36 -05:00
|
|
|
if err == nil || err == ErrExecutionReverted {
|
2021-03-25 04:13:14 -05:00
|
|
|
scope.Memory.Set(retOffset.Uint64(), retSize.Uint64(), ret)
|
2015-11-27 08:40:29 -06:00
|
|
|
}
|
2024-03-22 12:53:53 -05:00
|
|
|
|
|
|
|
scope.Contract.RefundGas(returnGas, interpreter.evm.Config.Tracer, tracing.GasChangeCallLeftOverRefunded)
|
2017-01-04 13:17:24 -06:00
|
|
|
|
2021-11-29 07:46:24 -06:00
|
|
|
interpreter.returnData = ret
|
2017-02-01 15:36:51 -06:00
|
|
|
return ret, nil
|
2015-11-27 08:40:29 -06:00
|
|
|
}
|
|
|
|
|
2021-03-25 04:13:14 -05:00
|
|
|
func opStaticCall(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
2018-07-25 07:56:39 -05:00
|
|
|
// Pop gas. The actual gas is in interpreter.evm.callGasTemp.
|
2021-03-25 04:13:14 -05:00
|
|
|
stack := scope.Stack
|
2020-06-08 07:24:40 -05:00
|
|
|
// We use it as a temporary value
|
|
|
|
temp := stack.pop()
|
2018-07-25 07:56:39 -05:00
|
|
|
gas := interpreter.evm.callGasTemp
|
2017-11-28 13:05:49 -06:00
|
|
|
// Pop other call parameters.
|
2020-06-08 07:24:40 -05:00
|
|
|
addr, inOffset, inSize, retOffset, retSize := stack.pop(), stack.pop(), stack.pop(), stack.pop(), stack.pop()
|
|
|
|
toAddr := common.Address(addr.Bytes20())
|
2017-11-28 13:05:49 -06:00
|
|
|
// Get arguments from the memory.
|
2024-08-08 03:27:38 -05:00
|
|
|
args := scope.Memory.GetPtr(inOffset.Uint64(), inSize.Uint64())
|
2017-08-15 03:23:23 -05:00
|
|
|
|
2021-03-25 04:13:14 -05:00
|
|
|
ret, returnGas, err := interpreter.evm.StaticCall(scope.Contract, toAddr, args, gas)
|
2017-08-15 03:23:23 -05:00
|
|
|
if err != nil {
|
2020-06-08 07:24:40 -05:00
|
|
|
temp.Clear()
|
2017-08-15 03:23:23 -05:00
|
|
|
} else {
|
2020-06-08 07:24:40 -05:00
|
|
|
temp.SetOne()
|
2017-08-16 09:09:29 -05:00
|
|
|
}
|
2020-06-08 07:24:40 -05:00
|
|
|
stack.push(&temp)
|
2020-04-22 03:25:36 -05:00
|
|
|
if err == nil || err == ErrExecutionReverted {
|
2021-03-25 04:13:14 -05:00
|
|
|
scope.Memory.Set(retOffset.Uint64(), retSize.Uint64(), ret)
|
2017-08-15 03:23:23 -05:00
|
|
|
}
|
2024-03-22 12:53:53 -05:00
|
|
|
|
|
|
|
scope.Contract.RefundGas(returnGas, interpreter.evm.Config.Tracer, tracing.GasChangeCallLeftOverRefunded)
|
2017-08-15 03:23:23 -05:00
|
|
|
|
2021-11-29 07:46:24 -06:00
|
|
|
interpreter.returnData = ret
|
2017-08-15 03:23:23 -05:00
|
|
|
return ret, nil
|
|
|
|
}
|
|
|
|
|
2021-03-25 04:13:14 -05:00
|
|
|
func opReturn(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
offset, size := scope.Stack.pop(), scope.Stack.pop()
|
2024-08-20 07:31:06 -05:00
|
|
|
ret := scope.Memory.GetCopy(offset.Uint64(), size.Uint64())
|
2017-01-05 04:52:10 -06:00
|
|
|
|
2021-11-29 07:46:24 -06:00
|
|
|
return ret, errStopToken
|
2017-08-16 07:32:59 -05:00
|
|
|
}
|
2017-02-01 15:36:51 -06:00
|
|
|
|
2021-03-25 04:13:14 -05:00
|
|
|
func opRevert(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
offset, size := scope.Stack.pop(), scope.Stack.pop()
|
2024-08-20 07:31:06 -05:00
|
|
|
ret := scope.Memory.GetCopy(offset.Uint64(), size.Uint64())
|
2017-08-16 07:32:59 -05:00
|
|
|
|
2021-11-29 07:46:24 -06:00
|
|
|
interpreter.returnData = ret
|
|
|
|
return ret, ErrExecutionReverted
|
2015-08-30 03:19:10 -05:00
|
|
|
}
|
2017-01-05 04:52:10 -06:00
|
|
|
|
2021-12-03 04:04:54 -06:00
|
|
|
func opUndefined(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
return nil, &ErrInvalidOpCode{opcode: OpCode(scope.Contract.Code[*pc])}
|
|
|
|
}
|
|
|
|
|
2021-03-25 04:13:14 -05:00
|
|
|
func opStop(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
2021-11-29 07:46:24 -06:00
|
|
|
return nil, errStopToken
|
2015-08-30 03:19:10 -05:00
|
|
|
}
|
|
|
|
|
2021-12-01 03:33:29 -06:00
|
|
|
func opSelfdestruct(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
2021-12-01 03:21:21 -06:00
|
|
|
if interpreter.readOnly {
|
|
|
|
return nil, ErrWriteProtection
|
|
|
|
}
|
2021-03-25 04:13:14 -05:00
|
|
|
beneficiary := scope.Stack.pop()
|
|
|
|
balance := interpreter.evm.StateDB.GetBalance(scope.Contract.Address())
|
2024-03-22 12:53:53 -05:00
|
|
|
interpreter.evm.StateDB.AddBalance(beneficiary.Bytes20(), balance, tracing.BalanceIncreaseSelfdestruct)
|
2023-07-15 09:35:30 -05:00
|
|
|
interpreter.evm.StateDB.SelfDestruct(scope.Contract.Address())
|
2023-04-04 08:50:13 -05:00
|
|
|
if tracer := interpreter.evm.Config.Tracer; tracer != nil {
|
2024-03-22 12:53:53 -05:00
|
|
|
if tracer.OnEnter != nil {
|
|
|
|
tracer.OnEnter(interpreter.evm.depth, byte(SELFDESTRUCT), scope.Contract.Address(), beneficiary.Bytes20(), []byte{}, 0, balance.ToBig())
|
|
|
|
}
|
|
|
|
if tracer.OnExit != nil {
|
|
|
|
tracer.OnExit(interpreter.evm.depth, []byte{}, 0, nil, false)
|
|
|
|
}
|
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 02:31:22 -05:00
|
|
|
}
|
2021-11-29 07:46:24 -06:00
|
|
|
return nil, errStopToken
|
2015-08-30 03:19:10 -05:00
|
|
|
}
|
|
|
|
|
2023-07-17 12:02:18 -05: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())
|
2024-03-22 12:53:53 -05:00
|
|
|
interpreter.evm.StateDB.SubBalance(scope.Contract.Address(), balance, tracing.BalanceDecreaseSelfdestruct)
|
|
|
|
interpreter.evm.StateDB.AddBalance(beneficiary.Bytes20(), balance, tracing.BalanceIncreaseSelfdestruct)
|
core/state: move state log mechanism to a separate layer (#30569)
This PR moves the logging/tracing-facilities out of `*state.StateDB`,
in to a wrapping struct which implements `vm.StateDB` instead.
In most places, it is a pretty straight-forward change:
- First, hoisting the invocations from state objects up to the statedb.
- Then making the mutation-methods simply return the previous value, so
that the external logging layer could log everything.
Some internal code uses the direct object-accessors to mutate the state,
particularly in testing and in setting up state overrides, which means
that these changes are unobservable for the hooked layer. Thus, configuring
the overrides are not necessarily part of the API we want to publish.
The trickiest part about the layering is that when the selfdestructs are
finally deleted during `Finalise`, there's the possibility that someone
sent some ether to it, which is burnt at that point, and thus needs to
be logged. The hooked layer reaches into the inner layer to figure out
these events.
In package `vm`, the conversion from `state.StateDB + hooks` into a
hooked `vm.StateDB` is performed where needed.
---------
Co-authored-by: Gary Rong <garyrong0905@gmail.com>
2024-10-23 01:03:36 -05:00
|
|
|
interpreter.evm.StateDB.SelfDestruct6780(scope.Contract.Address())
|
2023-07-17 12:02:18 -05:00
|
|
|
if tracer := interpreter.evm.Config.Tracer; tracer != nil {
|
2024-03-22 12:53:53 -05:00
|
|
|
if tracer.OnEnter != nil {
|
|
|
|
tracer.OnEnter(interpreter.evm.depth, byte(SELFDESTRUCT), scope.Contract.Address(), beneficiary.Bytes20(), []byte{}, 0, balance.ToBig())
|
|
|
|
}
|
|
|
|
if tracer.OnExit != nil {
|
|
|
|
tracer.OnExit(interpreter.evm.depth, []byte{}, 0, nil, false)
|
|
|
|
}
|
2023-07-17 12:02:18 -05:00
|
|
|
}
|
|
|
|
return nil, errStopToken
|
|
|
|
}
|
|
|
|
|
2015-08-30 03:19:10 -05:00
|
|
|
// following functions are used by the instruction jump table
|
|
|
|
|
|
|
|
// make log instruction function
|
2017-01-05 04:52:10 -06:00
|
|
|
func makeLog(size int) executionFunc {
|
2021-03-25 04:13:14 -05:00
|
|
|
return func(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
2021-12-01 03:21:21 -06:00
|
|
|
if interpreter.readOnly {
|
|
|
|
return nil, ErrWriteProtection
|
|
|
|
}
|
2015-08-30 03:19:10 -05:00
|
|
|
topics := make([]common.Hash, size)
|
2021-03-25 04:13:14 -05:00
|
|
|
stack := scope.Stack
|
2020-06-08 07:24:40 -05:00
|
|
|
mStart, mSize := stack.pop(), stack.pop()
|
2015-08-30 03:19:10 -05:00
|
|
|
for i := 0; i < size; i++ {
|
2020-06-08 07:24:40 -05:00
|
|
|
addr := stack.pop()
|
2020-11-25 14:00:23 -06:00
|
|
|
topics[i] = addr.Bytes32()
|
2015-08-30 03:19:10 -05:00
|
|
|
}
|
|
|
|
|
2024-08-08 03:27:38 -05:00
|
|
|
d := scope.Memory.GetCopy(mStart.Uint64(), mSize.Uint64())
|
2018-07-25 07:56:39 -05:00
|
|
|
interpreter.evm.StateDB.AddLog(&types.Log{
|
2021-03-25 04:13:14 -05:00
|
|
|
Address: scope.Contract.Address(),
|
2017-01-05 07:03:50 -06: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 06:42:19 -06:00
|
|
|
BlockNumber: interpreter.evm.Context.BlockNumber.Uint64(),
|
2017-01-05 07:03:50 -06:00
|
|
|
})
|
2017-01-04 13:17:24 -06:00
|
|
|
|
2017-01-05 04:52:10 -06:00
|
|
|
return nil, nil
|
2015-08-30 03:19:10 -05:00
|
|
|
}
|
|
|
|
}
|
2015-07-17 16:09:36 -05:00
|
|
|
|
2019-03-12 04:40:05 -05:00
|
|
|
// opPush1 is a specialized version of pushN
|
2021-03-25 04:13:14 -05:00
|
|
|
func opPush1(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
2019-03-12 04:40:05 -05:00
|
|
|
var (
|
2021-03-25 04:13:14 -05:00
|
|
|
codeLen = uint64(len(scope.Contract.Code))
|
2020-06-08 07:24:40 -05:00
|
|
|
integer = new(uint256.Int)
|
2019-03-12 04:40:05 -05:00
|
|
|
)
|
|
|
|
*pc += 1
|
|
|
|
if *pc < codeLen {
|
2021-03-25 04:13:14 -05:00
|
|
|
scope.Stack.push(integer.SetUint64(uint64(scope.Contract.Code[*pc])))
|
2019-03-12 04:40:05 -05:00
|
|
|
} else {
|
2021-03-25 04:13:14 -05:00
|
|
|
scope.Stack.push(integer.Clear())
|
2019-03-12 04:40:05 -05:00
|
|
|
}
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2015-08-30 03:19:10 -05:00
|
|
|
// make push instruction function
|
2017-05-23 03:39:53 -05:00
|
|
|
func makePush(size uint64, pushByteSize int) executionFunc {
|
2021-03-25 04:13:14 -05:00
|
|
|
return func(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
2024-04-16 07:57:57 -05:00
|
|
|
var (
|
|
|
|
codeLen = len(scope.Contract.Code)
|
|
|
|
start = min(codeLen, int(*pc+1))
|
|
|
|
end = min(codeLen, start+pushByteSize)
|
|
|
|
)
|
2024-10-30 12:01:47 -05:00
|
|
|
a := new(uint256.Int).SetBytes(scope.Contract.Code[start:end])
|
2024-05-10 13:13:11 -05:00
|
|
|
|
2024-10-30 12:01:47 -05:00
|
|
|
// Missing bytes: pushByteSize - len(pushData)
|
|
|
|
if missing := pushByteSize - (end - start); missing > 0 {
|
|
|
|
a.Lsh(a, uint(8*missing))
|
|
|
|
}
|
|
|
|
scope.Stack.push(a)
|
2015-08-30 03:19:10 -05:00
|
|
|
*pc += size
|
2017-01-05 04:52:10 -06:00
|
|
|
return nil, nil
|
2015-08-30 03:19:10 -05:00
|
|
|
}
|
|
|
|
}
|
2015-07-17 16:09:36 -05:00
|
|
|
|
2018-05-23 07:02:10 -05:00
|
|
|
// make dup instruction function
|
2017-01-05 04:52:10 -06:00
|
|
|
func makeDup(size int64) executionFunc {
|
2021-03-25 04:13:14 -05:00
|
|
|
return func(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
|
|
|
|
scope.Stack.dup(int(size))
|
2017-01-05 04:52:10 -06:00
|
|
|
return nil, nil
|
2015-08-30 03:19:10 -05:00
|
|
|
}
|
|
|
|
}
|