Comptroller.healAccount doesn’t distribute rewards for a healed borrower
The Comptroller.healAccount function seizes collateral and clears debt but does not distribute rewards earned by the borrower before healing. As a result, the healed account loses the rewards it had accrued on its debt.
Originally disclosed on Code4rena
Submitted by rvierdiiev.
As a result, the healed account receives less rewards.
Proof of Concept
Comptroller.healAccount can be called by anyone in order to fully close accounts. The healer should repay part of account’s debt in order to receive all account’s collateral. At the end account debt will be cleared.
This is the part when collateral is seized and debt is cleared: https://github.com/code-423n4/2023-05-venus/blob/main/contracts/Comptroller.sol#L611-L625
for (uint256 i; i < userAssetsCount; ++i) {
VToken market = userAssets[i];
(uint256 tokens, uint256 borrowBalance, ) = _safeGetAccountSnapshot(market, user);
uint256 repaymentAmount = mul_ScalarTruncate(percentage, borrowBalance);
// Seize the entire collateral
if (tokens != 0) {
market.seize(liquidator, user, tokens);
}
// Repay a certain percentage of the borrow, forgive the rest
if (borrowBalance != 0) {
market.healBorrow(liquidator, user, repaymentAmount);
}
}
In order to seize the collateral, market.seize is called, which will then call comptroller.preSeizeHook. And this hook will distribute supply rewards to both accounts.
In order to clear, healed account debt market.healBorrow is called. This function will not call any comptroller function. As a result, the debt of the healed account is set to 0, but rewards that were earned by the account before healing were not distributed. So the user lost rewards for that debt amount.
Tools Used
VsCode
Recommended Mitigation Steps
Comptroller should distribute rewards to this account that were earned before and only then set debt to 0.
Will leave open for sponsor comment, I think this would amount to dust given the state of the user’s account.
@chechu - can you confirm this has more impact than just dust amounts?
@chechu - can you confirm this has more impact than just dust amounts?
It can be more than dust amounts. I can imagine a user position like this:
- Collateral:
$1M (just with one asset)- Borrow:
$500K (healthy, generating a significant amount of borrow rewards if no one interacts with this account for a long time)Then, a black swan happens and the collateral value moves from
$1M to$20, so anyone could invoke thehealAccountfunction, repaying part (no more than$20) of the loan.The current implementation is not distributing the borrow rewards to the borrower, and given the big amount it could be significant. The key point here is, the borrow rewards depend on the loan, not on the collateral (that will be very low, I agree).
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
Impact
The healed account loses the borrow rewards it earned before healing; the judge initially thought this would be dust, but the sponsor noted it could be significant if the borrow was large and had accrued rewards over a long time.
What the attacker needed
A borrow position with accrued rewards; anyone can call healAccount
The fix
The Comptroller should distribute rewards to the account that were earned before setting the debt to zero.
How it was found
- A user has a borrow position that has accrued rewards over time.
- Anyone calls Comptroller.healAccount on that user.
- The function seizes the user's collateral via market.seize, which distributes supply rewards.
- The function clears the user's debt via market.healBorrow, which does not distribute borrow rewards.
- The user's debt is set to zero without distributing the rewards earned on that debt.
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.
When you borrow money in a lending system, you often earn rewards over time. The healAccount function lets someone else close your loan by repaying part of it and taking your collateral. But this function forgets to give you the rewards you earned before the loan was closed, so you lose them.
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.