Unsafe down-casting from uint256 to uint88 can lead to under-reporting of m.short.ercDebt inside _performForcedBid() while performing a primary margin call.
The calculation inside _performForcedBid():
The data types of these variables are:
The unsafe casting of uint256 to uint88 can cause truncation of the value and hence the real ercDebt, as shown in the following PoC. This reduced m.short.ercDebt causes an increased ercDebtSocialized in Line 232.
Create a new file under test/ folder named MathCastingPerformForcedBid.t.sol and run the following code via forge test --mt test_casting_performForcedBid -vv:
Output:
ercDebt256 is the actual value while ercDebt88 is the truncated one used by the protocol.
Higher ercDebtSocialized to other users and hence loss of funds for them.
This also throws off other calculations since lesser ercAmount is filled than expected via the forced bid.
Manual inspection, forge test.
It is recommended to specify a correct upper limit for these values using a require() statement inside the function, so that they do not eventually overflow on performing arithmetic operations but instead revert at the start itself.
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.