First user can inflate `pointsPerShare` and cause `_correctPoints()` to revert due to overflow
The first user to deposit can manipulate the pointsPerShare value to an extremely large number by depositing a tiny amount and then distributing rewards. Later, when other users deposit or withdraw, the multiplication in _correctPoints() overflows, causing transactions to revert and locking funds.
Source: https://github.com/sherlock-audit/2022-10-merit-circle-judging/issues/103
Found by
WATCHPUG, bin2chen
Summary
pointsPerShare can be manipulated by the first user and cause _correctPoints() to revert later.
Vulnerability Detail
POINTS_MULTIPLIER is an unusually large number as a precision fix for pointsPerShare: type(uint128).max ~= 3.4e38.
This makes it possible for the first user to manipulate the pointsPerShare to near type(int256).max and a later regular user can trigger the overflow of _shares * _shares * in _correctPoints().
PoC
deposit(1 wei)lock for 10 mins,mint()1 wei of shares;distributeRewards(1000e18),pointsPerShare += 1000e18 * type(uint128).max / 1== 3e59;- the victim
deposit(100e18)for 1 year,mint()150e18 shares; _shares * pointsPerShare == -150e18 * 3e59 == -4.5e+79which exceedstype(int256).min, thus the transaction will revert.
The attacker can also manipulate pointsPerShare to a slightly smaller number, so that _shares * pointsPerShare will only overflow after a certain amount of deposits.
Impact
By manipulating the pointPerShare precisely, the attacker can make it possible for the system to run normally for a little while and only to explode after a certain amount of deposits, as the pointsPerShare will be too large by then and all the _mint and _burn will revert due to overflow in _correctPoints().
The users who deposited before will be unable to withdraw their funds.
Code Snippet
Tool used
Manual Review
Recommendation
- Add a minimal mint amount requirement for the first minter and send a portion of the initial shares to gov as a permanent reserve to avoid
pointPerSharemanipulating. - Use a smaller number for
POINTS_MULTIPLIER, eg,1e12.
Discussion
federava
Agree with the recommendation. Requiring a minimal amount for first minter/minting on deployment by governance should be enough to prevent the described manipulation.
federava
PR from this issue
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 lack of a minimum initial deposit and the use of an excessively large POINTS_MULTIPLIER allow the first depositor to inflate pointsPerShare to a value that causes overflow in later calculations.
Impact
The attacker can cause all future _mint and _burn operations to revert, preventing users who deposited before from withdrawing their funds.
What the attacker needed
Attacker is the first depositor; attacker can call distributeRewards
The fix
The project added a minimum mint amount for the first minter and sent a portion of initial shares to governance as a permanent reserve, and also recommended using a smaller POINTS_MULTIPLIER.
How it was found
- Attacker deposits 1 wei and locks for 10 minutes, minting 1 wei of shares.
- Attacker calls distributeRewards with a large amount, causing pointsPerShare to become extremely large.
- Victim deposits a larger amount for 1 year, minting many shares.
- The multiplication _shares * pointsPerShare overflows, causing the transaction to revert.
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.
In a rewards system, pointsPerShare tracks how many reward points each share earns. The first person to join can set this number very high by depositing a tiny amount and then adding a large reward. Later, when someone else tries to deposit or withdraw, the maths overflows and the transaction fails, so their money gets stuck.
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.