Skip to content
Business logic Audit finding Intermediate

twAML weights can be griefed by burning tokens

The OTAP token has an open burn function, allowing users to burn their tokens after participating in twAML voting. This prevents the exitPosition function from resetting twAML values, so a user's influence on twAML calculations persists indefinitely.

carrotsmuggler Follow

Originally disclosed on Code4rena

Submitted by carrotsmuggler

Users can lock their liquidity in the TOLP contract and mint OTAP tokens in the TOB contract. The TOB contract has a special mechanism called twAML to balance out how much rewards they emit over time.

Basically, if a user commits OTAP tokens worth more than a minimum amount of shares, they are eligible to sway the votes:

bool hasVotingPower =
    lock.ybShares >= computeMinWeight(pool.totalDeposited + VIRTUAL_TOTAL_AMOUNT, MIN_WEIGHT_FACTOR);

This allows them to influence the magnitude, divergence as well as the twAML value of this asset id.

pool.averageMagnitude = (pool.averageMagnitude + magnitude) / pool.totalParticipants; // compute new average magnitude
    // Compute and save new cumulative
    divergenceForce = lock.lockDuration >= pool.cumulative;
    if (divergenceForce) {
        pool.cumulative += pool.averageMagnitude;
    } else {
        if (pool.cumulative > pool.averageMagnitude) {
            pool.cumulative -= pool.averageMagnitude;
        } else {
            pool.cumulative = 0;
        }
    }

    // Save new weight
    pool.totalDeposited += lock.ybShares;

    twAML[lock.sglAssetID] = pool

These values determine how large of a discount the users can get when exercising their options.

Similarly, when users decide to exit their position, or if their lock has expired, either they themselves or other users can kick them out of the TOB system and reset the twAML values to the values it was before.

if (!isSGLInRescueMode && participation.hasVotingPower) {
    TWAMLPool memory pool = twAML[lock.sglAssetID];

    if (participation.divergenceForce) {
    //...

So the twAML change a single user can cause is limited to their lock duration. However, users also have another option: they can directly burn their OTAP token after participating. This is because the OTAP contract has an open burn function.

function burn(uint256 _tokenId) external {
    if (!_isApprovedOrOwner(msg.sender, _tokenId)) revert NotAuthorized();
    _burn(_tokenId);

    emit Burn(msg.sender, _tokenId, options[_tokenId]);
}

Now, these user’s contributions to the twAML calculations cannot be wiped out after their lock expires. This is because the exitPosition function calls otap.burn which will fail since the user has already burnt their tokens.

So users can affect the twAML calculations for an infinite amount of time by burning tokens. This scenario is specifically prevented in the TOLP contract which has a max lock duration enforced with MAX_LOCK_DURATION.

Since users can permanently affect the twAML calculations, this is a medium severity issue.

Proof of Concept

Users can directly burn tokens due to OTAP’s open burn function as evident from the linked code. This prevents exitPosition being called in the TOB contract and thus, never resets the twAML values.

Recommended Mitigation Steps

Disable the open burn function in the OTAP contract. Only allows selected contracts such as the TOB contract to call it.

Assessed type

Math

0xRektora (Tapioca) confirmed


The original report as published on Code4rena, by carrotsmuggler. 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

The OTAP token allows any holder to burn their tokens, which breaks the exitPosition function that relies on burning to reset twAML values.

What the attacker needed

User has OTAP tokens; user has participated in twAML voting

The fix

The open burn function in the OTAP contract should be disabled, allowing only selected contracts such as the TOB contract to call it.

How it was found

  1. User locks liquidity and mints OTAP tokens.
  2. User participates in twAML voting with their OTAP tokens.
  3. User directly burns their OTAP tokens using the open burn function.
  4. When exitPosition is called later, it fails because the tokens are already burnt, so twAML values are not reset.

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.

In this system, users lock tokens and get voting power to influence rewards. Normally, when they exit, their influence is removed. But because they can burn their tokens directly, the exit process fails, so their influence stays forever.

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 carrotsmuggler

View all

42 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.