Part 2

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

CreditDelegationBranch::rebalanceVaultsAssets will revert when vaults are in correct state

Summary

The rebalanceVaultsAssets function in CreditDelegationBranch contains incorrect comparisons and absolute value calculations for vault debts. When a vault is in credit, its debt is negative, but the condition incorrectly reverts even when the vaults are in a valid state. Additionally, the absolute value is applied to the wrong variable, leading to incorrect calculations in the rebalancing logic.

Vulnerability Details

Wrong Comparison in Vault Debt Check

if (
inCreditVaultUnsettledRealizedDebtUsdX18.lte(SD59x18_ZERO)
|| inDebtVaultUnsettledRealizedDebtUsdX18.gte(SD59x18_ZERO) // @audit - wrong comparison
) {
revert Errors.InvalidVaultDebtSettlementRequest();
}

The checks enforces:

  • The credit vault’s debt should be positive

  • The debt vault’s debt should be negative
    Due to the incorrect condition, the function incorrectly reverts when vaults are actually in the correct state.

Vault in debt have more asset than deposited USDC. So inDebt vault will have more unsettled realized debt than zero. And inCredit vault will have less asset than USDC. Due to this check, when vaults are in correct state, the function will revert

Impact

  • The function incorrectly reverts in cases where the vaults are already in the correct state.

  • Rebalancing cannot proceed, which could prevent proper debt settlement and affect protocol stability.

Tools Used

  • Manual code review

Recommendations

1. Fix the Debt Comparison Logic

Change:

if (
inCreditVaultUnsettledRealizedDebtUsdX18.gte(SD59x18_ZERO) // Corrected comparison
|| inDebtVaultUnsettledRealizedDebtUsdX18.lte(SD59x18_ZERO) // Corrected comparison
) {
revert Errors.InvalidVaultDebtSettlementRequest();
}

This ensures that:

  • The credit vault has a negative unsettled debt.

  • The debt vault has a positive unsettled debt.

Updates

Lead Judging Commences

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

Improper if conditions inside `rebalanceVaultsAssets` cause reverts when it shouldn't

Support

FAQs

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

Give us feedback!