Skip to content
Business logic Audit finding Intermediate

Malicious actors can repeatedly dilute emissions to a longer timeframe

The gulp_emissions function could be called repeatedly with no minimum time between calls, allowing anyone to dilute existing rewards over a longer timeframe and delay emissions. This could unfairly reduce rewards for current stakers.

rscodes Follow

Originally disclosed on Code4rena

Submitted by rscodes

https://github.com/code-423n4/2025-02-blend/blob/f23b3260763488f365ef6a95bfb139c95b0ed0f9/blend-contracts-v2/pool/src/contract.rs#L502-L508

Summary

pub fn gulp_emissions(e: &Env) -> i128 {
    let backstop = storage::get_backstop(e);
    let new_emissions =
        BackstopClient::new(e, &backstop).gulp_emissions(&e.current_contract_address());
    do_gulp_emissions(e, new_emissions);
    new_emissions
}

In the pool folder contracts, gulp_emissions allow any users to call it. It will then fetch the emissions from the backstop pool, record it under the variable new_emissions and distribute it with do_gulp_emissions(e, new_emissions).

do_gulp_emissions then calls update_reserve_emission_eps to adjust the new timeframe and new eps.

fn update_reserve_emission_eps(
    e: &Env,
    reserve_config: &ReserveConfig,
    asset: &Address,
    res_token_id: u32,
    new_reserve_emissions: i128,
) {
    ....
    let expiration: u64 = e.ledger().timestamp() + 7 * 24 * 60 * 60; //@my_comment <---- new expiration date

    if let Some(mut emission_data) = distributor::update_emission_data(
        e,
        res_token_id,
        supply,
        10i128.pow(reserve_config.decimals),
    ) {
        // data exists - update it with old config

        if emission_data.last_time != e.ledger().timestamp() {
            // force the emission data to be updated to the current timestamp
            emission_data.last_time = e.ledger().timestamp();
        }
        // determine the amount of tokens not emitted from the last config
        if emission_data.expiration > e.ledger().timestamp() {
            let time_since_last_emission = emission_data.expiration - e.ledger().timestamp();

            // Eps is scaled by 14 decimals
            let tokens_since_last_emission = i128(emission_data.eps).fixed_mul_floor(
                e,
                &i128(time_since_last_emission),
                &SCALAR_7,
            );
-->         tokens_left_to_emit += tokens_since_last_emission;
        }

-->     let eps = u64(tokens_left_to_emit * SCALAR_7 / (7 * 24 * 60 * 60)).unwrap_optimized();

        emission_data.expiration = expiration;
        emission_data.eps = eps;
        storage::set_res_emis_data(e, &res_token_id, &emission_data);
        PoolEvents::reserve_emission_update(e, res_token_id, eps, expiration);
    } else {
        ....
    }
}

As shown by the code, it will calculate the new expiration time and calculate the previous un-distributed rewards before diluting it over the new expiration timestamp.

There is no restriction on the minimum time that has to pass before this function can be called. If we look at do_gulp_emissions we can see that the only restriction is on the value of new_emissions. (Comment is the original comment from the code).

fn do_gulp_emissions(e: &Env, new_emissions: i128) {
  // ensure enough tokens are being emitted to avoid rounding issues
  if new_emissions < SCALAR_7 {
      panic_with_error!(e, PoolError::BadRequest)
  }
  ...
}

The emission token has 7 decimal places, so that means this can be called whenever there is 1 token to be emittted with no minimum time that must pass before it could be called again.

Impact

This bug has been reported before in some audit’s and accepted as a Medium in such as the Infrared audit on Cantina, as well as the Loopfi July Code4rena audit.

Basically, the impact is that since there is no minimum time that must pass before the function can be called again, anyone can repeatedly dilute the existing rewards into a longer timeframe to delay the emissions of the reward.

Users who do not have free funds now, and only plan to deposit sometime in the near future can consistently carry out this attack (like say every 3 minutes) and cause existing rewards to get diluted into the future timeframe. (and that’s extremely unfair to current stakers).

Recommended mitigation steps

Add a minimum time duration that must pass before gulp_emissions can be called again. That way users cannot repeatedly dilute the rewards into a longer timeframe which is unfair for current stakers.

markus_pl10 (Script3) disputed

mootz12 (Script3) commented:

This is probably not an issue. There is a minimum time that must pass before distribute can be called on the backstop (the source for all emissions), which helps mitigate this, as it can only be called once per hour. Also, the min balance check on gulp_emissions prevents emissions from being updated after emissions have stopped being directed towards a pool.

Even in the case where a specific reserve loses it’s emission status, it will not have it’s emissions config updated.

The only case this might impact something is when a reserve gets added, and spamming gulp_emissions every hour might make it take longer for the emissions to “reach full steam”. However, I’m not confident this is true.

LSDan (judge) commented:

This is a hand-wavy hypothetical report that does point to an issue where the protocol would not function as expected and there may be loss of unmatured / unrealized yield (reference). As such, it fits as a valid medium.

mootz12 (Script3) commented:

Fixed to:

  • Create better bounds on when distribute and gulp are run.
  • This fix was primarily for cleaning up reward zone changes, but does fix this as well, given gulp can only be run once a day per pool.

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 rscodes. 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 gulp_emissions function lacked a minimum time interval between calls, allowing repeated resets of the emission expiration and dilution of rewards.

What the attacker needed

No special privileges needed; at least 1 token to be emitted

The fix

The issue was fixed by creating better bounds on when distribute and gulp are run, so gulp can only be run once a day per pool.

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 smart contract gives out rewards over time. If someone can reset the end date of the reward period whenever they want, they can stretch the same rewards over a longer time, so each person gets less per day. This report says the function that resets the end date had no waiting period, so it could be called very often.

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 rscodes

View all

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