The Pizza Drop contract randomly assigns rewards between 100-500 APT to registered users.
The contract uses block timestamp modulo for randomness generation, which is predictable and can be manipulated to assign specific reward amounts.
Likelihood:
Block timestamps can be predicted with high accuracy
Validators can manipulate block timestamps within reasonable bounds
The modulo operation makes specific outcomes easily targetable by timing transactions
The randomness pattern is fully deterministic based on block inclusion time
Impact:
Fair random distribution of rewards is compromised
Owner can time registrations to assign high or low rewards to certain users
Validators can manipulate timestamps to benefit specific addresses
The following test demonstrates how the timestamp-based randomness can be manipulated to consistently get either minimum (100) or maximum (500) rewards:
This test shows that:
By setting timestamp to a multiple of 401, we get minimum reward (100)
By setting timestamp to (multiple of 401) + 400, we get maximum reward (500)
Validators can manipulate timestamps to target specific reward amounts
Owner can time their transactions to target higher or lower rewards
The vulnerability requires two key changes:
Replace timestamp-based randomness with Aptos's secure randomness module:
Remove public
visibility from register_pizza_lover
function to prevent unsafe exposure and add the #[randomness]
attribute which is required for entry functions calling randomnesss features:
Uses Aptos's secure randomness API instead of predictable timestamps
Prevents timestamp manipulation attacks
Ensures fair distribution of rewards
Properly annotates randomness usage with #[randomness]
attribute
Ensures safe randomness by not exposing it in a public function.
This change ensures that reward amounts cannot be predicted or manipulated by validators or users, maintaining the fairness of the airdrop distribution.
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.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.