From a6e5751a9ce57221a2dd5e8df73fa91d2ddb2939 Mon Sep 17 00:00:00 2001 From: rjl493456442 Date: Fri, 16 Jun 2017 16:19:00 +0800 Subject: [PATCH] core/vm/runtime: return `tx reverted` back --- cmd/evm/runner.go | 4 ++-- core/vm/runtime/fuzz.go | 2 +- core/vm/runtime/runtime.go | 18 +++++++++--------- core/vm/runtime/runtime_example_test.go | 2 +- core/vm/runtime/runtime_test.go | 4 ++-- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/cmd/evm/runner.go b/cmd/evm/runner.go index b1fb8998f1..482c2a8e73 100644 --- a/cmd/evm/runner.go +++ b/cmd/evm/runner.go @@ -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) diff --git a/core/vm/runtime/fuzz.go b/core/vm/runtime/fuzz.go index cb9ff08b5b..2b3eddb964 100644 --- a/core/vm/runtime/fuzz.go +++ b/core/vm/runtime/fuzz.go @@ -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, }) diff --git a/core/vm/runtime/runtime.go b/core/vm/runtime/runtime.go index 0bca6efb05..57eee6650e 100644 --- a/core/vm/runtime/runtime.go +++ b/core/vm/runtime/runtime.go @@ -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 } diff --git a/core/vm/runtime/runtime_example_test.go b/core/vm/runtime/runtime_example_test.go index b7d0ddc384..d183b3c22f 100644 --- a/core/vm/runtime/runtime_example_test.go +++ b/core/vm/runtime/runtime_example_test.go @@ -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) } diff --git a/core/vm/runtime/runtime_test.go b/core/vm/runtime/runtime_test.go index 7f40770d21..4897f64395 100644 --- a/core/vm/runtime/runtime_test.go +++ b/core/vm/runtime/runtime_test.go @@ -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) }