When sweepUnclaimedBonus() sweeps excess funds back to the recoveryAddress, it accurately reserves the sum of totalEligibleStake and unclaimedBonus. Because the pool relies on the locked snapshotTotalBonus for actual staker claim math, sweeping out extra donated funds cleanly protects the underlying liabilities.
If the free balance being swept consists of a large post-resolution donation, the amount swept can easily be much larger than totalBonus. The contract attempts to conditionally decrement the live totalBonus variable using a clamp: totalBonus -= amount <= totalBonus ? amount : totalBonus. If the donation was large enough, this clamp forcibly zeroes out totalBonus. Because staker math relies on the frozen snapshotTotalBonus, this doesn't disrupt payouts. However, if the moderator re-flags the pool later, a new snapshot will capture totalBonus (now 0) instead of the true remaining bonus, disrupting the sponsor's bonus allocation.
A user or sponsor donates tokens directly to the pool (transfer without calling contributeBonus) after the pool resolves.
sweepUnclaimedBonus is called by the sponsor, sweeping a volume that exceeds the total documented bonus pool.
The internal state variable totalBonus is permanently zeroes out.
If the pool is subsequently re-flagged by the moderator (while !claimsStarted), the new snapshot incorrectly records a zero bonus, robbing early claimers of their entitled yield.
Create a new test file test/unit/POCTest.t.sol inheriting from BaseConfidencePoolTest, paste the following code inside the contract body, and run it using the command forge test --match-test test_POC_SweepAccountingClamp -vvv.
A direct code-line fix (like simply removing the clamp) is not practically possible because it would either cause an arithmetic underflow (if amount > totalBonus) or leave the pool insolvent during a re-flag (if the bonus was swept but totalBonus wasn't decremented).
Instead of altering the clamp math, the protocol should explicitly segregate donations from the sweep mechanics. Add a dedicated sweepDonations() function that tracks excess balances strictly outside of totalBonus and eligibleStake. Alternatively, strictly document this edge case via NatSpec, explicitly warning sponsors: "Do not sweep unrecorded donations if a moderator re-flag is anticipated, as doing so permanently erases the stakers' bonus entitlement."
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.
The contest is complete and the rewards are being distributed.