2021-11-09 14:09:35 +03:00
|
|
|
// Copyright 2021 The go-ethereum Authors
|
|
|
|
// 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 tracetest
|
2021-11-05 13:48:21 +03:00
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"math/big"
|
2022-05-16 12:59:35 +03:00
|
|
|
"os"
|
2021-11-05 13:48:21 +03:00
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
|
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
|
|
|
"github.com/ethereum/go-ethereum/common/math"
|
|
|
|
"github.com/ethereum/go-ethereum/core"
|
|
|
|
"github.com/ethereum/go-ethereum/core/rawdb"
|
|
|
|
"github.com/ethereum/go-ethereum/core/types"
|
|
|
|
"github.com/ethereum/go-ethereum/core/vm"
|
|
|
|
"github.com/ethereum/go-ethereum/eth/tracers"
|
2021-11-09 14:09:35 +03:00
|
|
|
"github.com/ethereum/go-ethereum/params"
|
2021-11-05 13:48:21 +03:00
|
|
|
"github.com/ethereum/go-ethereum/rlp"
|
|
|
|
"github.com/ethereum/go-ethereum/tests"
|
|
|
|
)
|
|
|
|
|
|
|
|
type callContext struct {
|
|
|
|
Number math.HexOrDecimal64 `json:"number"`
|
|
|
|
Difficulty *math.HexOrDecimal256 `json:"difficulty"`
|
|
|
|
Time math.HexOrDecimal64 `json:"timestamp"`
|
|
|
|
GasLimit math.HexOrDecimal64 `json:"gasLimit"`
|
|
|
|
Miner common.Address `json:"miner"`
|
|
|
|
}
|
|
|
|
|
2022-11-01 14:03:26 +03:00
|
|
|
// callLog is the result of LOG opCode
|
|
|
|
type callLog struct {
|
|
|
|
Address common.Address `json:"address"`
|
|
|
|
Topics []common.Hash `json:"topics"`
|
|
|
|
Data hexutil.Bytes `json:"data"`
|
|
|
|
}
|
|
|
|
|
2021-11-05 13:48:21 +03:00
|
|
|
// callTrace is the result of a callTracer run.
|
|
|
|
type callTrace struct {
|
2023-01-31 11:29:17 +03:00
|
|
|
From common.Address `json:"from"`
|
|
|
|
Gas *hexutil.Uint64 `json:"gas"`
|
|
|
|
GasUsed *hexutil.Uint64 `json:"gasUsed"`
|
2023-03-07 16:39:11 +03:00
|
|
|
To *common.Address `json:"to,omitempty"`
|
2023-01-31 11:29:17 +03:00
|
|
|
Input hexutil.Bytes `json:"input"`
|
|
|
|
Output hexutil.Bytes `json:"output,omitempty"`
|
|
|
|
Error string `json:"error,omitempty"`
|
|
|
|
RevertReason string `json:"revertReason,omitempty"`
|
|
|
|
Calls []callTrace `json:"calls,omitempty"`
|
|
|
|
Logs []callLog `json:"logs,omitempty"`
|
|
|
|
Value *hexutil.Big `json:"value,omitempty"`
|
2022-10-21 18:55:15 +03:00
|
|
|
// Gencodec adds overridden fields at the end
|
|
|
|
Type string `json:"type"`
|
2021-11-05 13:48:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// callTracerTest defines a single test to check the call tracer against.
|
|
|
|
type callTracerTest struct {
|
2022-08-09 12:04:57 +03:00
|
|
|
Genesis *core.Genesis `json:"genesis"`
|
|
|
|
Context *callContext `json:"context"`
|
|
|
|
Input string `json:"input"`
|
|
|
|
TracerConfig json.RawMessage `json:"tracerConfig"`
|
|
|
|
Result *callTrace `json:"result"`
|
2021-11-05 13:48:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Iterates over all the input-output datasets in the tracer test harness and
|
|
|
|
// runs the JavaScript tracers against them.
|
|
|
|
func TestCallTracerLegacy(t *testing.T) {
|
|
|
|
testCallTracer("callTracerLegacy", "call_tracer_legacy", t)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCallTracerNative(t *testing.T) {
|
2021-11-08 16:08:12 +03:00
|
|
|
testCallTracer("callTracer", "call_tracer", t)
|
2021-11-05 13:48:21 +03:00
|
|
|
}
|
|
|
|
|
2022-11-01 14:03:26 +03:00
|
|
|
func TestCallTracerNativeWithLog(t *testing.T) {
|
|
|
|
testCallTracer("callTracer", "call_tracer_withLog", t)
|
|
|
|
}
|
|
|
|
|
2021-11-05 13:48:21 +03:00
|
|
|
func testCallTracer(tracerName string, dirPath string, t *testing.T) {
|
2022-10-28 13:28:29 +03:00
|
|
|
isLegacy := strings.HasSuffix(dirPath, "_legacy")
|
2022-05-17 15:27:04 +03:00
|
|
|
files, err := os.ReadDir(filepath.Join("testdata", dirPath))
|
2021-11-05 13:48:21 +03:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("failed to retrieve tracer test suite: %v", err)
|
|
|
|
}
|
|
|
|
for _, file := range files {
|
|
|
|
if !strings.HasSuffix(file.Name(), ".json") {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
file := file // capture range variable
|
|
|
|
t.Run(camel(strings.TrimSuffix(file.Name(), ".json")), func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
var (
|
|
|
|
test = new(callTracerTest)
|
|
|
|
tx = new(types.Transaction)
|
|
|
|
)
|
|
|
|
// Call tracer test found, read if from disk
|
2022-05-16 12:59:35 +03:00
|
|
|
if blob, err := os.ReadFile(filepath.Join("testdata", dirPath, file.Name())); err != nil {
|
2021-11-05 13:48:21 +03:00
|
|
|
t.Fatalf("failed to read testcase: %v", err)
|
|
|
|
} else if err := json.Unmarshal(blob, test); err != nil {
|
|
|
|
t.Fatalf("failed to parse testcase: %v", err)
|
|
|
|
}
|
2022-10-12 13:50:01 +03:00
|
|
|
if err := tx.UnmarshalBinary(common.FromHex(test.Input)); err != nil {
|
2021-11-05 13:48:21 +03:00
|
|
|
t.Fatalf("failed to parse testcase input: %v", err)
|
|
|
|
}
|
|
|
|
// Configure a blockchain with the given prestate
|
|
|
|
var (
|
2023-04-21 12:52:02 +03:00
|
|
|
signer = types.MakeSigner(test.Genesis.Config, new(big.Int).SetUint64(uint64(test.Context.Number)), uint64(test.Context.Time))
|
2021-11-05 13:48:21 +03:00
|
|
|
origin, _ = signer.Sender(tx)
|
|
|
|
txContext = vm.TxContext{
|
|
|
|
Origin: origin,
|
|
|
|
GasPrice: tx.GasPrice(),
|
|
|
|
}
|
|
|
|
context = vm.BlockContext{
|
|
|
|
CanTransfer: core.CanTransfer,
|
|
|
|
Transfer: core.Transfer,
|
|
|
|
Coinbase: test.Context.Miner,
|
|
|
|
BlockNumber: new(big.Int).SetUint64(uint64(test.Context.Number)),
|
2023-01-25 14:12:28 +03:00
|
|
|
Time: uint64(test.Context.Time),
|
2021-11-05 13:48:21 +03:00
|
|
|
Difficulty: (*big.Int)(test.Context.Difficulty),
|
|
|
|
GasLimit: uint64(test.Context.GasLimit),
|
2022-10-12 13:50:01 +03:00
|
|
|
BaseFee: test.Genesis.BaseFee,
|
2021-11-05 13:48:21 +03:00
|
|
|
}
|
all: activate pbss as experimental feature (#26274)
* all: activate pbss
* core/rawdb: fix compilation error
* cma, core, eth, les, trie: address comments
* cmd, core, eth, trie: polish code
* core, cmd, eth: address comments
* cmd, core, eth, les, light, tests: address comment
* cmd/utils: shorten log message
* trie/triedb/pathdb: limit node buffer size to 1gb
* cmd/utils: fix opening non-existing db
* cmd/utils: rename flag name
* cmd, core: group chain history flags and fix tests
* core, eth, trie: fix memory leak in snapshot generation
* cmd, eth, internal: deprecate flags
* all: enable state tests for pathdb, fixes
* cmd, core: polish code
* trie/triedb/pathdb: limit the node buffer size to 256mb
---------
Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: Péter Szilágyi <peterke@gmail.com>
2023-08-10 22:21:36 +03:00
|
|
|
triedb, _, statedb = tests.MakePreState(rawdb.NewMemoryDatabase(), test.Genesis.Alloc, false, rawdb.HashScheme)
|
2021-11-05 13:48:21 +03:00
|
|
|
)
|
all: activate pbss as experimental feature (#26274)
* all: activate pbss
* core/rawdb: fix compilation error
* cma, core, eth, les, trie: address comments
* cmd, core, eth, trie: polish code
* core, cmd, eth: address comments
* cmd, core, eth, les, light, tests: address comment
* cmd/utils: shorten log message
* trie/triedb/pathdb: limit node buffer size to 1gb
* cmd/utils: fix opening non-existing db
* cmd/utils: rename flag name
* cmd, core: group chain history flags and fix tests
* core, eth, trie: fix memory leak in snapshot generation
* cmd, eth, internal: deprecate flags
* all: enable state tests for pathdb, fixes
* cmd, core: polish code
* trie/triedb/pathdb: limit the node buffer size to 256mb
---------
Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: Péter Szilágyi <peterke@gmail.com>
2023-08-10 22:21:36 +03:00
|
|
|
triedb.Close()
|
|
|
|
|
2023-01-10 17:11:53 +03:00
|
|
|
tracer, err := tracers.DefaultDirectory.New(tracerName, new(tracers.Context), test.TracerConfig)
|
2021-11-05 13:48:21 +03:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("failed to create call tracer: %v", err)
|
|
|
|
}
|
2023-04-04 16:50:13 +03:00
|
|
|
evm := vm.NewEVM(context, txContext, statedb, test.Genesis.Config, vm.Config{Tracer: tracer})
|
core, core/types: plain Message struct (#25977)
Here, the core.Message interface turns into a plain struct and
types.Message gets removed.
This is a breaking change to packages core and core/types. While we do
not promise API stability for package core, we do for core/types. An
exception can be made for types.Message, since it doesn't have any
purpose apart from invoking the state transition in package core.
types.Message was also marked deprecated by the same commit it
got added in, 4dca5d4db7 (November 2016).
The core.Message interface was added in December 2014, in commit
db494170dc, for the purpose of 'testing' state transitions. It's the
same change that made transaction struct fields private. Before that,
the state transition used *types.Transaction directly.
Over time, multiple implementations of the interface accrued across
different packages, since constructing a Message is required whenever
one wants to invoke the state transition. These implementations all
looked very similar, a struct with private fields exposing the fields
as accessor methods.
By changing Message into a struct with public fields we can remove all
these useless interface implementations. It will also hopefully
simplify future changes to the type with less updates to apply across
all of go-ethereum when a field is added to Message.
---------
Co-authored-by: Felix Lange <fjl@twurst.com>
2023-03-09 16:19:12 +03:00
|
|
|
msg, err := core.TransactionToMessage(tx, signer, nil)
|
2021-11-05 13:48:21 +03:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("failed to prepare transaction for tracing: %v", err)
|
|
|
|
}
|
2022-10-28 13:28:29 +03:00
|
|
|
vmRet, err := core.ApplyMessage(evm, msg, new(core.GasPool).AddGas(tx.Gas()))
|
|
|
|
if err != nil {
|
2021-11-05 13:48:21 +03:00
|
|
|
t.Fatalf("failed to execute transaction: %v", err)
|
|
|
|
}
|
2022-10-11 10:37:00 +03:00
|
|
|
// Retrieve the trace result and compare against the expected.
|
2021-11-05 13:48:21 +03:00
|
|
|
res, err := tracer.GetResult()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("failed to retrieve trace result: %v", err)
|
|
|
|
}
|
2022-10-21 18:55:15 +03:00
|
|
|
// The legacy javascript calltracer marshals json in js, which
|
|
|
|
// is not deterministic (as opposed to the golang json encoder).
|
2022-10-28 13:28:29 +03:00
|
|
|
if isLegacy {
|
2022-10-21 18:55:15 +03:00
|
|
|
// This is a tweak to make it deterministic. Can be removed when
|
|
|
|
// we remove the legacy tracer.
|
|
|
|
var x callTrace
|
|
|
|
json.Unmarshal(res, &x)
|
|
|
|
res, _ = json.Marshal(x)
|
2021-11-05 13:48:21 +03:00
|
|
|
}
|
2022-10-21 18:55:15 +03:00
|
|
|
want, err := json.Marshal(test.Result)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("failed to marshal test: %v", err)
|
|
|
|
}
|
|
|
|
if string(want) != string(res) {
|
|
|
|
t.Fatalf("trace mismatch\n have: %v\n want: %v\n", string(res), string(want))
|
2021-11-05 13:48:21 +03:00
|
|
|
}
|
2022-10-28 13:28:29 +03:00
|
|
|
// Sanity check: compare top call's gas used against vm result
|
|
|
|
type simpleResult struct {
|
|
|
|
GasUsed hexutil.Uint64
|
|
|
|
}
|
|
|
|
var topCall simpleResult
|
|
|
|
if err := json.Unmarshal(res, &topCall); err != nil {
|
|
|
|
t.Fatalf("failed to unmarshal top calls gasUsed: %v", err)
|
|
|
|
}
|
|
|
|
if uint64(topCall.GasUsed) != vmRet.UsedGas {
|
|
|
|
t.Fatalf("top call has invalid gasUsed. have: %d want: %d", topCall.GasUsed, vmRet.UsedGas)
|
|
|
|
}
|
2021-11-05 13:48:21 +03:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkTracers(b *testing.B) {
|
2022-05-17 15:27:04 +03:00
|
|
|
files, err := os.ReadDir(filepath.Join("testdata", "call_tracer"))
|
2021-11-05 13:48:21 +03:00
|
|
|
if err != nil {
|
|
|
|
b.Fatalf("failed to retrieve tracer test suite: %v", err)
|
|
|
|
}
|
|
|
|
for _, file := range files {
|
|
|
|
if !strings.HasSuffix(file.Name(), ".json") {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
file := file // capture range variable
|
|
|
|
b.Run(camel(strings.TrimSuffix(file.Name(), ".json")), func(b *testing.B) {
|
2022-05-16 12:59:35 +03:00
|
|
|
blob, err := os.ReadFile(filepath.Join("testdata", "call_tracer", file.Name()))
|
2021-11-05 13:48:21 +03:00
|
|
|
if err != nil {
|
|
|
|
b.Fatalf("failed to read testcase: %v", err)
|
|
|
|
}
|
|
|
|
test := new(callTracerTest)
|
|
|
|
if err := json.Unmarshal(blob, test); err != nil {
|
|
|
|
b.Fatalf("failed to parse testcase: %v", err)
|
|
|
|
}
|
2022-05-18 17:34:18 +03:00
|
|
|
benchTracer("callTracer", test, b)
|
2021-11-05 13:48:21 +03:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func benchTracer(tracerName string, test *callTracerTest, b *testing.B) {
|
|
|
|
// Configure a blockchain with the given prestate
|
|
|
|
tx := new(types.Transaction)
|
|
|
|
if err := rlp.DecodeBytes(common.FromHex(test.Input), tx); err != nil {
|
|
|
|
b.Fatalf("failed to parse testcase input: %v", err)
|
|
|
|
}
|
2023-04-21 12:52:02 +03:00
|
|
|
signer := types.MakeSigner(test.Genesis.Config, new(big.Int).SetUint64(uint64(test.Context.Number)), uint64(test.Context.Time))
|
core, core/types: plain Message struct (#25977)
Here, the core.Message interface turns into a plain struct and
types.Message gets removed.
This is a breaking change to packages core and core/types. While we do
not promise API stability for package core, we do for core/types. An
exception can be made for types.Message, since it doesn't have any
purpose apart from invoking the state transition in package core.
types.Message was also marked deprecated by the same commit it
got added in, 4dca5d4db7 (November 2016).
The core.Message interface was added in December 2014, in commit
db494170dc, for the purpose of 'testing' state transitions. It's the
same change that made transaction struct fields private. Before that,
the state transition used *types.Transaction directly.
Over time, multiple implementations of the interface accrued across
different packages, since constructing a Message is required whenever
one wants to invoke the state transition. These implementations all
looked very similar, a struct with private fields exposing the fields
as accessor methods.
By changing Message into a struct with public fields we can remove all
these useless interface implementations. It will also hopefully
simplify future changes to the type with less updates to apply across
all of go-ethereum when a field is added to Message.
---------
Co-authored-by: Felix Lange <fjl@twurst.com>
2023-03-09 16:19:12 +03:00
|
|
|
msg, err := core.TransactionToMessage(tx, signer, nil)
|
2021-11-05 13:48:21 +03:00
|
|
|
if err != nil {
|
|
|
|
b.Fatalf("failed to prepare transaction for tracing: %v", err)
|
|
|
|
}
|
|
|
|
origin, _ := signer.Sender(tx)
|
|
|
|
txContext := vm.TxContext{
|
|
|
|
Origin: origin,
|
|
|
|
GasPrice: tx.GasPrice(),
|
|
|
|
}
|
|
|
|
context := vm.BlockContext{
|
|
|
|
CanTransfer: core.CanTransfer,
|
|
|
|
Transfer: core.Transfer,
|
|
|
|
Coinbase: test.Context.Miner,
|
|
|
|
BlockNumber: new(big.Int).SetUint64(uint64(test.Context.Number)),
|
2023-01-25 14:12:28 +03:00
|
|
|
Time: uint64(test.Context.Time),
|
2021-11-05 13:48:21 +03:00
|
|
|
Difficulty: (*big.Int)(test.Context.Difficulty),
|
|
|
|
GasLimit: uint64(test.Context.GasLimit),
|
|
|
|
}
|
all: activate pbss as experimental feature (#26274)
* all: activate pbss
* core/rawdb: fix compilation error
* cma, core, eth, les, trie: address comments
* cmd, core, eth, trie: polish code
* core, cmd, eth: address comments
* cmd, core, eth, les, light, tests: address comment
* cmd/utils: shorten log message
* trie/triedb/pathdb: limit node buffer size to 1gb
* cmd/utils: fix opening non-existing db
* cmd/utils: rename flag name
* cmd, core: group chain history flags and fix tests
* core, eth, trie: fix memory leak in snapshot generation
* cmd, eth, internal: deprecate flags
* all: enable state tests for pathdb, fixes
* cmd, core: polish code
* trie/triedb/pathdb: limit the node buffer size to 256mb
---------
Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: Péter Szilágyi <peterke@gmail.com>
2023-08-10 22:21:36 +03:00
|
|
|
triedb, _, statedb := tests.MakePreState(rawdb.NewMemoryDatabase(), test.Genesis.Alloc, false, rawdb.HashScheme)
|
|
|
|
defer triedb.Close()
|
2021-11-05 13:48:21 +03:00
|
|
|
|
|
|
|
b.ReportAllocs()
|
|
|
|
b.ResetTimer()
|
|
|
|
for i := 0; i < b.N; i++ {
|
2023-01-10 17:11:53 +03:00
|
|
|
tracer, err := tracers.DefaultDirectory.New(tracerName, new(tracers.Context), nil)
|
2021-11-05 13:48:21 +03:00
|
|
|
if err != nil {
|
|
|
|
b.Fatalf("failed to create call tracer: %v", err)
|
|
|
|
}
|
2023-04-04 16:50:13 +03:00
|
|
|
evm := vm.NewEVM(context, txContext, statedb, test.Genesis.Config, vm.Config{Tracer: tracer})
|
2021-11-05 13:48:21 +03:00
|
|
|
snap := statedb.Snapshot()
|
|
|
|
st := core.NewStateTransition(evm, msg, new(core.GasPool).AddGas(tx.Gas()))
|
|
|
|
if _, err = st.TransitionDb(); err != nil {
|
|
|
|
b.Fatalf("failed to execute transaction: %v", err)
|
|
|
|
}
|
|
|
|
if _, err = tracer.GetResult(); err != nil {
|
|
|
|
b.Fatal(err)
|
|
|
|
}
|
|
|
|
statedb.RevertToSnapshot(snap)
|
|
|
|
}
|
|
|
|
}
|
2021-11-09 14:09:35 +03:00
|
|
|
|
2023-03-28 12:46:53 +03:00
|
|
|
func TestInternals(t *testing.T) {
|
|
|
|
var (
|
|
|
|
to = common.HexToAddress("0x00000000000000000000000000000000deadbeef")
|
|
|
|
origin = common.HexToAddress("0x00000000000000000000000000000000feed")
|
|
|
|
txContext = vm.TxContext{
|
|
|
|
Origin: origin,
|
|
|
|
GasPrice: big.NewInt(1),
|
|
|
|
}
|
|
|
|
context = vm.BlockContext{
|
|
|
|
CanTransfer: core.CanTransfer,
|
|
|
|
Transfer: core.Transfer,
|
|
|
|
Coinbase: common.Address{},
|
|
|
|
BlockNumber: new(big.Int).SetUint64(8000000),
|
|
|
|
Time: 5,
|
|
|
|
Difficulty: big.NewInt(0x30000),
|
|
|
|
GasLimit: uint64(6000000),
|
|
|
|
}
|
|
|
|
)
|
|
|
|
mkTracer := func(name string, cfg json.RawMessage) tracers.Tracer {
|
|
|
|
tr, err := tracers.DefaultDirectory.New(name, nil, cfg)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("failed to create call tracer: %v", err)
|
|
|
|
}
|
|
|
|
return tr
|
2021-11-09 14:09:35 +03:00
|
|
|
}
|
2023-03-28 12:46:53 +03:00
|
|
|
|
|
|
|
for _, tc := range []struct {
|
|
|
|
name string
|
|
|
|
code []byte
|
|
|
|
tracer tracers.Tracer
|
|
|
|
want string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
// TestZeroValueToNotExitCall tests the calltracer(s) on the following:
|
|
|
|
// Tx to A, A calls B with zero value. B does not already exist.
|
|
|
|
// Expected: that enter/exit is invoked and the inner call is shown in the result
|
|
|
|
name: "ZeroValueToNotExitCall",
|
|
|
|
code: []byte{
|
|
|
|
byte(vm.PUSH1), 0x0, byte(vm.DUP1), byte(vm.DUP1), byte(vm.DUP1), // in and outs zero
|
|
|
|
byte(vm.DUP1), byte(vm.PUSH1), 0xff, byte(vm.GAS), // value=0,address=0xff, gas=GAS
|
|
|
|
byte(vm.CALL),
|
|
|
|
},
|
|
|
|
tracer: mkTracer("callTracer", nil),
|
2023-07-13 15:44:42 +03:00
|
|
|
want: `{"from":"0x000000000000000000000000000000000000feed","gas":"0x13880","gasUsed":"0x54d8","to":"0x00000000000000000000000000000000deadbeef","input":"0x","calls":[{"from":"0x00000000000000000000000000000000deadbeef","gas":"0xe01a","gasUsed":"0x0","to":"0x00000000000000000000000000000000000000ff","input":"0x","value":"0x0","type":"CALL"}],"value":"0x0","type":"CALL"}`,
|
2021-11-09 14:09:35 +03:00
|
|
|
},
|
2023-03-28 12:46:53 +03:00
|
|
|
{
|
|
|
|
name: "Stack depletion in LOG0",
|
|
|
|
code: []byte{byte(vm.LOG3)},
|
|
|
|
tracer: mkTracer("callTracer", json.RawMessage(`{ "withLog": true }`)),
|
2023-07-13 15:44:42 +03:00
|
|
|
want: `{"from":"0x000000000000000000000000000000000000feed","gas":"0x13880","gasUsed":"0x13880","to":"0x00000000000000000000000000000000deadbeef","input":"0x","error":"stack underflow (0 \u003c=\u003e 5)","value":"0x0","type":"CALL"}`,
|
2021-11-09 14:09:35 +03:00
|
|
|
},
|
2023-03-28 12:46:53 +03:00
|
|
|
{
|
|
|
|
name: "Mem expansion in LOG0",
|
|
|
|
code: []byte{
|
|
|
|
byte(vm.PUSH1), 0x1,
|
|
|
|
byte(vm.PUSH1), 0x0,
|
|
|
|
byte(vm.MSTORE),
|
|
|
|
byte(vm.PUSH1), 0xff,
|
|
|
|
byte(vm.PUSH1), 0x0,
|
|
|
|
byte(vm.LOG0),
|
|
|
|
},
|
|
|
|
tracer: mkTracer("callTracer", json.RawMessage(`{ "withLog": true }`)),
|
2023-07-13 15:44:42 +03:00
|
|
|
want: `{"from":"0x000000000000000000000000000000000000feed","gas":"0x13880","gasUsed":"0x5b9e","to":"0x00000000000000000000000000000000deadbeef","input":"0x","logs":[{"address":"0x00000000000000000000000000000000deadbeef","topics":[],"data":"0x000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"}],"value":"0x0","type":"CALL"}`,
|
2023-03-28 12:46:53 +03:00
|
|
|
},
|
|
|
|
{
|
|
|
|
// Leads to OOM on the prestate tracer
|
2023-07-13 15:44:42 +03:00
|
|
|
name: "Prestate-tracer - CREATE2 OOM",
|
2023-03-28 12:46:53 +03:00
|
|
|
code: []byte{
|
|
|
|
byte(vm.PUSH1), 0x1,
|
|
|
|
byte(vm.PUSH1), 0x0,
|
|
|
|
byte(vm.MSTORE),
|
|
|
|
byte(vm.PUSH1), 0x1,
|
|
|
|
byte(vm.PUSH5), 0xff, 0xff, 0xff, 0xff, 0xff,
|
|
|
|
byte(vm.PUSH1), 0x1,
|
|
|
|
byte(vm.PUSH1), 0x0,
|
|
|
|
byte(vm.CREATE2),
|
|
|
|
byte(vm.PUSH1), 0xff,
|
|
|
|
byte(vm.PUSH1), 0x0,
|
|
|
|
byte(vm.LOG0),
|
|
|
|
},
|
2023-07-13 15:44:42 +03:00
|
|
|
tracer: mkTracer("prestateTracer", nil),
|
|
|
|
want: `{"0x0000000000000000000000000000000000000000":{"balance":"0x0"},"0x000000000000000000000000000000000000feed":{"balance":"0x1c6bf52647880"},"0x00000000000000000000000000000000deadbeef":{"balance":"0x0","code":"0x6001600052600164ffffffffff60016000f560ff6000a0"}}`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// CREATE2 which requires padding memory by prestate tracer
|
|
|
|
name: "Prestate-tracer - CREATE2 Memory padding",
|
|
|
|
code: []byte{
|
|
|
|
byte(vm.PUSH1), 0x1,
|
|
|
|
byte(vm.PUSH1), 0x0,
|
|
|
|
byte(vm.MSTORE),
|
|
|
|
byte(vm.PUSH1), 0x1,
|
|
|
|
byte(vm.PUSH1), 0xff,
|
|
|
|
byte(vm.PUSH1), 0x1,
|
|
|
|
byte(vm.PUSH1), 0x0,
|
|
|
|
byte(vm.CREATE2),
|
|
|
|
byte(vm.PUSH1), 0xff,
|
|
|
|
byte(vm.PUSH1), 0x0,
|
|
|
|
byte(vm.LOG0),
|
|
|
|
},
|
|
|
|
tracer: mkTracer("prestateTracer", nil),
|
|
|
|
want: `{"0x0000000000000000000000000000000000000000":{"balance":"0x0"},"0x000000000000000000000000000000000000feed":{"balance":"0x1c6bf52647880"},"0x00000000000000000000000000000000deadbeef":{"balance":"0x0","code":"0x6001600052600160ff60016000f560ff6000a0"},"0x91ff9a805d36f54e3e272e230f3e3f5c1b330804":{"balance":"0x0"}}`,
|
2023-03-28 12:46:53 +03:00
|
|
|
},
|
|
|
|
} {
|
2023-07-13 15:44:42 +03:00
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
all: activate pbss as experimental feature (#26274)
* all: activate pbss
* core/rawdb: fix compilation error
* cma, core, eth, les, trie: address comments
* cmd, core, eth, trie: polish code
* core, cmd, eth: address comments
* cmd, core, eth, les, light, tests: address comment
* cmd/utils: shorten log message
* trie/triedb/pathdb: limit node buffer size to 1gb
* cmd/utils: fix opening non-existing db
* cmd/utils: rename flag name
* cmd, core: group chain history flags and fix tests
* core, eth, trie: fix memory leak in snapshot generation
* cmd, eth, internal: deprecate flags
* all: enable state tests for pathdb, fixes
* cmd, core: polish code
* trie/triedb/pathdb: limit the node buffer size to 256mb
---------
Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: Péter Szilágyi <peterke@gmail.com>
2023-08-10 22:21:36 +03:00
|
|
|
triedb, _, statedb := tests.MakePreState(rawdb.NewMemoryDatabase(),
|
2023-07-13 15:44:42 +03:00
|
|
|
core.GenesisAlloc{
|
|
|
|
to: core.GenesisAccount{
|
|
|
|
Code: tc.code,
|
|
|
|
},
|
|
|
|
origin: core.GenesisAccount{
|
|
|
|
Balance: big.NewInt(500000000000000),
|
|
|
|
},
|
all: activate pbss as experimental feature (#26274)
* all: activate pbss
* core/rawdb: fix compilation error
* cma, core, eth, les, trie: address comments
* cmd, core, eth, trie: polish code
* core, cmd, eth: address comments
* cmd, core, eth, les, light, tests: address comment
* cmd/utils: shorten log message
* trie/triedb/pathdb: limit node buffer size to 1gb
* cmd/utils: fix opening non-existing db
* cmd/utils: rename flag name
* cmd, core: group chain history flags and fix tests
* core, eth, trie: fix memory leak in snapshot generation
* cmd, eth, internal: deprecate flags
* all: enable state tests for pathdb, fixes
* cmd, core: polish code
* trie/triedb/pathdb: limit the node buffer size to 256mb
---------
Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: Péter Szilágyi <peterke@gmail.com>
2023-08-10 22:21:36 +03:00
|
|
|
}, false, rawdb.HashScheme)
|
|
|
|
defer triedb.Close()
|
|
|
|
|
2023-07-13 15:44:42 +03:00
|
|
|
evm := vm.NewEVM(context, txContext, statedb, params.MainnetChainConfig, vm.Config{Tracer: tc.tracer})
|
|
|
|
msg := &core.Message{
|
|
|
|
To: &to,
|
|
|
|
From: origin,
|
|
|
|
Value: big.NewInt(0),
|
|
|
|
GasLimit: 80000,
|
|
|
|
GasPrice: big.NewInt(0),
|
|
|
|
GasFeeCap: big.NewInt(0),
|
|
|
|
GasTipCap: big.NewInt(0),
|
|
|
|
SkipAccountChecks: false,
|
|
|
|
}
|
|
|
|
st := core.NewStateTransition(evm, msg, new(core.GasPool).AddGas(msg.GasLimit))
|
|
|
|
if _, err := st.TransitionDb(); err != nil {
|
|
|
|
t.Fatalf("test %v: failed to execute transaction: %v", tc.name, err)
|
|
|
|
}
|
|
|
|
// Retrieve the trace result and compare against the expected
|
|
|
|
res, err := tc.tracer.GetResult()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("test %v: failed to retrieve trace result: %v", tc.name, err)
|
|
|
|
}
|
|
|
|
if string(res) != tc.want {
|
|
|
|
t.Errorf("test %v: trace mismatch\n have: %v\n want: %v\n", tc.name, string(res), tc.want)
|
|
|
|
}
|
|
|
|
})
|
2021-11-09 14:09:35 +03:00
|
|
|
}
|
|
|
|
}
|