2018-02-14 15:49:11 +03:00
|
|
|
// Copyright 2015 The go-ethereum Authors
|
2015-07-22 19:48:40 +03:00
|
|
|
// This file is part of the go-ethereum library.
|
2015-07-07 03:54:22 +03:00
|
|
|
//
|
2015-07-23 19:35:11 +03:00
|
|
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
2015-07-07 03:54:22 +03:00
|
|
|
// 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.
|
|
|
|
//
|
2015-07-22 19:48:40 +03:00
|
|
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
2015-07-07 03:54:22 +03:00
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2015-07-22 19:48:40 +03:00
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2015-07-07 03:54:22 +03:00
|
|
|
// GNU Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
2015-07-22 19:48:40 +03:00
|
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
2015-07-07 03:54:22 +03:00
|
|
|
|
2015-06-10 19:04:56 +03:00
|
|
|
package tests
|
|
|
|
|
2015-06-10 19:34:38 +03:00
|
|
|
import (
|
2019-01-24 13:36:30 +03:00
|
|
|
"bufio"
|
2017-07-11 14:49:14 +03:00
|
|
|
"bytes"
|
|
|
|
"fmt"
|
2022-01-28 10:47:19 +03:00
|
|
|
"math/big"
|
2023-11-14 20:40:16 +03:00
|
|
|
"math/rand"
|
2022-01-28 10:47:19 +03:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2017-07-11 14:49:14 +03:00
|
|
|
"reflect"
|
2023-11-14 20:40:16 +03:00
|
|
|
"runtime"
|
2022-01-28 10:47:19 +03:00
|
|
|
"strings"
|
2015-06-10 19:34:38 +03:00
|
|
|
"testing"
|
2022-09-28 11:39:20 +03:00
|
|
|
"time"
|
2016-10-20 14:36:29 +03:00
|
|
|
|
2022-01-28 10:47:19 +03:00
|
|
|
"github.com/ethereum/go-ethereum/core"
|
|
|
|
"github.com/ethereum/go-ethereum/core/rawdb"
|
|
|
|
"github.com/ethereum/go-ethereum/core/types"
|
2017-07-11 14:49:14 +03:00
|
|
|
"github.com/ethereum/go-ethereum/core/vm"
|
2021-11-25 15:17:09 +03:00
|
|
|
"github.com/ethereum/go-ethereum/eth/tracers/logger"
|
2024-01-23 16:51:58 +03:00
|
|
|
"github.com/holiman/uint256"
|
2015-06-10 19:34:38 +03:00
|
|
|
)
|
|
|
|
|
2017-07-11 14:49:14 +03:00
|
|
|
func TestState(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
st := new(testMatcher)
|
|
|
|
// Long tests:
|
2018-09-28 23:23:47 +03:00
|
|
|
st.slow(`^stAttackTest/ContractCreationSpam`)
|
|
|
|
st.slow(`^stBadOpcode/badOpcodes`)
|
|
|
|
st.slow(`^stPreCompiledContracts/modexp`)
|
|
|
|
st.slow(`^stQuadraticComplexityTest/`)
|
|
|
|
st.slow(`^stStaticCall/static_Call50000`)
|
|
|
|
st.slow(`^stStaticCall/static_Return50000`)
|
|
|
|
st.slow(`^stSystemOperationsTest/CallRecursiveBomb`)
|
|
|
|
st.slow(`^stTransactionTest/Opcodes_TransactionInit`)
|
2019-10-02 11:33:51 +03:00
|
|
|
// Very time consuming
|
|
|
|
st.skipLoad(`^stTimeConsuming/`)
|
2021-08-25 16:07:58 +03:00
|
|
|
st.skipLoad(`.*vmPerformance/loop.*`)
|
2020-05-05 12:27:09 +03:00
|
|
|
// Uses 1GB RAM per tested fork
|
|
|
|
st.skipLoad(`^stStaticCall/static_Call1MB`)
|
2021-08-17 18:30:21 +03:00
|
|
|
|
2017-07-11 14:49:14 +03:00
|
|
|
// Broken tests:
|
2023-07-16 00:27:36 +03:00
|
|
|
// EOF is not part of cancun
|
|
|
|
st.skipLoad(`^stEOF/`)
|
|
|
|
|
2019-10-02 11:33:51 +03:00
|
|
|
// For Istanbul, older tests were moved into LegacyTests
|
2019-11-20 15:54:18 +03:00
|
|
|
for _, dir := range []string{
|
2023-07-16 00:27:36 +03:00
|
|
|
filepath.Join(baseDir, "EIPTests", "StateTests"),
|
2019-11-20 15:54:18 +03:00
|
|
|
stateTestDir,
|
2021-08-17 18:30:21 +03:00
|
|
|
legacyStateTestDir,
|
2022-01-28 10:47:19 +03:00
|
|
|
benchmarksDir,
|
2019-11-20 15:54:18 +03:00
|
|
|
} {
|
|
|
|
st.walk(t, dir, func(t *testing.T, name string, test *StateTest) {
|
2023-11-14 20:40:16 +03:00
|
|
|
if runtime.GOARCH == "386" && runtime.GOOS == "windows" && rand.Int63()%2 == 0 {
|
|
|
|
t.Skip("test (randomly) skipped on 32-bit windows")
|
|
|
|
return
|
|
|
|
}
|
2019-11-20 15:54:18 +03:00
|
|
|
for _, subtest := range test.Subtests() {
|
|
|
|
subtest := subtest
|
|
|
|
key := fmt.Sprintf("%s/%d", subtest.Fork, subtest.Index)
|
2020-03-03 10:10:23 +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
|
|
|
t.Run(key+"/hash/trie", func(t *testing.T) {
|
2020-03-03 10:10:23 +03:00
|
|
|
withTrace(t, test.gasLimit(subtest), func(vmconfig vm.Config) error {
|
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
|
|
|
var result error
|
2024-02-14 19:02:56 +03:00
|
|
|
test.Run(subtest, vmconfig, false, rawdb.HashScheme, func(err error, state *StateTestState) {
|
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
|
|
|
result = st.checkFailure(t, err)
|
|
|
|
})
|
|
|
|
return result
|
2020-03-03 10:10:23 +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
|
|
|
t.Run(key+"/hash/snap", func(t *testing.T) {
|
2019-11-20 15:54:18 +03:00
|
|
|
withTrace(t, test.gasLimit(subtest), func(vmconfig vm.Config) error {
|
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
|
|
|
var result error
|
2024-02-14 19:02:56 +03:00
|
|
|
test.Run(subtest, vmconfig, true, rawdb.HashScheme, func(err error, state *StateTestState) {
|
|
|
|
if state.Snapshots != nil && state.StateDB != nil {
|
|
|
|
if _, err := state.Snapshots.Journal(state.StateDB.IntermediateRoot(false)); err != nil {
|
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
|
|
|
result = err
|
|
|
|
return
|
|
|
|
}
|
2021-06-18 13:21:34 +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
|
|
|
result = st.checkFailure(t, err)
|
|
|
|
})
|
|
|
|
return result
|
|
|
|
})
|
|
|
|
})
|
|
|
|
t.Run(key+"/path/trie", func(t *testing.T) {
|
|
|
|
withTrace(t, test.gasLimit(subtest), func(vmconfig vm.Config) error {
|
|
|
|
var result error
|
2024-02-14 19:02:56 +03:00
|
|
|
test.Run(subtest, vmconfig, false, rawdb.PathScheme, func(err error, state *StateTestState) {
|
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
|
|
|
result = st.checkFailure(t, err)
|
|
|
|
})
|
|
|
|
return result
|
|
|
|
})
|
|
|
|
})
|
|
|
|
t.Run(key+"/path/snap", func(t *testing.T) {
|
|
|
|
withTrace(t, test.gasLimit(subtest), func(vmconfig vm.Config) error {
|
|
|
|
var result error
|
2024-02-14 19:02:56 +03:00
|
|
|
test.Run(subtest, vmconfig, true, rawdb.PathScheme, func(err error, state *StateTestState) {
|
|
|
|
if state.Snapshots != nil && state.StateDB != nil {
|
|
|
|
if _, err := state.Snapshots.Journal(state.StateDB.IntermediateRoot(false)); err != nil {
|
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
|
|
|
result = err
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result = st.checkFailure(t, err)
|
|
|
|
})
|
|
|
|
return result
|
2019-11-20 15:54:18 +03:00
|
|
|
})
|
2019-10-02 11:33:51 +03:00
|
|
|
})
|
2019-11-20 15:54:18 +03:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2016-10-31 13:32:05 +03:00
|
|
|
}
|
|
|
|
|
2017-07-11 14:49:14 +03:00
|
|
|
// Transactions with gasLimit above this value will not get a VM trace on failure.
|
2018-01-04 15:18:30 +03:00
|
|
|
const traceErrorLimit = 400000
|
2016-10-31 13:32:05 +03:00
|
|
|
|
2017-07-11 14:49:14 +03:00
|
|
|
func withTrace(t *testing.T, gasLimit uint64, test func(vm.Config) error) {
|
2019-09-11 15:41:22 +03:00
|
|
|
// Use config from command line arguments.
|
2021-07-06 23:03:09 +03:00
|
|
|
config := vm.Config{}
|
2019-09-11 15:41:22 +03:00
|
|
|
err := test(config)
|
2017-07-11 14:49:14 +03:00
|
|
|
if err == nil {
|
|
|
|
return
|
2016-10-31 13:32:05 +03:00
|
|
|
}
|
2019-09-11 15:41:22 +03:00
|
|
|
|
|
|
|
// Test failed, re-run with tracing enabled.
|
2017-07-11 14:49:14 +03:00
|
|
|
t.Error(err)
|
|
|
|
if gasLimit > traceErrorLimit {
|
|
|
|
t.Log("gas limit too high for EVM trace")
|
|
|
|
return
|
2016-10-31 13:32:05 +03:00
|
|
|
}
|
2019-01-24 13:36:30 +03:00
|
|
|
buf := new(bytes.Buffer)
|
|
|
|
w := bufio.NewWriter(buf)
|
2023-04-04 16:50:13 +03:00
|
|
|
config.Tracer = logger.NewJSONLogger(&logger.Config{}, w)
|
2019-09-11 15:41:22 +03:00
|
|
|
err2 := test(config)
|
2017-07-11 14:49:14 +03:00
|
|
|
if !reflect.DeepEqual(err, err2) {
|
|
|
|
t.Errorf("different error for second run: %v", err2)
|
2016-10-31 13:32:05 +03:00
|
|
|
}
|
2019-01-24 13:36:30 +03:00
|
|
|
w.Flush()
|
2017-07-11 14:49:14 +03:00
|
|
|
if buf.Len() == 0 {
|
|
|
|
t.Log("no EVM operation logs generated")
|
|
|
|
} else {
|
|
|
|
t.Log("EVM operation log:\n" + buf.String())
|
2016-10-31 13:32:05 +03:00
|
|
|
}
|
2021-05-25 23:47:14 +03:00
|
|
|
// t.Logf("EVM output: 0x%x", tracer.Output())
|
|
|
|
// t.Logf("EVM error: %v", tracer.Error())
|
2016-10-31 13:32:05 +03:00
|
|
|
}
|
2022-01-28 10:47:19 +03:00
|
|
|
|
|
|
|
func BenchmarkEVM(b *testing.B) {
|
|
|
|
// Walk the directory.
|
|
|
|
dir := benchmarksDir
|
|
|
|
dirinfo, err := os.Stat(dir)
|
|
|
|
if os.IsNotExist(err) || !dirinfo.IsDir() {
|
|
|
|
fmt.Fprintf(os.Stderr, "can't find test files in %s, did you clone the evm-benchmarks submodule?\n", dir)
|
|
|
|
b.Skip("missing test files")
|
|
|
|
}
|
|
|
|
err = filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
|
|
|
|
if info.IsDir() {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
if ext := filepath.Ext(path); ext == ".json" {
|
|
|
|
name := filepath.ToSlash(strings.TrimPrefix(strings.TrimSuffix(path, ext), dir+string(filepath.Separator)))
|
|
|
|
b.Run(name, func(b *testing.B) { runBenchmarkFile(b, path) })
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
b.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func runBenchmarkFile(b *testing.B, path string) {
|
|
|
|
m := make(map[string]StateTest)
|
|
|
|
if err := readJSONFile(path, &m); err != nil {
|
|
|
|
b.Fatal(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if len(m) != 1 {
|
|
|
|
b.Fatal("expected single benchmark in a file")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
for _, t := range m {
|
2022-06-13 17:24:45 +03:00
|
|
|
t := t
|
2022-01-28 10:47:19 +03:00
|
|
|
runBenchmark(b, &t)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func runBenchmark(b *testing.B, t *StateTest) {
|
|
|
|
for _, subtest := range t.Subtests() {
|
|
|
|
subtest := subtest
|
|
|
|
key := fmt.Sprintf("%s/%d", subtest.Fork, subtest.Index)
|
|
|
|
|
|
|
|
b.Run(key, func(b *testing.B) {
|
|
|
|
vmconfig := vm.Config{}
|
|
|
|
|
|
|
|
config, eips, err := GetChainConfig(subtest.Fork)
|
|
|
|
if err != nil {
|
|
|
|
b.Error(err)
|
|
|
|
return
|
|
|
|
}
|
2023-01-25 14:12:28 +03:00
|
|
|
var rules = config.Rules(new(big.Int), false, 0)
|
2022-09-28 11:39:20 +03:00
|
|
|
|
2022-01-28 10:47:19 +03:00
|
|
|
vmconfig.ExtraEips = eips
|
2022-08-09 12:44:39 +03:00
|
|
|
block := t.genesis(config).ToBlock()
|
2024-02-14 19:02:56 +03:00
|
|
|
state := MakePreState(rawdb.NewMemoryDatabase(), t.json.Pre, false, rawdb.HashScheme)
|
|
|
|
defer state.Close()
|
2022-01-28 10:47:19 +03:00
|
|
|
|
|
|
|
var baseFee *big.Int
|
2022-09-28 11:39:20 +03:00
|
|
|
if rules.IsLondon {
|
2022-01-28 10:47:19 +03:00
|
|
|
baseFee = t.json.Env.BaseFee
|
|
|
|
if baseFee == nil {
|
|
|
|
// Retesteth uses `0x10` for genesis baseFee. Therefore, it defaults to
|
|
|
|
// parent - 2 : 0xa as the basefee for 'this' context.
|
|
|
|
baseFee = big.NewInt(0x0a)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
post := t.json.Post[subtest.Fork][subtest.Index]
|
|
|
|
msg, err := t.json.Tx.toMessage(post, baseFee)
|
|
|
|
if err != nil {
|
|
|
|
b.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try to recover tx with current signer
|
|
|
|
if len(post.TxBytes) != 0 {
|
|
|
|
var ttx types.Transaction
|
|
|
|
err := ttx.UnmarshalBinary(post.TxBytes)
|
|
|
|
if err != nil {
|
|
|
|
b.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, err := types.Sender(types.LatestSigner(config), &ttx); err != nil {
|
|
|
|
b.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prepare the EVM.
|
|
|
|
txContext := core.NewEVMTxContext(msg)
|
|
|
|
context := core.NewEVMBlockContext(block.Header(), nil, &t.json.Env.Coinbase)
|
|
|
|
context.GetHash = vmTestBlockHash
|
|
|
|
context.BaseFee = baseFee
|
2024-02-14 19:02:56 +03:00
|
|
|
evm := vm.NewEVM(context, txContext, state.StateDB, config, vmconfig)
|
2022-01-28 10:47:19 +03:00
|
|
|
|
|
|
|
// Create "contract" for sender to cache code analysis.
|
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
|
|
|
sender := vm.NewContract(vm.AccountRef(msg.From), vm.AccountRef(msg.From),
|
2022-01-28 10:47:19 +03:00
|
|
|
nil, 0)
|
|
|
|
|
2022-09-28 11:39:20 +03:00
|
|
|
var (
|
|
|
|
gasUsed uint64
|
|
|
|
elapsed uint64
|
|
|
|
refund uint64
|
|
|
|
)
|
2022-01-28 10:47:19 +03:00
|
|
|
b.ResetTimer()
|
|
|
|
for n := 0; n < b.N; n++ {
|
2024-02-14 19:02:56 +03:00
|
|
|
snapshot := state.StateDB.Snapshot()
|
|
|
|
state.StateDB.Prepare(rules, msg.From, context.Coinbase, msg.To, vm.ActivePrecompiles(rules), msg.AccessList)
|
2022-09-28 11:39:20 +03:00
|
|
|
b.StartTimer()
|
|
|
|
start := time.Now()
|
|
|
|
|
|
|
|
// Execute the message.
|
2024-01-23 16:51:58 +03:00
|
|
|
_, leftOverGas, err := evm.Call(sender, *msg.To, msg.Data, msg.GasLimit, uint256.MustFromBig(msg.Value))
|
2022-01-28 10:47:19 +03:00
|
|
|
if err != nil {
|
|
|
|
b.Error(err)
|
|
|
|
return
|
|
|
|
}
|
2022-09-28 11:39:20 +03:00
|
|
|
|
|
|
|
b.StopTimer()
|
|
|
|
elapsed += uint64(time.Since(start))
|
2024-02-14 19:02:56 +03:00
|
|
|
refund += state.StateDB.GetRefund()
|
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
|
|
|
gasUsed += msg.GasLimit - leftOverGas
|
2022-09-28 11:39:20 +03:00
|
|
|
|
2024-02-14 19:02:56 +03:00
|
|
|
state.StateDB.RevertToSnapshot(snapshot)
|
2022-01-28 10:47:19 +03:00
|
|
|
}
|
2022-09-28 11:39:20 +03:00
|
|
|
if elapsed < 1 {
|
|
|
|
elapsed = 1
|
|
|
|
}
|
|
|
|
// Keep it as uint64, multiply 100 to get two digit float later
|
|
|
|
mgasps := (100 * 1000 * (gasUsed - refund)) / elapsed
|
|
|
|
b.ReportMetric(float64(mgasps)/100, "mgas/s")
|
2022-01-28 10:47:19 +03:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|