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