Lack of sanity checks for new plugin address in `addPlugin()`
The addPlugin() function in a vault contract did not validate the address of a new plugin, so an incorrect or duplicate address could be registered. This could break deposit and withdraw functions, or cause the vault to double-count a plugin's balance, giving depositors too few shares and withdrawers too many tokens.
Source: https://github.com/sherlock-audit/2022-10-mycelium-judging/tree/main/010-M
Found by
Ruhum, ctf_sec, bin2chen, hansfriese, 0x52, dipp, berndartmueller, WATCHPUG
Summary
Without sanity checks for new plugin address in addPlugin(), wrong address or duplicated address can be added.
Vulnerability Detail
When adding a new plugin, there are no sanity checks for the new plugin's address.
However, adding a wrong address or duplicated address can cause severe damage to the users, and it may be irreversible:
When the new plugin is not a correct contract, removePlugin() will revert at IPlugin(_plugin).withdraw(_amount);.
Impact
When a wrong address is added as a plugin, many essential features of the Vault contract will malfunction, including deposit() and withdraw(), as totalSupply() will revert at IPlugin(plugins[i]).balance().
When an existing plugin is wrongfully added as a new plugin, the totalSupply() will double count the balance of that plugin, which makes the user who deposits receives fewer shares and the users who withdraw, receives more tokens.
Code Snippet
Tool used
Manual Review
Recommendation
- Add a check to ensure
_plugin.Vault == address(this), which will first ensure the plugin address is a valid contract with Vault interface, and it's set to the correct vault address. - Add a check to ensure
_pluginis new (not an existing one).
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 addPlugin() function lacked validation that the supplied address is a valid plugin contract bound to this vault and is not already registered.
Impact
A wrong address makes deposit and withdraw malfunction because totalSupply() reverts, and a duplicated plugin makes totalSupply() double count its balance, so depositors receive fewer shares and withdrawers receive more tokens; the text says this may be irreversible.
What the attacker needed
Ability to call addPlugin(); plugin address is wrong or duplicated
The fix
The addPlugin() function should check that the plugin's Vault equals this contract's address and that the plugin is not already registered.
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 lets users deposit tokens and later withdraw them, and it tracks balances through helper contracts called plugins. The function that registers a plugin never checked that the address really was a valid plugin or that it was not already registered. Adding a bad or repeated address could then break the vault's accounting, so some users get too few shares and others get too many.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.