From aed6b88a816a8860ec7e09574eecda9e74fd1bcc Mon Sep 17 00:00:00 2001 From: WeiLoy Date: Fri, 10 Sep 2021 09:49:53 +0800 Subject: [PATCH] Fix the problem thrown by error --- core/vm/evm.go | 10 +++++----- core/vm/instructions.go | 5 ----- core/vm/interpreter.go | 4 ++-- core/vm/wagon_runtime.go | 10 +++++----- core/vm/wasm_engine.go | 2 +- core/vm/wasm_interpreter.go | 2 +- 6 files changed, 14 insertions(+), 19 deletions(-) diff --git a/core/vm/evm.go b/core/vm/evm.go index 7c731a92e8..b9ff2e9c57 100644 --- a/core/vm/evm.go +++ b/core/vm/evm.go @@ -299,7 +299,7 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas // when we're in homestead this also counts for code storage gas errors. if err != nil { evm.RevertToDBSnapshot(snapshotForSnapshotDB, snapshotForStateDB) - if err != errExecutionReverted { + if err != ErrExecutionReverted { contract.UseGas(contract.Gas) } } @@ -343,7 +343,7 @@ func (evm *EVM) CallCode(caller ContractRef, addr common.Address, input []byte, ret, err = run(evm, contract, input, false) if err != nil { evm.RevertToDBSnapshot(snapshotForSnapshotDB, snapshotForStateDB) - if err != errExecutionReverted { + if err != ErrExecutionReverted { contract.UseGas(contract.Gas) } } @@ -376,7 +376,7 @@ func (evm *EVM) DelegateCall(caller ContractRef, addr common.Address, input []by ret, err = run(evm, contract, input, false) if err != nil { evm.RevertToDBSnapshot(snapshotForSnapshotDB, snapshotForStateDB) - if err != errExecutionReverted { + if err != ErrExecutionReverted { contract.UseGas(contract.Gas) } } @@ -418,7 +418,7 @@ func (evm *EVM) StaticCall(caller ContractRef, addr common.Address, input []byte ret, err = run(evm, contract, input, true) if err != nil { evm.RevertToDBSnapshot(snapshotForSnapshotDB, snapshotForStateDB) - if err != errExecutionReverted { + if err != ErrExecutionReverted { contract.UseGas(contract.Gas) } } @@ -505,7 +505,7 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64, // when we're in homestead this also counts for code storage gas errors. if maxCodeSizeExceeded || (err != nil && err != ErrCodeStoreOutOfGas) { evm.RevertToDBSnapshot(snapshotForSnapshotDB, snapshotForStateDB) - if err != errExecutionReverted { + if err != ErrExecutionReverted { contract.UseGas(contract.Gas) } } diff --git a/core/vm/instructions.go b/core/vm/instructions.go index 1b50a5bc5a..986f7988e8 100644 --- a/core/vm/instructions.go +++ b/core/vm/instructions.go @@ -17,7 +17,6 @@ package vm import ( - "errors" "github.com/PlatONnetwork/PlatON-Go/common" "github.com/PlatONnetwork/PlatON-Go/core/types" "github.com/PlatONnetwork/PlatON-Go/params" @@ -25,10 +24,6 @@ import ( "golang.org/x/crypto/sha3" ) -var ( - errExecutionReverted = errors.New("execution reverted") -) - func opAdd(pc *uint64, interpreter *EVMInterpreter, callContext *callCtx) ([]byte, error) { x, y := callContext.stack.pop(), callContext.stack.peek() y.Add(&x, y) diff --git a/core/vm/interpreter.go b/core/vm/interpreter.go index fe3e393a8d..0813d78c25 100644 --- a/core/vm/interpreter.go +++ b/core/vm/interpreter.go @@ -120,7 +120,7 @@ func NewEVMInterpreter(evm *EVM, cfg Config) *EVMInterpreter { // // It's important to note that any errors returned by the interpreter should be // considered a revert-and-consume-all-gas operation except for -// errExecutionReverted which means revert-and-keep-gas-left. +// ErrExecutionReverted which means revert-and-keep-gas-left. func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (ret []byte, err error) { go func(ctx context.Context) { @@ -286,7 +286,7 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) ( case err != nil: return nil, err case operation.reverts: - return res, errExecutionReverted + return res, ErrExecutionReverted case operation.halts: return res, nil case !operation.jumps: diff --git a/core/vm/wagon_runtime.go b/core/vm/wagon_runtime.go index 9a26a3f2f9..9ea8819c90 100644 --- a/core/vm/wagon_runtime.go +++ b/core/vm/wagon_runtime.go @@ -1298,7 +1298,7 @@ func CallContract(proc *exec.Process, addrPtr, args, argsLen, val, valLen, callC status = 0 } - if err == nil || err == errExecutionReverted { + if err == nil || err == ErrExecutionReverted { ctx.CallOut = ret } @@ -1365,7 +1365,7 @@ func DelegateCallContract(proc *exec.Process, addrPtr, params, paramsLen, callCo status = 0 } - if err == nil || err == errExecutionReverted { + if err == nil || err == ErrExecutionReverted { ctx.CallOut = ret } @@ -1433,7 +1433,7 @@ func StaticCallContract(proc *exec.Process, addrPtr, params, paramsLen, callCost status = 0 } - if err == nil || err == errExecutionReverted { + if err == nil || err == ErrExecutionReverted { ctx.CallOut = ret } @@ -1623,7 +1623,7 @@ func MigrateInnerContract(proc *exec.Process, newAddr, val, valLen, callCost, ca // when we're in homestead this also counts for code storage gas errors. if maxCodeSizeExceeded || (err != nil && err != ErrCodeStoreOutOfGas) { ctx.evm.RevertToDBSnapshot(snapshotForSnapshotDB, snapshotForStateDB) - if err != errExecutionReverted { + if err != ErrExecutionReverted { contract.UseGas(contract.Gas) } } @@ -2251,7 +2251,7 @@ func CreateContract(proc *exec.Process, newAddr, val, valLen, callCost, callCost // when we're in homestead this also counts for code storage gas errors. if maxCodeSizeExceeded || (err != nil && err != ErrCodeStoreOutOfGas) { ctx.evm.RevertToDBSnapshot(snapshotForSnapshotDB, snapshotForStateDB) - if err != errExecutionReverted { + if err != ErrExecutionReverted { contract.UseGas(contract.Gas) } } diff --git a/core/vm/wasm_engine.go b/core/vm/wasm_engine.go index 57f0006522..ca4637890a 100644 --- a/core/vm/wasm_engine.go +++ b/core/vm/wasm_engine.go @@ -164,7 +164,7 @@ func (engine *wagonEngine) exec(index int64) (ret []byte, err error) { switch { case ctx.Revert: - return nil, errExecutionReverted + return nil, ErrExecutionReverted case engine.vm.Abort(): return nil, ErrAbort } diff --git a/core/vm/wasm_interpreter.go b/core/vm/wasm_interpreter.go index 7e977c83cd..e38269bd85 100644 --- a/core/vm/wasm_interpreter.go +++ b/core/vm/wasm_interpreter.go @@ -41,7 +41,7 @@ func NewWASMInterpreter(evm *EVM, cfg Config) *WASMInterpreter { // // It's important to note that any errors returned by the interpreter should be // considered a revert-and-consume-all-gas operations except for -// errExecutionReverted which means revert-and-keep-gas-lfet. +// ErrExecutionReverted which means revert-and-keep-gas-lfet. func (in *WASMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (ret []byte, err error) { defer func() { if r := recover(); r != nil {