Tadle

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

Incorrect Use of memory Instead of storage in listOffer Function Leading to State Inconsistency

Summary

A vulnerability has been identified in the listOffer function where the originOfferInfo struct is defined as a memory variable instead of storage. This issue leads to the incorrect handling of the abortOfferStatus attribute, potentially resulting in inconsistent contract state and unexpected behavior.

Vulnerability Details

In the listOffer function, the originOfferInfo struct is intended to reference an existing offer's state in storage. However, it is incorrectly defined as a memory variable, which creates a temporary copy of the data rather than pointing to the original data in storage. As a result, any modifications made to abortOfferStatus do not persist beyond the function execution.

The relevant code snippet is:

function listOffer(...) public {
OfferInfo memory originOfferInfo = offers[offerId];//<<= FOUND
originOfferInfo.abortOfferStatus = true;
...
originOfferInfo.abortOfferStatus = AbortOfferStatus.SubOfferListed;
}

Here, the abortOfferStatus attribute is updated in memory but not in storage, leading to the change being discarded when the function execution ends.

Impact

The improper use of memory instead of storage results in the abortOfferStatus attribute not being updated correctly. This can cause the contract to function incorrectly, with offers that should be marked as aborted still being treated as active. It could lead to potential exploits or unintended consequences where aborted offers are mistakenly processed.

Tools Used

Manual Code Review

Recommendations

To fix this vulnerability, the originOfferInfo variable should be defined as a storage type, ensuring that any changes to the abortOfferStatus attribute are correctly persisted to the blockchain's storage.

The corrected code snippet would look like this:

function listOffer(...) public {
OfferInfo storage originOfferInfo = offers[offerId];// <<= CORRECTED
originOfferInfo.abortOfferStatus = true;
...
}

This change ensures that the abortOfferStatus is properly updated in the contract's storage, preventing any inconsistencies or potential vulnerabilities.

Updates

Lead Judging Commences

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

finding-PreMarkets-listOffer-originIOfferInfo-storage-memory

Valid high severity, because the `abortOfferStatus` of the offer is not updated and persist through `storage` when listing an offer for turbo mode within the `offerInfoMap` mapping, it allows premature abortion given the `abortOfferStatus` defaults to `Initialized`, allowing the bypass of this [check](https://github.com/Cyfrin/2024-08-tadle/blob/04fd8634701697184a3f3a5558b41c109866e5f8/src/core/PreMarkets.sol#L552-L557) here and allow complete refund of initial collateral + stealing of trade tax which can potentially be gamed for profits using multiple addresses

Support

FAQs

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