mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 15:16:43 +00:00
core/vm/runtime: return tx reverted back
This commit is contained in:
parent
24c7b58baf
commit
a6e5751a9c
5 changed files with 15 additions and 15 deletions
|
|
@ -174,12 +174,12 @@ func runCmd(ctx *cli.Context) error {
|
|||
var leftOverGas uint64
|
||||
if ctx.GlobalBool(CreateFlag.Name) {
|
||||
input := append(code, common.Hex2Bytes(ctx.GlobalString(InputFlag.Name))...)
|
||||
ret, _, leftOverGas, err = runtime.Create(input, &runtimeConfig)
|
||||
ret, _, leftOverGas, _, err = runtime.Create(input, &runtimeConfig)
|
||||
} else {
|
||||
receiver := common.StringToAddress("receiver")
|
||||
statedb.SetCode(receiver, code)
|
||||
|
||||
ret, leftOverGas, err = runtime.Call(receiver, common.Hex2Bytes(ctx.GlobalString(InputFlag.Name)), &runtimeConfig)
|
||||
ret, leftOverGas, _, err = runtime.Call(receiver, common.Hex2Bytes(ctx.GlobalString(InputFlag.Name)), &runtimeConfig)
|
||||
}
|
||||
execTime := time.Since(tstart)
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ package runtime
|
|||
// This returns 1 for valid parsable/runable code, 0
|
||||
// for invalid opcode.
|
||||
func Fuzz(input []byte) int {
|
||||
_, _, err := Execute(input, input, &Config{
|
||||
_, _, _, err := Execute(input, input, &Config{
|
||||
GasLimit: 3000000,
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ func setDefaults(cfg *Config) {
|
|||
// Executes sets up a in memory, temporarily, environment for the execution of
|
||||
// the given code. It enabled the JIT by default and make sure that it's restored
|
||||
// to it's original state afterwards.
|
||||
func Execute(code, input []byte, cfg *Config) ([]byte, *state.StateDB, error) {
|
||||
func Execute(code, input []byte, cfg *Config) ([]byte, *state.StateDB, bool, error) {
|
||||
if cfg == nil {
|
||||
cfg = new(Config)
|
||||
}
|
||||
|
|
@ -113,7 +113,7 @@ func Execute(code, input []byte, cfg *Config) ([]byte, *state.StateDB, error) {
|
|||
// set the receiver's (the executing contract) code for execution.
|
||||
cfg.State.SetCode(address, code)
|
||||
// Call the code with the given configuration.
|
||||
ret, _, _, err := vmenv.Call(
|
||||
ret, _, reverted, err := vmenv.Call(
|
||||
sender,
|
||||
common.StringToAddress("contract"),
|
||||
input,
|
||||
|
|
@ -121,11 +121,11 @@ func Execute(code, input []byte, cfg *Config) ([]byte, *state.StateDB, error) {
|
|||
cfg.Value,
|
||||
)
|
||||
|
||||
return ret, cfg.State, err
|
||||
return ret, cfg.State, reverted, err
|
||||
}
|
||||
|
||||
// Create executes the code using the EVM create method
|
||||
func Create(input []byte, cfg *Config) ([]byte, common.Address, uint64, error) {
|
||||
func Create(input []byte, cfg *Config) ([]byte, common.Address, uint64, bool, error) {
|
||||
if cfg == nil {
|
||||
cfg = new(Config)
|
||||
}
|
||||
|
|
@ -141,13 +141,13 @@ func Create(input []byte, cfg *Config) ([]byte, common.Address, uint64, error) {
|
|||
)
|
||||
|
||||
// Call the code with the given configuration.
|
||||
code, address, leftOverGas, _, err := vmenv.Create(
|
||||
code, address, leftOverGas, reverted, err := vmenv.Create(
|
||||
sender,
|
||||
input,
|
||||
cfg.GasLimit,
|
||||
cfg.Value,
|
||||
)
|
||||
return code, address, leftOverGas, err
|
||||
return code, address, leftOverGas, reverted, err
|
||||
}
|
||||
|
||||
// Call executes the code given by the contract's address. It will return the
|
||||
|
|
@ -155,14 +155,14 @@ func Create(input []byte, cfg *Config) ([]byte, common.Address, uint64, error) {
|
|||
//
|
||||
// Call, unlike Execute, requires a config and also requires the State field to
|
||||
// be set.
|
||||
func Call(address common.Address, input []byte, cfg *Config) ([]byte, uint64, error) {
|
||||
func Call(address common.Address, input []byte, cfg *Config) ([]byte, uint64, bool, error) {
|
||||
setDefaults(cfg)
|
||||
|
||||
vmenv := NewEnv(cfg, cfg.State)
|
||||
|
||||
sender := cfg.State.GetOrNewStateObject(cfg.Origin)
|
||||
// Call the code with the given configuration.
|
||||
ret, leftOverGas, _, err := vmenv.Call(
|
||||
ret, leftOverGas, reverted, err := vmenv.Call(
|
||||
sender,
|
||||
address,
|
||||
input,
|
||||
|
|
@ -170,5 +170,5 @@ func Call(address common.Address, input []byte, cfg *Config) ([]byte, uint64, er
|
|||
cfg.Value,
|
||||
)
|
||||
|
||||
return ret, leftOverGas, err
|
||||
return ret, leftOverGas, reverted, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ import (
|
|||
)
|
||||
|
||||
func ExampleExecute() {
|
||||
ret, _, err := runtime.Execute(common.Hex2Bytes("6060604052600a8060106000396000f360606040526008565b00"), nil, nil)
|
||||
ret, _, _, err := runtime.Execute(common.Hex2Bytes("6060604052600a8060106000396000f360606040526008565b00"), nil, nil)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ func TestEVM(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestExecute(t *testing.T) {
|
||||
ret, _, err := Execute([]byte{
|
||||
ret, _, _, err := Execute([]byte{
|
||||
byte(vm.PUSH1), 10,
|
||||
byte(vm.PUSH1), 0,
|
||||
byte(vm.MSTORE),
|
||||
|
|
@ -106,7 +106,7 @@ func TestCall(t *testing.T) {
|
|||
byte(vm.RETURN),
|
||||
})
|
||||
|
||||
ret, _, err := Call(address, nil, &Config{State: state})
|
||||
ret, _, _, err := Call(address, nil, &Config{State: state})
|
||||
if err != nil {
|
||||
t.Fatal("didn't expect error", err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue