Race condition in streak calculation leads to unfair streak reset for users spinning near utc day change
The streak calculation uses the oracle callback's block timestamp instead of the user's startSpin timestamp, so a spin initiated just before a UTC day change but processed after it can reset the user's streak. An attacker cannot exploit this for gain, but users can lose accumulated streak rewards.
Plume Network
Originally disclosed on Immunefi
52277 sc low race condition in streak calculation leads to unfair streak reset for users spinning near utc day change
- Submitted on: Aug 9th 2025 at 11:19:27 UTC by @Orionn for Attackathon | Plume Network
- Report ID: #52277
- Report Type: Smart Contract
- Severity: Low
- Target: https://github.com/immunefi-team/attackathon-plume-network/blob/main/plume/src/spin/Spin.sol
- Impacts: Contract fails to deliver promised returns, but doesn't lose value
{% hint style="warning" %} A race condition in streak calculation can unfairly reset a user's daily streak when the oracle callback is mined after a UTC day boundary, even if the user initiated their spin before the boundary. {% endhint %}
Description
Brief / Intro
A race condition exists in the daily streak calculation logic within Spin.sol. The _computeStreak function uses the block.timestamp from the oracle's callback transaction (handleRandomness) to determine the day of the spin, rather than the block.timestamp of the user's initial startSpin transaction. If a user starts a spin shortly before a UTC day change, and the oracle callback is mined after the day change, the user's streak can be unfairly reset.
Vulnerability Details
The daily streak mechanic relies on comparing the day of the last spin (lastDaySpun) with the day of the current spin (today). The contract treats the oracle callback time as the spin time, which is asynchronous and outside the user's control.
- User's Transaction (
startSpin): user initiates spin at timestamp A (the user's intended spin time). - Oracle's Transaction (
handleRandomness): oracle callback occurs at timestamp B (potentially later). - Root Cause:
_computeStreakis called inhandleRandomnessand usesnowTs(the callback's block.timestamp) to computetoday. If A and B fall on different UTC days, the streak calculation can be incorrect and penalize the user.
Vulnerable code excerpt: Spin::_computeStreak
uint256 lastDaySpun = lastSpinTs / SECONDS_PER_DAY;
uint256 today = nowTs / SECONDS_PER_DAY; // `nowTs` is the block.timestamp of the handleRandomness callback
if (today == lastDaySpun + 1) { // This check fails if `today` is `lastDaySpun + 2` due to the timing gap
return userData[user].streakCount + streakAdjustment;
}
return 0 + streakAdjustment; // The user's streak is unfairly reset
Impact Details
- Loss of Value: Users can lose their accumulated daily streak. Higher streaks yield higher "Raffle Ticket" rewards (
baseRaffleMultiplier * streakForReward), so breaking a streak reduces future rewards. - Loss of Opportunity: Users may lose eligibility for weekly Jackpot rewards that require a minimum
streakCount.
References
Proof of Concept
{% stepper %} {% step %}
Scenario setup
- Actor: Alice, with
streakCount = 9andlastSpinTimestamprecorded on Day 9. - Goal: Perform daily spin on Day 10 to reach
streakCount = 10. {% endstep %}
{% step %}
Step 1 — Alice starts spin just before UTC day change
- Time: Day 10, 23:59:50 UTC.
- Action: Alice calls
startSpin(). Her transaction is mined in a block stamped on Day 10. - From Alice's perspective, she completed the daily action for Day 10. {% endstep %}
{% step %}
Step 2 — Oracle delay
- A small network/oracle delay occurs before the oracle processes the randomness request. {% endstep %}
{% step %}
Step 3 — Oracle callback after UTC day change
- Time: Day 11, 00:00:10 UTC.
- The oracle's callback transaction is mined with a block timestamp on Day 11 and
handleRandomnessis executed. {% endstep %}
{% step %}
Step 4 — Bug triggers in streak computation
_computeStreakis called insidehandleRandomnessusingnowTsfrom the callback (Day 11).- Calculations:
lastDaySpunderived from Alice'slastSpinTimestamp→ Day 9.todayderived fromnowTs→ Day 11.- Check
if (today == lastDaySpun + 1)=> checks11 == 9 + 1→ false.
- Result: The function treats the spin as breaking the streak and returns
1. {% endstep %}
{% step %}
Final result
userData[alice].streakCountis set to1instead of10. Alice's streak is lost due to an oracle timing race that is outside her control. {% endstep %} {% endstepper %}
Race Condition in Streak Calculation Leads to Unfair Streak Reset for Users Spinning Near UTC Day Change
Context
The target is the Spin.sol contract of the Plume Network, submitted through the Attackathon | Plume Network programme on Immunefi. The report is a smart contract finding rated Low, with the impact category "Contract fails to deliver promised returns, but doesn't lose value".
The feature under scrutiny is the daily spin mechanic. A user calls startSpin() to begin a spin, and the outcome is later delivered by an oracle callback that executes handleRandomness. The contract tracks a per-user daily streak: a user who spins on consecutive UTC days accumulates a streakCount, and that streak feeds into rewards. Higher streaks yield higher "Raffle Ticket" rewards, computed as baseRaffleMultiplier * streakForReward, and weekly Jackpot rewards require a minimum streakCount. The streak is therefore a value-bearing counter, and resetting it wrongly costs the user future rewards.
The vulnerable logic lives in Spin::_computeStreak, which decides whether the current spin continues the streak or breaks it.
Setup
The report does not describe any tooling, environment, fork or test harness. The only precondition it establishes is the timing relationship between two transactions:
- The user's
startSpintransaction, mined at timestamp A. - The oracle's
handleRandomnesscallback transaction, mined at timestamp B, which may be later than A.
The proof of concept uses a single actor, Alice, with streakCount = 9 and a lastSpinTimestamp recorded on Day 9. Her goal is to perform the daily spin on Day 10 and reach streakCount = 10.
Finding it
The researcher noticed that _computeStreak derives the day of the spin from nowTs, which is the block.timestamp of the handleRandomness callback, rather than from the block.timestamp of the user's startSpin transaction. Because the callback is asynchronous and its mining time is outside the user's control, a spin initiated on one UTC day can be attributed to the next.
The streak logic compares the day of the last spin (lastDaySpun) with the day of the current spin (today). The continuation check only accepts an exact one-day gap. If the callback lands two days after the last recorded spin day, the check fails and the function returns a reset value. The vulnerable excerpt is:
uint256 lastDaySpun = lastSpinTs / SECONDS_PER_DAY;
uint256 today = nowTs / SECONDS_PER_DAY; // `nowTs` is the block.timestamp of the handleRandomness callback
if (today == lastDaySpun + 1) { // This check fails if `today` is `lastDaySpun + 2` due to the timing gap
return userData[user].streakCount + streakAdjustment;
}
return 0 + streakAdjustment; // The user's streak is unfairly reset
Both days are computed by integer division of a timestamp by SECONDS_PER_DAY, so the day boundary is the UTC midnight. The if branch preserves and increments the streak; the fall-through returns 0 + streakAdjustment, discarding the accumulated count.
Exploitation
This is not an attack that an adversary performs against a victim. It is a timing race that penalises an honest user. The proof of concept walks through the sequence.
Step 1: Alice starts the spin just before the UTC day change
At Day 10, 23:59:50 UTC, Alice calls startSpin(). Her transaction is mined in a block stamped on Day 10. From her perspective she has completed the daily action for Day 10.
Step 2: Oracle delay
A small network or oracle delay occurs before the oracle processes the randomness request. The report does not quantify this delay.
Step 3: Oracle callback after the UTC day change
At Day 11, 00:00:10 UTC, the oracle's callback transaction is mined with a block timestamp on Day 11, and handleRandomness executes.
Step 4: The bug triggers in the streak computation
_computeStreak is called inside handleRandomness using nowTs from the callback, which is Day 11. The calculation proceeds as follows:
lastDaySpunis derived from Alice'slastSpinTimestamp, giving Day 9.todayis derived fromnowTs, giving Day 11.- The check
if (today == lastDaySpun + 1)evaluates11 == 9 + 1, which is false.
The function treats the spin as breaking the streak and returns 1.
Final result
userData[alice].streakCount is set to 1 instead of 10. Alice's streak is lost because of an oracle timing race that is outside her control.
Root cause
The contract treats the oracle callback time as the spin time. The user's intent is expressed at timestamp A in startSpin, but the day attribution is taken from timestamp B in handleRandomness. When A and B fall on different UTC days, the streak calculation can be incorrect and penalise the user.
The specific failure is the exact-match continuation check. today == lastDaySpun + 1 only accepts a one-day gap. In the scenario, the last recorded spin day is Day 9 and the callback day is Day 11, so the gap is two days and the check fails. The user did spin on Day 10, but that fact was never recorded against Day 10.
The report does not describe any safeguard against this timing gap.
Impact
Two consequences are described:
- Loss of value. Users can lose their accumulated daily streak. Because higher streaks yield higher Raffle Ticket rewards (
baseRaffleMultiplier * streakForReward), breaking a streak reduces future rewards. - Loss of opportunity. Users may lose eligibility for weekly Jackpot rewards that require a minimum
streakCount.
The impact is bounded: the contract fails to deliver promised returns but does not lose value in the sense of funds being stolen. The condition is narrow, requiring a spin initiated shortly before a UTC day change with the oracle callback mined after the boundary.
Fix
The report does not propose or describe a fix, and does not state that one was applied. The direction implied by the root cause is to attribute the spin to the day of the user's startSpin transaction rather than the day of the handleRandomness callback, so that the day used in _computeStreak reflects the user's intended spin time. Whether the programme adopted this or any other change is not recorded here.
Variants to test
- Other day-bucketed counters driven by callbacks. Look for streak, daily-limit, cooldown or epoch counters that are updated in an asynchronous callback rather than in the user's initiating transaction. A positive result is a counter that can be attributed to the wrong day or epoch when the callback is delayed across a boundary.
- Exact-gap continuation checks. Search for conditions of the form
today == last + 1or equivalent equality on time buckets. A positive result is a legitimate consecutive action that fails the check because the recorded bucket skipped one. - Boundary-adjacent initiation. For any feature with a daily reset, initiate the action just before the boundary and observe whether the recorded day matches the initiation day. A positive result is a recorded day that differs from the day of the initiating transaction.
- Reward multipliers tied to the counter. Where a counter feeds a multiplier or eligibility threshold, check whether a reset crosses a threshold. A positive result is a user losing eligibility or a multiplier purely because of callback timing.
Hunting notes
This class of bug hides where user intent and on-chain recording are separated by an asynchronous step: oracle callbacks, keeper executions, delayed settlement and any two-transaction flow. During recon, the signals are functions that read block.timestamp in a callback handler, day or epoch bucketing via integer division, and equality checks on consecutive buckets. The report ties the reset counter to the Raffle Ticket formula (baseRaffleMultiplier * streakForReward) and to a Jackpot eligibility threshold. That framing, a named user, a specific streak value and a step-by-step timeline across the boundary, is what makes the race legible to a reviewer.
What happened, in plain words
Plume Network runs a smart contract called Spin.sol. A smart contract is a small program that lives on a blockchain: it runs automatically, and nobody can change its behaviour after it is deployed. This particular contract runs a daily spin feature, a bit like a loyalty card at a coffee shop. If you come back every day and spin, your "streak" grows. The longer the streak, the better the prizes you can win.
The problem is about when the contract decides which day your spin belongs to. When you press the spin button, your request is recorded on the blockchain straight away. But the actual result of the spin (the random outcome) is not produced by the contract itself. It is produced later by an oracle, an outside service that supplies information the blockchain cannot generate on its own, here a random number. The oracle sends its answer back in a second transaction, and only then does the contract update your streak.
The contract uses the time of that second transaction, not the time of your own click, to work out which day you spun. If you spin at 23:59:50 and the oracle answers at 00:00:10 the next day, the contract thinks you spun on the next day. Because the streak rule only accepts an exact one-day gap, the contract can conclude you skipped a day and wipe your streak back to 1.
This is called a race condition: two things happen in an order the user does not control, and the result depends on which one lands first. Here the two things are your spin request and the oracle's reply. The report rates the issue Low, because no money is stolen; the contract simply fails to deliver the rewards it promised.
The feature and where the bug lives
The daily spin works in two transactions:
- You call
startSpin(). You callstartSpin()to begin a spin. - The oracle later calls back into the contract through a function called
handleRandomness. This is where the result is applied and your streak is updated.
The streak itself is a per-user counter called streakCount. It feeds two rewards:
- Raffle Tickets, whose amount is calculated as
baseRaffleMultiplier * streakForReward. In plain terms, the bigger your streak, the more tickets you get. - Weekly Jackpot eligibility, which requires a minimum
streakCount. Below the threshold, you cannot take part.
So the streak is not just a number on a screen: it is worth future prizes. Resetting it wrongly costs the user something real, even though no funds are taken.
The decision about whether a spin continues the streak or breaks it is made in a function called _computeStreak. That function is the heart of the report.
The vulnerable code
The report quotes this excerpt from Spin::_computeStreak:
uint256 lastDaySpun = lastSpinTs / SECONDS_PER_DAY;
uint256 today = nowTs / SECONDS_PER_DAY; // `nowTs` is the block.timestamp of the handleRandomness callback
if (today == lastDaySpun + 1) { // This check fails if `today` is `lastDaySpun + 2` due to the timing gap
return userData[user].streakCount + streakAdjustment;
}
return 0 + streakAdjustment; // The user's streak is unfairly reset
Line by line, in plain words:
uint256 lastDaySpun = lastSpinTs / SECONDS_PER_DAY;takes the timestamp of the user's previous spin (lastSpinTs, a number of seconds counted from a fixed starting point) and divides it by the number of seconds in a day. Whole-number division throws away the remainder, so the result is simply "which day number was that". Day 0 is the first day of the counting system, Day 1 the next, and so on.uint256 today = nowTs / SECONDS_PER_DAY;does the same fornowTs. The comment explains thatnowTsis the timestamp of thehandleRandomnesscallback, that is, the moment the oracle's reply was recorded, not the moment the user pressed spin.if (today == lastDaySpun + 1) {asks a strict question: is today exactly one day after the last recorded spin day? Only an exact one-day gap counts. A gap of two days fails.return userData[user].streakCount + streakAdjustment;is the happy path: keep the existing streak and add any adjustment.return 0 + streakAdjustment;is the unhappy path: the streak is thrown away and starts again from zero (plus any adjustment).
Because both days are computed by dividing a timestamp by the length of a day, the day boundary is midnight UTC. UTC is the world's shared clock reference, so "midnight UTC" is the same instant everywhere.
Why this is a race, not an attack
It is worth being clear about what this is not. Nobody is breaking in, stealing funds or tricking another user. The person who suffers is an honest user doing exactly what the feature asks. The loss comes from the gap between two moments in time:
- The user's
startSpintransaction, recorded at timestamp A. - The oracle's
handleRandomnesstransaction, recorded at timestamp B, which can be later than A.
The contract uses B to decide the day, but the user's intent was expressed at A. When A and B fall on different UTC days, the day attribution is wrong. The report does not say how long the oracle delay typically is, only that a small delay is enough to cross the boundary.
The proof of concept, step by step
The report uses one imaginary user, Alice, to make the timing concrete. She has streakCount = 9 and her last spin was recorded on Day 9. Her goal is to spin on Day 10 and reach a streak of 10.
Step 1: Alice starts the spin just before the day changes
At Day 10, 23:59:50 UTC, Alice calls startSpin(). Her transaction is recorded in a block stamped on Day 10. From her point of view, she has done her daily action for Day 10, with ten seconds to spare.
Step 2: The oracle is delayed
A small network or oracle delay happens before the oracle processes the randomness request. The report does not give a figure for this delay; the point is only that it exists.
Step 3: The oracle replies after the day changes
At Day 11, 00:00:10 UTC, the oracle's callback transaction is recorded with a timestamp on Day 11, and handleRandomness runs.
Step 4: The streak calculation goes wrong
_computeStreak runs inside handleRandomness and uses nowTs from the callback, which is Day 11. The arithmetic is:
lastDaySpuncomes from Alice'slastSpinTimestamp, giving Day 9.todaycomes fromnowTs, giving Day 11.- The check
if (today == lastDaySpun + 1)becomes11 == 9 + 1, which is false.
The function therefore treats the spin as having broken the streak and returns 1.
The result
userData[alice].streakCount is set to 1 instead of 10. Alice did spin on Day 10, but that fact was never recorded against Day 10, so her nine days of effort are gone because of a timing race she could not control.
Root cause
The contract treats the oracle callback time as the spin time. The user's intent is expressed at timestamp A in startSpin, but the day is taken from timestamp B in handleRandomness. When A and B fall on different UTC days, the calculation can be wrong and the user is penalised.
The specific failure is the exact-match check. today == lastDaySpun + 1 accepts only a one-day gap. In the scenario the last recorded day is Day 9 and the callback day is Day 11, so the gap is two days and the check fails.
Impact
The report describes two consequences:
- Loss of value. Users can lose their accumulated daily streak. Since higher streaks yield higher Raffle Ticket rewards (
baseRaffleMultiplier * streakForReward), a broken streak reduces future rewards. - Loss of opportunity. Users may lose eligibility for weekly Jackpot rewards that require a minimum
streakCount.
The impact is bounded: the contract fails to deliver promised returns but does not lose value in the sense of funds being stolen. The condition is narrow, needing a spin started shortly before a UTC day change with the callback recorded after the boundary.
Fix
The report does not propose or describe a fix, and does not state that one was applied. The direction implied by the root cause is to attribute the spin to the day of the user's startSpin transaction rather than the day of the handleRandomness callback, so that the day used in _computeStreak reflects the user's intended spin time. Whether the programme adopted this or any other change is not recorded here.
Variants to test
- Other day-bucketed counters driven by callbacks. Look for streak, daily-limit, cooldown or epoch counters that are updated in an asynchronous callback rather than in the user's initiating transaction. A positive result is a counter that can be attributed to the wrong day or epoch when the callback is delayed across a boundary.
- Exact-gap continuation checks. Search for conditions of the form
today == last + 1or equivalent equality on time buckets. A positive result is a legitimate consecutive action that fails the check because the recorded bucket skipped one. - Boundary-adjacent initiation. For any feature with a daily reset, initiate the action just before the boundary and observe whether the recorded day matches the initiation day. A positive result is a recorded day that differs from the day of the initiating transaction.
- Reward multipliers tied to the counter. Where a counter feeds a multiplier or eligibility threshold, check whether a reset crosses a threshold. A positive result is a user losing eligibility or a multiplier purely because of callback timing.
Hunting notes
This class of bug hides where user intent and on-chain recording are separated by an asynchronous step: oracle callbacks, keeper executions, delayed settlement and any two-transaction flow. During recon, the signals are functions that read block.timestamp in a callback handler, day or epoch bucketing via integer division, and equality checks on consecutive buckets. The report ties the reset counter to the Raffle Ticket formula (baseRaffleMultiplier * streakForReward) and to a Jackpot eligibility threshold. That framing, a named user, a specific streak value and a step-by-step timeline across the boundary, is what makes the race legible to a reviewer.
Glossary
- Smart contract: a program stored on a blockchain that runs automatically and cannot be altered after deployment.
- Blockchain: a shared, append-only record of transactions kept by many computers at once.
- Transaction: a single recorded action on a blockchain, such as calling a function in a contract.
- Block: a bundle of transactions recorded together, carrying a timestamp.
block.timestamp: the time recorded with a block, used by contracts as "now".- Oracle: an outside service that supplies data a blockchain cannot produce itself, such as a random number.
- Callback: a function the contract runs when the oracle sends its answer back.
- Asynchronous: happening at a later, unpredictable moment rather than immediately.
- Race condition: a bug where the outcome depends on the order or timing of two events the user does not control.
- Streak: a counter of consecutive days on which a user performed an action.
- UTC: the shared world clock reference; midnight UTC is the same instant everywhere.
- Integer division: division that discards the remainder, used here to turn a timestamp into a day number.
SECONDS_PER_DAY: the constant number of seconds in a day, used as the divisor.startSpin(): the function a user calls to begin a spin.handleRandomness: the function the oracle calls to deliver the random result._computeStreak: the internal function that decides whether a spin continues or resets the streak.lastSpinTs/lastSpinTimestamp: the recorded time of the user's previous spin.nowTs: the timestamp used inside the callback, taken from the callback's block.streakCount: the per-user counter of consecutive spin days.streakAdjustment: an extra amount added to the streak when it is recalculated.userData: the contract's per-user storage, holding values such as the streak.- Raffle Ticket: a reward whose amount grows with the streak, calculated as
baseRaffleMultiplier * streakForReward. - Jackpot: a weekly prize that requires a minimum
streakCountto be eligible. - Severity: the rating of how serious a finding is; here Low.
- Proof of concept: a worked example showing how a bug produces a wrong result.