Skip to content
Business logic Audit finding Intermediate

_ineligible() redemptionEligible is miscalculated

The Vault contract's _ineligible() function incorrectly subtracts the current deposit amount from totalCollateral when calculating redemptionEligible, even though that deposit is not yet part of totalCollateral. This makes redemptionEligible too small, causing too many positions to be opened and potentially preventing proper claimAssets.

bin2chen Follow

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2024-08-perennial-v2-update-3-judging/issues/36

Found by

bin2chen

Summary

Vault._ineligible() should not include the depositAssets of update() when calculating the redemptionEligible, which is not part of the totalCollateral.

Root Cause

in Vault.sol:L411

The method _ineligible() internally calculates the redemptionEligible first. using the formula: redemptionEligible = totalCollateral - (global.assets + withdrawal) - global.deposit

The problem is subtracting global.deposit, which already contains the current depositAssets. The current depositAssets is not in totalCollateral and should not be subtracted.

the redemptionEligible is too small, which causes the ineligible to be too small.

Example: context.totalCollateral = 100 , global.assets = 0, global.deposit =0

  1. user call update(depositAssets = 10)
  2. global.deposit += depositAssets = 10 (includes this deposit)
  3. redemptionEligible = 100 - (0 + 0) - 10 = 90

The correct value should be: redemptionEligible = 100

Internal pre-conditions

No response

External pre-conditions

No response

Attack Path

No response

Impact

One of the main effects of _ineligible() is that this part cannot be used as an asset to open a position; if this value is too small, too many positions are opened, resulting in the inability to claimAssets properly.

PoC

No response

Mitigation

Diff
-   function _ineligible(Context memory context, UFixed6 withdrawal) private pure returns (UFixed6) {
+   function _ineligible(Context memory context,UFixed6 deposit, UFixed6 withdrawal) private pure returns (UFixed6) {

        // assets eligible for redemption
        UFixed6 redemptionEligible = UFixed6Lib.unsafeFrom(context.totalCollateral)
            // assets pending claim (use latest global assets before withdrawal for redeemability)
            .unsafeSub(context.global.assets.add(withdrawal))
            // assets pending deposit
-           .unsafeSub(context.global.deposit);
+           .unsafeSub(context.global.deposit.sub(deposit))

        return redemptionEligible
            // approximate assets up for redemption
            .mul(context.global.redemption.unsafeDiv(context.global.shares.add(context.global.redemption)))
            // assets pending claim (use new global assets after withdrawal for eligability)
            .add(context.global.assets);
            // assets pending deposit are eligible for allocation
    }

Discussion

sherlock-admin2

The protocol team fixed this issue in the following PRs/commits: https://github.com/equilibria-xyz/perennial-v2/pull/460

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

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 _ineligible() function subtracts global.deposit, which includes the current depositAssets, from totalCollateral even though depositAssets is not yet part of totalCollateral.

Impact

Because redemptionEligible is too small, too many positions may be opened, which could prevent proper claimAssets.

What the attacker needed

None

The fix

The protocol team fixed this issue by adjusting the calculation to subtract only the portion of global.deposit that does not include the current deposit.

How it was found

  1. A user calls update with a deposit amount.
  2. The global.deposit value is increased by that deposit amount.
  3. The _ineligible() function calculates redemptionEligible by subtracting global.deposit from totalCollateral, which incorrectly reduces the eligible amount.

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.

A vault contract calculates how much of its assets can be redeemed. It mistakenly subtracts a new deposit from the total collateral even though that deposit has not been added to the collateral yet. This makes the redeemable amount look smaller than it is, so the vault may open too many positions and later fail to pay out withdrawals.

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 bin2chen

View all

139 more disclosed reports, best first.

More from Perennial V2 Update #3

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.