|
|
|
// Copyright 2014 The go-ethereum Authors
|
|
|
|
// This file is part of go-ethereum.
|
|
|
|
//
|
|
|
|
// go-ethereum is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// go-ethereum 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 General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
// evm executes EVM code snippets.
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
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
8 years ago
|
|
|
"math/big"
|
|
|
|
"os"
|
|
|
|
"slices"
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/cmd/evm/internal/t8ntool"
|
|
|
|
"github.com/ethereum/go-ethereum/internal/debug"
|
|
|
|
"github.com/ethereum/go-ethereum/internal/flags"
|
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
|
|
|
|
// Force-load the tracer engines to trigger registration
|
|
|
|
_ "github.com/ethereum/go-ethereum/eth/tracers/js"
|
|
|
|
_ "github.com/ethereum/go-ethereum/eth/tracers/native"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
DebugFlag = &cli.BoolFlag{
|
|
|
|
Name: "debug",
|
|
|
|
Usage: "output full trace logs",
|
|
|
|
Category: flags.VMCategory,
|
|
|
|
}
|
|
|
|
StatDumpFlag = &cli.BoolFlag{
|
|
|
|
Name: "statdump",
|
|
|
|
Usage: "displays stack and heap memory information",
|
|
|
|
Category: flags.VMCategory,
|
|
|
|
}
|
|
|
|
CodeFlag = &cli.StringFlag{
|
|
|
|
Name: "code",
|
|
|
|
Usage: "EVM code",
|
|
|
|
Category: flags.VMCategory,
|
|
|
|
}
|
|
|
|
CodeFileFlag = &cli.StringFlag{
|
|
|
|
Name: "codefile",
|
|
|
|
Usage: "File containing EVM code. If '-' is specified, code is read from stdin ",
|
|
|
|
Category: flags.VMCategory,
|
|
|
|
}
|
|
|
|
GasFlag = &cli.Uint64Flag{
|
|
|
|
Name: "gas",
|
|
|
|
Usage: "gas limit for the evm",
|
|
|
|
Value: 10000000000,
|
|
|
|
Category: flags.VMCategory,
|
|
|
|
}
|
|
|
|
PriceFlag = &flags.BigFlag{
|
|
|
|
Name: "price",
|
|
|
|
Usage: "price set for the evm",
|
|
|
|
Value: new(big.Int),
|
|
|
|
Category: flags.VMCategory,
|
|
|
|
}
|
|
|
|
ValueFlag = &flags.BigFlag{
|
|
|
|
Name: "value",
|
|
|
|
Usage: "value set for the evm",
|
|
|
|
Value: new(big.Int),
|
|
|
|
Category: flags.VMCategory,
|
|
|
|
}
|
|
|
|
DumpFlag = &cli.BoolFlag{
|
|
|
|
Name: "dump",
|
|
|
|
Usage: "dumps the state after the run",
|
|
|
|
Category: flags.VMCategory,
|
|
|
|
}
|
|
|
|
InputFlag = &cli.StringFlag{
|
|
|
|
Name: "input",
|
|
|
|
Usage: "input for the EVM",
|
|
|
|
Category: flags.VMCategory,
|
|
|
|
}
|
|
|
|
InputFileFlag = &cli.StringFlag{
|
|
|
|
Name: "inputfile",
|
|
|
|
Usage: "file containing input for the EVM",
|
|
|
|
Category: flags.VMCategory,
|
|
|
|
}
|
|
|
|
BenchFlag = &cli.BoolFlag{
|
|
|
|
Name: "bench",
|
|
|
|
Usage: "benchmark the execution",
|
|
|
|
Category: flags.VMCategory,
|
|
|
|
}
|
|
|
|
CreateFlag = &cli.BoolFlag{
|
|
|
|
Name: "create",
|
|
|
|
Usage: "indicates the action should be create rather than call",
|
|
|
|
Category: flags.VMCategory,
|
|
|
|
}
|
|
|
|
GenesisFlag = &cli.StringFlag{
|
|
|
|
Name: "prestate",
|
|
|
|
Usage: "JSON file with prestate (genesis) config",
|
|
|
|
Category: flags.VMCategory,
|
|
|
|
}
|
|
|
|
MachineFlag = &cli.BoolFlag{
|
|
|
|
Name: "json",
|
|
|
|
Usage: "output trace logs in machine readable format (json)",
|
|
|
|
Category: flags.VMCategory,
|
|
|
|
}
|
|
|
|
SenderFlag = &cli.StringFlag{
|
|
|
|
Name: "sender",
|
|
|
|
Usage: "The transaction origin",
|
|
|
|
Category: flags.VMCategory,
|
|
|
|
}
|
|
|
|
ReceiverFlag = &cli.StringFlag{
|
|
|
|
Name: "receiver",
|
|
|
|
Usage: "The transaction receiver (execution context)",
|
|
|
|
Category: flags.VMCategory,
|
|
|
|
}
|
|
|
|
DisableMemoryFlag = &cli.BoolFlag{
|
|
|
|
Name: "nomemory",
|
|
|
|
Value: true,
|
|
|
|
Usage: "disable memory output",
|
|
|
|
Category: flags.VMCategory,
|
|
|
|
}
|
|
|
|
DisableStackFlag = &cli.BoolFlag{
|
|
|
|
Name: "nostack",
|
|
|
|
Usage: "disable stack output",
|
|
|
|
Category: flags.VMCategory,
|
|
|
|
}
|
|
|
|
DisableStorageFlag = &cli.BoolFlag{
|
|
|
|
Name: "nostorage",
|
|
|
|
Usage: "disable storage output",
|
|
|
|
Category: flags.VMCategory,
|
|
|
|
}
|
|
|
|
DisableReturnDataFlag = &cli.BoolFlag{
|
|
|
|
Name: "noreturndata",
|
|
|
|
Value: true,
|
|
|
|
Usage: "enable return data output",
|
|
|
|
Category: flags.VMCategory,
|
|
|
|
}
|
core/vm, cmd/evm: implement eof validation (#30418)
The bulk of this PR is authored by @lightclient , in the original
EOF-work. More recently, the code has been picked up and reworked for the new EOF
specification, by @MariusVanDerWijden , in https://github.com/ethereum/go-ethereum/pull/29518, and also @shemnon has contributed with fixes.
This PR is an attempt to start eating the elephant one small bite at a
time, by selecting only the eof-validation as a standalone piece which
can be merged without interfering too much in the core stuff.
In this PR:
- [x] Validation of eof containers, lifted from #29518, along with
test-vectors from consensus-tests and fuzzing, to ensure that the move
did not lose any functionality.
- [x] Definition of eof opcodes, which is a prerequisite for validation
- [x] Addition of `undefined` to a jumptable entry item. I'm not
super-happy with this, but for the moment it seems the least invasive
way to do it. A better way might be to go back and allowing nil-items or
nil execute-functions to denote "undefined".
- [x] benchmarks of eof validation speed
---------
Co-authored-by: lightclient <lightclient@protonmail.com>
Co-authored-by: Marius van der Wijden <m.vanderwijden@live.de>
Co-authored-by: Danno Ferrin <danno.ferrin@shemnon.com>
2 months ago
|
|
|
refTestFlag = &cli.StringFlag{
|
|
|
|
Name: "test",
|
|
|
|
Usage: "Path to EOF validation reference test.",
|
|
|
|
}
|
|
|
|
hexFlag = &cli.StringFlag{
|
|
|
|
Name: "hex",
|
|
|
|
Usage: "single container data parse and validation",
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
core/vm, cmd/evm: implement eof validation (#30418)
The bulk of this PR is authored by @lightclient , in the original
EOF-work. More recently, the code has been picked up and reworked for the new EOF
specification, by @MariusVanDerWijden , in https://github.com/ethereum/go-ethereum/pull/29518, and also @shemnon has contributed with fixes.
This PR is an attempt to start eating the elephant one small bite at a
time, by selecting only the eof-validation as a standalone piece which
can be merged without interfering too much in the core stuff.
In this PR:
- [x] Validation of eof containers, lifted from #29518, along with
test-vectors from consensus-tests and fuzzing, to ensure that the move
did not lose any functionality.
- [x] Definition of eof opcodes, which is a prerequisite for validation
- [x] Addition of `undefined` to a jumptable entry item. I'm not
super-happy with this, but for the moment it seems the least invasive
way to do it. A better way might be to go back and allowing nil-items or
nil execute-functions to denote "undefined".
- [x] benchmarks of eof validation speed
---------
Co-authored-by: lightclient <lightclient@protonmail.com>
Co-authored-by: Marius van der Wijden <m.vanderwijden@live.de>
Co-authored-by: Danno Ferrin <danno.ferrin@shemnon.com>
2 months ago
|
|
|
var (
|
|
|
|
stateTransitionCommand = &cli.Command{
|
|
|
|
Name: "transition",
|
|
|
|
Aliases: []string{"t8n"},
|
|
|
|
Usage: "Executes a full state transition",
|
|
|
|
Action: t8ntool.Transition,
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
t8ntool.TraceFlag,
|
|
|
|
t8ntool.TraceTracerFlag,
|
|
|
|
t8ntool.TraceTracerConfigFlag,
|
|
|
|
t8ntool.TraceEnableMemoryFlag,
|
|
|
|
t8ntool.TraceDisableStackFlag,
|
|
|
|
t8ntool.TraceEnableReturnDataFlag,
|
|
|
|
t8ntool.TraceEnableCallFramesFlag,
|
|
|
|
t8ntool.OutputBasedir,
|
|
|
|
t8ntool.OutputAllocFlag,
|
|
|
|
t8ntool.OutputResultFlag,
|
|
|
|
t8ntool.OutputBodyFlag,
|
|
|
|
t8ntool.InputAllocFlag,
|
|
|
|
t8ntool.InputEnvFlag,
|
|
|
|
t8ntool.InputTxsFlag,
|
|
|
|
t8ntool.ForknameFlag,
|
|
|
|
t8ntool.ChainIDFlag,
|
|
|
|
t8ntool.RewardFlag,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
core/vm, cmd/evm: implement eof validation (#30418)
The bulk of this PR is authored by @lightclient , in the original
EOF-work. More recently, the code has been picked up and reworked for the new EOF
specification, by @MariusVanDerWijden , in https://github.com/ethereum/go-ethereum/pull/29518, and also @shemnon has contributed with fixes.
This PR is an attempt to start eating the elephant one small bite at a
time, by selecting only the eof-validation as a standalone piece which
can be merged without interfering too much in the core stuff.
In this PR:
- [x] Validation of eof containers, lifted from #29518, along with
test-vectors from consensus-tests and fuzzing, to ensure that the move
did not lose any functionality.
- [x] Definition of eof opcodes, which is a prerequisite for validation
- [x] Addition of `undefined` to a jumptable entry item. I'm not
super-happy with this, but for the moment it seems the least invasive
way to do it. A better way might be to go back and allowing nil-items or
nil execute-functions to denote "undefined".
- [x] benchmarks of eof validation speed
---------
Co-authored-by: lightclient <lightclient@protonmail.com>
Co-authored-by: Marius van der Wijden <m.vanderwijden@live.de>
Co-authored-by: Danno Ferrin <danno.ferrin@shemnon.com>
2 months ago
|
|
|
transactionCommand = &cli.Command{
|
|
|
|
Name: "transaction",
|
|
|
|
Aliases: []string{"t9n"},
|
|
|
|
Usage: "Performs transaction validation",
|
|
|
|
Action: t8ntool.Transaction,
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
t8ntool.InputTxsFlag,
|
|
|
|
t8ntool.ChainIDFlag,
|
|
|
|
t8ntool.ForknameFlag,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
core/vm, cmd/evm: implement eof validation (#30418)
The bulk of this PR is authored by @lightclient , in the original
EOF-work. More recently, the code has been picked up and reworked for the new EOF
specification, by @MariusVanDerWijden , in https://github.com/ethereum/go-ethereum/pull/29518, and also @shemnon has contributed with fixes.
This PR is an attempt to start eating the elephant one small bite at a
time, by selecting only the eof-validation as a standalone piece which
can be merged without interfering too much in the core stuff.
In this PR:
- [x] Validation of eof containers, lifted from #29518, along with
test-vectors from consensus-tests and fuzzing, to ensure that the move
did not lose any functionality.
- [x] Definition of eof opcodes, which is a prerequisite for validation
- [x] Addition of `undefined` to a jumptable entry item. I'm not
super-happy with this, but for the moment it seems the least invasive
way to do it. A better way might be to go back and allowing nil-items or
nil execute-functions to denote "undefined".
- [x] benchmarks of eof validation speed
---------
Co-authored-by: lightclient <lightclient@protonmail.com>
Co-authored-by: Marius van der Wijden <m.vanderwijden@live.de>
Co-authored-by: Danno Ferrin <danno.ferrin@shemnon.com>
2 months ago
|
|
|
blockBuilderCommand = &cli.Command{
|
|
|
|
Name: "block-builder",
|
|
|
|
Aliases: []string{"b11r"},
|
|
|
|
Usage: "Builds a block",
|
|
|
|
Action: t8ntool.BuildBlock,
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
t8ntool.OutputBasedir,
|
|
|
|
t8ntool.OutputBlockFlag,
|
|
|
|
t8ntool.InputHeaderFlag,
|
|
|
|
t8ntool.InputOmmersFlag,
|
|
|
|
t8ntool.InputWithdrawalsFlag,
|
|
|
|
t8ntool.InputTxsRlpFlag,
|
|
|
|
t8ntool.SealCliqueFlag,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
eofParseCommand = &cli.Command{
|
|
|
|
Name: "eofparse",
|
|
|
|
Aliases: []string{"eof"},
|
|
|
|
Usage: "Parses hex eof container and returns validation errors (if any)",
|
|
|
|
Action: eofParseAction,
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
hexFlag,
|
|
|
|
refTestFlag,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
eofDumpCommand = &cli.Command{
|
|
|
|
Name: "eofdump",
|
|
|
|
Usage: "Parses hex eof container and prints out human-readable representation of the container.",
|
|
|
|
Action: eofDumpAction,
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
hexFlag,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
// vmFlags contains flags related to running the EVM.
|
|
|
|
var vmFlags = []cli.Flag{
|
|
|
|
CodeFlag,
|
|
|
|
CodeFileFlag,
|
|
|
|
CreateFlag,
|
|
|
|
GasFlag,
|
|
|
|
PriceFlag,
|
|
|
|
ValueFlag,
|
|
|
|
InputFlag,
|
|
|
|
InputFileFlag,
|
|
|
|
GenesisFlag,
|
|
|
|
SenderFlag,
|
|
|
|
ReceiverFlag,
|
|
|
|
}
|
|
|
|
|
|
|
|
// traceFlags contains flags that configure tracing output.
|
|
|
|
var traceFlags = []cli.Flag{
|
|
|
|
BenchFlag,
|
|
|
|
DebugFlag,
|
|
|
|
DumpFlag,
|
|
|
|
MachineFlag,
|
|
|
|
StatDumpFlag,
|
|
|
|
DisableMemoryFlag,
|
|
|
|
DisableStackFlag,
|
|
|
|
DisableStorageFlag,
|
|
|
|
DisableReturnDataFlag,
|
|
|
|
}
|
|
|
|
|
|
|
|
var app = flags.NewApp("the evm command line interface")
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
app.Flags = slices.Concat(vmFlags, traceFlags, debug.Flags)
|
|
|
|
app.Commands = []*cli.Command{
|
|
|
|
compileCommand,
|
|
|
|
disasmCommand,
|
|
|
|
runCommand,
|
|
|
|
blockTestCommand,
|
|
|
|
stateTestCommand,
|
|
|
|
stateTransitionCommand,
|
|
|
|
transactionCommand,
|
|
|
|
blockBuilderCommand,
|
core/vm, cmd/evm: implement eof validation (#30418)
The bulk of this PR is authored by @lightclient , in the original
EOF-work. More recently, the code has been picked up and reworked for the new EOF
specification, by @MariusVanDerWijden , in https://github.com/ethereum/go-ethereum/pull/29518, and also @shemnon has contributed with fixes.
This PR is an attempt to start eating the elephant one small bite at a
time, by selecting only the eof-validation as a standalone piece which
can be merged without interfering too much in the core stuff.
In this PR:
- [x] Validation of eof containers, lifted from #29518, along with
test-vectors from consensus-tests and fuzzing, to ensure that the move
did not lose any functionality.
- [x] Definition of eof opcodes, which is a prerequisite for validation
- [x] Addition of `undefined` to a jumptable entry item. I'm not
super-happy with this, but for the moment it seems the least invasive
way to do it. A better way might be to go back and allowing nil-items or
nil execute-functions to denote "undefined".
- [x] benchmarks of eof validation speed
---------
Co-authored-by: lightclient <lightclient@protonmail.com>
Co-authored-by: Marius van der Wijden <m.vanderwijden@live.de>
Co-authored-by: Danno Ferrin <danno.ferrin@shemnon.com>
2 months ago
|
|
|
eofParseCommand,
|
|
|
|
eofDumpCommand,
|
|
|
|
}
|
|
|
|
app.Before = func(ctx *cli.Context) error {
|
|
|
|
flags.MigrateGlobalFlags(ctx)
|
|
|
|
return debug.Setup(ctx)
|
|
|
|
}
|
|
|
|
app.After = func(ctx *cli.Context) error {
|
|
|
|
debug.Exit()
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
if err := app.Run(os.Args); err != nil {
|
|
|
|
code := 1
|
|
|
|
if ec, ok := err.(*t8ntool.NumberedError); ok {
|
|
|
|
code = ec.ExitCode()
|
|
|
|
}
|
|
|
|
fmt.Fprintln(os.Stderr, err)
|
|
|
|
os.Exit(code)
|
|
|
|
}
|
|
|
|
}
|