Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect cashAmount check for variable pool ability to fulfill withdrawal #318

Closed
howlbot-integration bot opened this issue Jul 8, 2024 · 4 comments
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

Comments

@howlbot-integration
Copy link

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 the Size:buyCreditMarket the parameter being passed is the mount returned from the executeBuyCreditMarket but amount 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 transfer

inside the function cashAmountIn is the amount being transferred, in both exactAmountIn situation

if (params.exactAmountIn) {
            cashAmountIn = params.amount;
            (creditAmountOut, fees) = state.getCreditAmountOut({
                cashAmountIn: cashAmountIn,
                maxCashAmountIn: params.creditPositionId == RESERVED_ID
                    ? cashAmountIn
                    : Math.mulDivUp(creditPosition.credit, PERCENT, PERCENT + ratePerTenor),
                maxCredit: params.creditPositionId == RESERVED_ID
                    ? Math.mulDivDown(cashAmountIn, PERCENT + ratePerTenor, PERCENT)
                    : creditPosition.credit,
                ratePerTenor: ratePerTenor,
                tenor: tenor
            });
        } else {
            creditAmountOut = params.amount;
            (cashAmountIn, fees) = state.getCashAmountIn({
                creditAmountOut: creditAmountOut,
                maxCredit: params.creditPositionId == RESERVED_ID ? creditAmountOut : creditPosition.credit,
                ratePerTenor: ratePerTenor,
                tenor: tenor
            });
        }

Then the amount is subtracted before transfer shown in the snippet below

state.data.borrowAToken.transferFrom(msg.sender, borrower, cashAmountIn - fees);
        state.data.borrowAToken.transferFrom(msg.sender, state.feeConfig.feeRecipient, fees);

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 pool
state.validateVariablePoolHasEnoughLiquidity(amount);
  • Size::liqudateWithReplacement also only checks if the amount being transferred is present in the variable pool
state.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

@howlbot-integration howlbot-integration bot added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value 🤖_191_group AI based duplicate group recommendation bug Something isn't working duplicate-170 sufficient quality report This report is of sufficient quality labels Jul 8, 2024
howlbot-integration bot added a commit that referenced this issue Jul 8, 2024
@c4-judge
Copy link
Contributor

hansfriese changed the severity to QA (Quality Assurance)

@c4-judge c4-judge added downgraded by judge Judge downgraded the risk level of this issue QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax and removed 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value labels Jul 11, 2024
@c4-judge c4-judge reopened this Jul 11, 2024
@c4-judge c4-judge removed downgraded by judge Judge downgraded the risk level of this issue QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax labels Jul 11, 2024
@c4-judge
Copy link
Contributor

This previously downgraded issue has been upgraded by hansfriese

@c4-judge c4-judge added the 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value label Jul 11, 2024
@c4-judge
Copy link
Contributor

hansfriese marked the issue as duplicate of #15

@c4-judge c4-judge added the satisfactory satisfies C4 submission criteria; eligible for awards label Jul 12, 2024
@c4-judge
Copy link
Contributor

hansfriese marked the issue as satisfactory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

1 participant