From 5f2f56b6750a0ed0e871d60b1a2e81e428e7e7f1 Mon Sep 17 00:00:00 2001 From: cheme Date: Fri, 20 Oct 2023 05:13:19 +0200 Subject: [PATCH] Switch trie cache random seed (#1935) Use a more secure seed for hashsets of cache. --- substrate/primitives/trie/Cargo.toml | 2 ++ substrate/primitives/trie/src/cache/shared_cache.rs | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/substrate/primitives/trie/Cargo.toml b/substrate/primitives/trie/Cargo.toml index 0b54514f6003d..1ef4318c51ff5 100644 --- a/substrate/primitives/trie/Cargo.toml +++ b/substrate/primitives/trie/Cargo.toml @@ -26,6 +26,7 @@ lazy_static = { version = "1.4.0", optional = true } memory-db = { version = "0.32.0", default-features = false } nohash-hasher = { version = "0.2.0", optional = true } parking_lot = { version = "0.12.1", optional = true } +rand = { version = "0.8", optional = true } scale-info = { version = "2.5.0", default-features = false, features = ["derive"] } thiserror = { version = "1.0.48", optional = true } tracing = { version = "0.1.29", optional = true } @@ -53,6 +54,7 @@ std = [ "memory-db/std", "nohash-hasher", "parking_lot", + "rand", "scale-info/std", "schnellru", "sp-core/std", diff --git a/substrate/primitives/trie/src/cache/shared_cache.rs b/substrate/primitives/trie/src/cache/shared_cache.rs index 28b3274fde11e..01ac41a1e47d9 100644 --- a/substrate/primitives/trie/src/cache/shared_cache.rs +++ b/substrate/primitives/trie/src/cache/shared_cache.rs @@ -30,7 +30,11 @@ use std::{ use trie_db::{node::NodeOwned, CachedValue}; lazy_static::lazy_static! { - static ref RANDOM_STATE: ahash::RandomState = ahash::RandomState::default(); + static ref RANDOM_STATE: ahash::RandomState = { + use rand::Rng; + let mut rng = rand::thread_rng(); + ahash::RandomState::generate_with(rng.gen(), rng.gen(), rng.gen(), rng.gen()) + }; } pub struct SharedNodeCacheLimiter {