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
- The function
offerofSimpleMarketis not overridden by theRubiconMarketcontract. Note: that this function is called in the testing example - The
cancelfunction insideSimpleMarketis overridden by thecancelfunction inRubiconMarket.
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:
isOfferSortedwill returnfalsebecause the offer was never inserted into_rank._hidewill also returnfalse, Because the offer was not inserted into the unsorted list_near.- Require check will fail because
_hidereturnedfalse.
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
);
}
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
- Call the inherited SimpleMarket offer function to create an offer.
- Later call the overridden RubiconMarket cancel function for that offer.
- The cancel function checks isOfferSorted, which returns false because the offer is not in _rank.
- It then calls _hide, which returns false because the offer is not in _near.
- 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.