Part 2

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

Vault::getUnsettledRealizedDebt miscalculates unsettled debt

Summary

The marketsRealizedDebtUsd represents the total amount of realized debt coming from markets in USD. This value represents the net delta of a market's credit deposits and its net usd token issuance. And depositedUsdc represents the total amount of USDC deposits coming from markets or other vaults to this vault, takes part of the unsettled realized debt value. According to settleVaultsDebt and rebalanceVaultsAssets, the vault is in debt when unsettled debt is negative. But the implementation of Vault::getUnsettledRealizedDebt subtract deposited usdc from realized debt. Deposited usdc is credit where as realized debt from markets is debt.

The correct calculation should deduct marketsRealizedDebtUsd from depositedUsdc:

  • If depositedUsdc > marketsRealizedDebtUsd, the vault is in credit.

  • If depositedUsdc < marketsRealizedDebtUsd, the vault is in debt.
    Currently it is doing opposite

Impact

Wrong calculation of unsettled debt causing no successfull call to settleVaultsDebt and rebalanceVaultsAssets And other functions depending on this will get affected

Recommendation

Deduct marketsRealizedDebtUsd from depositedUsdc:

function getUnsettledRealizedDebt(Data storage self)
internal
view
returns (SD59x18 unsettledRealizedDebtUsdX18)
{
unsettledRealizedDebtUsdX18 =
- sd59x18(self.marketsRealizedDebtUsd).add(unary(ud60x18(self.depositedUsdc).intoSD59x18()));
+ sd59x18(self.depositedUsdc).add(unary(sd59x18(self.marketsRealizedDebtUsd).intoSD59x18()));
}
Updates

Lead Judging Commences

inallhonesty Lead Judge
10 months ago
inallhonesty Lead Judge 10 months ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement

Appeal created

i_atiq Submitter
10 months ago
inallhonesty Lead Judge
10 months ago
inallhonesty Lead Judge 9 months ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement

Support

FAQs

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

Give us feedback!