Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions finance/lending/anchor-v1/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## Unreleased (2026-11-10)

`inflating_shares_through_own_borrow_does_not_pay` now runs its attack. The
borrow reserve used the default 10% reserve factor, which rounds its fee up, so
the program took the attacker's one minor unit of interest as its fee: the share
price never rose, the ratchet loop never moved it, and the test's assertions
held without the attack happening. The borrow reserve now has a zero reserve
factor, the attacker's best case, and the test asserts that the share price
rises after the borrow and again after the round trips. With a 10% reserve
factor the new assertion fails.

## Unreleased (2026-10-07)

Round interest against the borrower. Every debt is `borrowed_principal`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mod common;

use common::{default_config, Env};
use lending::constants::MINIMUM_SHARES;
use lending::state::ReserveConfig;
use solana_kite::mint_tokens_to_token_account;

/// The first deposit mints shares one-for-one, less the `MINIMUM_SHARES`
Expand Down Expand Up @@ -133,16 +134,25 @@ fn sole_supplier_leaves_the_minimum_behind() {
/// victim is not robbed outright; instead a deposit just under two shares'
/// worth mints one, and the attacker's share redeems half the pool.
///
/// The rate curve is the default one. Nothing about the attack needs the
/// market owner's cooperation or bad debt: the attacker repays what they owe.
/// The rate curve is the default one, with the reserve factor at zero. A
/// nonzero reserve factor rounds its fee up, so the program would take the one
/// unit of interest as its fee and the share price would not move; zero is the
/// attacker's best case. The test asserts that the share price rises after the
/// borrow and again after the round trips, so the attack does run. Nothing about
/// the attack needs the market owner's cooperation or bad debt: the attacker
/// repays what they owe.
///
/// `MINIMUM_SHARES` counts as shares nobody holds in every share conversion,
/// so the attacker's one share is 1 of 1_001 and whatever the rounding leaves
/// behind is spread mostly across shares they cannot redeem.
#[test]
fn inflating_shares_through_own_borrow_does_not_pay() {
let mut env = Env::new();
let usdc = env.add_empty_reserve(6, common::dollars(1), default_config());
let no_reserve_factor = ReserveConfig {
reserve_factor_bps: 0,
..default_config()
};
let usdc = env.add_empty_reserve(6, common::dollars(1), no_reserve_factor);
let collateral = env.add_reserve(6, common::dollars(1), default_config());

let attacker = env.create_user();
Expand All @@ -169,6 +179,10 @@ fn inflating_shares_through_own_borrow_does_not_pay() {
env.warp_seconds(1);
env.refresh_reserve_only(&attacker, &usdc);
assert_eq!(env.reserve(&usdc).current_borrowed_amount().unwrap(), 2);
// The extra unit of interest went to suppliers, so a share is now worth
// more than one minor unit.
let after_borrow = env.reserve(&usdc).total_liquidity().unwrap();
assert!(after_borrow > env.reserve(&usdc).total_shares().unwrap());

// Ratchet until one share is worth more than half the victim's deposit.
let victim_deposit: u64 = 1_000_000_000;
Expand All @@ -186,6 +200,9 @@ fn inflating_shares_through_own_borrow_does_not_pay() {
env.try_redeem(&attacker, &usdc, 1).unwrap();
}

// The round trips raised the share price further.
assert!(env.reserve(&usdc).total_liquidity().unwrap() > after_borrow);

let victim = env.create_user();
let victim_liquidity = env.fund(&victim, usdc.mint, victim_deposit);
let victim_share = env.supply(&victim, &usdc, victim_deposit);
Expand Down
11 changes: 11 additions & 0 deletions finance/lending/anchor/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## Unreleased (2026-11-10)

`inflating_shares_through_own_borrow_does_not_pay` now runs its attack. The
borrow reserve used the default 10% reserve factor, which rounds its fee up, so
the program took the attacker's one minor unit of interest as its fee: the share
price never rose, the ratchet loop never moved it, and the test's assertions
held without the attack happening. The borrow reserve now has a zero reserve
factor, the attacker's best case, and the test asserts that the share price
rises after the borrow and again after the round trips. With a 10% reserve
factor the new assertion fails.

## Unreleased (2026-10-07)

Round interest against the borrower. Every debt is `borrowed_principal`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mod common;
use common::{default_config, Env};
use lending::constants::MINIMUM_SHARES;
use lending::errors::LendingError;
use lending::state::ReserveConfig;
use solana_kite::mint_tokens_to_token_account;

/// The first deposit mints shares one-for-one, less the `MINIMUM_SHARES`
Expand Down Expand Up @@ -131,16 +132,25 @@ fn sole_supplier_leaves_the_minimum_behind() {
/// victim is not robbed outright; instead a deposit just under two shares'
/// worth mints one, and the attacker's share redeems half the pool.
///
/// The rate curve is the default one. Nothing about the attack needs the
/// market owner's cooperation or bad debt: the attacker repays what they owe.
/// The rate curve is the default one, with the reserve factor at zero. A
/// nonzero reserve factor rounds its fee up, so the program would take the one
/// unit of interest as its fee and the share price would not move; zero is the
/// attacker's best case. The test asserts that the share price rises after the
/// borrow and again after the round trips, so the attack does run. Nothing about
/// the attack needs the market owner's cooperation or bad debt: the attacker
/// repays what they owe.
///
/// `MINIMUM_SHARES` counts as shares nobody holds in every share conversion,
/// so the attacker's one share is 1 of 1_001 and whatever the rounding leaves
/// behind is spread mostly across shares they cannot redeem.
#[test]
fn inflating_shares_through_own_borrow_does_not_pay() {
let mut env = Env::new();
let usdc = env.add_empty_reserve(6, common::dollars(1), default_config());
let no_reserve_factor = ReserveConfig {
reserve_factor_bps: 0,
..default_config()
};
let usdc = env.add_empty_reserve(6, common::dollars(1), no_reserve_factor);
let collateral = env.add_reserve(6, common::dollars(1), default_config());

let attacker = env.create_user();
Expand All @@ -167,6 +177,10 @@ fn inflating_shares_through_own_borrow_does_not_pay() {
env.warp_seconds(1);
env.refresh_reserve_only(&attacker, &usdc);
assert_eq!(env.reserve(&usdc).current_borrowed_amount().unwrap(), 2);
// The extra unit of interest went to suppliers, so a share is now worth
// more than one minor unit.
let after_borrow = env.reserve(&usdc).total_liquidity().unwrap();
assert!(after_borrow > env.reserve(&usdc).total_shares().unwrap());

// Ratchet until one share is worth more than half the victim's deposit.
let victim_deposit: u64 = 1_000_000_000;
Expand All @@ -184,6 +198,9 @@ fn inflating_shares_through_own_borrow_does_not_pay() {
env.try_redeem(&attacker, &usdc, 1).unwrap();
}

// The round trips raised the share price further.
assert!(env.reserve(&usdc).total_liquidity().unwrap() > after_borrow);

let victim = env.create_user();
let victim_liquidity = env.fund(&victim, usdc.mint, victim_deposit);
let victim_share = env.supply(&victim, &usdc, victim_deposit);
Expand Down
11 changes: 11 additions & 0 deletions finance/lending/quasar/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## Unreleased (2026-11-10)

`inflating_shares_through_own_borrow_does_not_pay` now runs its attack. The
borrow reserve used the default 10% reserve factor, which rounds its fee up, so
the program took the attacker's one minor unit of interest as its fee: the share
price never rose, the ratchet loop never moved it, and the test's assertions
held without the attack happening. The borrow reserve now has a zero reserve
factor, the attacker's best case, and the test asserts that the share price
rises after the borrow and again after the round trips. With a 10% reserve
factor the new assertion fails.

## [Unreleased] (2026-10-07)

### Changed
Expand Down
38 changes: 30 additions & 8 deletions finance/lending/quasar/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1662,16 +1662,17 @@ mod clock_warp {
vault: Pubkey,
share: Pubkey,
price: Pubkey,
reserve_factor_bps: u16,
) {
// 75% LTV, 80% liquidation threshold, 5% bonus, 50% close factor,
// 10% reserve factor, kink 80%, 2% / 20% / 150% APR curve, and a
// 1% confidence limit on the price feed.
// the given reserve factor, kink 80%, 2% / 20% / 150% APR curve,
// and a 1% confidence limit on the price feed.
let config: [u16; 10] = [
7_500,
8_000,
500,
5_000,
1_000,
reserve_factor_bps,
8_000,
200,
2_000,
Expand Down Expand Up @@ -1705,8 +1706,17 @@ mod clock_warp {
}

/// Create the market and both reserves with no deposits, for tests of
/// the first deposit itself.
/// the first deposit itself. Both reserves keep a 10% reserve factor.
fn setup_empty_markets(&mut self) {
self.setup_empty_markets_with_borrow_reserve_factor(1_000);
}

/// As `setup_empty_markets`, with the borrow reserve keeping
/// `borrow_reserve_factor_bps` of interest as fees.
fn setup_empty_markets_with_borrow_reserve_factor(
&mut self,
borrow_reserve_factor_bps: u16,
) {
self.init_market();
self.set_price(COLLATERAL_MINT, self.collateral_price, dollars(1));
self.set_price(BORROW_MINT, self.borrow_price, dollars(1));
Expand All @@ -1716,13 +1726,15 @@ mod clock_warp {
self.collateral_vault,
self.collateral_share_mint,
self.collateral_price,
1_000,
);
self.initialize_reserve(
BORROW_MINT,
self.borrow_reserve,
self.borrow_vault,
self.borrow_share_mint,
self.borrow_price,
borrow_reserve_factor_bps,
);
}

Expand Down Expand Up @@ -2426,9 +2438,13 @@ mod clock_warp {
/// instead a deposit just under two shares' worth mints one, and the
/// attacker's share redeems half the pool.
///
/// The rate curve is the harness's usual one. Nothing about the attack
/// needs the market owner's cooperation or bad debt: the attacker repays
/// what they owe.
/// The rate curve is the harness's usual one, with the borrow reserve's
/// reserve factor at zero. A nonzero reserve factor rounds its fee up, so
/// the program would take the one unit of interest as its fee and the share
/// price would not move; zero is the attacker's best case. The test asserts
/// that the share price rises after the borrow and again after the round
/// trips, so the attack does run. Nothing about the attack needs the market
/// owner's cooperation or bad debt: the attacker repays what they owe.
///
/// `MINIMUM_SHARES` counts as shares nobody holds in every share
/// conversion, so the attacker's one share is 1 of 1_001 and whatever the
Expand All @@ -2437,7 +2453,7 @@ mod clock_warp {
#[test]
fn inflating_shares_through_own_borrow_does_not_pay() {
let mut world = World::new();
world.setup_empty_markets();
world.setup_empty_markets_with_borrow_reserve_factor(0);
world.open_collateral_reserve();
let budget = world.tokens(ATTACKER_BORROW);

Expand Down Expand Up @@ -2486,6 +2502,10 @@ mod clock_warp {
)
.unwrap();
assert_eq!(debt, 2);
// The extra unit of interest went to suppliers, so a share is now worth
// more than one minor unit.
let (after_borrow, shares) = world.borrow_reserve_totals();
assert!(after_borrow > shares);

// Ratchet until one share is worth more than half the victim's deposit.
let victim_deposit = world.tokens(VICTIM_BORROW);
Expand All @@ -2508,6 +2528,8 @@ mod clock_warp {
.redeem(ATTACKER, ATTACKER_BORROW, ATTACKER_BORROW_SHARE, 1)
.assert_success();
}
// The round trips raised the share price further.
assert!(world.borrow_reserve_totals().0 > after_borrow);

world
.supply(VICTIM, VICTIM_BORROW, VICTIM_BORROW_SHARE, victim_deposit)
Expand Down
Loading