Skip to content

Commit

Permalink
feat(axelarnet)!: block transfer to uppercase GMP account
Browse files Browse the repository at this point in the history
  • Loading branch information
haiyizxx committed Aug 15, 2023
1 parent 17cdb24 commit e598517
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
19 changes: 17 additions & 2 deletions x/axelarnet/message_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package axelarnet
import (
"encoding/json"
"fmt"
"strings"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
Expand Down Expand Up @@ -102,9 +103,13 @@ func OnRecvMessage(ctx sdk.Context, k keeper.Keeper, ibcK keeper.IBCKeeper, n ty
return channeltypes.NewErrorAcknowledgement(err)
}

err = validateReceiver(data.GetReceiver())
if err != nil {
return channeltypes.NewErrorAcknowledgement(err)
}

// Skip if packet not sent to Axelar message sender account.
// Receiver must be valid at this point. Otherwise, the transfer handler in upper layer would reject the packet.
if !types.AxelarGMPAccount.Equals(funcs.Must(sdk.AccAddressFromBech32(data.GetReceiver()))) {
if types.AxelarGMPAccount.String() != data.GetReceiver() {
// Rate limit non-GMP IBC transfers
// IBC receives are rate limited on the Incoming direction (tokens coming in to Axelar hub).
if err := r.RateLimitPacket(ctx, packet, nexus.Incoming, types.NewIBCPath(packet.GetDestPort(), packet.GetDestChannel())); err != nil {
Expand Down Expand Up @@ -399,3 +404,13 @@ func deductFee(ctx sdk.Context, b types.BankKeeper, fee *Fee, token keeper.Coin,

return token, b.SendCoins(ctx, types.AxelarGMPAccount, recipient, sdk.NewCoins(coin))
}

// validateReceiver rejects uppercase gmp account address
func validateReceiver(receiver string) error {
// Restrict to the lower case GMP account address
if strings.ToUpper(receiver) == receiver && types.AxelarGMPAccount.Equals(funcs.Must(sdk.AccAddressFromBech32(receiver))) {
return fmt.Errorf("uppercase GMP account address is not allowed")
}

return nil
}
5 changes: 1 addition & 4 deletions x/axelarnet/message_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,10 +386,7 @@ func TestHandleMessage(t *testing.T) {
ics20Packet.Receiver = strings.ToUpper(ics20Packet.Receiver)
packet = axelartestutils.RandomPacket(ics20Packet, ibctransfertypes.PortID, sourceChannel, ibctransfertypes.PortID, receiverChannel)
}).
Then("should return ack success", func(t *testing.T) {
assert.True(t, axelarnet.OnRecvMessage(ctx, k, ibcK, n, b, r, packet).Success())
assert.Equal(t, genMsg.Status, nexus.Approved)
}).
Then("should return ack error", func(t *testing.T) { ackError() }).
Run(t)

whenMessageIsValid.
Expand Down

0 comments on commit e598517

Please sign in to comment.