Duplicate _tokenNameSuffix and _tokenSymbolSuffix will incorrectly update current Market
The createMarket function did not check whether a market with the same name and symbol suffix already existed, so calling it again with the same suffixes overwrote the stored reference to the earlier market. An attacker or careless owner could thereby lose the factory's pointer to a live market.
Originally disclosed on Code4rena
Submitted by csanuragjain
Impacted Function: createMarket.
- Owner calls createMarket with _tokenNameSuffix S1 and _tokenSymbolSuffix S2 which creates a new market M1 with _deployedMarkets[_salt] pointing to M1. Here salt can be S which is computed using _tokenNameSuffix and _tokenSymbolSuffix
- This market is now being used
- After some time owner again mistakenly calls createMarket with _tokenNameSuffix S1 and _tokenSymbolSuffix S2
- Instead of returning error mentioning that this name and symbol already exists, new market gets created. The problem here is that salt which is computed using _tokenNameSuffix and _tokenSymbolSuffix will again come as S (as in step 1) which means _deployedMarkets[_salt] will now get updated to M2. This means reference to M1 is gone
Recommended Mitigation Steps
Add below check:
require(_deployedMarkets[_salt]==address(0), "Market already exists");
ramenforbreakfast (prePO) confirmed and commented:
This is a valid submission, and since this would overwrite the existing mapping within
PrePOMarketFactory, I think it is fair for this to remain as medium severity.
Agree with sponsor.
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 createMarket function computed a salt from the name and symbol suffixes and wrote to _deployedMarkets without first checking that the slot was empty.
Impact
The factory's mapping could be overwritten so the reference to the earlier market is lost; the sponsor rated this medium severity.
What the attacker needed
Owner or privileged caller; reuse of the same name and symbol suffixes
The fix
The report recommends requiring that the mapping slot for the computed salt is still the zero address before creating a market.
How it was found
- The owner calls createMarket with a name suffix and symbol suffix, creating market M1 stored under the computed salt.
- The market is used.
- The owner calls createMarket again with the same suffixes.
- No error is raised; a new market M2 is created and the stored reference is overwritten, losing the pointer to M1.
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 keeps a list that maps a name to the address of a market it created. The code built that name from two text suffixes but never checked whether the name was already in use, so creating a second market with the same suffixes replaced the first entry in the list. The first market still exists on the blockchain, but the factory no longer points to it.
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.