Skip to content
Business logic Audit finding Intermediate

LP Redelegation Uses Inaccurate Internal Tracker Amount, Leading to Potential Failures or Orphaned Funds

The redelegation function uses an internal tracker amount that can diverge from the actual staked amount due to rewards or slashing. This can cause redelegation to fail or leave funds staked with the old validator while the pool points to the new one.

edoscoba Follow

Originally disclosed on Code4rena

Submitted by edoscoba

https://github.com/code-423n4/2025-04-cabal/blob/5b5f92ab4f95e5f9f405bbfa252860472d164705/sources/pool_router.move#L327-L339

Summary

The redelegate_lp function, called during validator changes for LP pools, uses the internal pool.amount tracker to specify the amount for MsgBeginRedelegate. This tracker can diverge from the actual staked amount due to unreflected rewards or slashing, potentially causing redelegation failures or leaving funds staked with the old validator.

Finding Description

The pool_router::change_validator function allows the deployer (@staking_addr) to migrate staked assets managed by a specific StakePool object from one validator to another. For LP token pools, it calls the internal helper function redelegate_lp located in pool_router.move#L327-L339.

The redelegate_lp function constructs a MsgBeginRedelegate message to be sent via cosmos::stargate. The amount of tokens to be redelegated in this message is taken directly from the pool.amount field of the StakePool resource:

    fun redelegate_lp(pool: &StakePool, new_validator_address: String) {
        let denom = coin::metadata_to_denom(pool.metadata);
        let coin = Coin { denom, amount: pool.amount }; // <<< Uses pool.amount

        let msg = MsgBeginRedelegate {
            // ... other fields ...
            amount: vector[coin] // <<< Amount specified in the message
        };
        cosmos::stargate(&object::generate_signer_for_extending(&pool.ref), marshal(&msg));
    }

However, the pool.amount is merely an internal counter updated by pool_router::add_stake and pool_router::unstake and pool_router::unlock_lp. It does not automatically reflect changes in the actual staked balance within the underlying mstaking module due to:

  1. Accrued Rewards: Rewards earned by the staked LP tokens increase the actual delegation shares/amount but are not reflected in pool.amount until compound_lp_pool_rewards runs (triggered by user actions) and subsequently calls add_stake.
  2. Slashing: If the validator is slashed, the actual delegation shares/amount decreases, but pool.amount is never updated to reflect this loss.

Therefore, pool.amount can easily drift from the true staked amount. Sending a MsgBeginRedelegate with this potentially inaccurate amount breaks the expectation that the administrative function correctly manages the entirety of the funds associated with the StakePool object.

Impact

Using an inaccurate amount in MsgBeginRedelegate leads to two primary negative outcomes:

  1. Redelegation Failure:If pool.amount is greater than the actual staked amount (e.g., due to slashing), the underlying mstaking module will reject the request, causing the cosmos::stargate call and the entire change_validator transaction to abort. This prevents the deployer from migrating funds away from a potentially slashed or undesirable validator.
  2. Partial Redelegation / Orphaned Funds: If pool.amount is less than the actual staked amount (e.g., due to accrued rewards not yet reflected), the mstaking module will likely succeed in redelegating only the specified pool.amount. The remaining tokens (the difference) will be left staked with the original validator. However, the change_validator function proceeds to update pool.validator to the new address. This creates an inconsistent state where the StakePool object points to the new validator, but some funds remain with the old one, potentially becoming difficult to track, manage, or withdraw through the router’s standard logic.

Likelihood

The likelihood of pool.amount becoming inaccurate is High. Staking rewards are expected to accrue over time. If users don’t frequently stake or unstake from a specific LP pool, the compound_lp_pool_rewards function won’t run often, causing pool.amount to lag behind the actual staked amount (actual > tracker). Slashing events, while less frequent, would cause the tracker to exceed the actual amount.

Therefore, drift between pool.amount and the real staked value is highly likely. The likelihood of this drift causing a problem during a change_validator call is Medium, as it depends on when the deployer chooses to execute this administrative action relative to the drift.

Recommended mitigation steps

Modify the redelegate_lp function to query the actual delegation amount from the underlying mstaking module before constructing the MsgBeginRedelegate message. This can be done using a query_stargate call similar to the one used in get_lp_real_stakes. Use this queried, accurate amount instead of pool.amount.

