Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Damp Jade Wasp - Incorrect order execution in Bracket::checkInRange function #885

Open
sherlock-admin3 opened this issue Dec 9, 2024 · 1 comment

Comments

@sherlock-admin3
Copy link
Contributor

Damp Jade Wasp

High

Incorrect order execution in Bracket::checkInRange function

Summary

The checkInRange function is designed to determine whether the current exchange rate falls within the specified range defined by the takeProfit and stopPrice parameters. This logic relies on the direction variable, which is set during order creation by comparing the initial exchange rate with the takeProfit value. If direction is true, it indicates that the exchange rate at the time of order creation was greater than the takeProfit value; otherwise, it is false.

While the logic works as expected when direction is false, it fails when direction is true. In such cases, the function incorrectly executes the order when the exchange rate is lower than the takeProfit value. This behavior contradicts the intended functionality, as the order should only execute when the exchange rate is greater than or equal to the takeProfit value or when it meets the stop-loss condition (exchangeRate >= order.stopPrice).

Root Cause

https://github.com/sherlock-audit/2024-11-oku/blob/ee3f781a73d65e33fb452c9a44eb1337c5cfdbd6/oku-custom-order-types/contracts/automatedTrigger/Bracket.sol#L595-L598

Internal pre-conditions

No response

External pre-conditions

No response

Attack Path

No response

Impact

This flawed implementation creates a scenario where orders are triggered prematurely or inaccurately when direction is true,

PoC

No response

Mitigation

-    if (exchangeRate <= order.takeProfit)
+    if (exchangeRate <= order.takeProfit)
@bugvorus
Copy link

@sherlock-admin
when direction== true, the current logic implementation leads to missed trade execution. How can this be invalid?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants