The PreMarkets contract implements critical functionality for managing offers and stocks in a decentralized marketplace. Three key functions - closeOffer(), relistOffer(), and listOffer() - are responsible for transitioning the state of offers and stocks, as well as handling collateral deposits and refunds. However, these functions contain significant vulnerabilities in their state transition logic and collateral handling mechanisms.
The closeOffer() function updates the offerStatus to Canceled but fails to update the corresponding stockStatus. This inconsistency can lead to confusion and potential exploitation when the stock is later relisted or a new offer is created for it. The relistOffer() function compounds this issue by setting the offerStatus back to Virgin without properly managing the stock's state, potentially creating conflicts if the stock has been associated with another offer in the meantime.
Furthermore, the listOffer() function does not account for the possibility of a stock being previously associated with a different offer. This oversight can result in double-counting of collateral or mismanagement of funds, compromising the financial integrity of the marketplace.
This issue can severely undermine the integrity and security of the marketplace. Malicious actors could exploit these inconsistencies to manipulate market conditions, potentially leading to financial losses for other participants. The lack of proper state management could result in offers being incorrectly closed, relisted, or created, disrupting the normal functioning of the market.
The collateral mishandling issue in relistOffer() and listOffer() could lead to incorrect calculation and allocation of funds, potentially allowing attackers to game the system for financial gain. This could erode trust in the platform and discourage participation from honest users.
The absence of reentrancy protection exposes the contract to complex attack vectors, where an attacker could potentially drain funds or manipulate market states in ways that are difficult to detect or reverse.
Alice creates an offer using listOffer().
Bob takes the offer, partially fulfilling it.
Alice calls closeOffer(), which sets the offerStatus to Canceled but leaves the stockStatus unchanged.
Alice immediately calls relistOffer(), which sets the offerStatus back to Virgin.
Due to the inconsistent state, Bob's partial fulfillment is not properly accounted for, potentially allowing Alice to relist the offer with more collateral than she should have available.
Manual review
Implement consistent state management:
Improve collateral handling in relistOffer():
Add checks in listOffer() to prevent double-counting of collateral:
Implement reentrancy protection:
Valid low severity due to accounting error, although `stock` status is not update appropriately to `Finished`, there will be no exploit possible given relevant checks on the `offer` side.
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.