Sandwich attack on loan fulfillment will temporarily prevent users from accessing their borrowed funds #152
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
M-08
primary issue
Highest quality submission among a set of duplicates
🤖_primary
AI based primary recommendation
🤖_07_group
AI based duplicate group recommendation
satisfactory
satisfies C4 submission criteria; eligible for awards
selected for report
This submission will be included/highlighted in the audit report
sponsor acknowledged
Technically the issue is correct, but we're not going to resolve it for XYZ reasons
sufficient quality report
This report is of sufficient quality
Lines of code
https://github.com/code-423n4/2024-06-size/blob/main/src/Size.sol#L194
https://github.com/code-423n4/2024-06-size/blob/main/src/libraries/actions/SellCreditMarket.sol#L202
https://github.com/code-423n4/2024-06-size/blob/main/src/libraries/CapsLibrary.sol#L67
Vulnerability details
Impact
The protocol does not remove borrowed token liquidity from the aave pool once a loan is initiated. It only checks if there is enough available liquidity via the validateVariablePoolHasEnoughLiquidity() function. A user is expected to withdraw their funds after the loan is created. This means that a malicios user can sandwich loans that exceed the available liquidity in aave by depositing liquidity in a frontrun transaction and removing it in a backrun transaction. This way a user that takes out a loan will not be able to remove their funds until there is enough available liquidity in the pool.
Also note that liqudity may become unavailable via other factors, like external users removing liquidity from aave.
Proof of Concept
The sellCreditMarket() function does not remove liquidity from aave, but only checks if there is enough liqudity available via a call to validateVariablePoolHasEnoughLiquidity().
https://github.com/code-423n4/2024-06-size/blob/main/src/Size.sol#L194
Also, the executeSellCreditMarket() function transfers the size protocol accounting borrowAToken to the borrower, instead of the underlying token itself, leaving the user to withdraw their borrowed funds in a seprate transaction.
https://github.com/code-423n4/2024-06-size/blob/main/src/libraries/actions/SellCreditMarket.sol#L202
The validateVariablePoolHasEnoughLiquidity() function only checks the balance of the variable pool, and does not remove liquidity:
https://github.com/code-423n4/2024-06-size/blob/main/src/libraries/CapsLibrary.sol#L67
Tools Used
Manual Review
Recommended Mitigation Steps
Remove the liqudity from the pool when the loan is created and still let the user pull their funds in a separate transaction to remain compliant with pull over push pattern.
Assessed type
Other
The text was updated successfully, but these errors were encountered: