RewardDistributor claims can be DoSed through e
A malicious user can permanently block a veALCX token owner's reward claims by creating more than 50 userPointHistory entries through repeated small deposits. The claim calculation loop only checks 50 entries, so it returns zero claimable rewards for the targeted token.
- Disclosed after under an hour
31399 - [SC - High] RewardDistributor claims can be DoSed through e...
Submitted on May 18th 2024 at 03:47:27 UTC by @jecikpo for Boost | Alchemix
Report ID: #31399
Report type: Smart Contract
Report severity: High
Target: https://github.com/alchemix-finance/alchemix-v2-dao/blob/main/src/RewardsDistributor.sol
Impacts:
- Griefing (e.g. no profit motive for an attacker, but damage to the users or the protocol)
- Permanent freezing of unclaimed royalties
Description
Brief/Intro
A malicious user can DoS (permanently lock) veALCX token owner's claims, by creating certain amount of userPointHistory entries by calling VotingEscrow.depositFor() on a target token multiple times.
Vulnerability Details
RewardDistributor claims are calculated in the _claimable() function. The calculation first involves finding the last userPoint which was taken before the last weekCursor. This is done through a for loop that cycles from the last userEpoch until it finds one. The loop can cycle up to 50 times:
for (uint256 i = 0; i < 50; i++) {
hence if there are more userPoints than 50 the _claimable() function will return 0 as toDistribute.
A malicious user can call the VotingEscrow.depositFor() on the attacked veALCX token multiple times and can deposit minimum amount tokens (1 wei is enough), this way he can create the userPoints that will DoS the function.
The solution would be to use binary search like in other places in the system.
Impact Details
Te veALCX token holder loses irreversibly all claims.
References
Proof of Concept
paste the following code into Minter.t.sol:
function testDOSClaims() public {
initializeVotingEscrow();
// Get a fresh epoch
hevm.warp(newEpoch());
voter.distribute();
uint256 tokenId1 = createVeAlcx(admin, TOKEN_1, MAXTIME, false);
uint256 tokenId2 = createVeAlcx(beef, TOKEN_1, MAXTIME, false);
deal(bpt, beef, TOKEN_1);
hevm.prank(beef);
IERC20(bpt).approve(address(veALCX), TOKEN_1);
for (uint256 i; i < 60; i++) {
hevm.prank(beef);
veALCX.depositFor(tokenId1, 1);
hevm.roll(block.number + 1);
}
// Finish the epoch
hevm.warp(newEpoch());
voter.distribute();
// Go to the next epoch
hevm.warp(newEpoch());
voter.distribute();
// And the next epoch
hevm.warp(newEpoch());
voter.distribute();
uint256 claimable1 = distributor.claimable(tokenId1);
uint256 claimable2 = distributor.claimable(tokenId2);
console.log("claimable on tokenId1: %d", claimable1);
console.log("claimable on tokenId2: %d", claimable2);
}
We can see in the output that the tokenId1 that was attacked is returning 0 of claimable amount, while the tokenId2 returns the correct amount:
[PASS] testDOSClaims() (gas: 27805168)
Logs:
claimable on tokenId1: 0
claimable on tokenId2: 5158128881524544439089
Suite result: ok. 1 passed; 0 failed; 0 skipped; finished in 77.54s (39.96s CPU time)
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
The claim calculation uses a fixed 50-iteration loop to find the correct historical user point instead of a binary search, so it fails when there are more than 50 entries.
Impact
The targeted veALCX token holder permanently loses all unclaimed rewards, with no profit motive for the attacker.
What the attacker needed
Attacker has a small amount of tokens; victim owns a veALCX token
The fix
The claim calculation should use a binary search instead of a fixed 50-iteration loop.
How it was found
- Create two veALCX tokens with the same deposit amount.
- Approve the VotingEscrow contract to spend tokens from the attacker account.
- Call depositFor on the victim token 60 times with 1 wei each, advancing the block number each time.
- Advance through several epochs and call distribute.
- Check the claimable amount for both tokens; the attacked token returns 0 while the other returns a normal amount.
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.
Rewards for a locked token are calculated by looking back through a list of past deposit records. The code only checks the 50 most recent records, so if someone adds more than 50 tiny deposits to your token, the calculation gives up and says you have nothing to claim. An attacker can do this cheaply and permanently block your rewards.
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.