Skip to content

💡 [REQUEST] - Better random for fuzzing #438

@SteMak

Description

@SteMak

Summary

Trident uses fair random generator which is not a good solution for fuzzing toolkit

For example, the following assert did not reverted for over 100B executions

#[flow]
fn flow1(&mut self) {
    let a = self.trident.random_from_range(0..u64::MAX) as u128;
    let b = self.trident.random_from_range(0..u64::MAX) as u128;
    let c = self.trident.random_from_range(0..u64::MAX) as u128;

    assert!(a * b > c);
}

Basic Example

Unfair random based on various byte sequences can be used

// Funny sample of unfair random breaking the assert above
fn unfair_u64(&mut self) -> u64 {
    let pow = self.trident.random_from_range(7..71);
    let divisor = self.trident.random_from_range(131..247);
    return (2u128.pow(pow) / divisor) as u64;
}

Drawbacks

Good unfair random is a way more complex than the fair one, it is usually statefull which takes additional computation resources

Unresolved questions

No response

Implementation PR

No response

Reference Issues

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions