Attacker can manipulate the pricePerShare to profit from future users' deposits
The vault's share price can be inflated by an early depositor, causing later depositors to receive zero shares due to rounding down. An attacker can profit from future deposits by manipulating the price per share.
Source: https://github.com/sherlock-audit/2022-10-mycelium-judging/tree/main/001-H
Found by
Ruhum, ctf_sec, cccz, joestakey, ellahi, __141345__, 8olidity, hansfriese, minhquanym, 0x52, caventa, rvierdiiev, Sm4rty, rbserver, IllIllI, sorrynotsorry, JohnSmith, defsec, WATCHPUG, berndartmueller, ak1
Summary
By manipulating and inflating the pricePerShare to a super high value, the attacker can cause all future depositors to lose a significant portion of their deposits to the attacker due to precision loss.
Vulnerability Detail
A malicious early user can deposit() with 1 wei of LINK token as the first depositor of the Vault, and get (1 * STARTING_SHARES_PER_LINK) wei of shares.
Then the attacker can send STARTING_SHARES_PER_LINK - 1 of LINK tokens and inflate the price per share from 1 / STARTING_SHARES_PER_LINK to 1.0000 .
Then the attacker call withdraw() to withdraw STARTING_SHARES_PER_LINK - 1 shares, and send 1e22 of LINK token and inflate the price per share from 1.000 to 1.000e22.
As a result, the future user who deposits 9999e18 will only receive 0 (from 9999e18 * 1 / 10000e18) of shares token.
They will immediately lose all of their deposits.
Impact
Users may suffer a significant portion or even 100% of the funds they deposited to the Vault.
Code Snippet
https://github.com/sherlock-audit/2022-10-mycelium/blob/main/mylink-contracts/src/Vault.sol#L131-142
function deposit(uint256 _amount) external {
require(_amount > 0, "Amount must be greater than 0");
require(_amount <= availableForDeposit(), "Amount exceeds available capacity");
uint256 newShares = convertToShares(_amount);
_mintShares(msg.sender, newShares);
IERC20(LINK).transferFrom(msg.sender, address(this), _amount);
_distributeToPlugins();
emit Deposit(msg.sender, _amount);
}
function convertToShares(uint256 _tokens) public view returns (uint256) {
uint256 tokenSupply = totalSupply(); // saves one SLOAD
if (tokenSupply == 0) {
return _tokens * STARTING_SHARES_PER_LINK;
}
return _tokens.mulDivDown(totalShares, tokenSupply);
}
Tool used
Manual Review
Recommendation
Consider requiring a minimal amount of share tokens to be minted for the first minter, and send part of the initial mints as a permanent reserve to the DAO/treasury/deployer so that the pricePerShare can be more resistant to manipulation.
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 share calculation uses integer division that rounds down, and the first depositor can manipulate the share price by donating tokens directly to the vault.
Impact
Future depositors could lose a significant portion or even all of their deposited funds.
What the attacker needed
Attacker is first depositor; attacker has LINK tokens
The fix
The vault should require a minimum initial share mint and allocate part of the initial shares to a permanent reserve to make the share price more resistant to manipulation.
How it was found
- Attacker deposits 1 wei of LINK as the first depositor and receives shares.
- Attacker sends LINK tokens directly to the vault to inflate the price per share.
- Attacker withdraws some shares to further manipulate the price.
- Attacker sends a large amount of LINK to inflate the price per share to a very high value.
- A future user deposits a large amount of LINK but receives zero shares due to rounding down.
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 lets people deposit tokens and get shares in return. The number of shares you get depends on the current price per share. An attacker can make the price per share extremely high by being the first depositor and then donating tokens, so when someone else deposits, the calculation rounds down to zero shares, and they lose their deposit.
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.