Boost _ Folks Finance 34050 - [Smart Contract - High] Vulnerability in getLoanLiquidity leads to und

Submitted on Sun Aug 04 2024 18:02:43 GMT-0400 (Atlantic Standard Time) by @A2Security for Boost | Folks Finance

Report ID: #34050

Report type: Smart Contract

Report severity: High

Target: https://testnet.snowtrace.io/address/0x2cAa1315bd676FbecABFC3195000c642f503f1C9

Impacts:

  • Protocol insolvency

  • Direct theft of any user funds, whether at-rest or in-motion, other than unclaimed yield

Description

Brief Description

There is a flaw in the implementation of the liquidity calculations for loans where the effective borrow value will be significantly undervalued for stable borrows. Specifically, the getLiquidity() function incorrectly calculates the effective borrow value due to a mistake in the order of indexes when calling balance.calcBorrowBalance(). The getLiquidity() function is crucial because it used at the end of functions that reduces user loan health (including withdraw) to check if loan is healthy .

Impact

Worst case scenario this bug could be used by attacker, to directly steal funds from the protocol, by undervaluing his debt(with accrued interest) and then withdraw a large portion of his collateral (see poc) however this requires enough time untill enough interest is accrued for the balance to be devalued enough for the attacker to be able to withdraw a large amount of his collateral and because of this we think the high severity is fair.

Description

The function calcStableBorrowBalance() is used in getLoanLiquidity() to calculate the effective borrowbalance of a userLoan if he has stable debt. contracts/hub/logic/UserLoanLogic.sol

There is a bug in the order of parameter passed to calcBorrowBalance() leading to the balance being undervalued (Oldindex is divided by newIndex instead of the correct order)

and this is how the calcStableBorrowBalance() is implemented: contracts/hub/logic/UserLoanLogic.sol

Tools Used

Manual Review

Recommended Mitigation Steps: To mitigate this issue simply fix the order of param in calcStableBorrowBalance():

Proof of concept

Proof Of Concept

RESULT:

please first add the following file to test/pocs/base_test.sol

then please add the poc test to test/pocs/forktest.t.sol

Last updated

Was this helpful?