Beginner FriendlyGameFi
100 EXP
View results
Submission Details
Severity: medium
Valid

Predictable Randomness `pizza_drop::get_random_slice`

Root + Impact

Timestamp-Based Randomness is Manipulable + Medium-High Impact

Description

  • The contract generates random amounts using block timestamp modulo operation

  • Block timestamps are predictable and can be influenced by miners/validators, making the randomness gameable

let time = timestamp::now_microseconds(); // @> Predictable timestamp source
let random_val = time % 401; // @> Easily calculable result
let random_amount = 100 + random_val; // @> Manipulable final amount

Risk

Likelihood:

  • Miners/validators can manipulate block timestamps within small ranges

  • Attackers can time transactions to land in favorable timestamp windows

Impact:

  • Unfair airdrop distribution favoring miners and sophisticated attackers

  • Loss of trust in the airdrop's fairness and randomness guarantees

  • Potential legal and reputational damage due to biased outcomes

Proof of Concept

// Miner can predict and manipulate:
// Current timestamp: 1641024000000000
// timestamp % 401 = 1641024000000000 % 401 = 287
// Result: 100 + 287 = 387 APT
// Miner adjusts timestamp slightly to get better result:
// Modified timestamp: 1641024000000400
// 1641024000000400 % 401 = 0
// Result: 100 + 0 = 100 APT (worse) - try again
// Next attempt: 1641024000000350
// 1641024000000350 % 401 = 350
// Result: 100 + 350 = 450 APT (optimal)

Recommended Mitigation

- let time = timestamp::now_microseconds();
- let random_val = time % 401;
- let random_amount = 100 + random_val;
+ use aptos_framework::randomness;
+
+ let random_seed = randomness::randomness();
+ let random_val = (random_seed % 401);
+ let random_amount = 100 + random_val;
Updates

Appeal created

bube Lead Judge 10 days ago
Submission Judgement Published
Validated
Assigned finding tags:

Predictable randomness

The `get_random_slice` function should only be called by the owner via the `register_pizza_lover` function. Also, the `owner` is trusted and will not choose a specific time for a new user to register. Therefore, I disagree with the claim of most reports in this group that an attacker can manipulate the random number of pizza slices. But I agree with the root cause of the reports in this group, that the random distribution is not completely random.

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.