Attackers can buyLoan
with worthless ERC20
tokens due to missing checks for token mismatches, which leads to the borrower's collateral becoming locked.
The problem with the buyLoan function is that it lacks a check to ensure whether the tokens of the new pool mismatch with those of the old pool (similar to the giveLoan function).
This scenario can be exploited as follows:
Bob is the lender, Mallory is the borrower, and Eve is the attacker.
Bob calls setPool to create a pool with loanToken: WETH
and collateralToken: DAI
.
Mallory decides to take a loan from Bob's pool and proceeds by calling borrow, which transfers the DAI
tokens into the protocol and transfer her the corresponding amount of WETH
.
At a later point, Bob decides to sell Mallory's loan to retrieve his WETH
tokens, so he calls startAuction.
Recognizing an opportunity, Eve deploys a malicious ERC20
token (let's call it ATR
), which is worthless. Subsequently, she uses this token and calls setPool to create a new pool with loanToken: ATR
and collateralToken: DAI
As a result, Eve can now buy Mallory's loan from Bob's auction, causing the loan's loanToken
to be set to her malicious token address. This is possible because the contract lacks a check for tokens mismatch.
Add this test in the Lender.t.sol
The borrower is unable to retrieve his collateral because it becomes locked in a non-existent pool.
Manual review, Foundry
Add the following check-in buyLoan
https://github.com/Cyfrin/2023-07-beedle/blob/main/src/Lender.sol#L487
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.