Skip to content
DoS Audit finding Intermediate

Unlimited gauge numbers can DoS users distribut

The Voter contract allows anyone to create an unlimited number of gauges, and the distribute function iterates over all gauges. An attacker could create enough gauges that the gas cost of distribute exceeds the block gas limit, preventing users from distributing their voting power.

Hoverfly9132 Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

30667 - [SC - Medium] Unlimited gauge numbers can DoS users distribut...

Submitted on May 3rd 2024 at 20:20:16 UTC by @Hoverfly9132 for Boost | Alchemix

Report ID: #30667

Report type: Smart Contract

Report severity: Medium

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

Impacts:

  • Temporary freezing of funds for 12 hours

Description

Brief/Intro

Voter#createGauge allow users create unlimited gauges and distribute vote power to any numbers of alive gauges in Voter#distribute, once the gauges numbers reach a limitation, the users can't execute Voter#distribute any more.

Vulnerability Details

Currently, there is no limit to Voter#createGauge function, as the doc description:

- each veALCX tokenId may distribute their voting power across any number of gauges, it means that any users can create any numbers of gauges and distribute vote power to them. Once the gauges be created, the pool will be recorded in gauges array, and in Voter#distribute function will traverse the array and then distribute vote power to them.

However, if the gauges is large enough, the gas cost may reach the ethereum/optimism gas limit, currently is 30_000_000, then such txs would be failed, which means users can't execute distribute vote power action any more, unless they remove the gauge, but there is no remove gauge function in this version, only have killGauge function to set the gauges to be not alive state.

Impact Details

Users can't execute Voter#distribute any more when created gauges numbers is large enough.

References

NA

Proof of Concept

Because the needed gauges need cost much time in test case, so I will show distribute to different gauges would cost how much gas:

Solidity
function testExecutorCreateGaugeFrontRunDos() public {
    address attacker = address(0x2345);

    uint256 created_gauges = 1;
    hevm.startPrank(address(timelockExecutor));
    for (uint i = 0; i < created_gauges; i++) {
        voter.createGauge(address(uint160(i)), IVoter.GaugeType.Passthrough);
    }
    hevm.stopPrank();

    hevm.warp(block.timestamp + 3 weeks);
    uint256 gas_left = gasleft();
    voter.distribute();
    uint256 gas_after = gasleft();
    console.log("gas left: ", gas_left - gas_after);
}

When the created_gauges is equal to 1, Voter#distribute gas cost is about ~1050000 wei:

JSON
[PASS] testExecutorCreateGaugeFrontRunDos() (gas: 3607681)
Logs:
  gas left:  1054068

When the created_gauges is equal to 10, Voter#distribute gas cost is about ~1154915 wei:

JSON
[PASS] testExecutorCreateGaugeFrontRunDos() (gas: 27094489)
Logs:
  gas left:  1154915

When the created_gauges is equal to 20, Voter#distribute gas cost is about ~1154915 wei:

JSON
[PASS] testExecutorCreateGaugeFrontRunDos() (gas: 53190954)
Logs:
  gas left:  1266968

So distribute to more one gauge, gas cost is about: (1266968 - 1154915) / 10 ~= 11205, the max gauge in one tx is about 30000000 / 11205 ~= 2677. Actually, the max gauge should less than 2677 because the distribute action will cost gas in other function. When set created_gauges to 2677, the Voter#distribute function gas cost greater than 30_000_000 wei absolutely.

The original report as published on Immunefi, by Hoverfly9132. 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 createGauge function has no cap on the number of gauges, and distribute loops over the entire gauge array, so the loop can exceed the block gas limit.

Impact

Users could be unable to distribute their voting power, temporarily freezing funds for up to 12 hours, because the distribute transaction would exceed the block gas limit.

What the attacker needed

Ability to call createGauge; enough funds to create many gauges

How it was found

  1. Create many gauges using the createGauge function.
  2. Wait for the voting period to become active.
  3. Call distribute, which iterates over all gauges and runs out of gas.

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 gauge is a place where votes are directed. The contract lets anyone add new gauges without limit, and when votes are distributed it checks every gauge in turn. If there are too many gauges, the check takes more gas than a block allows, so the transaction always fails and nobody can distribute votes.

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 Hoverfly9132

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.

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.