Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Remove impl Randomness for () #6452

@burdges

Description

@burdges

We gained an impl<Output: Decode + Default> Randomness<Output> for () in https://crates.parity.io/frame_support/traits/trait.Randomness.html#foreign-impls added by cdceee2#diff-0010d009b169768f89902f63e50e3c10R780 which looks dangerous.

It's only used in frame/society/src/mock.rs which lives behind #[cfg(test)] mod mock; so maybe it can be replaced by pallet-randomness-collective-flip which provides insecure randomness for tests elsewhere?

If we want this, then it would require the test feature be propagated into frame-support, like

impl<Output: Decode + Default> Randomness<Output> for () {
        fn random(subject: &[u8]) -> Output {
                if cfg!(test) {
                        Output::decode(&mut TrailingZeroInput::new(subject)).unwrap_or_default()
                } else {
                        panic!("Used () as Randomness in production")
                }
        }
}

If test already implies std then one might play games with std::collections::hash_map::RandomState but presumably that's more cargo pain than its worth.

Metadata

Metadata

Assignees

No one assigned

    Labels

    I2-securityThe client fails to follow expected, security-sensitive, behaviour.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions