The stockInfo.id and offerInfo.id, which are supposed to be unique, can be duplicated, leading to potential issues in the system.
When creating an offer with PreMarkets::createOffer, the global offerId is used to generate addresses before the offerId is incremented:
Later in the same function, the offerId is used as the ID for both OfferInfo and stockInfo:
However, the offerId is not incremented further, which can lead to the same ID being used for multiple entries.
the full code here : https://github.com/Cyfrin/2024-08-tadle/blob/04fd8634701697184a3f3a5558b41c109866e5f8/src/core/PreMarkets.sol#L39
In the PreMarkets::createTaker function, a new stock is created with the offerId, which is then incremented:
At this point, there is a risk that two StockInfo entries could end up with the same ID
In the listOffer function, stockInfo.id is used to generate a new offerAddr and ID:
This can result in two OfferInfo entries having the same ID, leading to potential conflicts.
user A create an offer with offerId = 1
offerAddr, stockAddr and makerAddr are generated with =1
offerId is then incremented (offerId = 2)
stockInfo.id = 2
offerInfo.id = 2
user B create a taker with offerId = 2
stockInfo.id = 2
offerId is then update (offerId = 3)
user B list offer (using the stock he just create)
offerInfo.id = 2
Duplicate IDs in stockInfo and offerInfo can compromise the integrity of the data.
Modify the createOffer logic to increment the offerId only after both offerInfo and stockInfo entries have been successfully created. This will ensure that each offerId is unique and used consistently throughout the process, preventing collisions.
I believe this is valid low severity, although there is inconsistency here when using the correct `offerId` for assigning offerIds and generating the unique addresses as seen [here](https://github.com/Cyfrin/2024-08-tadle/blob/04fd8634701697184a3f3a5558b41c109866e5f8/src/core/PreMarkets.sol#L67-L69), this is purely an accounting error for offerIds. If we generate the offerId using current `offerId - 1`, the appropriate listing/taker orders can still be created against those offers.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.