From 92d59d0336a90584a5619a103e02b8dbc308cb57 Mon Sep 17 00:00:00 2001 From: Mike MacCana Date: Tue, 10 Nov 2026 16:42:07 +0000 Subject: [PATCH] Lending: the share-inflation attack needs a zero reserve factor A reserve factor rounds its fee up and takes the attacker's one minor unit of interest, so the share price only rises in a reserve with no reserve factor. inflating_shares_through_own_borrow_does_not_pay now runs on such a reserve and checks that the share price rises (quicknode/solana-program-examples#212). Claude-Session: https://claude.ai/code/session_01GZHin6BQpAqf7j2ucSZWkx --- building-financial-products-in-solana/lending.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/building-financial-products-in-solana/lending.md b/building-financial-products-in-solana/lending.md index 8513dec1..3b64af98 100644 --- a/building-financial-products-in-solana/lending.md +++ b/building-financial-products-in-solana/lending.md @@ -167,7 +167,7 @@ Because every division rounds this way, the market never loses a minor unit to r - **Skipping the refresh** would let positions be judged on old values; `ReserveStale`, `ObligationStale`, and `borrow_without_obligation_refresh_is_rejected` close the path. - **Cross-market smuggling**: an obligation in one market pledging reserves from another is refused (`MarketMismatch`, `cross_market_reserve_is_rejected`). - **Dangerous configurations are rejected at write time**: LTV above threshold, zero close factor, misordered rate curves, a rate above 300% a year, a confidence limit of zero or above the price (`rejects_ltv_above_liquidation_threshold`, `rejects_misordered_interest_rate_curve`, `rejects_borrow_rate_above_ceiling_on_update`, `rejects_zero_confidence_limit`, `rejects_confidence_limit_wider_than_the_price`). `update_reserve_config()` also refuses a lower liquidation threshold with `RiskLimitLowered`, so an update cannot pull the liquidation threshold down under an open borrow (`rejects_lowering_liquidation_threshold`). It accepts a lower loan-to-value, down to zero to stop new borrowing (`accepts_lowering_loan_to_value`). -- **Share inflation through the reserve's own borrowing.** Total liquidity counts interest owed on borrows, and a supplier may borrow from the reserve they supply. The attacker is the only supplier of an empty reserve, holding a single minor unit of its shares, and borrows one minor unit from it against collateral in another reserve. Debt rounds up, so a second of interest makes that debt two minor units, and the attacker's unit of shares is worth two without anything being minted. From there, deposits and redemptions push the share price higher, because both round in the pool's favor and the attacker owns the whole pool. Once that unit is worth about 690 USDC, a 1,000 USDC deposit mints one unit of shares, and the attacker's unit redeems half the pool. `inflating_shares_through_own_borrow_does_not_pay` runs this on the default rate curve, and the attacker repays the loan and leaves no bad debt. Without the withheld shares the attacker would keep about 155 USDC of the victim's deposit. With them, the attacker's unit is one of 1,001, and nearly everything the rounding leaves behind goes to shares nobody can redeem. The test asserts that the attacker ends with no more than they started with and the victim gets back at least 99.9% of the deposit. A reserve whose suppliers have all left keeps the 1,000 minor units behind the withheld shares, and the next deposit is priced against them instead of starting the reserve over (`sole_supplier_leaves_the_minimum_behind`). +- **Share inflation through the reserve's own borrowing.** Total liquidity counts interest owed on borrows, and a supplier may borrow from the reserve they supply. The attacker is the only supplier of an empty reserve, holding a single minor unit of its shares, and borrows one minor unit from it against collateral in another reserve. Debt rounds up, so a second of interest makes that debt two minor units. A reserve factor rounds its fee up and would take that whole unit, but in a reserve with no reserve factor the unit goes to suppliers, and the attacker's unit of shares is worth two without anything being minted. From there, deposits and redemptions push the share price higher, because both round in the pool's favor and the attacker owns the whole pool. Once that unit is worth about 690 USDC, a 1,000 USDC deposit mints one unit of shares, and the attacker's unit redeems half the pool. `inflating_shares_through_own_borrow_does_not_pay` runs this on the default rate curve with no reserve factor, and the attacker repays the loan and leaves no bad debt. Without the withheld shares the attacker would keep about 155 USDC of the victim's deposit. With them, the attacker's unit is one of 1,001, and nearly everything the rounding leaves behind goes to shares nobody can redeem. The test asserts that the share price rises after the borrow and again after the round trips, that the attacker ends with no more than they started with, and that the victim gets back at least 99.9% of the deposit. A reserve whose suppliers have all left keeps the 1,000 minor units behind the withheld shares, and the next deposit is priced against them instead of starting the reserve over (`sole_supplier_leaves_the_minimum_behind`). - **Self-liquidation** is allowed (`owner_can_liquidate_their_own_obligation`): it is only possible while unhealthy and is economically pointless. ## Testing Considerations