CreditDelegationBranch::settleVaultsDebt()
function uses incorrect comparison and causes assets to be swapped in the wrong direction when settling vault debt/credit positions. This allows users to swap usdTokens for vault assets at a better ratio.
Note: this submission has 3 parts. First and third part describe the same problem but in different parts of the codebase. The second part builds on top of part 1, thus keeping them togheter.
vault.getUnsettledRealizedDebt()
returns an SD59x18
type value representing the vault's debt/credit position. A negative value indicates a credit balance, meaning the vault has accumulated USDC that should be swapped to the vault's asset. A positive value indicates debt, requiring the vault's assets to be swapped to USDC for coverage. This is the core purpose of the settleVaultsDebt function.
The function first queries getUnsettledRealizedDebt()
to determine the debtOrCredit value, then checks whether the vault is in debt or credit. However, the logic for this determination is inverted: when vaultUnsettledRealizedDebtUsdX18
is less than 0
, the vault is actually in credit, not debt as the current code assumes.
When vault is in credit and vault's assets are swapped to USDC vault.marketsRealizedDebtUsd is decreased by the amount of USDC it received, decreasing realized debt.
This variable is used in getUnsettledRealizedDebt meaning that vault's total unsettled debt will be smaller. A value smaller than 0 representing a credit for the vault.
getUnsettledRealizedDebt
is used to calculate Vault::getTotalDebt, which is called in StabilityBranch.getAmountOfAssetOut to calculate the premiumDiscountFactor
.
Because the total debt is reduced (negative) and vault.totalAssets
is smaller, the premiumDiscountFactor
will be artificially inflated. The amountOut
returned by getAmountOfAssetOut
to be artificially inflated.
By calling StabilityBranch::initiateSwap and StabilityBranch::fulfillSwap users can swap usdToken to vault's asset and receive more assets than they should.
Note: There's an issue in getPremiumDiscountFactor
reported in a separate submission that makes this function to return a wrong factor multiplier.
Calling settleVaultsDebt
will swap vault's assets to USDC when the vault is in profit. This allows users to swap usdToken for vault's asset with a premium.
Another instance of the same issue described in first part is in rebalanceVaultAssets
Protocol features doesn't work as intended, allowing usdToken holders to steal funds from the vault.
Update settleVaultsDebt
and rebalanceVaultsAssets
function accordingly:
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.