latestMarket used where marketIndex should have been used
The functions initializeMarket and _seedMarketInitially used the variable latestMarket instead of the marketIndex parameter, so if called separately from createNewSyntheticMarket, the latest market would be initialised multiple times and previous markets would not be initialised properly. An attacker with admin access could cause incorrect market initialisation, but the functions are admin-only.
Submitted by gpersoon, also found by 0xImpostor, cmichel, shw, hack3r-0m, jonah1005, loop and pauliax
The functions initializeMarket and _seedMarketInitially use the variable latestMarket. If these functions would be called seperately from createNewSyntheticMarket, then latestMarket would have the same value for each call of initializeMarket and _seedMarketInitially
This would mean that the latestMarket is initialized multiple times and the previous market(s) are not initialized properly. Note: the call to addNewStakingFund could have prevented this issue, but also allows this, see separate issue.
Note: the functions can only be called by the admin, so if createNewSyntheticMarket and initializeMarket are called in combination, then it would not lead to problems, but in future release of the software the calls to createNewSyntheticMarket and initializeMarket might get separated.
function _seedMarketInitially(uint256 initialMarketSeedForEachMarketSide, uint32 marketIndex) internal virtual {
...
ISyntheticToken(syntheticTokens[latestMarket][true]).mint(PERMANENT_INITIAL_LIQUIDITY_HOLDER,initialMarketSeedForEachMarketSide); // should be marketIndex
ISyntheticToken(syntheticTokens[latestMarket][false]).mint(PERMANENT_INITIAL_LIQUIDITY_HOLDER,initialMarketSeedForEachMarketSide); // should be marketIndex
function initializeMarket(
uint32 marketIndex,....)
...
require(!marketExists[marketIndex], "already initialized");
require(marketIndex <= latestMarket, "index too high");
marketExists[marketIndex] = true;
..
IStaker(staker).addNewStakingFund(
`latestMarket`, // should be marketIndex.
syntheticTokens[latestMarket][true], // should be marketIndex
syntheticTokens[latestMarket][false], // should be marketIndex
...
Recommend replacing latestMarket with marketIndex in the functions initializeMarket and _seedMarketInitially.
p.s. confirmed by Jason of float capital: Definitely an issue, luckily both of those functions are adminOnly. But that is definitely not ideal!
Great spot!
Not a risk if you know about it (you just need to launch markets sequentially not in batches), but we didn’t. So 2 - medium risk is fair :)
Resolved PR https://github.com/Float-Capital/monorepo/pull/1106
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 code mistakenly used the state variable latestMarket instead of the function parameter marketIndex when referring to the market being initialised.
Impact
If the admin calls initializeMarket and _seedMarketInitially separately from createNewSyntheticMarket, the latest market could be initialised multiple times and previous markets would not be initialised properly, but the functions are admin-only so the risk is limited.
What the attacker needed
Admin access to call functions
The fix
The issue was fixed by replacing latestMarket with marketIndex in the affected functions.
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.
This is a smart contract bug where a function used the wrong variable. Instead of using the specific market number passed in, it used a global 'latest market' number, so if you set up several markets in a row, they would all point to the same one. Only an admin could trigger it, but it could mess up the setup of new markets.
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.