Repository navigation
lending: make the share-inflation test run its attack - #212
Merged
mikemaccana merged 1 commit intoNov 10, 2026
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
inflating_shares_through_own_borrow_does_not_paypassed 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, andaccrue_interestrounds that fee up. The one unit of interest became a one-unit program fee and suppliers gained nothing.I instrumented the anchor-v1 test:
total_liquiditywas 1,001 against 1,001 shares, withaccumulated_program_fees1.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
total_liquidityexceedstotal_shares, so the share price rose.total_liquiditygrew further. In anchor-v1 the reserve goes from 1,002 to 1,066 units.World::initialize_reservenow takes one, andsetup_empty_markets_with_borrow_reserve_factorpasses it for the borrow reserve.setup_empty_marketskeeps 10% for both reserves, so other tests are unchanged.CHANGELOG.mdentries for all three versions.Applied to
finance/lending/anchor-v1,finance/lending/anchorandfinance/lending/quasar.Testing
I built each program with
cargo build-sbf(Agave 3.1.8) and ran its tests:cargo test, all suites pass.cargo +1.97.1 test, all suites pass. LiteSVM 0.18 needs rustc 1.97.1.cargo test, 45 passed.cargo fmt --checkis clean.Generated by Claude Code