liquidateAccount will fail if the transaction is not included in the current block
The liquidateAccount function requires the repaid amount to exactly equal the borrower's borrow balance, which grows every block as interest accrues. A liquidator whose transaction lands in a later block than expected will have the call revert, so liquidations fail and must be retried.
Submitted by xuwinnie, also found by Udsen, mussucal and BoltzmannBrain.
Functon liquidateAccount will fail if the transaction is not included in the current block because interest accrues per block, and repayAmount and borrowBalance need to match precisely.
Proof of Concept
At the end of the function liquidateAccount, a check is performed to ensure that the borrowBalance is zero:
for (uint256 i; i < marketsCount; ++i) {
(, uint256 borrowBalance, ) = _safeGetAccountSnapshot(borrowMarkets[i], borrower);
require(borrowBalance == 0, "Nonzero borrow balance after liquidation");
}
This means that repayAmount specified in calldata must exactly match the borrowBalance call. (If repayAmount is greater than borrowBalance, Comptroller.preLiquidateHook will revert with the error TooMuchRepay.) However, the borrowBalance updates every block due to interest accrual. The liquidator cannot be certain that their transaction will be included in the current block or in a future block. This uncertainty significantly increases the likelihood of liquidation failure.
Recommended Mitigation Steps
Use a looser check:
snapshot = _getCurrentLiquiditySnapshot(borrower, _getLiquidationThreshold);
require (snapshot.shortfall == 0);
to replace:
for (uint256 i; i < marketsCount; ++i) {
(, uint256 borrowBalance, ) = _safeGetAccountSnapshot(borrowMarkets[i], borrower);
require(borrowBalance == 0, "Nonzero borrow balance after liquidation");
}
Assessed type
Invalid Validation
chechu (Venus) confirmed via duplicate issue #545
chechu (Venus) disagreed with severity and commented:
Suggestion: QA (no risk for funds, no risk of DoS).
The liquidator has to take into account the pending interests to be accrued before invoking
liquidateAccount. It’s technically feasible and if the TX fails, they can retry it, so finally the position will be liquidated. The amount to be liquidated will be very low, so we don’t see any risk of front running.
0xean (judge) decreased severity to Medium and commented:
They would have to know which block specifically their transaction would get mined in to be able to precompute this.
While they could retry the transaction, I do think this will have an impact of the protocol’s availability under normal conditions and therefore does meet the criteria for Medium severity.
They would have to know which block specifically their transaction would get mined in to be able to precompute this.
While they could retry the transaction, I do think this will have an impact of the protocol’s availability under normal conditions and therefore does meet the criteria for Medium severity.
@0xean - The liquidator can calculate the exact needed amount in a contract; for example, to guarantee that the amount is valid in the same block where the transaction will be minted.
@chechu - I agree, that is possible, but how does one do this from an EOA?
@chechu - I agree, that is possible, but how does one do this from an EOA?
@0xean - with an EOA I would do a multicall, first statically invoking the functions to accrue interest, and then invoking the function to get the precise borrow amounts. You could use https://www.npmjs.com/package/ethereum-multicall to do this. We do something similar in our frontend here.
By doing this, it’s true that your TX may not be included in the current block and it won’t be valid in the next one.
Yeah, this seems like a workaround to the problem, in my opinion. Why would you be opposed to simply updating the function to make it more tolerant to the specific block it’s called in?
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the final check demands an exact zero borrow balance rather than checking that the account is no longer in shortfall, so any interest accrued between preparation and inclusion breaks the match.
Impact
Liquidations can revert when the transaction is not mined in the block the amount was computed for, which the judge said impacts the protocol's availability under normal conditions; the sponsor argued a contract or multicall can compute the amount and retry.
What the attacker needed
Liquidator submits a liquidation; transaction mined in a later block
The fix
The check should be loosened to verify the account's liquidity snapshot shows no shortfall instead of requiring a zero borrow balance.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
In a lending protocol, a borrower's debt slowly grows over time as interest is added. This function insists the liquidator repay the debt to the exact last unit, but the debt changes every block, so a transaction prepared for one block often fails in the next. The liquidator then has to try again.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.