Skip to content
Business logic Audit finding Intermediate

RubiconMarket buys can not be disabled if offer matching is disabled

The buyEnabled flag is only checked inside the _buys function, which is used only when matchingEnabled is true. If matchingEnabled is false, the buy function calls the parent contract's buy directly, bypassing the check, so buys can still be executed even when the administrator intended to disable them.

berndartmueller Follow

Originally disclosed on Code4rena

Submitted by berndartmueller

In the RubiconMarket contract, buys can be disabled with setBuyEnabled. However, if matchingEnabled is set to false, buys can not be disabled as the require check is located in the _buys function instead of checking buyEnabled in the buy function.

Proof of Concept

RubiconMarket.sol#L962

function _buys(uint256 id, uint256 amount) internal returns (bool) {
    require(buyEnabled); // @audit-info Buys can not be disabled if offer matching is disabled - this require statement should be moved to `buy` function
    if (amount == offers[id].pay_amt) {
        if (isOfferSorted(id)) {
            //offers[id] must be removed from sorted list because all of it is bought
            _unsort(id);
        } else {
            _hide(id);
        }
    }

    require(super.buy(id, amount));

    // If offer has become dust during buy, we cancel it
    if (
        isActive(id) &&
        offers[id].pay_amt < _dust[address(offers[id].pay_gem)]
    ) {
        dustId = id; //enable current msg.sender to call cancel(id)
        cancel(id);
    }
    return true;
}

Recommended Mitigation Steps

Move the require check for buyEnabled to the buy function here.

bghughes (Rubicon) disputed and commented:

Seems irrelevant as buyEnabled is working as intended.

HickupHH3 (judge) commented:

@bghughes kindly double check; the warden is correct.

If matchingEnabled is false, then it will enter the latter case of the ternary statement:

function(uint256, uint256) returns (bool) fn = matchingEnabled
   ? _buys
   : super.buy;

https://github.com/code-423n4/2022-05-rubicon/blob/8c312a63a91193c6a192a9aab44ff980fbfd7741/contracts/RubiconMarket.sol#L670-L672

which means buys can still be executed because the buyEnabled isn’t checked in the parent function. This probably stems from the intended functionality of the buyEnabled variable: is it supposed to disable entirely, or only when matching is enabled?

As the warden’s concern is valid, I’ll be letting the issue stand.

bghughes (Rubicon) confirmed and commented:

Thank you @HickupHH3 for your support throughout the review process and apologies for being late to reply. You are correct, it seems this is a valid issue, I was dismissive because we never use this in practice, always having matchingEnabled and buying enabled.


The original report as published on Code4rena, by berndartmueller. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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 buyEnabled check is placed in the _buys helper, which is only called when matchingEnabled is true, rather than in the main buy function that is always called.

Impact

If matchingEnabled is false, buys can still be executed even when the administrator has set buyEnabled to false, so the intended disable switch does not work.

What the attacker needed

MatchingEnabled is false; buyEnabled is false

The fix

The require check for buyEnabled should be moved to the buy function so it applies regardless of matchingEnabled.

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 switch meant to stop people from buying. But the check for that switch is in only one of two possible paths. When the other path is taken, the check is skipped, so buying still works even though it was supposed to be turned off.

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 berndartmueller

View all

97 more disclosed reports, best first.

More from Rubicon v2

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.