Skip to content

lending: make the share-inflation test run its attack - #212

Merged
mikemaccana merged 1 commit into
mainfrom
claude/peaceful-ptolemy-oh26c8-lending-inflation-test
Nov 10, 2026
Merged

mikemaccana merged 1 commit into
mainfrom
claude/peaceful-ptolemy-oh26c8-lending-inflation-test

Conversation

@mikemaccana

Copy link
Copy Markdown
Collaborator

The bug

inflating_shares_through_own_borrow_does_not_pay passed without the attack ever happening.

The test borrows one minor unit from a reserve, waits one second, and relies on rounding to make the debt two units, so the attacker's lone share is worth more than one unit. But the reserve used default_config(), which keeps a 10% reserve factor, and accrue_interest rounds that fee up. The one unit of interest became a one-unit program fee and suppliers gained nothing.

I instrumented the anchor-v1 test:

  • After the borrow: the reserve's total_liquidity was 1,001 against 1,001 shares, with accumulated_program_fees 1.
  • After all 64 ratchet round trips: the same values.

The share price never moved, so the assertions that the attacker does not profit and the victim gets their deposit back were checking a pool nobody had attacked.

The fix

  • The borrow reserve now uses a zero reserve factor, the attacker's best case. The collateral reserve keeps the default config.
  • After the borrow, the test asserts that total_liquidity exceeds total_shares, so the share price rose.
  • After the round trips, it asserts that total_liquidity grew further. In anchor-v1 the reserve goes from 1,002 to 1,066 units.
  • The existing assertions stay: the attacker ends with no more than their budget, and the victim gets back at least 99.9% of the deposit.
  • The doc comment explains why the reserve factor is zero.
  • Quasar's test harness had no way to pick a reserve factor. World::initialize_reserve now takes one, and setup_empty_markets_with_borrow_reserve_factor passes it for the borrow reserve. setup_empty_markets keeps 10% for both reserves, so other tests are unchanged.
  • CHANGELOG.md entries for all three versions.

Applied to finance/lending/anchor-v1, finance/lending/anchor and finance/lending/quasar.

Testing

I built each program with cargo build-sbf (Agave 3.1.8) and ran its tests:

  • anchor-v1: cargo test, all suites pass.
  • anchor: cargo +1.97.1 test, all suites pass. LiteSVM 0.18 needs rustc 1.97.1.
  • quasar: cargo test, 45 passed.
  • Regression check: with the borrow reserve set back to a 10% reserve factor, the new assertion fails in anchor-v1 and in quasar. I didn't run that check on the Anchor v2 version.
  • cargo fmt --check is clean.

Generated by Claude Code

inflating_shares_through_own_borrow_does_not_pay borrowed from a reserve with
the default 10% reserve factor. The fee rounds up, so the program took the one
minor unit of interest as its fee and suppliers gained nothing: after the
borrow the reserve held 1,001 units against 1,001 shares, and after the ratchet
loop it still did. The test passed without the share price ever moving.

The borrow reserve now has a zero reserve factor, and the test asserts that the
share price rises after the borrow and again after the round trips (1,002 then
1,066 units in anchor-v1). With the 10% factor restored, the new assertions
fail. The attacker still ends with less than they started with, and the victim
still gets back at least 99.9% of the deposit.

Applied to anchor-v1, anchor and quasar.

Claude-Session: https://claude.ai/code/session_01GZHin6BQpAqf7j2ucSZWkx
@mikemaccana
mikemaccana merged commit f67b69c into main Nov 10, 2026
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant