Open codehawks-bot opened 1 year ago
This is not the same issue as https://github.com/Cyfrin/2023-07-beedle/issues/1172 because this one is a re-entrancy on the collateral
token transfer.
This can be solved by moving Lines 686-698 at Line 660 which will not solve https://github.com/Cyfrin/2023-07-beedle/issues/1172
There are 2 different re-entrancies in the refinance
function as you can see they allow to steal 2 different tokens (this one allows to steal the collateral
whereas the other one allows to steal the debt
). As you can see in the POCs they are exploited in different ways.
@MiniGlome thanks for the escalation. The issue occurs from the same vulnerability, but the exact attack is different. A fix to one will fix the other, I'm going to leave it as the same issue.
Lender contract can be drained by re-entrancy in
refinance
(collateral)Severity
High Risk
Relevant GitHub Links
https://github.com/Cyfrin/2023-07-beedle/blob/658e046bda8b010a5b82d2d85e824f3823602d27/src/Lender.sol#L670
Summary
Tokens allowing reentrant calls on transfer can be drained from a pool.
Vulnerability Details
Some tokens allow reentrant calls on transfer (e.g.
ERC777
tokens). Example of token with hook on transfer:This kind of token allows a re-entrancy attack in the
refinance
function. When the newcollateral
is less than the current loan collateral, the difference is sent to the borrower before updating the state.https://github.com/Cyfrin/2023-07-beedle/blob/658e046bda8b010a5b82d2d85e824f3823602d27/src/Lender.sol#L670
Impact
POC
An attacker can use the following exploit contract to drain the
lender
contract:Here are the tests that can be added to
Lender.t.sol
to illustrate the steps of an attacker:Tools Used
Manual review + Foundry
Recommendations
Follow the Checks - Effect - Interactions (CEI) pattern by updating the loan variables before transfering the funds AND use nonReentrant modifiers