Skip to content
Business logic Audit finding Intermediate

Some offers can’t be cancelled

An offer created through the inherited SimpleMarket offer function is not added to the market's internal sorted or unsorted lists, so the overridden cancel function cannot find it and reverts. A user who creates an offer this way can never cancel it, leaving their funds locked in the offer.

CryptoCraze Follow with joestakey, kaden and 12 others

Originally disclosed on Code4rena

Submitted by CryptoCraze, also found by joestakey, kaden, jasonxiale, Delvir0, 0xDING99YA, popular00, popular00, carrotsmuggler, Juntao, mrpathfindr, mrpathfindr, said, CRYP70 and jangle.

A normal user can’t cancel their offer when using a specific API.

Proof of Concept

  1. The function offer of SimpleMarket is not overridden by the RubiconMarket contract. Note: that this function is called in the testing example
  2. The cancel function inside SimpleMarket is overridden by the cancel function in RubiconMarket.

When a normal user creates an offer with the SimpleMarket API(1), the offer is not inserted into the linked list _rank.

After some time the user wants to cancel their order. They can only call RubiconMarket’s cancel function(2). When they call cancel what will happen is:

  1. isOfferSorted will return false because the offer was never inserted into _rank.
  2. _hide will also return false, Because the offer was not inserted into the unsorted list _near.
  3. Require check will fail because _hide returned false.

Therefore, the user won’t be able to cancel their offer.

Exploit

Can’t cancel when creating an offer with SimpleMarket’s offer. Add this to ProtocolDeployment.t.sol:

function test_ExploitCantCancel() public {
  uint id;
  // Create an offer with the function `offer(uint256,ERC20,uint256,ERC20,address,address)` in `SimpleMarket`
  id = market.offer(90e6, TUSDC, 100e18, TEST, address(this), owner);

  // The created offer can't be cancelled! The following line will revert with "Reason: can't hide"
  vm.expectRevert("can't hide");
  market.cancel(id);
}

Recommended Mitigation Steps

Override the offer function in SimpleMarket with the offer function in RubiconMarket. Add this offer function:

function offer(
    uint256 pay_amt,
    ERC20 pay_gem,
    uint256 buy_amt,
    ERC20 buy_gem,
    address owner,
    address recipient
) public override can_offer returns (uint256) {
    return
        offer(
            pay_amt,
            pay_gem,
            buy_amt,
            buy_gem,
            0,
            true,
            owner,
            recipient
        );
  }

daoio (Rubicon) confirmed


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

Likely the RubiconMarket contract overrides cancel but not offer, so offers created via the inherited SimpleMarket offer function are never inserted into the _rank or _near data structures that cancel relies on.

Impact

A user who creates an offer through the SimpleMarket API cannot cancel it, so their offered tokens remain locked in the market.

What the attacker needed

User creates an offer via SimpleMarket's offer function

The fix

Override the SimpleMarket offer function in RubiconMarket so that it routes through the sorted offer logic and inserts the offer into the tracking lists.

How it was found

  1. Call the inherited SimpleMarket offer function to create an offer.
  2. Later call the overridden RubiconMarket cancel function for that offer.
  3. The cancel function checks isOfferSorted, which returns false because the offer is not in _rank.
  4. It then calls _hide, which returns false because the offer is not in _near.
  5. The require check fails and the transaction reverts with 'can't hide'.

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 two versions of a function: an older one and a newer one that replaces it. If you use the older version to create an offer, the newer cancel function cannot find that offer because it was never recorded in the list the cancel function checks. As a result, the user's offer stays active forever and they cannot get their tokens back.

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 CryptoCraze

View all

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