From 8fdc86a1991121a87d271c2a2ba29255869d6ef0 Mon Sep 17 00:00:00 2001 From: Jonathan Gray Date: Wed, 30 Aug 2023 12:57:28 +0100 Subject: [PATCH] remove insecure randomness --- Cargo.lock | 44 +--------------------------- pallets/symmetric-key/src/weights.rs | 28 ++++++++++-------- runtime/Cargo.toml | 3 -- runtime/src/lib.rs | 5 +--- 4 files changed, 17 insertions(+), 63 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3ec2df70..8155d6b6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1767,7 +1767,6 @@ dependencies = [ "pallet-collective", "pallet-doas", "pallet-grandpa", - "pallet-insecure-randomness-collective-flip", "pallet-membership", "pallet-node-authorization", "pallet-preimage", @@ -4877,20 +4876,6 @@ dependencies = [ "sp-std", ] -[[package]] -name = "pallet-insecure-randomness-collective-flip" -version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.42#ff24c60ac7d9f87727ecdd0ded9a80c56e4f4b65" -dependencies = [ - "frame-support", - "frame-system", - "parity-scale-codec", - "safe-mix", - "scale-info", - "sp-runtime", - "sp-std", -] - [[package]] name = "pallet-membership" version = "4.0.0-dev" @@ -6148,15 +6133,6 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3e75f6a532d0fd9f7f13144f392b6ad56a32696bfcd9c78f797f16bbb6f072d6" -[[package]] -name = "rustc_version" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" -dependencies = [ - "semver 0.9.0", -] - [[package]] name = "rustc_version" version = "0.4.0" @@ -6272,15 +6248,6 @@ version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041" -[[package]] -name = "safe-mix" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d3d055a2582e6b00ed7a31c1524040aa391092bf636328350813f3a0605215c" -dependencies = [ - "rustc_version 0.2.3", -] - [[package]] name = "safe_arch" version = "0.6.0" @@ -7483,15 +7450,6 @@ dependencies = [ "semver-parser", ] -[[package]] -name = "semver" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" -dependencies = [ - "semver-parser", -] - [[package]] name = "semver" version = "1.0.17" @@ -7719,7 +7677,7 @@ dependencies = [ "curve25519-dalek 4.0.0-rc.1", "rand_core 0.6.4", "ring", - "rustc_version 0.4.0", + "rustc_version", "sha2 0.10.6", "subtle", ] diff --git a/pallets/symmetric-key/src/weights.rs b/pallets/symmetric-key/src/weights.rs index fd9a53df..c339cb61 100644 --- a/pallets/symmetric-key/src/weights.rs +++ b/pallets/symmetric-key/src/weights.rs @@ -47,19 +47,21 @@ impl WeightInfo for SubstrateWeight { .saturating_add(Weight::from_parts(0, 0)) .saturating_add(T::DbWeight::get().writes(1)) } - /// Storage: RandomnessCollectiveFlip RandomMaterial (r:1 w:0) - /// Proof: RandomnessCollectiveFlip RandomMaterial (max_values: Some(1), max_size: Some(2594), added: 3089, mode: MaxEncodedLen) - /// Storage: IpfsKey Key (r:0 w:1) - /// Proof: IpfsKey Key (max_values: Some(1), max_size: Some(33), added: 528, mode: MaxEncodedLen) - fn rotate_key() -> Weight { - // Proof Size summary in bytes: - // Measured: `6` - // Estimated: `4079` - // Minimum execution time: 4_000_000 picoseconds. - Weight::from_parts(5_000_000, 0) - .saturating_add(Weight::from_parts(0, 4079)) - .saturating_add(T::DbWeight::get().reads(1)) - .saturating_add(T::DbWeight::get().writes(1)) + /// Storage: Babe NextRandomness (r:1 w:0) + /// Proof: Babe NextRandomness (max_values: Some(1), max_size: Some(32), added: 527, mode: MaxEncodedLen) + /// Storage: Babe EpochStart (r:1 w:0) + /// Proof: Babe EpochStart (max_values: Some(1), max_size: Some(8), added: 503, mode: MaxEncodedLen) + /// Storage: IpfsKey Key (r:0 w:1) + /// Proof: IpfsKey Key (max_values: Some(1), max_size: Some(33), added: 528, mode: MaxEncodedLen) + fn rotate_key() -> Weight { + // Proof Size summary in bytes: + // Measured: `132` + // Estimated: `1517` + // Minimum execution time: 5_000_000 picoseconds. + Weight::from_parts(6_000_000, 0) + .saturating_add(Weight::from_parts(0, 1517)) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(1)) } } diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 6c377294..06b32ce3 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -22,7 +22,6 @@ pallet-babe = { version = "4.0.0-dev", default-features = false, git = "https:// pallet-balances = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" } frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" } pallet-grandpa = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" } -pallet-insecure-randomness-collective-flip = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" } pallet-sudo = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" } frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.42" } frame-try-runtime = { version = "0.10.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", optional = true, branch = "polkadot-v0.9.42" } @@ -93,7 +92,6 @@ std = [ "pallet-node-authorization/std", "pallet-preimage/std", "pallet-process-validation/std", - "pallet-insecure-randomness-collective-flip/std", "pallet-sudo/std", "pallet-timestamp/std", "pallet-transaction-payment-free/std", @@ -145,7 +143,6 @@ try-runtime = [ "pallet-node-authorization/try-runtime", "pallet-preimage/try-runtime", "pallet-process-validation/try-runtime", - "pallet-insecure-randomness-collective-flip/try-runtime", "pallet-scheduler/try-runtime", "pallet-utxo-nft/try-runtime", "pallet-sudo/try-runtime", diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 2a4ebb0c..6c6a8403 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -206,8 +206,6 @@ impl frame_system::Config for Runtime { type MaxConsumers = frame_support::traits::ConstU32<16>; } -impl pallet_insecure_randomness_collective_flip::Config for Runtime {} - parameter_types! { // NOTE: Currently it is not possible to change the epoch duration after the chain has started. // Attempting to do so will brick block production. @@ -461,7 +459,7 @@ impl pallet_symmetric_key::Config for Runtime { type ScheduleCall = RuntimeCall; type UpdateOrigin = MoreThanHalfMembers; type RotateOrigin = MoreThanTwoMembers; - type Randomness = RandomnessCollectiveFlip; + type Randomness = pallet_babe::RandomnessFromOneEpochAgo; type PalletsOrigin = OriginCaller; type Scheduler = Scheduler; type WeightInfo = pallet_symmetric_key::weights::SubstrateWeight; @@ -476,7 +474,6 @@ construct_runtime!( UncheckedExtrinsic = UncheckedExtrinsic, { System: frame_system, - RandomnessCollectiveFlip: pallet_insecure_randomness_collective_flip, Timestamp: pallet_timestamp, Babe: pallet_babe, Grandpa: pallet_grandpa,