refactor: separate error clearing from inner functionality

`EVMInterpreter.Run` was clearing the `errStopToken`, which is useful in some projects that customize the EVM.
This commit is contained in:
Ayoub Benaissa 2023-12-01 16:17:54 +01:00 committed by GitHub
parent 5fb8ebc9ec
commit bd220bc950
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -98,13 +98,8 @@ func NewEVMInterpreter(evm *EVM) *EVMInterpreter {
return &EVMInterpreter{evm: evm, table: table}
}
// Run loops and evaluates the contract's code with the given input data and returns
// the return byte-slice and an error if one occurred.
//
// 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.
func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (ret []byte, err error) {
// Similar to `Run`, except that it doesn't clear stop token error
func (in *EVMInterpreter) RunAndKeepStopToken(contract *Contract, input []byte, readOnly bool) (ret []byte, err error) {
// Increment the call depth which is restricted to 1024
in.evm.depth++
defer func() { in.evm.depth-- }()
@ -233,6 +228,17 @@ func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (
}
pc++
}
return res, err
}
// Run loops and evaluates the contract's code with the given input data and returns
// the return byte-slice and an error if one occurred.
//
// 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.
func (in *EVMInterpreter) Run(contract *Contract, input []byte, readOnly bool) (ret []byte, err error) {
res, err := in.RunAndKeepStopToken(contract, input, readOnly)
if err == errStopToken {
err = nil // clear stop token error