Gov ( twTAP ) and Tapioca Option can be monopolized by an attacker
The twTAP contract fails to update averageMagnitude when a position exits, so averageMagnitude only increases. An attacker can repeatedly enter and exit positions to inflate averageMagnitude and then reset cumulative to zero, preventing others from participating and monopolising governance.
ronnyx2017 Follow with immeas and GalloDaSballo
Originally disclosed on Code4rena
Submitted by ronnyx2017, also found by immeas and GalloDaSballo
Vulnerability details
The function twTAP._releaseTap updates only --twAML.totalParticipants and neglected to update twAML.averageMagnitude. This will result in twAML.averageMagnitude accumulating every time a new position participates, without ever decreasing.
pool.averageMagnitude = (pool.averageMagnitude + magnitude) / pool.totalParticipants; // compute new average magnitude
Impact
An attacker can monopolize the gov by precisely controlling the number of tokens entering and exiting to ensure that only their own position remains in the current twTap.
On the other hand, there is another exploit way here. If pool.cumulative < pool.averageMagnitude, then pool.cumulative will be set to 0. But the greater position.averageMagnitude will be added to pool.cumulative when the position exits. This will cause pool.cumulative to continuously increase, which will result in the efficiency of twTAP/TapiocaOptionBroker becoming increasingly lower. Because the multiplier of the twTAP or target of the TapiocaOptionBroker will always be dMIN.
The same issue is also in the TapiocaOptionBroker. The only difference is that the pool.cumulative can’t be decreased to zero, because it will be reset to EPOCH_DURATION if it’s zero here. The following PoC uses the twTap as the exploit case.
Proof of Concept
We describe this attack using the simplest scenario, assuming that initially, the pool contains only the attacker’s own position, but the pool.averageMagnitude is not zero (which means there were some participators before).
- The attacker first needs to create a positions with
divergenceForce = true, andmagnitude = M1 = current pool.averageMagnitude. After the participation, thepool.averageMagnitudewill bepool.averageMagnitude + M1. - Waiting for the unlock time and exits the above position. After the exit, pool.
averageMagnituderemains unchanged (pool.averageMagnitude +M1), but thepool.totalParticipantsis back to0. - The attacker repeats the above process, which results in
pool.averageMagnitudeincreasing byM1each time. - Before the last unlock, the
pool.cumulativeandpool.averageMagnitudenow are very large values, the attacker participates withdivergenceForce = falsefor a couple of months. - Then the attacker exits his last position with
divergenceForce = true. It will makepool.cumulative = 0;, which breaks the developers’ assumptions about this branch:
// TODO: Strongly suspect this is never less. Prove it.
if (pool.cumulative > pool.averageMagnitude) {
pool.cumulative -= pool.averageMagnitude;
} else {
pool.cumulative = 0;
}
Now others will no longer be able to participate in twTAP, and the gov will be monopolized by the attacker.
Please note that “the pool contains only the attacker’s own position” is not a necessary condition; the attack can still be carried out even with the participation of others. As the exit process accumulates, this attack will become increasingly easier to occur, and may even be triggered unintentionally by users.
Recommendation
Update pool.averageMagnitude in the _releaseTap.
Assessed type
Context
LSDan (judge) decreased severity to Medium
0xRektora (Tapioca) confirmed, but disagreed with severity and commented via duplicate Issue #165:
Low. While true, the probabilities of this happening are very thin.
Note: For full discussion, see here.
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 exit function fails to update averageMagnitude, so it only increases and can be manipulated to reset cumulative.
Impact
Others may no longer be able to participate in twTAP, and governance could be monopolised by the attacker; the project team considers the probability very low.
What the attacker needed
Attacker has tokens to lock; some prior participants existed; attacker can wait for unlock periods
The fix
Update pool.averageMagnitude in the _releaseTap function.
How it was found
- Create a position with divergenceForce true and magnitude equal to current averageMagnitude.
- Wait for unlock time and exit the position; averageMagnitude remains unchanged but totalParticipants becomes zero.
- Repeat the process to increase averageMagnitude each time.
- Before the last unlock, participate with divergenceForce false for a couple of months.
- Exit the last position with divergenceForce true, which sets cumulative to zero.
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, people lock tokens to get voting power. The contract tracks an average 'magnitude' to decide how much voting power each participant gets. Because the average is never lowered when someone leaves, an attacker can make it grow huge and then reset a counter to zero, blocking everyone else from joining.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.