Skip to content

Commit

Permalink
[AUDIT FIX] migrate halted field, remove prepare delegation, clarifyi…
Browse files Browse the repository at this point in the history
…ng comment, check halted in claim
  • Loading branch information
sampocs committed Jun 29, 2024
1 parent c3ffbf6 commit 25ed61b
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
5 changes: 0 additions & 5 deletions x/staketia/keeper/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ func (k Keeper) BeforeEpochStart(ctx sdk.Context, epochInfo epochstypes.EpochInf
// Every day, refresh the redemption rate and prepare delegations
// Every 4 days, prepare undelegations
if epochInfo.Identifier == epochstypes.DAY_EPOCH {
// Prepare delegations by transferring the deposited tokens to the host zone
if err := k.SafelyPrepareDelegation(ctx, epochNumber, epochInfo.Duration); err != nil {
k.Logger(ctx).Error(fmt.Sprintf("Unable to prepare delegation for epoch %d: %s", epochNumber, err.Error()))
}

// Every few days (depending on the unbonding frequency) prepare undelegations which
// freezes the accumulating unbonding record and refreshes the native token amount
// TODO [cleanup]: replace with unbonding frequency
Expand Down
1 change: 1 addition & 0 deletions x/staketia/keeper/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func (k Keeper) UpdateStakeibcHostZone(ctx sdk.Context, legacyHostZone oldtypes.
stakeibcHostZone.RedemptionRate = legacyHostZone.RedemptionRate
stakeibcHostZone.MinInnerRedemptionRate = legacyHostZone.MinInnerRedemptionRate
stakeibcHostZone.MaxInnerRedemptionRate = legacyHostZone.MaxInnerRedemptionRate
stakeibcHostZone.Halted = legacyHostZone.Halted

// Set the total delegations to the sum of the staketia total
stakeibcHostZone.TotalDelegations = legacyHostZone.DelegatedBalance
Expand Down
3 changes: 3 additions & 0 deletions x/staketia/keeper/migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

func (s *KeeperTestSuite) TestUpdateStakeibcHostZone() {
// Create a host zone with a delegated balance of 1000
halted := true
totalDelegations := sdk.NewInt(1_000)
redemptionRate := sdk.NewDec(2)
minInnerRedemptionRate := sdk.MustNewDecFromStr("1.9")
Expand All @@ -24,6 +25,7 @@ func (s *KeeperTestSuite) TestUpdateStakeibcHostZone() {
DelegatedBalance: totalDelegations,
MinInnerRedemptionRate: minInnerRedemptionRate,
MaxInnerRedemptionRate: maxInnerRedemptionRate,
Halted: halted,
}
stakeibcHostZone := stakeibctypes.HostZone{
ChainId: types.CelestiaChainId,
Expand All @@ -40,6 +42,7 @@ func (s *KeeperTestSuite) TestUpdateStakeibcHostZone() {
s.Require().Equal(redemptionRate, actualStakeibcHostZone.RedemptionRate, "redemption rate")
s.Require().Equal(minInnerRedemptionRate, actualStakeibcHostZone.MinInnerRedemptionRate, "min redemption rate")
s.Require().Equal(maxInnerRedemptionRate, actualStakeibcHostZone.MaxInnerRedemptionRate, "max redemption rate")
s.Require().Equal(halted, actualStakeibcHostZone.Halted, "halted")

// Remove the host zone and try again, it should fail
s.App.StakeibcKeeper.RemoveHostZone(s.Ctx, types.CelestiaChainId)
Expand Down
8 changes: 7 additions & 1 deletion x/staketia/keeper/unbonding.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (k Keeper) RedeemStake(
) (nativeToken sdk.Coin, err error) {
// Validate Basic already has ensured redeemer is legal address, stTokenAmount is above min threshold

// Check HostZone exists, has legal redemption address for escrow, is not halted, has RR in bounds
// Check HostZone exists, and that the stakeibc host zone is not halted
hostZone, err := k.GetUnhaltedHostZone(ctx)
if err != nil {
return nativeToken, err
Expand All @@ -41,6 +41,7 @@ func (k Keeper) RedeemStake(
return nativeToken, types.ErrRedemptionsDisabled
}

// Check that the redemption address exists as the escrow account
escrowAccount, err := sdk.AccAddressFromBech32(hostZone.RedemptionAddress)
if err != nil {
return nativeToken, errorsmod.Wrapf(err, "could not bech32 decode redemption address %s on stride", hostZone.RedemptionAddress)
Expand Down Expand Up @@ -386,10 +387,15 @@ func (k Keeper) ConfirmUnbondedTokenSweep(ctx sdk.Context, recordId uint64, txHa
func (k Keeper) DistributeClaims(ctx sdk.Context) error {
// Get the claim address which will be the sender
// The token denom will be the native host zone token in it's IBC form as it lives on stride
// We check the stakeibc host zone as well to confirm there's no halt
hostZone, err := k.GetUnhaltedHostZone(ctx)
if err != nil {
return err
}
_, err = k.stakeibcKeeper.GetActiveHostZone(ctx, types.CelestiaChainId)
if err != nil {
return err
}
nativeTokenIbcDenom := hostZone.NativeTokenIbcDenom

claimAddress, err := sdk.AccAddressFromBech32(hostZone.ClaimAddress)
Expand Down
5 changes: 5 additions & 0 deletions x/staketia/keeper/unbonding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,11 @@ func (s *KeeperTestSuite) SetupTestDistributeClaims() DistributeClaimsTestCase {
}
s.App.StaketiaKeeper.SetHostZone(s.Ctx, hostZone)

// Create unhalted stakeibc host zone
s.App.StakeibcKeeper.SetHostZone(s.Ctx, stakeibctypes.HostZone{
ChainId: types.CelestiaChainId,
})

// Define unbonding records with different statuses
claimableRecordIds := []uint64{1, 3}
unbondingRecords := []types.UnbondingRecord{
Expand Down

0 comments on commit 25ed61b

Please sign in to comment.