Liquidations could revert
Whenever a user is getting liquidated, the following function is called:
This is a part of the function being called:
We can see that we go through the different payments the user has to make, in this case all of his collateral tokens and a liquidation fee. Due to the code, if the user has 2 different collateral tokens deposited with 50 tokens of each and he has to pay 100 tokens, the function will first go through the first collateral, take the tokens and then get the rest from the second collateral token.
Let's imagine the following scenario:
Bob is getting liquidated, he has 100 tokens to pay as the PnL parameter and 50 tokens as liquidation fees
He has 50 tokens of his first collateral token and 50 of his second one
The function first takes his 50 tokens as liquidation fees from the first collateral token and he is left with no amount of it anymore
The function still continues running and we end up in the PnL check (where he has to pay 100 tokens) despite him having no tokens
We end up in this else check as he doesn't have enough tokens for the payment:
amountToTransfer
is 0 as he doesn't have any balance of that collateral
The safeTransfer()
will revert if a revert on zero amount transfer token is used or if any of the allowed tokens upgrade to a new implementation
While the likelihood of that is not high, the impact will be critical as liquidations will fail. We can see that the protocol tried to take care of the case where a user has no balance of a particular token:
However, they do not take care of it when the collateral has been used up after he has paid the liquidation fees. This issue also has an impact now and that is the fact that it does unnecessary computations and function calls when it will have no effect as he doesn't have any collateral (calling withdrawMarginUsd()
, which computes if checks, does calculations, calls withdraw()
, converts tokens, transfers tokens, writes to memory and storage multiple times, reads from storage multiple times). This will make the function much more gas intensive than required.
Liquidations could revert
Manual Review
Whenever you get in an if check and call withdrawMarginUsd()
, check the isMissingMargin
variable and continue if it's true, that means that the collateral was used up.
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.