main.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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/cmd/utils"
  24. "gopkg.in/urfave/cli.v1"
  25. )
  26. var gitCommit = "" // Git SHA1 commit hash of the release (set via linker flags)
  27. var gitDate = ""
  28. var (
  29. app = utils.NewApp(gitCommit, gitDate, "the evm command line interface")
  30. DebugFlag = cli.BoolFlag{
  31. Name: "debug",
  32. Usage: "output full trace logs",
  33. }
  34. MemProfileFlag = cli.StringFlag{
  35. Name: "memprofile",
  36. Usage: "creates a memory profile at the given path",
  37. }
  38. CPUProfileFlag = cli.StringFlag{
  39. Name: "cpuprofile",
  40. Usage: "creates a CPU profile at the given path",
  41. }
  42. StatDumpFlag = cli.BoolFlag{
  43. Name: "statdump",
  44. Usage: "displays stack and heap memory information",
  45. }
  46. CodeFlag = cli.StringFlag{
  47. Name: "code",
  48. Usage: "EVM code",
  49. }
  50. CodeFileFlag = cli.StringFlag{
  51. Name: "codefile",
  52. Usage: "File containing EVM code. If '-' is specified, code is read from stdin ",
  53. }
  54. GasFlag = cli.Uint64Flag{
  55. Name: "gas",
  56. Usage: "gas limit for the evm",
  57. Value: 10000000000,
  58. }
  59. PriceFlag = utils.BigFlag{
  60. Name: "price",
  61. Usage: "price set for the evm",
  62. Value: new(big.Int),
  63. }
  64. ValueFlag = utils.BigFlag{
  65. Name: "value",
  66. Usage: "value set for the evm",
  67. Value: new(big.Int),
  68. }
  69. DumpFlag = cli.BoolFlag{
  70. Name: "dump",
  71. Usage: "dumps the state after the run",
  72. }
  73. InputFlag = cli.StringFlag{
  74. Name: "input",
  75. Usage: "input for the EVM",
  76. }
  77. InputFileFlag = cli.StringFlag{
  78. Name: "inputfile",
  79. Usage: "file containing input for the EVM",
  80. }
  81. VerbosityFlag = cli.IntFlag{
  82. Name: "verbosity",
  83. Usage: "sets the verbosity level",
  84. }
  85. BenchFlag = cli.BoolFlag{
  86. Name: "bench",
  87. Usage: "benchmark the execution",
  88. }
  89. CreateFlag = cli.BoolFlag{
  90. Name: "create",
  91. Usage: "indicates the action should be create rather than call",
  92. }
  93. GenesisFlag = cli.StringFlag{
  94. Name: "prestate",
  95. Usage: "JSON file with prestate (genesis) config",
  96. }
  97. MachineFlag = cli.BoolFlag{
  98. Name: "json",
  99. Usage: "output trace logs in machine readable format (json)",
  100. }
  101. SenderFlag = cli.StringFlag{
  102. Name: "sender",
  103. Usage: "The transaction origin",
  104. }
  105. ReceiverFlag = cli.StringFlag{
  106. Name: "receiver",
  107. Usage: "The transaction receiver (execution context)",
  108. }
  109. DisableMemoryFlag = cli.BoolFlag{
  110. Name: "nomemory",
  111. Usage: "disable memory output",
  112. }
  113. DisableStackFlag = cli.BoolFlag{
  114. Name: "nostack",
  115. Usage: "disable stack output",
  116. }
  117. EVMInterpreterFlag = cli.StringFlag{
  118. Name: "vm.evm",
  119. Usage: "External EVM configuration (default = built-in interpreter)",
  120. Value: "",
  121. }
  122. )
  123. var stateTransitionCommand = cli.Command{
  124. Name: "transition",
  125. Aliases: []string{"t8n"},
  126. Usage: "executes a full state transition",
  127. Action: t8ntool.Main,
  128. Flags: []cli.Flag{
  129. t8ntool.TraceFlag,
  130. t8ntool.TraceDisableMemoryFlag,
  131. t8ntool.TraceDisableStackFlag,
  132. t8ntool.OutputAllocFlag,
  133. t8ntool.OutputResultFlag,
  134. t8ntool.InputAllocFlag,
  135. t8ntool.InputEnvFlag,
  136. t8ntool.InputTxsFlag,
  137. t8ntool.ForknameFlag,
  138. t8ntool.ChainIDFlag,
  139. t8ntool.RewardFlag,
  140. t8ntool.VerbosityFlag,
  141. },
  142. }
  143. func init() {
  144. app.Flags = []cli.Flag{
  145. BenchFlag,
  146. CreateFlag,
  147. DebugFlag,
  148. VerbosityFlag,
  149. CodeFlag,
  150. CodeFileFlag,
  151. GasFlag,
  152. PriceFlag,
  153. ValueFlag,
  154. DumpFlag,
  155. InputFlag,
  156. InputFileFlag,
  157. MemProfileFlag,
  158. CPUProfileFlag,
  159. StatDumpFlag,
  160. GenesisFlag,
  161. MachineFlag,
  162. SenderFlag,
  163. ReceiverFlag,
  164. DisableMemoryFlag,
  165. DisableStackFlag,
  166. EVMInterpreterFlag,
  167. }
  168. app.Commands = []cli.Command{
  169. compileCommand,
  170. disasmCommand,
  171. runCommand,
  172. stateTestCommand,
  173. stateTransitionCommand,
  174. }
  175. cli.CommandHelpTemplate = utils.OriginCommandHelpTemplate
  176. }
  177. func main() {
  178. if err := app.Run(os.Args); err != nil {
  179. code := 1
  180. if ec, ok := err.(*t8ntool.NumberedError); ok {
  181. code = ec.Code()
  182. }
  183. fmt.Fprintln(os.Stderr, err)
  184. os.Exit(code)
  185. }
  186. }