Pieces Protocol

First Flight #32
Beginner FriendlyFoundrySolidityNFT
100 EXP
View results
Submission Details
Severity: high
Invalid

Limited Payment Options in buyOrder

Summary

The `buyOrder` function is designed to accept payments only in Ether, despite an intention or expectation to allow payment with ERC20 tokens as well. This limitation means users cannot leverage their ERC20 token balances for transactions, potentially reducing the platform's utility and flexibility.

Vulnerability Details

Impact

The exclusivity to Ether payments can lead to the following issues:
1. Reduced Flexibility: Users with only ERC20 tokens cannot participate in transactions, limiting the platform's accessibility and adoption.
2. User Frustration: Users expecting to use ERC20 tokens for payments might encounter errors or confusion when their transactions fail due to unsupported payment methods.
3. Market Limitation: By not accepting ERC20 tokens, the platform misses out on potential liquidity from various token economies, thereby reducing its market reach.
4. Operational Inefficiency: The platform might need to convert tokens to Ether for users, introducing additional complexity, risk, and possibly transaction fees.

Tools Used

Manual Review

Recommendations

Modify the `buyOrder` function to accept both Ether and ERC20 tokens for payment.
Here's how it could be done:
Code Snippet:
```solidity
function buyOrder(uint256 orderIndex, address seller, address paymentToken) external payable {
if (seller == address(0)) {
revert TokenDivider__InvalidSeller();
}
SellOrder memory order = s_userToSellOrders[seller][orderIndex];
if (paymentToken == address(0)) { // Payment with Ether
require(msg.value >= order.price, "Insufficient Ether sent");
// ... existing Ether transfer logic ...
} else { // Payment with ERC20 token
IERC20 token = IERC20(paymentToken);
require(token.allowance(msg.sender, address(this)) >= order.price, "Not enough token allowance");
require(token.transferFrom(msg.sender, address(this), order.price), "Token transfer failed");
// Handle fees with tokens (if applicable)
uint256 fee = order.price / 100;
uint256 sellerFee = fee / 2;
require(token.transfer(seller, order.price - sellerFee), "Transfer to seller failed");
require(token.transfer(owner(), fee), "Transfer of fee failed");
}
balances[msg.sender][order.erc20Address] += order.amount;
s_userToSellOrders[seller][orderIndex] = s_userToSellOrders[seller][s_userToSellOrders[seller].length - 1];
s_userToSellOrders[seller].pop();
emit OrderSelled(msg.sender, order.price);
IERC20(order.erc20Address).transfer(msg.sender, order.amount);
}
```
Updates

Lead Judging Commences

fishy Lead Judge 5 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

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