Skip to content
DoS Audit finding Intermediate

Division before multiplication may cause division by zero DOS during low backstop supply

The backstop token valuation performs integer division before multiplication, so with a low-decimal oracle and low backstop supply the value rounds to zero, causing a division-by-zero panic that blocks interest and bad-debt auctions.

oakcobalt Follow

Originally disclosed on Code4rena

Submitted by oakcobalt

https://github.com/code-423n4/2025-02-blend/blob/f23b3260763488f365ef6a95bfb139c95b0ed0f9/blend-contracts-v2/pool/src/auctions/backstop_interest_auction.rs#L76-L84

Finding description and impact

Division before multiplication and unchecked oracle decimals may cause division by zero DOS during low backstop supply.

Proof of Concept

When calculating backstop_token_to_base, division before multiplication is performed when deriving backstop_value_base. Currently, oracle_scalar is intended to prevent excessive precision loss in backstop_value_base calculation.

There are two vulnerabilities here:

  1. Pool deployment is permissionless and oracle_scalar is based on unchecked pool’s constructor parameters, i.e. custom oracle implementation oracle_client.decimals(). There is no check that the oracle’s decimal is greater than 7. When oracle_scalar is less than 10e7, backstop_value_base will round down and lose precision.
pub fn execute_initialize(
    e: &Env,
    admin: &Address,
    name: &String,
    oracle: &Address,
    bstop_rate: &u32,
    max_positions: &u32,
    min_collateral: &i128,
    backstop_address: &Address,
    blnd_id: &Address,
) {
    let pool_config = PoolConfig {
|>      oracle: oracle.clone(), //@audit no check on oracle decimal precisions.
        min_collateral: *min_collateral,
        bstop_rate: *bstop_rate,
        status: 6,
        max_positions: *max_positions,
    };

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

  1. Division before multiplication: backstop_value_base performs integer division first before multiplication in backstop_token_to_base.
    // get value of backstop_token (BLND-USDC LP token) to base
    let pool_backstop_data = backstop_client.pool_data(&e.current_contract_address());
    //@audit (usdc * oracle_scalar / scalar_7) perform division first before multiplication in `backstop_token_to_base`
|>  let backstop_value_base = pool_backstop_data
        .usdc
        .fixed_mul_floor(e, &oracle_scalar, &SCALAR_7) // adjust for oracle scalar
        * 5; // Since the backstop LP token is an 80/20 split of USDC/BLND, we multiply by 5 to get the value of the BLND portion
    let backstop_token_to_base =
        backstop_value_base.fixed_div_floor(e, &pool_backstop_data.tokens, &SCALAR_7);

    // determine lot amount of backstop tokens needed to safely cover bad debt, or post
    // all backstop tokens if there isn't enough to cover the bad debt
    let mut lot_amount = debt_value
        .fixed_mul_floor(e, &1_2000000, &SCALAR_7)
        .fixed_div_floor(e, &backstop_token_to_base, &SCALAR_7);

https://github.com/code-423n4/2025-02-blend/blob/f23b3260763488f365ef6a95bfb139c95b0ed0f9/blend-contracts-v2/pool/src/auctions/bad_debt_auction.rs#L75-L81

The above may cause backstop_token_to_base round down to zero when backstop is low in supply, resulting in division by zero panic in create_interest_auction_data and create_bad_debt_auction_data. Backstop supply(pool_backstop_data.tokens) can be low when lending pool is new or due to large backstop depositor withdrawals.

POC

Suppose pool_backstop_data.usdc = 0_0050000, pool_backstop_data.tokens = 10_0000000, oracle_scalar = 100.

backstop_value_base = (pool_backstop_data.usdc * oracle_scalar / SCALAR_7) * 5

                    = (50000 * 100 / 1e7) * 5 -> 0

backstop_token_to_base = backstop_value_base * SCALAR_7 / pool_backstop_data.tokens

                       = 0

Case 1: bad debt auction: lot_amount = debt_value * 1.2 * SCALAR_7 / backstop_token_to_base -> division by zero

Case 2: interest auction: bit_amount = interest_value * 1.2 * SCALAR_7 / backstop_token_to_base -> division by zero

As seen above, both bad debt auction and interest auction flow can be DOSsed when backstop supply is critically low.

Impact

When backstop token supply for a pool is critically low (or zero), the pool can be extremely unhealthy and risky. The pool needs more backstop deposits through interest auctions where existing backstop credits accumulated in the pool’s reserves can be auctioned in exchange for more backstop tokens to offset bad debts.

However, from the POC we see that interest auction can be DOSsed and the pool cannot attract more backstop tokens when it needs them the most.

Recommended mitigation steps

In pool’s constructor → require_valid_pool_config, consider enforcing checks that the oracle decimal is no less than 7.

May also consider fetching the comet pool’s usdc and total supply to derive backstop_token_to_base directly without relying on the intermediate pool_backstop_data.tokens.

markus_pl10 (Script3) confirmed

mootz12 (Script3) commented:

Validated this is an issue. Documentation likely needs to be added to ensure extremely low decimal oracles aren’t used.

Regardless, an interest auction likely should be able to be created for an empty backstop, even if this situation is unlikely (can’t borrow funds unless your past backstop threshold).

No risk to backstop credit, as if more tokens enter the backstop, the credit is safely tracked and the interest auction can be created later. This is incredibly likely as interest auctions need at least $200 to get kicked off, and this example shows $0.05 in total backstop deposits.

LSDan (judge) commented:

This holds as a medium for me. The functionality of the protocol could be impacted enough that mitigations are required.

mootz12 (Script3) commented:

Fixed here - token price returned from backstop, no longer depends on pool backstop state.

Testerbot (warden) commented:

I would like to address the classification of this issue, as I believe it may have been incorrectly assessed.

The issue in question was marked as medium severity. However, I would like to provide my reasoning for reconsideration:

The core of the reported issue lies in the following formula:

backstop_value_base = (pool_backstop_data.usdc * oracle_scalar / SCALAR_7)

If the product of pool_backstop_data.usdc * oracle_scalar is less than 10e7, then backstop_value_base will round down to zero, leading to a division by zero panic later in the code.

Likelihood Analysis

The condition to trigger this issue is pool_backstop_data.usdc * oracle_scalar < 10e7.

In Soroban, tokens typically have 7 decimal places, which applies to USDC. Therefore, the first condition to meet is for pool_backstop_data.usdc to be less than 1 USDC (10e7). This means that at least 1 USDC will prevent this issue from occurring.

If we consider 0.1 USDC (10e6), the oracle price would need to have at most 1 decimal (10). For 0.01 USDC (10e5), the oracle price would need at most 2 decimals (100), and so on.

Consequently, it is unlikely that such a small amount of USDC would be deposited in the backstop, and having oracle prices with such limited decimal places simultaneously is even less probable. From the currently deployed oracle providers on Stellar, I have not found any prices with fewer than 7 decimals:

Current oracle providers. Reflector contract. Reflector set prices with 7 decimals.

Impact Analysis

Even in the unlikely event that this situation occurs, the impact does not warrant a medium severity classification. The report describes the following impact:

The above may cause backstop_token_to_base round down to zero when backstop is low in supply, resulting in division by zero panic in create_interest_auction_data and create_bad_debt_auction_data.

The division by zero will prevent the creation of bad debt and interest auctions. Some facts about this:

  • These functions are not core components of the lending protocol that put user funds at risk.
  • The denial of service (DoS) regarding the interest auction is temporary and easily remedied; an admin or any user can simply make a deposit to the backstop contract, which is not affected by this issue.
  • This situation is no different to a pool without backstop deposits, where it is normal not to have bad debt or interest auctions (as there would be no one to cover bad debt or claim interest).

In conclusion, we are dealing with a scenario that is very unlikely to occur, and the worst-case impact is merely a temporary DoS.

rscodes (warden) commented:

In addition to Testerbot’s comment, I would like to add that according to the competition page token table: Low decimals ( < 6) | Out of scope.

I understand that the above submission is about oracle decimal. However, oracle decimal => token decimal. If low decimal tokens are not used (as oos) then it doesn’t make sense to use a low decimal oracle, since the oracle is supposed to reflect the price of the token.

LSDan (judge) commented:

Ruling stands. This is 6, not < 6. Medium still holds for me.

Blend mitigated:

Commit f0296cf to make lp token valuation pool independent for auction creation.

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


The original report as published on Code4rena, by oakcobalt. 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 code divides before multiplying when computing the backstop token value and does not enforce a minimum oracle decimal precision, so the value can round to zero.

Impact

Interest and bad-debt auctions could not be created while backstop supply is critically low, temporarily blocking the pool from attracting more backstop tokens; the text notes no risk to backstop credit and that a deposit remedies it.

What the attacker needed

Permissionless pool deployment; oracle with low decimals; critically low backstop supply

How it was found

  1. Deploy a pool with an oracle whose decimals are low, so oracle_scalar is small.
  2. Ensure the backstop supply is very low, for example a new pool or after large withdrawals.
  3. Trigger creation of an interest auction or a bad-debt auction.
  4. The backstop value rounds to zero, and the later division by backstop_token_to_base panics.

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.

Smart contracts often use fixed-point maths, where numbers are scaled by a constant to represent fractions. If you divide before multiplying, small values can round down to zero, and a later division by that zero crashes the transaction. Here, a pool with very little backstop money and an oracle with few decimals could not start auctions.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

More by oakcobalt

View all

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

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.