Skip to content
Smart contracts Audit finding Beginner

Tautology in PoolVoterregisterGauge makes it im

The PoolVoter contract's registerGauge function contains a tautology: it only adds a pool to the _pools array if isPool[_asset] is already true, but isPool is only set to true inside that same conditional, so the array remains empty. As a result, distribute functions that rely on _pools either do nothing or revert, preventing gauge distribution.

nethoxa Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

29181 - [SC - High] Tautology in PoolVoterregisterGauge makes it im...

Submitted on Mar 9th 2024 at 20:29:08 UTC by @nethoxa for Boost | ZeroLend

Report ID: #29181

Report type: Smart Contract

Report severity: High

Target: https://github.com/zerolend/governance

Impacts:

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

Description

Brief/Intro

Tautology in PoolVoter::registerGauge makes it impossible to add pools to the _pools array, as it checks for isPool[_asset] to be true, which is set in the same logical branch so it can't be triggered. That makes most of the distribute* functions useless as they rely on either _pools.length (which would be 0 so they become NOPs) or they access elements inside such array, triggering an OOB error and always reverting such a transaction.

Vulnerability Details

It is pretty visual, the only place where isPool is set to true for a given asset is in PoolVoter::registerGauge:

Solidity
    function registerGauge(
        address _asset,
        address _gauge
    ) external onlyOwner returns (address) {
        if (isPool[_asset]) {
            _pools.push(_asset);
            isPool[_asset] = true;
        }

        ...
    }

however, as mappings defaults to 0 or false, it won't be triggered and the _pools array will remain empty.

Impact Details

Calls to distribute or distributeEx will either revert or return without doing anything, as they rely on _pools.length to iterate the array or they will access it, even if it is empty. That is, those functions remain useless, so it can be seen a self-griefing from the contract to any user who calls those functions.

Proof of Concept

I initialized a Foundry repo to test it, but I believe this is simple enough that it does not matter which framework you use to test it. I can provide the repo if you want:

Solidity
pragma solidity 0.8.20;

import {Test} from "forge-std/Test.sol";
import {PoolVoter} from "src/voter/PoolVoter.sol";

contract POC is Test {

    function test_POC() external {
        PoolVoter voter = new PoolVoter();
        voter.init(address(0xabcd), address(0xabcd));
        
        voter.registerGauge(address(0xabcd), address(0xabcd));
        require(voter.pools().length == 0, "POC");
    }
}

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

The condition checks isPool[_asset] before it is ever set to true, creating a logical impossibility.

Impact

Calls to distribute or distributeEx will either revert or do nothing, making those functions useless and causing griefing to users who call them.

What the attacker needed

None

The fix

The condition should be inverted to check if isPool[_asset] is false before adding the pool and setting isPool to true.

How it was found

  1. Deploy the PoolVoter contract and call init.
  2. Call registerGauge with an asset and gauge address.
  3. Observe that the pools array length remains zero.

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 has a function meant to register pools for rewards, but it only adds a pool if a flag is already set to true. That flag is only set to true inside the same block of code that adds the pool, so it never happens. As a result, the list of pools stays empty and reward distribution functions cannot work.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by nethoxa

View all

1 more disclosed report, best first.

More from ZeroLend

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.