Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use codespace-d errors for wasm->evm calls #1887

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions x/evm/client/wasm/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func NewEVMQueryHandler(k *keeper.Keeper) *EVMQueryHandler {
func (h *EVMQueryHandler) HandleStaticCall(ctx sdk.Context, from string, to string, data []byte) ([]byte, error) {
fromAddr, err := sdk.AccAddressFromBech32(from)
if err != nil {
return nil, err
return nil, types.ErrInvalidBech32
}
var toAddr *common.Address
if to != "" {
Expand Down Expand Up @@ -63,7 +63,7 @@ func (h *EVMQueryHandler) HandleERC20TransferPayload(ctx sdk.Context, recipient
func (h *EVMQueryHandler) HandleERC20TokenInfo(ctx sdk.Context, contractAddress string, caller string) ([]byte, error) {
callerAddr, err := sdk.AccAddressFromBech32(caller)
if err != nil {
return nil, err
return nil, types.ErrInvalidBech32
}
contract := common.HexToAddress(contractAddress)
abi, err := native.NativeMetaData.GetAbi()
Expand Down Expand Up @@ -135,7 +135,7 @@ func (h *EVMQueryHandler) HandleERC20TokenInfo(ctx sdk.Context, contractAddress
func (h *EVMQueryHandler) HandleERC20Balance(ctx sdk.Context, contractAddress string, account string) ([]byte, error) {
addr, err := sdk.AccAddressFromBech32(account)
if err != nil {
return nil, err
return nil, types.ErrInvalidBech32
}
evmAddr, found := h.k.GetEVMAddress(ctx, addr)
if !found {
Expand Down Expand Up @@ -166,7 +166,7 @@ func (h *EVMQueryHandler) HandleERC20Balance(ctx sdk.Context, contractAddress st
func (h *EVMQueryHandler) HandleERC721Owner(ctx sdk.Context, caller string, contractAddress string, tokenId string) ([]byte, error) {
callerAddr, err := sdk.AccAddressFromBech32(caller)
if err != nil {
return nil, err
return nil, types.ErrInvalidBech32
}
contract := common.HexToAddress(contractAddress)
abi, err := cw721.Cw721MetaData.GetAbi()
Expand Down Expand Up @@ -309,7 +309,7 @@ func (h *EVMQueryHandler) HandleERC20Allowance(ctx sdk.Context, contractAddress
// Get the evm address of the owner
ownerAddr, err := sdk.AccAddressFromBech32(owner)
if err != nil {
return nil, err
return nil, types.ErrInvalidBech32
}
ownerEvmAddr, found := h.k.GetEVMAddress(ctx, ownerAddr)
if !found {
Expand Down Expand Up @@ -353,7 +353,7 @@ func (h *EVMQueryHandler) HandleERC20Allowance(ctx sdk.Context, contractAddress
func (h *EVMQueryHandler) HandleERC721Approved(ctx sdk.Context, caller string, contractAddress string, tokenId string) ([]byte, error) {
callerAddr, err := sdk.AccAddressFromBech32(caller)
if err != nil {
return nil, err
return nil, types.ErrInvalidBech32
}
contract := common.HexToAddress(contractAddress)
abi, err := cw721.Cw721MetaData.GetAbi()
Expand Down Expand Up @@ -388,7 +388,7 @@ func (h *EVMQueryHandler) HandleERC721Approved(ctx sdk.Context, caller string, c
func (h *EVMQueryHandler) HandleERC721IsApprovedForAll(ctx sdk.Context, caller string, contractAddress string, owner string, operator string) ([]byte, error) {
callerAddr, err := sdk.AccAddressFromBech32(caller)
if err != nil {
return nil, err
return nil, types.ErrInvalidBech32
}
ownerEvmAddr, found := h.k.GetEVMAddress(ctx, sdk.MustAccAddressFromBech32(owner))
if !found {
Expand Down Expand Up @@ -422,7 +422,7 @@ func (h *EVMQueryHandler) HandleERC721IsApprovedForAll(ctx sdk.Context, caller s
func (h *EVMQueryHandler) HandleERC721TotalSupply(ctx sdk.Context, caller string, contractAddress string) ([]byte, error) {
callerAddr, err := sdk.AccAddressFromBech32(caller)
if err != nil {
return nil, err
return nil, types.ErrInvalidBech32
}
contract := common.HexToAddress(contractAddress)
abi, err := cw721.Cw721MetaData.GetAbi()
Expand All @@ -449,7 +449,7 @@ func (h *EVMQueryHandler) HandleERC721TotalSupply(ctx sdk.Context, caller string
func (h *EVMQueryHandler) HandleERC721NameSymbol(ctx sdk.Context, caller string, contractAddress string) ([]byte, error) {
callerAddr, err := sdk.AccAddressFromBech32(caller)
if err != nil {
return nil, err
return nil, types.ErrInvalidBech32
}
contract := common.HexToAddress(contractAddress)
abi, err := cw721.Cw721MetaData.GetAbi()
Expand Down Expand Up @@ -489,7 +489,7 @@ func (h *EVMQueryHandler) HandleERC721NameSymbol(ctx sdk.Context, caller string,
func (h *EVMQueryHandler) HandleERC721Uri(ctx sdk.Context, caller string, contractAddress string, tokenId string) ([]byte, error) {
callerAddr, err := sdk.AccAddressFromBech32(caller)
if err != nil {
return nil, err
return nil, types.ErrInvalidBech32
}
t, ok := sdk.NewIntFromString(tokenId)
if !ok {
Expand Down Expand Up @@ -519,7 +519,7 @@ func (h *EVMQueryHandler) HandleERC721Uri(ctx sdk.Context, caller string, contra
func (h *EVMQueryHandler) HandleGetEvmAddress(ctx sdk.Context, seiAddr string) ([]byte, error) {
addr, err := sdk.AccAddressFromBech32(seiAddr)
if err != nil {
return nil, err
return nil, types.ErrInvalidBech32
}
evmAddr, associated := h.k.GetEVMAddress(ctx, addr)
response := bindings.GetEvmAddressResponse{EvmAddress: evmAddr.Hex(), Associated: associated}
Expand All @@ -536,7 +536,7 @@ func (h *EVMQueryHandler) HandleGetSeiAddress(ctx sdk.Context, evmAddr string) (
func (h *EVMQueryHandler) HandleERC721RoyaltyInfo(ctx sdk.Context, caller string, contractAddress string, tokenId string, salePrice *sdk.Int) ([]byte, error) {
callerAddr, err := sdk.AccAddressFromBech32(caller)
if err != nil {
return nil, err
return nil, types.ErrInvalidBech32
}
t, ok := sdk.NewIntFromString(tokenId)
if !ok {
Expand Down Expand Up @@ -573,7 +573,7 @@ func (h *EVMQueryHandler) HandleERC721RoyaltyInfo(ctx sdk.Context, caller string
func (h *EVMQueryHandler) HandleSupportsInterface(ctx sdk.Context, caller string, id string, contractAddress string) ([]byte, error) {
callerAddr, err := sdk.AccAddressFromBech32(caller)
if err != nil {
return nil, err
return nil, types.ErrInvalidBech32
}
contract := common.HexToAddress(contractAddress)
abi, err := cw721.Cw721MetaData.GetAbi()
Expand Down
16 changes: 8 additions & 8 deletions x/evm/keeper/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
}
senderAddr, err := sdk.AccAddressFromBech32(req.Sender)
if err != nil {
return nil, err
return nil, types.ErrInvalidBech32
}
ret, err := k.CallEVM(ctx, k.GetEVMAddressOrDefault(ctx, senderAddr), to, req.Value, req.Data)
if err != nil {
Expand Down Expand Up @@ -75,10 +75,10 @@

func (k *Keeper) CallEVM(ctx sdk.Context, from common.Address, to *common.Address, val *sdk.Int, data []byte) (retdata []byte, reterr error) {
if ctx.IsEVM() && !ctx.EVMEntryViaWasmdPrecompile() {
return nil, errors.New("sei does not support EVM->CW->EVM call pattern")
return nil, types.ErrMoreThanOneHop
}
if to == nil && len(data) > params.MaxInitCodeSize {
return nil, fmt.Errorf("%w: code size %v, limit %v", core.ErrMaxInitCodeSizeExceeded, len(data), params.MaxInitCodeSize)
return nil, sdkerrors.Wrap(types.ErrMaxInitCodeSize, fmt.Sprintf("%w: code size %v, limit %v", core.ErrMaxInitCodeSizeExceeded, len(data), params.MaxInitCodeSize))

Check failure on line 81 in x/evm/keeper/evm.go

View workflow job for this annotation

GitHub Actions / tests (14)

fmt.Sprintf does not support error-wrapping directive %w

Check failure on line 81 in x/evm/keeper/evm.go

View workflow job for this annotation

GitHub Actions / lint

printf: fmt.Sprintf does not support error-wrapping directive %w (govet)
}
value := utils.Big0
if val != nil {
Expand All @@ -105,15 +105,15 @@
}
res, err := k.applyEVMMessage(ctx, evmMsg, stateDB, gp)
if err != nil {
return nil, err
return nil, sdkerrors.Wrap(types.ErrEVMExecution, err.Error())
}
k.consumeEvmGas(ctx, res.UsedGas)
if res.Err != nil {
return nil, res.Err
return nil, sdkerrors.Wrap(types.ErrResult, res.Err.Error())
}
surplus, err := stateDB.Finalize()
if err != nil {
return nil, err
return nil, sdkerrors.Wrap(types.ErrFinalizeState, err.Error())
}
vmErr := ""
if res.Err != nil {
Expand All @@ -138,7 +138,7 @@
}
receipt, err := k.WriteReceipt(ctx, stateDB, evmMsg, ethtypes.LegacyTxType, ctx.TxSum(), res.UsedGas, vmErr)
if err != nil {
return nil, err
return nil, sdkerrors.Wrap(types.ErrWriteReceipt, err.Error())
}
bloom := ethtypes.Bloom{}
bloom.SetBytes(receipt.LogsBloom)
Expand All @@ -165,7 +165,7 @@
ret, leftoverGas, err := f(vm.AccountRef(from), to, data, evmGasLimit, value)
k.consumeEvmGas(ctx, evmGasLimit-leftoverGas)
if err != nil {
return nil, err
return nil, sdkerrors.Wrap(types.ErrEVMExecution, err.Error())
}
return ret, nil
}
Expand Down
22 changes: 22 additions & 0 deletions x/evm/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package types
import (
"fmt"
"strings"

sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)

type AssociationMissingErr struct {
Expand All @@ -23,3 +25,23 @@ func (e AssociationMissingErr) AddressType() string {
}
return "sei"
}

const EvmCodespace = "evm"

var (
errInternal = sdkerrors.Register(EvmCodespace, 1, "internal")

ErrInvalidBech32 = sdkerrors.Register(EvmCodespace, 2, "invalid bech32 address representation")

ErrMoreThanOneHop = sdkerrors.Register(EvmCodespace, 3, "sei does not support EVM->CW->EVM call pattern")

ErrMaxInitCodeSize = sdkerrors.Register(EvmCodespace, 4, "max init code size exceeded")

ErrEVMExecution = sdkerrors.Register(EvmCodespace, 5, "execution error")

ErrResult = sdkerrors.Register(EvmCodespace, 6, "error in execution result")

ErrFinalizeState = sdkerrors.Register(EvmCodespace, 7, "error in stateDB finalization")

ErrWriteReceipt = sdkerrors.Register(EvmCodespace, 8, "error writing receipt")
)
Loading