#pallet #randomness #frame #flip #production #polkadot #insecure

no-std pallet-insecure-randomness-collective-flip

Insecure do not use in production: FRAME randomness collective flip pallet (polkadot v1.10.0)

23 releases (major breaking)

new 20.0.0 Apr 8, 2024
19.0.0 Mar 18, 2024
18.0.0 Feb 26, 2024
17.0.0 Feb 13, 2024
0.0.0 Feb 2, 2023

#1027 in Magic Beans

Download history 10/week @ 2023-12-18 9/week @ 2023-12-25 30/week @ 2024-01-01 203/week @ 2024-01-08 248/week @ 2024-01-15 170/week @ 2024-01-22 196/week @ 2024-01-29 110/week @ 2024-02-05 309/week @ 2024-02-12 620/week @ 2024-02-19 1006/week @ 2024-02-26 414/week @ 2024-03-04 692/week @ 2024-03-11 1326/week @ 2024-03-18 866/week @ 2024-03-25 908/week @ 2024-04-01

3,813 downloads per month
Used in 9 crates (6 directly)

Apache-2.0

2MB
34K SLoC

DO NOT USE IN PRODUCTION

The produced values do not fulfill the cryptographic requirements for random numbers. Should not be used for high-stake production use-cases.

Randomness Module

The Randomness Collective Flip module provides a random function that generates low-influence random values based on the block hashes from the previous 81 blocks. Low-influence randomness can be useful when defending against relatively weak adversaries. Using this pallet as a randomness source is advisable primarily in low-security situations like testing.

Public Functions

See the Module struct for details of publicly available functions.

Usage

Prerequisites

Import the Randomness Collective Flip module and derive your module's configuration trait from the system trait.

Example - Get random seed for the current block

use frame_support::traits::Randomness;

#[frame_support::pallet]
pub mod pallet {
    use super::*;
    use frame_support::pallet_prelude::*;
    use frame_system::pallet_prelude::*;

    #[pallet::pallet]
    pub struct Pallet<T>(_);

    #[pallet::config]
    pub trait Config: frame_system::Config + pallet_insecure_randomness_collective_flip::Config {}

    #[pallet::call]
    impl<T: Config> Pallet<T> {
        #[pallet::weight(0)]
        pub fn random_module_example(origin: OriginFor<T>) -> DispatchResult {
            let _random_value = <pallet_insecure_randomness_collective_flip::Pallet<T>>::random(&b"my context"[..]);
            Ok(())
        }
    }
}

License: Apache-2.0

Dependencies

~18–31MB
~511K SLoC