Pieces Protocol

First Flight #32
Beginner FriendlyFoundrySolidityNFT
100 EXP
View results
Submission Details
Severity: low
Valid

buyOrder Function Preventing Return of Extra ETH to msg.sender

Summary

The buyOrder function in the provided smart contract has a bug that prevents any excess Ether (ETH) sent by the buyer from being returned. Specifically, when the buyer sends more ETH than the required order.price + sellerFee, the function does not handle returning the excess amount. As a result, the extra ETH is simply consumed without refunding it to the buyer.

Vulnerability Details

In the buyOrder function, there is no logic to return excess Ether sent by the buyer. The contract checks if the sent Ether is enough to cover the order price and the seller’s fee but does not account for any extra Ether. If the buyer overpays, the additional Ether is not refunded and is effectively lost.

Impact

The vulnerability can lead to financial loss for buyers who unintentionally send more Ether than needed for the transaction. The extra Ether is consumed without any refund mechanism, which can negatively affect user experience and trust in the contract.

Tools Used

Manual code review

Recommendations

Add a mechanism to refund any excess Ether sent by the buyer. After transferring the required Ether to the seller and owner, check for any remaining balance and transfer it back to the buyer.

uint256 excessETH = msg.value - (order.price + sellerFee);
if (excessETH > 0) {
(bool refundSuccess, ) = payable(msg.sender).call{value: excessETH}("");
if (!refundSuccess) {
revert TokenDivider__RefundFailed();
}
}
Updates

Lead Judging Commences

fishy Lead Judge 5 months ago
Submission Judgement Published
Validated
Assigned finding tags:

Token misshandling

The extra eth sent by the user in the buy order will be locked in the contract forever

Support

FAQs

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