Skip to content
Business logic Audit finding Intermediate

Minter UpdatePeriod after weeks causes Rewards

The Minter contract's _checkpointToken function updates lastTokenTime to the current block timestamp even though it only distributes rewards for up to 20 weeks, so any time beyond 20 weeks is skipped. An attacker or negligent operator could cause users to permanently lose unclaimed rewards proportional to the elapsed time beyond 20 weeks.

copperscrewer Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

31559 - [SC - Low] Minter UpdatePeriod after weeks causes Rewards...

Submitted on May 21st 2024 at 10:20:50 UTC by @copperscrewer for Boost | Alchemix

Report ID: #31559

Report type: Smart Contract

Report severity: Low

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

Impacts:

  • Permanent freezing of unclaimed royalties
  • Permanent freezing of unclaimed yield

Description

Brief/Intro

The Minter is a contract that calls UpdatedPeriod which then updates rewards to claim in tokensPerWeek in Rewards Distributor

In _checkpointToken The hard cap of 20 weeks and the invalid updation of lastTokenTime to block.timestamp, allows direct loss of rewards proportional to amount of time elapsed from the 20 weeks mark.

Vulnerability Details

Minter UpdatePeriod after 20 weeks causes RewardsDistributor contract to lose claimable amount. The Rewards Distributor Contract has a claim function for a token id where it distributes rewards to the holder, however the rewards are only captured till 20 weeks from last updated epoch and set to the current block.timestamp despite only updating 20 weeks from lastTokenTime.

This is in contrast to the 255 weeks limit in Voting escrow as the number of weeks are just 20 for the exploit to damage the protocol, and there are no associated complexities in carrying out the attack.

SOLIDIITY
    function _checkpointToken() internal {
    .
    lastTokenTime = block.timestamp; 
    //@audit wrong as it's not calculated till block.timestamp, It should cover only till where it updated 
    .
    for (uint256 i = 0; i < 20; i++) { 
    //@audit limit 20 is fine but the former incorrectly updates lastTokenTime 
to block.timestamp
    .
    tokensPerWeek[thisWeek] += (toDistribute * (nextWeek - t)) / sinceLast;
    .
    }


Since the rewards are not entered correctly, the protocol permanently loses the rewards to distribute to the user.

Impact Details

The impact is that the user will permanently lose rewards, and the exploit can be as easy as 20 weeks of negligence and no added complexity to carry out the attack.

Proof of Concept

Copy paste the following code in Minter.t.sol and execute the following command forge test --match-test testtokensPerWeekPOC* --fork-url https://eth-mainnet.alchemyapi.io/v2/[API_KEY] -vvv

Solidity
    function testtokensPerWeekPOC() external 
    {
        console.log("Block timestamp : ", block.timestamp);
        console.log("minter active period : ", minter.activePeriod() );

        uint256 activePeriodThen = minter.activePeriod();
        hevm.warp(activePeriodThen + 20 weeks); 

        //ROUND1        
        hevm.startPrank(address(voter));

        minter.updatePeriod(); // deposits alcx to Distributor
        hevm.stopPrank();

        //We prank veALCX for POC reasons
        hevm.startPrank(address(veALCX));

        uint256 claimedAmount = distributor.claim(1, false);
        console.log("Claimed amount @ 20 weeks : ", claimedAmount);       

    }

    function testtokensPerWeekPOC18() external 
    {
        console.log("Block timestamp : ", block.timestamp);
        console.log("minter active period : ", minter.activePeriod() );

        uint256 activePeriodThen = minter.activePeriod();
        hevm.warp(activePeriodThen + 18 weeks);

        //ROUND1        
        hevm.startPrank(address(voter));

        minter.updatePeriod(); // deposits alcx to Distributor
        hevm.stopPrank();

        //We prank veALCX for POC reasons
        hevm.startPrank(address(veALCX));

        uint256 claimedAmount = distributor.claim(1, false);
        console.log("Claimed amount @ 18 weeks : ", claimedAmount);       

    }

    function testtokensPerWeekPOC10() external 
    {
        console.log("Block timestamp : ", block.timestamp);
        console.log("minter active period : ", minter.activePeriod() );

        uint256 activePeriodThen = minter.activePeriod();
        hevm.warp(activePeriodThen + 10 weeks); 

        //ROUND1        
        hevm.startPrank(address(voter));

        minter.updatePeriod(); // deposits alcx to Distributor
        hevm.stopPrank();

        //We prank veALCX for POC reasons
        hevm.startPrank(address(veALCX));

        uint256 claimedAmount = distributor.claim(1, false);
        console.log("Claimed amount @ 10 weeks : ", claimedAmount);       

    }

    function testtokensPerWeekPOC22() external 
    {
        console.log("\nBlock timestamp : ", block.timestamp);
        console.log("minter active period : ", minter.activePeriod() );

        uint256 activePeriodThen = minter.activePeriod();
        hevm.warp(activePeriodThen + 22 weeks); 

        //ROUND1        
        hevm.startPrank(address(voter));

        minter.updatePeriod(); // deposits alcx to Distributor
        hevm.stopPrank();

        //We prank veALCX for POC reasons
        hevm.startPrank(address(veALCX));

        uint256 claimedAmount = distributor.claim(1, false);
        console.log("Claimed amount @ 22 weeks : ", claimedAmount);       
        

    }

    function testtokensPerWeekPOC30() external 
    {
        console.log("\nBlock timestamp : ", block.timestamp);
        console.log("minter active period : ", minter.activePeriod() );

        uint256 activePeriodThen = minter.activePeriod();
        hevm.warp(activePeriodThen + 30 weeks); 

        //ROUND1        
        hevm.startPrank(address(voter));

        minter.updatePeriod(); // deposits alcx to Distributor
        hevm.stopPrank();

        //We prank veALCX for POC reasons
        hevm.startPrank(address(veALCX));

        uint256 claimedAmount = distributor.claim(1, false);
        console.log("Claimed amount @ 30 weeks : ", claimedAmount);  

        claimedAmount = distributor.claim(1, false);
        console.log("Claimed again : ", claimedAmount);  
    }

The original report as published on Immunefi, by copperscrewer. 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

Root cause

Likely the _checkpointToken function sets lastTokenTime to block.timestamp instead of advancing it by only the 20 weeks it actually processed, so any excess time is discarded.

Impact

Users permanently lose unclaimed rewards proportional to the time elapsed beyond 20 weeks, and the loss can occur simply through 20 weeks of negligence without any added complexity.

What the attacker needed

20 weeks pass without updatePeriod being called

The fix

The _checkpointToken function should update lastTokenTime by only the 20 weeks it actually processed, not to the current block timestamp, so that excess time is not skipped.

How it was found

  1. Advance the blockchain time by more than 20 weeks from the last update.
  2. Call minter.updatePeriod() to trigger reward distribution.
  3. Call distributor.claim() for a token id to see the reduced claimable 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.

A smart contract distributes rewards over time. It keeps a marker of when it last paid out. If nobody triggers a payout for more than 20 weeks, the contract only calculates rewards for the first 20 weeks but then moves the marker to the current time, skipping the rest. That means rewards for the skipped period are never given out and are lost forever.

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 copperscrewer

View all

3 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.