Commit 71b4410
fix(tanda): auto-complete on defaulter pruning; full-collapse handler
Critical correctness fix surfaced by edge-case testing.
Bug: when future-slot defaulter pruning drove payoutOrder.length below
currentCycle, the tanda became stuck in ACTIVE. The next triggerPayout
would access payoutOrder[currentCycle-1] out-of-bounds and revert with
a Solidity Panic(0x32). Funds (insurance pool, contributions, survivor's
would-be payout) were permanently locked with no recovery path.
Fix has two pieces, both routed through _completeTanda for consistency:
1. markDefaulter auto-complete trigger
When pruning drives payoutOrder.length below currentCycle, the
contract auto-completes in the same transaction. Defensive
payoutOrderAssigned guard prevents premature completion in the
pre-VRF window.
2. _completeTanda zero-active branch
Early-return into new _fullCollapse helper when activeParticipantCount
is zero. Sweeps the entire token balance to treasury (lender-of-last-
resort rule). Forfeits all prior pendingWithdrawals and insurance
balances. No Completion NFTs minted. FullCollapse event emitted.
Also fixes a related stranded-funds bug: the existing slash-pool guard
'slashedPool > 0 && activeParticipantCount > 0' silently stranded the
slash pool when natural completion happened with zero actives. Routing
all zero-active completions through _fullCollapse handles both entry
points uniformly.
Tests:
- Renamed and rewrote test_KNOWN_BUG_allFutureSlotDefaulters_triggersOOB
to test_allFutureSlotDefaulters_autoCompletes. Asserts exact survivor
breakdown: 475 cycle-1 payout + 20 insurance refund + 100 excess
contribution refund + 38 slash share = 633 USDC.
- New test_fullCollapse_allDefaulters_everythingToTreasury: 5 marks,
final mark triggers full collapse, treasury sweeps full 550 USDC
balance, all prior credits wiped, contract drains to zero.
85 tests pass, 0 regressions. Existing test_defaulter_pastSlot_keptInOrder
unchanged — confirms the Case 4 'inactive recipient at current slot'
scenario considered during design is unreachable by construction.
CLAUDE.md: new 'Auto-completion on defaulter pruning' subsection
documenting both the partial-survival and full-collapse paths.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 5ab81e8 commit 71b4410
3 files changed
Lines changed: 692 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
99 | 99 | | |
100 | 100 | | |
101 | 101 | | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
102 | 111 | | |
103 | 112 | | |
104 | 113 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
292 | 292 | | |
293 | 293 | | |
294 | 294 | | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
295 | 300 | | |
296 | 301 | | |
297 | 302 | | |
| |||
609 | 614 | | |
610 | 615 | | |
611 | 616 | | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
612 | 627 | | |
613 | 628 | | |
614 | 629 | | |
615 | 630 | | |
616 | 631 | | |
617 | | - | |
| 632 | + | |
618 | 633 | | |
619 | 634 | | |
620 | 635 | | |
| |||
650 | 665 | | |
651 | 666 | | |
652 | 667 | | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
653 | 678 | | |
654 | 679 | | |
655 | 680 | | |
| |||
741 | 766 | | |
742 | 767 | | |
743 | 768 | | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
744 | 777 | | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
745 | 783 | | |
746 | 784 | | |
747 | | - | |
| 785 | + | |
748 | 786 | | |
749 | 787 | | |
750 | 788 | | |
| |||
768 | 806 | | |
769 | 807 | | |
770 | 808 | | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
771 | 843 | | |
772 | 844 | | |
773 | 845 | | |
| |||
0 commit comments