withdrawMarginUsd()
has rounding errors in calculating the amount of withdrawal tokens.
The relavant code of TradingAccount.withdrawMarginUsd()
is following.
As shown above, the function rounds down the requiredMarginInCollateralX18
in L448
and then it is used to withdraw collaterals in L452
.
Since the requiredMarginInCollateralX18
is deducted from the user's balance, it should round up in order to be in favor of the protocol.
Although the amount of rounding error is small, withdrawMarginUsd()
is called frequently in the protocol.
Calculating in a way that is not in favor of the protocol may cause a lack of collateral tokens to the protocol.
Manual Review
It is recommended to use rounding up in calculation.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.