Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0xNirix - Liquidity Vault will accumulate inaccessible Pegged Assets (PA) affecting users funds #101

Closed
sherlock-admin2 opened this issue Sep 10, 2024 · 0 comments
Labels
Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label High A High severity issue. Reward A payout will be made for this issue

Comments

@sherlock-admin2
Copy link
Contributor

sherlock-admin2 commented Sep 10, 2024

0xNirix

High

Liquidity Vault will accumulate inaccessible Pegged Assets (PA) affecting users funds

Summary

A flaw in the reserve calculation logic will cause an accumulation of inaccessible Pegged Assets (PA) as the Liquidity Vault will not consider stagnant PA balances in rationing on new issuance.

Root Cause

In VaultPoolLibrary, the reserve function fails to include the stagnatedPaBalance in its calculations.
https://github.com/sherlock-audit/2024-08-cork-protocol/blob/main/Depeg-swap/contracts/libraries/VaultPoolLib.sol#L26-L28

function reserve(VaultPool storage self, uint256 totalLvIssued, uint256 addedRa, uint256 addedPa) internal {
    // ... (RA handling)

    // PA
    uint256 totalPa = self.withdrawalPool.paBalance + addedPa;
    (attributedToWithdraw, attributedToAmm, ratePerLv) =
        MathHelper.separateLiquidity(totalPa, totalLvIssued, totalLvWithdrawn);

    self.withdrawalPool.paBalance = attributedToWithdraw;
    self.withdrawalPool.stagnatedPaBalance = attributedToWithdraw;
    self.withdrawalPool.paExchangeRate = ratePerLv;
}

The totalPa calculation only considers the current paBalance and addedPa (redeemed using CT), omitting the stagnatedPaBalance. Both paBalance and stagnatedPaBalance are then set to the new attributedToWithdraw value, effectively overwriting any previous stagnant PA without including it in new calculations. This leads to a continuous accumulation of inaccessible PA with each reserve operation.
According to the comment in the code also since PA are not used for providing liquidity to AMM, they should be rationed again at next issuance:

// FIXME : this is only temporary, for now
// we trate PA the same as RA, thus we also separate PA
// the difference is the PA here isn't being used as anything
// and for now will just sit there until rationed again at next expiry.

There is another issue that the stagnatedPaBalance is incorrectly set to attributedToWithdraw instead of attributedToAmm.

Internal pre-conditions

No response

External pre-conditions

No response

Attack Path

  1. A reserve operation occurs during issuance, adding new PA to the system through redemption of CT.
  2. The reserve function calculates totalPa without including stagnatedPaBalance.
  3. New paBalance and stagnatedPaBalance are set, overwriting previous values.
  4. Steps 1-3 repeat with each new reserve operation, accumulating inaccessible PA.

Impact

The users suffer an approximate loss equal to the cumulative amount of PA that becomes inaccessible over time. Users cannot redeem the full amount of PA that should be available in the system.

PoC

No response

Mitigation

Modify the reserve function to include stagnatedPaBalance in the totalPa calculation and correct the stagnatedPaBalance assignment.

Duplicate of #191

@github-actions github-actions bot added Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label High A High severity issue. labels Sep 14, 2024
@sherlock-admin3 sherlock-admin3 changed the title Gorgeous Chrome Locust - Liquidity Vault will accumulate inaccessible Pegged Assets (PA) affecting users funds 0xNirix - Liquidity Vault will accumulate inaccessible Pegged Assets (PA) affecting users funds Sep 25, 2024
@sherlock-admin3 sherlock-admin3 added the Reward A payout will be made for this issue label Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label High A High severity issue. Reward A payout will be made for this issue
Projects
None yet
Development

No branches or pull requests

2 participants