2018-02-14 12:49:11 +00:00
|
|
|
// Copyright 2017 The go-ethereum Authors
|
cmd, core, eth/tracers: support fancier js tracing (#15516)
* cmd, core, eth/tracers: support fancier js tracing
* eth, internal/web3ext: rework trace API, concurrency, chain tracing
* eth/tracers: add three more JavaScript tracers
* eth/tracers, vendor: swap ottovm to duktape for tracing
* core, eth, internal: finalize call tracer and needed extras
* eth, tests: prestate tracer, call test suite, rewinding
* vendor: fix windows builds for tracer js engine
* vendor: temporary duktape fix
* eth/tracers: fix up 4byte and evmdis tracer
* vendor: pull in latest duktape with my upstream fixes
* eth: fix some review comments
* eth: rename rewind to reexec to make it more obvious
* core/vm: terminate tracing using defers
2017-12-21 11:56:11 +00: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/>.
|
|
|
|
|
|
|
|
package tracers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"math/big"
|
|
|
|
"sync/atomic"
|
|
|
|
"time"
|
|
|
|
"unsafe"
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
|
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
2020-12-27 20:57:19 +00:00
|
|
|
"github.com/ethereum/go-ethereum/core"
|
cmd, core, eth/tracers: support fancier js tracing (#15516)
* cmd, core, eth/tracers: support fancier js tracing
* eth, internal/web3ext: rework trace API, concurrency, chain tracing
* eth/tracers: add three more JavaScript tracers
* eth/tracers, vendor: swap ottovm to duktape for tracing
* core, eth, internal: finalize call tracer and needed extras
* eth, tests: prestate tracer, call test suite, rewinding
* vendor: fix windows builds for tracer js engine
* vendor: temporary duktape fix
* eth/tracers: fix up 4byte and evmdis tracer
* vendor: pull in latest duktape with my upstream fixes
* eth: fix some review comments
* eth: rename rewind to reexec to make it more obvious
* core/vm: terminate tracing using defers
2017-12-21 11:56:11 +00:00
|
|
|
"github.com/ethereum/go-ethereum/core/vm"
|
|
|
|
"github.com/ethereum/go-ethereum/crypto"
|
|
|
|
"github.com/ethereum/go-ethereum/log"
|
2021-02-02 09:32:44 +00:00
|
|
|
"gopkg.in/olebedev/go-duktape.v3"
|
cmd, core, eth/tracers: support fancier js tracing (#15516)
* cmd, core, eth/tracers: support fancier js tracing
* eth, internal/web3ext: rework trace API, concurrency, chain tracing
* eth/tracers: add three more JavaScript tracers
* eth/tracers, vendor: swap ottovm to duktape for tracing
* core, eth, internal: finalize call tracer and needed extras
* eth, tests: prestate tracer, call test suite, rewinding
* vendor: fix windows builds for tracer js engine
* vendor: temporary duktape fix
* eth/tracers: fix up 4byte and evmdis tracer
* vendor: pull in latest duktape with my upstream fixes
* eth: fix some review comments
* eth: rename rewind to reexec to make it more obvious
* core/vm: terminate tracing using defers
2017-12-21 11:56:11 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// bigIntegerJS is the minified version of https://github.com/peterolson/BigInteger.js.
|
|
|
|
const bigIntegerJS = `var bigInt=function(undefined){"use strict";var BASE=1e7,LOG_BASE=7,MAX_INT=9007199254740992,MAX_INT_ARR=smallToArray(MAX_INT),LOG_MAX_INT=Math.log(MAX_INT);function Integer(v,radix){if(typeof v==="undefined")return Integer[0];if(typeof radix!=="undefined")return+radix===10?parseValue(v):parseBase(v,radix);return parseValue(v)}function BigInteger(value,sign){this.value=value;this.sign=sign;this.isSmall=false}BigInteger.prototype=Object.create(Integer.prototype);function SmallInteger(value){this.value=value;this.sign=value<0;this.isSmall=true}SmallInteger.prototype=Object.create(Integer.prototype);function isPrecise(n){return-MAX_INT<n&&n<MAX_INT}function smallToArray(n){if(n<1e7)return[n];if(n<1e14)return[n%1e7,Math.floor(n/1e7)];return[n%1e7,Math.floor(n/1e7)%1e7,Math.floor(n/1e14)]}function arrayToSmall(arr){trim(arr);var length=arr.length;if(length<4&&compareAbs(arr,MAX_INT_ARR)<0){switch(length){case 0:return 0;case 1:return arr[0];case 2:return arr[0]+arr[1]*BASE;default:return arr[0]+(arr[1]+arr[2]*BASE)*BASE}}return arr}function trim(v){var i=v.length;while(v[--i]===0);v.length=i+1}function createArray(length){var x=new Array(length);var i=-1;while(++i<length){x[i]=0}return x}function truncate(n){if(n>0)return Math.floor(n);return Math.ceil(n)}function add(a,b){var l_a=a.length,l_b=b.length,r=new Array(l_a),carry=0,base=BASE,sum,i;for(i=0;i<l_b;i++){sum=a[i]+b[i]+carry;carry=sum>=base?1:0;r[i]=sum-carry*base}while(i<l_a){sum=a[i]+carry;carry=sum===base?1:0;r[i++]=sum-carry*base}if(carry>0)r.push(carry);return r}function addAny(a,b){if(a.length>=b.length)return add(a,b);return add(b,a)}function addSmall(a,carry){var l=a.length,r=new Array(l),base=BASE,sum,i;for(i=0;i<l;i++){sum=a[i]-base+carry;carry=Math.floor(sum/base);r[i]=sum-carry*base;carry+=1}while(carry>0){r[i++]=carry%base;carry=Math.floor(carry/base)}return r}BigInteger.prototype.add=function(v){var n=parseValue(v);if(this.sign!==n.sign){return this.subtract(n.negate())}var a=this.value,b=n.value;if(n.isSmall){return new BigInteger(addSmall(a,Math.abs(b)),this.sign)}return new BigInteger(addAny(a,b),this.sign)};BigInteger.prototype.plus=BigInteger.prototype.add;SmallInteger.prototype.add=function(v){var n=parseValue(v);var a=this.value;if(a<0!==n.sign){return this.subtract(n.negate())}var b=n.value;if(n.isSmall){if(isPrecise(a+b))return new SmallInteger(a+b);b=smallToArray(Math.abs(b))}return new BigInteger(addSmall(b,Math.abs(a)),a<0)};SmallInteger.prototype.plus=SmallInteger.prototype.add;function subtract(a,b){var a_l=a.length,b_l=b.length,r=new Array(a_l),borrow=0,base=BASE,i,difference;for(i=0;i<b_l;i++){difference=a[i]-borrow-b[i];if(difference<0){difference+=base;borrow=1}else borrow=0;r[i]=difference}for(i=b_l;i<a_l;i++){difference=a[i]-borrow;if(difference<0)difference+=base;else{r[i++]=difference;break}r[i]=difference}for(;i<a_l;i++){r[i]=a[i]}trim(r);return r}function subtractAny(a,b,sign){var value;if(compareAbs(a,b)>=0){value=subtract(a,b)}else{value=subtract(b,a);sign=!sign}value=arrayToSmall(value);if(typeof value==="number"){if(sign)value=-value;return new SmallInteger(value)}return new BigInteger(value,sign)}function subtractSmall(a,b,sign){var l=a.length,r=new Array(l),carry=-b,base=BASE,i,difference;for(i=0;i<l;i++){difference=a[i]+carry;carry=Math.floor(difference/base);difference%=base;r[i]=difference<0?difference+base:difference}r=arrayToSmall(r);if(typeof r==="number"){if(sign)r=-r;return new SmallInteger(r)}return new BigInteger(r,sign)}BigInteger.prototype.subtract=function(v){var n=parseValue(v);if(this.sign!==n.sign){return this.add(n.negate())}var a=this.value,b=n.value;if(n.isSmall)return subtractSmall(a,Math.abs(b),this.sign);return subtractAny(a,b,this.sign)};BigInteger.prototype.minus=BigInteger.prototype.subtract;SmallInteger.prototype.subtract=function(v){var n=parseValue(v);var a=this.value;if(a<0!==n.sign){return this.add(n.negate())}var b=n.value;if(n.isSmall){return new SmallInteger(a-b)}return subtractSmall(b,Math.abs(a),a>=0)};SmallInteger.prototype.minus=SmallInteger.prototype.subtract;BigInte
|
|
|
|
|
|
|
|
// makeSlice convert an unsafe memory pointer with the given type into a Go byte
|
|
|
|
// slice.
|
|
|
|
//
|
|
|
|
// Note, the returned slice uses the same memory area as the input arguments.
|
|
|
|
// If those are duktape stack items, popping them off **will** make the slice
|
|
|
|
// contents change.
|
|
|
|
func makeSlice(ptr unsafe.Pointer, size uint) []byte {
|
|
|
|
var sl = struct {
|
|
|
|
addr uintptr
|
|
|
|
len int
|
|
|
|
cap int
|
|
|
|
}{uintptr(ptr), int(size), int(size)}
|
|
|
|
|
|
|
|
return *(*[]byte)(unsafe.Pointer(&sl))
|
|
|
|
}
|
|
|
|
|
|
|
|
// popSlice pops a buffer off the JavaScript stack and returns it as a slice.
|
|
|
|
func popSlice(ctx *duktape.Context) []byte {
|
|
|
|
blob := common.CopyBytes(makeSlice(ctx.GetBuffer(-1)))
|
|
|
|
ctx.Pop()
|
|
|
|
return blob
|
|
|
|
}
|
|
|
|
|
|
|
|
// pushBigInt create a JavaScript BigInteger in the VM.
|
|
|
|
func pushBigInt(n *big.Int, ctx *duktape.Context) {
|
|
|
|
ctx.GetGlobalString("bigInt")
|
|
|
|
ctx.PushString(n.String())
|
|
|
|
ctx.Call(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
// opWrapper provides a JavaScript wrapper around OpCode.
|
|
|
|
type opWrapper struct {
|
|
|
|
op vm.OpCode
|
|
|
|
}
|
|
|
|
|
|
|
|
// pushObject assembles a JSVM object wrapping a swappable opcode and pushes it
|
|
|
|
// onto the VM stack.
|
|
|
|
func (ow *opWrapper) pushObject(vm *duktape.Context) {
|
|
|
|
obj := vm.PushObject()
|
|
|
|
|
|
|
|
vm.PushGoFunction(func(ctx *duktape.Context) int { ctx.PushInt(int(ow.op)); return 1 })
|
|
|
|
vm.PutPropString(obj, "toNumber")
|
|
|
|
|
|
|
|
vm.PushGoFunction(func(ctx *duktape.Context) int { ctx.PushString(ow.op.String()); return 1 })
|
|
|
|
vm.PutPropString(obj, "toString")
|
|
|
|
|
|
|
|
vm.PushGoFunction(func(ctx *duktape.Context) int { ctx.PushBoolean(ow.op.IsPush()); return 1 })
|
|
|
|
vm.PutPropString(obj, "isPush")
|
|
|
|
}
|
|
|
|
|
|
|
|
// memoryWrapper provides a JavaScript wrapper around vm.Memory.
|
|
|
|
type memoryWrapper struct {
|
|
|
|
memory *vm.Memory
|
|
|
|
}
|
|
|
|
|
|
|
|
// slice returns the requested range of memory as a byte slice.
|
|
|
|
func (mw *memoryWrapper) slice(begin, end int64) []byte {
|
2020-02-04 08:55:07 +00:00
|
|
|
if end == begin {
|
|
|
|
return []byte{}
|
|
|
|
}
|
|
|
|
if end < begin || begin < 0 {
|
|
|
|
// TODO(karalabe): We can't js-throw from Go inside duktape inside Go. The Go
|
|
|
|
// runtime goes belly up https://github.com/golang/go/issues/15639.
|
|
|
|
log.Warn("Tracer accessed out of bound memory", "offset", begin, "end", end)
|
|
|
|
return nil
|
|
|
|
}
|
cmd, core, eth/tracers: support fancier js tracing (#15516)
* cmd, core, eth/tracers: support fancier js tracing
* eth, internal/web3ext: rework trace API, concurrency, chain tracing
* eth/tracers: add three more JavaScript tracers
* eth/tracers, vendor: swap ottovm to duktape for tracing
* core, eth, internal: finalize call tracer and needed extras
* eth, tests: prestate tracer, call test suite, rewinding
* vendor: fix windows builds for tracer js engine
* vendor: temporary duktape fix
* eth/tracers: fix up 4byte and evmdis tracer
* vendor: pull in latest duktape with my upstream fixes
* eth: fix some review comments
* eth: rename rewind to reexec to make it more obvious
* core/vm: terminate tracing using defers
2017-12-21 11:56:11 +00:00
|
|
|
if mw.memory.Len() < int(end) {
|
|
|
|
// TODO(karalabe): We can't js-throw from Go inside duktape inside Go. The Go
|
|
|
|
// runtime goes belly up https://github.com/golang/go/issues/15639.
|
|
|
|
log.Warn("Tracer accessed out of bound memory", "available", mw.memory.Len(), "offset", begin, "size", end-begin)
|
|
|
|
return nil
|
|
|
|
}
|
2019-11-04 09:31:10 +00:00
|
|
|
return mw.memory.GetCopy(begin, end-begin)
|
cmd, core, eth/tracers: support fancier js tracing (#15516)
* cmd, core, eth/tracers: support fancier js tracing
* eth, internal/web3ext: rework trace API, concurrency, chain tracing
* eth/tracers: add three more JavaScript tracers
* eth/tracers, vendor: swap ottovm to duktape for tracing
* core, eth, internal: finalize call tracer and needed extras
* eth, tests: prestate tracer, call test suite, rewinding
* vendor: fix windows builds for tracer js engine
* vendor: temporary duktape fix
* eth/tracers: fix up 4byte and evmdis tracer
* vendor: pull in latest duktape with my upstream fixes
* eth: fix some review comments
* eth: rename rewind to reexec to make it more obvious
* core/vm: terminate tracing using defers
2017-12-21 11:56:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// getUint returns the 32 bytes at the specified address interpreted as a uint.
|
|
|
|
func (mw *memoryWrapper) getUint(addr int64) *big.Int {
|
2020-02-04 08:55:07 +00:00
|
|
|
if mw.memory.Len() < int(addr)+32 || addr < 0 {
|
cmd, core, eth/tracers: support fancier js tracing (#15516)
* cmd, core, eth/tracers: support fancier js tracing
* eth, internal/web3ext: rework trace API, concurrency, chain tracing
* eth/tracers: add three more JavaScript tracers
* eth/tracers, vendor: swap ottovm to duktape for tracing
* core, eth, internal: finalize call tracer and needed extras
* eth, tests: prestate tracer, call test suite, rewinding
* vendor: fix windows builds for tracer js engine
* vendor: temporary duktape fix
* eth/tracers: fix up 4byte and evmdis tracer
* vendor: pull in latest duktape with my upstream fixes
* eth: fix some review comments
* eth: rename rewind to reexec to make it more obvious
* core/vm: terminate tracing using defers
2017-12-21 11:56:11 +00:00
|
|
|
// TODO(karalabe): We can't js-throw from Go inside duktape inside Go. The Go
|
|
|
|
// runtime goes belly up https://github.com/golang/go/issues/15639.
|
|
|
|
log.Warn("Tracer accessed out of bound memory", "available", mw.memory.Len(), "offset", addr, "size", 32)
|
|
|
|
return new(big.Int)
|
|
|
|
}
|
|
|
|
return new(big.Int).SetBytes(mw.memory.GetPtr(addr, 32))
|
|
|
|
}
|
|
|
|
|
|
|
|
// pushObject assembles a JSVM object wrapping a swappable memory and pushes it
|
|
|
|
// onto the VM stack.
|
|
|
|
func (mw *memoryWrapper) pushObject(vm *duktape.Context) {
|
|
|
|
obj := vm.PushObject()
|
|
|
|
|
|
|
|
// Generate the `slice` method which takes two ints and returns a buffer
|
|
|
|
vm.PushGoFunction(func(ctx *duktape.Context) int {
|
|
|
|
blob := mw.slice(int64(ctx.GetInt(-2)), int64(ctx.GetInt(-1)))
|
|
|
|
ctx.Pop2()
|
|
|
|
|
|
|
|
ptr := ctx.PushFixedBuffer(len(blob))
|
2018-09-14 20:07:13 +00:00
|
|
|
copy(makeSlice(ptr, uint(len(blob))), blob)
|
cmd, core, eth/tracers: support fancier js tracing (#15516)
* cmd, core, eth/tracers: support fancier js tracing
* eth, internal/web3ext: rework trace API, concurrency, chain tracing
* eth/tracers: add three more JavaScript tracers
* eth/tracers, vendor: swap ottovm to duktape for tracing
* core, eth, internal: finalize call tracer and needed extras
* eth, tests: prestate tracer, call test suite, rewinding
* vendor: fix windows builds for tracer js engine
* vendor: temporary duktape fix
* eth/tracers: fix up 4byte and evmdis tracer
* vendor: pull in latest duktape with my upstream fixes
* eth: fix some review comments
* eth: rename rewind to reexec to make it more obvious
* core/vm: terminate tracing using defers
2017-12-21 11:56:11 +00:00
|
|
|
return 1
|
|
|
|
})
|
|
|
|
vm.PutPropString(obj, "slice")
|
|
|
|
|
|
|
|
// Generate the `getUint` method which takes an int and returns a bigint
|
|
|
|
vm.PushGoFunction(func(ctx *duktape.Context) int {
|
|
|
|
offset := int64(ctx.GetInt(-1))
|
|
|
|
ctx.Pop()
|
|
|
|
|
|
|
|
pushBigInt(mw.getUint(offset), ctx)
|
|
|
|
return 1
|
|
|
|
})
|
|
|
|
vm.PutPropString(obj, "getUint")
|
|
|
|
}
|
|
|
|
|
|
|
|
// stackWrapper provides a JavaScript wrapper around vm.Stack.
|
|
|
|
type stackWrapper struct {
|
|
|
|
stack *vm.Stack
|
|
|
|
}
|
|
|
|
|
|
|
|
// peek returns the nth-from-the-top element of the stack.
|
|
|
|
func (sw *stackWrapper) peek(idx int) *big.Int {
|
2020-02-04 08:55:07 +00:00
|
|
|
if len(sw.stack.Data()) <= idx || idx < 0 {
|
cmd, core, eth/tracers: support fancier js tracing (#15516)
* cmd, core, eth/tracers: support fancier js tracing
* eth, internal/web3ext: rework trace API, concurrency, chain tracing
* eth/tracers: add three more JavaScript tracers
* eth/tracers, vendor: swap ottovm to duktape for tracing
* core, eth, internal: finalize call tracer and needed extras
* eth, tests: prestate tracer, call test suite, rewinding
* vendor: fix windows builds for tracer js engine
* vendor: temporary duktape fix
* eth/tracers: fix up 4byte and evmdis tracer
* vendor: pull in latest duktape with my upstream fixes
* eth: fix some review comments
* eth: rename rewind to reexec to make it more obvious
* core/vm: terminate tracing using defers
2017-12-21 11:56:11 +00:00
|
|
|
// TODO(karalabe): We can't js-throw from Go inside duktape inside Go. The Go
|
|
|
|
// runtime goes belly up https://github.com/golang/go/issues/15639.
|
|
|
|
log.Warn("Tracer accessed out of bound stack", "size", len(sw.stack.Data()), "index", idx)
|
|
|
|
return new(big.Int)
|
|
|
|
}
|
2020-06-08 12:24:40 +00:00
|
|
|
return sw.stack.Back(idx).ToBig()
|
cmd, core, eth/tracers: support fancier js tracing (#15516)
* cmd, core, eth/tracers: support fancier js tracing
* eth, internal/web3ext: rework trace API, concurrency, chain tracing
* eth/tracers: add three more JavaScript tracers
* eth/tracers, vendor: swap ottovm to duktape for tracing
* core, eth, internal: finalize call tracer and needed extras
* eth, tests: prestate tracer, call test suite, rewinding
* vendor: fix windows builds for tracer js engine
* vendor: temporary duktape fix
* eth/tracers: fix up 4byte and evmdis tracer
* vendor: pull in latest duktape with my upstream fixes
* eth: fix some review comments
* eth: rename rewind to reexec to make it more obvious
* core/vm: terminate tracing using defers
2017-12-21 11:56:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// pushObject assembles a JSVM object wrapping a swappable stack and pushes it
|
|
|
|
// onto the VM stack.
|
|
|
|
func (sw *stackWrapper) pushObject(vm *duktape.Context) {
|
|
|
|
obj := vm.PushObject()
|
|
|
|
|
|
|
|
vm.PushGoFunction(func(ctx *duktape.Context) int { ctx.PushInt(len(sw.stack.Data())); return 1 })
|
|
|
|
vm.PutPropString(obj, "length")
|
|
|
|
|
|
|
|
// Generate the `peek` method which takes an int and returns a bigint
|
|
|
|
vm.PushGoFunction(func(ctx *duktape.Context) int {
|
|
|
|
offset := ctx.GetInt(-1)
|
|
|
|
ctx.Pop()
|
|
|
|
|
|
|
|
pushBigInt(sw.peek(offset), ctx)
|
|
|
|
return 1
|
|
|
|
})
|
|
|
|
vm.PutPropString(obj, "peek")
|
|
|
|
}
|
|
|
|
|
|
|
|
// dbWrapper provides a JavaScript wrapper around vm.Database.
|
|
|
|
type dbWrapper struct {
|
|
|
|
db vm.StateDB
|
|
|
|
}
|
|
|
|
|
|
|
|
// pushObject assembles a JSVM object wrapping a swappable database and pushes it
|
|
|
|
// onto the VM stack.
|
|
|
|
func (dw *dbWrapper) pushObject(vm *duktape.Context) {
|
|
|
|
obj := vm.PushObject()
|
|
|
|
|
|
|
|
// Push the wrapper for statedb.GetBalance
|
|
|
|
vm.PushGoFunction(func(ctx *duktape.Context) int {
|
|
|
|
pushBigInt(dw.db.GetBalance(common.BytesToAddress(popSlice(ctx))), ctx)
|
|
|
|
return 1
|
|
|
|
})
|
|
|
|
vm.PutPropString(obj, "getBalance")
|
|
|
|
|
|
|
|
// Push the wrapper for statedb.GetNonce
|
|
|
|
vm.PushGoFunction(func(ctx *duktape.Context) int {
|
|
|
|
ctx.PushInt(int(dw.db.GetNonce(common.BytesToAddress(popSlice(ctx)))))
|
|
|
|
return 1
|
|
|
|
})
|
|
|
|
vm.PutPropString(obj, "getNonce")
|
|
|
|
|
|
|
|
// Push the wrapper for statedb.GetCode
|
|
|
|
vm.PushGoFunction(func(ctx *duktape.Context) int {
|
|
|
|
code := dw.db.GetCode(common.BytesToAddress(popSlice(ctx)))
|
|
|
|
|
|
|
|
ptr := ctx.PushFixedBuffer(len(code))
|
2018-09-14 20:07:13 +00:00
|
|
|
copy(makeSlice(ptr, uint(len(code))), code)
|
cmd, core, eth/tracers: support fancier js tracing (#15516)
* cmd, core, eth/tracers: support fancier js tracing
* eth, internal/web3ext: rework trace API, concurrency, chain tracing
* eth/tracers: add three more JavaScript tracers
* eth/tracers, vendor: swap ottovm to duktape for tracing
* core, eth, internal: finalize call tracer and needed extras
* eth, tests: prestate tracer, call test suite, rewinding
* vendor: fix windows builds for tracer js engine
* vendor: temporary duktape fix
* eth/tracers: fix up 4byte and evmdis tracer
* vendor: pull in latest duktape with my upstream fixes
* eth: fix some review comments
* eth: rename rewind to reexec to make it more obvious
* core/vm: terminate tracing using defers
2017-12-21 11:56:11 +00:00
|
|
|
return 1
|
|
|
|
})
|
|
|
|
vm.PutPropString(obj, "getCode")
|
|
|
|
|
|
|
|
// Push the wrapper for statedb.GetState
|
|
|
|
vm.PushGoFunction(func(ctx *duktape.Context) int {
|
|
|
|
hash := popSlice(ctx)
|
|
|
|
addr := popSlice(ctx)
|
|
|
|
|
|
|
|
state := dw.db.GetState(common.BytesToAddress(addr), common.BytesToHash(hash))
|
|
|
|
|
|
|
|
ptr := ctx.PushFixedBuffer(len(state))
|
|
|
|
copy(makeSlice(ptr, uint(len(state))), state[:])
|
|
|
|
return 1
|
|
|
|
})
|
|
|
|
vm.PutPropString(obj, "getState")
|
|
|
|
|
|
|
|
// Push the wrapper for statedb.Exists
|
|
|
|
vm.PushGoFunction(func(ctx *duktape.Context) int {
|
|
|
|
ctx.PushBoolean(dw.db.Exist(common.BytesToAddress(popSlice(ctx))))
|
|
|
|
return 1
|
|
|
|
})
|
|
|
|
vm.PutPropString(obj, "exists")
|
|
|
|
}
|
|
|
|
|
|
|
|
// contractWrapper provides a JavaScript wrapper around vm.Contract
|
|
|
|
type contractWrapper struct {
|
|
|
|
contract *vm.Contract
|
|
|
|
}
|
|
|
|
|
|
|
|
// pushObject assembles a JSVM object wrapping a swappable contract and pushes it
|
|
|
|
// onto the VM stack.
|
|
|
|
func (cw *contractWrapper) pushObject(vm *duktape.Context) {
|
|
|
|
obj := vm.PushObject()
|
|
|
|
|
|
|
|
// Push the wrapper for contract.Caller
|
|
|
|
vm.PushGoFunction(func(ctx *duktape.Context) int {
|
|
|
|
ptr := ctx.PushFixedBuffer(20)
|
|
|
|
copy(makeSlice(ptr, 20), cw.contract.Caller().Bytes())
|
|
|
|
return 1
|
|
|
|
})
|
|
|
|
vm.PutPropString(obj, "getCaller")
|
|
|
|
|
|
|
|
// Push the wrapper for contract.Address
|
|
|
|
vm.PushGoFunction(func(ctx *duktape.Context) int {
|
|
|
|
ptr := ctx.PushFixedBuffer(20)
|
|
|
|
copy(makeSlice(ptr, 20), cw.contract.Address().Bytes())
|
|
|
|
return 1
|
|
|
|
})
|
|
|
|
vm.PutPropString(obj, "getAddress")
|
|
|
|
|
|
|
|
// Push the wrapper for contract.Value
|
|
|
|
vm.PushGoFunction(func(ctx *duktape.Context) int {
|
|
|
|
pushBigInt(cw.contract.Value(), ctx)
|
|
|
|
return 1
|
|
|
|
})
|
|
|
|
vm.PutPropString(obj, "getValue")
|
|
|
|
|
|
|
|
// Push the wrapper for contract.Input
|
|
|
|
vm.PushGoFunction(func(ctx *duktape.Context) int {
|
|
|
|
blob := cw.contract.Input
|
|
|
|
|
|
|
|
ptr := ctx.PushFixedBuffer(len(blob))
|
2018-09-14 20:07:13 +00:00
|
|
|
copy(makeSlice(ptr, uint(len(blob))), blob)
|
cmd, core, eth/tracers: support fancier js tracing (#15516)
* cmd, core, eth/tracers: support fancier js tracing
* eth, internal/web3ext: rework trace API, concurrency, chain tracing
* eth/tracers: add three more JavaScript tracers
* eth/tracers, vendor: swap ottovm to duktape for tracing
* core, eth, internal: finalize call tracer and needed extras
* eth, tests: prestate tracer, call test suite, rewinding
* vendor: fix windows builds for tracer js engine
* vendor: temporary duktape fix
* eth/tracers: fix up 4byte and evmdis tracer
* vendor: pull in latest duktape with my upstream fixes
* eth: fix some review comments
* eth: rename rewind to reexec to make it more obvious
* core/vm: terminate tracing using defers
2017-12-21 11:56:11 +00:00
|
|
|
return 1
|
|
|
|
})
|
|
|
|
vm.PutPropString(obj, "getInput")
|
|
|
|
}
|
|
|
|
|
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 07:31:22 +00:00
|
|
|
type frame struct {
|
|
|
|
typ *string
|
|
|
|
from *common.Address
|
|
|
|
to *common.Address
|
|
|
|
input []byte
|
|
|
|
gas *uint
|
|
|
|
value *big.Int
|
|
|
|
}
|
|
|
|
|
|
|
|
func newFrame() *frame {
|
|
|
|
return &frame{
|
|
|
|
typ: new(string),
|
|
|
|
from: new(common.Address),
|
|
|
|
to: new(common.Address),
|
|
|
|
gas: new(uint),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *frame) pushObject(vm *duktape.Context) {
|
|
|
|
obj := vm.PushObject()
|
|
|
|
|
|
|
|
vm.PushGoFunction(func(ctx *duktape.Context) int { pushValue(ctx, *f.typ); return 1 })
|
|
|
|
vm.PutPropString(obj, "getType")
|
|
|
|
|
|
|
|
vm.PushGoFunction(func(ctx *duktape.Context) int { pushValue(ctx, *f.from); return 1 })
|
|
|
|
vm.PutPropString(obj, "getFrom")
|
|
|
|
|
|
|
|
vm.PushGoFunction(func(ctx *duktape.Context) int { pushValue(ctx, *f.to); return 1 })
|
|
|
|
vm.PutPropString(obj, "getTo")
|
|
|
|
|
|
|
|
vm.PushGoFunction(func(ctx *duktape.Context) int { pushValue(ctx, f.input); return 1 })
|
|
|
|
vm.PutPropString(obj, "getInput")
|
|
|
|
|
|
|
|
vm.PushGoFunction(func(ctx *duktape.Context) int { pushValue(ctx, *f.gas); return 1 })
|
|
|
|
vm.PutPropString(obj, "getGas")
|
|
|
|
|
|
|
|
vm.PushGoFunction(func(ctx *duktape.Context) int {
|
|
|
|
if f.value != nil {
|
|
|
|
pushValue(ctx, f.value)
|
|
|
|
} else {
|
|
|
|
ctx.PushUndefined()
|
|
|
|
}
|
|
|
|
return 1
|
|
|
|
})
|
|
|
|
vm.PutPropString(obj, "getValue")
|
|
|
|
}
|
|
|
|
|
|
|
|
type frameResult struct {
|
|
|
|
gasUsed *uint
|
|
|
|
output []byte
|
|
|
|
errorValue *string
|
|
|
|
}
|
|
|
|
|
|
|
|
func newFrameResult() *frameResult {
|
|
|
|
return &frameResult{
|
|
|
|
gasUsed: new(uint),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *frameResult) pushObject(vm *duktape.Context) {
|
|
|
|
obj := vm.PushObject()
|
|
|
|
|
|
|
|
vm.PushGoFunction(func(ctx *duktape.Context) int { pushValue(ctx, *r.gasUsed); return 1 })
|
|
|
|
vm.PutPropString(obj, "getGasUsed")
|
|
|
|
|
|
|
|
vm.PushGoFunction(func(ctx *duktape.Context) int { pushValue(ctx, r.output); return 1 })
|
|
|
|
vm.PutPropString(obj, "getOutput")
|
|
|
|
|
|
|
|
vm.PushGoFunction(func(ctx *duktape.Context) int {
|
|
|
|
if r.errorValue != nil {
|
|
|
|
pushValue(ctx, *r.errorValue)
|
|
|
|
} else {
|
|
|
|
ctx.PushUndefined()
|
|
|
|
}
|
|
|
|
return 1
|
|
|
|
})
|
|
|
|
vm.PutPropString(obj, "getError")
|
|
|
|
}
|
|
|
|
|
2021-11-05 10:48:21 +00:00
|
|
|
// jsTracer provides an implementation of Tracer that evaluates a Javascript
|
cmd, core, eth/tracers: support fancier js tracing (#15516)
* cmd, core, eth/tracers: support fancier js tracing
* eth, internal/web3ext: rework trace API, concurrency, chain tracing
* eth/tracers: add three more JavaScript tracers
* eth/tracers, vendor: swap ottovm to duktape for tracing
* core, eth, internal: finalize call tracer and needed extras
* eth, tests: prestate tracer, call test suite, rewinding
* vendor: fix windows builds for tracer js engine
* vendor: temporary duktape fix
* eth/tracers: fix up 4byte and evmdis tracer
* vendor: pull in latest duktape with my upstream fixes
* eth: fix some review comments
* eth: rename rewind to reexec to make it more obvious
* core/vm: terminate tracing using defers
2017-12-21 11:56:11 +00:00
|
|
|
// function for each VM execution step.
|
2021-11-05 10:48:21 +00:00
|
|
|
type jsTracer struct {
|
cmd, core, eth/tracers: support fancier js tracing (#15516)
* cmd, core, eth/tracers: support fancier js tracing
* eth, internal/web3ext: rework trace API, concurrency, chain tracing
* eth/tracers: add three more JavaScript tracers
* eth/tracers, vendor: swap ottovm to duktape for tracing
* core, eth, internal: finalize call tracer and needed extras
* eth, tests: prestate tracer, call test suite, rewinding
* vendor: fix windows builds for tracer js engine
* vendor: temporary duktape fix
* eth/tracers: fix up 4byte and evmdis tracer
* vendor: pull in latest duktape with my upstream fixes
* eth: fix some review comments
* eth: rename rewind to reexec to make it more obvious
* core/vm: terminate tracing using defers
2017-12-21 11:56:11 +00:00
|
|
|
vm *duktape.Context // Javascript VM instance
|
|
|
|
|
|
|
|
tracerObject int // Stack index of the tracer JavaScript object
|
|
|
|
stateObject int // Stack index of the global state to pull arguments from
|
|
|
|
|
|
|
|
opWrapper *opWrapper // Wrapper around the VM opcode
|
|
|
|
stackWrapper *stackWrapper // Wrapper around the VM stack
|
|
|
|
memoryWrapper *memoryWrapper // Wrapper around the VM memory
|
|
|
|
contractWrapper *contractWrapper // Wrapper around the contract object
|
|
|
|
dbWrapper *dbWrapper // Wrapper around the VM environment
|
|
|
|
|
2018-10-23 14:28:18 +00:00
|
|
|
pcValue *uint // Swappable pc value wrapped by a log accessor
|
|
|
|
gasValue *uint // Swappable gas value wrapped by a log accessor
|
|
|
|
costValue *uint // Swappable cost value wrapped by a log accessor
|
|
|
|
depthValue *uint // Swappable depth value wrapped by a log accessor
|
|
|
|
errorValue *string // Swappable error value wrapped by a log accessor
|
|
|
|
refundValue *uint // Swappable refund value wrapped by a log accessor
|
cmd, core, eth/tracers: support fancier js tracing (#15516)
* cmd, core, eth/tracers: support fancier js tracing
* eth, internal/web3ext: rework trace API, concurrency, chain tracing
* eth/tracers: add three more JavaScript tracers
* eth/tracers, vendor: swap ottovm to duktape for tracing
* core, eth, internal: finalize call tracer and needed extras
* eth, tests: prestate tracer, call test suite, rewinding
* vendor: fix windows builds for tracer js engine
* vendor: temporary duktape fix
* eth/tracers: fix up 4byte and evmdis tracer
* vendor: pull in latest duktape with my upstream fixes
* eth: fix some review comments
* eth: rename rewind to reexec to make it more obvious
* core/vm: terminate tracing using defers
2017-12-21 11:56:11 +00:00
|
|
|
|
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 07:31:22 +00:00
|
|
|
frame *frame // Represents entry into call frame. Fields are swappable
|
|
|
|
frameResult *frameResult // Represents exit from a call frame. Fields are swappable
|
|
|
|
|
cmd, core, eth/tracers: support fancier js tracing (#15516)
* cmd, core, eth/tracers: support fancier js tracing
* eth, internal/web3ext: rework trace API, concurrency, chain tracing
* eth/tracers: add three more JavaScript tracers
* eth/tracers, vendor: swap ottovm to duktape for tracing
* core, eth, internal: finalize call tracer and needed extras
* eth, tests: prestate tracer, call test suite, rewinding
* vendor: fix windows builds for tracer js engine
* vendor: temporary duktape fix
* eth/tracers: fix up 4byte and evmdis tracer
* vendor: pull in latest duktape with my upstream fixes
* eth: fix some review comments
* eth: rename rewind to reexec to make it more obvious
* core/vm: terminate tracing using defers
2017-12-21 11:56:11 +00:00
|
|
|
ctx map[string]interface{} // Transaction context gathered throughout execution
|
|
|
|
err error // Error, if one has occurred
|
|
|
|
|
|
|
|
interrupt uint32 // Atomic flag to signal execution interruption
|
|
|
|
reason error // Textual reason for the interruption
|
2021-06-28 12:13:27 +00:00
|
|
|
|
|
|
|
activePrecompiles []common.Address // Updated on CaptureStart based on given rules
|
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 07:31:22 +00:00
|
|
|
traceSteps bool // When true, will invoke step() on each opcode
|
|
|
|
traceCallFrames bool // When true, will invoke enter() and exit() js funcs
|
cmd, core, eth/tracers: support fancier js tracing (#15516)
* cmd, core, eth/tracers: support fancier js tracing
* eth, internal/web3ext: rework trace API, concurrency, chain tracing
* eth/tracers: add three more JavaScript tracers
* eth/tracers, vendor: swap ottovm to duktape for tracing
* core, eth, internal: finalize call tracer and needed extras
* eth, tests: prestate tracer, call test suite, rewinding
* vendor: fix windows builds for tracer js engine
* vendor: temporary duktape fix
* eth/tracers: fix up 4byte and evmdis tracer
* vendor: pull in latest duktape with my upstream fixes
* eth: fix some review comments
* eth: rename rewind to reexec to make it more obvious
* core/vm: terminate tracing using defers
2017-12-21 11:56:11 +00:00
|
|
|
}
|
|
|
|
|
2021-06-24 09:46:26 +00:00
|
|
|
// Context contains some contextual infos for a transaction execution that is not
|
|
|
|
// available from within the EVM object.
|
|
|
|
type Context struct {
|
|
|
|
BlockHash common.Hash // Hash of the block the tx is contained within (zero if dangling tx or call)
|
|
|
|
TxIndex int // Index of the transaction within a block (zero if dangling tx or call)
|
|
|
|
TxHash common.Hash // Hash of the transaction being traced (zero if dangling call)
|
|
|
|
}
|
|
|
|
|
cmd, core, eth/tracers: support fancier js tracing (#15516)
* cmd, core, eth/tracers: support fancier js tracing
* eth, internal/web3ext: rework trace API, concurrency, chain tracing
* eth/tracers: add three more JavaScript tracers
* eth/tracers, vendor: swap ottovm to duktape for tracing
* core, eth, internal: finalize call tracer and needed extras
* eth, tests: prestate tracer, call test suite, rewinding
* vendor: fix windows builds for tracer js engine
* vendor: temporary duktape fix
* eth/tracers: fix up 4byte and evmdis tracer
* vendor: pull in latest duktape with my upstream fixes
* eth: fix some review comments
* eth: rename rewind to reexec to make it more obvious
* core/vm: terminate tracing using defers
2017-12-21 11:56:11 +00:00
|
|
|
// New instantiates a new tracer instance. code specifies a Javascript snippet,
|
|
|
|
// which must evaluate to an expression returning an object with 'step', 'fault'
|
|
|
|
// and 'result' functions.
|
2021-11-05 10:48:21 +00:00
|
|
|
func newJsTracer(code string, ctx *Context) (*jsTracer, error) {
|
|
|
|
tracer := &jsTracer{
|
cmd, core, eth/tracers: support fancier js tracing (#15516)
* cmd, core, eth/tracers: support fancier js tracing
* eth, internal/web3ext: rework trace API, concurrency, chain tracing
* eth/tracers: add three more JavaScript tracers
* eth/tracers, vendor: swap ottovm to duktape for tracing
* core, eth, internal: finalize call tracer and needed extras
* eth, tests: prestate tracer, call test suite, rewinding
* vendor: fix windows builds for tracer js engine
* vendor: temporary duktape fix
* eth/tracers: fix up 4byte and evmdis tracer
* vendor: pull in latest duktape with my upstream fixes
* eth: fix some review comments
* eth: rename rewind to reexec to make it more obvious
* core/vm: terminate tracing using defers
2017-12-21 11:56:11 +00:00
|
|
|
vm: duktape.New(),
|
|
|
|
ctx: make(map[string]interface{}),
|
|
|
|
opWrapper: new(opWrapper),
|
|
|
|
stackWrapper: new(stackWrapper),
|
|
|
|
memoryWrapper: new(memoryWrapper),
|
|
|
|
contractWrapper: new(contractWrapper),
|
|
|
|
dbWrapper: new(dbWrapper),
|
|
|
|
pcValue: new(uint),
|
|
|
|
gasValue: new(uint),
|
|
|
|
costValue: new(uint),
|
|
|
|
depthValue: new(uint),
|
2018-10-23 14:28:18 +00:00
|
|
|
refundValue: new(uint),
|
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 07:31:22 +00:00
|
|
|
frame: newFrame(),
|
|
|
|
frameResult: newFrameResult(),
|
cmd, core, eth/tracers: support fancier js tracing (#15516)
* cmd, core, eth/tracers: support fancier js tracing
* eth, internal/web3ext: rework trace API, concurrency, chain tracing
* eth/tracers: add three more JavaScript tracers
* eth/tracers, vendor: swap ottovm to duktape for tracing
* core, eth, internal: finalize call tracer and needed extras
* eth, tests: prestate tracer, call test suite, rewinding
* vendor: fix windows builds for tracer js engine
* vendor: temporary duktape fix
* eth/tracers: fix up 4byte and evmdis tracer
* vendor: pull in latest duktape with my upstream fixes
* eth: fix some review comments
* eth: rename rewind to reexec to make it more obvious
* core/vm: terminate tracing using defers
2017-12-21 11:56:11 +00:00
|
|
|
}
|
2021-06-24 09:46:26 +00:00
|
|
|
if ctx.BlockHash != (common.Hash{}) {
|
|
|
|
tracer.ctx["blockHash"] = ctx.BlockHash
|
2020-12-27 20:57:19 +00:00
|
|
|
|
2021-06-24 09:46:26 +00:00
|
|
|
if ctx.TxHash != (common.Hash{}) {
|
|
|
|
tracer.ctx["txIndex"] = ctx.TxIndex
|
|
|
|
tracer.ctx["txHash"] = ctx.TxHash
|
|
|
|
}
|
|
|
|
}
|
cmd, core, eth/tracers: support fancier js tracing (#15516)
* cmd, core, eth/tracers: support fancier js tracing
* eth, internal/web3ext: rework trace API, concurrency, chain tracing
* eth/tracers: add three more JavaScript tracers
* eth/tracers, vendor: swap ottovm to duktape for tracing
* core, eth, internal: finalize call tracer and needed extras
* eth, tests: prestate tracer, call test suite, rewinding
* vendor: fix windows builds for tracer js engine
* vendor: temporary duktape fix
* eth/tracers: fix up 4byte and evmdis tracer
* vendor: pull in latest duktape with my upstream fixes
* eth: fix some review comments
* eth: rename rewind to reexec to make it more obvious
* core/vm: terminate tracing using defers
2017-12-21 11:56:11 +00:00
|
|
|
// Set up builtins for this environment
|
|
|
|
tracer.vm.PushGlobalGoFunction("toHex", func(ctx *duktape.Context) int {
|
|
|
|
ctx.PushString(hexutil.Encode(popSlice(ctx)))
|
|
|
|
return 1
|
|
|
|
})
|
|
|
|
tracer.vm.PushGlobalGoFunction("toWord", func(ctx *duktape.Context) int {
|
|
|
|
var word common.Hash
|
|
|
|
if ptr, size := ctx.GetBuffer(-1); ptr != nil {
|
|
|
|
word = common.BytesToHash(makeSlice(ptr, size))
|
|
|
|
} else {
|
|
|
|
word = common.HexToHash(ctx.GetString(-1))
|
|
|
|
}
|
|
|
|
ctx.Pop()
|
|
|
|
copy(makeSlice(ctx.PushFixedBuffer(32), 32), word[:])
|
|
|
|
return 1
|
|
|
|
})
|
|
|
|
tracer.vm.PushGlobalGoFunction("toAddress", func(ctx *duktape.Context) int {
|
|
|
|
var addr common.Address
|
|
|
|
if ptr, size := ctx.GetBuffer(-1); ptr != nil {
|
|
|
|
addr = common.BytesToAddress(makeSlice(ptr, size))
|
|
|
|
} else {
|
|
|
|
addr = common.HexToAddress(ctx.GetString(-1))
|
|
|
|
}
|
|
|
|
ctx.Pop()
|
|
|
|
copy(makeSlice(ctx.PushFixedBuffer(20), 20), addr[:])
|
|
|
|
return 1
|
|
|
|
})
|
|
|
|
tracer.vm.PushGlobalGoFunction("toContract", func(ctx *duktape.Context) int {
|
|
|
|
var from common.Address
|
|
|
|
if ptr, size := ctx.GetBuffer(-2); ptr != nil {
|
|
|
|
from = common.BytesToAddress(makeSlice(ptr, size))
|
|
|
|
} else {
|
|
|
|
from = common.HexToAddress(ctx.GetString(-2))
|
|
|
|
}
|
|
|
|
nonce := uint64(ctx.GetInt(-1))
|
|
|
|
ctx.Pop2()
|
|
|
|
|
|
|
|
contract := crypto.CreateAddress(from, nonce)
|
|
|
|
copy(makeSlice(ctx.PushFixedBuffer(20), 20), contract[:])
|
|
|
|
return 1
|
|
|
|
})
|
2019-01-05 20:26:50 +00:00
|
|
|
tracer.vm.PushGlobalGoFunction("toContract2", func(ctx *duktape.Context) int {
|
|
|
|
var from common.Address
|
|
|
|
if ptr, size := ctx.GetBuffer(-3); ptr != nil {
|
|
|
|
from = common.BytesToAddress(makeSlice(ptr, size))
|
|
|
|
} else {
|
|
|
|
from = common.HexToAddress(ctx.GetString(-3))
|
|
|
|
}
|
|
|
|
// Retrieve salt hex string from js stack
|
|
|
|
salt := common.HexToHash(ctx.GetString(-2))
|
|
|
|
// Retrieve code slice from js stack
|
|
|
|
var code []byte
|
|
|
|
if ptr, size := ctx.GetBuffer(-1); ptr != nil {
|
|
|
|
code = common.CopyBytes(makeSlice(ptr, size))
|
|
|
|
} else {
|
|
|
|
code = common.FromHex(ctx.GetString(-1))
|
|
|
|
}
|
|
|
|
codeHash := crypto.Keccak256(code)
|
|
|
|
ctx.Pop3()
|
|
|
|
contract := crypto.CreateAddress2(from, salt, codeHash)
|
|
|
|
copy(makeSlice(ctx.PushFixedBuffer(20), 20), contract[:])
|
|
|
|
return 1
|
|
|
|
})
|
cmd, core, eth/tracers: support fancier js tracing (#15516)
* cmd, core, eth/tracers: support fancier js tracing
* eth, internal/web3ext: rework trace API, concurrency, chain tracing
* eth/tracers: add three more JavaScript tracers
* eth/tracers, vendor: swap ottovm to duktape for tracing
* core, eth, internal: finalize call tracer and needed extras
* eth, tests: prestate tracer, call test suite, rewinding
* vendor: fix windows builds for tracer js engine
* vendor: temporary duktape fix
* eth/tracers: fix up 4byte and evmdis tracer
* vendor: pull in latest duktape with my upstream fixes
* eth: fix some review comments
* eth: rename rewind to reexec to make it more obvious
* core/vm: terminate tracing using defers
2017-12-21 11:56:11 +00:00
|
|
|
tracer.vm.PushGlobalGoFunction("isPrecompiled", func(ctx *duktape.Context) int {
|
2021-06-28 12:13:27 +00:00
|
|
|
addr := common.BytesToAddress(popSlice(ctx))
|
|
|
|
for _, p := range tracer.activePrecompiles {
|
|
|
|
if p == addr {
|
|
|
|
ctx.PushBoolean(true)
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ctx.PushBoolean(false)
|
cmd, core, eth/tracers: support fancier js tracing (#15516)
* cmd, core, eth/tracers: support fancier js tracing
* eth, internal/web3ext: rework trace API, concurrency, chain tracing
* eth/tracers: add three more JavaScript tracers
* eth/tracers, vendor: swap ottovm to duktape for tracing
* core, eth, internal: finalize call tracer and needed extras
* eth, tests: prestate tracer, call test suite, rewinding
* vendor: fix windows builds for tracer js engine
* vendor: temporary duktape fix
* eth/tracers: fix up 4byte and evmdis tracer
* vendor: pull in latest duktape with my upstream fixes
* eth: fix some review comments
* eth: rename rewind to reexec to make it more obvious
* core/vm: terminate tracing using defers
2017-12-21 11:56:11 +00:00
|
|
|
return 1
|
|
|
|
})
|
|
|
|
tracer.vm.PushGlobalGoFunction("slice", func(ctx *duktape.Context) int {
|
|
|
|
start, end := ctx.GetInt(-2), ctx.GetInt(-1)
|
|
|
|
ctx.Pop2()
|
|
|
|
|
|
|
|
blob := popSlice(ctx)
|
|
|
|
size := end - start
|
|
|
|
|
|
|
|
if start < 0 || start > end || end > len(blob) {
|
|
|
|
// TODO(karalabe): We can't js-throw from Go inside duktape inside Go. The Go
|
|
|
|
// runtime goes belly up https://github.com/golang/go/issues/15639.
|
|
|
|
log.Warn("Tracer accessed out of bound memory", "available", len(blob), "offset", start, "size", size)
|
|
|
|
ctx.PushFixedBuffer(0)
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
copy(makeSlice(ctx.PushFixedBuffer(size), uint(size)), blob[start:end])
|
|
|
|
return 1
|
|
|
|
})
|
|
|
|
// Push the JavaScript tracer as object #0 onto the JSVM stack and validate it
|
|
|
|
if err := tracer.vm.PevalString("(" + code + ")"); err != nil {
|
|
|
|
log.Warn("Failed to compile tracer", "err", err)
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
tracer.tracerObject = 0 // yeah, nice, eval can't return the index itself
|
|
|
|
|
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 07:31:22 +00:00
|
|
|
hasStep := tracer.vm.GetPropString(tracer.tracerObject, "step")
|
cmd, core, eth/tracers: support fancier js tracing (#15516)
* cmd, core, eth/tracers: support fancier js tracing
* eth, internal/web3ext: rework trace API, concurrency, chain tracing
* eth/tracers: add three more JavaScript tracers
* eth/tracers, vendor: swap ottovm to duktape for tracing
* core, eth, internal: finalize call tracer and needed extras
* eth, tests: prestate tracer, call test suite, rewinding
* vendor: fix windows builds for tracer js engine
* vendor: temporary duktape fix
* eth/tracers: fix up 4byte and evmdis tracer
* vendor: pull in latest duktape with my upstream fixes
* eth: fix some review comments
* eth: rename rewind to reexec to make it more obvious
* core/vm: terminate tracing using defers
2017-12-21 11:56:11 +00:00
|
|
|
tracer.vm.Pop()
|
|
|
|
|
|
|
|
if !tracer.vm.GetPropString(tracer.tracerObject, "fault") {
|
2019-11-24 20:06:06 +00:00
|
|
|
return nil, fmt.Errorf("trace object must expose a function fault()")
|
cmd, core, eth/tracers: support fancier js tracing (#15516)
* cmd, core, eth/tracers: support fancier js tracing
* eth, internal/web3ext: rework trace API, concurrency, chain tracing
* eth/tracers: add three more JavaScript tracers
* eth/tracers, vendor: swap ottovm to duktape for tracing
* core, eth, internal: finalize call tracer and needed extras
* eth, tests: prestate tracer, call test suite, rewinding
* vendor: fix windows builds for tracer js engine
* vendor: temporary duktape fix
* eth/tracers: fix up 4byte and evmdis tracer
* vendor: pull in latest duktape with my upstream fixes
* eth: fix some review comments
* eth: rename rewind to reexec to make it more obvious
* core/vm: terminate tracing using defers
2017-12-21 11:56:11 +00:00
|
|
|
}
|
|
|
|
tracer.vm.Pop()
|
|
|
|
|
|
|
|
if !tracer.vm.GetPropString(tracer.tracerObject, "result") {
|
2019-11-24 20:06:06 +00:00
|
|
|
return nil, fmt.Errorf("trace object must expose a function result()")
|
cmd, core, eth/tracers: support fancier js tracing (#15516)
* cmd, core, eth/tracers: support fancier js tracing
* eth, internal/web3ext: rework trace API, concurrency, chain tracing
* eth/tracers: add three more JavaScript tracers
* eth/tracers, vendor: swap ottovm to duktape for tracing
* core, eth, internal: finalize call tracer and needed extras
* eth, tests: prestate tracer, call test suite, rewinding
* vendor: fix windows builds for tracer js engine
* vendor: temporary duktape fix
* eth/tracers: fix up 4byte and evmdis tracer
* vendor: pull in latest duktape with my upstream fixes
* eth: fix some review comments
* eth: rename rewind to reexec to make it more obvious
* core/vm: terminate tracing using defers
2017-12-21 11:56:11 +00:00
|
|
|
}
|
|
|
|
tracer.vm.Pop()
|
|
|
|
|
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 07:31:22 +00:00
|
|
|
hasEnter := tracer.vm.GetPropString(tracer.tracerObject, "enter")
|
|
|
|
tracer.vm.Pop()
|
|
|
|
hasExit := tracer.vm.GetPropString(tracer.tracerObject, "exit")
|
|
|
|
tracer.vm.Pop()
|
|
|
|
if hasEnter != hasExit {
|
|
|
|
return nil, fmt.Errorf("trace object must expose either both or none of enter() and exit()")
|
|
|
|
}
|
2021-11-04 17:54:00 +00:00
|
|
|
tracer.traceCallFrames = hasEnter && hasExit
|
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 07:31:22 +00:00
|
|
|
tracer.traceSteps = hasStep
|
|
|
|
|
cmd, core, eth/tracers: support fancier js tracing (#15516)
* cmd, core, eth/tracers: support fancier js tracing
* eth, internal/web3ext: rework trace API, concurrency, chain tracing
* eth/tracers: add three more JavaScript tracers
* eth/tracers, vendor: swap ottovm to duktape for tracing
* core, eth, internal: finalize call tracer and needed extras
* eth, tests: prestate tracer, call test suite, rewinding
* vendor: fix windows builds for tracer js engine
* vendor: temporary duktape fix
* eth/tracers: fix up 4byte and evmdis tracer
* vendor: pull in latest duktape with my upstream fixes
* eth: fix some review comments
* eth: rename rewind to reexec to make it more obvious
* core/vm: terminate tracing using defers
2017-12-21 11:56:11 +00:00
|
|
|
// Tracer is valid, inject the big int library to access large numbers
|
|
|
|
tracer.vm.EvalString(bigIntegerJS)
|
|
|
|
tracer.vm.PutGlobalString("bigInt")
|
|
|
|
|
|
|
|
// Push the global environment state as object #1 into the JSVM stack
|
|
|
|
tracer.stateObject = tracer.vm.PushObject()
|
|
|
|
|
|
|
|
logObject := tracer.vm.PushObject()
|
|
|
|
|
|
|
|
tracer.opWrapper.pushObject(tracer.vm)
|
|
|
|
tracer.vm.PutPropString(logObject, "op")
|
|
|
|
|
|
|
|
tracer.stackWrapper.pushObject(tracer.vm)
|
|
|
|
tracer.vm.PutPropString(logObject, "stack")
|
|
|
|
|
|
|
|
tracer.memoryWrapper.pushObject(tracer.vm)
|
|
|
|
tracer.vm.PutPropString(logObject, "memory")
|
|
|
|
|
|
|
|
tracer.contractWrapper.pushObject(tracer.vm)
|
|
|
|
tracer.vm.PutPropString(logObject, "contract")
|
|
|
|
|
|
|
|
tracer.vm.PushGoFunction(func(ctx *duktape.Context) int { ctx.PushUint(*tracer.pcValue); return 1 })
|
|
|
|
tracer.vm.PutPropString(logObject, "getPC")
|
|
|
|
|
|
|
|
tracer.vm.PushGoFunction(func(ctx *duktape.Context) int { ctx.PushUint(*tracer.gasValue); return 1 })
|
|
|
|
tracer.vm.PutPropString(logObject, "getGas")
|
|
|
|
|
|
|
|
tracer.vm.PushGoFunction(func(ctx *duktape.Context) int { ctx.PushUint(*tracer.costValue); return 1 })
|
|
|
|
tracer.vm.PutPropString(logObject, "getCost")
|
|
|
|
|
|
|
|
tracer.vm.PushGoFunction(func(ctx *duktape.Context) int { ctx.PushUint(*tracer.depthValue); return 1 })
|
|
|
|
tracer.vm.PutPropString(logObject, "getDepth")
|
|
|
|
|
2018-10-23 14:28:18 +00:00
|
|
|
tracer.vm.PushGoFunction(func(ctx *duktape.Context) int { ctx.PushUint(*tracer.refundValue); return 1 })
|
|
|
|
tracer.vm.PutPropString(logObject, "getRefund")
|
|
|
|
|
cmd, core, eth/tracers: support fancier js tracing (#15516)
* cmd, core, eth/tracers: support fancier js tracing
* eth, internal/web3ext: rework trace API, concurrency, chain tracing
* eth/tracers: add three more JavaScript tracers
* eth/tracers, vendor: swap ottovm to duktape for tracing
* core, eth, internal: finalize call tracer and needed extras
* eth, tests: prestate tracer, call test suite, rewinding
* vendor: fix windows builds for tracer js engine
* vendor: temporary duktape fix
* eth/tracers: fix up 4byte and evmdis tracer
* vendor: pull in latest duktape with my upstream fixes
* eth: fix some review comments
* eth: rename rewind to reexec to make it more obvious
* core/vm: terminate tracing using defers
2017-12-21 11:56:11 +00:00
|
|
|
tracer.vm.PushGoFunction(func(ctx *duktape.Context) int {
|
|
|
|
if tracer.errorValue != nil {
|
|
|
|
ctx.PushString(*tracer.errorValue)
|
|
|
|
} else {
|
|
|
|
ctx.PushUndefined()
|
|
|
|
}
|
|
|
|
return 1
|
|
|
|
})
|
|
|
|
tracer.vm.PutPropString(logObject, "getError")
|
|
|
|
|
|
|
|
tracer.vm.PutPropString(tracer.stateObject, "log")
|
|
|
|
|
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 07:31:22 +00:00
|
|
|
tracer.frame.pushObject(tracer.vm)
|
|
|
|
tracer.vm.PutPropString(tracer.stateObject, "frame")
|
|
|
|
|
|
|
|
tracer.frameResult.pushObject(tracer.vm)
|
|
|
|
tracer.vm.PutPropString(tracer.stateObject, "frameResult")
|
|
|
|
|
cmd, core, eth/tracers: support fancier js tracing (#15516)
* cmd, core, eth/tracers: support fancier js tracing
* eth, internal/web3ext: rework trace API, concurrency, chain tracing
* eth/tracers: add three more JavaScript tracers
* eth/tracers, vendor: swap ottovm to duktape for tracing
* core, eth, internal: finalize call tracer and needed extras
* eth, tests: prestate tracer, call test suite, rewinding
* vendor: fix windows builds for tracer js engine
* vendor: temporary duktape fix
* eth/tracers: fix up 4byte and evmdis tracer
* vendor: pull in latest duktape with my upstream fixes
* eth: fix some review comments
* eth: rename rewind to reexec to make it more obvious
* core/vm: terminate tracing using defers
2017-12-21 11:56:11 +00:00
|
|
|
tracer.dbWrapper.pushObject(tracer.vm)
|
|
|
|
tracer.vm.PutPropString(tracer.stateObject, "db")
|
|
|
|
|
|
|
|
return tracer, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Stop terminates execution of the tracer at the first opportune moment.
|
2021-11-05 10:48:21 +00:00
|
|
|
func (jst *jsTracer) Stop(err error) {
|
cmd, core, eth/tracers: support fancier js tracing (#15516)
* cmd, core, eth/tracers: support fancier js tracing
* eth, internal/web3ext: rework trace API, concurrency, chain tracing
* eth/tracers: add three more JavaScript tracers
* eth/tracers, vendor: swap ottovm to duktape for tracing
* core, eth, internal: finalize call tracer and needed extras
* eth, tests: prestate tracer, call test suite, rewinding
* vendor: fix windows builds for tracer js engine
* vendor: temporary duktape fix
* eth/tracers: fix up 4byte and evmdis tracer
* vendor: pull in latest duktape with my upstream fixes
* eth: fix some review comments
* eth: rename rewind to reexec to make it more obvious
* core/vm: terminate tracing using defers
2017-12-21 11:56:11 +00:00
|
|
|
jst.reason = err
|
|
|
|
atomic.StoreUint32(&jst.interrupt, 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
// call executes a method on a JS object, catching any errors, formatting and
|
|
|
|
// returning them as error objects.
|
2021-11-05 10:48:21 +00:00
|
|
|
func (jst *jsTracer) call(noret bool, method string, args ...string) (json.RawMessage, error) {
|
cmd, core, eth/tracers: support fancier js tracing (#15516)
* cmd, core, eth/tracers: support fancier js tracing
* eth, internal/web3ext: rework trace API, concurrency, chain tracing
* eth/tracers: add three more JavaScript tracers
* eth/tracers, vendor: swap ottovm to duktape for tracing
* core, eth, internal: finalize call tracer and needed extras
* eth, tests: prestate tracer, call test suite, rewinding
* vendor: fix windows builds for tracer js engine
* vendor: temporary duktape fix
* eth/tracers: fix up 4byte and evmdis tracer
* vendor: pull in latest duktape with my upstream fixes
* eth: fix some review comments
* eth: rename rewind to reexec to make it more obvious
* core/vm: terminate tracing using defers
2017-12-21 11:56:11 +00:00
|
|
|
// Execute the JavaScript call and return any error
|
|
|
|
jst.vm.PushString(method)
|
|
|
|
for _, arg := range args {
|
|
|
|
jst.vm.GetPropString(jst.stateObject, arg)
|
|
|
|
}
|
|
|
|
code := jst.vm.PcallProp(jst.tracerObject, len(args))
|
|
|
|
defer jst.vm.Pop()
|
|
|
|
|
|
|
|
if code != 0 {
|
|
|
|
err := jst.vm.SafeToString(-1)
|
|
|
|
return nil, errors.New(err)
|
|
|
|
}
|
|
|
|
// No error occurred, extract return value and return
|
2021-05-11 13:23:54 +00:00
|
|
|
if noret {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
// Push a JSON marshaller onto the stack. We can't marshal from the out-
|
|
|
|
// side because duktape can crash on large nestings and we can't catch
|
|
|
|
// C++ exceptions ourselves from Go. TODO(karalabe): Yuck, why wrap?!
|
|
|
|
jst.vm.PushString("(JSON.stringify)")
|
|
|
|
jst.vm.Eval()
|
|
|
|
|
|
|
|
jst.vm.Swap(-1, -2)
|
|
|
|
if code = jst.vm.Pcall(1); code != 0 {
|
|
|
|
err := jst.vm.SafeToString(-1)
|
|
|
|
return nil, errors.New(err)
|
|
|
|
}
|
|
|
|
return json.RawMessage(jst.vm.SafeToString(-1)), nil
|
cmd, core, eth/tracers: support fancier js tracing (#15516)
* cmd, core, eth/tracers: support fancier js tracing
* eth, internal/web3ext: rework trace API, concurrency, chain tracing
* eth/tracers: add three more JavaScript tracers
* eth/tracers, vendor: swap ottovm to duktape for tracing
* core, eth, internal: finalize call tracer and needed extras
* eth, tests: prestate tracer, call test suite, rewinding
* vendor: fix windows builds for tracer js engine
* vendor: temporary duktape fix
* eth/tracers: fix up 4byte and evmdis tracer
* vendor: pull in latest duktape with my upstream fixes
* eth: fix some review comments
* eth: rename rewind to reexec to make it more obvious
* core/vm: terminate tracing using defers
2017-12-21 11:56:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func wrapError(context string, err error) error {
|
2018-07-30 09:30:09 +00:00
|
|
|
return fmt.Errorf("%v in server-side tracer function '%v'", err, context)
|
cmd, core, eth/tracers: support fancier js tracing (#15516)
* cmd, core, eth/tracers: support fancier js tracing
* eth, internal/web3ext: rework trace API, concurrency, chain tracing
* eth/tracers: add three more JavaScript tracers
* eth/tracers, vendor: swap ottovm to duktape for tracing
* core, eth, internal: finalize call tracer and needed extras
* eth, tests: prestate tracer, call test suite, rewinding
* vendor: fix windows builds for tracer js engine
* vendor: temporary duktape fix
* eth/tracers: fix up 4byte and evmdis tracer
* vendor: pull in latest duktape with my upstream fixes
* eth: fix some review comments
* eth: rename rewind to reexec to make it more obvious
* core/vm: terminate tracing using defers
2017-12-21 11:56:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// CaptureStart implements the Tracer interface to initialize the tracing operation.
|
2021-11-05 10:48:21 +00:00
|
|
|
func (jst *jsTracer) CaptureStart(env *vm.EVM, from common.Address, to common.Address, create bool, input []byte, gas uint64, value *big.Int) {
|
cmd, core, eth/tracers: support fancier js tracing (#15516)
* cmd, core, eth/tracers: support fancier js tracing
* eth, internal/web3ext: rework trace API, concurrency, chain tracing
* eth/tracers: add three more JavaScript tracers
* eth/tracers, vendor: swap ottovm to duktape for tracing
* core, eth, internal: finalize call tracer and needed extras
* eth, tests: prestate tracer, call test suite, rewinding
* vendor: fix windows builds for tracer js engine
* vendor: temporary duktape fix
* eth/tracers: fix up 4byte and evmdis tracer
* vendor: pull in latest duktape with my upstream fixes
* eth: fix some review comments
* eth: rename rewind to reexec to make it more obvious
* core/vm: terminate tracing using defers
2017-12-21 11:56:11 +00:00
|
|
|
jst.ctx["type"] = "CALL"
|
|
|
|
if create {
|
|
|
|
jst.ctx["type"] = "CREATE"
|
|
|
|
}
|
|
|
|
jst.ctx["from"] = from
|
|
|
|
jst.ctx["to"] = to
|
|
|
|
jst.ctx["input"] = input
|
|
|
|
jst.ctx["gas"] = gas
|
2021-06-24 09:46:26 +00:00
|
|
|
jst.ctx["gasPrice"] = env.TxContext.GasPrice
|
cmd, core, eth/tracers: support fancier js tracing (#15516)
* cmd, core, eth/tracers: support fancier js tracing
* eth, internal/web3ext: rework trace API, concurrency, chain tracing
* eth/tracers: add three more JavaScript tracers
* eth/tracers, vendor: swap ottovm to duktape for tracing
* core, eth, internal: finalize call tracer and needed extras
* eth, tests: prestate tracer, call test suite, rewinding
* vendor: fix windows builds for tracer js engine
* vendor: temporary duktape fix
* eth/tracers: fix up 4byte and evmdis tracer
* vendor: pull in latest duktape with my upstream fixes
* eth: fix some review comments
* eth: rename rewind to reexec to make it more obvious
* core/vm: terminate tracing using defers
2017-12-21 11:56:11 +00:00
|
|
|
jst.ctx["value"] = value
|
|
|
|
|
2021-03-25 09:13:14 +00:00
|
|
|
// Initialize the context
|
|
|
|
jst.ctx["block"] = env.Context.BlockNumber.Uint64()
|
|
|
|
jst.dbWrapper.db = env.StateDB
|
2021-06-28 12:13:27 +00:00
|
|
|
// Update list of precompiles based on current block
|
|
|
|
rules := env.ChainConfig().Rules(env.Context.BlockNumber)
|
|
|
|
jst.activePrecompiles = vm.ActivePrecompiles(rules)
|
2021-06-24 09:46:26 +00:00
|
|
|
|
2021-03-25 09:13:14 +00:00
|
|
|
// Compute intrinsic gas
|
|
|
|
isHomestead := env.ChainConfig().IsHomestead(env.Context.BlockNumber)
|
|
|
|
isIstanbul := env.ChainConfig().IsIstanbul(env.Context.BlockNumber)
|
|
|
|
intrinsicGas, err := core.IntrinsicGas(input, nil, jst.ctx["type"] == "CREATE", isHomestead, isIstanbul)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
jst.ctx["intrinsicGas"] = intrinsicGas
|
cmd, core, eth/tracers: support fancier js tracing (#15516)
* cmd, core, eth/tracers: support fancier js tracing
* eth, internal/web3ext: rework trace API, concurrency, chain tracing
* eth/tracers: add three more JavaScript tracers
* eth/tracers, vendor: swap ottovm to duktape for tracing
* core, eth, internal: finalize call tracer and needed extras
* eth, tests: prestate tracer, call test suite, rewinding
* vendor: fix windows builds for tracer js engine
* vendor: temporary duktape fix
* eth/tracers: fix up 4byte and evmdis tracer
* vendor: pull in latest duktape with my upstream fixes
* eth: fix some review comments
* eth: rename rewind to reexec to make it more obvious
* core/vm: terminate tracing using defers
2017-12-21 11:56:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// CaptureState implements the Tracer interface to trace a single step of VM execution.
|
2021-11-05 10:48:21 +00:00
|
|
|
func (jst *jsTracer) CaptureState(env *vm.EVM, pc uint64, op vm.OpCode, gas, cost uint64, scope *vm.ScopeContext, rData []byte, depth int, err error) {
|
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 07:31:22 +00:00
|
|
|
if !jst.traceSteps {
|
|
|
|
return
|
|
|
|
}
|
2021-03-25 09:13:14 +00:00
|
|
|
if jst.err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
// If tracing was interrupted, set the error and stop
|
|
|
|
if atomic.LoadUint32(&jst.interrupt) > 0 {
|
|
|
|
jst.err = jst.reason
|
2021-09-16 11:45:16 +00:00
|
|
|
env.Cancel()
|
2021-03-25 09:13:14 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
jst.opWrapper.op = op
|
|
|
|
jst.stackWrapper.stack = scope.Stack
|
|
|
|
jst.memoryWrapper.memory = scope.Memory
|
|
|
|
jst.contractWrapper.contract = scope.Contract
|
|
|
|
|
|
|
|
*jst.pcValue = uint(pc)
|
|
|
|
*jst.gasValue = uint(gas)
|
|
|
|
*jst.costValue = uint(cost)
|
|
|
|
*jst.depthValue = uint(depth)
|
|
|
|
*jst.refundValue = uint(env.StateDB.GetRefund())
|
|
|
|
|
|
|
|
jst.errorValue = nil
|
|
|
|
if err != nil {
|
|
|
|
jst.errorValue = new(string)
|
|
|
|
*jst.errorValue = err.Error()
|
|
|
|
}
|
|
|
|
|
2021-05-11 13:23:54 +00:00
|
|
|
if _, err := jst.call(true, "step", "log", "db"); err != nil {
|
2021-03-25 09:13:14 +00:00
|
|
|
jst.err = wrapError("step", err)
|
cmd, core, eth/tracers: support fancier js tracing (#15516)
* cmd, core, eth/tracers: support fancier js tracing
* eth, internal/web3ext: rework trace API, concurrency, chain tracing
* eth/tracers: add three more JavaScript tracers
* eth/tracers, vendor: swap ottovm to duktape for tracing
* core, eth, internal: finalize call tracer and needed extras
* eth, tests: prestate tracer, call test suite, rewinding
* vendor: fix windows builds for tracer js engine
* vendor: temporary duktape fix
* eth/tracers: fix up 4byte and evmdis tracer
* vendor: pull in latest duktape with my upstream fixes
* eth: fix some review comments
* eth: rename rewind to reexec to make it more obvious
* core/vm: terminate tracing using defers
2017-12-21 11:56:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// CaptureFault implements the Tracer interface to trace an execution fault
|
2021-11-05 10:48:21 +00:00
|
|
|
func (jst *jsTracer) CaptureFault(env *vm.EVM, pc uint64, op vm.OpCode, gas, cost uint64, scope *vm.ScopeContext, depth int, err error) {
|
2021-03-25 09:13:14 +00:00
|
|
|
if jst.err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
// Apart from the error, everything matches the previous invocation
|
|
|
|
jst.errorValue = new(string)
|
|
|
|
*jst.errorValue = err.Error()
|
cmd, core, eth/tracers: support fancier js tracing (#15516)
* cmd, core, eth/tracers: support fancier js tracing
* eth, internal/web3ext: rework trace API, concurrency, chain tracing
* eth/tracers: add three more JavaScript tracers
* eth/tracers, vendor: swap ottovm to duktape for tracing
* core, eth, internal: finalize call tracer and needed extras
* eth, tests: prestate tracer, call test suite, rewinding
* vendor: fix windows builds for tracer js engine
* vendor: temporary duktape fix
* eth/tracers: fix up 4byte and evmdis tracer
* vendor: pull in latest duktape with my upstream fixes
* eth: fix some review comments
* eth: rename rewind to reexec to make it more obvious
* core/vm: terminate tracing using defers
2017-12-21 11:56:11 +00:00
|
|
|
|
2021-05-11 13:23:54 +00:00
|
|
|
if _, err := jst.call(true, "fault", "log", "db"); err != nil {
|
2021-03-25 09:13:14 +00:00
|
|
|
jst.err = wrapError("fault", err)
|
cmd, core, eth/tracers: support fancier js tracing (#15516)
* cmd, core, eth/tracers: support fancier js tracing
* eth, internal/web3ext: rework trace API, concurrency, chain tracing
* eth/tracers: add three more JavaScript tracers
* eth/tracers, vendor: swap ottovm to duktape for tracing
* core, eth, internal: finalize call tracer and needed extras
* eth, tests: prestate tracer, call test suite, rewinding
* vendor: fix windows builds for tracer js engine
* vendor: temporary duktape fix
* eth/tracers: fix up 4byte and evmdis tracer
* vendor: pull in latest duktape with my upstream fixes
* eth: fix some review comments
* eth: rename rewind to reexec to make it more obvious
* core/vm: terminate tracing using defers
2017-12-21 11:56:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// CaptureEnd is called after the call finishes to finalize the tracing.
|
2021-11-05 10:48:21 +00:00
|
|
|
func (jst *jsTracer) CaptureEnd(output []byte, gasUsed uint64, t time.Duration, err error) {
|
cmd, core, eth/tracers: support fancier js tracing (#15516)
* cmd, core, eth/tracers: support fancier js tracing
* eth, internal/web3ext: rework trace API, concurrency, chain tracing
* eth/tracers: add three more JavaScript tracers
* eth/tracers, vendor: swap ottovm to duktape for tracing
* core, eth, internal: finalize call tracer and needed extras
* eth, tests: prestate tracer, call test suite, rewinding
* vendor: fix windows builds for tracer js engine
* vendor: temporary duktape fix
* eth/tracers: fix up 4byte and evmdis tracer
* vendor: pull in latest duktape with my upstream fixes
* eth: fix some review comments
* eth: rename rewind to reexec to make it more obvious
* core/vm: terminate tracing using defers
2017-12-21 11:56:11 +00:00
|
|
|
jst.ctx["output"] = output
|
|
|
|
jst.ctx["time"] = t.String()
|
2020-12-27 20:57:19 +00:00
|
|
|
jst.ctx["gasUsed"] = gasUsed
|
cmd, core, eth/tracers: support fancier js tracing (#15516)
* cmd, core, eth/tracers: support fancier js tracing
* eth, internal/web3ext: rework trace API, concurrency, chain tracing
* eth/tracers: add three more JavaScript tracers
* eth/tracers, vendor: swap ottovm to duktape for tracing
* core, eth, internal: finalize call tracer and needed extras
* eth, tests: prestate tracer, call test suite, rewinding
* vendor: fix windows builds for tracer js engine
* vendor: temporary duktape fix
* eth/tracers: fix up 4byte and evmdis tracer
* vendor: pull in latest duktape with my upstream fixes
* eth: fix some review comments
* eth: rename rewind to reexec to make it more obvious
* core/vm: terminate tracing using defers
2017-12-21 11:56:11 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
jst.ctx["error"] = err.Error()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 07:31:22 +00:00
|
|
|
// CaptureEnter is called when EVM enters a new scope (via call, create or selfdestruct).
|
2021-11-05 10:48:21 +00:00
|
|
|
func (jst *jsTracer) CaptureEnter(typ vm.OpCode, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) {
|
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 07:31:22 +00:00
|
|
|
if !jst.traceCallFrames {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if jst.err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
// If tracing was interrupted, set the error and stop
|
|
|
|
if atomic.LoadUint32(&jst.interrupt) > 0 {
|
|
|
|
jst.err = jst.reason
|
|
|
|
return
|
|
|
|
}
|
cmd, core, eth/tracers: support fancier js tracing (#15516)
* cmd, core, eth/tracers: support fancier js tracing
* eth, internal/web3ext: rework trace API, concurrency, chain tracing
* eth/tracers: add three more JavaScript tracers
* eth/tracers, vendor: swap ottovm to duktape for tracing
* core, eth, internal: finalize call tracer and needed extras
* eth, tests: prestate tracer, call test suite, rewinding
* vendor: fix windows builds for tracer js engine
* vendor: temporary duktape fix
* eth/tracers: fix up 4byte and evmdis tracer
* vendor: pull in latest duktape with my upstream fixes
* eth: fix some review comments
* eth: rename rewind to reexec to make it more obvious
* core/vm: terminate tracing using defers
2017-12-21 11:56:11 +00:00
|
|
|
|
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 07:31:22 +00:00
|
|
|
*jst.frame.typ = typ.String()
|
|
|
|
*jst.frame.from = from
|
|
|
|
*jst.frame.to = to
|
|
|
|
jst.frame.input = common.CopyBytes(input)
|
|
|
|
*jst.frame.gas = uint(gas)
|
|
|
|
jst.frame.value = nil
|
|
|
|
if value != nil {
|
|
|
|
jst.frame.value = new(big.Int).SetBytes(value.Bytes())
|
|
|
|
}
|
cmd, core, eth/tracers: support fancier js tracing (#15516)
* cmd, core, eth/tracers: support fancier js tracing
* eth, internal/web3ext: rework trace API, concurrency, chain tracing
* eth/tracers: add three more JavaScript tracers
* eth/tracers, vendor: swap ottovm to duktape for tracing
* core, eth, internal: finalize call tracer and needed extras
* eth, tests: prestate tracer, call test suite, rewinding
* vendor: fix windows builds for tracer js engine
* vendor: temporary duktape fix
* eth/tracers: fix up 4byte and evmdis tracer
* vendor: pull in latest duktape with my upstream fixes
* eth: fix some review comments
* eth: rename rewind to reexec to make it more obvious
* core/vm: terminate tracing using defers
2017-12-21 11:56:11 +00:00
|
|
|
|
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 07:31:22 +00:00
|
|
|
if _, err := jst.call(true, "enter", "frame"); err != nil {
|
|
|
|
jst.err = wrapError("enter", err)
|
|
|
|
}
|
|
|
|
}
|
cmd, core, eth/tracers: support fancier js tracing (#15516)
* cmd, core, eth/tracers: support fancier js tracing
* eth, internal/web3ext: rework trace API, concurrency, chain tracing
* eth/tracers: add three more JavaScript tracers
* eth/tracers, vendor: swap ottovm to duktape for tracing
* core, eth, internal: finalize call tracer and needed extras
* eth, tests: prestate tracer, call test suite, rewinding
* vendor: fix windows builds for tracer js engine
* vendor: temporary duktape fix
* eth/tracers: fix up 4byte and evmdis tracer
* vendor: pull in latest duktape with my upstream fixes
* eth: fix some review comments
* eth: rename rewind to reexec to make it more obvious
* core/vm: terminate tracing using defers
2017-12-21 11:56:11 +00:00
|
|
|
|
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 07:31:22 +00:00
|
|
|
// CaptureExit is called when EVM exits a scope, even if the scope didn't
|
|
|
|
// execute any code.
|
2021-11-05 10:48:21 +00:00
|
|
|
func (jst *jsTracer) CaptureExit(output []byte, gasUsed uint64, err error) {
|
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 07:31:22 +00:00
|
|
|
if !jst.traceCallFrames {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
// If tracing was interrupted, set the error and stop
|
|
|
|
if atomic.LoadUint32(&jst.interrupt) > 0 {
|
|
|
|
jst.err = jst.reason
|
|
|
|
return
|
|
|
|
}
|
cmd, core, eth/tracers: support fancier js tracing (#15516)
* cmd, core, eth/tracers: support fancier js tracing
* eth, internal/web3ext: rework trace API, concurrency, chain tracing
* eth/tracers: add three more JavaScript tracers
* eth/tracers, vendor: swap ottovm to duktape for tracing
* core, eth, internal: finalize call tracer and needed extras
* eth, tests: prestate tracer, call test suite, rewinding
* vendor: fix windows builds for tracer js engine
* vendor: temporary duktape fix
* eth/tracers: fix up 4byte and evmdis tracer
* vendor: pull in latest duktape with my upstream fixes
* eth: fix some review comments
* eth: rename rewind to reexec to make it more obvious
* core/vm: terminate tracing using defers
2017-12-21 11:56:11 +00:00
|
|
|
|
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 07:31:22 +00:00
|
|
|
jst.frameResult.output = common.CopyBytes(output)
|
|
|
|
*jst.frameResult.gasUsed = uint(gasUsed)
|
|
|
|
jst.frameResult.errorValue = nil
|
|
|
|
if err != nil {
|
|
|
|
jst.frameResult.errorValue = new(string)
|
|
|
|
*jst.frameResult.errorValue = err.Error()
|
|
|
|
}
|
cmd, core, eth/tracers: support fancier js tracing (#15516)
* cmd, core, eth/tracers: support fancier js tracing
* eth, internal/web3ext: rework trace API, concurrency, chain tracing
* eth/tracers: add three more JavaScript tracers
* eth/tracers, vendor: swap ottovm to duktape for tracing
* core, eth, internal: finalize call tracer and needed extras
* eth, tests: prestate tracer, call test suite, rewinding
* vendor: fix windows builds for tracer js engine
* vendor: temporary duktape fix
* eth/tracers: fix up 4byte and evmdis tracer
* vendor: pull in latest duktape with my upstream fixes
* eth: fix some review comments
* eth: rename rewind to reexec to make it more obvious
* core/vm: terminate tracing using defers
2017-12-21 11:56:11 +00:00
|
|
|
|
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 07:31:22 +00:00
|
|
|
if _, err := jst.call(true, "exit", "frameResult"); err != nil {
|
|
|
|
jst.err = wrapError("exit", err)
|
|
|
|
}
|
|
|
|
}
|
2021-06-25 06:02:15 +00:00
|
|
|
|
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 07:31:22 +00:00
|
|
|
// GetResult calls the Javascript 'result' function and returns its value, or any accumulated error
|
2021-11-05 10:48:21 +00:00
|
|
|
func (jst *jsTracer) GetResult() (json.RawMessage, error) {
|
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 07:31:22 +00:00
|
|
|
// Transform the context into a JavaScript object and inject into the state
|
|
|
|
obj := jst.vm.PushObject()
|
2021-06-25 06:02:15 +00:00
|
|
|
|
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 07:31:22 +00:00
|
|
|
for key, val := range jst.ctx {
|
|
|
|
jst.addToObj(obj, key, val)
|
cmd, core, eth/tracers: support fancier js tracing (#15516)
* cmd, core, eth/tracers: support fancier js tracing
* eth, internal/web3ext: rework trace API, concurrency, chain tracing
* eth/tracers: add three more JavaScript tracers
* eth/tracers, vendor: swap ottovm to duktape for tracing
* core, eth, internal: finalize call tracer and needed extras
* eth, tests: prestate tracer, call test suite, rewinding
* vendor: fix windows builds for tracer js engine
* vendor: temporary duktape fix
* eth/tracers: fix up 4byte and evmdis tracer
* vendor: pull in latest duktape with my upstream fixes
* eth: fix some review comments
* eth: rename rewind to reexec to make it more obvious
* core/vm: terminate tracing using defers
2017-12-21 11:56:11 +00:00
|
|
|
}
|
|
|
|
jst.vm.PutPropString(jst.stateObject, "ctx")
|
|
|
|
|
|
|
|
// Finalize the trace and return the results
|
2021-05-11 13:23:54 +00:00
|
|
|
result, err := jst.call(false, "result", "ctx", "db")
|
cmd, core, eth/tracers: support fancier js tracing (#15516)
* cmd, core, eth/tracers: support fancier js tracing
* eth, internal/web3ext: rework trace API, concurrency, chain tracing
* eth/tracers: add three more JavaScript tracers
* eth/tracers, vendor: swap ottovm to duktape for tracing
* core, eth, internal: finalize call tracer and needed extras
* eth, tests: prestate tracer, call test suite, rewinding
* vendor: fix windows builds for tracer js engine
* vendor: temporary duktape fix
* eth/tracers: fix up 4byte and evmdis tracer
* vendor: pull in latest duktape with my upstream fixes
* eth: fix some review comments
* eth: rename rewind to reexec to make it more obvious
* core/vm: terminate tracing using defers
2017-12-21 11:56:11 +00:00
|
|
|
if err != nil {
|
|
|
|
jst.err = wrapError("result", err)
|
|
|
|
}
|
|
|
|
// Clean up the JavaScript environment
|
|
|
|
jst.vm.DestroyHeap()
|
|
|
|
jst.vm.Destroy()
|
|
|
|
|
|
|
|
return result, jst.err
|
|
|
|
}
|
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 07:31:22 +00:00
|
|
|
|
|
|
|
// addToObj pushes a field to a JS object.
|
2021-11-05 10:48:21 +00:00
|
|
|
func (jst *jsTracer) addToObj(obj int, key string, val interface{}) {
|
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 07:31:22 +00:00
|
|
|
pushValue(jst.vm, val)
|
|
|
|
jst.vm.PutPropString(obj, key)
|
|
|
|
}
|
|
|
|
|
|
|
|
func pushValue(ctx *duktape.Context, val interface{}) {
|
|
|
|
switch val := val.(type) {
|
|
|
|
case uint64:
|
|
|
|
ctx.PushUint(uint(val))
|
|
|
|
case string:
|
|
|
|
ctx.PushString(val)
|
|
|
|
case []byte:
|
|
|
|
ptr := ctx.PushFixedBuffer(len(val))
|
|
|
|
copy(makeSlice(ptr, uint(len(val))), val)
|
|
|
|
case common.Address:
|
|
|
|
ptr := ctx.PushFixedBuffer(20)
|
|
|
|
copy(makeSlice(ptr, 20), val[:])
|
|
|
|
case *big.Int:
|
|
|
|
pushBigInt(val, ctx)
|
|
|
|
case int:
|
|
|
|
ctx.PushInt(val)
|
|
|
|
case uint:
|
|
|
|
ctx.PushUint(val)
|
|
|
|
case common.Hash:
|
|
|
|
ptr := ctx.PushFixedBuffer(32)
|
|
|
|
copy(makeSlice(ptr, 32), val[:])
|
|
|
|
default:
|
|
|
|
panic(fmt.Sprintf("unsupported type: %T", val))
|
|
|
|
}
|
|
|
|
}
|