main.go 4.89 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
// Copyright 2014 The go-ethereum Authors
// This file is part of go-ethereum.
//
// go-ethereum is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// go-ethereum is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 13 14
// GNU General Public License for more details.
//
// 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/>.
obscuren's avatar
obscuren committed
16

17
// evm executes EVM code snippets.
obscuren's avatar
obscuren committed
18 19 20 21
package main

import (
	"fmt"
22
	"math/big"
obscuren's avatar
obscuren committed
23 24
	"os"

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"
obscuren's avatar
obscuren committed
29 30
)

31
var gitCommit = "" // Git SHA1 commit hash of the release (set via linker flags)
32
var gitDate = ""
33

obscuren's avatar
obscuren committed
34
var (
35
	app = flags.NewApp(gitCommit, gitDate, "the evm command line interface")
36

37 38 39 40
	DebugFlag = cli.BoolFlag{
		Name:  "debug",
		Usage: "output full trace logs",
	}
41 42 43 44 45 46 47 48 49 50 51 52
	MemProfileFlag = cli.StringFlag{
		Name:  "memprofile",
		Usage: "creates a memory profile at the given path",
	}
	CPUProfileFlag = cli.StringFlag{
		Name:  "cpuprofile",
		Usage: "creates a CPU profile at the given path",
	}
	StatDumpFlag = cli.BoolFlag{
		Name:  "statdump",
		Usage: "displays stack and heap memory information",
	}
53 54 55 56
	CodeFlag = cli.StringFlag{
		Name:  "code",
		Usage: "EVM code",
	}
57 58
	CodeFileFlag = cli.StringFlag{
		Name:  "codefile",
59
		Usage: "File containing EVM code. If '-' is specified, code is read from stdin ",
60
	}
61
	GasFlag = cli.Uint64Flag{
62 63
		Name:  "gas",
		Usage: "gas limit for the evm",
64
		Value: 10000000000,
65
	}
66
	PriceFlag = utils.BigFlag{
67 68
		Name:  "price",
		Usage: "price set for the evm",
69
		Value: new(big.Int),
70
	}
71
	ValueFlag = utils.BigFlag{
72 73
		Name:  "value",
		Usage: "value set for the evm",
74
		Value: new(big.Int),
75 76 77 78 79 80 81 82 83
	}
	DumpFlag = cli.BoolFlag{
		Name:  "dump",
		Usage: "dumps the state after the run",
	}
	InputFlag = cli.StringFlag{
		Name:  "input",
		Usage: "input for the EVM",
	}
84 85 86 87
	InputFileFlag = cli.StringFlag{
		Name:  "inputfile",
		Usage: "file containing input for the EVM",
	}
88 89 90 91
	VerbosityFlag = cli.IntFlag{
		Name:  "verbosity",
		Usage: "sets the verbosity level",
	}
92 93 94 95
	BenchFlag = cli.BoolFlag{
		Name:  "bench",
		Usage: "benchmark the execution",
	}
96 97 98 99
	CreateFlag = cli.BoolFlag{
		Name:  "create",
		Usage: "indicates the action should be create rather than call",
	}
100 101 102 103 104 105 106 107 108 109 110 111
	GenesisFlag = cli.StringFlag{
		Name:  "prestate",
		Usage: "JSON file with prestate (genesis) config",
	}
	MachineFlag = cli.BoolFlag{
		Name:  "json",
		Usage: "output trace logs in machine readable format (json)",
	}
	SenderFlag = cli.StringFlag{
		Name:  "sender",
		Usage: "The transaction origin",
	}
112 113 114 115
	ReceiverFlag = cli.StringFlag{
		Name:  "receiver",
		Usage: "The transaction receiver (execution context)",
	}
116 117 118 119 120 121 122 123
	DisableMemoryFlag = cli.BoolFlag{
		Name:  "nomemory",
		Usage: "disable memory output",
	}
	DisableStackFlag = cli.BoolFlag{
		Name:  "nostack",
		Usage: "disable stack output",
	}
124 125 126 127 128 129 130 131
	DisableStorageFlag = cli.BoolFlag{
		Name:  "nostorage",
		Usage: "disable storage output",
	}
	DisableReturnDataFlag = cli.BoolFlag{
		Name:  "noreturndata",
		Usage: "disable return data output",
	}
132 133 134 135 136
	EVMInterpreterFlag = cli.StringFlag{
		Name:  "vm.evm",
		Usage: "External EVM configuration (default = built-in interpreter)",
		Value: "",
	}
obscuren's avatar
obscuren committed
137 138
)

139 140 141 142 143 144 145 146 147
var stateTransitionCommand = cli.Command{
	Name:    "transition",
	Aliases: []string{"t8n"},
	Usage:   "executes a full state transition",
	Action:  t8ntool.Main,
	Flags: []cli.Flag{
		t8ntool.TraceFlag,
		t8ntool.TraceDisableMemoryFlag,
		t8ntool.TraceDisableStackFlag,
148
		t8ntool.TraceDisableReturnDataFlag,
149
		t8ntool.OutputBasedir,
150 151 152 153 154 155 156 157 158 159 160 161
		t8ntool.OutputAllocFlag,
		t8ntool.OutputResultFlag,
		t8ntool.InputAllocFlag,
		t8ntool.InputEnvFlag,
		t8ntool.InputTxsFlag,
		t8ntool.ForknameFlag,
		t8ntool.ChainIDFlag,
		t8ntool.RewardFlag,
		t8ntool.VerbosityFlag,
	},
}

162 163
func init() {
	app.Flags = []cli.Flag{
164
		BenchFlag,
165
		CreateFlag,
166
		DebugFlag,
167
		VerbosityFlag,
168
		CodeFlag,
169
		CodeFileFlag,
170 171 172 173 174
		GasFlag,
		PriceFlag,
		ValueFlag,
		DumpFlag,
		InputFlag,
175
		InputFileFlag,
176 177 178
		MemProfileFlag,
		CPUProfileFlag,
		StatDumpFlag,
179 180 181
		GenesisFlag,
		MachineFlag,
		SenderFlag,
182
		ReceiverFlag,
183 184
		DisableMemoryFlag,
		DisableStackFlag,
185 186
		DisableStorageFlag,
		DisableReturnDataFlag,
187
		EVMInterpreterFlag,
188
	}
189 190
	app.Commands = []cli.Command{
		compileCommand,
191
		disasmCommand,
192
		runCommand,
193
		stateTestCommand,
194
		stateTransitionCommand,
195
	}
196
	cli.CommandHelpTemplate = flags.OriginCommandHelpTemplate
197 198 199 200
}

func main() {
	if err := app.Run(os.Args); err != nil {
201 202 203 204
		code := 1
		if ec, ok := err.(*t8ntool.NumberedError); ok {
			code = ec.Code()
		}
205
		fmt.Fprintln(os.Stderr, err)
206
		os.Exit(code)
207
	}
obscuren's avatar
obscuren committed
208
}