Sending more TAP tokens to the TapToken.sol contract does not actually increase the total amount to be distributed
The TapToken contract treats any TAP tokens sent to it as boosted TAP and adds them to the weekly emission, but it still deducts those same tokens from the dso_supply accounting. An attacker could send extra TAP to the contract to speed up the emission schedule and break the intended linearly decaying distribution curve, and with enough tokens could cause an underflow that blocks weekly rollover.
Originally disclosed on Code4rena
Submitted by deadrxsezzz
Within the TapToken contract, the to-be-distributed balance is tracked by the dso_supply. Every week a percentage of is distributed to the users via oTAP emissions.
function emitForWeek() external onlyMinter returns (uint256) {
if (_getChainId() != governanceEid) revert NotValid();
uint256 week = _timestampToWeek(block.timestamp);
if (emissionForWeek[week] > 0) return 0;
// Compute unclaimed emission from last week and add it to the current week emission
uint256 unclaimed;
if (week > 0) {
// Update DSO supply from last minted emissions
dso_supply -= mintedInWeek[week - 1];
// Push unclaimed emission from last week to the current week
unclaimed = emissionForWeek[week - 1] - mintedInWeek[week - 1];
}
uint256 emission = _computeEmission();
emission += unclaimed;
// Boosted TAP is burned and added to the emission to be minted on demand later on in `extractTAP()`
uint256 boostedTAP = balanceOf(address(this));
if (boostedTAP > 0) {
_burn(address(this), boostedTAP);
emission += boostedTAP; // Add TAP in the contract as boosted TAP
emit BoostedTAP(boostedTAP);
}
emissionForWeek[week] = emission;
emit Emitted(week, emission);
return emission;
}
If we look at the code, we’ll see that there’s a check if there’s extra tokens within the contract and distribute them if that’s the case. The problem is that if such funds are distributed, they’ll still be deducted from the dso_supply which will mean that these tokens will not be treated as an extra.
What they’ll do is actually speed up the regular distribution and break the linearly decaying curve of weekly emissions.
Note: From the same core of the problem, there could be an underflow in dso_supply (if there’s enough Boost Tap sent when the weekly emissions have become low enough). This would block rolling over a week, within the TapToken and TapiocaOptionBroker contracts, though no funds will be locked.
Recommended Mitigation Steps
Fix accounting for extra tap tokens sent.
Assessed type
Context
0xRektora (Tapioca) confirmed and commented:
Nice catch,
mintedInWeekis increased inextractTAP(). If boosted withTAPsent from outside the DSO it actually reduces its supply.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the boosted TAP added to the emission is not excluded from the dso_supply deduction, so externally sent tokens are double-counted against the distribution supply.
Impact
Extra TAP sent to the contract speeds up the regular distribution and breaks the linearly decaying emission curve; with enough boosted TAP an underflow in dso_supply could block rolling over a week, though no funds would be locked.
What the attacker needed
Ability to send TAP to the contract
The fix
The accounting should be fixed so that extra TAP tokens sent to the contract are not deducted from dso_supply.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A token contract keeps a running total of how many tokens are left to hand out over time. If someone sends extra tokens to the contract, the code adds them to this week's payout but also subtracts them from the remaining total, so the same tokens are counted twice. That makes the payouts run out faster than planned and can even make the remaining total go negative, which stops the weekly update.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.