Part 2

Zaros
PerpetualsDEXFoundrySolidity
70,000 USDC
View results
Submission Details
Severity: high
Valid

Critical Flaw in Market's Debt Calculation Logic

[M-4] Critical Flaw in Market's Debt Calculation Logic

Description:
The getRealizedDebtUsd function in Market contract contains a fundamental logical error in debt calculation. This function is pivotal for core protocol operations including vault credit/debt settlement.

Impact:

  • Incorrect debt calculations for markets

  • Flawed vault credit/debt settlement

  • Potential system-wide accounting mismatches

Proof of Concept:

/// @notice Returns the market's net realized debt in USD.
/// @param self The market storage pointer.
/// @return realizedDebtUsdX18 The market's net realized debt in USD as SD59x18.
function getRealizedDebtUsd(Data storage self) internal view returns (SD59x18 realizedDebtUsdX18) {
// prepare the credit deposits usd value variable;
UD60x18 creditDepositsValueUsdX18;
// if the credit deposits usd value cache is up to date, return the stored value
if (block.timestamp <= self.lastCreditDepositsValueRehydration) {
creditDepositsValueUsdX18 = ud60x18(self.creditDepositsValueCacheUsd);
} else {
// otherwise, we'll need to loop over credit deposits to calculate it
creditDepositsValueUsdX18 = getCreditDepositsValueUsd(self);
}
// finally after determining the market's latest credit deposits usd value, sum it with the stored net usd
// token issuance to return the net realized debt usd value
realizedDebtUsdX18 = creditDepositsValueUsdX18.intoSD59x18().add(sd59x18(self.netUsdTokenIssuance));
}

Scenario:

Market State:
- Credit deposits: 4000 USDC
- Issued tokens: 2000 USD
Current Calculation:
realizedDebt = 4000 + 2000 = 6000 USD // Wrong!

The current implementation adds credit deposits to issued tokens , leading to:

  1. Inflated debt calculations

  2. Incorrect credit capacity assessments

  3. Potential over-delegation of credit

Recommended Mitigation:
Kindly correct the wrong calculation

Updates

Lead Judging Commences

inallhonesty Lead Judge 7 months ago
Submission Judgement Published
Validated
Assigned finding tags:

Market::getRealizedDebtUsd incorrectly adds creditDeposits to netUsdTokenIssuance when calculating debt, causing accounting errors because credit deposits should reduce debt

Support

FAQs

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