A vesting schedule that could never finish vesting — the shareMint geometric decay

Another verified fix landed on TTSwap this week (PR #340, bounty #325): shareMint was supposed to release a share allocation over chips unlocks, but the math guaranteed it never would. Independent QA reproduced the exact claimed failure — full allocation minted: 683593 != 1000000 — on unfixed code, and 5/5 schedule tests pass on the fix branch.

The bug class

The contract intended: each shareMint() call releases leftamount / chips, and after chips unlocks the allocation is fully vested. The implementation divided by chips — a value stored on the share struct that never decremented. So every unlock released the same fraction of the original denominator while leftamount shrank:

unlock 1: 1,000,000 / 4 = 250,000 leftamount -> 750,000 unlock 2: 750,000 / 4 = 187,500 leftamount -> 562,500 unlock 3: 562,500 / 4 = 140,625 leftamount -> 421,875 unlock 4: 421,875 / 4 = 105,469 leftamount -> 316,406 stranded 

Geometric decay. Roughly a quarter to a third of every allocation was unreachable — and once chips unlocks were consumed, terminal calls minted 0 while still burning metric. The failing test caught it precisely: after 4 unlocks on a 1M/4-chip grant, only 683,593 had minted.

The fix pattern

Track consumption, divide by what remains:

mapping(address => uint256) internal shareUnlocks; uint256 unlocks = shareUnlocks[msg.sender]; uint256 chips = shares[msg.sender].chips; uint256 chipsLeft = unlocks < chips ? chips - unlocks : 1; mintamount = leftamount / chipsLeft; // final chip sweeps the dust shareUnlocks[msg.sender] = unlocks + 1; 

Now each chip releases an equal share of what's left, and the last unlock sweeps the remainder — chips unlocks mint exactly leftamount. The counter resets on a fresh grant and is cleared by burnShare, so merges mid-schedule complete correctly (covered by a dedicated test).

Why skeptical devs respect this

The worker didn't claim "vesting fixed." They shipped test/ShareMintSchedule.t.sol with the issue's exact figure reproduced on base, 62 focused token/share tests green, and honestly disclosed the residual: 2**metric overflows past ~127 unlocks — a separate defect already fixed upstream in v2.1.0, explicitly scoped out. Verify-don't-assert, including about your own scope.

The meta-lesson

Any schedule — vesting, drip, decay, installment — has the same failure mode: a denominator that doesn't track progress turns linear release into geometric decay. If your loop counter isn't in the math, the math is lying to you.

Same discipline on our end: every number on a product page is verified against the delivered archive before it ships. Free tools and the auto-updating store link are on the nexusfoundry dev.to profile.