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.
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 buyeligibleAmount = 1 * 60 / 2 = 30TAPs. - In the same epoch, Candice participates in the broker with
position.amount = 1and immediately callsexerciseOption(). She will buyeligibleAmount = 1 * 60 / 3 = 20TAPs. - When Bob calls
exerciseOption, he can buyeligibleAmount = 1 * 60 / 3 = 20TAPs, but this cannot happen since if Bob decides to buy 20 TAPs, the total minted amount of TAPs will exceedgaugeTotalForEpoch(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.amountnetAmounts[lockTime+lockDuration] += lock.amount
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
- Alice and Bob participate with equal position amounts.
- Alice calls exerciseOption and buys TAPs based on the current total pool.
- Candice participates and immediately exercises, buying more TAPs.
- 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.