CreditDelegationBranch.rebalanceVaultsAssets
doesn't take DEX swap slippage into consideration when swapping debt vault's collateral asset to credit vault's usdc.
CreditDelegationBranch.rebalanceVaultsAssets
rebalances credit and debt between two vaults by swapping debt vault's collateral asset to USDC and accumulates this to credit vault's depositedUsdc
and marketRealizedDebtUsd
.
The problem is, this swapping is done via DEX like Curve, Uniswap V2/3 that uses CFMM to decide amountOut
, while assetInputNative
is estimated by price ratio.
So tokenOut
will be different than usdDelta
by up to slippageToleranceBps
%
According to the current implementation, total sum of marketRealizedDebtUsd
and total depositedUsdc
remains the same after the rebalancing. Thus, slippage is not accounted anywhere.
The protocol will suffer from DEX swap slippage
Manual Review
Consider the following change:
Why marketsRealizedDebtUsd
is not changed by amountOut
?
Because it's just transferring debt from one vault to another
Why inDebtVault.depositedUsdc
is not changed by amountOut
?
With this fix, after rebalancing, sum of the two vaults' debt remains the same, while sum of depositedUsdc is changed by usdDelta - amountOut
Thus, sum of vaults' totalDebt is changed by usdDelta - amountOut
This effectively delegates slippage to credit vault.
If inDebtVault.depositedUsdc
is also changed by amountOut
, total depositedUsdc
won't be changed, thus silently dropping sloppage
he rebalanceVaultsAssets function in CreditDelegationBranch.sol updates vault accounting using the pre-swap USD value (usdDelta) rather than the actual post-swap USDC amount received. This means slippage is not accounted for, causing accounting misalignment - if there's negative slippage, the credit vault gets credited more USDC than actually received; if there's positive slippage, it gets credited less.
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.