Violation of Invariant Allowing DSSs to Slash Unregistered Operators
The Karak protocol allowed a DSS to finalize a slashing request on an operator even after the operator had unregistered from that DSS, breaking the invariant that only registered DSSs can slash an operator. An attacker (the DSS) could slash an operator who had already unstaked and unregistered, potentially causing loss to new depositors unaware of the pending slash.
0xCiphky Follow with 20centclub and KupiaSec
Originally disclosed on Code4rena
Submitted by 0xCiphky, also found by 20centclub and KupiaSec
Operators select DSSs to allocate their funds to, and for each DSS, they can choose a list of vaults to stake. The selected vaults are fully staked to the chosen DSS.
To unstake, the operator must adhere to a MIN_STAKE_UPDATE_DELAY of 9 days, which prevents front-running a slashing event. An operator can fully unregister from a DSS once all the vaults are unstaked. The DSS has the ability to slash any malicious behaviour that occurred before the withdrawal initiation for up to 7 days.
The problem is, the current implementation breaks one of the main invariants (confirmed by sponsors).
Consider the following scenario:
- Operator calls the requestUpdateVaultStakeInDSS function to unstake Vault 1 from DSS, initiating the 9-day
MIN_STAKE_UPDATE_DELAY. - After 8 days, the DSS calls the requestSlashing function on Operator’s Vault 1, starting the 2-day
SLASHING_VETO_WINDOW. - After 1 day, the operator calls the finalizeUnstaking function to finalize unstaking Vault 1 from DSS and the unregisterOperatorFromDSS function to unregister from DSS.
- After another day, the DSS (or anyone) calls the finalizeSlashing function to finalize the slash on the operator, who is no longer registered with the DSS.
Proof Of Concept
function test_slash_unregistered_operator() public {
// register operator to dss, deploy vaults, stake vaults to dss
stake_vaults_to_dss();
// check if operator is registered to dss
assertEq(true, core.isOperatorRegisteredToDSS(operator, dss));
// unstake vaults from dss
address[] memory operatorVaults = core.fetchVaultsStakedInDSS(operator, dss);
Operator.StakeUpdateRequest memory stakeUpdate =
Operator.StakeUpdateRequest({vault: operatorVaults[0], dss: dss, toStake: false});
Operator.StakeUpdateRequest memory stakeUpdate2 =
Operator.StakeUpdateRequest({vault: operatorVaults[1], dss: dss, toStake: false});
vm.startPrank(operator);
Operator.QueuedStakeUpdate memory queuedStakeUpdate = core.requestUpdateVaultStakeInDSS(stakeUpdate);
Operator.QueuedStakeUpdate memory queuedStakeUpdate2 = core.requestUpdateVaultStakeInDSS(stakeUpdate2);
vm.stopPrank();
skip(8 days);
// dss request slashing
uint96[] memory slashPercentagesWad = new uint96[](2);
slashPercentagesWad[0] = uint96(10e18);
slashPercentagesWad[1] = uint96(10e18);
SlasherLib.SlashRequest memory slashingReq = SlasherLib.SlashRequest({
operator: operator,
slashPercentagesWad: slashPercentagesWad,
vaults: operatorVaults
});
vm.startPrank(address(dss));
SlasherLib.QueuedSlashing memory queuedSlashing = core.requestSlashing(slashingReq);
vm.stopPrank();
skip(1 days);
vm.startPrank(operator);
// finalize unstake and unregister operator from dss
core.finalizeUpdateVaultStakeInDSS(queuedStakeUpdate);
core.finalizeUpdateVaultStakeInDSS(queuedStakeUpdate2);
core.unregisterOperatorFromDSS(dss, "");
vm.stopPrank();
skip(1 days);
// check if operator is unregistered from dss
assertEq(false, core.isOperatorRegisteredToDSS(operator, dss));
// finalize slashing on unregistered operator
core.finalizeSlashing(queuedSlashing);
}
Impact
The current implementation allows a DSS to finalize a slash on an operator even after the operator has unregistered from the DSS. This breaks the intended invariant that only DSSs an operator is registered with can slash that operator.
Additionally, new users depositing into the DSS may be unaware of the pending slash because the operator is no longer registered with the DSS, leading to a potential loss on deposits.
Tools Used
- Manual analysis
- Foundry
Recommendation
Consider implementing a check to prevent operators from unregistering from a DSS that has pending slashing requests on them. This will ensure that all slashing actions are finalized before an operator can fully unregister, thereby maintaining the intended invariant/design.
This issue demonstrates how if
requestSlashing()was called in the last 2 days of a vault unstake request (ie. duringSLASHING_VETO_WINDOW),finalizeSlashing()can be called on a vault even after its operator has unregistered the DSS withunregisterOperatorFromDSS().Given that this breaks one of the main invariants stated in the README, I believe high severity is appropriate.
Fixed.
There have been comments that this should be downgraded as the veto committee has the ability to stop it, but I disagree. Following this reasoning, all issues related to slashing can be downgraded to QA since the veto committee can simply stop all slashings-related bugs.
It’s not clear when the veto committee will overturn a slashing and for what reasons, as such, we cannot assume this will be stopped by the committee. I think a fair assumption to make is the committee will overturn any slashings that are outright malicious, which isn’t the case here.
This remains as high.
This mitigation validates the operator, vaults status in the finalizing slashing.
Status: Mitigation confirmed. Full details in reports from sl1 and 0xCiphky.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the unregister function does not check for pending slashing requests, allowing an operator to unregister while a slash is still in its veto window.
Impact
A DSS could slash an operator after they have unregistered, breaking the stated invariant and potentially causing losses to new depositors who are unaware of the pending slash.
What the attacker needed
Operator registered with a DSS; operator unstakes and unregisters; DSS requests slashing during veto window
The fix
The protocol was fixed by validating the operator and vault status when finalizing a slashing.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
In this staking system, operators put funds into vaults for DSSs (services). If an operator misbehaves, the DSS can slash (penalise) their funds. The rule is that only a DSS the operator is currently registered with can slash them. This report shows that an operator could unregister before a pending slash was finalised, yet the slash still went through, breaking that rule.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.