github.com/codysnider/go-ethereum@v1.10.18-0.20220420071915-14f4ae99222a/cmd/evm/main.go (about)

     1  // Copyright 2014 The go-ethereum Authors
     2  // This file is part of go-ethereum.
     3  //
     4  // go-ethereum is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // go-ethereum is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    12  // GNU General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU General Public License
    15  // along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  // evm executes EVM code snippets.
    18  package main
    19  
    20  import (
    21  	"fmt"
    22  	"math/big"
    23  	"os"
    24  
    25  	"github.com/ethereum/go-ethereum/cmd/evm/internal/t8ntool"
    26  	"github.com/ethereum/go-ethereum/cmd/utils"
    27  	"github.com/ethereum/go-ethereum/internal/flags"
    28  	"gopkg.in/urfave/cli.v1"
    29  )
    30  
    31  var gitCommit = "" // Git SHA1 commit hash of the release (set via linker flags)
    32  var gitDate = ""
    33  
    34  var (
    35  	app = flags.NewApp(gitCommit, gitDate, "the evm command line interface")
    36  
    37  	DebugFlag = cli.BoolFlag{
    38  		Name:  "debug",
    39  		Usage: "output full trace logs",
    40  	}
    41  	MemProfileFlag = cli.StringFlag{
    42  		Name:  "memprofile",
    43  		Usage: "creates a memory profile at the given path",
    44  	}
    45  	CPUProfileFlag = cli.StringFlag{
    46  		Name:  "cpuprofile",
    47  		Usage: "creates a CPU profile at the given path",
    48  	}
    49  	StatDumpFlag = cli.BoolFlag{
    50  		Name:  "statdump",
    51  		Usage: "displays stack and heap memory information",
    52  	}
    53  	CodeFlag = cli.StringFlag{
    54  		Name:  "code",
    55  		Usage: "EVM code",
    56  	}
    57  	CodeFileFlag = cli.StringFlag{
    58  		Name:  "codefile",
    59  		Usage: "File containing EVM code. If '-' is specified, code is read from stdin ",
    60  	}
    61  	GasFlag = cli.Uint64Flag{
    62  		Name:  "gas",
    63  		Usage: "gas limit for the evm",
    64  		Value: 10000000000,
    65  	}
    66  	PriceFlag = utils.BigFlag{
    67  		Name:  "price",
    68  		Usage: "price set for the evm",
    69  		Value: new(big.Int),
    70  	}
    71  	ValueFlag = utils.BigFlag{
    72  		Name:  "value",
    73  		Usage: "value set for the evm",
    74  		Value: new(big.Int),
    75  	}
    76  	DumpFlag = cli.BoolFlag{
    77  		Name:  "dump",
    78  		Usage: "dumps the state after the run",
    79  	}
    80  	InputFlag = cli.StringFlag{
    81  		Name:  "input",
    82  		Usage: "input for the EVM",
    83  	}
    84  	InputFileFlag = cli.StringFlag{
    85  		Name:  "inputfile",
    86  		Usage: "file containing input for the EVM",
    87  	}
    88  	VerbosityFlag = cli.IntFlag{
    89  		Name:  "verbosity",
    90  		Usage: "sets the verbosity level",
    91  	}
    92  	BenchFlag = cli.BoolFlag{
    93  		Name:  "bench",
    94  		Usage: "benchmark the execution",
    95  	}
    96  	CreateFlag = cli.BoolFlag{
    97  		Name:  "create",
    98  		Usage: "indicates the action should be create rather than call",
    99  	}
   100  	GenesisFlag = cli.StringFlag{
   101  		Name:  "prestate",
   102  		Usage: "JSON file with prestate (genesis) config",
   103  	}
   104  	MachineFlag = cli.BoolFlag{
   105  		Name:  "json",
   106  		Usage: "output trace logs in machine readable format (json)",
   107  	}
   108  	SenderFlag = cli.StringFlag{
   109  		Name:  "sender",
   110  		Usage: "The transaction origin",
   111  	}
   112  	ReceiverFlag = cli.StringFlag{
   113  		Name:  "receiver",
   114  		Usage: "The transaction receiver (execution context)",
   115  	}
   116  	DisableMemoryFlag = cli.BoolTFlag{
   117  		Name:  "nomemory",
   118  		Usage: "disable memory output",
   119  	}
   120  	DisableStackFlag = cli.BoolFlag{
   121  		Name:  "nostack",
   122  		Usage: "disable stack output",
   123  	}
   124  	DisableStorageFlag = cli.BoolFlag{
   125  		Name:  "nostorage",
   126  		Usage: "disable storage output",
   127  	}
   128  	DisableReturnDataFlag = cli.BoolTFlag{
   129  		Name:  "noreturndata",
   130  		Usage: "enable return data output",
   131  	}
   132  )
   133  
   134  var stateTransitionCommand = cli.Command{
   135  	Name:    "transition",
   136  	Aliases: []string{"t8n"},
   137  	Usage:   "executes a full state transition",
   138  	Action:  t8ntool.Transition,
   139  	Flags: []cli.Flag{
   140  		t8ntool.TraceFlag,
   141  		t8ntool.TraceDisableMemoryFlag,
   142  		t8ntool.TraceEnableMemoryFlag,
   143  		t8ntool.TraceDisableStackFlag,
   144  		t8ntool.TraceDisableReturnDataFlag,
   145  		t8ntool.TraceEnableReturnDataFlag,
   146  		t8ntool.OutputBasedir,
   147  		t8ntool.OutputAllocFlag,
   148  		t8ntool.OutputResultFlag,
   149  		t8ntool.OutputBodyFlag,
   150  		t8ntool.InputAllocFlag,
   151  		t8ntool.InputEnvFlag,
   152  		t8ntool.InputTxsFlag,
   153  		t8ntool.ForknameFlag,
   154  		t8ntool.ChainIDFlag,
   155  		t8ntool.RewardFlag,
   156  		t8ntool.VerbosityFlag,
   157  	},
   158  }
   159  var transactionCommand = cli.Command{
   160  	Name:    "transaction",
   161  	Aliases: []string{"t9n"},
   162  	Usage:   "performs transaction validation",
   163  	Action:  t8ntool.Transaction,
   164  	Flags: []cli.Flag{
   165  		t8ntool.InputTxsFlag,
   166  		t8ntool.ChainIDFlag,
   167  		t8ntool.ForknameFlag,
   168  		t8ntool.VerbosityFlag,
   169  	},
   170  }
   171  
   172  var blockBuilderCommand = cli.Command{
   173  	Name:    "block-builder",
   174  	Aliases: []string{"b11r"},
   175  	Usage:   "builds a block",
   176  	Action:  t8ntool.BuildBlock,
   177  	Flags: []cli.Flag{
   178  		t8ntool.OutputBasedir,
   179  		t8ntool.OutputBlockFlag,
   180  		t8ntool.InputHeaderFlag,
   181  		t8ntool.InputOmmersFlag,
   182  		t8ntool.InputTxsRlpFlag,
   183  		t8ntool.SealCliqueFlag,
   184  		t8ntool.SealEthashFlag,
   185  		t8ntool.SealEthashDirFlag,
   186  		t8ntool.SealEthashModeFlag,
   187  		t8ntool.VerbosityFlag,
   188  	},
   189  }
   190  
   191  func init() {
   192  	app.Flags = []cli.Flag{
   193  		BenchFlag,
   194  		CreateFlag,
   195  		DebugFlag,
   196  		VerbosityFlag,
   197  		CodeFlag,
   198  		CodeFileFlag,
   199  		GasFlag,
   200  		PriceFlag,
   201  		ValueFlag,
   202  		DumpFlag,
   203  		InputFlag,
   204  		InputFileFlag,
   205  		MemProfileFlag,
   206  		CPUProfileFlag,
   207  		StatDumpFlag,
   208  		GenesisFlag,
   209  		MachineFlag,
   210  		SenderFlag,
   211  		ReceiverFlag,
   212  		DisableMemoryFlag,
   213  		DisableStackFlag,
   214  		DisableStorageFlag,
   215  		DisableReturnDataFlag,
   216  	}
   217  	app.Commands = []cli.Command{
   218  		compileCommand,
   219  		disasmCommand,
   220  		runCommand,
   221  		stateTestCommand,
   222  		stateTransitionCommand,
   223  		transactionCommand,
   224  		blockBuilderCommand,
   225  	}
   226  	cli.CommandHelpTemplate = flags.OriginCommandHelpTemplate
   227  }
   228  
   229  func main() {
   230  	if err := app.Run(os.Args); err != nil {
   231  		code := 1
   232  		if ec, ok := err.(*t8ntool.NumberedError); ok {
   233  			code = ec.ExitCode()
   234  		}
   235  		fmt.Fprintln(os.Stderr, err)
   236  		os.Exit(code)
   237  	}
   238  }