Skip to content
Business logic Audit finding Intermediate

Removing a pool from the reward zone leads to the loss of ungulped emissions

When a pool is removed from the reward zone, its unaccrued emissions are not accounted for, so those emissions are permanently lost and cannot be claimed. An attacker could not directly exploit this, but the pool's users lose their share of emissions.

0xAlix2 Follow with 0xadrii, carrotsmuggler and 2 others

Originally disclosed on Code4rena

Submitted by 0xAlix2, also found by 0xadrii, carrotsmuggler, oakcobalt, and Testerbot

https://github.com/code-423n4/2025-02-blend/blob/main/blend-contracts-v2/backstop/src/emissions/manager.rs#L66-L78

Finding description and impact

Pools enter the reward zone in the backstop module to search emissions. When distribution happens, the global reward zone index is updated. Later, when changes happen to different pools, the pool reward zone index is updated to account for the newly distributed emissions. Each pool takes its part and adds it to the accrued balance until gulped later.

On the other hand, pools could be removed from the reward zone, if the pool’s backstop balance falls below a certain threshold. When a pool is removed, remove_from_reward_zone is called, which also calls remove_pool, which in turn removes the pool from the reward zone array, and sets the pool’s reward zone index to infinity.

https://github.com/code-423n4/2025-02-blend/blob/main/blend-contracts-v2/backstop/src/emissions/manager.rs#L92-L95

let to_remove_emis_data = storage::get_rz_emis_data(e, &to_remove).unwrap_optimized();
set_rz_emissions(e, &to_remove, i128::MAX, to_remove_emis_data.accrued, false);

reward_zone.remove(idx);

However, this doesn’t account for the unaccrued pool’s emissions, forcing them to be lost, in other words, update_rz_emis_data is not called to account for those emissions.

For example, if a distribution is made, and without any pool balance changes happen, the pool is removed. The pool’s part of the last emission is lost, and can never be claimed.

Proof of Concept

Add the following test to blend-contracts-v2/backstop/src/emissions/manager.rs:

#[test]
fn test_removed_rz_pool_loses_emissions() {
    let e = Env::default();
    e.ledger().set(LedgerInfo {
        timestamp: 1713139200,
        protocol_version: 22,
        sequence_number: 0,
        network_id: Default::default(),
        base_reserve: 10,
        min_temp_entry_ttl: 10,
        min_persistent_entry_ttl: 10,
        max_entry_ttl: 3110400,
    });
    e.mock_all_auths();

    let bombadil = Address::generate(&e);
    let backstop_id = create_backstop(&e);
    let pool_1 = Address::generate(&e);
    let pool_2 = Address::generate(&e);

    let (blnd_id, _) = create_blnd_token(&e, &backstop_id, &bombadil);
    let (usdc_id, _) = create_usdc_token(&e, &backstop_id, &bombadil);
    create_comet_lp_pool_with_tokens_per_share(
        &e,
        &backstop_id,
        &bombadil,
        &blnd_id,
        5_0000000,
        &usdc_id,
        0_1000000,
    );

    let reward_zone: Vec<Address> = vec![&e, pool_1.clone(), pool_2.clone()];

    e.as_contract(&backstop_id, || {
        storage::set_reward_zone(&e, &reward_zone);
        storage::set_last_distribution_time(&e, &(1713139200 - 1 * 24 * 60 * 60));

        // Set up balances for both pools
        storage::set_pool_balance(
            &e,
            &pool_1,
            &PoolBalance {
                shares: 90_000_0000000,
                tokens: 100_001_0000000,
                q4w: 1_000_0000000,
            },
        );
        // non-queued tokens are 0
        storage::set_pool_balance(
            &e,
            &pool_2,
            &PoolBalance {
                shares: 35_000_0000000,
                tokens: 40_000_0000000,
                q4w: 30_000_0000000,
            },
        );

        // Set emissions indexes
        storage::set_rz_emission_index(&e, &SCALAR_7);
        storage::set_rz_emis_data(
            &e,
            &pool_1,
            &RzEmissionData {
                index: SCALAR_7,
                accrued: 0,
            },
        );
        storage::set_rz_emis_data(
            &e,
            &pool_2,
            &RzEmissionData {
                index: SCALAR_7,
                accrued: 0,
            },
        );

        let mut pool_1_emis = storage::get_rz_emis_data(&e, &pool_1).unwrap_optimized();
        let mut pool_2_emis = storage::get_rz_emis_data(&e, &pool_2).unwrap_optimized();

        // Global index is set as initial index
        assert_eq!(storage::get_rz_emission_index(&e), SCALAR_7);

        // Pools 1 and 2 have initial index
        assert_eq!(pool_1_emis.index, SCALAR_7);
        assert_eq!(pool_2_emis.index, SCALAR_7);

        // No accrued emissions
        assert_eq!(pool_1_emis.accrued, 0);
        assert_eq!(pool_2_emis.accrued, 0);

        // Call `distribute` to distribute emissions
        distribute(&e);

        pool_1_emis = storage::get_rz_emis_data(&e, &pool_1).unwrap_optimized();
        pool_2_emis = storage::get_rz_emis_data(&e, &pool_2).unwrap_optimized();

        // Global index is updated, i.e. each pool has a part of the emissions
        assert_eq!(storage::get_rz_emission_index(&e), 8_259_710_4719394);

        // Pools 1 and 2 haven't accrued any emissions
        assert_eq!(pool_1_emis.accrued, 0);
        assert_eq!(pool_2_emis.accrued, 0);

        // Remove `pool_2` from the reward zone
        remove_from_reward_zone(&e, pool_2.clone());

        // Validate that pool_2 has been removed
        assert_eq!(storage::get_reward_zone(&e), vec![&e, pool_1.clone()]);

        pool_1_emis = storage::get_rz_emis_data(&e, &pool_1).unwrap_optimized();
        pool_2_emis = storage::get_rz_emis_data(&e, &pool_2).unwrap_optimized();

        // Pool 1 has initial index
        assert_eq!(storage::get_rz_emission_index(&e), 8_259_710_4719394);

        // Pool 1 has initial index
        assert_eq!(pool_1_emis.index, SCALAR_7);
        // Pool 2 has been removed and has an index of i128::MAX
        assert_eq!(pool_2_emis.index, i128::MAX);

        // Pool 2 has no accrued emissions, even though the index is i128::MAX
        assert_eq!(pool_2_emis.accrued, 0);
    });
}

