Skip to content
Business logic Audit finding Intermediate

An attacker can easily bypass the collateral value limit factor checks

The collateral value limit factor checks are not performed when withdrawing lent tokens, so an attacker can supply tokens, borrow against them, and then withdraw the supplied tokens in one transaction to exceed the intended limit. This can also cause calls from the AutoRange automator to revert because the limit is surpassed.

Arz Follow with lanrebayode77

Originally disclosed on Code4rena

Submitted by Arz, also found by lanrebayode77

The collateral value limit factor checks in _updateAndCheckCollateral() are used to check if the current value of used collateral is more than the allowed limit. The problem here is that these checks are not done when withdrawing lent tokens so an attacker can easily bypass these checks.

Example:

  1. The collateral value limit factor is set to 90% for both collateral tokens.
  2. The lent amount is 100 USDC and Alice has borrowed 90 USDC.
  3. An attacker wants to borrow the remaining 10 USDC but he cant because of the checks.
  4. He executes an attack in 1 transaction - he supplies 10 USDC, borrows 10 USDC and then withdraws the 10 USDC that he lent.
  5. The amount borrowed is 100 USDC even though the collateral factor is 90%.

The attacker can do this to bypass the checks, this can also block calls from the AutoRange automator. Whenever a new position is sent, _updateAndCheckCollateral() is called, which will revert because the attacker surpassed the limits.

Impact

The attacker can easily surpass the limits, this can also make calls from AutoRange revert because _updateAndCheckCollateral() is called when the position is replaced and it will revert because the limits were surpassed. The automator will fail to change the range of the positions.

Proof of Concept

Add this to V3Vault.t.sol, as you can see the limits were surpassed:

function testCollateralValueLimit() external {
        _setupBasicLoan(false);

        //set collateral value limit to 90%
        vault.setTokenConfig(address(DAI), uint32(Q32 * 9 / 10), uint32(Q32 * 9 / 10));

        vm.prank(TEST_NFT_ACCOUNT);
        vault.borrow(TEST_NFT, 8e6);

        //10 USDC were lent and 2 USDC were borrowed
        //Attacker can only borrow 1 USDC because of the collateral value limit

        //What he does is supplies 2 USDC, borrows 2 USDC and then withdraws what he lent
        _deposit(2e6, TEST_NFT_ACCOUNT_2);
        _createAndBorrow(TEST_NFT_2, TEST_NFT_ACCOUNT_2, 2e6);

        vm.prank(TEST_NFT_ACCOUNT_2);
        vault.withdraw(2e6, TEST_NFT_ACCOUNT_2, TEST_NFT_ACCOUNT_2);

        (,,uint192 totalDebtShares) = vault.tokenConfigs(address(DAI));
        console.log("The total amount of shares lent:", vault.totalSupply());
        console.log("The total amount of shares borrowed:", totalDebtShares);
    }

Tools Used

Foundry

Recommended Mitigation Steps

Not sure how this should be fixed as the collateral tokens are configured separately and the collateral factors can differ. However, maybe preventing depositing and withdrawing in the same tx/small fee can help this.

Assessed type

Invalid Validation

kalinbas (Revert) acknowledged and commented:

  • The fact that AutoRange automator doesn’t work if the collateral limit is reached is no problem (this is as designed).
  • The fact that withdrawing lent assets can lead to collateral value > limit is no problem because it is limited to a certain percentage (it’s not possible to add a huge amount, borrow it, and withdraw it (because it is borrowed)).

The original report as published on Code4rena, by Arz. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the collateral value limit check is only applied during borrowing and not during withdrawal of lent tokens, allowing a temporary supply to be used to bypass the limit.

Impact

The attacker can surpass the collateral value limit, and this can also make calls from the AutoRange automator revert because the limit is exceeded.

What the attacker needed

A lending position; ability to supply and borrow; same transaction

The fix

The report suggests preventing depositing and withdrawing in the same transaction or adding a small fee, but the project acknowledged the behaviour as no problem.

How it was found

  1. Set the collateral value limit factor to 90% for the collateral token.
  2. Borrow an amount close to the limit.
  3. Supply additional tokens, borrow against them, and then withdraw the supplied tokens in the same transaction.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

A lending system sets a maximum amount you can borrow based on the collateral you provide. The check for this maximum is only done when you borrow, not when you withdraw your own supplied tokens. So someone can quickly supply extra tokens, borrow more, and then take back the supplied tokens, leaving the system over its intended limit.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by Arz

View all

4 more disclosed reports, best first.

More from Revert Lend

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.