Incorrect calculation of new price while adding position #236
Labels
3 (High Risk)
Assets can be stolen/lost/compromised directly
bug
Something isn't working
edited-by-warden
H-06
primary issue
Highest quality submission among a set of duplicates
selected for report
This submission will be included/highlighted in the audit report
sponsor confirmed
Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
Lines of code
https://github.com/code-423n4/2022-12-tigris/blob/588c84b7bb354d20cbca6034544c4faa46e6a80e/contracts/Trading.sol#L295
Vulnerability details
Impact
The formula used for calculating
_newPrice
inaddToPosition()
function of Trading.sol is not correct, users will lose part of their funds/profit while using this function.The wrong formula
The correct formula is
Why this workS?
Given
Then
proven.
Proof of Concept
The following test case shows two examples that users lose some funds due to add new position whenever their existing position is in profit or loss state.
The test result
Tools Used
hardhat
Recommended Mitigation Steps
Use the correct formula, the following test case is for the same above examples after fix.
The test result
The text was updated successfully, but these errors were encountered: