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

Randomness wrongly implemented redering the whole setup ineffective

Root + Impact

Description

  • The amount of APT received is supposed to be random, apparently by making use of the Aptos randomness API.

  • The randomnesss is wrongly implemented. Instead, the amount of APT received is totally dependent on the timestamp.

#[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();
// @> ROOT CAUSE: Using timestamp for randomness is predictable and manipulable
let random_val = time % 401;
let random_amount = 100 + random_val; // 100-500 APT (in Octas: 10^8 smallest unit)
table::add(&mut state.users_claimed_amount, user_addr, random_amount);
}

Risk

There's no direct risk from the attacker as the get_random_slice function is only invoked after the register_pizza_lover function is called which can
only be executed by the contract owner.
It simply makes it unfair since the amount of APT received by pizza lovers will vary depending on the exact time their address was registered
by the contract owner.

Likelihood:

  • High

Impact:

Unfair distribution of APT.

Proof of Concept
N/A

Recommended Mitigation

Implement the randomness correctly and

- let time = timestamp::now_microseconds();
- let random_val = time % 401;
+ let random_val = randomness::u64_range(100, 501);

Also, add the folowing attribute on top of the register_pizza_lover function:

+ #[lint::allow_unsafe_randomness]

And the these 2 lines in each one of the tests to use randomness:
These are to initialise randomness for use in a testing environment.


+ randomness::initialize_for_testing(framework);
+ randomness::set_seed(x"0000000000000000000000000000000000000000000000000000000000000000");
Updates

Appeal created

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