There are two mistakes in the setFlagger function of the LibShortRecord which allows users to delete and claim the flaggerId of other users for themself, even if the flagger id is still valid. This can be misused as griefing attack, as well as to avoid being liquidated.
The setFlagger function of the LibShortRecord.sol contract is used to set and also delete flaggerIds (as flaggerIds can be reused). To check if the id can be reused, the time difference is calculated and compared against the firstLiquidationTime of the CUSD asset:
Here are two mistakes made:
The time difference is checked against the firstLiquidationTime instead of the secondLiquidationTime or resetTime. The firstLiquidationTime is the time when margin callers who flagged a shortRecord for liquidation are able to actually liquidate it. Therefore, if this time is taken to check if the id can be reused, the shorter who is flagged for liquidation can wait till the margin caller would be able to liquidate and instantly reuse, with front running, the id of the margin caller. So that if the margin caller who calls liquidate now will be reverted.
It does not take the firstLiquidationTime of the given asset and instead uses the firstLiquidationTime of the hardcoded CUSD address. As the firstLiquidationTime of assets can differ and can be updated in the OwnerFacet, this could also lead to problems even if the right time would be used.
Inside the MarginCallPrimaryFacet.sol contract, we can see that the hardcoded CUSD address is used:
We can also see that inside the flagShort function the right check is given to prevent the first mistake declared above:
However, this does not prevent the bug, as it checks inside the _canLiquidate function, if the liquidate caller is the flagger and this function looks for the flagger inside the flagMapping, which is updated by the setFlagger function in LibShortRecord.sol:
Therefore, it is possible to call flagShort on another shortRecord to remove the flagger from any wished shortRecord after the firstLiquidationTime.
Users can misuse this as griefing attack, and shorters can avoid being liquidated.
Manual Review
Check if the timeDiff is bigger than the secondLiquidationTime or even the resetTime and check it for the given asset and not for CUSD.
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.