Skip to content
Business logic Audit finding Intermediate

Uint8 truncation and missing cap on week index can return wrong/zero jackpot amounts (Low — Contract fails to deliver promised returns)

The reward calculation casts the current week to an 8-bit integer and uses it to index a jackpot prize array that is only initialised for the first 12 weeks. After the campaign ends, or after 256 weeks when the cast wraps, a winning spin can pay out zero or the wrong prize.

Plume Network

Originally disclosed on Immunefi

52990 sc low uint8 truncation and missing cap on week index can return wrong zero jackpot amounts low contract fails to deliver promised returns

Description

Brief / Intro

determineReward() computes:

Solidity
uint8 weekNumber = uint8(getCurrentWeek());
  • Past the designed 12-week campaign, jackpotPrizes[weekNumber] often defaults to 0 (uninitialized), so winners can receive 0 unexpectedly.
  • After 256 weeks, casting to uint8 wraps (mod 256) and can index an unintended bucket, again returning wrong prizes (commonly 0).

Vulnerability Details

  • initialize() only configures indices 0..11. No guard exists in determineReward() to zero out jackpots post-campaign or cap the index.
  • getWeeklyJackpot() caps the display (if (weekNumber > 11) return (weekNumber, 0, 0);), but this guard is not used in determineReward().

Impact Details

{% hint style="info" %}

  • Immunefi Impact: Low — Contract fails to deliver promised returns, but doesn't lose value
  • After week 12 (or any misconfiguration where campaignStartDate is old), jackpot payouts can become 0. After week 256, indexing is effectively nondeterministic modulo 256. {% endhint %}

References

  • determineReward() (uint8 weekNumber = uint8(getCurrentWeek());)
  • initialize() (only sets 0..11)
  • getWeeklyJackpot() (has a cap that isn’t applied in determineReward())

