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

Insecure randomness

Insecure randomness

Description

The expected behavior is that each registered user should receive a random allocation of APT between 100-500 units, which is supposed to be unpredictable and fair. However, relying as source of randomness to timestamp::now_microseconds() and taking a simple modulus, makes it predictable and exploitable by validators.

#[randomness]
entry fun get_random_slice(user_addr: address) acquires ModuleData, State {
let state = borrow_global_mut<State>(get_resource_address());
@> let time = timestamp::now_microseconds();
@> let random_val = time % 401;
let random_amount = 100 + random_val; // 100-500 APT
table::add(&mut state.users_claimed_amount, user_addr, random_amount);
}

Risk

Likelihood: High

Transaction timestamps are publicly visible and predictable in the Aptos network, so user can knwo in advance what value will be produced. Validator can reorder transactions to force timestamp values during block production.

Impact: High

Validators can deterministacally choose payout amounts for users, so the fairness of the airdrop is completely compromised.

Proof of Concept

random_val = timestamp % 401

Any of the following timestamps produce a favorable outcome

1756753893060045
1756753893060446
1756753893060847
1756753893061248
1756753893061649

Recommended Mitigation

Aptos framework has a native package for managing randomness

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

Appeal created

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