`_withdrawFromPlugin()` will revert when `_withdrawalValues[i] == 0`
The vault's rebalance and plugin removal functions attempt to withdraw zero tokens from a plugin when the withdrawal amount is zero or the plugin balance is zero. This causes a revert in plugins like AaveV2Plugin that reject zero withdrawals, blocking rebalancing and plugin removal.
ctf_sec Follow with hansfriese and WATCHPUG
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2022-10-mycelium-judging/tree/main/013-M
Found by
ctf_sec, hansfriese, WATCHPUG
Summary
Vulnerability Detail
When _withdrawalValues[i] == 0 in rebalancePlugins(), it means NOT to rebalance this plugin.
However, the current implementation still tries to withdraw 0 from the plugin.
This will revert in AaveV2Plugin as Aave V2's validateWithdraw() does not allow 0 withdrawals:
function validateWithdraw(
address reserveAddress,
uint256 amount,
uint256 userBalance,
mapping(address => DataTypes.ReserveData) storage reservesData,
DataTypes.UserConfigurationMap storage userConfig,
mapping(uint256 => address) storage reserves,
uint256 reservesCount,
address oracle
) external view {
require(amount != 0, Errors.VL_INVALID_AMOUNT);
removePlugin() will also always _withdrawFromPlugin() even if the plugin's balance is 0, as it will also tries to withdraw 0 in that case (balance is 0).
Impact
For AaveV2Plugin (and any future plugins that dont allow withdraw 0):
- In every rebalance call, it must at least withdraw 1 wei from the plugin for the rebalance to work.
- The plugin can not be removed or rebalanced when there is no balance in it.
If such a plugin can not deposit for some reason (paused by gov, AaveV2Plugin may face that), this will further cause the whole system unable to be rebalanced until the deposit resumes for that plugin.
Code Snippet
Tool used
Manual Review
Recommendation
Only call _withdrawFromPlugin() when IPlugin(pluginAddr).balance() > 0:
function removePlugin(uint256 _index) external onlyOwner {
require(_index < pluginCount, "Index out of bounds");
address pluginAddr = plugins[_index];
if (IPlugin(pluginAddr).balance() > 0){
_withdrawFromPlugin(pluginAddr, IPlugin(pluginAddr).balance());
}
uint256 pointer = _index;
while (pointer < pluginCount - 1) {
plugins[pointer] = plugins[pointer + 1];
pointer++;
}
delete plugins[pluginCount - 1];
pluginCount--;
IERC20(LINK).approve(pluginAddr, 0);
emit PluginRemoved(pluginAddr);
}
function rebalancePlugins(uint256[] memory _withdrawalValues) external onlyOwner {
require(_withdrawalValues.length == pluginCount, "Invalid withdrawal values");
for (uint256 i = 0; i < pluginCount; i++) {
if (_withdrawalValues[i] > 0)
_withdrawFromPlugin(plugins[i], _withdrawalValues[i]);
}
_distributeToPlugins();
}
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 code unconditionally calls `_withdrawFromPlugin()` even when the withdrawal amount is zero or the plugin balance is zero, without checking if a withdrawal is needed.
Impact
For plugins that do not allow zero withdrawals, every rebalance must withdraw at least 1 wei, and the plugin cannot be removed or rebalanced when its balance is zero; if the plugin cannot deposit (e.g., paused), the whole system cannot be rebalanced until deposits resume.
What the attacker needed
Owner calls rebalance or remove; plugin rejects zero withdrawals
The fix
Only call `_withdrawFromPlugin()` when the plugin's balance is greater than zero, and skip zero withdrawal values in rebalance.
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 vault contract manages funds across several plugins. When the owner wants to rebalance or remove a plugin, the code always calls a withdraw function, even if the amount is zero. Some plugins, like Aave V2, refuse zero withdrawals and cause the whole transaction to fail, so the owner cannot rebalance or remove that plugin.
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.