There is no mechanism that prevents from minting less than esLBR maximum supply in StakingRewardsV2
The esLBR token has a maximum supply, but the StakingRewardsV2 contract does not prevent the reward rate from causing total minted tokens to exceed that limit. If the maximum supply is reached, users cannot claim their earned rewards because the mint function will revert.
Submitted by bart1e
Lines of code
https://github.com/code-423n4/2023-06-lybra/blob/7b73ef2fbb542b569e182d9abf79be643ca883ee/contracts/lybra/token/esLBR.sol#L30-L32 https://github.com/code-423n4/2023-06-lybra/blob/7b73ef2fbb542b569e182d9abf79be643ca883ee/contracts/lybra/token/esLBR.sol#L20 https://github.com/code-423n4/2023-06-lybra/blob/7b73ef2fbb542b569e182d9abf79be643ca883ee/contracts/lybra/miner/ProtocolRewardsPool.sol#L73-L77
Vulnerability details
I’m assuming that esLBR is distributed as a reward in StakingRewardsV2 - it’s not clear from the docs. But rewardsToken is of type IesLBR and in order to calculate boost for rewards esLBRBoost contract is used, so I think that it’s a reasonable assumption.
The esLBR token has a total supply of 100 000 000 and this is enforced in the esLBR contract:
function mint(address user, uint256 amount) external returns (bool) {
require(configurator.tokenMiner(msg.sender), "not authorized");
require(totalSupply() + amount <= maxSupply, "exceeding the maximum supply quantity.");
However, the StakingRewardsV2 contract which is approved to mint new esLBR tokens doesn’t enforce that new tokens can always be minted.
Either due to admin mistake (it’s possible to call StakingRewardsV2::notifyRewardAmount with arbitrarily high _amount, which is not validated; it’s also possible to set duration to an arbitrarily low value, so rewardRatio may be very high), or by normal protocol functioning, 100 000 000 of esLBR may be finally minted.
If that happens, no user will be able to claim their reward via getReward, since mint will revert. It also won’t be possible to stake esLBR tokens in ProtocolRewardsPool or call any functions that use esLBR.mint underneath.
Impact
Lack of the possibility to stake esLBR is impacting important functionality of the protocol, while no possibility to withdraw earned rewards, this is a loss of assets for users.
From Code4Rena docs:
3 - High: Assets can be stolen/lost/compromised directly (or indirectly if there is a valid attack path that does not have hand-wavy hypotheticals).
Here, assets definitely can be lost. Also, while it could happen because of a misconfiguration by the admin, it can also happen naturally, since esLBR is inflationary and there is no mechanism that enforces the supply being far enough from the max supply. The only thing that could be done to prevent it is that the admin would have to calculate the current supply, analyse the number of stakers, control staking boosts, and set reward ratio accordingly, which is hard to do and error prone. Since assets can be lost and there aren’t any needed external requirements here (and it doesn’t have hand-wavy hypotheticals, in my opinion), I’m submitting this finding as High.
Proof of Concept
Number of reward tokens that users get is calculated here: https://github.com/code-423n4/2023-06-lybra/blob/7b73ef2fbb542b569e182d9abf79be643ca883ee/contracts/lybra/miner/stakerewardV2pool.sol#L106-L108
Users can get their rewards by calling getReward:
https://github.com/code-423n4/2023-06-lybra/blob/7b73ef2fbb542b569e182d9abf79be643ca883ee/contracts/lybra/miner/stakerewardV2pool.sol#L111-L118
There is no mechanism preventing too high rewardRatio when it’s set:
https://github.com/code-423n4/2023-06-lybra/blob/7b73ef2fbb542b569e182d9abf79be643ca883ee/contracts/lybra/miner/stakerewardV2pool.sol#L132-L145
mint will fail on too high supply:
https://github.com/code-423n4/2023-06-lybra/blob/7b73ef2fbb542b569e182d9abf79be643ca883ee/contracts/lybra/token/esLBR.sol#L30-L36
Users won’t be able to claim acquired rewards, which is a loss of assets for them.
Tools Used
VS Code
Recommended Mitigation Steps
Do one of the following:
- Introduce some mechanism that will enforce that esLBR max supply will never be achieved (something similar to Bitcoin halving, for example).
- Do not set esLBR max supply (still do your best to limit it to
100 000 000, but if it goes above that number, users will still be able to claim their acquired rewards).
Assessed type
ERC20
0xean (judge) decreased severity to Low and commented:
This comes down to input sanitization, which is typically awarded as QA.
0xean (judge) increased severity to Medium and commented:
Thought about this one a bit more and since there is a possibility of the inputs being correct, but the emissions exceeding the max supply. M feels like the right severity.
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 StakingRewardsV2 contract lacks a check to ensure that the total supply plus new rewards does not exceed the maximum supply before minting.
Impact
Users could permanently lose earned rewards because they cannot claim them once the maximum supply is reached, and staking esLBR may also be blocked.
What the attacker needed
EsLBR total supply reaches max; admin sets high reward rate or low duration
The fix
The contract should enforce that the maximum supply is never reached, for example by adjusting reward rates or removing the hard cap.
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 token has a hard cap on how many can ever exist. The staking contract pays out rewards in this token but doesn't check if the total would go over the cap. If the cap is hit, the token's mint function stops working, so users can't get their rewards.
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.