determineReward() (https://github.com/immunefi-team/attackathon-plume-network/blob/580cc6d61b08a728bd98f11b9a2140b84f41c802/plume/src/spin/Spin.sol#L286)

Proof of Concept

{% stepper %} {% step %}

Setup: campaign start > 12 weeks ago

  • Set campaignStartDate to be more than 12 weeks in the past. {% endstep %}

{% step %}

Force a jackpot and trigger a spin

  • Make jackpotProbabilities[dayOfWeek] high (or otherwise force a jackpot) and trigger a spin. {% endstep %}

{% step %}

observe jackpot index and payout

  • determineReward() computes weekNumber via uint8(getCurrentWeek()).
  • Because weekNumber > 11, jackpotPrizes[weekNumber] is uninitialized (defaults to 0).
  • The user “wins” a 0-amount jackpot. {% endstep %}

{% step %}

Long-term wraparound (> 256 weeks)

  • If campaignStartDate is more than 256 weeks ago, uint8(getCurrentWeek()) wraps (mod 256) and indexes an unintended bucket (often unset = 0), producing wrong payouts. {% endstep %} {% endstepper %}

The original report as published on Immunefi. Images and videos are our own copies; raw HTML is shown as text. View it on Immunefi.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 4 min read.

Uint8 truncation and a missing cap on the week index in Spin.sol

Context

The target is Spin.sol in the Plume Network Attackathon repository, a smart contract that runs a weekly spin campaign with jackpot prizes. The relevant function is determineReward(), which decides what a participant wins when a spin lands on the jackpot. It derives the current campaign week and uses that week number to look up the prize in the jackpotPrizes array.

The campaign is designed to run for 12 weeks. initialize() only configures prize entries for indices 0..11. There is a separate view function, getWeeklyJackpot(), that caps the displayed week at 11, but that cap lives only in the view function and is not applied where the actual payout is calculated.

Setup

The report does not describe any accounts, roles, tooling or versions. The only precondition that matters is the value of campaignStartDate: the bug appears once the campaign start date is far enough in the past that getCurrentWeek() returns a value outside the configured range. The proof of concept manipulates that state directly rather than waiting for real time to pass.

Finding it

The researcher looked at how determineReward() converts the current week into an array index:

Solidity
uint8 weekNumber = uint8(getCurrentWeek());

Two things stood out. First, jackpotPrizes is only populated for indices 0..11 by initialize(), and nothing in determineReward() zeroes out or rejects a week beyond the campaign. Past week 12, jackpotPrizes[weekNumber] is uninitialised and therefore defaults to 0, so a winner can be paid nothing. Second, the cast to uint8 truncates: after 256 weeks the value wraps modulo 256 and indexes an unintended bucket, again returning the wrong prize, commonly 0.

The inconsistency with getWeeklyJackpot() made the omission clear. That function contains the guard if (weekNumber > 11) return (weekNumber, 0, 0);, but the same guard is absent from determineReward(), which is the function that actually determines the payout.

Exploitation

Step 1: Set the campaign start more than 12 weeks in the past

Set campaignStartDate to a timestamp more than 12 weeks ago. This is the state a misconfigured deployment with an old campaignStartDate would reach.

Step 2: Force a jackpot and trigger a spin

Make jackpotProbabilities[dayOfWeek] high, or otherwise force a jackpot outcome, and trigger a spin. The report does not give the exact call or parameters used.

Step 3: Observe the jackpot index and the payout

determineReward() computes weekNumber via uint8(getCurrentWeek()). Because weekNumber > 11, jackpotPrizes[weekNumber] is uninitialised and defaults to 0. The user wins a jackpot worth zero.

Step 4: Long-term wraparound beyond 256 weeks

If campaignStartDate is more than 256 weeks ago, uint8(getCurrentWeek()) wraps modulo 256 and indexes an unintended bucket, often one that was never set and therefore holds 0. The payout is wrong again.

Root cause

The week index used for the prize lookup is not validated against the range that initialize() actually populates. determineReward() trusts getCurrentWeek() and narrows it to uint8 without checking either the upper bound of the campaign or the width of the type. The 12-week cap exists in getWeeklyJackpot() but was not reused in the payout path, so the display and the payout disagree about what a valid week is. The uint8 cast adds a second failure mode: even if the array were larger, the index would silently wrap every 256 weeks.

Impact

Under the program's own impact classification, this is Low: contract fails to deliver promised returns, but does not lose value. After week 12, or in any misconfiguration where campaignStartDate is old, jackpot payouts can become 0. After week 256, indexing is effectively nondeterministic modulo 256. The report does not claim any theft or loss of funds, only that winners may receive less than the campaign promises.

Fix

Variants to test

  1. Other prize or reward arrays indexed by time. Look for arrays populated only for a fixed campaign window and indexed by a computed period. A positive result is a period value outside the initialised range that still reaches the lookup.
  2. Narrow integer casts on counters. Search for uint8(...), uint16(...) and similar casts applied to values that grow with time or block number. A positive result is a value that wraps and indexes a different slot than intended.
  3. Guards present in view functions but missing in state-changing ones. Compare read-only helpers with the functions that move value. A positive result is a bound enforced in the view path but absent where the payout is computed.

Hunting notes

This kind of bug hides in reward and payout logic that indexes storage by a time-derived value, especially where a campaign has a fixed length and the initialiser only fills part of an array. During review, the signal is a mismatch between a capped view function and an uncapped payout function, or a cast to a small integer type on a value that is not bounded. The report outlines the state (campaignStartDate in the past), the forced jackpot and the resulting zero payout, and ties it to the program's impact category for failing to deliver promised returns.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 9 min read.

What happened, in plain words

A smart contract called Spin.sol runs a weekly prize campaign. Each week, participants can spin, and sometimes a spin lands on a jackpot. The contract has to work out which week it is and then look up the prize for that week in a list.

The problem is that the contract only ever fills in prizes for the first 12 weeks. After that, the list has nothing in the later slots, and an empty slot in this kind of list reads as zero. So a person who wins the jackpot after week 12 can be paid nothing at all, even though the campaign promised a prize.

There is a second, slower problem. The week number is stored in a very small container that can only count up to 255. Once the campaign is more than 256 weeks old, the counter rolls over back to the start, like a car odometer ticking from 999999 to 000000. The contract then looks up a prize for the wrong week, which again is usually an empty slot worth zero.

The report rates this as Low severity: the contract fails to deliver the returns it promised, but no money is stolen or lost from the system.

Background: the words you need first

Before the details, a few ideas explained from scratch.

  • Smart contract. A program that lives on a blockchain. It runs exactly as written, and anyone can call it. Think of a vending machine: you press a button, it follows its internal rules, and it either gives you the item or does not. Nobody can reach inside and change the rules while it runs.
  • Solidity. The programming language this contract is written in. It looks a bit like JavaScript or C.
  • Function. A named block of code that does one job. You call it by name, it runs, and it may return a value. determineReward() is a function: its job is to decide what a spin wins.
  • Array. An ordered list of slots, each with a number (its index). Slot 0 is the first, slot 1 the second, and so on. In this contract, jackpotPrizes is an array: jackpotPrizes[0] is the prize for week 0, jackpotPrizes[1] for week 1, and so on.
  • Uninitialised slot. A slot in an array that was never given a value. In Solidity, such a slot reads as 0. Think of a row of pigeonholes where only the first twelve have envelopes in them; the rest are empty, and asking for the contents of an empty pigeonhole gives you nothing, which the program treats as zero.
  • Integer type and uint8. A whole number stored in a fixed amount of space. uint8 means an unsigned (non-negative) integer of 8 bits, which can hold values from 0 to 255. If you try to put 256 into a uint8, it does not error: it wraps around to 0. This is like a two-digit mechanical counter that goes 98, 99, 00, 01. The technical name for this wrapping is truncation or overflow.
  • Cast. Telling the language to treat a value as a different type. uint8(getCurrentWeek()) means: take the week number and squeeze it into a uint8. If the week number is larger than 255, the squeeze silently loses the high part.
  • View function. A function that only reads data and reports it; it does not change anything on the blockchain. getWeeklyJackpot() is a view function: it tells you what the jackpot for a week is, without paying anyone.
  • Guard. A check inside a function that stops it doing something silly, for example if (weekNumber > 11) return .... A guard is like a sign on a door saying "staff only": it only works if it is actually on the door you walk through.
  • Campaign start date. A stored timestamp recording when the 12-week campaign began. The current week is calculated by comparing now with that date.

The target

The contract is Spin.sol, from the Plume Network Attackathon repository. It runs a weekly spin campaign with jackpot prizes. The function at the centre of the report is determineReward(), which decides what a participant wins when a spin lands on the jackpot. It works out the current campaign week and uses that week number to fetch the prize from the jackpotPrizes array.

The campaign is designed to last 12 weeks. The setup function initialize() only fills in prize entries for indices 0..11, that is, slots 0 through 11, twelve slots in total. There is also a separate read-only function, getWeeklyJackpot(), that caps the week it displays at 11. That cap, however, exists only in the read-only function. It is not applied where the actual payout is calculated.

Setup

The report does not describe any accounts, roles, tools or versions. The only precondition that matters is the value of campaignStartDate: the bug appears once the campaign start date is far enough in the past that getCurrentWeek() returns a number outside the configured range. The proof of concept changes that stored value directly rather than waiting for real time to pass, in the same way you might wind a clock forward to test an alarm rather than sitting and waiting for the morning.

Finding it

The researcher looked at how determineReward() turns the current week into an array index:

Solidity
uint8 weekNumber = uint8(getCurrentWeek());

Line by line:

  1. getCurrentWeek() asks the contract what week of the campaign it is now. The result is a normal-sized number that can grow without limit as time passes.
  2. uint8(...) squeezes that number into an 8-bit container, which can only hold 0 to 255. Anything above 255 wraps around.
  3. uint8 weekNumber = ... stores the squeezed value in a variable called weekNumber, which is then used to look up the prize.

Two things stood out.

First, jackpotPrizes is only filled for indices 0..11 by initialize(), and nothing in determineReward() zeroes out or rejects a week beyond the campaign. Past week 12, jackpotPrizes[weekNumber] is uninitialised and therefore reads as 0, so a winner can be paid nothing.

Second, the cast to uint8 truncates. After 256 weeks the value wraps modulo 256 and points at an unintended slot, again returning the wrong prize, commonly 0.

The inconsistency with getWeeklyJackpot() made the omission clear. That function contains the guard if (weekNumber > 11) return (weekNumber, 0, 0);, but the same guard is absent from determineReward(), the function that actually decides the payout. In everyday terms: the front desk has a sign saying "we only have prizes for weeks 0 to 11", but the person actually handing out the prizes never looks at the sign.

Exploitation

Step 1: Set the campaign start more than 12 weeks in the past

Set campaignStartDate to a timestamp more than 12 weeks ago. This is the state a misconfigured deployment with an old campaignStartDate would reach. The step is taken because the bug only shows up once the current week is outside the twelve weeks that were configured.

Step 2: Force a jackpot and trigger a spin

Make jackpotProbabilities[dayOfWeek] high, or otherwise force a jackpot outcome, and trigger a spin. The report does not give the exact call or parameters used.

Step 3: Observe the jackpot index and the payout

determineReward() computes weekNumber via uint8(getCurrentWeek()). Because weekNumber > 11, jackpotPrizes[weekNumber] is uninitialised and reads as 0. The user wins a jackpot worth zero.

Step 4: Long-term wraparound beyond 256 weeks

If campaignStartDate is more than 256 weeks ago, uint8(getCurrentWeek()) wraps modulo 256 and points at an unintended slot, often one that was never set and therefore holds 0. The payout is wrong again.

Root cause

The week index used for the prize lookup is not checked against the range that initialize() actually fills. determineReward() trusts getCurrentWeek() and squeezes it into uint8 without checking either the upper bound of the campaign or the width of the type. The 12-week cap exists in getWeeklyJackpot() but was not reused in the payout path, so the display and the payout disagree about what a valid week is. The uint8 cast adds a second failure mode: even if the array were larger, the index would silently wrap every 256 weeks.

Impact

Under the program's own impact classification, this is Low: contract fails to deliver promised returns, but does not lose value. After week 12, or in any misconfiguration where campaignStartDate is old, jackpot payouts can become 0. After week 256, indexing is effectively nondeterministic modulo 256. The report does not claim any theft or loss of funds, only that winners may receive less than the campaign promises.

Fix

Variants to test

  1. Other prize or reward arrays indexed by time. Look for arrays filled only for a fixed campaign window and indexed by a computed period. A positive result is a period value outside the filled range that still reaches the lookup.
  2. Narrow integer casts on counters. Search for uint8(...), uint16(...) and similar casts applied to values that grow with time or block number. A positive result is a value that wraps and points at a different slot than intended.
  3. Guards present in view functions but missing in state-changing ones. Compare read-only helpers with the functions that move value. A positive result is a bound enforced in the read path but absent where the payout is computed.

Hunting notes

This kind of bug hides in reward and payout logic that indexes storage by a time-derived value, especially where a campaign has a fixed length and the initialiser only fills part of an array. During review, the signal is a mismatch between a capped view function and an uncapped payout function, or a cast to a small integer type on a value that is not bounded. The report outlines the state (campaignStartDate in the past), the forced jackpot and the resulting zero payout, and ties it to the program's impact category for failing to deliver promised returns.

Glossary

  • Smart contract: a program stored and run on a blockchain, which executes exactly as written and can be called by anyone.
  • Solidity: the programming language used to write this contract.
  • Function: a named block of code that performs one job and may return a value.
  • Array: an ordered list of slots, each identified by a number called its index, starting at 0.
  • Index: the number used to pick one slot out of an array.
  • Uninitialised slot: an array slot that was never given a value; in Solidity it reads as 0.
  • Integer type: a whole-number type with a fixed size, such as uint8.
  • uint8: an unsigned 8-bit integer, holding values from 0 to 255.
  • Truncation: silently dropping the part of a value that does not fit into a smaller type.
  • Wraparound (overflow): when a counter passes its maximum and restarts from zero, like 255 becoming 0 in a uint8.
  • Modulo: the remainder after division; wrapping modulo 256 means the value is reduced to its remainder when divided by 256.
  • Cast: converting a value from one type to another, for example uint8(...).
  • View function: a function that only reads data and reports it, without changing anything on the blockchain.
  • Guard: a check inside a function that prevents an unwanted case, such as rejecting a week number above 11.
  • initialize(): the setup function that fills in the contract's starting values, here the prize slots for weeks 0 to 11.
  • determineReward(): the function that decides what a spin wins and looks up the prize for the current week.
  • getWeeklyJackpot(): a read-only function that reports the jackpot for a week and caps the displayed week at 11.
  • campaignStartDate: the stored timestamp marking when the 12-week campaign began.
  • jackpotPrizes: the array holding the prize for each week.
  • jackpotProbabilities: the per-day settings that control how likely a jackpot is.
  • Proof of concept (PoC): a step-by-step demonstration that the bug can actually happen.
  • Impact classification: the program's own scale for rating how serious a bug is; here, Low, meaning promised returns are not delivered but no value is lost.

More from Plume Network

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.