The sellErc20
function is vulnerable to Denial of Service (DoS) attacks because it relies on the transferFrom
function of an ERC20 token to transfer tokens to the contract. If the transferFrom
call fails (e.g., due to a non-compliant ERC20 token that returns false instead of reverting), the function will not revert, and the sell order will remain in an inconsistent state. This could make the function unusable for certain tokens.
The issue lies in the following section of the sellErc20 function:
The sellErc20 function relies on the transferFrom function of an ERC20 token to transfer tokens to the contract. However, it does not check the return value of transferFrom or handle failures properly. If the transferFrom call fails (e.g., due to a non-compliant ERC20 token that returns false instead of reverting), the function will not revert, and the sell order will remain in an inconsistent state. This can lead to a Denial of Service (DoS) attack, where the function becomes unusable for certain tokens, and the contract state (e.g., balances and sell orders) may become corrupted.
Medium Impact: If the transferFrom call fails, the sell order will be created, but the tokens will not be transferred to the contract. This leaves the contract in an inconsistent state and could prevent users from creating valid sell orders.
Users may lose trust in the platform if they cannot reliably create sell orders.
Manual Review, Foundry
To prevent DoS attacks, add a mechanism to handle non-compliant tokens or allow users to cancel orders. Here’s an example of how to implement this:
Check the Return Value of transferFrom
:
Ensure the function reverts if the transferFrom call fails.
Allow Users to Cancel Orders:
Add a function to cancel sell orders if the transferFrom call fails.
The return value check ensures that the function reverts if the transferFrom call fails, preventing inconsistent states.
The cancel order mechanism allows users to recover their tokens if the transferFrom call fails, improving the user experience.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.