Fail to accrue interests on multiple token positions
The bank's execute function checks whether a position is liquidatable using debt values that are only updated for the token involved in the action, not for all tokens in the position. An attacker could perform actions that leave their position virtually liquidatable without reverting, worsening the bank's debt situation.
cducrest-brainbot Follow with rvierdiiev and Jeiwan
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2023-02-blueberry-judging/issues/140
Found by
cducrest-brainbot, rvierdiiev, Jeiwan
Summary
In BlueBerryBank.sol the functions borrow, repay, lend, or withdrawLend call poke(token) to trigger interest accrual on concerned token, but fail to do so for other token debts of the concerned position. This could lead to wrong calculation of position's debt and whether the position is liquidatable.
Vulnerability Detail
Whether a position is liquidatable or not is checked at the end of the execute function, the execution should revert if the position is liquidatable.
The calculation of whether a position is liquidatable takes into account all the different debt tokens within the position. However, the debt accrual has been triggered only for one of these tokens, the one concerned by the executed action. For other tokens, the value of bank.totalDebt will be lower than what it should be. This results in the debt value of the position being lower than what it should be and a position seen as not liquidatable while it should be liquidatable.
Impact
Users may be able to operate on their position leading them in a virtually liquidatable state while not reverting as interests were not applied. This will worsen the debt situation of the bank and lead to overall more liquidatable positions.
Code Snippet
execute checking isLiquidatable without triggering interests:
https://github.com/sherlock-audit/2023-02-blueberry/blob/main/contracts/BlueBerryBank.sol#L607
actions only poke one token (here for borrow):
https://github.com/sherlock-audit/2023-02-blueberry/blob/main/contracts/BlueBerryBank.sol#L709-L715
bank.totalDebt is used to calculate a position's debt while looping over every tokens:
https://github.com/sherlock-audit/2023-02-blueberry/blob/main/contracts/BlueBerryBank.sol#L451-L475
The position's debt is used to calculate the risk:
https://github.com/sherlock-audit/2023-02-blueberry/blob/main/contracts/BlueBerryBank.sol#L477-L495
The risk is used to calculate whether a debt is liquidatable:
https://github.com/sherlock-audit/2023-02-blueberry/blob/main/contracts/BlueBerryBank.sol#L497-L505
Tool used
Manual Review
Recommendation
Review how token interests are triggered. Probably need to accrue interests on every debt token of a position at the beginning of execute.
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 execute function checks liquidatability without first accruing interest on every debt token of the position, so stale debt values are used.
Impact
Users may be able to operate on their position leading them in a virtually liquidatable state while not reverting as interests were not applied, worsening the bank's debt situation.
What the attacker needed
A position with multiple debt tokens
The fix
The recommendation is to accrue interest on every debt token of a position at the beginning of execute.
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 system, interest builds up over time on what you owe. Before checking if a borrower is in trouble (liquidatable), the system should update the interest on all their debts. Here, it only updates one debt, so the check underestimates what the borrower owes and may wrongly allow them to keep borrowing.
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.