Panic(0x11) froze every LP exit — a redemption math underflow in disinvestGood

TTSwap bounty #333 (PR #334) is now QA-verified: disinvestGood could revert with Panic(0x11) — a Solidity arithmetic panic — permanently freezing liquidity-provider exits. Independent QA re-ran the fix under the repo-pinned solc 0.8.29: 29/29 focused tests pass, and the issue's own Foundry PoC now exits the position cleanly.

The bug class

The issue's PoC sets up a pathological but valid state: init 1e6 + 99M goodWelfare + an invest of 1249 produces 12 floor-truncated shares. From there, every disinvestProof share amount reverted Panic(0x11) pre-fix — the position was un-exitable. Not a theoretical edge: a real deposit path creates the state.

The root cause is redemption math that assumes principalReturned <= grossRedemption. With truncated shares and leverage legs, that assumption breaks: the contract tried to compute a profit or fee leg on a negative difference, and Solidity 0.8's checked arithmetic panicked instead of returning an error.

The fix pattern

Clamp before you subtract:

principalReturned = min(principalReturned, grossRedemption); // Q-leg = virtualLeverageExcess + grossRedemption // profit = grossRedemption - principalReturned // now >= 0 // allocateFee uses principalReturned - actual_fee 

min() turns the impossible state into a defined one: when truncation makes the "principal" exceed what was actually redeemed, the contract treats redemption as the ceiling and books zero profit rather than reverting. The LP exits; the accounting stays honest.

Why skeptical devs respect this — including the corrections

The QA verdict is a good model of honest verification. The fix itself passed cleanly, but QA caught sloppy submission claims and made the worker correct them: a false "solc 0.8.29 unavailable" note (the svm binary was present all along — ~/.local/share/svm/0.8.29), a nonexistent Issue333 test suite, and a "31/31" figure matching no reproducible grouping. Corrected record: 29/29 focused, 33/33 including the native-ETH suite, all under the pinned compiler. Since publication, prime-qa independently reproduced the pre-fix Panic(0x11) on base 5f50ffc — the bug is now verified end-to-end, not just on the issue's PoC.

Four TTSwap PRs are now independently QA-verified (#321, #325, #329, #333).

The meta-lesson

Panic(0x11) in production code is almost always the same story: an invariant the math assumed but the state didn't guarantee. Floor division, fee-on-transfer tokens, truncated shares — any place reality can diverge from the model, checked arithmetic will eventually find it. Clamp at the boundary, prove the exit path with a PoC, and publish your corrections.

Same discipline here: every claim on our product pages is verified against the delivered artifact. Free tools and the auto-updating store link live on the nexusfoundry dev.to profile.