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

M-01 Predictable Timestamp Randomness

Root + Impact

Description

The PizzaDrop contract uses predictable timestamp-based pseudo-randomness for reward generation instead of cryptographically secure randomness. The get_random_slice() function on line 90-92 generates reward amounts using timestamp::now_microseconds() % 401 + 100, making all rewards completely deterministic and exploitable.

Since blockchain timestamps are publicly visible and predictable, attackers can calculate optimal transaction timing to guarantee maximum rewards (500 Octas) while legitimate users receive suboptimal amounts based on random registration timing.

move// Lines 123-126 in pizza_drop.move
let time = timestamp::now_microseconds();
let random_val = time % 401; // Predictable "randomness"
let random_amount = 100 + random_val; // 100-500 range, fully deterministic

Risk

Likelihood:

  • Every user registration automatically triggers this predictable generation mechanism

  • Every user registration automatically triggers this predictable generation mechanism

  • Sophisticated attackers can time transactions to microsecond precision using MEV techniques

  • No additional conditions or privileges required for exploitation

Impact:

  • Unfair reward distribution heavily favoring attackers who optimize transaction timing

  • Legitimate users systematically receive suboptimal rewards due to random timing

  • Complete breakdown of airdrop fairness guarantees and randomness assumptions

  • Potential for coordinated attacks to drain maximum value from the reward pool

  • Reputational damage to protocol due to manipulated reward distribution

Proof of Concept

Live blockchain testing demonstrates complete predictability of the randomness mechanism:

# User1 registration result: 181 Octas assigned
# User2 registration at timestamp: 1756837649567798
# User2 assigned amount: 356 Octas
# Mathematical verification:
# timestamp % 401 + 100 = 1756837649567798 % 401 + 100 = 256 + 100 = 356
# This proves the formula is deterministic and exploitable

An attacker monitoring blockchain state can calculate that registering when timestamp % 401 = 300 guarantees the maximum reward of 400 + 100 = 500 Octas, while other users receive random amounts based purely on timing luck.

Recommended Mitigation

Implement cryptographically secure randomness or combine multiple unpredictable entropy sources to prevent timing-based manipulation of reward amounts.

- let time = timestamp::now_microseconds();
- let random_val = time % 401;
+ // Use proper randomness source if available
+ use aptos_framework::randomness_api_v0_config;
+ let random_bytes = randomness::u64_range(0, 401);
+ let random_val = random_bytes;
// Alternative: Combine multiple entropy sources
+ let combined_entropy = timestamp::now_microseconds() +
+ signer::address_of(user_addr) as u64 +
+ transaction::get_transaction_hash();
+ let random_val = combined_entropy % 401;
Updates

Appeal created

bube Lead Judge 13 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.