The fulfillSwap
function is designed to convert a specified USD amount into a collateral asset. However, the underlying logic in getAmountOfAssetOut
, which calculates the discount for the swap, relies on potentially stale data. This is because the recalculateVaultsCreditCapacity
function is not invoked before the calculation, leading to incorrect results.
The vulnerability stems from the following code:
The issue lies in the fact that getPremiumDiscountFactor
relies on vaultAssetsUsdX18
and vaultDebtUsdX18
to compute the premium or discount. However, these values may be stale if recalculateVaultsCreditCapacity
is not called beforehand. This can lead to incorrect calculations of the premiumDiscountFactorX18
, as the vault's debt and asset values may not reflect the current state.
The failure to invoke recalculateVaultsCreditCapacity
before computing the premiumDiscountFactorX18
can result in incorrect premium or discount values. This is particularly problematic in scenarios where the vault has excessive debt or credit. If the vault's debt is understated due to stale data, a lower premium factor may be applied, leading to an unfavorable swap rate. This could harm the vault by allowing more assets to be swapped than intended, potentially resulting in financial losses.
Manual code review.
To address this issue, refactor the code to ensure that recalculateVaultsCreditCapacity
is called before calculating the premiumDiscountFactorX18
. Here’s an example of how the code can be updated:
Same fix should be added to the initiateSwap
, so the minAmount check to be applied correctly
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.