A malicious early user/attacker can manipulate the LToken's pricePerShare to take an unfair share of future users' deposits
An early depositor could manipulate the price per share of an LToken by depositing a tiny amount and then inflating the share price, causing later depositors to receive far fewer shares and lose part of their funds. The attacker could profit from these losses.
Source: https://github.com/sherlock-audit/2022-08-sentiment-judging/tree/main/004-H
Found by
kankodu, JohnSmith, PwnPatrol, WATCHPUG, berndartmueller, hyh, __141345__, IllIllI, TomJ
Summary
A well known attack vector for almost all shares based liquidity pool contracts, where an early user can manipulate the price per share and profit from late users' deposits because of the precision loss caused by the rather large value of price per share.
Vulnerability Detail
A malicious early user can deposit() with 1 wei of asset token as the first depositor of the LToken, and get 1 wei of shares.
Then the attacker can send 10000e18 - 1 of asset tokens and inflate the price per share from 1.0000 to an extreme value of 1.0000e22 ( from (1 + 10000e18 - 1) / 1) .
As a result, the future user who deposits 19999e18 will only receive 1 wei (from 19999e18 * 1 / 10000e18) of shares token.
They will immediately lose 9999e18 or half of their deposits if they redeem() right after the deposit().
Impact
The attacker can profit from future users' deposits. While the late users will lose part of their funds to the attacker.
Code Snippet
function deposit(uint256 assets, address receiver) public virtual returns (uint256 shares) {
beforeDeposit(assets, shares);
// Check for rounding error since we round down in previewDeposit.
require((shares = previewDeposit(assets)) != 0, "ZERO_SHARES");
// Need to transfer before minting or ERC777s could reenter.
asset.safeTransferFrom(msg.sender, address(this), assets);
_mint(receiver, shares);
emit Deposit(msg.sender, receiver, assets, shares);
}
function previewDeposit(uint256 assets) public view virtual returns (uint256) {
return convertToShares(assets);
}
function convertToShares(uint256 assets) public view virtual returns (uint256) {
uint256 supply = totalSupply; // Saves an extra SLOAD if totalSupply is non-zero.
return supply == 0 ? assets : assets.mulDivDown(supply, totalAssets());
}
function totalAssets() public view override returns (uint) {
return asset.balanceOf(address(this)) + getBorrows() - getReserves();
}
Tool used
Manual Review
Recommendation
Consider requiring a minimal amount of share tokens to be minted for the first minter, and send a port of the initial mints as a reserve to the DAO so that the pricePerShare can be more resistant to manipulation.
function deposit(uint256 assets, address receiver) public virtual returns (uint256 shares) {
beforeDeposit(assets, shares);
// Check for rounding error since we round down in previewDeposit.
require((shares = previewDeposit(assets)) != 0, "ZERO_SHARES");
// for the first mint, we require the mint amount > (10 ** decimals) / 100
// and send (10 ** decimals) / 1_000_000 of the initial supply as a reserve to DAO
if (totalSupply == 0 && decimals >= 6) {
require(shares > 10 ** (decimals - 2));
uint256 reserveShares = 10 ** (decimals - 6);
_mint(DAO, reserveShares);
shares -= reserveShares;
}
// Need to transfer before minting or ERC777s could reenter.
asset.safeTransferFrom(msg.sender, address(this), assets);
_mint(receiver, shares);
emit Deposit(msg.sender, receiver, assets, shares);
}
function mint(uint256 shares, address receiver) public virtual returns (uint256 assets) {
beforeDeposit(assets, shares);
assets = previewMint(shares); // No need to check for rounding error, previewMint rounds up.
// for the first mint, we require the mint amount > (10 ** decimals) / 100
// and send (10 ** decimals) / 1_000_000 of the initial supply as a reserve to DAO
if (totalSupply == 0 && decimals >= 6) {
require(shares > 10 ** (decimals - 2));
uint256 reserveShares = 10 ** (decimals - 6);
_mint(DAO, reserveShares);
shares -= reserveShares;
}
// Need to transfer before minting or ERC777s could reenter.
asset.safeTransferFrom(msg.sender, address(this), assets);
_mint(receiver, shares);
emit Deposit(msg.sender, receiver, assets, shares);
}
Sentiment Team
Fixed as recommended but instead of sending these shares to the DAO, we burn them. PR here.
Lead Senior Watson
Confirmed fix.
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 rounds down and does not enforce a minimum initial deposit or reserve, allowing the first depositor to set an extreme price per share.
Impact
The attacker can profit from future users' deposits, while late users lose part of their funds to the attacker.
What the attacker needed
Attacker is first depositor; attacker can send large amount of tokens
The fix
The team fixed it as recommended, burning the reserve shares instead of sending them to the DAO.
How it was found
- Attacker deposits 1 wei of asset token as the first depositor and receives 1 wei of shares.
- Attacker sends a large amount of asset tokens to inflate the price per share to an extreme value.
- A future user deposits a large amount but receives only 1 wei of shares due to rounding down.
- The user loses about half of their deposit if they redeem immediately.
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.
This is a 'share price manipulation' bug in a savings pool. The first person to deposit can make each share very expensive by adding a lot of money after a tiny initial deposit, so later depositors get almost no shares for their money and lose value.
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.