Skip to content
DoS Audit finding Advanced

DOS of withdrawals through filling the userPoin

Every checkpoint call for a tokenId writes a new entry into a fixed-size array of user points, and any user can trigger checkpoints for any tokenId through depositFor. By filling that array an attacker could make later withdrawals for the tokenId revert, though the text says the cost makes this barely feasible.

NinetyNineCrits Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

30922 - [SC - High] DOS of withdrawals through filling the userPoin...

Submitted on May 8th 2024 at 07:48:35 UTC by @NinetyNineCrits for Boost | Alchemix

Report ID: #30922

Report type: Smart Contract

Report severity: High

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

Impacts:

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

Description

Brief/Intro

While not very feasible, it is technically possible to DOS withdraws associated with a tokenId, by doing a large amount of deposits for said tokenId.

Vulnerability Details

Unlike Velodrome, every _checkpoint call with an associated tokenId writes a new userPoint:

Solidity
    uint256 userEpoch = userPointEpoch[_tokenId] + 1;

    userPointEpoch[_tokenId] = userEpoch;
    newPoint.ts = block.timestamp;
    newPoint.blk = block.number;
    userPointHistory[_tokenId][userEpoch] = newPoint;

This opens up the door to a DOS, as the number of possible user points is limited:

Solidity
mapping(uint256 => Point[1000000000]) public userPointHistory;

Any user can invoke _checkpoint for any tokenId by using depositFor.

Naturally 1 Billion is a very large number that somewhats limits the feasability and likelihood of this attack (but does not mean a billion transactions need to be made, as the deposits could be looped through a contract). Even though the impact could be categorized as a permanent freeze, the limitations do not justify a higher severity than medium imo, hence griefing seems to be the appropriate impact.

Impact Details

DOS of any tokenId, but associated with very high costs of attack.

Recommendations

Consider going back to Velodromes approach of accounting, which limits the addition of points to 1 per block:

Solidity
uint256 userEpoch = userPointEpoch[_tokenId];
if (userEpoch != 0 && _userPointHistory[_tokenId][userEpoch].ts == block.timestamp) {
    _userPointHistory[_tokenId][userEpoch] = uNew;
} else {
    userPointEpoch[_tokenId] = ++userEpoch;
    _userPointHistory[_tokenId][userEpoch] = uNew;
}

This would also add a time constraint on the attack, which would require 380 years, assuming a a block each 12 seconds.

Proof of Concept

Solidity
    //@note requires modifying `mapping(uint256 => Point[1000000000]) public userPointHistory;` in VotingEscrow to a size of 5
    function testMinhDOSWithdraw() public {
        address user = address(0x12345);
        address attacker = address(0x6789);
        deal(bpt, user, 10e18);
        deal(bpt, attacker, 10);

        hevm.startPrank(user);
        IERC20(bpt).approve(address(veALCX), 10e18);
        uint256 tokenId = veALCX.createLock(10e18, 2 weeks, false);
        hevm.stopPrank();

        hevm.startPrank(attacker);
        IERC20(bpt).approve(address(veALCX), 10);
        veALCX.depositFor(tokenId, 1);
        veALCX.depositFor(tokenId, 1);
        veALCX.depositFor(tokenId, 1);
        hevm.stopPrank();

        hevm.warp(block.timestamp + 2 weeks);

        hevm.startPrank(user);
        veALCX.startCooldown(tokenId);

        hevm.warp(block.timestamp + 2 weeks);

        veALCX.withdraw(tokenId);
    }

This test will revert on the withdraw call with:

Solidity
[FAIL. Reason: Index out of bounds]

The original report as published on Immunefi, by NinetyNineCrits. 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 contract appends a new user point on every checkpoint instead of overwriting the entry for the current block, so the bounded userPointHistory array can be exhausted.

Impact

Withdrawals for a targeted tokenId could be permanently blocked, but the text states the attack requires very high costs and is not very feasible.

What the attacker needed

Attacker holds a small amount of the deposit token; target tokenId exists

The fix

The checkpoint logic should be changed to overwrite the existing user point within the same block rather than appending a new one, as the report recommends.

How it was found

  1. Create a lock to obtain a tokenId
  2. As an attacker, call depositFor on that tokenId repeatedly to add user points
  3. Wait for the lock period and start cooldown
  4. Attempt to withdraw the tokenId, which reverts

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 a history of changes for each locked token in a list with a fixed maximum length. Anyone can add entries to someone else's list by making tiny deposits on their behalf, so in theory the list could fill up and the owner could no longer withdraw. The report notes this would take an enormous number of transactions, so it is mostly a design concern.

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.

More by NinetyNineCrits

View all

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

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.