main.go 4.9 KB

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