github.com/Cleverse/go-ethereum@v0.0.0-20220927095127-45113064e7f2/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/internal/flags"
    27  	"github.com/urfave/cli/v2"
    28  )
    29  
    30  var (
    31  	gitCommit = "" // Git SHA1 commit hash of the release (set via linker flags)
    32  	gitDate   = ""
    33  
    34  	app = flags.NewApp(gitCommit, gitDate, "the evm command line interface")
    35  )
    36  
    37  var (
    38  	DebugFlag = &cli.BoolFlag{
    39  		Name:  "debug",
    40  		Usage: "output full trace logs",
    41  	}
    42  	MemProfileFlag = &cli.StringFlag{
    43  		Name:  "memprofile",
    44  		Usage: "creates a memory profile at the given path",
    45  	}
    46  	CPUProfileFlag = &cli.StringFlag{
    47  		Name:  "cpuprofile",
    48  		Usage: "creates a CPU profile at the given path",
    49  	}
    50  	StatDumpFlag = &cli.BoolFlag{
    51  		Name:  "statdump",
    52  		Usage: "displays stack and heap memory information",
    53  	}
    54  	CodeFlag = &cli.StringFlag{
    55  		Name:  "code",
    56  		Usage: "EVM code",
    57  	}
    58  	CodeFileFlag = &cli.StringFlag{
    59  		Name:  "codefile",
    60  		Usage: "File containing EVM code. If '-' is specified, code is read from stdin ",
    61  	}
    62  	GasFlag = &cli.Uint64Flag{
    63  		Name:  "gas",
    64  		Usage: "gas limit for the evm",
    65  		Value: 10000000000,
    66  	}
    67  	PriceFlag = &flags.BigFlag{
    68  		Name:  "price",
    69  		Usage: "price set for the evm",
    70  		Value: new(big.Int),
    71  	}
    72  	ValueFlag = &flags.BigFlag{
    73  		Name:  "value",
    74  		Usage: "value set for the evm",
    75  		Value: new(big.Int),
    76  	}
    77  	DumpFlag = &cli.BoolFlag{
    78  		Name:  "dump",
    79  		Usage: "dumps the state after the run",
    80  	}
    81  	InputFlag = &cli.StringFlag{
    82  		Name:  "input",
    83  		Usage: "input for the EVM",
    84  	}
    85  	InputFileFlag = &cli.StringFlag{
    86  		Name:  "inputfile",
    87  		Usage: "file containing input for the EVM",
    88  	}
    89  	VerbosityFlag = &cli.IntFlag{
    90  		Name:  "verbosity",
    91  		Usage: "sets the verbosity level",
    92  	}
    93  	BenchFlag = &cli.BoolFlag{
    94  		Name:  "bench",
    95  		Usage: "benchmark the execution",
    96  	}
    97  	CreateFlag = &cli.BoolFlag{
    98  		Name:  "create",
    99  		Usage: "indicates the action should be create rather than call",
   100  	}
   101  	GenesisFlag = &cli.StringFlag{
   102  		Name:  "prestate",
   103  		Usage: "JSON file with prestate (genesis) config",
   104  	}
   105  	MachineFlag = &cli.BoolFlag{
   106  		Name:  "json",
   107  		Usage: "output trace logs in machine readable format (json)",
   108  	}
   109  	SenderFlag = &cli.StringFlag{
   110  		Name:  "sender",
   111  		Usage: "The transaction origin",
   112  	}
   113  	ReceiverFlag = &cli.StringFlag{
   114  		Name:  "receiver",
   115  		Usage: "The transaction receiver (execution context)",
   116  	}
   117  	DisableMemoryFlag = &cli.BoolFlag{
   118  		Name:  "nomemory",
   119  		Value: true,
   120  		Usage: "disable memory output",
   121  	}
   122  	DisableStackFlag = &cli.BoolFlag{
   123  		Name:  "nostack",
   124  		Usage: "disable stack output",
   125  	}
   126  	DisableStorageFlag = &cli.BoolFlag{
   127  		Name:  "nostorage",
   128  		Usage: "disable storage output",
   129  	}
   130  	DisableReturnDataFlag = &cli.BoolFlag{
   131  		Name:  "noreturndata",
   132  		Value: true,
   133  		Usage: "enable return data output",
   134  	}
   135  )
   136  
   137  var stateTransitionCommand = &cli.Command{
   138  	Name:    "transition",
   139  	Aliases: []string{"t8n"},
   140  	Usage:   "executes a full state transition",
   141  	Action:  t8ntool.Transition,
   142  	Flags: []cli.Flag{
   143  		t8ntool.TraceFlag,
   144  		t8ntool.TraceDisableMemoryFlag,
   145  		t8ntool.TraceEnableMemoryFlag,
   146  		t8ntool.TraceDisableStackFlag,
   147  		t8ntool.TraceDisableReturnDataFlag,
   148  		t8ntool.TraceEnableReturnDataFlag,
   149  		t8ntool.OutputBasedir,
   150  		t8ntool.OutputAllocFlag,
   151  		t8ntool.OutputResultFlag,
   152  		t8ntool.OutputBodyFlag,
   153  		t8ntool.InputAllocFlag,
   154  		t8ntool.InputEnvFlag,
   155  		t8ntool.InputTxsFlag,
   156  		t8ntool.ForknameFlag,
   157  		t8ntool.ChainIDFlag,
   158  		t8ntool.RewardFlag,
   159  		t8ntool.VerbosityFlag,
   160  	},
   161  }
   162  
   163  var transactionCommand = &cli.Command{
   164  	Name:    "transaction",
   165  	Aliases: []string{"t9n"},
   166  	Usage:   "performs transaction validation",
   167  	Action:  t8ntool.Transaction,
   168  	Flags: []cli.Flag{
   169  		t8ntool.InputTxsFlag,
   170  		t8ntool.ChainIDFlag,
   171  		t8ntool.ForknameFlag,
   172  		t8ntool.VerbosityFlag,
   173  	},
   174  }
   175  
   176  var blockBuilderCommand = &cli.Command{
   177  	Name:    "block-builder",
   178  	Aliases: []string{"b11r"},
   179  	Usage:   "builds a block",
   180  	Action:  t8ntool.BuildBlock,
   181  	Flags: []cli.Flag{
   182  		t8ntool.OutputBasedir,
   183  		t8ntool.OutputBlockFlag,
   184  		t8ntool.InputHeaderFlag,
   185  		t8ntool.InputOmmersFlag,
   186  		t8ntool.InputTxsRlpFlag,
   187  		t8ntool.SealCliqueFlag,
   188  		t8ntool.SealEthashFlag,
   189  		t8ntool.SealEthashDirFlag,
   190  		t8ntool.SealEthashModeFlag,
   191  		t8ntool.VerbosityFlag,
   192  	},
   193  }
   194  
   195  func init() {
   196  	app.Flags = []cli.Flag{
   197  		BenchFlag,
   198  		CreateFlag,
   199  		DebugFlag,
   200  		VerbosityFlag,
   201  		CodeFlag,
   202  		CodeFileFlag,
   203  		GasFlag,
   204  		PriceFlag,
   205  		ValueFlag,
   206  		DumpFlag,
   207  		InputFlag,
   208  		InputFileFlag,
   209  		MemProfileFlag,
   210  		CPUProfileFlag,
   211  		StatDumpFlag,
   212  		GenesisFlag,
   213  		MachineFlag,
   214  		SenderFlag,
   215  		ReceiverFlag,
   216  		DisableMemoryFlag,
   217  		DisableStackFlag,
   218  		DisableStorageFlag,
   219  		DisableReturnDataFlag,
   220  	}
   221  	app.Commands = []*cli.Command{
   222  		compileCommand,
   223  		disasmCommand,
   224  		runCommand,
   225  		stateTestCommand,
   226  		stateTransitionCommand,
   227  		transactionCommand,
   228  		blockBuilderCommand,
   229  	}
   230  }
   231  
   232  func main() {
   233  	if err := app.Run(os.Args); err != nil {
   234  		code := 1
   235  		if ec, ok := err.(*t8ntool.NumberedError); ok {
   236  			code = ec.ExitCode()
   237  		}
   238  		fmt.Fprintln(os.Stderr, err)
   239  		os.Exit(code)
   240  	}
   241  }