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

Users might not be able to withdraw USDC from the protocol #391

Closed
howlbot-integration bot opened this issue Jul 8, 2024 · 11 comments
Closed

Users might not be able to withdraw USDC from the protocol #391

howlbot-integration bot opened this issue Jul 8, 2024 · 11 comments
Labels
bug Something isn't working downgraded by judge Judge downgraded the risk level of this issue grade-c QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax 🤖_42_group AI based duplicate group recommendation sufficient quality report This report is of sufficient quality unsatisfactory does not satisfy C4 submission criteria; not eligible for awards

Comments

@howlbot-integration
Copy link

Lines of code

https://github.com/code-423n4/2024-06-size/blob/8850e25fb088898e9cf86f9be1c401ad155bea86/src/libraries/CapsLibrary.sol#L67-L72

Vulnerability details

Impact

Users might not be able to withdraw USDC from the protocol

Proof of Concept

After some operations, there is this check such as taking a loan, there is this check:

function validateVariablePoolHasEnoughLiquidity(State storage state, uint256 amount) public view {
        uint256 liquidity = state.data.underlyingBorrowToken.balanceOf(address(state.data.variablePool));
        if (liquidity < amount) {
            revert Errors.NOT_ENOUGH_BORROW_ATOKEN_LIQUIDITY(liquidity, amount);
        }
    }

It has the goal to not allow taking out loans whenever there would not be enough liquidity in Aave for the user to convert the internally used version of USDC into actual USDC by withdrawing. The issue is that the liquidity is computed by using balanceOf which can lead to incorrect data.

Whenever a user deposits into the protocol, supply() is called on the Aave pool which mints a special token to the receiver showing the amount he deposited and thus, what he can withdraw. Then, upon withdrawing, withdraw() is called which burns those tokens. If a malicious user directly sends USDC into the Aave pool, then balanceOf would increase but no new tokens will be minted.

Imagine the following scenario:

  1. There are 90 tokens in the pool
  2. After a borrow, validateVariablePoolHasEnoughLiquidity() is called with an amount of 100
  3. This should revert but a malicious user frontruns the borrow and directly sends 10 tokens into the pool
  4. Now, the function passes but the actual aToken balance of the pool is still 90 as those 10 were directly sent
  5. User tries to withdraw the 100 tokens from the protocol but it fails as it tries to burn 100 tokens when only 90 are actually available

Tools Used

Manual Review

Recommended Mitigation Steps

Avoid using a manipulatable value like balanceOf

Assessed type

Other

@howlbot-integration howlbot-integration bot added 3 (High Risk) Assets can be stolen/lost/compromised directly 🤖_42_group AI based duplicate group recommendation bug Something isn't working duplicate-225 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 c4-judge added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value downgraded by judge Judge downgraded the risk level of this issue and removed 3 (High Risk) Assets can be stolen/lost/compromised directly labels Jul 11, 2024
@c4-judge
Copy link
Contributor

hansfriese changed the severity to 2 (Med Risk)

@c4-judge
Copy link
Contributor

hansfriese marked the issue as duplicate of #152

@c4-judge c4-judge added duplicate-152 satisfactory satisfies C4 submission criteria; eligible for awards and removed duplicate-225 labels Jul 11, 2024
@c4-judge
Copy link
Contributor

hansfriese marked the issue as satisfactory

@samuraii77
Copy link

samuraii77 commented Jul 15, 2024

Hi, this issue should not be duplicated with the one it is currently duplicated to. Take a look at #225 which is another issue I have reported, they are duplicated to each other. 225 is properly duplicated however this one is not. These 2 issues have 2 different root causes and should not be a duplicate of each other.

@gesha17
Copy link

gesha17 commented Jul 17, 2024

Hi @samuraii77,

Indeed it seems this one should not be duplicate of #152.

In the scenario you describe, attempting to create a loan with 100 borrowed tokens, when only 90 are available in Size's account would fail. The call to transfer borrowAToken from the lender to the msg.sender(borrower) would fail, since there would be only at most 90 borrowATokens available in the lender's account.

Essentially, you can't create a loan borrowing more than the lender has offered.

@samuraii77
Copy link

I said in the pool which means Aave pool (as available liquidity), not Size.

@gesha17
Copy link

gesha17 commented Jul 17, 2024

Ah, I see what you meant. Got confused by the example.

@hansfriese
Copy link

It is not a duplicate of #152, but I believe it is not a valid Medium risk.

  • QA is appropriate since an attacker would lose a non-negligible amount of funds.
  • It seems illogical that the pool would not utilize the increased funds (though I did not check the logic of AAVE v3 in detail).

Now, the function passes but the actual aToken balance of the pool is still 90 as those 10 were directly sent

I will invalidate this issue as the warden hasn't submitted a QA report.

@c4-judge
Copy link
Contributor

hansfriese marked the issue as not a duplicate

@c4-judge
Copy link
Contributor

hansfriese changed the severity to QA (Quality Assurance)

@c4-judge c4-judge added 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 21, 2024
@c4-judge
Copy link
Contributor

hansfriese marked the issue as grade-c

@c4-judge c4-judge removed the satisfactory satisfies C4 submission criteria; eligible for awards label Jul 21, 2024
@c4-judge c4-judge added grade-c unsatisfactory does not satisfy C4 submission criteria; not eligible for awards labels Jul 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working downgraded by judge Judge downgraded the risk level of this issue grade-c QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax 🤖_42_group AI based duplicate group recommendation sufficient quality report This report is of sufficient quality unsatisfactory does not satisfy C4 submission criteria; not eligible for awards
Projects
None yet
Development

No branches or pull requests

4 participants