Account that is affiliated with a plugin can sometimes evade slashing
A malicious staking plugin could revert its notification check to make the slashing call fail, letting an affiliated account avoid being slashed. By timing a pending withdrawal window, the account could withdraw its whole stake before the plugin was removed.
Source: https://github.com/sherlock-audit/2023-02-telcoin-judging/issues/62
Found by
hyh
Summary
Rogue plugin can be a big staker itself or can collide with one and allow such staker to evade slashing in a number of scenarios, i.e. reduce the probability of slashing execution.
Vulnerability Detail
In order to achieve that the plugin can behave otherwise normally in all regards, but on observing staked amount reduction for a specific account it can revert IPlugin(plugin).requiresNotification().
If a given account also partially mitigate the existence of withdrawalDelay > 0 with the periodic renewal of withdrawal requests (without using any, just to have some window available), the overall probability of it to be able to withdraw while plugin is still in the system is noticeable.
This way the overall scenario is:
pluginandaccountcollide and set up the monitoring- SLASHER's slash() for
accountis front-run withplugintx switching its state so it is now reverting onIPlugin(plugin).requiresNotification() - slash() is reverted this way,
pluginswitches to a normal state (it basically sandwiches slashing with two txs, own state change forth and back) - SLASHER investigate with PLUGIN_EDITOR who the reverting plugin is
- Meanwhile withdraw window
accounthas requested beforehand is approaching and if it occurs before PLUGIN_EDITOR removes a plugin (the ability to do so is an another issue, here we suppose it's fixed and plugin is removable) theaccountwill be able to withdraw fully accountexit() executes aspluginis in normal state and doesn't block anything
Impact
account have some chance to evade the slashing, withdrawing the whole stake before slashing can occur.
With the growth of the protocol and increasing of the number of plugins this probability will gradually raise as volatile behavior of a particular plugin can be more tricky to identify which can provide enough time for an account.
The cost of being removed can be bearable for plugin provided that the account stake saved is big enough.
Code Snippet
Plugin can revert the IPlugin(plugin).requiresNotification() call:
/// @dev Calls `notifyStakeChange` on all plugins that require it. This is done in case any given plugin needs to do some stuff when a user exits.
/// @param account Account that is exiting
function _notifyStakeChangeAllPlugins(address account, uint256 amountBefore, uint256 amountAfter) private {
// loop over all plugins
for (uint256 i = 0; i < nPlugins; i++) {
// only notify if the plugin requires
>> if (IPlugin(plugins[i]).requiresNotification()) {
try IPlugin(plugins[i]).notifyStakeChange(account, amountBefore, amountAfter) {}
catch {
emit StakeChangeNotificationFailed(plugins[i]);
}
}
}
}
It will prohibit slashing as slash() calls _claimAndExit() that invokes _notifyStakeChangeAllPlugins():
function slash(address account, uint amount, address to, bytes calldata auxData) external onlyRole(SLASHER_ROLE) nonReentrant {
_claimAndExit(account, amount, to, auxData);
emit Slashed(account, amount);
}
function _claimAndExit(address account, uint256 amount, address to, bytes calldata auxData) private checkpointProtection(account) {
require(amount <= balanceOf(account, auxData), "Account has insufficient balance");
// keep track of initial stake
uint256 oldStake = _stakes[account].latest();
// xClaimed = total amount claimed
uint256 xClaimed = _claim(account, address(this), auxData);
uint256 newStake = oldStake + xClaimed - amount;
// notify all plugins that account's stake has changed (if the plugin requires)
>> _notifyStakeChangeAllPlugins(account, oldStake, newStake);
If there is a withdrawalDelay the account can routinely renew withdrawal requests:
function requestWithdrawal() external {
require(withdrawalDelay > 0, "StakingModule: Withdrawal delay is 0");
require(block.timestamp > withdrawalRequestTimestamps[msg.sender] + withdrawalDelay + withdrawalWindow, "StakingModule: Withdrawal already pending");
withdrawalRequestTimestamps[msg.sender] = block.timestamp;
}
This way there is a chance that account will be able to withdraw while SLASHER locates the reason of blocking and communicate with PLUGIN_EDITOR in order to remove the plugin.
Tool used
Manual Review
Recommendation
Consider adding try-catch to the requiresNotification() call, for example:
/// @dev Calls `notifyStakeChange` on all plugins that require it. This is done in case any given plugin needs to do some stuff when a user exits.
/// @param account Account that is exiting
function _notifyStakeChangeAllPlugins(address account, uint256 amountBefore, uint256 amountAfter) private {
// loop over all plugins
for (uint256 i = 0; i < nPlugins; i++) {
// only notify if the plugin requires
- if (IPlugin(plugins[i]).requiresNotification()) {
+ bool notificationRequired;
+ try IPlugin(plugins[i]).requiresNotification() returns (bool req) { notificationRequired = req; }
+ catch { emit StakeChangeNotificationFailed(plugins[i]); }
+ if (notificationRequired) {
try IPlugin(plugins[i]).notifyStakeChange(account, amountBefore, amountAfter) {}
catch {
emit StakeChangeNotificationFailed(plugins[i]);
}
}
}
}
Discussion
amshirif
https://github.com/telcoin/telcoin-audit/pull/5
dmitriia
Looks ok
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 plugin notification loop calls requiresNotification() without a try-catch, so a reverting plugin aborts the whole slashing transaction.
Impact
The account has some chance to evade slashing and withdraw the whole stake before the penalty can occur, and this chance grows as more plugins join the protocol.
What the attacker needed
A malicious or colluding plugin; an account willing to collude; a pending withdrawal window; withdrawalDelay greater than zero
The fix
The requiresNotification() call should be wrapped in try-catch so a reverting plugin cannot block slashing.
How it was found
- The plugin and account collude and set up monitoring of the account's stake.
- The slasher's slash call for the account is front-run by a plugin transaction that makes it revert on the notification check.
- The slash call reverts, and the plugin switches back to a normal state.
- The slasher investigates with the plugin editor to find the reverting plugin.
- A withdrawal window the account requested earlier arrives before the plugin is removed, allowing a full withdrawal.
- The account's exit executes while the plugin is in its normal state and does not block anything.
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.
Staking lets people lock tokens, and slashing is a penalty that removes some of those tokens when rules are broken. Plugins are helper contracts that get told when a stake changes, and here one of them could deliberately cause an error so the penalty transaction failed. The account working with that plugin could then pull its tokens out before anyone removed the plugin.
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.