The StakingPool contract that allows an attacker to exploit rounding errors during the donation process. By leveraging this vulnerability, an attacker can effectively claim a disproportionate amount of shares in the staking pool, thereby preventing legitimate users from earning rewards from their deposits.
The vulnerability stems from the following functions within the StakingRewardsPool contract:
getSharesByStake(uint256 _amount): This function computes the shares that correspond to a given token amount, which performs integer division during its calculation. A rounding error occurs when the total staked tokens are disproportionately increased through a donation, causing new deposits to receive fewer or zero shares due to this imbalance.
getStakeByShares(uint256 _amount): Similarly, it calculates the token amount for a given share count. This rounding effect is exacerbated when the donate function is exploited because it increases the totalStaked without minting equivalent new shares.
An attacker can execute the following sequence to exploit this:
Initiate a minimal deposit that covers the DEAD_SHARES to set an initial position within the pool.
Perform a large token donation to skew the ratio of totalStaked to totalShares.
Subsequent deposits by legitimate users result in zero or minimal shares due to rounding effects, causing them to miss out on rewards.
Legitimate users' deposits become ineffectual because they receive insufficient shares, or No shares.
The attacker, by securing the majority of shares, effectively monopolizes future reward distributions.
Logs
Foundry
Modify the getSharesByStake and getStakeByShares functions to implement more precise calculation methods.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.