main.go 5.6 KB

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