RCFactory.createMarket() does not enforce _timestamps and _timestamps being larger than _timestamps , even though proper functioning requires them to be so
The market creation function does not enforce that the opening time is before the locking and resolution times, allowing a market to be created where locking and resolution occur before opening. An attacker could create such a market, potentially disrupting the intended sequence of events.
jvaqa Follow with 0xRajeev, paulius.eth and 1 other
Originally disclosed on Code4rena
Submitted by jvaqa, also found by 0xRajeev, paulius.eth and shw
RCFactory.createMarket() does not enforce _timestamps[1] and _timestamps[2] being larger than _timestamps[0], even though proper functioning requires them to be so.
IRCMarket defines a sequence of events that each market should progress through sequentially, CLOSED, OPEN, LOCKED, WITHDRAW. (1)
The comments explicitly state that _incrementState() should be called “thrice” (2)
However, it is possible to create a market where these events do not occur sequentially.
You can create a market where the marketOpeningTime is later than the marketLockingTime and oracleResolutionTime.
This is because although RCFactory checks to ensure that _timestamps[2] is greater than _timestamps[1], it does not check to ensure that _timestamps[1] is greater than _timestamps[0] (3)
This is also because although RCFactory checks to ensure that _timestamps[0] is equal to or greater than block.timestamp, it makes no check for a minimum value for _timestamps[1] or _timestamps[2], or a relative check between the value of _timestamps[0] and _timestamps[1]. (4)
Thus, you can create a market where the marketLockingTime and the oracleResolutionTime occur before the marketOpeningTime.
When calling RCFactory.createMarket(), Alice can supply 0 as the argument for _timestamps[1] and _timestamps[2], and any value equal to or greater than block.timestamp for _timestamps[0] (5)
Recommend adding the following check to RCFactory.createMarket():
require(
_timestamps[0] < _timestamps[1],
"market must begin before market can lock"
);
Splidge (Reality Cards) confirmed and resolved:
Implemented here
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 createMarket function lacks a check that the opening timestamp is less than the locking timestamp.
Impact
This could allow the creation of markets with an invalid event sequence, potentially causing unexpected behaviour in the market's lifecycle.
What the attacker needed
Ability to call createMarket()
The fix
The issue was fixed by adding a check that the opening timestamp is less than the locking timestamp.
How it was found
- Call RCFactory.createMarket() with _timestamps[1] and _timestamps[2] set to 0.
- Set _timestamps[0] to any value equal to or greater than block.timestamp.
- The market is created with locking and resolution times before the opening time.
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 for prediction markets lets users create new markets with three timestamps: when trading opens, when it locks, and when the outcome is resolved. The creation function checks that the resolution time is after the locking time, but it does not check that the opening time is before the locking time. This means someone can create a market where locking and resolution happen before opening, which breaks the expected order of events.
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.