2015-07-07 03:54:22 +03:00
|
|
|
// 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
|
2015-07-22 19:48:40 +03:00
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2015-07-07 03:54:22 +03:00
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
2015-07-22 19:48:40 +03:00
|
|
|
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
|
2014-11-10 12:47:37 +02:00
|
|
|
|
2015-07-07 06:08:16 +03:00
|
|
|
// evm executes EVM code snippets.
|
2014-11-10 12:47:37 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
common: move big integer math to common/math (#3699)
* common: remove CurrencyToString
Move denomination values to params instead.
* common: delete dead code
* common: move big integer operations to common/math
This commit consolidates all big integer operations into common/math and
adds tests and documentation.
There should be no change in semantics for BigPow, BigMin, BigMax, S256,
U256, Exp and their behaviour is now locked in by tests.
The BigD, BytesToBig and Bytes2Big functions don't provide additional
value, all uses are replaced by new(big.Int).SetBytes().
BigToBytes is now called PaddedBigBytes, its minimum output size
parameter is now specified as the number of bytes instead of bits. The
single use of this function is in the EVM's MSTORE instruction.
Big and String2Big are replaced by ParseBig, which is slightly stricter.
It previously accepted leading zeros for hexadecimal inputs but treated
decimal inputs as octal if a leading zero digit was present.
ParseUint64 is used in places where String2Big was used to decode a
uint64.
The new functions MustParseBig and MustParseUint64 are now used in many
places where parsing errors were previously ignored.
* common: delete unused big integer variables
* accounts/abi: replace uses of BytesToBig with use of encoding/binary
* common: remove BytesToBig
* common: remove Bytes2Big
* common: remove BigTrue
* cmd/utils: add BigFlag and use it for error-checked integer flags
While here, remove environment variable processing for DirectoryFlag
because we don't use it.
* core: add missing error checks in genesis block parser
* common: remove String2Big
* cmd/evm: use utils.BigFlag
* common/math: check for 256 bit overflow in ParseBig
This is supposed to prevent silent overflow/truncation of values in the
genesis block JSON. Without this check, a genesis block that set a
balance larger than 256 bits would lead to weird behaviour in the VM.
* cmd/utils: fixup import
2017-02-27 00:21:51 +03:00
|
|
|
"math/big"
|
2014-11-10 12:47:37 +02:00
|
|
|
"os"
|
|
|
|
|
2015-07-17 16:43:16 +03:00
|
|
|
"github.com/ethereum/go-ethereum/cmd/utils"
|
2016-06-09 12:44:42 +03:00
|
|
|
"gopkg.in/urfave/cli.v1"
|
2014-11-10 12:47:37 +02:00
|
|
|
)
|
|
|
|
|
2016-09-05 14:08:41 +03:00
|
|
|
var gitCommit = "" // Git SHA1 commit hash of the release (set via linker flags)
|
|
|
|
|
2014-11-10 12:47:37 +02:00
|
|
|
var (
|
2016-09-05 14:08:41 +03:00
|
|
|
app = utils.NewApp(gitCommit, "the evm command line interface")
|
|
|
|
|
2015-07-17 16:43:16 +03:00
|
|
|
DebugFlag = cli.BoolFlag{
|
|
|
|
Name: "debug",
|
|
|
|
Usage: "output full trace logs",
|
|
|
|
}
|
2017-05-23 10:34:04 +03:00
|
|
|
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",
|
|
|
|
}
|
2015-07-17 16:43:16 +03:00
|
|
|
CodeFlag = cli.StringFlag{
|
|
|
|
Name: "code",
|
|
|
|
Usage: "EVM code",
|
|
|
|
}
|
2016-10-29 12:07:38 +03:00
|
|
|
CodeFileFlag = cli.StringFlag{
|
|
|
|
Name: "codefile",
|
2017-08-15 12:31:36 +03:00
|
|
|
Usage: "File containing EVM code. If '-' is specified, code is read from stdin ",
|
2016-10-29 12:07:38 +03:00
|
|
|
}
|
common: move big integer math to common/math (#3699)
* common: remove CurrencyToString
Move denomination values to params instead.
* common: delete dead code
* common: move big integer operations to common/math
This commit consolidates all big integer operations into common/math and
adds tests and documentation.
There should be no change in semantics for BigPow, BigMin, BigMax, S256,
U256, Exp and their behaviour is now locked in by tests.
The BigD, BytesToBig and Bytes2Big functions don't provide additional
value, all uses are replaced by new(big.Int).SetBytes().
BigToBytes is now called PaddedBigBytes, its minimum output size
parameter is now specified as the number of bytes instead of bits. The
single use of this function is in the EVM's MSTORE instruction.
Big and String2Big are replaced by ParseBig, which is slightly stricter.
It previously accepted leading zeros for hexadecimal inputs but treated
decimal inputs as octal if a leading zero digit was present.
ParseUint64 is used in places where String2Big was used to decode a
uint64.
The new functions MustParseBig and MustParseUint64 are now used in many
places where parsing errors were previously ignored.
* common: delete unused big integer variables
* accounts/abi: replace uses of BytesToBig with use of encoding/binary
* common: remove BytesToBig
* common: remove Bytes2Big
* common: remove BigTrue
* cmd/utils: add BigFlag and use it for error-checked integer flags
While here, remove environment variable processing for DirectoryFlag
because we don't use it.
* core: add missing error checks in genesis block parser
* common: remove String2Big
* cmd/evm: use utils.BigFlag
* common/math: check for 256 bit overflow in ParseBig
This is supposed to prevent silent overflow/truncation of values in the
genesis block JSON. Without this check, a genesis block that set a
balance larger than 256 bits would lead to weird behaviour in the VM.
* cmd/utils: fixup import
2017-02-27 00:21:51 +03:00
|
|
|
GasFlag = cli.Uint64Flag{
|
2015-07-17 16:43:16 +03:00
|
|
|
Name: "gas",
|
|
|
|
Usage: "gas limit for the evm",
|
common: move big integer math to common/math (#3699)
* common: remove CurrencyToString
Move denomination values to params instead.
* common: delete dead code
* common: move big integer operations to common/math
This commit consolidates all big integer operations into common/math and
adds tests and documentation.
There should be no change in semantics for BigPow, BigMin, BigMax, S256,
U256, Exp and their behaviour is now locked in by tests.
The BigD, BytesToBig and Bytes2Big functions don't provide additional
value, all uses are replaced by new(big.Int).SetBytes().
BigToBytes is now called PaddedBigBytes, its minimum output size
parameter is now specified as the number of bytes instead of bits. The
single use of this function is in the EVM's MSTORE instruction.
Big and String2Big are replaced by ParseBig, which is slightly stricter.
It previously accepted leading zeros for hexadecimal inputs but treated
decimal inputs as octal if a leading zero digit was present.
ParseUint64 is used in places where String2Big was used to decode a
uint64.
The new functions MustParseBig and MustParseUint64 are now used in many
places where parsing errors were previously ignored.
* common: delete unused big integer variables
* accounts/abi: replace uses of BytesToBig with use of encoding/binary
* common: remove BytesToBig
* common: remove Bytes2Big
* common: remove BigTrue
* cmd/utils: add BigFlag and use it for error-checked integer flags
While here, remove environment variable processing for DirectoryFlag
because we don't use it.
* core: add missing error checks in genesis block parser
* common: remove String2Big
* cmd/evm: use utils.BigFlag
* common/math: check for 256 bit overflow in ParseBig
This is supposed to prevent silent overflow/truncation of values in the
genesis block JSON. Without this check, a genesis block that set a
balance larger than 256 bits would lead to weird behaviour in the VM.
* cmd/utils: fixup import
2017-02-27 00:21:51 +03:00
|
|
|
Value: 10000000000,
|
2015-07-17 16:43:16 +03:00
|
|
|
}
|
common: move big integer math to common/math (#3699)
* common: remove CurrencyToString
Move denomination values to params instead.
* common: delete dead code
* common: move big integer operations to common/math
This commit consolidates all big integer operations into common/math and
adds tests and documentation.
There should be no change in semantics for BigPow, BigMin, BigMax, S256,
U256, Exp and their behaviour is now locked in by tests.
The BigD, BytesToBig and Bytes2Big functions don't provide additional
value, all uses are replaced by new(big.Int).SetBytes().
BigToBytes is now called PaddedBigBytes, its minimum output size
parameter is now specified as the number of bytes instead of bits. The
single use of this function is in the EVM's MSTORE instruction.
Big and String2Big are replaced by ParseBig, which is slightly stricter.
It previously accepted leading zeros for hexadecimal inputs but treated
decimal inputs as octal if a leading zero digit was present.
ParseUint64 is used in places where String2Big was used to decode a
uint64.
The new functions MustParseBig and MustParseUint64 are now used in many
places where parsing errors were previously ignored.
* common: delete unused big integer variables
* accounts/abi: replace uses of BytesToBig with use of encoding/binary
* common: remove BytesToBig
* common: remove Bytes2Big
* common: remove BigTrue
* cmd/utils: add BigFlag and use it for error-checked integer flags
While here, remove environment variable processing for DirectoryFlag
because we don't use it.
* core: add missing error checks in genesis block parser
* common: remove String2Big
* cmd/evm: use utils.BigFlag
* common/math: check for 256 bit overflow in ParseBig
This is supposed to prevent silent overflow/truncation of values in the
genesis block JSON. Without this check, a genesis block that set a
balance larger than 256 bits would lead to weird behaviour in the VM.
* cmd/utils: fixup import
2017-02-27 00:21:51 +03:00
|
|
|
PriceFlag = utils.BigFlag{
|
2015-07-17 16:43:16 +03:00
|
|
|
Name: "price",
|
|
|
|
Usage: "price set for the evm",
|
common: move big integer math to common/math (#3699)
* common: remove CurrencyToString
Move denomination values to params instead.
* common: delete dead code
* common: move big integer operations to common/math
This commit consolidates all big integer operations into common/math and
adds tests and documentation.
There should be no change in semantics for BigPow, BigMin, BigMax, S256,
U256, Exp and their behaviour is now locked in by tests.
The BigD, BytesToBig and Bytes2Big functions don't provide additional
value, all uses are replaced by new(big.Int).SetBytes().
BigToBytes is now called PaddedBigBytes, its minimum output size
parameter is now specified as the number of bytes instead of bits. The
single use of this function is in the EVM's MSTORE instruction.
Big and String2Big are replaced by ParseBig, which is slightly stricter.
It previously accepted leading zeros for hexadecimal inputs but treated
decimal inputs as octal if a leading zero digit was present.
ParseUint64 is used in places where String2Big was used to decode a
uint64.
The new functions MustParseBig and MustParseUint64 are now used in many
places where parsing errors were previously ignored.
* common: delete unused big integer variables
* accounts/abi: replace uses of BytesToBig with use of encoding/binary
* common: remove BytesToBig
* common: remove Bytes2Big
* common: remove BigTrue
* cmd/utils: add BigFlag and use it for error-checked integer flags
While here, remove environment variable processing for DirectoryFlag
because we don't use it.
* core: add missing error checks in genesis block parser
* common: remove String2Big
* cmd/evm: use utils.BigFlag
* common/math: check for 256 bit overflow in ParseBig
This is supposed to prevent silent overflow/truncation of values in the
genesis block JSON. Without this check, a genesis block that set a
balance larger than 256 bits would lead to weird behaviour in the VM.
* cmd/utils: fixup import
2017-02-27 00:21:51 +03:00
|
|
|
Value: new(big.Int),
|
2015-07-17 16:43:16 +03:00
|
|
|
}
|
common: move big integer math to common/math (#3699)
* common: remove CurrencyToString
Move denomination values to params instead.
* common: delete dead code
* common: move big integer operations to common/math
This commit consolidates all big integer operations into common/math and
adds tests and documentation.
There should be no change in semantics for BigPow, BigMin, BigMax, S256,
U256, Exp and their behaviour is now locked in by tests.
The BigD, BytesToBig and Bytes2Big functions don't provide additional
value, all uses are replaced by new(big.Int).SetBytes().
BigToBytes is now called PaddedBigBytes, its minimum output size
parameter is now specified as the number of bytes instead of bits. The
single use of this function is in the EVM's MSTORE instruction.
Big and String2Big are replaced by ParseBig, which is slightly stricter.
It previously accepted leading zeros for hexadecimal inputs but treated
decimal inputs as octal if a leading zero digit was present.
ParseUint64 is used in places where String2Big was used to decode a
uint64.
The new functions MustParseBig and MustParseUint64 are now used in many
places where parsing errors were previously ignored.
* common: delete unused big integer variables
* accounts/abi: replace uses of BytesToBig with use of encoding/binary
* common: remove BytesToBig
* common: remove Bytes2Big
* common: remove BigTrue
* cmd/utils: add BigFlag and use it for error-checked integer flags
While here, remove environment variable processing for DirectoryFlag
because we don't use it.
* core: add missing error checks in genesis block parser
* common: remove String2Big
* cmd/evm: use utils.BigFlag
* common/math: check for 256 bit overflow in ParseBig
This is supposed to prevent silent overflow/truncation of values in the
genesis block JSON. Without this check, a genesis block that set a
balance larger than 256 bits would lead to weird behaviour in the VM.
* cmd/utils: fixup import
2017-02-27 00:21:51 +03:00
|
|
|
ValueFlag = utils.BigFlag{
|
2015-07-17 16:43:16 +03:00
|
|
|
Name: "value",
|
|
|
|
Usage: "value set for the evm",
|
common: move big integer math to common/math (#3699)
* common: remove CurrencyToString
Move denomination values to params instead.
* common: delete dead code
* common: move big integer operations to common/math
This commit consolidates all big integer operations into common/math and
adds tests and documentation.
There should be no change in semantics for BigPow, BigMin, BigMax, S256,
U256, Exp and their behaviour is now locked in by tests.
The BigD, BytesToBig and Bytes2Big functions don't provide additional
value, all uses are replaced by new(big.Int).SetBytes().
BigToBytes is now called PaddedBigBytes, its minimum output size
parameter is now specified as the number of bytes instead of bits. The
single use of this function is in the EVM's MSTORE instruction.
Big and String2Big are replaced by ParseBig, which is slightly stricter.
It previously accepted leading zeros for hexadecimal inputs but treated
decimal inputs as octal if a leading zero digit was present.
ParseUint64 is used in places where String2Big was used to decode a
uint64.
The new functions MustParseBig and MustParseUint64 are now used in many
places where parsing errors were previously ignored.
* common: delete unused big integer variables
* accounts/abi: replace uses of BytesToBig with use of encoding/binary
* common: remove BytesToBig
* common: remove Bytes2Big
* common: remove BigTrue
* cmd/utils: add BigFlag and use it for error-checked integer flags
While here, remove environment variable processing for DirectoryFlag
because we don't use it.
* core: add missing error checks in genesis block parser
* common: remove String2Big
* cmd/evm: use utils.BigFlag
* common/math: check for 256 bit overflow in ParseBig
This is supposed to prevent silent overflow/truncation of values in the
genesis block JSON. Without this check, a genesis block that set a
balance larger than 256 bits would lead to weird behaviour in the VM.
* cmd/utils: fixup import
2017-02-27 00:21:51 +03:00
|
|
|
Value: new(big.Int),
|
2015-07-17 16:43:16 +03:00
|
|
|
}
|
|
|
|
DumpFlag = cli.BoolFlag{
|
|
|
|
Name: "dump",
|
|
|
|
Usage: "dumps the state after the run",
|
|
|
|
}
|
|
|
|
InputFlag = cli.StringFlag{
|
|
|
|
Name: "input",
|
|
|
|
Usage: "input for the EVM",
|
|
|
|
}
|
2015-08-30 11:19:10 +03:00
|
|
|
VerbosityFlag = cli.IntFlag{
|
|
|
|
Name: "verbosity",
|
|
|
|
Usage: "sets the verbosity level",
|
|
|
|
}
|
2016-06-14 17:09:27 +03:00
|
|
|
CreateFlag = cli.BoolFlag{
|
|
|
|
Name: "create",
|
|
|
|
Usage: "indicates the action should be create rather than call",
|
|
|
|
}
|
2017-01-05 13:52:10 +03:00
|
|
|
DisableGasMeteringFlag = cli.BoolFlag{
|
|
|
|
Name: "nogasmetering",
|
|
|
|
Usage: "disable gas metering",
|
|
|
|
}
|
2017-06-07 18:09:08 +03:00
|
|
|
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",
|
|
|
|
}
|
2017-08-15 12:31:36 +03:00
|
|
|
ReceiverFlag = cli.StringFlag{
|
|
|
|
Name: "receiver",
|
|
|
|
Usage: "The transaction receiver (execution context)",
|
|
|
|
}
|
2017-06-21 15:52:31 +03:00
|
|
|
DisableMemoryFlag = cli.BoolFlag{
|
|
|
|
Name: "nomemory",
|
|
|
|
Usage: "disable memory output",
|
|
|
|
}
|
|
|
|
DisableStackFlag = cli.BoolFlag{
|
|
|
|
Name: "nostack",
|
|
|
|
Usage: "disable stack output",
|
|
|
|
}
|
2014-11-10 12:47:37 +02:00
|
|
|
)
|
|
|
|
|
2015-07-17 16:43:16 +03:00
|
|
|
func init() {
|
|
|
|
app.Flags = []cli.Flag{
|
2016-06-14 17:09:27 +03:00
|
|
|
CreateFlag,
|
2015-07-17 16:43:16 +03:00
|
|
|
DebugFlag,
|
2015-08-30 11:19:10 +03:00
|
|
|
VerbosityFlag,
|
2015-07-17 16:43:16 +03:00
|
|
|
CodeFlag,
|
2016-10-29 12:07:38 +03:00
|
|
|
CodeFileFlag,
|
2015-07-17 16:43:16 +03:00
|
|
|
GasFlag,
|
|
|
|
PriceFlag,
|
|
|
|
ValueFlag,
|
|
|
|
DumpFlag,
|
|
|
|
InputFlag,
|
2017-01-05 13:52:10 +03:00
|
|
|
DisableGasMeteringFlag,
|
2017-05-23 10:34:04 +03:00
|
|
|
MemProfileFlag,
|
|
|
|
CPUProfileFlag,
|
|
|
|
StatDumpFlag,
|
2017-06-07 18:09:08 +03:00
|
|
|
GenesisFlag,
|
|
|
|
MachineFlag,
|
|
|
|
SenderFlag,
|
2017-08-15 12:31:36 +03:00
|
|
|
ReceiverFlag,
|
2017-06-21 15:52:31 +03:00
|
|
|
DisableMemoryFlag,
|
|
|
|
DisableStackFlag,
|
2015-07-17 16:43:16 +03:00
|
|
|
}
|
2017-03-01 03:11:24 +03:00
|
|
|
app.Commands = []cli.Command{
|
|
|
|
compileCommand,
|
2017-03-01 15:34:50 +03:00
|
|
|
disasmCommand,
|
2017-03-01 03:11:24 +03:00
|
|
|
runCommand,
|
2017-09-05 12:24:26 +03:00
|
|
|
stateTestCommand,
|
2015-07-18 00:09:36 +03:00
|
|
|
}
|
2015-07-17 16:43:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
if err := app.Run(os.Args); err != nil {
|
|
|
|
fmt.Fprintln(os.Stderr, err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
2014-11-10 12:47:37 +02:00
|
|
|
}
|