Skip to content
Business logic Audit finding Advanced

Epoch-boundary checkpoints retroactively qualify for the previous epoch’s rewards

The epoch-end timestamp used for reward snapshots equals the first second of the next epoch, and the voting escrow's historical lookup includes checkpoints at that exact timestamp. An attacker could create or increase a lock at that boundary second and retroactively qualify for the previous epoch's rewards, stealing or diluting emissions.

0xastronatey Follow with 0x15, 0xanmol and 39 others

Originally disclosed on Code4rena

Submitted by 0xastronatey, also found by 0x15, 0xanmol, 0xApple, 0xDemon, 0xscater, 0xsolisec, aestheticbhai, ahahaHard1k, akhilmanga, Alan_Clan_67, b_void, beer, BlockKnock, dna-thug, Drynooo, gesha17, Hakeem_is_here, happykilling, hiram, hodlturk, jerry0422, jhongamersx, kb520, kind0dev, legat, meganpark, NexusAudits, nstatoshi, oreztker, qed, QuillAudits_Team, saamin, sgtpepper, skipper, solarizer_ai, th3_hybrid, udaykiranpedda, Waiyaki, winfunc, XDZIBECX, and y4y

  • /protocol/emissions/CoreEmissionsController.sol #L178-L180
  • /protocol/emissions/CoreEmissionsController.sol #L207-L213
  • /protocol/emissions/TrustBonding.sol #L194-L213
  • /protocol/emissions/TrustBonding.sol #L475-L492

TrustBonding snapshots veTRUST at epochTimestampEnd(epoch), but currentEpoch() already advances at that exact timestamp. Because VotingEscrow now resolves historical checkpoints with an inclusive ts <= t lookup, a lock created, topped up, or extended at the first second of epoch N+1 is still counted inside epoch N’s reward snapshot, letting an attacker steal or dilute the previous epoch’s emissions without actually being bonded during that epoch.

This is distinct from the known post-mortem underflow issue (POST-MORTEM.md#L22-L57). That outage required a checkpoint strictly after the boundary (ts > t); this issue exploits a checkpoint exactly at the boundary (ts == t), which the fixed binary-search lookup now intentionally includes (VotingEscrow.sol#L544-L576, VotingEscrow.sol#L590-L623).

Root Cause

1. Controller epoch arithmetic makes epochTimestampEnd(n) equal to the first moment of epoch n+1

CoreEmissionsController.sol#L178-L180

function _calculateEpochTimestampEnd(uint256 epoch) internal view returns (uint256) {
    return _START_TIMESTAMP + (epoch * _EPOCH_LENGTH) + _EPOCH_LENGTH;
    // <-- returns the first timestamp of epoch+1
}

CoreEmissionsController.sol#L207-L213

function _calculateTotalEpochsToTimestamp(uint256 timestamp) internal view returns (uint256) {
    if (timestamp < _START_TIMESTAMP) {
        return 0;
    }

    return (timestamp - _START_TIMESTAMP) / _EPOCH_LENGTH;
    // <-- at timestamp == epochTimestampEnd(n), currentEpoch() is already n+1
}

The controller-side epoch arithmetic makes epochTimestampEnd(n) equal to the first moment of epoch n+1, not the last in-epoch moment of n.

2. TrustBonding allocates rewards from boundary snapshots, so the inclusive choice directly feeds reward accounting

TrustBonding.sol#L194-L213

function totalBondedBalanceAtEpochEnd(uint256 epoch) public view returns (uint256) {
    if (epoch > currentEpoch()) {
        revert TrustBonding_InvalidEpoch();
    }

    return _totalSupply(_epochTimestampEnd(epoch));
    // <-- previous-epoch rewards use the inclusive boundary timestamp as the snapshot time
}

function userBondedBalanceAtEpochEnd(address account, uint256 epoch) public view returns (uint256) {
    if (account == address(0)) {
        revert TrustBonding_ZeroAddress();
    }

    if (epoch > currentEpoch()) {
        revert TrustBonding_InvalidEpoch();
    }

    return _balanceOf(account, _epochTimestampEnd(epoch));
    // <-- a checkpoint created exactly at that boundary is eligible for this snapshot
}

TrustBonding.sol#L475-L492

function _userEligibleRewardsForEpoch(address account, uint256 epoch) internal view returns (uint256) {
    if (account == address(0)) {
        revert TrustBonding_ZeroAddress();
    }

    if (epoch > currentEpoch()) {
        revert TrustBonding_InvalidEpoch();
    }

    uint256 userBalance = userBondedBalanceAtEpochEnd(account, epoch);
    uint256 totalBalance = totalBondedBalanceAtEpochEnd(epoch);
    // <-- reward allocation depends entirely on those boundary snapshots

    if (userBalance == 0 || totalBalance == 0) {
        return 0;
    }

    return userBalance * _emissionsForEpoch(epoch) / totalBalance;
}

3. VotingEscrow checkpoint writes and inclusive historical lookups admit boundary-second mutations

VotingEscrow.sol#L314-L316

u_new.ts = block.timestamp;
u_new.blk = block.number;
user_point_history[addr][user_epoch] = u_new;
// <-- lock/create/top-up/extend writes a checkpoint at the exact transaction timestamp

VotingEscrow.sol#L544-L576

if (point_history[_mid].ts <= _ts) {
    _min = _mid;
    // <-- global checkpoint lookup is inclusive: ts == snapshot time is selected
} else {
    _max = _mid - 1;
}

VotingEscrow.sol#L590-L623

if (user_point_history[addr][_mid].ts <= _ts) {
    _min = _mid;
    // <-- user checkpoint lookup is inclusive too
} else {
    _max = _mid - 1;
}

VotingEscrow.sol#L630-L638

uint256 target_epoch = _find_user_timestamp_epoch(addr, _t, user_point_epoch[addr]);
// <-- a user checkpoint created at _t is treated as part of the balance snapshot at _t

VotingEscrow.sol#L732-L736

uint256 target_epoch = _find_timestamp_epoch(t, epoch);
// <-- same rule for total supply

Lock mutations in VotingEscrow always checkpoint at block.timestamp, and both the global and per-user historical lookups now deliberately select the latest checkpoint whose timestamp is <= t. That means a checkpoint written exactly at epochTimestampEnd(prevEpoch) is included in prevEpoch’s reward snapshot.

4. claimRewards targets the previous epoch whose snapshot still admits brand-new checkpoints

TrustBonding.sol#L348-L363

uint256 currentEpochLocal = currentEpoch();

if (currentEpochLocal == 0) {
    revert TrustBonding_NoClaimingDuringFirstEpoch();
}

uint256 prevEpoch = currentEpochLocal - 1;
uint256 rawUserRewards = _userEligibleRewardsForEpoch(msg.sender, prevEpoch);
// <-- once the boundary is reached, the contract claims prevEpoch,
//     but prevEpoch's snapshot still includes checkpoints created at that same boundary

So once the boundary timestamp is reached, the contract immediately claims the previous epoch, but that previous-epoch snapshot still admits brand-new checkpoints created in the same second.

Internal Pre-conditions

The satellite controller must hold claimable emissions for the target epoch, which is the normal operating condition for claimRewards().

External Pre-conditions

The attacker must be able to submit a lock mutation at the exact timestamp returned by epochTimestampEnd(prevEpoch). An EOA can do this through ordinary VotingEscrow entry points such as create_lock, increase_amount, or increase_unlock_time. The exploit does not require any privileged role. EOA access is allowed because the inherited gate only blocks contract callers unless whitelisted.

Attack Path

  1. The attacker waits until t = epochTimestampEnd(prevEpoch).
  2. At that exact timestamp, currentEpoch() already returns prevEpoch + 1 because epoch arithmetic is integer-division based on (timestamp - start) / epochLength.
  3. In that same second, the attacker calls create_lock, increase_amount, or increase_unlock_time. VotingEscrow writes a checkpoint with ts = block.timestamp, i.e. ts = epochTimestampEnd(prevEpoch).
  4. claimRewards() now targets prevEpoch, and _userEligibleRewardsForEpoch() computes balances from _balanceOf/_totalSupply at epochTimestampEnd(prevEpoch).
  5. Because the historical lookup is inclusive (ts <= t), the attacker’s brand-new boundary checkpoint is treated as part of prevEpoch’s snapshot. The attacker receives rewards for an epoch they did not actually participate in.
  6. If nobody else was bonded during prevEpoch, the attacker can capture the entire epoch’s emissions by joining only at the first second of the next epoch. If others were bonded, the attacker still retroactively dilutes them.

Impact

This is direct reward theft. The cleanest version is at the epoch-0/epoch-1 boundary: the attacker can join only when epoch 1 has already started, yet still claim epoch 0 emissions. For epochs 0 and 1, the personal-utilization path is automatically 100%, so the exploit does not even need MultiVault activity to get through the utilization layer.

The bug also generalizes beyond the very first epoch. Any existing veTRUST holder can retroactively increase their previous-epoch voting weight by topping up or extending at the first second of the next epoch, which steals emissions from honest participants every cycle. Because the attacker’s capital is only locked, not spent, the attack cost is mainly timing and temporary capital commitment, while the extracted value is live emissions. I would rate this High.

Negative Check (why blockers don’t apply)

  • Access control does not stop it. The relevant lock-mutating entry points are inherited VotingEscrow user flows, and EOAs can call them permissionlessly.
  • claimRewards() itself works exactly as intended; the bug is the historical snapshot timestamp it relies on. The claim path simply consumes the corrupted-at-boundary snapshot.
  • The known underflow fix does not prevent this. It changed historical lookup behavior to select checkpoints with ts <= t (POST-MORTEM.md (PR #126 context), VotingEscrow.sol#L544-L576, VotingEscrow.sol#L590-L623); that inclusive rule is exactly what makes the boundary checkpoint count toward the old epoch.
  • This is not the prior zero-amount/utilization-driven repeat-claim issue (Zero-amount claims bypass claimed check) documented in the published V12 findings (README.md#L30-L34, code_423n4_2026_03_intuition__main_0a19e25_findings.md#L256-L275). This issue does not rely on utilization gaming or missing claims; it is purely a temporal snapshot-admission bug.

Mitigation

Make the epoch-end reward snapshot exclusive.

The simplest fix is to snapshot at epochTimestampEnd(epoch) - 1 instead of epochTimestampEnd(epoch), so only voting power that existed strictly before the next epoch began is eligible. A more invasive but cleaner alternative is to redefine the controller’s “epoch end” helper to be an inclusive in-epoch timestamp and keep that convention consistent across currentEpoch(), epochAtTimestamp(), _balanceOf(), and _totalSupply().

Add regression tests for:

  • create_lock exactly at epochTimestampEnd(n)
  • increase_amount exactly at epochTimestampEnd(n)
  • increase_unlock_time exactly at epochTimestampEnd(n)
  • immediate claimRewards() for n

Proof of Concept

View Detailed Proof of Concept

Local Verification

Command run locally:

forge test --match-path tests/PoCEpochBoundaryRewards.t.sol --match-test test_boundaryJoinRetroactivelyEarnsPreviousEpochRewards -v

Output:

Ran 1 test for tests/PoCEpochBoundaryRewards.t.sol:PoCEpochBoundaryRewards
[PASS] test_boundaryJoinRetroactivelyEarnsPreviousEpochRewards() (gas: 523951)
Suite result: ok. 1 passed; 0 failed; 0 skipped; finished in 8.57ms (765.96µs CPU time)

Ran 1 test suite in 150.34ms (8.57ms CPU time): 1 tests passed, 0 failed, 0 skipped (1 total tests)

Intuition mitigated:

  • Updated CoreEmissionsController epoch-end calculation to be boundary-exclusive across epochs (end = start + (epoch+1)*length - 1).
  • Added per-epoch budget guardrails in TrustBonding.claimRewards (revert when exhausted, clamp to remaining budget otherwise).
  • Updated and added unit tests to reflect the new closed-interval semantics and to regression-test boundary eligibility and budget invariants.

Status: Mitigation confirmed. Full details in reports from jerry0422, gesha17, and 0xastronatey.


The original report as published on Code4rena, by 0xastronatey. 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.

How it worked

Root cause

Likely the epoch-end helper returns the first timestamp of the next epoch, and the voting escrow's historical balance lookup includes checkpoints at exactly that timestamp, so a lock mutation at the boundary is counted in the previous epoch's snapshot.

Impact

An attacker could steal the entire previous epoch's emissions if nobody else was bonded, or retroactively dilute other participants' rewards; the attack costs only timing and temporary capital lock-up.

What the attacker needed

Ability to submit a transaction at the exact boundary second; claimable emissions exist for the target epoch; no privileged role required

The fix

The epoch-end snapshot was made boundary-exclusive (end = start + (epoch+1)*length - 1) and per-epoch budget guardrails were added; the mitigation was confirmed.

How it was found

  1. Wait until the timestamp equal to the end of the previous epoch.
  2. At that exact second, call a lock-mutating function such as create_lock, increase_amount, or increase_unlock_time.
  3. Call claimRewards, which targets the previous epoch and computes balances at that boundary timestamp.
  4. Because the lookup includes checkpoints at that timestamp, the new lock counts toward the previous epoch's rewards.

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.

This is a smart contract that pays rewards to people who lock tokens for a period. The reward for each period is based on how many tokens were locked at the moment the period ended. The code mistakenly treats the first second of the next period as still part of the previous one, so someone can lock tokens right at that second and still get paid for the period that just finished.

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.

More by 0xastronatey

View all

5 more disclosed reports, best first.

More from Intuition

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.