Incorrect cashAmount check for variable pool ability to fulfill withdrawal #318
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
duplicate-15
🤖_191_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-06-size/blob/8850e25fb088898e9cf86f9be1c401ad155bea86/src/Size.sol#L178-L185
Vulnerability details
Impact
the
validateVariablePoolHasEnoughLiquidity
function was meant as a check to know if the variable pool balance of the borrow token exceeds the amount of the cash being received by the receiver. The issue here is that in theSize:buyCreditMarket
the parameter being passed is the mount returned from theexecuteBuyCreditMarket
butamount
is actually the combination of the amount to be received + the fees for the receiver. Which is the wrong implementation as the amount received is the only one to be checked, if this implementation is used it will cause the buyCreditMarket to revert even though the protocol has enough to pay the cash receiver.Proof of Concept
Inside the
executeBuyCreditMarket
function as shown below the amount being returned is the cashAmount + fees which is later deducted before transferinside the function
cashAmountIn
is the amount being transferred, in both exactAmountIn situationThen the amount is subtracted before transfer shown in the snippet below
But the amount being used being for the
validateVariablePoolHasEnoughLiquidity
call is the cashAmountIn which will lead to a DOS even though the variable pool has enough for the fee receiver.Note: There is an inconsistent implementation of the same type of function with different logic from the protocol for example
sellCreditMarket::executeSellCreditMarket
only checks if the amount of cash being received is present in the variable poolstate.validateVariablePoolHasEnoughLiquidity(amount);
Size::liqudateWithReplacement
also only checks if the amount being transferred is present in the variable poolstate.validateVariablePoolHasEnoughLiquidity(amount);
One of this logics is wrong and the protocol should act to fix the logic
Tools Used
Manual Review
Recommended Mitigation Steps
Refactor the code to fit with the already established logic for checking if the variable pool can pay the amount the receiver is getting or a new system can be developed by the protocol.
Assessed type
Other
The text was updated successfully, but these errors were encountered: