Rogue plugin can become unremovable and halt all staking and claiming
A malicious plugin could prevent its own removal by always returning false from deactivated(), and could also cause arithmetic overflow or revert calls, halting all staking and claiming operations. This would permanently freeze all staked funds.
Source: https://github.com/sherlock-audit/2023-02-telcoin-judging/issues/67
Found by
hyh
Summary
StakingModule's plugin that turned rogue can deny any attempts of its removal and can effectively stop the contract, disturbing the whole range of StakingModule operations.
I.e. if any plugin turns malicious due to bug or upgrade altering its functionality vs one that was in place as of the time of its addition to StakingModule, such malicious plugin can halt StakingModule and freeze all the funds staked.
Vulnerability Detail
The reason is removePlugins() having require(IPlugin(plugin).deactivated()) condition, which success is required.
Suppose that a plugin turned malicious (as a result of a bug or by owner's intent via upgrade), begin to permanently return false for the deactivated() call.
And, for instance, it can simultaneously return 2**256-1 in claim() to overflow the sum and revert the IPlugin(plugin).requiresNotification() calls.
Impact
As all StakingModule operations will be frozen and funds withdrawal be unavailable in this scenario it will be permanent freeze of funds for all the stakers.
Code Snippet
If a plugin turns rogue:
It can return 2**256-1 in claim() to overflow the sum:
function _claim(address account, address to, bytes calldata auxData) private returns (uint256) {
// balance of `to` before claiming
uint256 balBefore = IERC20Upgradeable(tel).balanceOf(to);
// call claim on all plugins and count the total amount claimed
uint256 total;
bytes[] memory parsedAuxData = parseAuxData(auxData);
for (uint256 i = 0; i < nPlugins; i++) {
>> try IPlugin(plugins[i]).claim(account, to, parsedAuxData[i]) returns (uint256 xClaimed) {
total += xClaimed;
} catch {
emit PluginClaimFailed(plugins[i]);
}
}
This will block slash(), claim(), fullClaimAndExit(), partialClaimAndExit() functions.
Also, it 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 also block stake(), partialExit(), exit(), and migration claimAndExitFor(), stakeFor() functions.
As all involve _notifyStakeChangeAllPlugins(), for example:
function claimAndExitFor(address account, address to, bytes calldata auxData) external onlyRole(MIGRATOR_ROLE) nonReentrant returns (uint256, uint256) {
>> return (_claim(account, to, auxData), _exit(account, to));
}
function _exit(address account, address to) private returns (uint256) {
uint256 stakedAmt = _stakes[account].latest();
>> _partialExit(account, to, stakedAmt);
return stakedAmt;
}
function _partialExit(address account, address to, uint256 exitAmount) private checkpointProtection(account) {
if (exitAmount == 0) {
return;
}
uint256 stakedAmt = _stakes[account].latest();
require(stakedAmt >= exitAmount, "StakingMoudle: Cannot exit more than is staked");
// notify plugins
>> _notifyStakeChangeAllPlugins(account, stakedAmt, stakedAmt - exitAmount);
Tool used
Manual Review
Recommendation
Consider adding force option to removePlugin(), for example:
/// @notice Removes a plugin
- function removePlugin(uint256 index) external onlyRole(PLUGIN_EDITOR_ROLE) {
+ function removePlugin(uint256 index, bool force) external onlyRole(PLUGIN_EDITOR_ROLE) {
address plugin = plugins[index];
- require(IPlugin(plugin).deactivated(), "StakingModule::removePlugin: Plugin is not deactivated");
+ require(force || IPlugin(plugin).deactivated(), "StakingModule::removePlugin: Plugin is not deactivated");
pluginsMapping[plugin] = false;
plugins[index] = plugins[nPlugins - 1];
pluginIndicies[plugins[index]] = index;
plugins.pop();
nPlugins--;
emit PluginRemoved(plugin, nPlugins);
}
Discussion
dmitriia
Looks ok
jacksanford1
Admin note: This is the PR that was created and signed off on: https://github.com/telcoin/telcoin-audit/pull/10
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
The removePlugin function requires the plugin to report itself as deactivated, which a malicious plugin can simply refuse to do, and the main contract does not handle plugin failures gracefully in all cases.
Impact
All staking operations, including withdrawals, could be permanently frozen for all stakers.
What the attacker needed
A plugin becomes malicious; plugin is added to StakingModule
The fix
The removePlugin function should be modified to allow a forced removal that bypasses the deactivated check.
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.
A plugin is a separate contract that adds features to the main staking contract. The main contract trusts plugins to behave correctly. If a plugin turns malicious, it can refuse to be removed and can break the main contract's functions, locking everyone's funds.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.