Boost _ Folks Finance 33817 - [Smart Contract - High] Incorrect calculation of effective borrow value in getLoanLiquidity leads to protocol insolvency through wrong withdrawals and liquidations
Submitted on Tue Jul 30 2024 04:21:26 GMT-0400 (Atlantic Standard Time) by @zarkk for Boost | Folks Finance
Report ID: #33817
Report type: Smart Contract
Report severity: High
Target: https://testnet.snowtrace.io/address/0xf8E94c5Da5f5F23b39399F6679b2eAb29FE3071e
Impacts:
Protocol insolvency
Description
Brief/Intro
Effective stable borrow value is calculated incorrectly with stable borrow balance to be decreasing instead of increasing, leading to protocol insolvency due to under-collateralized loan acceptance and wrong liquidations.
Vulnerability Details
When a withdrawal or a liquidation is about to happen in Folks Finance, the collateralization of the UserLoan
is checked through the getLoanLiquidity
function which returns the effective borrow value
and the effective collateral value
of a UserLoan
. We can see the implementation here :
However, if we deep on the calculations of stable borrow balance, we will see that they are done incorrectly. In order to calculate the stable borrow balance, calcStableBorrow
function is called passing the current debt (loanBorrow.balance
), the current interest index(loanBorrow.lastInterestIndex
), the current interest rate (loanBorrow.stableInterestRate
) and the time passed since the last update. This happens in order to update the interest index and then the debt to be updated also, so to reflect the present. Let's see how calcStableBorrowBalance
is implemented :
The stableborrowInterestIndex
is the new updated interest index which is supposed to inflate the balance
. However, as we see in the calcBorrowBalance
, due to wrong order of parameters, the balance
is decreased instead of increased. Here, is the calcBorrowBalance
of MathUtils
which expects as second parameter the new interest index and as third parameter the old interest index.
However, the parameters are passed in the opposite order and a deflated balance (debt) is returned. As a result, the UserLoan
seems to have less debt than what really has.
Impact Details
This vulnerability leads, eventually and rapidly, to the insolvency of Folks Finance. Firstly, as demonstrated in the Proof of Concept (PoC), users are able to withdraw collateral from their loans, leaving them under-collateralized. This can have catastrophic effects for the protocol as it accrues bad debt. Secondly, it prevents legitimate liquidations from happening since the debt of the violator seems smaller than it actually is. The combined effect of these issues can lead to a cascading failure of the lending system, where the protocol cannot cover the borrowed amounts with the available collateral, ultimately leading to insolvency and significant financial losses for both the protocol and its users.
References
https://github.com/Folks-Finance/folks-finance-xchain-contracts/blob/fb92deccd27359ea4f0cf0bc41394c86448c7abb/contracts/hub/logic/UserLoanLogic.sol#L387
Proof of concept
Proof of Concept
To understand better this critical vulnerability, add this test under the "Withdraw" test suite of
LoanManager.test.tsand run
npm run test``` :
Last updated
Was this helpful?