The DsFlashSwap.emptyReserve() function incorrectly always returns 0
Summary
The DsFlashSwap.emptyReserve() function incorrectly returns 0 instead of the original reserve amount. This leads to erroneous behavior within the VaultLib._liquidatedLp() function, which relies on the DsFlashSwap.emptyReserve() function, as it should utilize the original reserve amount.
Vulnerability Detail
As noted at line 77, the DsFlashSwap.emptyReservePartial() function returns the remaining reserve amount, not the removed amount. Consequently, the DsFlashSwap.emptyReserve() function always returns 0 (see line 67), as it removes the entire reserve amount. This, in turn, causes the FlashSwapRouter.emptyReserve() function to also return 0, since it calls the DsFlashSwap.emptyReserve() function at line 70.
This results in incorrect behavior within the VaultLib._liquidatedLp() function.
For instance, at line 374 of the VaultLib._liquidatedLp() function, the value of reservedDs is always 0 because the flashSwapRouter.emptyReserve() function consistently returns 0. This impacts redeemAmount, making it always 0 (see line 376), which leads to incomplete redemption of RA. Consequently, users will incur a loss of RA.
KupiaSec
High
The
DsFlashSwap.emptyReserve()
function incorrectly always returns 0Summary
The
DsFlashSwap.emptyReserve()
function incorrectly returns 0 instead of the original reserve amount. This leads to erroneous behavior within theVaultLib._liquidatedLp()
function, which relies on theDsFlashSwap.emptyReserve()
function, as it should utilize the original reserve amount.Vulnerability Detail
As noted at line 77, the
DsFlashSwap.emptyReservePartial()
function returns the remaining reserve amount, not the removed amount. Consequently, theDsFlashSwap.emptyReserve()
function always returns 0 (see line 67), as it removes the entire reserve amount. This, in turn, causes theFlashSwapRouter.emptyReserve()
function to also return 0, since it calls theDsFlashSwap.emptyReserve()
function at line 70.This results in incorrect behavior within the
VaultLib._liquidatedLp()
function.For instance, at line 374 of the
VaultLib._liquidatedLp()
function, the value ofreservedDs
is always 0 because theflashSwapRouter.emptyReserve()
function consistently returns 0. This impactsredeemAmount
, making it always 0 (see line 376), which leads to incomplete redemption ofRA
. Consequently, users will incur a loss ofRA
.Impact
Leading to incomplete redemption of
RA
when processing expired states, resulting in a loss ofRA
for users.Code Snippet
https://github.com/sherlock-audit/2024-08-cork-protocol/tree/main/Depeg-swap/contracts/libraries/DsFlashSwap.sol#L66-L78
https://github.com/sherlock-audit/2024-08-cork-protocol/tree/main/Depeg-swap/contracts/core/flash-swaps/FlashSwapRouter.sol#L69-L72
https://github.com/sherlock-audit/2024-08-cork-protocol/tree/main/Depeg-swap/contracts/libraries/VaultLib.sol#L349-L393
Tool used
Manual Review
Recommendation
Make the following fixes.
Duplicate of #68