sherlock-audit / 2023-06-dinari-judging

5 stars 4 forks source link

DevABDee - The absence of a price threshold option for users can result in users obtaining assets at unexpected & undesired prices. #98

Closed sherlock-admin closed 1 year ago

sherlock-admin commented 1 year ago

DevABDee

medium

The absence of a price threshold option for users can result in users obtaining assets at unexpected & undesired prices.

Summary

Buying/Selling of dShares (stock assets) is a 2-step process. (1) Users first submit a buy/sell order and (2) then the Operator executes that order. However, due to potential price fluctuations between these steps, users may experience losses if the price of dShares changes unfavorably.

Vulnerability Detail

Dinari enables the buying and selling of Stock Assets (dShares Tokens). Users can purchase dShares by placing a Market Order, which involves a 2-step process. First, users submit a buy/sell order, and then the Operator fulfills/executes that order. However, if there is a delay in the Operator's execution, users may receive the dShares at an undesired or unexpected price due to price fluctuations.

Delays can occur, that's why requestCancel() order functionality exists. Primarily It can happen in these two cases:

  1. Very Large Order: When a user places a large order, the Operator executes it in partial steps.
  2. Orders placed outside of the US Trading hours: Outside of US trading hours, Orders are filled in the next trading session.

PoC:

Scenario 1: (In the case of Partial executions of the large orders)

Scenario 2: (In the case when a user puts an order outside of the US Trading hours)

Note: Scenario 1 >>>>> Scenario 2. I believe that in Scenario 2, the responsibility lies more with the user. The protocol already discourages and provides warnings against trading outside of the US Trading hours. However, in Scenario 1, the fault primarily lies with the protocol itself, as it may have limitations or disabilities that can potentially lead to losses for the user.

Impact

Code Snippet

https://github.com/sherlock-audit/2023-06-dinari/blob/4851cb7ebc86a7bc26b8d0d399a7dd7f9520f393/sbt-contracts/src/issuer/OrderProcessor.sol#L244 https://github.com/sherlock-audit/2023-06-dinari/blob/4851cb7ebc86a7bc26b8d0d399a7dd7f9520f393/sbt-contracts/src/issuer/OrderProcessor.sol#L272

Tool used

Shaheen's Vision

Recommendation

The protocol should provide users with the ability to establish a risk threshold. This can be achieved through two options:

  1. Allowing users to set minimum and maximum price limits for the fluctuating asset that they are willing to accept.
  2. Enabling users to define a percentage-based risk threshold, such as 1% to 2%.

If the price of the asset goes beyond the user-defined limit or threshold, the Operator should not execute that order, either in full or partially. This would help mitigate unexpected price fluctuations and protect users from potential losses.