2018-02-14 12:49:11 +00:00
|
|
|
// Copyright 2015 The go-ethereum Authors
|
2015-07-22 16:48:40 +00:00
|
|
|
// This file is part of the go-ethereum library.
|
2015-07-07 00:54:22 +00:00
|
|
|
//
|
2015-07-23 16:35:11 +00:00
|
|
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
2015-07-07 00:54:22 +00: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 16:48:40 +00:00
|
|
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
2015-07-07 00:54:22 +00:00
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2015-07-22 16:48:40 +00:00
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2015-07-07 00:54:22 +00: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 16:48:40 +00:00
|
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
2015-07-07 00:54:22 +00:00
|
|
|
|
2015-06-10 18:38:39 +00:00
|
|
|
package tests
|
|
|
|
|
|
|
|
import (
|
2017-07-11 11:49:14 +00:00
|
|
|
"encoding/hex"
|
|
|
|
"encoding/json"
|
2015-06-10 18:38:39 +00:00
|
|
|
"fmt"
|
2017-07-11 11:49:14 +00:00
|
|
|
"math/big"
|
2019-08-08 09:07:23 +00:00
|
|
|
"strconv"
|
2016-10-05 21:55:47 +00:00
|
|
|
"strings"
|
2015-06-10 18:38:39 +00:00
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
2017-07-11 11:49:14 +00:00
|
|
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
common: move big integer math to common/math (#3699)
* common: remove CurrencyToString
Move denomination values to params instead.
* common: delete dead code
* common: move big integer operations to common/math
This commit consolidates all big integer operations into common/math and
adds tests and documentation.
There should be no change in semantics for BigPow, BigMin, BigMax, S256,
U256, Exp and their behaviour is now locked in by tests.
The BigD, BytesToBig and Bytes2Big functions don't provide additional
value, all uses are replaced by new(big.Int).SetBytes().
BigToBytes is now called PaddedBigBytes, its minimum output size
parameter is now specified as the number of bytes instead of bits. The
single use of this function is in the EVM's MSTORE instruction.
Big and String2Big are replaced by ParseBig, which is slightly stricter.
It previously accepted leading zeros for hexadecimal inputs but treated
decimal inputs as octal if a leading zero digit was present.
ParseUint64 is used in places where String2Big was used to decode a
uint64.
The new functions MustParseBig and MustParseUint64 are now used in many
places where parsing errors were previously ignored.
* common: delete unused big integer variables
* accounts/abi: replace uses of BytesToBig with use of encoding/binary
* common: remove BytesToBig
* common: remove Bytes2Big
* common: remove BigTrue
* cmd/utils: add BigFlag and use it for error-checked integer flags
While here, remove environment variable processing for DirectoryFlag
because we don't use it.
* core: add missing error checks in genesis block parser
* common: remove String2Big
* cmd/evm: use utils.BigFlag
* common/math: check for 256 bit overflow in ParseBig
This is supposed to prevent silent overflow/truncation of values in the
genesis block JSON. Without this check, a genesis block that set a
balance larger than 256 bits would lead to weird behaviour in the VM.
* cmd/utils: fixup import
2017-02-26 21:21:51 +00:00
|
|
|
"github.com/ethereum/go-ethereum/common/math"
|
2015-06-10 18:38:39 +00:00
|
|
|
"github.com/ethereum/go-ethereum/core"
|
2018-09-24 12:57:49 +00:00
|
|
|
"github.com/ethereum/go-ethereum/core/rawdb"
|
2015-06-10 18:38:39 +00:00
|
|
|
"github.com/ethereum/go-ethereum/core/state"
|
2021-02-25 07:10:30 +00:00
|
|
|
"github.com/ethereum/go-ethereum/core/state/snapshot"
|
2017-01-05 13:03:50 +00:00
|
|
|
"github.com/ethereum/go-ethereum/core/types"
|
2017-07-11 11:49:14 +00:00
|
|
|
"github.com/ethereum/go-ethereum/core/vm"
|
|
|
|
"github.com/ethereum/go-ethereum/crypto"
|
2015-06-10 18:38:39 +00:00
|
|
|
"github.com/ethereum/go-ethereum/ethdb"
|
2016-10-20 11:36:29 +00:00
|
|
|
"github.com/ethereum/go-ethereum/params"
|
2017-08-24 09:26:06 +00:00
|
|
|
"github.com/ethereum/go-ethereum/rlp"
|
2019-01-03 22:15:26 +00:00
|
|
|
"golang.org/x/crypto/sha3"
|
2015-06-10 18:38:39 +00:00
|
|
|
)
|
|
|
|
|
2017-07-11 11:49:14 +00:00
|
|
|
// StateTest checks transaction processing without block context.
|
|
|
|
// See https://github.com/ethereum/EIPs/issues/176 for the test format specification.
|
|
|
|
type StateTest struct {
|
|
|
|
json stJSON
|
|
|
|
}
|
2015-06-14 21:55:03 +00:00
|
|
|
|
2017-07-11 11:49:14 +00:00
|
|
|
// StateSubtest selects a specific configuration of a General State Test.
|
|
|
|
type StateSubtest struct {
|
|
|
|
Fork string
|
|
|
|
Index int
|
2015-06-14 21:55:03 +00:00
|
|
|
}
|
|
|
|
|
2017-07-11 11:49:14 +00:00
|
|
|
func (t *StateTest) UnmarshalJSON(in []byte) error {
|
|
|
|
return json.Unmarshal(in, &t.json)
|
|
|
|
}
|
2015-06-14 21:55:03 +00:00
|
|
|
|
2017-07-11 11:49:14 +00:00
|
|
|
type stJSON struct {
|
|
|
|
Env stEnv `json:"env"`
|
|
|
|
Pre core.GenesisAlloc `json:"pre"`
|
|
|
|
Tx stTransaction `json:"transaction"`
|
|
|
|
Out hexutil.Bytes `json:"out"`
|
|
|
|
Post map[string][]stPostState `json:"post"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type stPostState struct {
|
|
|
|
Root common.UnprefixedHash `json:"hash"`
|
2017-08-24 09:26:06 +00:00
|
|
|
Logs common.UnprefixedHash `json:"logs"`
|
2017-07-11 11:49:14 +00:00
|
|
|
Indexes struct {
|
|
|
|
Data int `json:"data"`
|
|
|
|
Gas int `json:"gas"`
|
|
|
|
Value int `json:"value"`
|
2015-06-14 21:55:03 +00:00
|
|
|
}
|
2017-07-11 11:49:14 +00:00
|
|
|
}
|
2015-06-14 21:55:03 +00:00
|
|
|
|
2017-07-11 11:49:14 +00:00
|
|
|
//go:generate gencodec -type stEnv -field-override stEnvMarshaling -out gen_stenv.go
|
2015-06-14 21:55:03 +00:00
|
|
|
|
2017-07-11 11:49:14 +00:00
|
|
|
type stEnv struct {
|
|
|
|
Coinbase common.Address `json:"currentCoinbase" gencodec:"required"`
|
|
|
|
Difficulty *big.Int `json:"currentDifficulty" gencodec:"required"`
|
2017-11-13 11:47:27 +00:00
|
|
|
GasLimit uint64 `json:"currentGasLimit" gencodec:"required"`
|
2017-07-11 11:49:14 +00:00
|
|
|
Number uint64 `json:"currentNumber" gencodec:"required"`
|
|
|
|
Timestamp uint64 `json:"currentTimestamp" gencodec:"required"`
|
2015-06-14 21:55:03 +00:00
|
|
|
}
|
|
|
|
|
2017-07-11 11:49:14 +00:00
|
|
|
type stEnvMarshaling struct {
|
|
|
|
Coinbase common.UnprefixedAddress
|
|
|
|
Difficulty *math.HexOrDecimal256
|
2017-11-13 11:47:27 +00:00
|
|
|
GasLimit math.HexOrDecimal64
|
2017-07-11 11:49:14 +00:00
|
|
|
Number math.HexOrDecimal64
|
|
|
|
Timestamp math.HexOrDecimal64
|
|
|
|
}
|
|
|
|
|
|
|
|
//go:generate gencodec -type stTransaction -field-override stTransactionMarshaling -out gen_sttransaction.go
|
|
|
|
|
|
|
|
type stTransaction struct {
|
|
|
|
GasPrice *big.Int `json:"gasPrice"`
|
|
|
|
Nonce uint64 `json:"nonce"`
|
|
|
|
To string `json:"to"`
|
|
|
|
Data []string `json:"data"`
|
|
|
|
GasLimit []uint64 `json:"gasLimit"`
|
|
|
|
Value []string `json:"value"`
|
|
|
|
PrivateKey []byte `json:"secretKey"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type stTransactionMarshaling struct {
|
|
|
|
GasPrice *math.HexOrDecimal256
|
|
|
|
Nonce math.HexOrDecimal64
|
|
|
|
GasLimit []math.HexOrDecimal64
|
|
|
|
PrivateKey hexutil.Bytes
|
|
|
|
}
|
|
|
|
|
2020-06-30 08:12:51 +00:00
|
|
|
// GetChainConfig takes a fork definition and returns a chain config.
|
2019-08-08 09:07:23 +00:00
|
|
|
// The fork definition can be
|
|
|
|
// - a plain forkname, e.g. `Byzantium`,
|
|
|
|
// - a fork basename, and a list of EIPs to enable; e.g. `Byzantium+1884+1283`.
|
2020-06-30 08:12:51 +00:00
|
|
|
func GetChainConfig(forkString string) (baseConfig *params.ChainConfig, eips []int, err error) {
|
2019-08-08 09:07:23 +00:00
|
|
|
var (
|
|
|
|
splitForks = strings.Split(forkString, "+")
|
|
|
|
ok bool
|
|
|
|
baseName, eipsStrings = splitForks[0], splitForks[1:]
|
|
|
|
)
|
|
|
|
if baseConfig, ok = Forks[baseName]; !ok {
|
|
|
|
return nil, nil, UnsupportedForkError{baseName}
|
|
|
|
}
|
|
|
|
for _, eip := range eipsStrings {
|
|
|
|
if eipNum, err := strconv.Atoi(eip); err != nil {
|
|
|
|
return nil, nil, fmt.Errorf("syntax error, invalid eip number %v", eipNum)
|
|
|
|
} else {
|
2020-06-30 08:12:51 +00:00
|
|
|
if !vm.ValidEip(eipNum) {
|
|
|
|
return nil, nil, fmt.Errorf("syntax error, invalid eip number %v", eipNum)
|
|
|
|
}
|
2019-08-08 09:07:23 +00:00
|
|
|
eips = append(eips, eipNum)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return baseConfig, eips, nil
|
|
|
|
}
|
|
|
|
|
2017-07-11 11:49:14 +00:00
|
|
|
// Subtests returns all valid subtests of the test.
|
|
|
|
func (t *StateTest) Subtests() []StateSubtest {
|
|
|
|
var sub []StateSubtest
|
|
|
|
for fork, pss := range t.json.Post {
|
2017-11-08 10:45:52 +00:00
|
|
|
for i := range pss {
|
2017-07-11 11:49:14 +00:00
|
|
|
sub = append(sub, StateSubtest{fork, i})
|
|
|
|
}
|
2015-07-17 21:09:36 +00:00
|
|
|
}
|
2017-07-11 11:49:14 +00:00
|
|
|
return sub
|
|
|
|
}
|
|
|
|
|
2019-09-11 11:46:14 +00:00
|
|
|
// Run executes a specific subtest and verifies the post-state and logs
|
2020-05-04 08:54:24 +00:00
|
|
|
func (t *StateTest) Run(subtest StateSubtest, vmconfig vm.Config, snapshotter bool) (*snapshot.Tree, *state.StateDB, error) {
|
|
|
|
snaps, statedb, root, err := t.RunNoVerify(subtest, vmconfig, snapshotter)
|
2019-09-11 11:46:14 +00:00
|
|
|
if err != nil {
|
2020-05-04 08:54:24 +00:00
|
|
|
return snaps, statedb, err
|
2019-09-11 11:46:14 +00:00
|
|
|
}
|
|
|
|
post := t.json.Post[subtest.Fork][subtest.Index]
|
|
|
|
// N.B: We need to do this in a two-step process, because the first Commit takes care
|
|
|
|
// of suicides, and we need to touch the coinbase _after_ it has potentially suicided.
|
|
|
|
if root != common.Hash(post.Root) {
|
2020-05-04 08:54:24 +00:00
|
|
|
return snaps, statedb, fmt.Errorf("post state root mismatch: got %x, want %x", root, post.Root)
|
2019-09-11 11:46:14 +00:00
|
|
|
}
|
|
|
|
if logs := rlpHash(statedb.Logs()); logs != common.Hash(post.Logs) {
|
2020-05-04 08:54:24 +00:00
|
|
|
return snaps, statedb, fmt.Errorf("post state logs hash mismatch: got %x, want %x", logs, post.Logs)
|
2019-09-11 11:46:14 +00:00
|
|
|
}
|
2020-05-04 08:54:24 +00:00
|
|
|
return snaps, statedb, nil
|
2019-09-11 11:46:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// RunNoVerify runs a specific subtest and returns the statedb and post-state root
|
2020-05-04 08:54:24 +00:00
|
|
|
func (t *StateTest) RunNoVerify(subtest StateSubtest, vmconfig vm.Config, snapshotter bool) (*snapshot.Tree, *state.StateDB, common.Hash, error) {
|
2020-06-30 08:12:51 +00:00
|
|
|
config, eips, err := GetChainConfig(subtest.Fork)
|
2019-08-08 09:07:23 +00:00
|
|
|
if err != nil {
|
2020-05-04 08:54:24 +00:00
|
|
|
return nil, nil, common.Hash{}, UnsupportedForkError{subtest.Fork}
|
2015-07-17 21:09:36 +00:00
|
|
|
}
|
2019-08-08 09:07:23 +00:00
|
|
|
vmconfig.ExtraEips = eips
|
2018-02-05 16:40:32 +00:00
|
|
|
block := t.genesis(config).ToBlock(nil)
|
2020-05-04 08:54:24 +00:00
|
|
|
snaps, statedb := MakePreState(rawdb.NewMemoryDatabase(), t.json.Pre, snapshotter)
|
2015-07-17 21:09:36 +00:00
|
|
|
|
2017-07-11 11:49:14 +00:00
|
|
|
post := t.json.Post[subtest.Fork][subtest.Index]
|
|
|
|
msg, err := t.json.Tx.toMessage(post)
|
|
|
|
if err != nil {
|
2020-05-04 08:54:24 +00:00
|
|
|
return nil, nil, common.Hash{}, err
|
2015-07-17 21:09:36 +00:00
|
|
|
}
|
2021-02-25 14:26:57 +00:00
|
|
|
|
|
|
|
// Prepare the EVM.
|
2020-11-13 12:42:19 +00:00
|
|
|
txContext := core.NewEVMTxContext(msg)
|
|
|
|
context := core.NewEVMBlockContext(block.Header(), nil, &t.json.Env.Coinbase)
|
2017-07-11 11:49:14 +00:00
|
|
|
context.GetHash = vmTestBlockHash
|
2020-11-13 12:42:19 +00:00
|
|
|
evm := vm.NewEVM(context, txContext, statedb, config, vmconfig)
|
2015-07-17 21:09:36 +00:00
|
|
|
|
2021-02-25 14:26:57 +00:00
|
|
|
// Execute the message.
|
|
|
|
snapshot := statedb.Snapshot()
|
2017-07-11 11:49:14 +00:00
|
|
|
gaspool := new(core.GasPool)
|
|
|
|
gaspool.AddGas(block.GasLimit())
|
2020-04-22 08:25:36 +00:00
|
|
|
if _, err := core.ApplyMessage(evm, msg, gaspool); err != nil {
|
2017-07-11 11:49:14 +00:00
|
|
|
statedb.RevertToSnapshot(snapshot)
|
|
|
|
}
|
2021-02-25 14:26:57 +00:00
|
|
|
|
2018-09-04 08:49:18 +00:00
|
|
|
// Commit block
|
|
|
|
statedb.Commit(config.IsEIP158(block.Number()))
|
|
|
|
// Add 0-value mining reward. This only makes a difference in the cases
|
|
|
|
// where
|
|
|
|
// - the coinbase suicided, or
|
|
|
|
// - there are only 'bad' transactions, which aren't executed. In those cases,
|
|
|
|
// the coinbase gets no txfee, so isn't created, and thus needs to be touched
|
|
|
|
statedb.AddBalance(block.Coinbase(), new(big.Int))
|
|
|
|
// And _now_ get the state root
|
|
|
|
root := statedb.IntermediateRoot(config.IsEIP158(block.Number()))
|
2020-05-04 08:54:24 +00:00
|
|
|
return snaps, statedb, root, nil
|
2015-07-17 21:09:36 +00:00
|
|
|
}
|
|
|
|
|
2017-07-11 11:49:14 +00:00
|
|
|
func (t *StateTest) gasLimit(subtest StateSubtest) uint64 {
|
|
|
|
return t.json.Tx.GasLimit[t.json.Post[subtest.Fork][subtest.Index].Indexes.Gas]
|
|
|
|
}
|
2015-07-17 21:09:36 +00:00
|
|
|
|
2020-05-04 08:54:24 +00:00
|
|
|
func MakePreState(db ethdb.Database, accounts core.GenesisAlloc, snapshotter bool) (*snapshot.Tree, *state.StateDB) {
|
2017-07-11 11:49:14 +00:00
|
|
|
sdb := state.NewDatabase(db)
|
2019-08-06 10:40:28 +00:00
|
|
|
statedb, _ := state.New(common.Hash{}, sdb, nil)
|
2017-07-11 11:49:14 +00:00
|
|
|
for addr, a := range accounts {
|
|
|
|
statedb.SetCode(addr, a.Code)
|
|
|
|
statedb.SetNonce(addr, a.Nonce)
|
|
|
|
statedb.SetBalance(addr, a.Balance)
|
|
|
|
for k, v := range a.Storage {
|
|
|
|
statedb.SetState(addr, k, v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Commit and re-open to start with a clean state.
|
2018-02-05 16:40:32 +00:00
|
|
|
root, _ := statedb.Commit(false)
|
2020-03-03 07:10:23 +00:00
|
|
|
|
|
|
|
var snaps *snapshot.Tree
|
|
|
|
if snapshotter {
|
all: bloom-filter based pruning mechanism (#21724)
* cmd, core, tests: initial state pruner
core: fix db inspector
cmd/geth: add verify-state
cmd/geth: add verification tool
core/rawdb: implement flatdb
cmd, core: fix rebase
core/state: use new contract code layout
core/state/pruner: avoid deleting genesis state
cmd/geth: add helper function
core, cmd: fix extract genesis
core: minor fixes
contracts: remove useless
core/state/snapshot: plugin stacktrie
core: polish
core/state/snapshot: iterate storage concurrently
core/state/snapshot: fix iteration
core: add comments
core/state/snapshot: polish code
core/state: polish
core/state/snapshot: rebase
core/rawdb: add comments
core/rawdb: fix tests
core/rawdb: improve tests
core/state/snapshot: fix concurrent iteration
core/state: run pruning during the recovery
core, trie: implement martin's idea
core, eth: delete flatdb and polish pruner
trie: fix import
core/state/pruner: add log
core/state/pruner: fix issues
core/state/pruner: don't read back
core/state/pruner: fix contract code write
core/state/pruner: check root node presence
cmd, core: polish log
core/state: use HEAD-127 as the target
core/state/snapshot: improve tests
cmd/geth: fix verification tool
cmd/geth: use HEAD as the verification default target
all: replace the bloomfilter with martin's fork
cmd, core: polish code
core, cmd: forcibly delete state root
core/state/pruner: add hash64
core/state/pruner: fix blacklist
core/state: remove blacklist
cmd, core: delete trie clean cache before pruning
cmd, core: fix lint
cmd, core: fix rebase
core/state: fix the special case for clique networks
core/state/snapshot: remove useless code
core/state/pruner: capping the snapshot after pruning
cmd, core, eth: fixes
core/rawdb: update db inspector
cmd/geth: polish code
core/state/pruner: fsync bloom filter
cmd, core: print warning log
core/state/pruner: adjust the parameters for bloom filter
cmd, core: create the bloom filter by size
core: polish
core/state/pruner: sanitize invalid bloomfilter size
cmd: address comments
cmd/geth: address comments
cmd/geth: address comment
core/state/pruner: address comments
core/state/pruner: rename homedir to datadir
cmd, core: address comments
core/state/pruner: address comment
core/state: address comments
core, cmd, tests: address comments
core: address comments
core/state/pruner: release the iterator after each commit
core/state/pruner: improve pruner
cmd, core: adjust bloom paramters
core/state/pruner: fix lint
core/state/pruner: fix tests
core: fix rebase
core/state/pruner: remove atomic rename
core/state/pruner: address comments
all: run go mod tidy
core/state/pruner: avoid false-positive for the middle state roots
core/state/pruner: add checks for middle roots
cmd/geth: replace crit with error
* core/state/pruner: fix lint
* core: drop legacy bloom filter
* core/state/snapshot: improve pruner
* core/state/snapshot: polish concurrent logs to report ETA vs. hashes
* core/state/pruner: add progress report for pruning and compaction too
* core: fix snapshot test API
* core/state: fix some pruning logs
* core/state/pruner: support recovering from bloom flush fail
Co-authored-by: Péter Szilágyi <peterke@gmail.com>
2021-02-08 11:16:30 +00:00
|
|
|
snaps, _ = snapshot.New(db, sdb.TrieDB(), 1, root, false, true, false)
|
2020-03-03 07:10:23 +00:00
|
|
|
}
|
|
|
|
statedb, _ = state.New(root, sdb, snaps)
|
2020-05-04 08:54:24 +00:00
|
|
|
return snaps, statedb
|
2015-07-17 21:09:36 +00:00
|
|
|
}
|
|
|
|
|
2017-07-11 11:49:14 +00:00
|
|
|
func (t *StateTest) genesis(config *params.ChainConfig) *core.Genesis {
|
|
|
|
return &core.Genesis{
|
|
|
|
Config: config,
|
|
|
|
Coinbase: t.json.Env.Coinbase,
|
|
|
|
Difficulty: t.json.Env.Difficulty,
|
2017-11-13 11:47:27 +00:00
|
|
|
GasLimit: t.json.Env.GasLimit,
|
2017-07-11 11:49:14 +00:00
|
|
|
Number: t.json.Env.Number,
|
|
|
|
Timestamp: t.json.Env.Timestamp,
|
|
|
|
Alloc: t.json.Pre,
|
2015-06-14 21:55:03 +00:00
|
|
|
}
|
2017-07-11 11:49:14 +00:00
|
|
|
}
|
2015-06-10 18:38:39 +00:00
|
|
|
|
2017-07-11 11:49:14 +00:00
|
|
|
func (tx *stTransaction) toMessage(ps stPostState) (core.Message, error) {
|
|
|
|
// Derive sender from private key if present.
|
|
|
|
var from common.Address
|
|
|
|
if len(tx.PrivateKey) > 0 {
|
|
|
|
key, err := crypto.ToECDSA(tx.PrivateKey)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("invalid private key: %v", err)
|
2015-06-10 21:04:06 +00:00
|
|
|
}
|
2017-07-11 11:49:14 +00:00
|
|
|
from = crypto.PubkeyToAddress(key.PublicKey)
|
|
|
|
}
|
|
|
|
// Parse recipient if present.
|
|
|
|
var to *common.Address
|
|
|
|
if tx.To != "" {
|
|
|
|
to = new(common.Address)
|
|
|
|
if err := to.UnmarshalText([]byte(tx.To)); err != nil {
|
|
|
|
return nil, fmt.Errorf("invalid to address: %v", err)
|
2015-06-10 18:38:39 +00:00
|
|
|
}
|
2017-07-11 11:49:14 +00:00
|
|
|
}
|
2015-06-10 18:38:39 +00:00
|
|
|
|
2017-07-11 11:49:14 +00:00
|
|
|
// Get values specific to this post state.
|
|
|
|
if ps.Indexes.Data > len(tx.Data) {
|
|
|
|
return nil, fmt.Errorf("tx data index %d out of bounds", ps.Indexes.Data)
|
|
|
|
}
|
|
|
|
if ps.Indexes.Value > len(tx.Value) {
|
|
|
|
return nil, fmt.Errorf("tx value index %d out of bounds", ps.Indexes.Value)
|
|
|
|
}
|
|
|
|
if ps.Indexes.Gas > len(tx.GasLimit) {
|
|
|
|
return nil, fmt.Errorf("tx gas limit index %d out of bounds", ps.Indexes.Gas)
|
|
|
|
}
|
|
|
|
dataHex := tx.Data[ps.Indexes.Data]
|
|
|
|
valueHex := tx.Value[ps.Indexes.Value]
|
|
|
|
gasLimit := tx.GasLimit[ps.Indexes.Gas]
|
|
|
|
// Value, Data hex encoding is messy: https://github.com/ethereum/tests/issues/203
|
|
|
|
value := new(big.Int)
|
|
|
|
if valueHex != "0x" {
|
|
|
|
v, ok := math.ParseBig256(valueHex)
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("invalid tx value %q", valueHex)
|
|
|
|
}
|
|
|
|
value = v
|
|
|
|
}
|
|
|
|
data, err := hex.DecodeString(strings.TrimPrefix(dataHex, "0x"))
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("invalid tx data %q", dataHex)
|
2015-06-14 21:55:03 +00:00
|
|
|
}
|
2015-06-10 18:38:39 +00:00
|
|
|
|
2021-02-25 14:26:57 +00:00
|
|
|
msg := types.NewMessage(from, to, tx.Nonce, value, gasLimit, tx.GasPrice, data, nil, true)
|
2017-07-11 11:49:14 +00:00
|
|
|
return msg, nil
|
2015-06-14 21:55:03 +00:00
|
|
|
}
|
2015-06-10 18:38:39 +00:00
|
|
|
|
2017-08-24 09:26:06 +00:00
|
|
|
func rlpHash(x interface{}) (h common.Hash) {
|
2019-01-03 22:15:26 +00:00
|
|
|
hw := sha3.NewLegacyKeccak256()
|
2017-08-24 09:26:06 +00:00
|
|
|
rlp.Encode(hw, x)
|
|
|
|
hw.Sum(h[:0])
|
|
|
|
return h
|
2015-06-10 18:38:39 +00:00
|
|
|
}
|