Incorrect listing type validation bypasses enforcement of minimum purchase amount
The marketplace contract validated the minimum purchase amount against the wrong listing type, so the intended range check was applied to single listings instead of partial ones. A seller could therefore create a partial listing with a minimum purchase amount outside the allowed range, defeating the minimum-purchase enforcement.
fyamf Follow with 0xastronatey, 0xKann and 30 others
Originally disclosed on Code4rena
Submitted by fyamf, also found by 0xastronatey, 0xKann, 0xPSB, 4rk4rk, ABAIKUNANBAEV, Abdessamed, AshishLach, aster, BajagaSec, BenRai, Bloqarl, bugvorus, DanielArmstrong, Drynooo, Fitro, honey-k12, ITCruiser, itsabinashb, kimnoic, KupiaSec, lightoasis, Olami978355, oualidpro, peanuts, pontifex, pulse, queen, Sabit, Sabit, shaflow2, tusharr1411, and wickie0x
https://github.com/code-423n4/2024-12-secondswap/blob/main/contracts/SecondSwap_Marketplace.sol#L253
Incorrect validation of the listing type allows bypassing the enforcement of _minPurchaseAmt being within the range of 0 to _amount.
Proof of Concept
A listing can have two types: Single or Partial:
enum ListingType {
PARTIAL,
SINGLE
}
https://github.com/code-423n4/2024-12-secondswap/blob/main/contracts/SecondSwap_Marketplace.sol#L37
For Partial listings, _minPurchaseAmt must be set to ensure buyers cannot purchase less than the specified minimum amount.
However, during the listing of a vesting, _minPurchaseAmt is not validated correctly.
Specifically, the following line is implemented improperly:
require(
_listingType != ListingType.SINGLE || (_minPurchaseAmt > 0 && _minPurchaseAmt <= _amount),
"SS_Marketplace: Minimum Purchase Amount cannot be more than listing amount"
);
https://github.com/code-423n4/2024-12-secondswap/blob/main/contracts/SecondSwap_Marketplace.sol#L253
This implementation mistakenly enforces that for Single listings, _minPurchaseAmt must fall within 0 and _amount. Instead, it should validate _minPurchaseAmt for Partial listings. The corrected implementation is as follows:
require(
_listingType == ListingType.SINGLE || (_minPurchaseAmt > 0 && _minPurchaseAmt <= _amount),
"SS_Marketplace: Minimum Purchase Amount cannot be more than listing amount"
);
With this change, the check ensures that _minPurchaseAmt falls within 0 and _amount for Partial listings, as intended.
Recommended mitigation steps
The validation logic should be updated as follows:
require(
- _listingType != ListingType.SINGLE || (_minPurchaseAmt > 0 && _minPurchaseAmt <= _amount),
+ _listingType == ListingType.SINGLE || (_minPurchaseAmt > 0 && _minPurchaseAmt <= _amount),
"SS_Marketplace: Minimum Purchase Amount cannot be more than listing amount"
);
https://github.com/code-423n4/2024-12-secondswap/blob/main/contracts/SecondSwap_Marketplace.sol#L253
calvinx (SecondSwap) commented:
This looks like a valid issue. Please put as a Medium issue.
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
The require condition used a not-equal comparison against the SINGLE listing type, so the minimum purchase amount range check was applied to single listings rather than partial listings.
Impact
For partial listings the minimum purchase amount could be set outside the intended range, so buyers could purchase less than the seller's stated minimum, breaking the marketplace's partial-purchase rules.
What the attacker needed
Ability to create a listing; listing type set to partial
The fix
The comparison should be changed to equality against the SINGLE listing type so the range check applies to partial listings.
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 listing can be sold all at once or in pieces. For piece-by-piece sales, the seller must set a smallest amount a buyer can take, and the contract is meant to check that this smallest amount is sensible. The check was written against the wrong kind of listing, so that safety check never ran where it mattered.
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.