WAuraPools will irreversibly break if reward tokens are added to pool after deposit
WAuraPools stores reward-per-share values in an array sized to the number of reward tokens at deposit time. If a new reward token is added later, the code reads an out-of-bounds index, causing a revert that breaks pendingRewards and liquidations.
Source: https://github.com/sherlock-audit/2023-04-blueberry-judging/issues/127
Found by
0x52, Ch_301
Summary
WAuraPools will irreversibly break if reward tokens are added to pool after deposit due to an OOB error on accExtPerShare.
Vulnerability Detail
uint extraRewardsCount = IAuraRewarder(crvRewarder)
.extraRewardsLength(); <- @audit-issue rewardTokenCount pulled fresh
tokens = new address[](extraRewardsCount + 1);
rewards = new uint256[](extraRewardsCount + 1);
tokens[0] = IAuraRewarder(crvRewarder).rewardToken();
rewards[0] = _getPendingReward(
stCrvPerShare,
crvRewarder,
amount,
lpDecimals
);
for (uint i = 0; i < extraRewardsCount; i++) {
address rewarder = IAuraRewarder(crvRewarder).extraRewards(i);
@audit-issue attempts to pull from array which will be too small if tokens are added
uint256 stRewardPerShare = accExtPerShare[tokenId][i];
tokens[i + 1] = IAuraRewarder(rewarder).rewardToken();
rewards[i + 1] = _getPendingReward(
stRewardPerShare,
rewarder,
amount,
lpDecimals
);
}
accExtPerShare stores the current rewardPerToken when the position is first created. It stores it as an array and only stores values for reward tokens that have been added prior to minting. This creates an issue if a reward token is added because now it will attempt to pull a value for an index that doesn't exist and throw an OOB error.
This is problematic because pendingRewards is called every single transaction via the isLiquidatable subcall in BlueBerryBank#execute.
Impact
WAuraPools will irreversibly break if reward tokens are added to pool after
Code Snippet
Tool used
Manual Review
Recommendation
Use a mapping rather than an array to store values
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 reward-per-share values are stored in a fixed-size array indexed by reward token position, so adding a reward token later makes the index exceed the stored length.
Impact
The contract irreversibly breaks because pendingRewards is called on every transaction, so liquidations and other operations that depend on it will fail.
What the attacker needed
Reward token added after deposit
The fix
The values should be stored in a mapping keyed by reward token rather than an array, so new tokens do not cause out-of-bounds reads.
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 smart contract keeps track of rewards for each deposit using a list. If the list grows after a deposit, the contract tries to read a slot that was never created, which makes it crash. Because this check runs on every transaction, the whole contract becomes unusable.
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.