Submitted by rbserver, also found by MrValioBg and Shaheen
According to https://github.com/code-423n4/2024-07-karak?tab=readme-ov-file#stakers, Stakers can initiate a withdrawal, subject to a ``MIN_WITHDRAW_DELAY`` of 9 days, and DSS can slash any malicious behavior occurring before the withdrawal initiation for up to 7 days. Since MIN_WITHDRAW_DELAY equals SLASHING_WINDOW + SLASHING_VETO_WINDOW, the stakers withdrawal should be safe without being associated with any malicious behavior and hence not slashable when the DSS does not request any slashing against the corresponding vault within the SLASHING_WINDOW of 7 days after such withdrawal is initiated.
https://github.com/code-423n4/2024-07-karak/blob/d19a4de35bcaf31ccec8bccd36e2d26594d05aad/src/interfaces/Constants.sol#L13-L16
During the 2 day period after the SLASHING_WINDOW of 7 days is passed after the stakers withdrawal is initiated, such as when just couple minutes are passed after such SLASHING_WINDOW is reached, the stakers withdrawal cannot be finished but a malicious behavior can occur and the DSS can make a slashing request against the corresponding vault; in this situation, the stakers withdrawal mentioned previously should not be subject to such slashing though. At that time, when the DSS calls the Core.requestSlashing function, which further calls the SlasherLib.requestSlashing and SlasherLib.fetchEarmarkedStakes functions, the token amount to be slashed is calculated as the DSSs allowed slashing percentage of the vaults totalAssets(), which includes the token amount corresponding to the stakers withdrawal. Because the stakers withdrawal should not be slashable, the token amount to be slashed actually should be the DSSs allowed slashing percentage of a value that equals the vaults totalAssets() minus the token amount corresponding to the stakers withdrawal. Thus, the DSS can unfairly slash more underlying token amount from the vault than it should be allowed.
https://github.com/code-423n4/2024-07-karak/blob/d19a4de35bcaf31ccec8bccd36e2d26594d05aad/src/entities/SlasherLib.sol#L94-L124
https://github.com/code-423n4/2024-07-karak/blob/d19a4de35bcaf31ccec8bccd36e2d26594d05aad/src/entities/SlasherLib.sol#L79-L92
Moreover, when the MIN_WITHDRAW_DELAY of 9 days is passed after the stakers withdrawal is initiated, the staker can call the Vault.finishRedeem function for finishing his withdrawal request. Since SLASHING_VETO_WINDOW is 2 days, the DSS can call the Core.finalizeSlashing function for finalizing its slashing request just after the MIN_WITHDRAW_DELAY of 9 days is passed after the initiation of the stakers withdrawal if the DSSs slashing request was made when just couple minutes were passed after the SLASHING_WINDOW for such withdrawal of the staker was reached. Because both the stakers Vault.finishRedeem transaction and the DSSs Core.finalizeSlashing transaction are sent at the similar time, a malicious miner can place and execute the DSSs Core.finalizeSlashing transaction before the stakers Vault.finishRedeem transaction. In this case, the stakers withdrawal can be unfairly slashed by the DSS even though it should not be slashed.
https://github.com/code-423n4/2024-07-karak/blob/53eb78ebda718d752023db4faff4ab1567327db4/src/Vault.sol#L157-L188
https://github.com/code-423n4/2024-07-karak/blob/d19a4de35bcaf31ccec8bccd36e2d26594d05aad/src/entities/VaultLib.sol#L24-L38
https://github.com/code-423n4/2024-07-karak/blob/53eb78ebda718d752023db4faff4ab1567327db4/src/Core.sol#L248-L256
https://github.com/code-423n4/2024-07-karak/blob/d19a4de35bcaf31ccec8bccd36e2d26594d05aad/src/entities/SlasherLib.sol#L126-L151
The following steps can occur for the first described scenario where the DSS unfairly slashes more underlying token amount from the vault than it should be allowed.
The following steps can occur for the second described scenario where the stakers withdrawal can be unfairly slashed by the DSS even though it should not be slashed.
One way to mitigate this issue is to update the Vault.finishRedeem function to allow the stakers withdrawal to be finished after the SLASHING_WINDOW of 7 days is passed after such withdrawal is initiated if the DSS does not request any slashing against the corresponding vault within such SLASHING_WINDOW and only enforce the MIN_WITHDRAW_DELAY of 9 days on the withdrawal if the DSS has requested to slash the corresponding vault within such SLASHING_WINDOW.
devdks25 (Karak) commented:
dewpe (Karak) commented:
devdks25 (Karak) disputed
MiloTruck (judge) decreased severity to Medium and commented:
devdks25 (Karak) commented:
devdks25 (Karak) commented:
Karak mitigated:
Status: Mitigation confirmed. Full details in reports from 0xCiphky, KupiaSec and sl1.
