The amendSellOrder function contains a reentrancy vulnerability when the seller reduces the amount of tokens in their sell order. The function performs an external call (safeTransfer) to return excess tokens to the seller before updating the order state, violating the checks-effects-interactions pattern.
In the above snippet:
If the token.safeTransfer(...) is called on a malicious contract that implements a fallback or onERC20Received hook, it can re-enter the amendSellOrder() function or other functions of the contract.
This would allow manipulation of contract state in an inconsistent state, potentially leading to loss of funds or bypass of validation logic.
Attacker creates a sell order with 100 tokens.
Attacker amends the order, reducing to 10 tokens.
The protocol tries to send back 90 tokens before updating the order state.
Attacker’s contract uses receive() to re-enter and calls cancelOrder() or amendSellOrder() again.
State is not yet updated, leading to possible double-withdrawals or state corruption.
Update states before external call
High
This is a classic reentrancy pattern that can lead to:
Inconsistent order states
Multiple token withdrawals
Potential fund theft if other logic relies on state assumptions
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.