OrderBook

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

Reentrancy Vulnerability in amendSellOrder() Function

Summary

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.

Vulnerability Details

if (_newAmountToSell < order.amountToSell) {
uint256 diff = order.amountToSell - _newAmountToSell;
token.safeTransfer(order.seller, diff); // external call
}
// State update happens *after*
order.amountToSell = _newAmountToSell;
order.priceInUSDC = _newPriceInUSDC;
order.deadlineTimestamp = newDeadlineTimestamp;

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.

Exploit Scenario

  • 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.

Recommended Mitigation

  • Update states before external call

Severity

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

Updates

Lead Judging Commences

yeahchibyke Lead Judge about 1 month ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement

Support

FAQs

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