Tadle

Tadle
DeFiFoundry
27,750 USDC
View results
Submission Details
Severity: low
Valid

Wrong `offerId` assigned to the `PreMarkets:stockInfoMap` and `PreMarkets:offerInfoMap` .

Summary

An incorrect offerId is assigned to the PreMarkets:stockInfoMap and PreMarkets:offerInfoMap, leading to a mismatch between the offer identifiers used to generate addresses and the identifiers stored in these mappings.

Vulnerability Details

The PreMarkets:createOffer function is responsible for creating an offer by generating addresses for makerInfoMap, offerInfoMap, and stockInfoMap, each associated with an offerId. The addresses are created as follows:
https://github.com/Cyfrin/2024-08-tadle/blob/04fd8634701697184a3f3a5558b41c109866e5f8/src/core/PreMarkets.sol#L67-L69

address makerAddr = GenerateAddress.generateMakerAddress(offerId);
address offerAddr = GenerateAddress.generateOfferAddress(offerId);
address stockAddr = GenerateAddress.generateStockAddress(offerId);

As the execution proceeds, the offerId is incremented:

https://github.com/Cyfrin/2024-08-tadle/blob/04fd8634701697184a3f3a5558b41c109866e5f8/src/core/PreMarkets.sol#L83

offerId = offerId + 1;

After this increment, the mappings makerInfoMap, offerInfoMap, and stockInfoMap are fetched using the previously generated addresses makerAddr, offerAddr, and stockAddr. However, the id fields in the offerInfoMap and stockInfoMap structs are set to the new, incremented offerId, which differs from the offerId initially used to generate the addresses.
https://github.com/Cyfrin/2024-08-tadle/blob/04fd8634701697184a3f3a5558b41c109866e5f8/src/core/PreMarkets.sol#L116-L146

This results in a misalignment between the offerId used to create the addresses and the offerId stored in the mappings, potentially causing inconsistencies and errors in the offer-related data.

Impact

Misalignment between the offerId used to create the addresses and the offerId stored in the mappings

Tools Used

Manually

Recommendations

Use correct offerId update it later

Updates

Lead Judging Commences

0xnevi Lead Judge about 1 year ago
Submission Judgement Published
Validated
Assigned finding tags:

finding-PreMarkets-createOffer-offerId-increment-after

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.

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.