diff --git a/protocol/x/affiliates/keeper/keeper.go b/protocol/x/affiliates/keeper/keeper.go index f942e46418..ee068a7265 100644 --- a/protocol/x/affiliates/keeper/keeper.go +++ b/protocol/x/affiliates/keeper/keeper.go @@ -310,8 +310,12 @@ func (k Keeper) SetAffiliateWhitelist(ctx sdk.Context, whitelist types.Affiliate "taker fee share ppm %d is greater than the cap %d", tier.TakerFeeSharePpm, types.AffiliatesRevSharePpmCap) } - // Check for duplicate addresses. for _, address := range tier.Addresses { + // Check for invalid addresses. + if _, err := sdk.AccAddressFromBech32(address); err != nil { + return errorsmod.Wrapf(types.ErrInvalidAddress, "address to whitelist: %s", address) + } + // Check for duplicate addresses. if addressSet[address] { return errorsmod.Wrapf(types.ErrDuplicateAffiliateAddressForWhitelist, "address %s is duplicated in affiliate whitelist", address) diff --git a/protocol/x/affiliates/keeper/keeper_test.go b/protocol/x/affiliates/keeper/keeper_test.go index 96b25b83e5..aeb9efd139 100644 --- a/protocol/x/affiliates/keeper/keeper_test.go +++ b/protocol/x/affiliates/keeper/keeper_test.go @@ -484,6 +484,36 @@ func TestSetAffiliateWhitelist(t *testing.T) { }, expectedError: types.ErrRevShareSafetyViolation, }, + { + name: "Invalid bech32 address present", + whitelist: types.AffiliateWhitelist{ + Tiers: []types.AffiliateWhitelist_Tier{ + { + Addresses: []string{ + constants.AliceAccAddress.String(), + "dydxinvalidaddress", + }, + TakerFeeSharePpm: 500_000, // 50% + }, + }, + }, + expectedError: types.ErrInvalidAddress, + }, + { + name: "Validator operator address not accepted", + whitelist: types.AffiliateWhitelist{ + Tiers: []types.AffiliateWhitelist_Tier{ + { + Addresses: []string{ + constants.AliceAccAddress.String(), + "dydxvaloper1et2kxktzr6tav65uhrxsyr8gx82xvan6gl78xd", + }, + TakerFeeSharePpm: 500_000, // 50% + }, + }, + }, + expectedError: types.ErrInvalidAddress, + }, } for _, tc := range testCases {