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

fix: fix ibc transfer msg recv length check #2550

Merged
merged 7 commits into from
Jun 17, 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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ Ref: https://keepachangelog.com/en/1.0.0/
- [2473](https://github.com/umee-network/umee/pull/2473) Correct x/ugov Amino registration for x/ugov messages (they don't have MessageName option).
- [2547](https://github.com/umee-network/umee/pull/2547) Fix the `MissCounters` grpc-web get api result.

## v6.4.1 - 2024-04-30

### Improvements

- [daef10a](https://github.com/umee-network/umee/commit/daef10ad4f774aae915ad33f4ab1134695146785) Update dependencies.
gsk967 marked this conversation as resolved.
Show resolved Hide resolved

## v6.4.0 - 2024-03-21

### Features
Expand Down
4 changes: 2 additions & 2 deletions docs/VALIDATOR.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ Here are our testnet public endpoints:

1. Make sure you firstly tested your setup on Testnet.
2. Use one of the community snapshots:
* [Polkachu](https://polkachu.com/tendermint_snapshots/umee).
* [Autostake](https://autostake.com/networks/umee/#services).
- [Polkachu](https://polkachu.com/tendermint_snapshots/umee).
- [Autostake](https://autostake.com/networks/umee/#services).
3. Buy `uumee` to self delegate.
4. Make sure your Price Feeder is running correctly. If your [mainnet window misses](https://price-feeder.com/) are above 50% then something is wrong. Look for a help on Discord.

Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ require (
github.com/moby/term v0.0.0-20220808134915-39b0c02b01ae // indirect
github.com/mtibben/percent v0.2.1 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/onsi/gomega v1.31.1 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0-rc2 // indirect
github.com/opencontainers/runc v1.1.5 // indirect
Expand Down
10 changes: 10 additions & 0 deletions tests/e2e/e2e_ibc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
setup "github.com/umee-network/umee/v6/tests/e2e/setup"
"github.com/umee-network/umee/v6/tests/grpc"
"github.com/umee-network/umee/v6/util/coin"
ibcutil "github.com/umee-network/umee/v6/util/ibc"
"github.com/umee-network/umee/v6/util/sdkutil"
"github.com/umee-network/umee/v6/x/uibc"
)

Expand Down Expand Up @@ -164,6 +166,14 @@ func (s *E2ETest) TestIBCTokenTransfer() {
// supply don't change
s.checkSupply(gaiaAPIEndpoint, umeeIBCHash, math.ZeroInt())

// << Recevier Addr = maximum length + 1
// send $110 UMEE from umee to gaia (token_quota is 100$)
recvAddr := sdkutil.GenerateString(ibcutil.MaximumMemoLength + 1)
s.SendIBC(s.Chain.ID, setup.GaiaChainID, recvAddr, exceedUmee, true, "", "")
// check the ibc (umee) quota after ibc txs - this one should have failed
// supply don't change
s.checkSupply(gaiaAPIEndpoint, umeeIBCHash, math.ZeroInt())

gsk967 marked this conversation as resolved.
Show resolved Hide resolved
// send $110 ATOM from umee to gaia
exceedAtom := mulCoin(atomQuota, "1.1")
// supply will be not be decreased because sending amount is more than token quota so it will fail
Expand Down
8 changes: 6 additions & 2 deletions tests/e2e/setup/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,14 @@ func (s *E2ETestSuite) SendIBC(srcChainID, dstChainID, recipient string, token s
if i < 4 {
continue
}
s.Require().Failf("failed to find transaction hash in output outBuf: %s errBuf: %s", outBuf.String(), errBuf.String())
if !strings.Contains(outBuf.String(), "bad packet in rate limit's SendPacket") {
s.Require().Failf("failed to find transaction hash in output outBuf: %s errBuf: %s",
outBuf.String(), errBuf.String())
}
}

// s.Require().NotEmptyf(txHash, "failed to find transaction hash in output outBuf: %s errBuf: %s", outBuf.String(), errBuf.String())
// s.Require().NotEmptyf(txHash, "failed to find transaction hash in output outBuf: %s
// errBuf: %s", outBuf.String(), errBuf.String())
// endpoint := s.UmeeREST()
// if strings.Contains(srcChainID, "gaia") {
// endpoint = s.GaiaREST()
Expand Down
32 changes: 30 additions & 2 deletions util/ibc/ibc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,33 @@ package ibc

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

sdkmath "cosmossdk.io/math"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
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 @@ -17,9 +37,17 @@ 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{}, "", sdkerrors.ErrInvalidRequest.Wrapf("invalid transfer amount %s", packetData.Amount)
return sdkmath.Int{}, "", ibcerrors.ErrInvalidRequest.Wrapf("invalid transfer amount %s", packetData.Amount)
}

return amount, GetLocalDenom(packetData.Denom), nil
Expand Down
12 changes: 12 additions & 0 deletions util/ibc/ibc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/cometbft/cometbft/crypto"
ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
"github.com/umee-network/umee/v6/util/sdkutil"
"gotest.tools/v3/assert"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -32,6 +33,17 @@ func TestGetFundsFromPacket(t *testing.T) {
assert.NilError(t, err)
assert.Equal(t, denom, fdenom)
assert.Equal(t, famount.String(), amount)

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

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

func TestGetLocalDenom(t *testing.T) {
Expand Down
11 changes: 11 additions & 0 deletions util/sdkutil/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package sdkutil

import (
"fmt"
"math/rand"
"strings"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -30,3 +31,13 @@ func FormatDec(d sdk.Dec) string {
func FormatDecCoin(c sdk.DecCoin) string {
return fmt.Sprintf("%s %s", FormatDec(c.Amount), c.Denom)
}

func GenerateString(length uint) string {
// character set used for generating a random string in GenerateString
charset := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
bytes := make([]byte, length)
for i := range bytes {
bytes[i] = charset[rand.Intn(len(charset))] //nolint
}
return string(bytes)
}
gsk967 marked this conversation as resolved.
Show resolved Hide resolved
Loading