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

Inside Multicall, wrong parameters passed into state.validateBorrowATokenIncreaseLteDebtTokenDecrease allows for unintended behaviour where total supply of borrowAtokens exceed borrowATokenCap despite not being for the purpose of decreasing debt #294

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/Multicall.sol#L29-L42

Vulnerability details

Impact

Inside multicall, wrong parameters passed into state.validateBorrowATokenIncreaseLteDebtTokenDecrease allows for unintended behaviour where borrowAToken.totalSupply() exceed borrowATokenCap despite not being for the purpose of decreasing debt

Compromises the integrity of state.riskConfig.borrowATokenCap as users can easily deposit USDC into the pool far exceeding the borrowATokenCap even though it is not for reducing debt.

Proof of Concept

The piece of code below shows how user Alice can deposit 2 Million USDC even though the token cap is 1 Million.

function test_multicall_evades_cap() public {
    uint256 amount = 2_000_000e6; // deposits 2 million USDC through multicall to bypass borrowATokenCap
    deal(address(usdc), alice, amount);
    vm.prank(alice);
    IERC20Metadata(address(usdc)).approve(address(size), amount);

    bytes[] memory data = new bytes[](1);
    data[0] = abi.encodeCall(size.deposit, (DepositParams({token: address(usdc), amount: amount, to: alice}))); 
    vm.prank(alice);
    bytes[] memory results = size.multicall(data);
}

The purpose of calling state.validateBorrowATokenIncreaseLteDebtTokenDecrease at the end of of multicall is to allow users to deposit more tokens than the cap allows if it is for the sake of reducing debt. However in the piece of code above, even though no debt was reduced the user was still able to exceed the token cap.

Tools Used

Manual Review

Recommended Mitigation Steps

To fix the issue instead of using borrowAToken.balanceOf(address(this)) use borrowAToken.totalSupply().

 function multicall(State storage state, bytes[] calldata data) internal returns (bytes[] memory results) {
     state.data.isMulticall = true;
        
-    uint256 borrowATokenSupplyBefore = state.data.borrowAToken.balanceOf(address(this));
+    uint256 borrowATokenSupplyBefore = state.data.borrowAToken.totalSupply();
     uint256 debtTokenSupplyBefore = state.data.debtToken.totalSupply();

     .......

-    uint256 borrowATokenSupplyAfter = state.data.borrowAToken.balanceOf(address(this));
+    uint256 borrowATokenSupplyAfter = state.data.borrowAToken.totalSupply();
     uint256 debtTokenSupplyAfter = state.data.debtToken.totalSupply();

     state.validateBorrowATokenIncreaseLteDebtTokenDecrease(
         borrowATokenSupplyBefore, debtTokenSupplyBefore, borrowATokenSupplyAfter, debtTokenSupplyAfter
     );

     state.data.isMulticall = false;
 }

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