Submitted by iam_emptyset, also found by ether_sky, 0x04bytes, samuraii77, Jorgect, radin100 (1, 2), DanielArmstrong, 0xStalin, 0xanmol, carlos__alegre, inzinko, dhank, Infect3d (1, 2), hyh, 0xarno, elhaj, zarkk01, trachev, KupiaSec, 0xRobocop, ilchovski, 0xJoyBoy03, BoltzmannBrain, pkqs90, and said
https://github.com/code-423n4/2024-06-size/blob/8850e25fb088898e9cf86f9be1c401ad155bea86/src/libraries/actions/BuyCreditMarket.sol#L91https://github.com/code-423n4/2024-06-size/blob/8850e25fb088898e9cf86f9be1c401ad155bea86/src/libraries/actions/SellCreditMarket.sol#L93
The minimum credit user can buy or sell can be gotten from state.riskConfig.minimumCreditBorrowAToken which was set as 5e6. However, in buyCreditMarket and sellCreditMarket user can not buy or sell minimun credit allowed or small amount above it due to the exactAmountIn condition he chose.
In buyCreditMarket: when user set params.exactAmountIn = true, The params.amount value will be cash he want to use to buy credit. Since the params.amount value is cash it can be set less than state.riskConfig.minimumCreditBorrowAToken (5e6) as long as when the value get converted to credit it will reach the state.riskConfig.minimumCreditBorrowAToken value. But, unfortunately, in validateBuyCreditMarket() whenever params.amount is less than state.riskConfig.minimumCreditBorrowAToken the transaction will revert due to below code present in the function.
For example, the cash user can use to buy minimum credit allowed (5e6) can be calculated as in the code below, And the value should be less than the minimum credit allowed (5e6).
In sellCreditMarket: when user set params.exactAmountIn = false, The params.amount will be the exact cash he want to receive. But he will also not be able to set the params.amount value to be less than state.riskConfig.minimumCreditBorrowAToken value due to the below code present in validateSellCreditMarket().
For BuyCreditMarket: Copy and paste below code in /test/local/actions/BuyCreditMarket.t.sol:
Then run the test with below command, the test should pass because it will revert with an error Errors.CREDIT_LOWER_THAN_MINIMUM_CREDIT.
For SellCreditMarket: Copy and paste below code in /test/local/actions/SellCreditMarket.t.sol:
Then run the test with below command, the test should pass because it will revert with an error Errors.CREDIT_LOWER_THAN_MINIMUM_CREDIT.
In validateBuyCreditMarket() and  validateSellCreditMarket() for BuyCreditMarket and SellCreditMarket libraries respectively, there is a need of considering the condition of params.exactAmountIn value. The check should be implemented as shown below.
For BuyCreditMarket library: inside validateBuyCreditMarket() replace below code:
With the below code:
For SellCreditMarket library: inside validateSellCreditMarket() replace below code:
With the below code:
Invalid Validation
aviggiano (Size) confirmed and commented:
