A single second in an epoch makes an user eligible for the entire epoch’s rewards
The TOLP contract records lock durations in seconds while the TOB contract processes them in epochs, so a lock expiring one second into an epoch makes the user eligible for that entire epoch's rewards. A user can also exit their position after the lock expires but still claim rewards for the rest of the epoch.
carrotsmuggler Follow with KIntern_NA and GalloDaSballo
Originally disclosed on Code4rena
Submitted by carrotsmuggler, also found by KIntern_NA, deadrxsezzz (1, 2), and GalloDaSballo
A user can lock their LP tokens into the TOLP contract, and then put their TOLP into the TOB contract to be eligible for option rewards. These option rewards are paid out every epoch and distributed proportionally to all the participants in that epoch. When locking LP tokens in TOLP, the user can choose their own _lockDuration.
The TOB contract has 2 important functions. One is the exitPosition, which allows users to take out their TOLP token, and the other is the exerciseOption function, which allows the users to collect the option rewards. The issue is that the TOLP contract records lock duration in seconds, while the TOB contract processes them in epochs.
So if a user creates a lock position where the lock end time is a single second after the epoch change, the epoch when the lock is due to expire in the TOB contract will be calculated as shown.
uint128 lockExpiry = lock.lockTime + lock.lockDuration;
uint256 lastEpoch = _timestampToWeek(lockExpiry);
So if a user lock expires a single second into an epoch, the lastEpoch will be calculated as that epoch and the user will be eligible for that entire epoch’s rewards.
Moreover, this also allows a peculiar situation where a user can take out their TOLP token and exit their position and then come back and collect their token rewards. This is because when users want to exit their position, the contract checks if the lock has expired.
if (!isSGLInRescueMode) {
if (block.timestamp < lock.lockTime + lock.lockDuration) {
revert LockNotExpired();
}
}
But when a user wants to exercise their options, the contract checks for the liveness of the position in different terms, the epoch.
uint256 expiryWeek = _timestampToWeek(_lock.lockTime + _lock.lockDuration);
isPositionActive = epoch <= expiryWeek;
The first method and the second method can disagree if a position is active. If the expiry time is in the middle of an epoch, for the entire second half of the epoch, the exitPosition function will treat the position as expired and will allow the user to take out their TOLP token, but the exerciseOption contract will treat the position as active and will allow the user to collect rewards as well. Due to the discussion above, the user can have only a single second of lock time remaining in this second epoch; so for the entire duration of 7 days, the user can have no TOLP locked in the contract but still be eligible to withdraw rewards.
Proof of Concept
The situation can be created in the following manner:
- Say the current timestamp is 100. Say the epoch is scheduled to end at 200. Alice creates a lock with the lock duration of 101 seconds.
- The expiry epoch is calculated as 2, since epoch 1 ends at 200 but the position expires at 201.
- Thus, Alice is eligible to collect rewards for epoch 2 even though she only spends 1 second in that epoch locked.
- Alice can then take out her TOLP token the moment timestamp passes 201. However since the current epoch (2) is
<=the expiry epoch (2), she can claim rewards later as well. - Alice waits until the next epoch start at 300 and claims her option rewards.
Recommended Mitigation Steps
The different contracts should use the same mechanism to define locks. Either use epochs in both TOLP and TOB contracts, or use seconds in both. The current situation is a bit confusing and can lead to unexpected behavior.
Assessed type
Invalid Validation
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 two contracts use different time units (seconds vs epochs) to determine lock expiry, causing inconsistent active status.
Impact
A user could claim rewards for an entire epoch while only locking tokens for one second of it, and could also exit their position yet still collect rewards for the remainder of that epoch.
What the attacker needed
Ability to lock LP tokens in TOLP; ability to deposit TOLP into TOB; timing lock expiry just after epoch boundary
The fix
The contracts should use the same time unit (either seconds or epochs) to define lock expiry.
How it was found
- Alice creates a lock with a duration that ends one second after the current epoch ends.
- The expiry epoch is calculated as the next epoch.
- Alice becomes eligible for rewards in that next epoch despite only being locked for one second of it.
- Alice exits her position once the lock expires.
- Alice claims rewards for the entire epoch later.
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 user locks tokens for a chosen time. The system pays rewards per week (epoch). Because one part measures time in seconds and another in weeks, a lock ending just after a week boundary counts as active for the whole next week. The user can take their tokens out but still collect rewards for that week.
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.