Skip to content
Business logic Audit finding Intermediate

Removal of pool from reward zone does not allow gulping emissions which were already distributed in the past

YouCrossTheLineAlfie Follow with 0xadrii, monrel and 1 other

Originally disclosed on Code4rena

Submitted by YouCrossTheLineAlfie, also found by 0xadrii, monrel, and rscodes

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

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

Finding description and impact

The BackstopContract::distribute is used to update the backstop with new emissions for all the reward zone pools.

Then, calling the BackstopContract::gulp_emissions with a specific pool address will gulp emissions in the ratio of 70% to the backstop and 30% to the pool.

A pool can be removed using the BackstopContract::remove_reward function if the threshold requirements are not met.

    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) {           <<@ -- // Checks if a pool is above threshold and reverts
            panic_with_error!(e, BackstopError::BadRequest);
        } else {
            remove_pool(e, &mut reward_zone, &to_remove);
            storage::set_reward_zone(e, &reward_zone);
        }
    }

However, while removing the pool, the remove_pool sets the emission index to i128::MAX without allowing to claim the emissions via BackstopContract::gulp_emissions which were already distributed.

    /// Remove a pool from the reward zone and set the backstop emissions index to i128::MAX
    fn remove_pool(e: &Env, reward_zone: &mut Vec<Address>, to_remove: &Address) {
        let to_remove_index = reward_zone.first_index_of(to_remove.clone());
        match to_remove_index {
            Some(idx) => {
                // . . . Rest of the code . . .
                // update backstop emissions for the pool before removing it from the reward zone
                // set emission index to i128::MAX to prevent further emissions
                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);             <<@ -- // sets i128::MAX as the index

                reward_zone.remove(idx);
            }
            None => panic_with_error!(e, BackstopError::InvalidRewardZoneEntry),
        }
    }

This would fail the BackstopContract::gulp_emissions call due to an overflow not allowing the rightful emissions to the pool and the backstop.

    pub fn gulp_emissions(e: &Env, pool: &Address) -> (i128, i128) {
        let pool_balance = storage::get_pool_balance(e, pool);

        let new_emissions = update_rz_emis_data(e, pool, true);         <<@ - // This call would revert
        // . . . Rest of the code . . .
        return (0, 0);
    }

The new emissions variable would overflow here as gulp_index is valid amount but the emission_data.index is set as i128::MAX whose difference will get multiplied by SCALAR_14, hence overflowing the signed 128 bit integer.

    pub fn update_rz_emis_data(e: &Env, pool: &Address, to_gulp: bool) -> i128 {
        if let Some(emission_data) = storage::get_rz_emis_data(e, pool) {
            let pool_balance = storage::get_pool_balance(e, pool);
            let gulp_index = storage::get_rz_emission_index(e);
            let mut accrued = emission_data.accrued;
            if emission_data.index < gulp_index || to_gulp {
                if pool_balance.non_queued_tokens() > 0 {
                    let new_emissions = pool_balance
                        .non_queued_tokens()
                        .fixed_mul_floor(gulp_index - emission_data.index, SCALAR_14)           <<@ -- // Overflows here
                        .unwrap_optimized();
                    accrued += new_emissions;
                    return set_rz_emissions(e, pool, gulp_index, accrued, to_gulp);
                } else {
                    return set_rz_emissions(e, pool, gulp_index, accrued, to_gulp);
                }
            }
        }
        return 0;
    }

P.S: The distribute call was made prior to the pool being under threshold or simply some other pool got higher deposits than current.

Impact

  1. Loss of funds for the users and pool as the emissions were distributed before removal from reward zone, but the gulping of them is not allowed. There’s a possibility that the pool will never get added to the reward zone as pools are essentially competing with each other for a place in reward zone.
  2. Temporary funds stuck for the pool if there’s a chance it is added back to the reward zone.

Proof of Concept

The below test case was added inside blend-contracts-v2/backstop/src/emissions/manager.rs file:

    #[test]
    #[should_panic]
    fn test_remove_from_rz_failing_gulp() {
        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 to_remove = 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 mut reward_zone: Vec<Address> = vec![
            &e,
            Address::generate(&e),
            to_remove.clone(), // index 7
        ];

        e.as_contract(&backstop_id, || {
            storage::set_reward_zone(&e, &reward_zone);
            storage::set_last_distribution_time(&e, &(1713139200 - 1 * 24 * 60 * 60));
            storage::set_pool_balance(
                &e,
                &to_remove,
                &PoolBalance {
                    shares: 90_000_0000000,
                    tokens: 100_001_0000000,
                    q4w: 1_000_0000000,
                },
            );
            storage::set_pool_balance(
                &e,
                &to_remove,
                &PoolBalance {
                    shares: 35_000_0000000,
                    tokens: 40_000_0000000,
                    q4w: 1_000_0000000,
                },
            );
            storage::set_backstop_emis_data(
                &e,
                &to_remove,
                &BackstopEmissionData {
                    eps: 0_10000000000000,
                    expiration: 1713139200 + 1000,
                    index: 0,
                    last_time: 1713139200 - 12345,
                },
            );
            storage::set_rz_emis_data(&e, &to_remove, {
                &RzEmissionData {
                    index: 1234 * SCALAR_7,
                    accrued: 0,
                }
            });
            storage::set_rz_emission_index(&e, &(5678 * SCALAR_7));

remove_from_reward_zone(&e, to_remove.clone());
            let actual_rz = storage::get_reward_zone(&e);
            reward_zone.remove(1);
            assert_eq!(actual_rz.len(), 1);
            assert_eq!(actual_rz, reward_zone);
            // gulp emissions after removal
            let ( fi, si ) = gulp_emissions(&e, &to_remove.clone());

        });
    }

As we can infer, the function reverts as expected.

Recommended mitigation steps

It is recommended to gulp the emissions before removing the pool:

    pub fn add_to_reward_zone(e: &Env, to_add: Address, to_remove: Option<Address>) {

        // . . . Rest of the code . . .

        if MAX_RZ_SIZE > reward_zone.len() {
            // there is room in the reward zone. Add "to_add".
            reward_zone.push_front(to_add.clone());
        } else {
            match to_remove {
                None => panic_with_error!(e, BackstopError::RewardZoneFull),
                Some(to_remove) => {
                    // Verify "to_add" has a higher backstop deposit that "to_remove"
                    if pool_data.tokens <= storage::get_pool_balance(e, &to_remove).tokens {
                        panic_with_error!(e, BackstopError::InvalidRewardZoneEntry);
                    }
+                    gulp_emissions(e, &to_remove);
                    remove_pool(e, &mut reward_zone, &to_remove);
                    reward_zone.push_front(to_add.clone());
                }
            }
        }
        // . . . Rest of the code . . .
    }

markus_pl10 (Script3) confirmed

Blend mitigated:

Commit 6204dba to improve reward zone changes emissions impact.

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


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

What is known

A medium-severity business logic bug in Blend V2 Audit + Certora Formal Verification. Code4rena made it public on 13 August 2025. Found in the 2025-02-blend-v2-audit-certora-formal-verification audit contest (finding M-16), also found by 3 other wardens.

About Business logic

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

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

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 YouCrossTheLineAlfie

View all

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