Outdated penalty fee gets charged if the penalty fee has changed since listing
The unlistVesting function charges the current penalty fee rather than the fee that was in effect when the listing was created. If the penalty fee changes after listing, a user cancelling early may pay a different amount than expected.
Submitted by 0xrex, also found by 0xAkira and aua_oo7
https://github.com/code-423n4/2024-12-secondswap/blob/main/contracts/SecondSwap_Marketplace.sol#L360
Minimum listing duration is currently set at 2 mins, at which point a listing cancellation will no longer incur the fee when unlisted less than 2 minutes since it got listed. However, users can be charged an outdated fee which is more or less the initial fee they expected to pay.
Proof of Concept
function unlistVesting(address _vestingPlan, uint256 _listingId) external isFreeze {
Listing storage listing = listings[_vestingPlan][_listingId];
require(listing.status == Status.LIST, "SS_Marketplace: Listing not active");
require(
listing.seller == msg.sender || msg.sender == IMarketplaceSetting(marketplaceSetting).s2Admin(),
"SS_Marketplace: Not the seller"
);
uint256 _penaltyFee = 0;
if (msg.sender != IMarketplaceSetting(marketplaceSetting).s2Admin()) {
// 3.4. The s2Admin is unable to unlist vesting
if ((listing.listTime + IMarketplaceSetting(marketplaceSetting).minListingDuration()) > block.timestamp) {
require(
(IMarketplaceSetting(marketplaceSetting).usdt()).balanceOf(msg.sender) >=
IMarketplaceSetting(marketplaceSetting).penaltyFee(),
"SS_Marketplace: Penalty fee required for early unlisting"
); // 3.7. Value difference caused by the same penalty fee
(IMarketplaceSetting(marketplaceSetting).usdt()).safeTransferFrom(
msg.sender,
IMarketplaceSetting(marketplaceSetting).feeCollector(), // 3.7. Value difference caused by the same penalty fee
IMarketplaceSetting(marketplaceSetting).penaltyFee()
); // 3.6. DOS caused by the use of transfer and transferFrom functions
@> _penaltyFee = IMarketplaceSetting(marketplaceSetting).penaltyFee();
}
}
IVestingManager(IMarketplaceSetting(marketplaceSetting).vestingManager()).unlistVesting(
listing.seller,
_vestingPlan,
listing.balance
); // 3.4. The s2Admin is unable to unlist vesting
listing.status = Status.DELIST; // 3.3. Buyer can choose listing price
listing.balance = 0; // 3.3. Buyer can choose listing price
emit Delisted(_vestingPlan, _listingId, _penaltyFee, msg.sender);
}
Suppose the user were to pay 2 USDC for unlisting, then the fee changes to 5, they would end up paying twice the initial amount.
Recommended mitigation steps
Having a cache of the fee stored in the listing struct of the listing ID would be sufficient to figure out which fee to charge them.
This should be Medium since the user should be protected from such cases. The user should be able to make an informed decision with a protection mechanism in place. Other than that, the responsibility is on the user.
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 contract reads the penalty fee from the current settings at cancellation time instead of storing the fee that applied when the listing was created.
Impact
A user could be charged a higher or lower penalty fee than the one expected at listing time, depending on how the fee setting changed.
What the attacker needed
A listing created before a fee change; cancelling before minimum duration
The fix
The fee should be cached in the listing struct when the listing is created and used at cancellation.
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.
When you list an item, you agree to a cancellation fee if you remove it too soon. This report says the contract looks up the fee at the moment you cancel, not the fee you saw when you listed. So if the fee goes up in between, you pay more than you agreed to.
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.