Hooks.wtf

Recipients

StakingRecipient.sol

StakingRecipient distributes revenue using stake checkpoints. Its previous-block snapshot prevents the original same-transaction attack, but a one-block stake can still capture fees accrued earlier.

Reviewed source: src/recipients/StakingRecipient.sol at commit 38f14ff.

Findings

IDSeverityFinding
B-06MediumA one-block stake captures fees accrued before it was deposited

[MEDIUM] B-06 · A one-block stake captures fees accrued before it was deposited

B-06 · Medium

The previous-block snapshot stops the original flash-loan attack, but a stake held across one block can still take a large share of fees earned before it arrived.

Staking rewards are attributed to the stake recorded at the end of the previous block. This prevents an attacker from borrowing, staking, distributing and withdrawing in one transaction.

However, Flaunch.distribute delivers all fees accrued since the last distribution as a single receipt, and anyone can trigger it. The reward calculation sees when that receipt arrives, not when its revenue was earned. An attacker can buy and stake in block N, distribute in block N+1, then claim and exit with a share of the entire backlog.

Earlier review: Residual of F-01. The original same-transaction flash-loan form is fixed; this cross-block variant remains.

Impact

Long-term stakers lose a share of revenue accrued before the attacker staked. The attack is profitable when that backlog exceeds the cost of buying and selling the stake, including trading fees.

The source review measured Base blocks at 0.2 seconds on 25 November, so crossing one block does not impose a meaningful holding period. The attacker still needs capital and remains exposed to price changes between transactions.

Affected code

Locations refer to the reviewed commit, 38f14ff.

From src/recipients/StakingRecipient.sol:282–295:

// Reserve all incoming funds, including fractions that may remain as rounding dust.
reward.reserve += _amount;
if (_snapshotTotalStaked == 0) {
    // Nothing was staked when the previous block ended; the next receipt with eligible stake activates these funds.
    reward.pending += _amount;
} else {
    // Divide by the previous block's total so the balances in place then receive exactly this amount between them.
    uint available = reward.pending + _amount;
    reward.pending = 0;
    reward.index += Math.mulDiv(available, PRECISION, _snapshotTotalStaked);

    // The odd sequence orders this receipt after every earlier block's stake change and before this block's.
    // Receipts sharing a block share this sequence; the upper-bound lookup resolves to the last of them.
    reward.history.push(Checkpoint(_snapshotSequence + 1, reward.index));

Proof of concept

  1. Let fees accrue while Alice is the only staker.
  2. In block N, have the attacker buy tokens and stake them.
  3. In block N+1, call distribute, claim, withdraw and sell the stake.

StakingOneBlockCapture.t.sol::test_oneBlockStakeCapturesLongAccruedFees starts with 1 ETH of accrued fees. The attacker buys with 3 ETH and nets 0.7655 ETH after both swap fees; the long-term staker receives 0.1869 ETH. The test uses the real trading and staking paths.

The test source is poc/StakingOneBlockCapture.t.sol in the Solidity evidence bundle. Follow the reproduction setup, then run:

FOUNDRY_GAS_LIMIT=1000000000000 forge test --match-path 'test/audit/StakingOneBlockCapture.t.sol' -vv

Stream receipts over a defined window, weight rewards by stake-seconds, or require a minimum stake age. Frequent keeper distributions reduce the available backlog but do not remove the timing mismatch.

Previous
BuyAndBurnRecipient.sol