Skip to content
Business logic Audit finding Advanced

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.

deadrxsezzz Follow

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, mintedInWeek is increased in extractTAP(). If boosted with TAP sent from outside the DSO it actually reduces its supply.


The original report as published on Code4rena, by deadrxsezzz. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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.

More by deadrxsezzz

View all

11 more disclosed reports, best first.

More from Tapioca Invitational

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.