caelum0x b02a83dcf6 fix: stop deposit() permanently reverting after a full bad-debt wipeout
A full liquidate() bad-debt write-off can drive totalAssets() to exactly
zero while totalLenderShares() stays nonzero (the wiped-out lender never
called withdraw()). deposit()'s exchange-rate formula divided by that
zero assetsBefore and reverted with a bare Panic(0x12) on every future
deposit forever -- a real, permanent DoS on new lending liquidity.
Confirmed live via git stash against the pre-fix bytecode before writing
the fix.

Added an epoch-stamped lender share balance: deposit() now detects this
exact state (totalLenderShares > 0, assetsBefore == 0), bumps a new
lenderEpoch, resets totalLenderShares, and mints the next depositor fresh
1:1 shares. The epoch stamp (not a bare reset) is what keeps this safe --
every prior stale holder's effective lenderShares() reads zero against
the new epoch, so they can never dilute or later drain a fresh
depositor's money once the pool has real value in it again.

Verified two ways: a new Foundry regression test reproducing the exact
wipeout-then-deposit sequence (64 -> 65/65 pass), and live against a
fresh throwaway vault deployed on the persistent self-hosted demo chain
(http://130.61.180.42:8647) -- real deposit() succeeded post-wipeout, the
stale lender's lenderShares() read 0, and their own withdraw(1) reverted
InsufficientShares. The public demo's own vault was untouched (its 0% APR
position never reaches this state).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-29 10:41:03 +03:00
..