Attacker can prevent rewards from being issued to gauges for a given epoch in TapiocaOptionBroker
The function that emits weekly rewards can be called by anyone, and it returns zero on subsequent calls within the same week. An attacker can front-run the epoch update so that the broker receives zero and distributes no rewards to gauges for that epoch.
Submitted by Ruhum, also found by 0xRobocop, bin2chen, KIntern_NA, carrotsmuggler, c7e7eff, 0xnev, glcanvas, marcKn, and dirk_y
An attacker can prevent rewards from being issued to gauges for a given epoch
Proof of Concept
TapOFT.emitForWeek() is callable by anyone. The function will only return a value > 0 the first time it’s called in any given week:
///-- Write methods --
/// @notice Emit the TAP for the current week
/// @return the emitted amount
function emitForWeek() external notPaused returns (uint256) {
require(_getChainId() == governanceChainIdentifier, "chain not valid");
uint256 week = _timestampToWeek(block.timestamp);
if (emissionForWeek[week] > 0) return 0;
// Update DSO supply from last minted emissions
dso_supply -= mintedInWeek[week - 1];
// Compute unclaimed emission from last week and add it to the current week emission
uint256 unclaimed = emissionForWeek[week - 1] - mintedInWeek[week - 1];
uint256 emission = uint256(_computeEmission());
emission += unclaimed;
emissionForWeek[week] = emission;
emit Emitted(week, emission);
return emission;
}
In TapiocaOptionBroker.newEpoch() the return value of emitForWeek() is used to determine the amount of tokens to distribute to the gauges. If the return value is 0, it will assign 0 reward tokens to each gauge:
/// @notice Start a new epoch, extract TAP from the TapOFT contract,
/// emit it to the active singularities and get the price of TAP for the epoch.
function newEpoch() external {
require(
block.timestamp >= lastEpochUpdate + EPOCH_DURATION,
"tOB: too soon"
);
uint256[] memory singularities = tOLP.getSingularities();
require(singularities.length > 0, "tOB: No active singularities");
// Update epoch info
lastEpochUpdate = block.timestamp;
epoch++;
// Extract TAP
// @audit `emitForWeek` can be called by anyone. If it's called for a given
// week, subsequent calls will return `0`.
//
// Attacker calls `emitForWeek` before it's executed through `newEpoch()`.
// The call to `newEpoch()` will cause `emitForWeek` to return `0`.
// That will prevent it from emitting any of the TAP to the gauges.
// For that epoch, no rewards will be distributed to users.
uint256 epochTAP = tapOFT.emitForWeek();
_emitToGauges(epochTAP);
// Get epoch TAP valuation
(, epochTAPValuation) = tapOracle.get(tapOracleData);
emit NewEpoch(epoch, epochTAP, epochTAPValuation);
}
An attacker who frontruns the call to newEpoch() with a call to emitForWeek() will prevent any rewards from being distributed for a given epoch.
The reward tokens aren’t lost. TapOFT will roll the missed epoch’s rewards into the next one. Meaning, the gauge rewards will be delayed. The length depends on the number of times the attacker is able to frontrun the call to newEpoch().
But, it will cause the distribution to be screwed. If Alice is eligible for gauge rewards until epoch x + 1 (her lock runs out), and the attacker manages to keep the attack running until x + 2, she won’t be able to claim her reward tokens. They will be distributed in epoch x + 3 to all the users who have an active lock at that time.
Here’s a PoC:
// tOB.test.ts
it.only("should fail to emit rewards to gauges if attacker frontruns", async () => {
const {
tOB,
tapOFT,
tOLP,
sglTokenMock,
sglTokenMockAsset,
tapOracleMock,
sglTokenMock2,
sglTokenMock2Asset,
} = await loadFixture(setupFixture);
// Setup tOB
await tOB.oTAPBrokerClaim();
await tapOFT.setMinter(tOB.address);
// No singularities
await expect(tOB.newEpoch()).to.be.revertedWith(
'tOB: No active singularities',
);
// Register sgl
const tapPrice = BN(1e18).mul(2);
await tapOracleMock.set(tapPrice);
await tOLP.registerSingularity(
sglTokenMock.address,
sglTokenMockAsset,
0,
);
await tapOFT.emitForWeek();
await tOB.newEpoch();
const emittedTAP = await tapOFT.getCurrentWeekEmission();
expect(await tOB.singularityGauges(1, sglTokenMockAsset)).to.be.equal(
emittedTAP,
);
})
Test output:
TapiocaOptionBroker
1) should fail to emit rewards to gauges if attacker frontruns
0 passing (1s)
1 failing
1) TapiocaOptionBroker
should fail to emit rewards to gauges if attacker frontruns:
AssertionError: expected 0 to equal 469157964000000000000000. The numerical values of the given "ethers.BigNumber" and "ethers.BigNumber" inputs were compared, and they differed.
+ expected - actual
-0
+469157964000000000000000
at Context.<anonymous> (test/oTAP/tOB.test.ts:606:73)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at runNextTicks (node:internal/process/task_queues:65:3)
at listOnTimeout (node:internal/timers:528:9)
at processTimers (node:internal/timers:502:7)
Recommended Mitigation Steps
emitForWeek() should return the current week’s emitted amount if it was already called:
function emitForWeek() external notPaused returns (uint256) {
require(_getChainId() == governanceChainIdentifier, "chain not valid");
uint256 week = _timestampToWeek(block.timestamp);
if (emissionForWeek[week] > 0) return emissionForWeek[week];
// ...
0xRektora (Tapioca) confirmed via duplicate issue 192
LSDan (Judge) increase severity to High
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 emit function returns zero instead of the already-computed emission when called again in the same week, and the broker treats that zero as the amount to distribute.
Impact
Rewards for an epoch can be delayed indefinitely if the attacker keeps front-running, and users whose locks expire before a successful distribution may never receive their share.
What the attacker needed
Ability to send a transaction before the epoch update; no special role required
The fix
The emit function should return the current week's already-computed emission instead of zero when called again.
How it was found
- Register a singularity so the broker has an active gauge.
- Call the emit function before the epoch update.
- Call the epoch update, which then receives zero from the emit function.
- Observe that the gauge receives zero rewards for that epoch.
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 anyone trigger the weekly reward calculation. If someone does this just before the scheduled epoch update, the update sees zero rewards and gives nothing to the gauges. The rewards are not lost but delayed, which can mean some users miss out if their lock expires before the next successful distribution.
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.