Exploiting transform() to get free flash loan. #134
Labels
2 (Med Risk)
Assets not at direct risk, but function/availability of the protocol could be impacted or leak value
bug
Something isn't working
downgraded by judge
Judge downgraded the risk level of this issue
duplicate-435
🤖_44_group
AI based duplicate group recommendation
satisfactory
satisfies C4 submission criteria; eligible for awards
sufficient quality report
This report is of sufficient quality
Lines of code
https://github.com/code-423n4/2024-03-revert-lend/blob/435b054f9ad2404173f36f0f74a5096c894b12b7/src/V3Vault.sol#L954
Vulnerability details
Impact
The
V3Vault.transform()
allows users through a verified contract to transform a loan and check the health factor at the end of the function.When
V3Vault.transform()
is called,transformedTokenId
is set totokenId
of the loan to be transformed, and the function performs low-level calls in the data input.This call could be to any function in the vault except for ones where calls from the transformer were explicitly denied with a check(liquidate and decreaseLiquidityAndCollect ).
The
V3Vault.borrow()
, calls are not rejected, and when borrowing in transform mode, loan health is not checked, this makes it possible to borrow undercollateralized loans in transform mode, since the check is only done at the end of the transform function.Malicious users can exploit this to get free flash-loan. Couple with the fact that
repay()
does not have any restriction against transform mode, the loan can be repaid without any interest before control goes back to the transform function where loan health is checked.Proof of Concept
A call through
transform()
toborrow()
the largest possible amount considering available asset, GlobalDebtLimit, dailyDebtIncreaseLimitLeft and collateral threshold.The user uses the asset in the same call and calls repay() with the borrowed amount to return the position to a healthy one in the same transaction.
Since all the transactions are happening in the same block, the loan is repaid with the same
newDebtExchangeRateX96
that the loan was taken, so there is zero interest payment. All that is needed is for a user to have a loan position, even with the minimum acceptable amount.Tools Used
Manual review
Recommended Mitigation Steps
Check if in transform mode in
repay()
and charge a specific interest fee, sincenewDebtExchangeRateX96
cannot be updated twice in a single block.Assessed type
Invalid Validation
The text was updated successfully, but these errors were encountered: