Skip to content
Business logic Audit finding Intermediate

Not enough TAP tokens to exercise if a user participates and exercises in the same epoch

The TAP token allocation for an epoch is fixed, but users can participate and exercise in the same epoch, causing the total minted TAPs to exceed the allocation and making later exercises revert. An attacker could participate and exercise early to consume a disproportionate share, preventing others from purchasing their deserved TAPs.

KIntern_NA Follow

Originally disclosed on Code4rena

Submitted by KIntern_NA

Users were unable to purchase their deserved amount of TAPs

Proof of Concept

During each epoch and for a specific sglAssetID, there is a fixed amount of TAP tokens that will be minted and stored in the STORAGE mapping singularityGauges[epoch][sglAssetID]. Users have the option to purchase these TAP tokens by first calling the function TapiocaOptionBroker.participate() and then executing TapiocaOptionBroker.exerciseOption() before the position expires to buy TAPs at a discounted price. The amount of TAP tokens that a user can purchase with each position can be calculated using the formula:

eligibleTapAmount = position.amount * gaugeTotalForEpoch / totalPoolDeposited

- position.amount: The locked amount of the position in `sglAssetId`.
- gaugeTotalForEpoch: The total number of TAP tokens that can be minted for the `(epoch, sglAssetId)`.
- totalPoolDeposited: The total locked amount of all positions in `sglAssetId`.

The flaw arises when a user who participates in sglAssetId in the current epoch can immediately call exerciseOption() to purchase the TAP tokens. This results in a situation where the participants cannot exercise their expected TAP tokens.

For example:

  • Both Alice and Bob participate in the broker with position.amount = 1.
  • The amount of TAP tokens allocated for the current epoch is gaugeTotalForEpoch = 60.
  • Alice calls exerciseOption() to buy eligibleAmount = 1 * 60 / 2 = 30 TAPs.
  • In the same epoch, Candice participates in the broker with position.amount = 1 and immediately calls exerciseOption(). She will buy eligibleAmount = 1 * 60 / 3 = 20 TAPs.
  • When Bob calls exerciseOption, he can buy eligibleAmount = 1 * 60 / 3 = 20 TAPs, but this cannot happen since if Bob decides to buy 20 TAPs, the total minted amount of TAPs will exceed gaugeTotalForEpoch (30 + 20 + 20 = 70 > 60), resulting in a revert.

Recommended Mitigation Steps

Consider developing a technique similar to the one implemented in twTAP.sol for storing the netAmounts. When a user participates in the broker, perform the following actions:

  • netAmounts[block.timestamp+1] += lock.amount
  • netAmounts[lockTime+lockDuration] += lock.amount

0xRektora (Tapioca) confirmed


The original report as published on Code4rena, by KIntern_NA. 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 eligible TAP amount is calculated using the current total pool deposits, which can change within the same epoch, so early exercisers consume more than their fair share of the fixed epoch allocation.

Impact

Participants may be unable to exercise their expected TAP tokens because the epoch allocation is exhausted by early exercisers.

What the attacker needed

A position in the broker; ability to call participate and exerciseOption

The fix

The fix should track net amounts over time, similar to twTAP, so that participation and exercise in the same epoch do not let early users consume more than their share.

How it was found

  1. Alice and Bob participate with equal position amounts.
  2. Alice calls exerciseOption and buys TAPs based on the current total pool.
  3. Candice participates and immediately exercises, buying more TAPs.
  4. Bob tries to exercise but the total minted would exceed the epoch allocation, so the transaction reverts.

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 smart contract lets people lock tokens and then buy a limited number of reward tokens at a discount. The limit is shared among everyone who locks in the same period. If someone locks and buys immediately, they take a share based on a smaller total, leaving less for others. Later buyers find the limit already reached and their purchase fails.

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 KIntern_NA

View all

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