github.com/cryptotooltop/go-ethereum@v0.0.0-20231103184714-151d1922f3e5/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 "gopkg.in/urfave/cli.v1" 26 27 "github.com/scroll-tech/go-ethereum/cmd/evm/internal/t8ntool" 28 "github.com/scroll-tech/go-ethereum/cmd/utils" 29 "github.com/scroll-tech/go-ethereum/internal/flags" 30 ) 31 32 var gitCommit = "" // Git SHA1 commit hash of the release (set via linker flags) 33 var gitDate = "" 34 35 var ( 36 app = flags.NewApp(gitCommit, gitDate, "the evm command line interface") 37 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 = utils.BigFlag{ 68 Name: "price", 69 Usage: "price set for the evm", 70 Value: new(big.Int), 71 } 72 ValueFlag = utils.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.BoolTFlag{ 118 Name: "nomemory", 119 Usage: "disable memory output", 120 } 121 DisableStackFlag = cli.BoolFlag{ 122 Name: "nostack", 123 Usage: "disable stack output", 124 } 125 DisableStorageFlag = cli.BoolFlag{ 126 Name: "nostorage", 127 Usage: "disable storage output", 128 } 129 DisableReturnDataFlag = cli.BoolTFlag{ 130 Name: "noreturndata", 131 Usage: "enable return data output", 132 } 133 ) 134 135 var stateTransitionCommand = cli.Command{ 136 Name: "transition", 137 Aliases: []string{"t8n"}, 138 Usage: "executes a full state transition", 139 Action: t8ntool.Transition, 140 Flags: []cli.Flag{ 141 t8ntool.TraceFlag, 142 t8ntool.TraceDisableMemoryFlag, 143 t8ntool.TraceEnableMemoryFlag, 144 t8ntool.TraceDisableStackFlag, 145 t8ntool.TraceDisableReturnDataFlag, 146 t8ntool.TraceEnableReturnDataFlag, 147 t8ntool.OutputBasedir, 148 t8ntool.OutputAllocFlag, 149 t8ntool.OutputResultFlag, 150 t8ntool.OutputBodyFlag, 151 t8ntool.InputAllocFlag, 152 t8ntool.InputEnvFlag, 153 t8ntool.InputTxsFlag, 154 t8ntool.ForknameFlag, 155 t8ntool.ChainIDFlag, 156 t8ntool.RewardFlag, 157 t8ntool.VerbosityFlag, 158 }, 159 } 160 var transactionCommand = cli.Command{ 161 Name: "transaction", 162 Aliases: []string{"t9n"}, 163 Usage: "performs transaction validation", 164 Action: t8ntool.Transaction, 165 Flags: []cli.Flag{ 166 t8ntool.InputTxsFlag, 167 t8ntool.ChainIDFlag, 168 t8ntool.ForknameFlag, 169 t8ntool.VerbosityFlag, 170 }, 171 } 172 173 var blockBuilderCommand = cli.Command{ 174 Name: "block-builder", 175 Aliases: []string{"b11r"}, 176 Usage: "builds a block", 177 Action: t8ntool.BuildBlock, 178 Flags: []cli.Flag{ 179 t8ntool.OutputBasedir, 180 t8ntool.OutputBlockFlag, 181 t8ntool.InputHeaderFlag, 182 t8ntool.InputOmmersFlag, 183 t8ntool.InputTxsRlpFlag, 184 t8ntool.SealCliqueFlag, 185 t8ntool.SealEthashFlag, 186 t8ntool.SealEthashDirFlag, 187 t8ntool.SealEthashModeFlag, 188 t8ntool.VerbosityFlag, 189 }, 190 } 191 192 func init() { 193 app.Flags = []cli.Flag{ 194 BenchFlag, 195 CreateFlag, 196 DebugFlag, 197 VerbosityFlag, 198 CodeFlag, 199 CodeFileFlag, 200 GasFlag, 201 PriceFlag, 202 ValueFlag, 203 DumpFlag, 204 InputFlag, 205 InputFileFlag, 206 MemProfileFlag, 207 CPUProfileFlag, 208 StatDumpFlag, 209 GenesisFlag, 210 MachineFlag, 211 SenderFlag, 212 ReceiverFlag, 213 DisableMemoryFlag, 214 DisableStackFlag, 215 DisableStorageFlag, 216 DisableReturnDataFlag, 217 } 218 app.Commands = []cli.Command{ 219 compileCommand, 220 disasmCommand, 221 runCommand, 222 stateTestCommand, 223 stateTransitionCommand, 224 transactionCommand, 225 blockBuilderCommand, 226 } 227 cli.CommandHelpTemplate = flags.OriginCommandHelpTemplate 228 } 229 230 func main() { 231 if err := app.Run(os.Args); err != nil { 232 code := 1 233 if ec, ok := err.(*t8ntool.NumberedError); ok { 234 code = ec.ExitCode() 235 } 236 fmt.Fprintln(os.Stderr, err) 237 os.Exit(code) 238 } 239 }