Malicious actor can abuse the minimum shares check in StakingLPEth and cause DoS or locked funds for the last user that withdraws
The StakingLPEth contract enforces a minimum total share supply after every deposit and withdrawal, which lets an attacker manipulate the share balance so that the last user cannot withdraw their full amount or new deposits are blocked. An attacker can also donate a small amount of lpEth to the contract before any shares exist, causing subsequent deposits to mint too few shares and revert.
Submitted by web3km, also found by asui, Eeyore, 0xMax1mus, Spearmint, boraichodrunkenmaster, zhaojohnson, peanuts, lian886 (1, 2), Infect3d, yashar, emmac002, Walter, Afriauditor, zhaojie (1, 2), 0xpiken, grearlake, Breeje, 0xAadi, hash, pkqs90, and nnez
Impact
The last user that tries to cooldown/withdraw his share will not be able to withdraw the full deposited amount.
Proof of Concept
The StakingLpEth contract implements a check for minimum shares to ensure that inflation attacks cannot happen:
function _checkMinShares() internal view {
uint256 _totalSupply = totalSupply();
if (_totalSupply > 0 && _totalSupply < MIN_SHARES) revert MinSharesViolation();
}
The _checkMinShares function is called on every deposit/withdrawal to ensure that _totalSupply does not become less than MIN_SHARES:
function _deposit(address caller, address receiver, uint256 assets, uint256 shares) internal override nonReentrant {
super._deposit(caller, receiver, assets, shares);
_checkMinShares();
}
/**
* @dev Withdraw/redeem common workflow.
* @param caller tx sender
* @param receiver where to send assets
* @param _owner where to burn shares from
* @param assets asset amount to transfer out
* @param shares shares to burn
*/
function _withdraw(
address caller,
address receiver,
address _owner,
uint256 assets,
uint256 shares
) internal override nonReentrant {
super._withdraw(caller, receiver, _owner, assets, shares);
_checkMinShares();
}
However, this check opens up a griefing opportunities for attackers to either make sure that the last user that tries to withdraw will only be able to withdraw (his balance - MIN_SHARES) locking the MIN_SHARES with no way of getting them out or completely DoSing the deposit/mint functionality of the vault.
Exploitation Scenarios:
Locking funds for the last user that withdraws/cooldowns:
- User1 mints
1e18shares. - Attacker sees that and backruns him minting only 1 wei shares.
- User1 tries to cooldown/withdraw all of his shares. However after
super._withdrawfunction executes the new_totalSupplywill be equal to 1 which is less thanMIN_SHARES, which will make_checkMinSharesfunction revert. - User2 comes and mints
1e18shares. - Now that User2 deposited User1 will be able to withdraw his shares.
- The cycle repeats of every new user waiting for the next one to deposit in order to withdraw/cooldown full amount, until the last one which will not be able to withdraw full amount leaving
MIN_SHARESamount stuck.
DoS of deposit/mint functionality:
The contract calculates the share the same way as every ERC4626 contract:
function _convertToShares(uint256 assets, Math.Rounding rounding) internal view virtual returns (uint256) {
return assets.mulDiv(totalSupply() + 10 ** _decimalsOffset(), totalAssets() + 1, rounding);
}
Since decimalsOffset() == 0 and totalAssets() will equal to the balance of lpEth in the contract.
The calculation will be:
f(share) = (lpEth * totalSupply + 1) / (totalLpEth() + 1)
- Right after deployment the attacker will transfer 0.01 lpEth to the contract without minting any shares.
- Suppose the next user wants to deposit 1000 lpEth, which is quite a large amount.
- His shares will be calculated as:
(1000e18 * 0 + 1) / (0.01e18 + 1) = $100000
Which is less than MIN_SHARES, which ultimately makes the function revert. The user will have to deposit 100_000_000_000_000 lpEth in order to pass the minimum shares requirement.
Recommended Mitigation Steps
Consider funding the contract in the deployment script and remove the MIN_SHARES check to ensure that no DoS or locking of funds is possible.
Assessed type
Error
0xtj24 (LoopFi) acknowledged and commented:
This behaviour is expected. After deployment of the contracts, the protocol will mint the minimum shares.
Koolex (judge) decreased severity to Medium
Note: For full discussion, see here.
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 minimum shares check is applied after every withdrawal and deposit, combined with a share calculation that can be manipulated by direct token transfers, allowing an attacker to force the total supply below the minimum or make new deposits mint too few shares.
What the attacker needed
Attacker can backrun a deposit transaction; attacker can transfer tokens directly to the contract; victim deposits or withdraws
The fix
The text recommends funding the contract in the deployment script and removing the MIN_SHARES check, though the protocol team stated they will mint the minimum shares after deployment.
How it was found
- User1 mints 1e18 shares.
- Attacker backruns and mints only 1 wei share.
- User1 tries to withdraw all shares but the transaction reverts because total supply would fall below MIN_SHARES.
- User2 mints 1e18 shares, allowing User1 to withdraw.
- The cycle repeats until the last user cannot withdraw the full amount, leaving MIN_SHARES stuck.
- Separately, right after deployment the attacker transfers 0.01 lpEth to the contract without minting shares, causing later deposits to mint too few shares and 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.
This is a staking contract where users deposit tokens and receive shares representing their portion of the pool. The contract has a rule that the total number of shares must never fall below a small minimum. An attacker can exploit this rule to trap the last person who tries to withdraw, or to stop new people from depositing by making the share calculation produce too few shares.
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.