You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Seer Protocol's MarketFactory contract creates prediction markets linked to Reality.eth questions. The askRealityQuestion function is responsible for generating unique question IDs and submitting these questions to Reality.eth.
The current implementation of askRealityQuestion generates a question_id based on a set of parameters that don't include any user-specific or time-specific data. This could potentially lead to question ID collisions in some cases, where two different markets end up referencing the same Reality.eth question.
In the event of a collision, two different markets could end up referencing the same Reality.eth question.
This could lead to market resolutions based on unintended questions, potentially causing confusion and financial losses for participants.
Scenario
Two users create markets with identical parameters (same question, templateId, openingTime, and minBond).
Due to the deterministic nature of the question_id generation, both markets generate the same question_id.
The second market creation reuses the existing Reality.eth question instead of creating a new one.
Both markets end up referencing the same Reality.eth question, which is correct behavior but could potentially lead to unexpected interactions between the markets.
Fix
Modify the question_id calculation to include the sender's address and the current block timestamp. This ensures uniqueness even if all other parameters are identical:
function askRealityQuestion(
stringmemoryencodedQuestion,
uint256templateId,
uint32openingTime,
uint256minBond
) internalreturns (bytes32) {
bytes32 content_hash =keccak256(abi.encodePacked(templateId, openingTime, encodedQuestion));
bytes32 question_id =keccak256(
abi.encodePacked(
content_hash, arbitrator, questionTimeout, minBond, address(realitio), address(this), msg.sender, block.timestamp
)
);
// Rest of the function remains the same
...
}
Poc
describe("Question ID Collision",function(){it("should generate the same question ID for identical market parameters",asyncfunction(){// Create the first marketconsttx1=awaitmarketFactory.createCategoricalMarket(categoricalMarketParams);constreceipt1=awaittx1.wait();constevent1=receipt1.events?.find(e=>e.event==="NewMarket");constquestionId1=event1?.args?.[4];// Create a second market with identical parametersconsttx2=awaitmarketFactory.createCategoricalMarket(categoricalMarketParams);constreceipt2=awaittx2.wait();constevent2=receipt2.events?.find(e=>e.event==="NewMarket");constquestionId2=event2?.args?.[4];// Check that both markets have the same question IDexpect(questionId1).to.equal(questionId2);// Verify that both markets point to the same Reality.eth questionconstmarketAddress1=(awaitmarketFactory.allMarkets())[0];constmarketAddress2=(awaitmarketFactory.allMarkets())[1];constmarket1=awaitethers.getContractAt("Market",marketAddress1);constmarket2=awaitethers.getContractAt("Market",marketAddress2);constquestionsIds1=awaitmarket1.questionsIds();constquestionsIds2=awaitmarket2.questionsIds();expect(questionsIds1[0]).to.equal(questionsIds2[0]);});});
This test does the following:
Creates two categorical markets with identical parameters.
Extracts the question IDs from the emitted events.
Compares the question IDs to show they are identical.
Retrieves the actual question IDs stored in the Market contracts to verify they indeed point to the same Reality.eth question.
This test demonstrates that creating two markets with identical parameters results in the same question ID being used
The text was updated successfully, but these errors were encountered:
It is possible for 2 markets to reference the same question. This is good as it prevents having multiple bonds and disputes on the same question. We expect this to be used quite often to create conditional markets (like "Who will win the US election?" TRUMP / HARRIS and then two condition markets on "What will be the inflation in the US in 2025?" one conditional on TRUMP the other on HARRIS, but sharing the same question for inflation).
Github username: --
Twitter username: --
Submission hash (on-chain): 0x24a915ee6bc6a35843f696d8d38ca7803e67d7499a774f800e020bff060ea789
Severity: medium
Description:
Details
The Seer Protocol's
MarketFactory
contract creates prediction markets linked to Reality.eth questions. TheaskRealityQuestion
function is responsible for generating unique question IDs and submitting these questions to Reality.eth.The current implementation of
askRealityQuestion
generates aquestion_id
based on a set of parameters that don't include any user-specific or time-specific data. This could potentially lead to question ID collisions in some cases, where two different markets end up referencing the same Reality.eth question.Code Snippet
Impact
Scenario
question_id
generation, both markets generate the samequestion_id
.Fix
Modify the
question_id
calculation to include the sender's address and the current block timestamp. This ensures uniqueness even if all other parameters are identical:Poc
This test does the following:
This test demonstrates that creating two markets with identical parameters results in the same question ID being used
The text was updated successfully, but these errors were encountered: