Part 2

Zaros
PerpetualsDEXFoundrySolidity
70,000 USDC
View results
Submission Details
Severity: medium
Invalid

`settleCreditDeposit()` Can Cause Division by Zero and Incorrect USDC Credit Distribution

Bug Description:

The settleCreditDeposit() function is responsible for removing a settled asset from creditDeposits and distributing the received USDC to vaults based on their delegated credit share. However, the function assumes that totalDelegatedCreditUsd is always nonzero, leading to a potential division by zero when calculating addedUsdcPerCreditShareX18:

// Calculate the USDC that has been accumulated per USD of credit delegated to the market
UD60x18 addedUsdcPerCreditShareX18 = netUsdcReceivedX18.div(ud60x18(self.totalDelegatedCreditUsd));

Key issues:

  1. If totalDelegatedCreditUsd == 0, this results in a division by zero, causing a transaction revert.

    • This can happen if all vaults have withdrawn their delegated credit before the function executes.

    • The market may become unable to distribute credit settlements, leading to frozen liquidity.

  2. If totalDelegatedCreditUsd is very small, rounding errors may result in vaults receiving disproportionate or zero USDC credit.

    • A vault with a minuscule amount of delegated credit could receive an abnormally high USDC credit share, leading to unfair distributions.

    • Conversely, rounding issues could cause vaults to receive zero USDC credit despite deposits.

Impact:

A division by zero causes a full contract failure, preventing further settlements. Even if it does not revert, incorrect credit distribution leads to unfair allocation of USDC, allowing vaults to manipulate credit delegation timing to receive disproportionate rewards.

Mitigation:

Before performing the division, ensure that totalDelegatedCreditUsd is nonzero, and set a minimum floor value to prevent extreme imbalances:

if (self.totalDelegatedCreditUsd == 0) {
revert Errors.NoDelegatedCredit(self.id);
}
UD60x18 addedUsdcPerCreditShareX18 = netUsdcReceivedX18.div(
ud60x18(self.totalDelegatedCreditUsd.max(1e18)) // Ensure division remains stable
);
Updates

Lead Judging Commences

inallhonesty Lead Judge 6 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.