DeFiFoundry
60,000 USDC
View results
Submission Details
Severity: medium
Invalid

Contradiction Between Comment and Code Logic in fillOffchainOrders Function

Summary

The fillOffchainOrders function contains a comment explaining the logic for validating fill prices based on whether the order is a buy or sell order. However, the actual code logic contradicts the comment, which may lead to confusion and potential errors in the order validation process.

Vulnerability Details

Comment:

// if the order increases the trading account's position (buy order), the fill price must be less than or
// equal to the target price, if it decreases the trading account's position (sell order), the fill price
// must be greater than or equal to the target price.

Code:

ctx.isFillPriceValid = (ctx.isBuyOrder && ctx.offchainOrder.targetPrice <= ctx.fillPriceX18.intoUint256())
|| (!ctx.isBuyOrder && ctx.offchainOrder.targetPrice >= ctx.fillPriceX18.intoUint256());

Contradiction:

  • Comment: For a buy order, the fill price should be less than or equal to the target price.

  • Code: For a buy order, the fill price is valid if it is greater than or equal to the target price (ctx.offchainOrder.targetPrice <= ctx.fillPriceX18.intoUint256()).

  • Comment: For a sell order, the fill price should be greater than or equal to the target price.

  • Code: For a sell order, the fill price is valid if it is less than or equal to the target price (ctx.offchainOrder.targetPrice >= ctx.fillPriceX18.intoUint256()).

Impact

This discrepancy between the comment and the code can lead to:

  • Incorrect validation of fill prices for both buy and sell orders.

  • Potential execution of trades at invalid prices, causing financial losses.

  • Confusion among developers and auditors, leading to difficulty in maintaining and auditing the code.

Tools Used

Manual code review

Recommendations

Correct the Comment or Code Logic: Align the comment with the actual code logic or update the code to match the intended logic described in the comment. For example, if the comment is correct, the code should be:

ctx.isFillPriceValid = (ctx.isBuyOrder && ctx.offchainOrder.targetPrice >= ctx.fillPriceX18.intoUint256())
|| (!ctx.isBuyOrder && ctx.offchainOrder.targetPrice <= ctx.fillPriceX18.intoUint256());
Updates

Lead Judging Commences

inallhonesty Lead Judge
over 1 year ago
inallhonesty Lead Judge over 1 year ago
Submission Judgement Published
Invalidated
Reason: Too generic

Support

FAQs

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

Give us feedback!