From 4e00501680c449a5866ccfcc115f8f358aa4dd6b Mon Sep 17 00:00:00 2001 From: Aidan Salzmann Date: Fri, 2 Dec 2022 11:26:18 -0500 Subject: [PATCH 1/2] IF-STRIDE-STAKEIBC-UPDATEDELEGATIONBALANCES fix --- x/stakeibc/keeper/icacallbacks_undelegate.go | 8 +++++++- x/stakeibc/types/errors.go | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/x/stakeibc/keeper/icacallbacks_undelegate.go b/x/stakeibc/keeper/icacallbacks_undelegate.go index 7b7d36ac0..8a8c76a3a 100644 --- a/x/stakeibc/keeper/icacallbacks_undelegate.go +++ b/x/stakeibc/keeper/icacallbacks_undelegate.go @@ -120,7 +120,13 @@ func (k Keeper) UpdateDelegationBalances(ctx sdk.Context, zone types.HostZone, u if !success { return sdkerrors.Wrapf(types.ErrValidatorDelegationChg, "Failed to remove delegation to validator") } - zone.StakedBal -= undelegation.Amount + if undelegation.Amount > zone.StakedBal { + // handle incoming underflow + // Once we add a killswitch, we should also stop liquid staking on the zone here + return sdkerrors.Wrapf(types.ErrUndelegationAmount, "undelegation.Amount > zone.StakedBal, undelegation.Amount: %s, zone.StakedBal %s", undelegation.Amount, zone.StakedBal) + } else { + zone.StakedBal -= undelegation.Amount + } } k.SetHostZone(ctx, zone) return nil diff --git a/x/stakeibc/types/errors.go b/x/stakeibc/types/errors.go index 062151529..d2de73ee6 100644 --- a/x/stakeibc/types/errors.go +++ b/x/stakeibc/types/errors.go @@ -47,4 +47,5 @@ var ( ErrHostZoneICAAccountNotFound = sdkerrors.Register(ModuleName, 1537, "host zone's ICA account not found") ErrNoValidatorAmts = sdkerrors.Register(ModuleName, 1538, "could not fetch validator amts") ErrMaxNumValidators = sdkerrors.Register(ModuleName, 1539, "max number of validators reached") + ErrUndelegationAmount = sdkerrors.Register(ModuleName, 1540, "Undelegation amount is greater than stakedBal") ) From edc73b0ebffa38307ba18eba3f66fa3bc2cf617d Mon Sep 17 00:00:00 2001 From: Aidan Salzmann Date: Sat, 3 Dec 2022 12:51:43 -0600 Subject: [PATCH 2/2] use %d --- x/stakeibc/keeper/icacallbacks_undelegate.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/stakeibc/keeper/icacallbacks_undelegate.go b/x/stakeibc/keeper/icacallbacks_undelegate.go index 8a8c76a3a..e51cf492e 100644 --- a/x/stakeibc/keeper/icacallbacks_undelegate.go +++ b/x/stakeibc/keeper/icacallbacks_undelegate.go @@ -123,7 +123,7 @@ func (k Keeper) UpdateDelegationBalances(ctx sdk.Context, zone types.HostZone, u if undelegation.Amount > zone.StakedBal { // handle incoming underflow // Once we add a killswitch, we should also stop liquid staking on the zone here - return sdkerrors.Wrapf(types.ErrUndelegationAmount, "undelegation.Amount > zone.StakedBal, undelegation.Amount: %s, zone.StakedBal %s", undelegation.Amount, zone.StakedBal) + return sdkerrors.Wrapf(types.ErrUndelegationAmount, "undelegation.Amount > zone.StakedBal, undelegation.Amount: %d, zone.StakedBal %d", undelegation.Amount, zone.StakedBal) } else { zone.StakedBal -= undelegation.Amount }