hats-finance / SeeR-PM-0x899bc13919880db76edf4ccd72bdfa5dfa666fb7

1 stars 0 forks source link

Incomplete Outcome Slot Count Definition in Scalar Market Creation #15

Open hats-bug-reporter[bot] opened 1 month ago

hats-bug-reporter[bot] commented 1 month ago

Github username: -- Twitter username: -- Submission hash (on-chain): 0xa3d4e5242323ee490da9b267496747be8cba6ec6bc304ffa57160a721a7d3581 Severity: low

Description: Description

The createScalarMarket function uses an outcomeSlotCount parameter that defines the number of outcome slots available for a scalar market. This parameter currently only accounts for three possible outcomes: two standard outcomes and one reserved for the INVALID result. However, the scalar market setup also requires an additional slot for the UNRESOLVED_ANSWER outcome. This discrepancy in the slot count may cause unexpected behavior or incorrect outcome handling in the market.

Attachments

  1. Proof of Concept (PoC)
function createScalarMarket(CreateMarketParams calldata params) external returns (address) {
        require(params.upperBound > params.lowerBound, "upperBound must be higher than lowerBound");
        // values reserved by Reality for INVALID and UNRESOLVED_ANSWER.
        require(params.upperBound < type(uint256).max - 2, "upperBound must be less than uint256.max - 2"); 
        require(params.outcomes.length == 2, "Outcomes count must be 2");

        string[] memory encodedQuestions = new string[](1);
        encodedQuestions[0] = encodeRealityQuestionWithoutOutcomes(params.marketName, params.category, params.lang);

        return createMarket(
            params,
            params.marketName,
            InternalMarketConfig({
                encodedQuestions: encodedQuestions,
 @>             outcomeSlotCount: 3, // additional outcome for Invalid Result.      
                templateId: REALITY_UINT_TEMPLATE
            })
        );
    }
  1. Revised Code To ensure all possible outcomes are represented correctly, the outcomeSlotCount parameter should be set to four, which includes both the standard outcomes and the two reserved outcomes. It is recommended to review and adjust the outcomeSlotCount parameter accordingly to accurately represent all potential outcomes for the scalar market.
function createScalarMarket(CreateMarketParams calldata params) external returns (address) {
        require(params.upperBound > params.lowerBound, "upperBound must be higher than lowerBound");
        // values reserved by Reality for INVALID and UNRESOLVED_ANSWER.
        require(params.upperBound < type(uint256).max - 2, "upperBound must be less than uint256.max - 2"); 
        require(params.outcomes.length == 2, "Outcomes count must be 2");

        string[] memory encodedQuestions = new string[](1);
        encodedQuestions[0] = encodeRealityQuestionWithoutOutcomes(params.marketName, params.category, params.lang);

        return createMarket(
            params,
            params.marketName,
            InternalMarketConfig({
                encodedQuestions: encodedQuestions,
--              outcomeSlotCount: 3, // additional outcome for Invalid Result.      
++              outcomeSlotCount: 4, // additional outcomes for Invalid and Unresolved_Answer Result.
                templateId: REALITY_UINT_TEMPLATE
            })
        );
    }
clesaege commented 1 month ago

UNRESOLVED_ANSWER means that the question is not yet resolved. To resolve a market, we call Reality there. It doesn't allow an unresolved answer.