OrderBook

First Flight #43
Beginner FriendlySolidity
100 EXP
View results
Submission Details
Impact: medium
Likelihood: medium
Invalid

Missing balance check in createSellOrder function may cause order creation failure

Root + Impact

function createSellOrder

Description

  • In the createSellOrder function, there is no explicit check to verify whether the seller (msg.sender) has a sufficient token balance of _tokenToSell before creating the order. Although the safeTransferFrom call will revert if the balance or allowance is insufficient, this check should be performed earlier to provide clearer error handling and prevent unnecessary transaction failures.

function createSellOrder(
address _tokenToSell,
uint256 _amountToSell,
uint256 _priceInUSDC,
uint256 _deadlineDuration
) public returns (uint256) {
if (!allowedSellToken[_tokenToSell]) revert InvalidToken();
if (_amountToSell == 0) revert InvalidAmount();
//add this
if (_amountToSell > IERC20(_tokenToSell).balanceOf(msg.sender)) revert InvalidAmount();
// Seller must have enough tokens
if (_priceInUSDC == 0) revert InvalidPrice();
if (_deadlineDuration == 0 || _deadlineDuration > MAX_DEADLINE_DURATION) revert InvalidDeadline();

Risk

Likelihood:

A user attempts to create a sell order for more tokens than they currently hold in their wallet.

The transaction proceeds until the token transfer is attempted, causing a revert at the transfer step rather than failing earlier.

Impact:

Impact:

The transaction reverts unexpectedly during token transfer, leading to wasted gas fees and a poor user experience due to lack of clear feedback.

Potential for increased failed transactions on the network, affecting overall contract usability.

Proof of Concept

// User calls createSellOrder with _amountToSell greater than their token balance
contract.callCreateSellOrder(tokenAddress, userTokenBalance + 1, priceInUSDC, deadlineDuration);

Recommended Mitigation

- remove this code
+ add this code
+ if (_amountToSell > IERC20(_tokenToSell).balanceOf(msg.sender)) revert InvalidAmount(); // Ensure user has enough tokens before proceeding
Updates

Lead Judging Commences

yeahchibyke Lead Judge
4 months ago
yeahchibyke Lead Judge 4 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.