When using multicall, the AToken cap is not checked, only the increase of AToken is checked against the decrease of debt. A user can exploit this to deposit USDC above the AToken cap.
Proof of Concept
By doing these steps in one transaction, a user can deposit USDC above the AToken cap:
Already have X AToken and a small amount AToken for swapping fee
Flashloan ETH and deposit ETH
Sell X credit to himself
Make a multicall:
3a. Deposit X USDC
3b. Repay the debt in step 2 (AToken in step 0 should cover the swapping fee)
Withdraw ETH and pay back the flashloan
Because the increase of AToken in step 3a is equals to the decrease of debt in step 3b, the check at the end of the multicall is passed. The user can repeat the steps above to deposit more AToken.
Tools Used
Manual Review.
Recommended Mitigation Steps
Add a check to cap the debtToken at the end of buyCreditMarket and sellCreditMarket.
Lines of code
https://github.com/code-423n4/2024-06-size/blob/8850e25fb088898e9cf86f9be1c401ad155bea86/src/libraries/Multicall.sol#L40-L42
Vulnerability details
Impact
When using
multicall
, the AToken cap is not checked, only the increase of AToken is checked against the decrease of debt. A user can exploit this to deposit USDC above the AToken cap.Proof of Concept
By doing these steps in one transaction, a user can deposit USDC above the AToken cap:
X
AToken and a small amount AToken for swapping feeX
credit to himselfX
USDC 3b. Repay the debt in step 2 (AToken in step 0 should cover the swapping fee)Because the increase of AToken in step 3a is equals to the decrease of debt in step 3b, the check at the end of the multicall is passed. The user can repeat the steps above to deposit more AToken.
Tools Used
Manual Review.
Recommended Mitigation Steps
Add a check to cap the
debtToken
at the end ofbuyCreditMarket
andsellCreditMarket
.Assessed type
Other