Closed code423n4 closed 1 year ago
Duplicate of #15
Coded POC making it primary
GalloDaSballo marked the issue as primary issue
Because this pertains to a risk that would happen only if triggered by the Admin, and we already have a generic Admin Privilege Report, am downgrading to Low Severity L
Lines of code
https://github.com/code-423n4/2022-12-tigris/blob/main/contracts/Trading.sol#L952-L969 https://github.com/code-423n4/2022-12-tigris/blob/main/contracts/Trading.sol#L163-L210 https://github.com/code-423n4/2022-12-tigris/blob/main/contracts/Trading.sol#L762-L810
Vulnerability details
Impact
When calling the following
Trading.setFees
function to set fees for opening and closing positions, there are no upper limits for these fees. If the owner of theTrading
contract becomes compromised or malicious, this owner can set these fees to be more than 100%. When this happens, as shown below, calling functions likeTrading.initiateMarketOrder
andTrading._handleCloseFees
can revert due to underflowed arithmetic operations caused by the high fees that are more than 100%. It is possible that the fees for opening position are set to normal values but the fees for closing position are set to values that are larger than 100%. In this case, for example, a user can initiate a market order but will fail to initiate closing position for this market order. As a result, this user is forced to lose the deposited margin.https://github.com/code-423n4/2022-12-tigris/blob/main/contracts/Trading.sol#L952-L969
https://github.com/code-423n4/2022-12-tigris/blob/main/contracts/Trading.sol#L163-L210
https://github.com/code-423n4/2022-12-tigris/blob/main/contracts/Trading.sol#L762-L810
Proof of Concept
Please add the following test in the
Trading using <18 decimal token
describe
block intest\07.Trading.js
. This test will pass to demonstrate the described scenario. Please see the comments in this test for more details.Tools Used
VSCode
Recommended Mitigation Steps
In the
Trading.setFees
function, each fee, which would be set, needs to be capped below a sensible upper limit that is less than 100%.