Setting dsId to an expired DS will lead to the reversal of the FlashSwapRouter.swapDsforRa() function
Summary
There is an exchange of CT + DS to RA during the DS selling process. This exchange can only be performed with the currently activated DS. Therefore, setting dsId to an expired DS will lead to the reversal of the selling.
Vulnerability Detail
The FlashSwapRouter.swapDsforRa() function has a parameter dsId (line 251) that represents the selling DS.
The function __afterFlashswapSell() is invoked during the selling process. As you can see at line 394, it exchanges CT + DS for RA. This exchange can only be performed with the currently activated DS, as indicated in the PsmLib.redeemRaWithCtDs() function. As a result, setting dsId to an expired DS will lead to the reversal of the transaction.
function __afterFlashswapSell(
ReserveState storage self,
uint256 ctAmount,
Id reserveId,
uint256 dsId,
address caller,
uint256 raAttributed
) internal {
AssetPair storage assetPair = self.ds[dsId];
assetPair.ds.approve(owner(), ctAmount);
assetPair.ct.approve(owner(), ctAmount);
IPSMcore psm = IPSMcore(owner());
394 (uint256 received,) = psm.redeemRaWithCtDs(reserveId, ctAmount);
// for rounding error and to satisfy uni v2 liquidity rules(it forces us to repay 1 wei higher to prevent liquidity stealing)
uint256 repaymentAmount = received - raAttributed;
Asset ra = assetPair.ra;
assert(repaymentAmount + raAttributed >= received);
// send caller their RA
IERC20(ra).safeTransfer(caller, raAttributed);
// repay flash loan
IERC20(ra).safeTransfer(msg.sender, repaymentAmount);
}
KupiaSec
Medium
Setting
dsId
to an expiredDS
will lead to the reversal of theFlashSwapRouter.swapDsforRa()
functionSummary
There is an exchange of
CT + DS
toRA
during theDS
selling process. This exchange can only be performed with the currently activatedDS
. Therefore, settingdsId
to an expiredDS
will lead to the reversal of the selling.Vulnerability Detail
The
FlashSwapRouter.swapDsforRa()
function has a parameterdsId
(line 251) that represents the sellingDS
.The function
__afterFlashswapSell()
is invoked during the selling process. As you can see at line 394, it exchangesCT + DS
forRA
. This exchange can only be performed with the currently activatedDS
, as indicated in the PsmLib.redeemRaWithCtDs() function. As a result, settingdsId
to an expiredDS
will lead to the reversal of the transaction.Impact
Selling
DS
could be reverted.Code Snippet
https://github.com/sherlock-audit/2024-08-cork-protocol/tree/main/Depeg-swap/contracts/core/flash-swaps/FlashSwapRouter.sol#L249-L265
https://github.com/sherlock-audit/2024-08-cork-protocol/tree/main/Depeg-swap/contracts/core/flash-swaps/FlashSwapRouter.sol#L357-L378
Tool used
Manual Review
Recommendation
Don't include the parameter
dsId
.