Utilization ratio can exceed 100% due to missing validation in withdrawal functions
The protocol's maximum utilization check is only applied when borrowing, not when withdrawing, so a large withdrawal can push utilization above 100%. This can cause extreme interest rates and market instability, potentially leading to bad debt and insolvency.
Submitted by 0x007
Finding description
The protocol implements a maximum utilization ratio check via the require_utilization_below_max function, which ensures that utilization = total_liabilities / total_supply remains below a specific threshold. However, this validation is only enforced in the apply_borrow function when increasing liabilities, and is critically missing from the apply_withdraw and apply_withdraw_collateral functions.
Since withdrawals reduce the total_supply denominator in the utilization formula, large withdrawals can cause the utilization ratio to increase beyond the intended maximum threshold. These seems intentional but there are downsides when utilization exceeds 100%. The extra amounts can come from backstop_interest or donations.
Impact
-
Unbounded Interest Rates: The protocol’s interest rate models uses utilization ratio as a key input. When utilization exceeds 100%, the interest rate calculation can produce extreme values.
-
Market Instability:
- Extended periods with utilization ratio above 100% can lead to liquidations, bad debt accumulation and potential protocol insolvency.
backstop_interest_auctionmight not work because the interest has been lent out
Proof of Concept
This was slightly modified from test_build_actions_from_request_withdraw_allows_over_max_util
#[test]
fn test_build_actions_from_request_withdraw_allows_over_100_util() {
let e = Env::default();
e.mock_all_auths();
let bombadil = Address::generate(&e);
let samwise = Address::generate(&e);
let pool = testutils::create_pool(&e);
let (underlying, _) = testutils::create_token_contract(&e, &bombadil);
let (mut reserve_config, mut reserve_data) = testutils::default_reserve_meta();
reserve_config.max_util = 0_9000000;
reserve_data.b_supply = 100_0000000;
reserve_data.d_supply = 89_0000000;
testutils::create_reserve(&e, &pool, &underlying, &reserve_config, &reserve_data);
e.ledger().set(LedgerInfo {
timestamp: 600,
protocol_version: 22,
sequence_number: 1234,
network_id: Default::default(),
base_reserve: 10,
min_temp_entry_ttl: 10,
min_persistent_entry_ttl: 10,
max_entry_ttl: 3110400,
});
let pool_config = PoolConfig {
oracle: Address::generate(&e),
min_collateral: 1_0000000,
bstop_rate: 0_2000000,
status: 0,
max_positions: 2,
};
let user_positions = Positions {
liabilities: map![&e],
collateral: map![&e],
supply: map![&e, (0, 20_0000000)],
};
e.as_contract(&pool, || {
storage::set_pool_config(&e, &pool_config);
storage::set_user_positions(&e, &samwise, &user_positions);
let mut pool = Pool::load(&e);
let requests = vec![
&e,
Request {
request_type: RequestType::Withdraw as u32,
address: underlying.clone(),
// diff1 from: amount: 2_0000000,
amount: 20_0000000,
},
];
let mut user = User::load(&e, &samwise);
let actions = build_actions_from_request(&e, &mut pool, &mut user, requests);
assert_eq!(actions.check_health, false);
let spender_transfer = actions.spender_transfer;
let pool_transfer = actions.pool_transfer;
assert_eq!(spender_transfer.len(), 0);
assert_eq!(pool_transfer.len(), 1);
// diff2 from: assert_eq!(pool_transfer.get_unchecked(underlying.clone()), 2_0000000);
assert_eq!(pool_transfer.get_unchecked(underlying.clone()), 20_0000000);
let positions = user.positions.clone();
assert_eq!(positions.liabilities.len(), 0);
assert_eq!(positions.collateral.len(), 0);
assert_eq!(positions.supply.len(), 1);
// diff3 from: assert_eq!(user.get_supply(0), 18_0000111);
assert_eq!(user.get_supply(0), 1110);
// diff4: add utilization rate check
let reserve = pool.load_reserve(&e, &underlying.clone(), false);
assert_eq!(reserve.utilization(&e), 1_1125010);
});
}
Recommended Mitigation
Add the require_utilization_below_max validation to both the apply_withdraw and apply_withdraw_collateral functions. This ensures that all operations that could potentially increase the utilization ratio (either by increasing liabilities or decreasing supply) are properly validated against the maximum threshold. If you want to permit withdrawal beyond threshold, add a require_utilization_below_100 for withdrawals.
markus_pl10 (Script3) confirmed
PR 48 - Validate if util is below 100% when doing withdraw actions (see commit).
Status: Mitigation confirmed. Full details in reports from 0x007, 0xAlix2, Testerbot and oakcobalt.
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
Impact
Utilization above 100% can produce extreme interest rates and may lead to liquidations, bad debt and protocol insolvency; the backstop interest auction might also fail because the interest has been lent out.
What the attacker needed
A supply position in the pool; withdrawal amount large enough to push utilization over the…
The fix
The issue was mitigated by adding a check that utilization stays below 100% during withdrawal actions.
How it was found
- Set up a pool with a reserve whose maximum utilization is 90% and with existing supply and liabilities.
- Give a user a supply position and no liabilities or collateral.
- Build a withdrawal request for the user's full supply amount.
- Observe that the withdrawal is allowed and the resulting utilization exceeds 100%.
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 lending pool tracks how much of the supplied money has been lent out as a ratio called utilization. The code only checked this ratio when someone borrowed, not when someone withdrew their own supply, so a big withdrawal could make the ratio go over 100 percent. That can make interest rates spike and destabilise the market.
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.