github.com/shrimpyuk/bor@v0.2.15-0.20220224151350-fb4ec6020bae/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.TraceDisableStackFlag, 143 t8ntool.TraceDisableReturnDataFlag, 144 t8ntool.OutputBasedir, 145 t8ntool.OutputAllocFlag, 146 t8ntool.OutputResultFlag, 147 t8ntool.OutputBodyFlag, 148 t8ntool.InputAllocFlag, 149 t8ntool.InputEnvFlag, 150 t8ntool.InputTxsFlag, 151 t8ntool.ForknameFlag, 152 t8ntool.ChainIDFlag, 153 t8ntool.RewardFlag, 154 t8ntool.VerbosityFlag, 155 }, 156 } 157 var transactionCommand = cli.Command{ 158 Name: "transaction", 159 Aliases: []string{"t9n"}, 160 Usage: "performs transaction validation", 161 Action: t8ntool.Transaction, 162 Flags: []cli.Flag{ 163 t8ntool.InputTxsFlag, 164 t8ntool.ChainIDFlag, 165 t8ntool.ForknameFlag, 166 t8ntool.VerbosityFlag, 167 }, 168 } 169 170 func init() { 171 app.Flags = []cli.Flag{ 172 BenchFlag, 173 CreateFlag, 174 DebugFlag, 175 VerbosityFlag, 176 CodeFlag, 177 CodeFileFlag, 178 GasFlag, 179 PriceFlag, 180 ValueFlag, 181 DumpFlag, 182 InputFlag, 183 InputFileFlag, 184 MemProfileFlag, 185 CPUProfileFlag, 186 StatDumpFlag, 187 GenesisFlag, 188 MachineFlag, 189 SenderFlag, 190 ReceiverFlag, 191 DisableMemoryFlag, 192 DisableStackFlag, 193 DisableStorageFlag, 194 DisableReturnDataFlag, 195 } 196 app.Commands = []cli.Command{ 197 compileCommand, 198 disasmCommand, 199 runCommand, 200 stateTestCommand, 201 stateTransitionCommand, 202 transactionCommand, 203 } 204 cli.CommandHelpTemplate = flags.OriginCommandHelpTemplate 205 } 206 207 func main() { 208 if err := app.Run(os.Args); err != nil { 209 code := 1 210 if ec, ok := err.(*t8ntool.NumberedError); ok { 211 code = ec.ExitCode() 212 } 213 fmt.Fprintln(os.Stderr, err) 214 os.Exit(code) 215 } 216 }