evm: treat all vm errors the same as reverted (#276)

Closes: #274

evm: fix `ExtraEIP` activation (#288)

Closes: #287

Update x/evm/types/utils.go

Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com>

Add `Failed` utility function and changelog
This commit is contained in:
yihuang
2021-07-15 02:01:05 -04:00
committed by GitHub
co-authored by Federico Kunze Küllmer
parent 9d1ce30ecd
commit 297a35dbdd
12 changed files with 416 additions and 201 deletions
+9 -9
View File
@@ -26,6 +26,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/crypto"
"github.com/tharsis/ethermint/crypto/hd"
@@ -525,10 +526,6 @@ func (e *PublicAPI) Call(args evmtypes.CallArgs, blockNr rpctypes.BlockNumber, _
return []byte{}, err
}
if data.Reverted {
return []byte{}, evmtypes.NewExecErrorWithReason(data.Ret)
}
return (hexutil.Bytes)(data.Ret), nil
}
@@ -547,6 +544,13 @@ func (e *PublicAPI) doCall(
return nil, err
}
if res.Failed() {
if res.VmError == vm.ErrExecutionReverted.Error() {
return nil, evmtypes.NewExecErrorWithReason(res.Ret)
}
return nil, errors.New(res.VmError)
}
return res, nil
}
@@ -562,10 +566,6 @@ func (e *PublicAPI) EstimateGas(args evmtypes.CallArgs) (hexutil.Uint64, error)
return 0, err
}
if data.Reverted {
return 0, evmtypes.NewExecErrorWithReason(data.Ret)
}
return hexutil.Uint64(data.GasUsed), nil
}
@@ -781,7 +781,7 @@ func (e *PublicAPI) GetTransactionReceipt(hash common.Hash) (map[string]interfac
// Get the transaction result from the log
var status hexutil.Uint
if strings.Contains(res.TxResult.GetLog(), evmtypes.AttributeKeyEthereumTxReverted) {
if strings.Contains(res.TxResult.GetLog(), evmtypes.AttributeKeyEthereumTxFailed) {
status = hexutil.Uint(ethtypes.ReceiptStatusFailed)
} else {
status = hexutil.Uint(ethtypes.ReceiptStatusSuccessful)