Skip to content
Smart contracts Audit finding Intermediate

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.

Ruhum Follow with ctf_sec, bin2chen and 5 others

Originally disclosed on Sherlock

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

https://github.com/sherlock-audit/2022-10-mycelium/blob/main/mylink-contracts/src/Vault.sol#L314-L329

Tool used

Manual Review

Recommendation

  1. 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.
  2. Add a check to ensure _plugin is new (not an existing one).

The original report as published on Sherlock, by Ruhum. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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.

More by Ruhum

View all

55 more disclosed reports, best first.

More from Mycelium

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.