Part 2

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

Incorrect check for settling vault debt

Summary

The function `settleVaultsDebt` settles the vaults debt or credit by swapping assets to usdc and vice versa.

If the vault has debt it should swap the vaults assets to USDC and if in credit then swap the vaults available USDC to its underlying asset. But the current implementation is faulty. The if statement to check if vault is in debt or not is incorrect.

Vulnerability Details

The if statement incorrectly checks if vault has debt or not.

2025-01-zaros-part-2/src/market-making/branches/CreditDelegationBranch.sol at main · Cyfrin/2025-01-zaros-part-2

// if the vault is in debt, swap its assets to USDC
if (ctx.vaultUnsettledRealizedDebtUsdX18.lt(SD59x18_ZERO))

The calculation in the if block is if the vault is in debt. But the line : `if (ctx.vaultUnsettledRealizedDebtUsdX18.lt(SD59x18_ZERO))` is incorrect as it contradicts the code and comment in the if block.

The code has to be executed if the `ctx.vaultUnsettledRealizedDebtUsdX18` is greater than 0, not is lesser than 0. If greater than 0 means that it has debt. The current check if when the vault is in credit. This disrupts the whole process as the calculation for debt and credit will be opposite to what is required.

Impact

Incorrect debt and credit calculation and swaps.

Tools Used

VS Code

Recommendations

Change to :

if (ctx.vaultUnsettledRealizedDebtUsdX18.gt(SD59x18_ZERO))
Updates

Lead Judging Commences

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

settleVaultDebt functions in opposite direction because of `ctx.vaultUnsettledRealizedDebtUsdX18.lt(SD59x18_ZERO)` having an inversed comparator (should have been gt)

Support

FAQs

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