github.com/snowblossomcoin/go-ethereum@v1.9.25/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.BoolFlag{ 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.BoolFlag{ 129 Name: "noreturndata", 130 Usage: "disable return data output", 131 } 132 EVMInterpreterFlag = cli.StringFlag{ 133 Name: "vm.evm", 134 Usage: "External EVM configuration (default = built-in interpreter)", 135 Value: "", 136 } 137 ) 138 139 var stateTransitionCommand = cli.Command{ 140 Name: "transition", 141 Aliases: []string{"t8n"}, 142 Usage: "executes a full state transition", 143 Action: t8ntool.Main, 144 Flags: []cli.Flag{ 145 t8ntool.TraceFlag, 146 t8ntool.TraceDisableMemoryFlag, 147 t8ntool.TraceDisableStackFlag, 148 t8ntool.TraceDisableReturnDataFlag, 149 t8ntool.OutputBasedir, 150 t8ntool.OutputAllocFlag, 151 t8ntool.OutputResultFlag, 152 t8ntool.InputAllocFlag, 153 t8ntool.InputEnvFlag, 154 t8ntool.InputTxsFlag, 155 t8ntool.ForknameFlag, 156 t8ntool.ChainIDFlag, 157 t8ntool.RewardFlag, 158 t8ntool.VerbosityFlag, 159 }, 160 } 161 162 func init() { 163 app.Flags = []cli.Flag{ 164 BenchFlag, 165 CreateFlag, 166 DebugFlag, 167 VerbosityFlag, 168 CodeFlag, 169 CodeFileFlag, 170 GasFlag, 171 PriceFlag, 172 ValueFlag, 173 DumpFlag, 174 InputFlag, 175 InputFileFlag, 176 MemProfileFlag, 177 CPUProfileFlag, 178 StatDumpFlag, 179 GenesisFlag, 180 MachineFlag, 181 SenderFlag, 182 ReceiverFlag, 183 DisableMemoryFlag, 184 DisableStackFlag, 185 DisableStorageFlag, 186 DisableReturnDataFlag, 187 EVMInterpreterFlag, 188 } 189 app.Commands = []cli.Command{ 190 compileCommand, 191 disasmCommand, 192 runCommand, 193 stateTestCommand, 194 stateTransitionCommand, 195 } 196 cli.CommandHelpTemplate = flags.OriginCommandHelpTemplate 197 } 198 199 func main() { 200 if err := app.Run(os.Args); err != nil { 201 code := 1 202 if ec, ok := err.(*t8ntool.NumberedError); ok { 203 code = ec.Code() 204 } 205 fmt.Fprintln(os.Stderr, err) 206 os.Exit(code) 207 } 208 }