Skip to content
DoS Audit finding Intermediate

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.

WatchPug Follow with bin2chen

Originally disclosed on Sherlock

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

  1. deposit(1 wei) lock for 10 mins, mint() 1 wei of shares;
  2. distributeRewards(1000e18), pointsPerShare += 1000e18 * type(uint128).max / 1 == 3e59;
  3. the victim deposit(100e18) for 1 year, mint() 150e18 shares;
  4. _shares * pointsPerShare == -150e18 * 3e59 == -4.5e+79 which exceeds type(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

https://github.com/sherlock-audit/2022-10-merit-circle/blob/main/merit-liquidity-mining/contracts/base/AbstractRewards.sol#L89-L99

https://github.com/sherlock-audit/2022-10-merit-circle/blob/main/merit-liquidity-mining/contracts/base/BasePool.sol#L80-L88

https://github.com/sherlock-audit/2022-10-merit-circle/blob/main/merit-liquidity-mining/contracts/base/AbstractRewards.sol#L125-L127

Tool used

Manual Review

Recommendation

  1. 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 pointPerShare manipulating.
  2. 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

The original report as published on Sherlock, by WATCHPUG. 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 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

  1. Attacker deposits 1 wei and locks for 10 minutes, minting 1 wei of shares.
  2. Attacker calls distributeRewards with a large amount, causing pointsPerShare to become extremely large.
  3. Victim deposits a larger amount for 1 year, minting many shares.
  4. 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.

More by WatchPug

View all

197 more disclosed reports, best first.

More from Merit Circle

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.