Recommended mitigation steps

Accrue the emissions of the removed pool, before setting its rewards index to infinity.

    /// remove a pool to the reward zone if below the minimum backstop deposit threshold
    pub fn remove_from_reward_zone(e: &Env, to_remove: Address) {
        let mut reward_zone = storage::get_reward_zone(e);

        // ensure to_add has met the minimum backstop deposit threshold
        // NOTE: "to_add" can only carry a pool balance if it is a deployed pool from the factory
        let pool_data = load_pool_backstop_data(e, &to_remove);
        if require_pool_above_threshold(&pool_data) {
            panic_with_error!(e, BackstopError::BadRequest);
        } else {
+           update_rz_emis_data(e, &to_remove, false);
            remove_pool(e, &mut reward_zone, &to_remove);
            storage::set_reward_zone(e, &reward_zone);
        }
    }

markus_pl10 (Script3) disputed

mootz12 (Script3) commented:

This is not a finding.

Removing pools is safeguarded by a check to ensure distribution was called fairly recently, to limit the lost emissions for removed pools.

This is not a common code pathway, and losing a day of emissions is not considered vital, due to the complications of forcing distribute to be invoked during removal with resource limitations.

However, documentation should be added to ensure that is clear.

LSDan (judge) commented:

I disagree. This locks funds and causes a loss of emissions. Medium is appropriate here, per the docs.

Blend mitigated:

Commit 6204dba to improve reward zone changes emissions impact.

Status: Mitigation confirmed. Full details in reports from oakcobalt, 0xAlix2, 0x007 and Testerbot.


The original report as published on Code4rena, by 0xAlix2. 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 removal function does not call the update function to accrue emissions before setting the pool's index to infinity.

Impact

The removed pool's unaccrued emissions are lost and cannot be claimed, though the loss is limited because removal is safeguarded by a recent distribution check.

What the attacker needed

Pool falls below backstop threshold; distribution occurred since last accrual

How it was found

  1. Set up a reward zone with two pools and initialise their emission data.
  2. Call distribute to update the global emission index.
  3. Remove one pool from the reward zone.
  4. Observe that the removed pool's accrued emissions remain zero despite the index change.

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.

In this system, pools earn emissions (rewards) over time. When a pool is removed from the reward zone, the code forgets to calculate and save the rewards it earned since the last distribution, so those rewards disappear. This means users of that pool lose out on rewards they should have received.

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 0xAlix2

View all

39 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.