Incorrect Validation of Amount
in sellCreditMarket
and buyCreditMarket
Functions Causes A Revert On Valid Inputs
#273
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-224
edited-by-warden
🤖_18_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/libraries/actions/SellCreditMarket.sol#L93-L94
https://github.com/code-423n4/2024-06-size/blob/8850e25fb088898e9cf86f9be1c401ad155bea86/src/libraries/actions/BuyCreditMarket.sol#L91-L92
Vulnerability details
Impact
exactAmountIn
mechanism not working as intended.Proof of Concept
sellCreditMarket
orbuyCreditMarket
function. Both functions validate the user's input before executing the action.Amount
and a booleanexactAmountIn
, which indicates whether theAmount
representscredit
orcash
.Amount
withminimumCreditBorrowAToken
which is the minimum credit allowed and revert ifAmount < minimumCreditBorrowAToken
.Amount
is intended to represent cashAmount rather than credit. In such cases, even if theAmount
is less thanminimumCreditBorrowAToken
, applying the fees and borrow rate to calculate the credit might result in a credit amount greater thanminimumCreditBorrowAToken
. Therefore, the validation is incorrect when theAmount
represents cash. which broke those invariants :Example:
minimumCreditBorrowAToken =
100
, ratePerTenor =20%
, swapFees =0.5%
, Amount =95
If we calculate credit for
95
cash, we get:credit =
(95 + 95 * 0.005) * 1.2
=114.57
Notice that the credit is more than
minimumCreditBorrowAToken
, but the transaction still reverts due to the incorrect comparison (95 < 100).Tools Used
Recommended Mitigation Steps
minimumCreditBorrowAToken
in both function :Assessed type
Invalid Validation
The text was updated successfully, but these errors were encountered: