Changing matchingEnabled in RubiconMarket breaks protocol
Offers created while matchingEnabled is false lack the _rank and _best fields, so when matchingEnabled is later set to true, those offers cannot be matched or cancelled because functions like isOfferSorted, _unsort, and _hide rely on those fields. An attacker could exploit this to lock offers, preventing their cancellation or matching.
Originally disclosed on Code4rena
Submitted by berndartmueller
If matchingEnabled in RubiconMarket is changed from false to true, all offers created while matchingEnabled = false can not be matched or canceled if matchingEnabled is toggled to true again. Only changing the value matchingEnabled back to false allows those offers to be used again.
Proof of Concept
Offers created while matchingEnabled = false do not populate _rank and _best. However, both variables are used in multiple functions isOfferSorted, _unsort, _hide which are used if matchingEnabled = true.
For example, canceling an offer that has been created when matchingEnabled = false and enabling matching again, will revert:
if (matchingEnabled) {
if (isOfferSorted(id)) {
require(_unsort(id)); // @audit-info will revert for offers created while `matchingEnabled = false`
} else {
require(_hide(id)); // @audit-info will revert for offers created while `matchingEnabled = false`
}
}
Recommended Mitigation Steps
Consider removing the functionality to toggle matchingEnabled or only allow changing matchingEnabled to false without changing the value back to true.
bghughes (Rubicon) disputed and commented:
This seems like an edge case to me, this kind of toggle could still be permissible in practice but we intend to only keep our value at
true.
Valid issue, even if it’s an edge case. As auditors, between what the code can actually do (and it’s impact) versus what it’s intended to, the former is arguably more important.
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 contract does not initialise the _rank and _best fields for offers created while matchingEnabled is false, but later assumes these fields are set when matchingEnabled is true.
Impact
Offers created while matchingEnabled is false become stuck and cannot be matched or cancelled when matchingEnabled is true, potentially locking funds or preventing users from managing their offers.
What the attacker needed
MatchingEnabled is toggled from false to true; offers exist that were created while matchingEnabled was…
The fix
The functionality to toggle matchingEnabled should be removed, or changing it back to true should be disallowed.
How it was found
- Set matchingEnabled to false.
- Create an offer while matchingEnabled is false.
- Set matchingEnabled to true.
- Attempt to cancel the offer, which reverts.
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.
The smart contract has a switch that turns matching on or off. When matching is off, new offers are saved without some extra sorting information. If matching is turned back on, the contract tries to use that missing information and fails, so those offers get stuck and can't be cancelled or matched.
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.