Use of tokenB’s price instead of tokenA in determining account health will lead to protocol mis-accounting and insolvency
A typo in the lending protocol's code caused the wrong token price to be used when calculating a user's supply balance, leading to incorrect account health assessments. This could result in protocol insolvency because all borrows, withdrawals, transfers, and liquidations rely on this miscalculation.
Submitted by 0xRajeev, also found by WatchPug.
Impact
In _supplyCreditUni(), the last argument of _convertTokenValues() on L674 being _priceB instead of _priceA in the calculation of supplyB is a typo (should be _priceA) and therefore miscalculates supplyB, creditB, creditUni and therefore totalAccountSupply in function accountHealth() which affects the health of account/protocol determination that is used across all borrows/withdrawals/transfers/liquidations in the protocol. This miscalculation significantly affects all calculations in protocol and could therefore cause protocol insolvency.
Proof of Concept
- https://github.com/code-423n4/2021-09-wildcredit/blob/c48235289a25b2134bb16530185483e8c85507f8/contracts/LendingPair.sol#L674
- https://github.com/code-423n4/2021-09-wildcredit/blob/c48235289a25b2134bb16530185483e8c85507f8/contracts/LendingPair.sol#L340
- https://github.com/code-423n4/2021-09-wildcredit/blob/c48235289a25b2134bb16530185483e8c85507f8/contracts/LendingPair.sol#L398-L401
- https://github.com/code-423n4/2021-09-wildcredit/blob/c48235289a25b2134bb16530185483e8c85507f8/contracts/LendingPair.sol#L532
- https://github.com/code-423n4/2021-09-wildcredit/blob/c48235289a25b2134bb16530185483e8c85507f8/contracts/LendingPair.sol#L544
- https://github.com/code-423n4/2021-09-wildcredit/blob/c48235289a25b2134bb16530185483e8c85507f8/contracts/LendingPair.sol#L119
- https://github.com/code-423n4/2021-09-wildcredit/blob/c48235289a25b2134bb16530185483e8c85507f8/contracts/LendingPair.sol#L266
- https://github.com/code-423n4/2021-09-wildcredit/blob/c48235289a25b2134bb16530185483e8c85507f8/contracts/LendingPair.sol#L289
Tools Used
Manual Analysis
Recommended Mitigation Steps
Change the last argument of \_convertTokenValues() from \_priceB to \_priceA on L674.
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
This miscalculation could cause protocol insolvency because it affects all borrows, withdrawals, transfers, and liquidations.
What the attacker needed
None
The fix
The last argument of `_convertTokenValues()` should be changed from `_priceB` to `_priceA` on line 674.
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, the system must correctly calculate how much each user has supplied and borrowed to decide if they are safe. Here, a simple mistake used the wrong token's price when valuing a user's supply, so the system could think users are safer or riskier than they really are. This could let people borrow too much or cause the protocol to lose money.
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.