AirdropBroker : When block.timestamp == lastEpochUpdate + EPOCH_DURATION , users can exercise options in the new epoch.
At the exact moment an epoch ends, a user could call newEpoch() and exerciseOption() in the same transaction, letting them exercise options from the previous epoch at the new epoch's TAP price. This could be profitable if the TAP price has dropped.
In AirdropBroker, when a user receives an airdrop, it should only be able to exercise the options in the current epoch.
function _participatePhase1() internal returns (uint256 oTAPTokenID) {
uint256 _eligibleAmount = phase1Users[msg.sender];
if (_eligibleAmount == 0) revert NotEligible();
// Close eligibility
phase1Users[msg.sender] = 0;
// Mint aoTAP
uint128 expiry = uint128(lastEpochUpdate + EPOCH_DURATION); // Set expiry to the end of the epoch
oTAPTokenID = aoTAP.mint(msg.sender, expiry, uint128(PHASE_1_DISCOUNT), _eligibleAmount);
}
...
function exerciseOption(uint256 _aoTAPTokenID, ERC20 _paymentToken, uint256 _tapAmount)
external
whenNotPaused
tapExists
{
// Load data
(, AirdropTapOption memory aoTapOption) = aoTAP.attributes(_aoTAPTokenID);
if (aoTapOption.expiry < block.timestamp) revert OptionExpired();
For example, Alice received the airdrop for epoch 1, then Alice can participate in epoch 1 and exercise the options in epoch 1. When Alice exercises her option, the TAP price is determined at the beginning of epoch 1.
The problem here is that when block.timestamp == lastEpochUpdate + EPOCH_DURATION, newEpoch() can be called to enter epoch 2, and exerciseOption() can also be called to exercise the option of epoch 1. This allows the user to exercise the epoch 1 option at the epoch 2 TAP price.
function newEpoch() external tapExists {
if (block.timestamp < lastEpochUpdate + EPOCH_DURATION) {
revert TooSoon();
}
...
function exerciseOption(uint256 _aoTAPTokenID, ERC20 _paymentToken, uint256 _tapAmount)
external
whenNotPaused
tapExists
{
// Load data
(, AirdropTapOption memory aoTapOption) = aoTAP.attributes(_aoTAPTokenID);
if (aoTapOption.expiry < block.timestamp) revert OptionExpired();
Consider the following scenario, Alice receives a 1000 options airdrop for epoch 1.
Epoch 1 starts, lastEpochUpdate = day 0, TAP price is 5 USD, and TAP price is in a downward trend. If Alice exercises the option in epoch 1, she needs to pay 5000 * 0.5 = 2500 USD.
However, when block.timestamp == lastEpochUpdate + EPOCH_DURATION, the current TAP price is 2 USD, Alice can call newEpoch() and exerciseOption() in one transaction, Alice will exercise the option at the price of epoch 2, and only needs to pay 1000 USD to get 1000 TAP.
it’s a good catch, however this is informational. Probability of this happening are very low. The epoch is called with an only owner function, so it can’t be done within the same Tx, as for the same block, since this happens on Arbitrum with the fair sequencing and low latency, the chances are close to 0. On top of the incentives are extremely low for the effort being made.
@0xRektora - I disagree. newEpoch() doesn’t have any modifiers like onlyOwner, i.e. newEpoch() can be called by anyone and immediately follow the exerciseOption() call.
function newEpoch() external tapExists {
if (block.timestamp < lastEpochUpdate + EPOCH_DURATION) {
revert TooSoon();
}
// Update epoch info
lastEpochUpdate = uint64(block.timestamp);
epoch++;
// At epoch 4, change the epoch duration to 7 days
if (epoch == 4) {
EPOCH_DURATION = 7 days;
}
// Get epoch TAP valuation
(bool success, uint256 _epochTAPValuation) = tapOracle.get(tapOracleData);
if (!success) revert Failed();
epochTAPValuation = uint128(_epochTAPValuation);
emit NewEpoch(epoch, epochTAPValuation);
}
As POC said, it’s highly profitable for attackers.
On review, I agree with @cccz on the impact an profitability here, due to the lack of onlyOwner on the newEpoch function.
The original report as published on Code4rena, by cccz. 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.
Generating the AI write-up for this report.
This usually takes about 40 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
How it worked
Root cause
The expiry check uses a strict less-than comparison, so an option is still valid at the exact timestamp when a new epoch can be started, allowing the option to be exercised at the new epoch's price.
Impact
A user could exercise an option at a more favourable price, potentially causing a loss to the protocol; the judge increased severity to Medium, but the protocol team argued the probability is very low.
What the attacker needed
User has an airdrop option; transaction timed at epoch boundary; TAP price moves favourably
The fix
The check should use <= instead of < so that options expire at the exact epoch boundary.
How it was found
Wait until block.timestamp equals lastEpochUpdate + EPOCH_DURATION.
Call newEpoch() to update the TAP price for the new epoch.
Call exerciseOption() in the same transaction to exercise the old option at the new price.
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.
Generating the AI write-up for this report.
This usually takes about 40 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
This is a smart contract for a token airdrop where users get options to buy tokens at a set price. The price is updated each epoch (a time period). The bug is that at the exact second an epoch ends, someone could trigger the price update and then immediately use their old option at the new, possibly lower, price, which is unfair to the project.
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.