Part 2

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

Vault::_updateCreditDelegations Will Revert If When Credit Capacity is Zero or Negative

Summary

The function _updateCreditDelegations updates vaults' credit delegations to connected markets.
The issue occurs in this line:

UD60x18 creditDeltaUsdX18 = newCreditDelegationUsdX18.sub(previousCreditDelegationUsdX18);

If newCreditDelegationUsdX18 is zero or less than previousCreditDelegationUsdX18, it will revert. This can happen when the vault's current credit capacity drops below its previous value.


Vulnerability Details

creditDeltaUsdX18 is a UD60x18 (unsigned decimal) type. When previousCreditDelegationUsdX18 > newCreditDelegationUsdX18, the subtraction:

newCreditDelegationUsdX18.sub(previousCreditDelegationUsdX18);

results in a negative number, which unsigned types do not support, causing a revert.


Impact

  • The function will always revert when newCreditDelegationUsdX18 <= previousCreditDelegationUsdX18, meaning the vault cannot reduce its credit delegation to it's connected markets

  • the vault cannot update it's state through recalculateVaultsCreditCapacity, as this function calls _updateCreditDelegations, meaning vault will stop updating it's states, users will lose rewards, depositors won't be able to withdraw funds from zlpvault


Recommendation

Use signed integers (SD59x18) for credit delta calculations.

SD59x18 creditDeltaUsdX18 = newCreditDelegationUsdX18.intoSD59x18().sub(previousCreditDelegationUsdX18.intoSD59x18());

This will eliminate the revert issue and can reduce delegated credit from market in case vault's credit capacity is less than or equal to zero

Updates

Lead Judging Commences

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

Vault::_updateCreditDelegations uses unsigned UD60x18 for credit delegation delta calculation which will underflow on any decrease in credit delegation amount

Support

FAQs

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

Give us feedback!