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.
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.
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.
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.
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.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
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.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
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.