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

The validateBorrowATokenIncreaseLteDebtTokenDecrease is incorrect and can be easily bypassed #243

Closed
howlbot-integration bot opened this issue Jul 8, 2024 · 3 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-238 🤖_48_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/libraries/CapsLibrary.sol#L27

Vulnerability details

Impact

The validateBorrowATokenIncreaseLteDebtTokenDecrease function in CapsLibrary.sol validates that the increase in borrow aToken supply is less than or equal to the decrease in debt token supply.
The issue is that due to incorrect validation, it is almost impossible for the function to ever not be successful, even when it shouldn't be.

Proof of Concept

The function should revert if the debt increase is greater than the supply increase and the supply is above the cap.
Here is the validation that the supply is above the cap:

if (borrowATokenSupplyAfter > state.riskConfig.borrowATokenCap) {...}

The issue is that the borrowATokenSupplyAfter is not the full supply of the borrowAToken but instead the contract's balance. This implementation is sufficient for the rest of the function, but should not be used in this particular instance as it is almost impossible for the balance of the contract to ever reach the supply cap.
However, in the current implementation, it is possible for the total supply of the borrow token to reach the supply cap and the required validation will still not be performed.

As a result, the validateBorrowATokenIncreaseLteDebtTokenDecrease will be bypassed in almost all cases, allowing for malicious actions to be performed.

Tools Used

Manual review

Recommended Mitigation Steps

Consider performing the validation the following way:

if (state.data.borrowAToken.totalSupply() > state.riskConfig.borrowATokenCap) {...}

Assessed type

Invalid Validation

@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 🤖_48_group AI based duplicate group recommendation bug Something isn't working duplicate-13 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 marked the issue as duplicate of #144

@c4-judge
Copy link
Contributor

hansfriese marked the issue as satisfactory

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

hansfriese marked the issue as duplicate of #238

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-238 🤖_48_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