When calling buyLoan it is not checking the pool which contains the collateral token that matches the loan token collateral. This can cause damage since the code is assuming that the loan collateral token is equal to the pool collateral token so it is not updating it. So when repaying the function repay has this code:
but since the loan.collateralToken of the pool now is different than the loan token which has not been updated it will cause the poolId is not found.
Example:
Assume we have a lender called Bob with Alice as a borrower, the loan has loanToken
as TOKEN_1
and collateralToken
as TOKEN_2
, at this point the pool Id looks something similar to keccak256(abi.encode(Bob's address, TOKEN_1, TOKEN_2))
. For whatever reason, Bob decides to "startAuction" on Alice's loan. The auction will allow anyone with "a pool with tokens" to buy this loan. Now, we have a new lender called Charlie with a pool with TOKEN_3
as loanToken
and TOKEN_4
as collateralToken
. Charlie wants to buy Alice's loan, so he will call buyLoan
, buyLoan
function doesn't validate if the tokens are matched, this will allow Alice's loan to be moved to a pool that has different tokens than the original loan, which for now is bypassing the validation of the tokens. Now, Alice's loan belongs to a pool of pool Id of keccak256(abi.encode(Charlie's address, TOKEN_1, TOKEN_2))
, which technically doesn't exist in pools
mapping. Now when "poor" Alice wants to repay her loan she will call it repay
, but this will fail on every instance of pools[poolId]
because poolId
doesn't exist in pools
mapping, according to what's said before. Now the loan is messed up, Alice can't repay her loan, and her collateral is stuck in the "imaginary" pool. This is a straightforward example, but it can be used to create a more complex attack.
Pool will not be found causing the collateral token to be stuck. So if a user buy loan and then the borrower decided to repay he will not be able and the attacker can force to get the borrower collateral.
Manual Review
Check that the collateral/loan tokens of the pool that is buying the Loan is equal to the loan's.
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.