31242 - [SC - Critical] RevenueHandlercheckpoint allows users to claim ...

Submitted on May 15th 2024 at 19:01:43 UTC by @yttriumzz for Boost | Alchemix

Report ID: #31242

Report type: Smart Contract

Report severity: Critical

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

Impacts:

  • Theft of unclaimed yield

Description

Brief/Intro

The RevenueHandler contract receives the revenue from Alchemix protocol. One part of the revenue is sent to the treasury. The rest is distributed to users that have $veToken. Each $veToken can claim rewards once per epoch. Anyone can call the RevenueHandler.checkpoint interface to refresh the currentEpoch. However, the checkpoint interface allows the currentEpoch to be updated to the timestamp of the current block, allowing attackers to use VotingEscrow.merge to repeatedly claim rewards.

Vulnerability Details

Please look at the following code. When block.timestamp is equal to currentEpoch + WEEK, currentEpoch is updated to block.timestamp.

///// https://github.com/alchemix-finance/alchemix-v2-dao/blob/f1007439ad3a32e412468c4c42f62f676822dc1f/src/RevenueHandler.sol#L228-L231
    function checkpoint() public {
        // only run checkpoint() once per epoch
        if (block.timestamp >= currentEpoch + WEEK /* && initializer == address(0) */) {
            currentEpoch = (block.timestamp / WEEK) * WEEK;

The RevenueHandler contract calculates the number of rewards that can be claimed for a certain $veToken based on the value of the $veToken at the currentEpoch time point. Please see the code below.

If currentEpoch can be set as the timestamp of the current block, then after the user claim the $veToken reward in the current block, he can transfer the value of $veToken to another $veToken through VotingEscrow.merge to continue claim it. The attack steps are briefly described below. Please see the PoC for details.

  1. When the block.timestamp of the block happens to be currentEpoch + WEEK, the attacker calls RevenueHandler.checkpoint to update currentEpoch to block.timestamp

  2. The attacker mints a $veTokenA and claim the reward

  3. The attacker mints a $veTokenTemp worth 1 wei with a cost of ~0

  4. The attacker merges $veTokenA into $veTokenTemp and claim rewards for $veTokenTemp

  5. Treat $veTokenTemp as $veTokenA and go back to Step2

Note that all the above steps are run in the same block.

Suggested fix

Users should only be able to claim past rewards

Impact Details

Users can claim rewards repeatedly

References

None

Proof of Concept

The PoC patch

Run the PoC

The log

Last updated

Was this helpful?