Apply the following conceptual change (exact query path and response parsing might need adjustment based on Initia’s mstaking module specifics) to pool_router.move#L327-L339:

     fun redelegate_lp(pool: &StakePool, new_validator_address: String) {
         let denom = coin::metadata_to_denom(pool.metadata);
-        let coin = Coin { denom, amount: pool.amount };
+        let pool_addr = object::address_from_extend_ref(&pool.ref);

+        // Query the actual staked amount instead of relying on the internal tracker
+        let path = b"/initia.mstaking.v1.Query/Delegation"; // Adjust path if needed
+        let request = DelegationRequest { validator_addr: pool.validator, delegator_addr: address::to_sdk(pool_addr) };
+        let response_bytes = query_stargate(path, marshal(&request));
+        // Note: Need robust parsing and error handling for the query response here.
+        // Assuming successful query and parsing to get the actual_staked_amount:
+        let actual_staked_amount = parse_delegation_response_amount(response_bytes, denom); // Placeholder for parsing logic
+        assert!(actual_staked_amount > 0, error::invalid_state(0)); // Add appropriate error code
+
+        let coin = Coin { denom, amount: actual_staked_amount }; // Use the queried amount
         let msg = MsgBeginRedelegate {
             _type_: string::utf8(b"/initia.mstaking.v1.MsgBeginRedelegate"),
             delegator_address: to_sdk(object::address_from_extend_ref(&pool.ref)),

(Note: The parse_delegation_response_amount function is illustrative; the actual implementation would involve using unmarshal and navigating the DelegationResponse struct as done in get_lp_real_stakes to extract the correct amount for the given denom.)

Proof of Concept

  1. Setup: Configure an LP pool using add_pool. Stake some LP tokens via cabal::stake_asset (which calls pool_router::add_stake), setting pool.amount to, say, 1,000,000.
  2. Scenario 1 (Rewards Accrued): Assume rewards accrue in the underlying mstaking module, increasing the actual staked amount to 1,050,000, but no user actions trigger compounding, so pool.amount remains 1,000,000.
  3. Action: The deployer calls change_validator for this pool. redelegate_lp is called.
  4. Execution: redelegate_lp constructs MsgBeginRedelegate with amount = 1,000,000.
  5. Outcome: The mstaking module successfully redelegates 1,000,000 tokens. 50,000 tokens remain staked with the old validator. change_validator updates pool.validator to the new address. The 50,000 tokens are now potentially orphaned from the router’s perspective.
  6. Scenario 2 (Slashing Occurred): Assume the validator was slashed, reducing the actual staked amount to 950,000, but pool.amount remains 1,000,000.
  7. Action: The deployer calls change_validator. redelegate_lp is called.
  8. Execution: reredelegate_lp constructs MsgBeginRedelegate with amount = 1,000,000.
  9. Outcome: The mstaking module rejects the request because only 950,000 tokens are available. The cosmos::stargate call fails, causing the change_validator transaction to abort. The validator cannot be changed.

The original report as published on Code4rena, by edoscoba. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The code uses an internal counter (`pool.amount`) that is not updated for accrued rewards or slashing, instead of querying the actual staked amount from the staking module.

Impact

If the tracker is too high, redelegation fails and the validator cannot be changed; if too low, some funds remain with the old validator and may become orphaned.

What the attacker needed

Deployer role; LP pool with staked tokens; rewards accrued or slashing occurred

The fix

The redelegation function should query the actual staked amount from the staking module and use that instead of the internal tracker.

How it was found

  1. Configure an LP pool and stake LP tokens, setting pool.amount to a value.
  2. Allow rewards to accrue or a slashing event to occur, so the actual staked amount differs from pool.amount.
  3. The deployer calls change_validator for the pool, which calls redelegate_lp.
  4. redelegate_lp constructs a MsgBeginRedelegate with the outdated pool.amount.
  5. The staking module either redelegates only the specified amount (leaving the rest with the old validator) or rejects the request if the amount exceeds the actual stake.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

When you stake tokens, the amount you actually have can change over time because you earn rewards or because the validator loses some tokens (slashing). The code here uses an old saved number instead of checking the real amount. So when it tries to move the tokens to a new validator, it might ask for too many or too few, causing an error or leaving some tokens behind.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by edoscoba

View all

3 more disclosed reports, best first.

More from Cabal Liquid Staking Token

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.