2015-07-06 19:54:22 -05:00
|
|
|
// 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
|
2015-07-22 11:48:40 -05:00
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2015-07-06 19:54:22 -05:00
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
2015-07-22 11:48:40 -05:00
|
|
|
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
2014-11-10 04:47:37 -06:00
|
|
|
|
2015-07-06 22:08:16 -05:00
|
|
|
// evm executes EVM code snippets.
|
2014-11-10 04:47:37 -06:00
|
|
|
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
2017-02-26 15:21:51 -06:00
|
|
|
"math/big"
|
2014-11-10 04:47:37 -06:00
|
|
|
"os"
|
|
|
|
|
2020-06-30 03:12:51 -05:00
|
|
|
"github.com/ethereum/go-ethereum/cmd/evm/internal/t8ntool"
|
2023-09-19 06:41:16 -05:00
|
|
|
"github.com/ethereum/go-ethereum/internal/debug"
|
2020-07-14 03:35:32 -05:00
|
|
|
"github.com/ethereum/go-ethereum/internal/flags"
|
2022-06-27 11:22:36 -05:00
|
|
|
"github.com/urfave/cli/v2"
|
2014-11-10 04:47:37 -06:00
|
|
|
)
|
|
|
|
|
2022-06-27 11:22:36 -05:00
|
|
|
var (
|
|
|
|
DebugFlag = &cli.BoolFlag{
|
2023-09-19 06:41:16 -05:00
|
|
|
Name: "debug",
|
|
|
|
Usage: "output full trace logs",
|
|
|
|
Category: flags.VMCategory,
|
2017-05-23 02:34:04 -05:00
|
|
|
}
|
2022-06-27 11:22:36 -05:00
|
|
|
StatDumpFlag = &cli.BoolFlag{
|
2023-09-19 06:41:16 -05:00
|
|
|
Name: "statdump",
|
|
|
|
Usage: "displays stack and heap memory information",
|
|
|
|
Category: flags.VMCategory,
|
2017-05-23 02:34:04 -05:00
|
|
|
}
|
2022-06-27 11:22:36 -05:00
|
|
|
CodeFlag = &cli.StringFlag{
|
2023-09-19 06:41:16 -05:00
|
|
|
Name: "code",
|
|
|
|
Usage: "EVM code",
|
|
|
|
Category: flags.VMCategory,
|
2015-07-17 08:43:16 -05:00
|
|
|
}
|
2022-06-27 11:22:36 -05:00
|
|
|
CodeFileFlag = &cli.StringFlag{
|
2023-09-19 06:41:16 -05:00
|
|
|
Name: "codefile",
|
|
|
|
Usage: "File containing EVM code. If '-' is specified, code is read from stdin ",
|
|
|
|
Category: flags.VMCategory,
|
2016-10-29 04:07:38 -05:00
|
|
|
}
|
2022-06-27 11:22:36 -05:00
|
|
|
GasFlag = &cli.Uint64Flag{
|
2023-09-19 06:41:16 -05:00
|
|
|
Name: "gas",
|
|
|
|
Usage: "gas limit for the evm",
|
|
|
|
Value: 10000000000,
|
|
|
|
Category: flags.VMCategory,
|
2015-07-17 08:43:16 -05:00
|
|
|
}
|
2022-06-27 11:22:36 -05:00
|
|
|
PriceFlag = &flags.BigFlag{
|
2023-09-19 06:41:16 -05:00
|
|
|
Name: "price",
|
|
|
|
Usage: "price set for the evm",
|
|
|
|
Value: new(big.Int),
|
|
|
|
Category: flags.VMCategory,
|
2015-07-17 08:43:16 -05:00
|
|
|
}
|
2022-06-27 11:22:36 -05:00
|
|
|
ValueFlag = &flags.BigFlag{
|
2023-09-19 06:41:16 -05:00
|
|
|
Name: "value",
|
|
|
|
Usage: "value set for the evm",
|
|
|
|
Value: new(big.Int),
|
|
|
|
Category: flags.VMCategory,
|
2015-07-17 08:43:16 -05:00
|
|
|
}
|
2022-06-27 11:22:36 -05:00
|
|
|
DumpFlag = &cli.BoolFlag{
|
2023-09-19 06:41:16 -05:00
|
|
|
Name: "dump",
|
|
|
|
Usage: "dumps the state after the run",
|
|
|
|
Category: flags.VMCategory,
|
2015-07-17 08:43:16 -05:00
|
|
|
}
|
2022-06-27 11:22:36 -05:00
|
|
|
InputFlag = &cli.StringFlag{
|
2023-09-19 06:41:16 -05:00
|
|
|
Name: "input",
|
|
|
|
Usage: "input for the EVM",
|
|
|
|
Category: flags.VMCategory,
|
2015-07-17 08:43:16 -05:00
|
|
|
}
|
2022-06-27 11:22:36 -05:00
|
|
|
InputFileFlag = &cli.StringFlag{
|
2023-09-19 06:41:16 -05:00
|
|
|
Name: "inputfile",
|
|
|
|
Usage: "file containing input for the EVM",
|
|
|
|
Category: flags.VMCategory,
|
2015-08-30 03:19:10 -05:00
|
|
|
}
|
2022-06-27 11:22:36 -05:00
|
|
|
BenchFlag = &cli.BoolFlag{
|
2023-09-19 06:41:16 -05:00
|
|
|
Name: "bench",
|
|
|
|
Usage: "benchmark the execution",
|
|
|
|
Category: flags.VMCategory,
|
2019-12-18 02:43:18 -06:00
|
|
|
}
|
2022-06-27 11:22:36 -05:00
|
|
|
CreateFlag = &cli.BoolFlag{
|
2023-09-19 06:41:16 -05:00
|
|
|
Name: "create",
|
|
|
|
Usage: "indicates the action should be create rather than call",
|
|
|
|
Category: flags.VMCategory,
|
2016-06-14 09:09:27 -05:00
|
|
|
}
|
2022-06-27 11:22:36 -05:00
|
|
|
GenesisFlag = &cli.StringFlag{
|
2023-09-19 06:41:16 -05:00
|
|
|
Name: "prestate",
|
|
|
|
Usage: "JSON file with prestate (genesis) config",
|
|
|
|
Category: flags.VMCategory,
|
2017-06-07 10:09:08 -05:00
|
|
|
}
|
2022-06-27 11:22:36 -05:00
|
|
|
MachineFlag = &cli.BoolFlag{
|
2023-09-19 06:41:16 -05:00
|
|
|
Name: "json",
|
|
|
|
Usage: "output trace logs in machine readable format (json)",
|
|
|
|
Category: flags.VMCategory,
|
2017-06-07 10:09:08 -05:00
|
|
|
}
|
2022-06-27 11:22:36 -05:00
|
|
|
SenderFlag = &cli.StringFlag{
|
2023-09-19 06:41:16 -05:00
|
|
|
Name: "sender",
|
|
|
|
Usage: "The transaction origin",
|
|
|
|
Category: flags.VMCategory,
|
2017-06-07 10:09:08 -05:00
|
|
|
}
|
2022-06-27 11:22:36 -05:00
|
|
|
ReceiverFlag = &cli.StringFlag{
|
2023-09-19 06:41:16 -05:00
|
|
|
Name: "receiver",
|
|
|
|
Usage: "The transaction receiver (execution context)",
|
|
|
|
Category: flags.VMCategory,
|
2017-08-15 04:31:36 -05:00
|
|
|
}
|
2022-06-27 11:22:36 -05:00
|
|
|
DisableMemoryFlag = &cli.BoolFlag{
|
2023-09-19 06:41:16 -05:00
|
|
|
Name: "nomemory",
|
|
|
|
Value: true,
|
|
|
|
Usage: "disable memory output",
|
|
|
|
Category: flags.VMCategory,
|
2017-06-21 07:52:31 -05:00
|
|
|
}
|
2022-06-27 11:22:36 -05:00
|
|
|
DisableStackFlag = &cli.BoolFlag{
|
2023-09-19 06:41:16 -05:00
|
|
|
Name: "nostack",
|
|
|
|
Usage: "disable stack output",
|
|
|
|
Category: flags.VMCategory,
|
2017-06-21 07:52:31 -05:00
|
|
|
}
|
2022-06-27 11:22:36 -05:00
|
|
|
DisableStorageFlag = &cli.BoolFlag{
|
2023-09-19 06:41:16 -05:00
|
|
|
Name: "nostorage",
|
|
|
|
Usage: "disable storage output",
|
|
|
|
Category: flags.VMCategory,
|
2020-07-16 07:06:19 -05:00
|
|
|
}
|
2022-06-27 11:22:36 -05:00
|
|
|
DisableReturnDataFlag = &cli.BoolFlag{
|
2023-09-19 06:41:16 -05:00
|
|
|
Name: "noreturndata",
|
|
|
|
Value: true,
|
|
|
|
Usage: "enable return data output",
|
|
|
|
Category: flags.VMCategory,
|
2020-07-16 07:06:19 -05:00
|
|
|
}
|
2014-11-10 04:47:37 -06:00
|
|
|
)
|
|
|
|
|
2022-06-27 11:22:36 -05:00
|
|
|
var stateTransitionCommand = &cli.Command{
|
2020-06-30 03:12:51 -05:00
|
|
|
Name: "transition",
|
|
|
|
Aliases: []string{"t8n"},
|
|
|
|
Usage: "executes a full state transition",
|
2021-09-13 06:57:40 -05:00
|
|
|
Action: t8ntool.Transition,
|
2020-06-30 03:12:51 -05:00
|
|
|
Flags: []cli.Flag{
|
|
|
|
t8ntool.TraceFlag,
|
|
|
|
t8ntool.TraceDisableMemoryFlag,
|
2021-11-24 03:15:23 -06:00
|
|
|
t8ntool.TraceEnableMemoryFlag,
|
2020-06-30 03:12:51 -05:00
|
|
|
t8ntool.TraceDisableStackFlag,
|
2020-07-16 07:06:19 -05:00
|
|
|
t8ntool.TraceDisableReturnDataFlag,
|
2021-11-24 03:15:23 -06:00
|
|
|
t8ntool.TraceEnableReturnDataFlag,
|
2020-08-19 04:31:13 -05:00
|
|
|
t8ntool.OutputBasedir,
|
2020-06-30 03:12:51 -05:00
|
|
|
t8ntool.OutputAllocFlag,
|
|
|
|
t8ntool.OutputResultFlag,
|
2021-02-25 08:26:57 -06:00
|
|
|
t8ntool.OutputBodyFlag,
|
2020-06-30 03:12:51 -05:00
|
|
|
t8ntool.InputAllocFlag,
|
|
|
|
t8ntool.InputEnvFlag,
|
|
|
|
t8ntool.InputTxsFlag,
|
|
|
|
t8ntool.ForknameFlag,
|
|
|
|
t8ntool.ChainIDFlag,
|
|
|
|
t8ntool.RewardFlag,
|
|
|
|
t8ntool.VerbosityFlag,
|
|
|
|
},
|
|
|
|
}
|
2022-06-27 11:22:36 -05:00
|
|
|
|
|
|
|
var transactionCommand = &cli.Command{
|
2021-09-13 06:57:40 -05:00
|
|
|
Name: "transaction",
|
|
|
|
Aliases: []string{"t9n"},
|
|
|
|
Usage: "performs transaction validation",
|
|
|
|
Action: t8ntool.Transaction,
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
t8ntool.InputTxsFlag,
|
|
|
|
t8ntool.ChainIDFlag,
|
|
|
|
t8ntool.ForknameFlag,
|
|
|
|
t8ntool.VerbosityFlag,
|
|
|
|
},
|
|
|
|
}
|
2020-06-30 03:12:51 -05:00
|
|
|
|
2022-06-27 11:22:36 -05:00
|
|
|
var blockBuilderCommand = &cli.Command{
|
2021-11-22 02:25:35 -06:00
|
|
|
Name: "block-builder",
|
|
|
|
Aliases: []string{"b11r"},
|
|
|
|
Usage: "builds a block",
|
|
|
|
Action: t8ntool.BuildBlock,
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
t8ntool.OutputBasedir,
|
|
|
|
t8ntool.OutputBlockFlag,
|
|
|
|
t8ntool.InputHeaderFlag,
|
|
|
|
t8ntool.InputOmmersFlag,
|
2023-01-25 08:32:25 -06:00
|
|
|
t8ntool.InputWithdrawalsFlag,
|
2021-11-22 02:25:35 -06:00
|
|
|
t8ntool.InputTxsRlpFlag,
|
|
|
|
t8ntool.SealCliqueFlag,
|
|
|
|
t8ntool.VerbosityFlag,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2023-09-19 06:41:16 -05:00
|
|
|
// 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,
|
|
|
|
}
|
|
|
|
|
2022-09-23 07:08:25 -05:00
|
|
|
var app = flags.NewApp("the evm command line interface")
|
|
|
|
|
2015-07-17 08:43:16 -05:00
|
|
|
func init() {
|
2023-09-19 06:41:16 -05:00
|
|
|
app.Flags = flags.Merge(vmFlags, traceFlags, debug.Flags)
|
2022-06-27 11:22:36 -05:00
|
|
|
app.Commands = []*cli.Command{
|
2017-02-28 18:11:24 -06:00
|
|
|
compileCommand,
|
2017-03-01 06:34:50 -06:00
|
|
|
disasmCommand,
|
2017-02-28 18:11:24 -06:00
|
|
|
runCommand,
|
2023-01-27 07:30:13 -06:00
|
|
|
blockTestCommand,
|
2017-09-05 04:24:26 -05:00
|
|
|
stateTestCommand,
|
2020-06-30 03:12:51 -05:00
|
|
|
stateTransitionCommand,
|
2021-09-13 06:57:40 -05:00
|
|
|
transactionCommand,
|
2021-11-22 02:25:35 -06:00
|
|
|
blockBuilderCommand,
|
2015-07-17 16:09:36 -05:00
|
|
|
}
|
2023-09-19 06:41:16 -05:00
|
|
|
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
|
|
|
|
}
|
2015-07-17 08:43:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
if err := app.Run(os.Args); err != nil {
|
2020-06-30 03:12:51 -05:00
|
|
|
code := 1
|
|
|
|
if ec, ok := err.(*t8ntool.NumberedError); ok {
|
2021-09-02 02:22:43 -05:00
|
|
|
code = ec.ExitCode()
|
2020-06-30 03:12:51 -05:00
|
|
|
}
|
2015-07-17 08:43:16 -05:00
|
|
|
fmt.Fprintln(os.Stderr, err)
|
2020-06-30 03:12:51 -05:00
|
|
|
os.Exit(code)
|
2015-07-17 08:43:16 -05:00
|
|
|
}
|
2014-11-10 04:47:37 -06:00
|
|
|
}
|