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

chore: removing the ibc-transfer recv addr and memo length check #2561

Merged
merged 2 commits into from
Jun 25, 2024
Merged
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
4 changes: 2 additions & 2 deletions tests/e2e/e2e_ibc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"

ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
appparams "github.com/umee-network/umee/v6/app/params"
setup "github.com/umee-network/umee/v6/tests/e2e/setup"
"github.com/umee-network/umee/v6/tests/grpc"
"github.com/umee-network/umee/v6/tests/tsdk"
"github.com/umee-network/umee/v6/util/coin"
ibcutil "github.com/umee-network/umee/v6/util/ibc"
"github.com/umee-network/umee/v6/x/uibc"
)

Expand Down Expand Up @@ -170,7 +170,7 @@ func (s *E2ETest) TestIBCTokenTransfer() {

// << Receiver Addr = maximum length + 1
// send $110 UMEE from umee to gaia (token_quota is 100$)
recvAddr := tsdk.GenerateString(ibcutil.MaximumMemoLength + 1)
recvAddr := tsdk.GenerateString(ibctransfertypes.MaximumReceiverLength + 1)
s.SendIBC(s.Chain.ID, setup.GaiaChainID, recvAddr, exceedUmee, "", "",
"recipient address must not exceed 2048 bytes")
// supply should not change
Expand Down
28 changes: 0 additions & 28 deletions util/ibc/ibc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,13 @@ package ibc

import (
"encoding/json"
"fmt"
"strings"

sdkmath "cosmossdk.io/math"
transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
ibcerrors "github.com/cosmos/ibc-go/v7/modules/core/errors"
)

const (
MaximumReceiverLength = 2048 // maximum length of the receiver address in bytes (value chosen arbitrarily)
MaximumMemoLength = 32768 // maximum length of the memo in bytes (value chosen arbitrarily)
)

func ValidateRecvAddr(receiver string) error {
if len(receiver) > MaximumReceiverLength {
return ibcerrors.ErrInvalidAddress.Wrapf("recipient address must not exceed %d bytes", MaximumReceiverLength)
}
return nil
}

func ValidateMemo(memo string) error {
if len(memo) > MaximumMemoLength {
return fmt.Errorf("memo must not exceed %d bytes", MaximumMemoLength)
}
return nil
}

// GetFundsFromPacket returns transfer amount and denom
func GetFundsFromPacket(data []byte) (sdkmath.Int, string, error) {
var packetData transfertypes.FungibleTokenPacketData
Expand All @@ -37,14 +17,6 @@ func GetFundsFromPacket(data []byte) (sdkmath.Int, string, error) {
return sdkmath.Int{}, "", err
}

if err := ValidateRecvAddr(packetData.Receiver); err != nil {
return sdkmath.Int{}, "", err
}

if err := ValidateMemo(packetData.Memo); err != nil {
return sdkmath.Int{}, "", err
}

amount, ok := sdkmath.NewIntFromString(packetData.Amount)
if !ok {
return sdkmath.Int{}, "", ibcerrors.ErrInvalidRequest.Wrapf("invalid transfer amount %s", packetData.Amount)
Expand Down
15 changes: 2 additions & 13 deletions util/ibc/ibc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,9 @@ func TestGetFundsFromPacket(t *testing.T) {
assert.Equal(t, denom, fdenom)
assert.Equal(t, famount.String(), amount)

// invalid address
data.Receiver = tsdk.GenerateString(MaximumReceiverLength + 1)
_, _, err = GetFundsFromPacket(data.GetBytes())
assert.ErrorContains(t, err, "recipient address must not exceed")

// invalid memo
data.Receiver = AddressFromString("a4")
data.Memo = tsdk.GenerateString(MaximumMemoLength + 1)
_, _, err = GetFundsFromPacket(data.GetBytes())
assert.ErrorContains(t, err, "memo must not exceed")

// valid address and memo
data.Receiver = tsdk.GenerateString(MaximumReceiverLength)
data.Memo = tsdk.GenerateString(MaximumMemoLength)
data.Receiver = tsdk.GenerateString(ibctransfertypes.MaximumReceiverLength)
data.Memo = tsdk.GenerateString(ibctransfertypes.MaximumMemoLength)
_, _, err = GetFundsFromPacket(data.GetBytes())
assert.NilError(t, err, "Should handle valid inputs without error")
}
Expand Down
Loading