Skip to content
Business logic Audit finding Beginner

Wrong condition check on RevenueHandlerconstruc

The RevenueHandler constructor checked the contract's existing treasuryPct variable instead of the incoming _treasuryPct parameter, so the BPS maximum of 10,000 could be bypassed at deployment. An attacker or deployer could set an arbitrary treasury percentage, breaking the contract's assumed invariant.

cryptonoob2k Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

31487 - [SC - Low] Wrong condition check on RevenueHandlerconstruc...

Submitted on May 20th 2024 at 10:34:10 UTC by @cryptonoob2k for Boost | Alchemix

Report ID: #31487

Report type: Smart Contract

Report severity: Low

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

Impacts:

  • Contract fails to deliver promised returns, but doesn't lose value

Description

Brief/Intro

The RevenueHandler constructor performs a wrong condition check allowing to break BPS maximum value (10_000) implemented invariant and bypass maximum BPS value leading to set tresuary pct to arbitrary value so failing to fulfill expected restrictions set for example in RevenueHandler::setTreasuryPct

Vulnerability Details

The vulnerability exists in RevenueHandler::constructor because wrongly checks the contract treasuryPct variable instead of constructor parameter value:

JavaScript
constructor(address _veALCX, address _treasury, uint256 _treasuryPct) Ownable() {
    veALCX = _veALCX;
    require(_treasury != address(0), "treasury cannot be 0x0");
    treasury = _treasury; 
    require(treasuryPct <= BPS, "treasury pct too large"); //<@ Wrong check
    treasuryPct = _treasuryPct;
 }

So parameter _treasuryPct coult be an arbitrary value , instead of maximum 10_000 value that is performed for eg in RevenueHandler::setTreasuryPct, and will be assigned as treasury pct.

Impact Details

The impact of this vulnerability includes:

  1. Bypass of maximum pct of treasury and breaking contract enviroment asumptions

Risk Breakdown

The vulnerability is fairly easy to exploit leading to breaking BPS invariant, but can only occour during constructor.
Also, the setted value can be modified using RevenueHandler::setTreasuryPct method.
Overall Risk Severity: Low
Likelihood: Medium
Impact: Low

References

https://owasp.org/www-project-smart-contract-top-10/2023/en/src/SC07-logic-errors.html

Proof of Concept

To show the vulnerability
Add this test on src/test/RevenueHandler.t.sol

JavaScript
    function testTreasuryPctLimitBypass() external {
        RevenueHandler revenueHandler2;
        revenueHandler2 = new RevenueHandler(address(veALCX),admin,12345678987654321);
        console.log("revenueHandler2.treasuryPct ",revenueHandler2.treasuryPct());
    }

Run test with

Bash
reset ; forge compile  ; forge test --deny-warnings --fork-url https://rpc.ankr.com/eth --fork-block-number 17133822 --mt testTreasuryPctLimitBypass -vv

Observe revenueHandler2.treasuryPct is more than the intended max allowed (10_000) and bypass restriction checks implemented in RevenueHandler::setTreasuryPct

The original report as published on Immunefi, by cryptonoob2k. 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 constructor validated the uninitialised state variable treasuryPct rather than the _treasuryPct argument, so the bound check never applied to the value actually stored.

Impact

The maximum treasury percentage invariant could be broken at deployment, though the value can later be corrected through setTreasuryPct, so the report rates the impact as low.

What the attacker needed

Occurs only at contract deployment

The fix

The constructor should validate the _treasuryPct parameter against BPS before assigning it.

How it was found

  1. Add the provided test to the RevenueHandler test file.
  2. Deploy a new RevenueHandler with a treasury percentage far above 10,000.
  3. Run the test with forge against a forked mainnet block.
  4. Observe that the stored treasuryPct exceeds the intended maximum.

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 constructor is the setup code that runs once when a smart contract is created. This setup code was meant to reject a treasury percentage above 10,000 (the maximum allowed), but it checked the wrong variable, so a huge value slipped through. The result is a contract that starts in a state its own rules say should be impossible.

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 cryptonoob2k

View all

1 more disclosed report, 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.