From 814b5972f25756bbe37e839d4841d9c904e0225a Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Wed, 25 Oct 2023 12:54:09 +0200 Subject: [PATCH 01/52] wip: sp-core::core --- substrate/primitives/core/Cargo.toml | 17 ++++++----------- substrate/primitives/core/src/crypto.rs | 15 +++++---------- .../primitives/keyring/src/bandersnatch.rs | 2 +- 3 files changed, 12 insertions(+), 22 deletions(-) diff --git a/substrate/primitives/core/Cargo.toml b/substrate/primitives/core/Cargo.toml index 9f1f0127d7cd..f0bc7adf6f9a 100644 --- a/substrate/primitives/core/Cargo.toml +++ b/substrate/primitives/core/Cargo.toml @@ -24,12 +24,12 @@ hash-db = { version = "0.16.0", default-features = false } hash256-std-hasher = { version = "0.15.2", default-features = false } bs58 = { version = "0.5.0", default-features = false, optional = true } rand = { version = "0.8.5", features = ["small_rng"], optional = true } -substrate-bip39 = { version = "0.4.4", optional = true } -tiny-bip39 = { version = "1.0.0", optional = true } -regex = { version = "1.6.0", optional = true } +substrate-bip39 = { version = "0.4.4" } +tiny-bip39 = { git = "https://github.com/michalkucharczyk/tiny-bip39/" , branch = "mku-rand-is-optional", default-features = false, features = [ "default-langs" ] } +regex = { version = "1.6.0",default-features = false, features = ["unicode-perl"] } zeroize = { version = "1.4.3", default-features = false } -secrecy = { version = "0.8.0", default-features = false } -lazy_static = { version = "1.4.0", default-features = false, optional = true } +secrecy = { version = "0.8.0", default-features = false, features = ["alloc"] } +lazy_static = { version = "1.4.0", default-features = false, features = [ "spin_no_std" ] } parking_lot = { version = "0.12.1", optional = true } ss58-registry = { version = "1.34.0", default-features = false } sp-std = { path = "../std", default-features = false} @@ -88,7 +88,6 @@ std = [ "hash-db/std", "hash256-std-hasher/std", "impl-serde/std", - "lazy_static", "libsecp256k1/std", "log/std", "merlin/std", @@ -98,12 +97,10 @@ std = [ "primitive-types/serde", "primitive-types/std", "rand", - "regex", "scale-info/std", "schnorrkel/std", "secp256k1/global-context", "secp256k1/std", - "secrecy/alloc", "serde/std", "sp-core-hashing/std", "sp-debug-derive/std", @@ -112,9 +109,8 @@ std = [ "sp-std/std", "sp-storage/std", "ss58-registry/std", - "substrate-bip39", "thiserror", - "tiny-bip39", + "tiny-bip39/rand", "tracing", "zeroize/alloc", ] @@ -129,7 +125,6 @@ serde = [ "impl-serde", "primitive-types/serde_no_std", "scale-info/serde", - "secrecy/alloc", "sp-core-hashing", "sp-storage/serde", ] diff --git a/substrate/primitives/core/src/crypto.rs b/substrate/primitives/core/src/crypto.rs index be9f56eb2ba4..782c947c0103 100644 --- a/substrate/primitives/core/src/crypto.rs +++ b/substrate/primitives/core/src/crypto.rs @@ -19,14 +19,14 @@ use crate::{ed25519, sr25519}; #[cfg(feature = "std")] -use bip39::{Language, Mnemonic, MnemonicType}; +use bip39::MnemonicType; +#[cfg(feature = "full_crypto")] +use bip39::{Language, Mnemonic}; use codec::{Decode, Encode, MaxEncodedLen}; #[cfg(feature = "std")] use rand::{rngs::OsRng, RngCore}; -#[cfg(feature = "std")] use regex::Regex; use scale_info::TypeInfo; -#[cfg(feature = "std")] pub use secrecy::{ExposeSecret, SecretString}; use sp_runtime_interface::pass_by::PassByInner; #[doc(hidden)] @@ -77,7 +77,6 @@ impl> UncheckedInto for S { /// An error with the interpretation of a secret. #[cfg_attr(feature = "std", derive(thiserror::Error))] #[derive(Debug, Clone, PartialEq, Eq)] -#[cfg(feature = "full_crypto")] pub enum SecretStringError { /// The overall format was invalid (e.g. the seed phrase contained symbols). #[cfg_attr(feature = "std", error("Invalid format"))] @@ -412,7 +411,6 @@ pub fn set_default_ss58_version(new_default: Ss58AddressFormat) { DEFAULT_VERSION.store(new_default.into(), core::sync::atomic::Ordering::Relaxed); } -#[cfg(feature = "std")] lazy_static::lazy_static! { static ref SS58_REGEX: Regex = Regex::new(r"^(?P[\w\d ]+)?(?P(//?[^/]+)*)$") .expect("constructed from known-good static value; qed"); @@ -798,7 +796,7 @@ mod dummy { /// assert_eq!("0xe5be9a5092b81bca64be81d212e7f2f9eba183bb7a90954f7b76361f6edb5c0a", suri.phrase.expose_secret()); /// assert!(suri.password.is_none()); /// ``` -#[cfg(feature = "std")] +#[cfg(feature = "full_crypto")] pub struct SecretUri { /// The phrase to derive the private key. /// @@ -810,7 +808,7 @@ pub struct SecretUri { pub junctions: Vec, } -#[cfg(feature = "std")] +#[cfg(feature = "full_crypto")] impl sp_std::str::FromStr for SecretUri { type Err = SecretStringError; @@ -878,7 +876,6 @@ pub trait Pair: CryptoType + Sized { } /// Returns the KeyPair from the English BIP39 seed `phrase`, or an error if it's invalid. - #[cfg(feature = "std")] fn from_phrase( phrase: &str, password: Option<&str>, @@ -954,7 +951,6 @@ pub trait Pair: CryptoType + Sized { /// Notably, integer junction indices may be legally prefixed with arbitrary number of zeros. /// Similarly an empty password (ending the SURI with `///`) is perfectly valid and will /// generally be equivalent to no password at all. - #[cfg(feature = "std")] fn from_string_with_seed( s: &str, password_override: Option<&str>, @@ -988,7 +984,6 @@ pub trait Pair: CryptoType + Sized { /// Interprets the string `s` in order to generate a key pair. /// /// See [`from_string_with_seed`](Pair::from_string_with_seed) for more extensive documentation. - #[cfg(feature = "std")] fn from_string(s: &str, password_override: Option<&str>) -> Result { Self::from_string_with_seed(s, password_override).map(|x| x.0) } diff --git a/substrate/primitives/keyring/src/bandersnatch.rs b/substrate/primitives/keyring/src/bandersnatch.rs index 8de6786a6fbf..ce43c197e9b0 100644 --- a/substrate/primitives/keyring/src/bandersnatch.rs +++ b/substrate/primitives/keyring/src/bandersnatch.rs @@ -25,7 +25,7 @@ use sp_core::{ }; use lazy_static::lazy_static; -use std::{collections::HashMap, ops::Deref, sync::Mutex}; +use sp_std::{collections::HashMap, ops::Deref, sync::Mutex}; /// Set of test accounts. #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, strum::Display, strum::EnumIter)] From 69f21686524d0da2d19a7d0e5b154ae79e93913d Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Wed, 25 Oct 2023 12:58:00 +0200 Subject: [PATCH 02/52] wip: sp-keyring --- substrate/primitives/keyring/Cargo.toml | 14 ++++++++--- substrate/primitives/keyring/src/ed25519.rs | 19 +++++++++++---- substrate/primitives/keyring/src/lib.rs | 2 ++ substrate/primitives/keyring/src/sr25519.rs | 26 ++++++++++++++------- 4 files changed, 46 insertions(+), 15 deletions(-) diff --git a/substrate/primitives/keyring/Cargo.toml b/substrate/primitives/keyring/Cargo.toml index 1ab78eeed453..66dbe2513915 100644 --- a/substrate/primitives/keyring/Cargo.toml +++ b/substrate/primitives/keyring/Cargo.toml @@ -14,12 +14,20 @@ readme = "README.md" targets = ["x86_64-unknown-linux-gnu"] [dependencies] -lazy_static = "1.4.0" +lazy_static = { version = "1.4.0", features = [ "spin_no_std" ], default-features = false } strum = { version = "0.24.1", features = ["derive"], default-features = false } -sp-core = { path = "../core" } -sp-runtime = { path = "../runtime" } +sp-core = { path = "../core", default-features = false, features = ["full_crypto"] } +sp-runtime = { path = "../runtime", default-features = false } +sp-std = { path = "../std", default-features = false } [features] +default = [ "std" ] +std = [ + "sp-core/std", + "sp-runtime/std", + "sp-std/std", +] + # This feature adds Bandersnatch crypto primitives. # It should not be used in production since the implementation and interface may still # be subject to significant changes. diff --git a/substrate/primitives/keyring/src/ed25519.rs b/substrate/primitives/keyring/src/ed25519.rs index c3ad86409e90..dafce7a356e2 100644 --- a/substrate/primitives/keyring/src/ed25519.rs +++ b/substrate/primitives/keyring/src/ed25519.rs @@ -24,10 +24,21 @@ use sp_core::{ ByteArray, Pair as PairT, H256, }; use sp_runtime::AccountId32; -use std::{collections::HashMap, ops::Deref}; + +#[cfg(not(feature = "std"))] +use sp_std::alloc::{format, string::String}; +#[cfg(not(feature = "std"))] +use sp_std::ops::Deref; +use sp_std::vec::Vec; +#[cfg(not(feature = "std"))] +use sp_std::{collections::btree_map::BTreeMap, prelude::*}; +#[cfg(feature = "std")] +use std::{collections::BTreeMap, ops::Deref}; /// Set of test accounts. -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, strum::Display, strum::EnumIter)] +#[derive( + Debug, Clone, Copy, PartialEq, Eq, Hash, strum::Display, strum::EnumIter, Ord, PartialOrd, +)] pub enum Keyring { Alice, Bob, @@ -117,9 +128,9 @@ impl From for sp_runtime::MultiSigner { } lazy_static! { - static ref PRIVATE_KEYS: HashMap = + static ref PRIVATE_KEYS: BTreeMap = Keyring::iter().map(|i| (i, i.pair())).collect(); - static ref PUBLIC_KEYS: HashMap = + static ref PUBLIC_KEYS: BTreeMap = PRIVATE_KEYS.iter().map(|(&name, pair)| (name, pair.public())).collect(); } diff --git a/substrate/primitives/keyring/src/lib.rs b/substrate/primitives/keyring/src/lib.rs index 1db18f7edbdc..4196bc61d1c8 100644 --- a/substrate/primitives/keyring/src/lib.rs +++ b/substrate/primitives/keyring/src/lib.rs @@ -15,6 +15,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#![cfg_attr(not(feature = "std"), no_std)] + //! Support code for the runtime. A set of test accounts. /// Test account crypto for sr25519. diff --git a/substrate/primitives/keyring/src/sr25519.rs b/substrate/primitives/keyring/src/sr25519.rs index c738cfdc59d9..f707393f1f63 100644 --- a/substrate/primitives/keyring/src/sr25519.rs +++ b/substrate/primitives/keyring/src/sr25519.rs @@ -24,10 +24,20 @@ use sp_core::{ ByteArray, Pair as PairT, H256, }; use sp_runtime::AccountId32; -use std::{collections::HashMap, ops::Deref}; +#[cfg(not(feature = "std"))] +use sp_std::alloc::{format, string::String}; +#[cfg(not(feature = "std"))] +use sp_std::ops::Deref; +use sp_std::vec::Vec; +#[cfg(not(feature = "std"))] +use sp_std::{collections::btree_map::BTreeMap, prelude::*}; +#[cfg(feature = "std")] +use std::{collections::BTreeMap, ops::Deref}; /// Set of test accounts. -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, strum::Display, strum::EnumIter)] +#[derive( + Debug, Clone, Copy, PartialEq, Eq, Hash, strum::Display, strum::EnumIter, Ord, PartialOrd, +)] pub enum Keyring { Alice, Bob, @@ -129,16 +139,16 @@ impl From for sp_runtime::MultiSigner { #[derive(Debug)] pub struct ParseKeyringError; -impl std::fmt::Display for ParseKeyringError { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl sp_std::fmt::Display for ParseKeyringError { + fn fmt(&self, f: &mut sp_std::fmt::Formatter<'_>) -> sp_std::fmt::Result { write!(f, "ParseKeyringError") } } -impl std::str::FromStr for Keyring { +impl sp_std::str::FromStr for Keyring { type Err = ParseKeyringError; - fn from_str(s: &str) -> Result::Err> { + fn from_str(s: &str) -> Result::Err> { match s { "alice" => Ok(Keyring::Alice), "bob" => Ok(Keyring::Bob), @@ -154,9 +164,9 @@ impl std::str::FromStr for Keyring { } lazy_static! { - static ref PRIVATE_KEYS: HashMap = + static ref PRIVATE_KEYS: BTreeMap = Keyring::iter().map(|i| (i, i.pair())).collect(); - static ref PUBLIC_KEYS: HashMap = + static ref PUBLIC_KEYS: BTreeMap = PRIVATE_KEYS.iter().map(|(&name, pair)| (name, pair.public())).collect(); } From f6a5ec0998ca02cb9aeefb308115f19efb46e662 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Wed, 25 Oct 2023 13:14:38 +0200 Subject: [PATCH 03/52] wip: test-runtime --- substrate/test-utils/runtime/Cargo.toml | 9 ++++----- substrate/test-utils/runtime/src/lib.rs | 3 +++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/substrate/test-utils/runtime/Cargo.toml b/substrate/test-utils/runtime/Cargo.toml index 4d279c7b703d..d87aa36855fa 100644 --- a/substrate/test-utils/runtime/Cargo.toml +++ b/substrate/test-utils/runtime/Cargo.toml @@ -13,7 +13,7 @@ publish = false targets = ["x86_64-unknown-linux-gnu"] [dependencies] -sp-application-crypto = { path = "../../primitives/application-crypto", default-features = false, features = ["serde"] } +sp-application-crypto = { path = "../../primitives/application-crypto", default-features = false, features = ["full_crypto"] } sp-consensus-aura = { path = "../../primitives/consensus/aura", default-features = false, features = ["serde"] } sp-consensus-babe = { path = "../../primitives/consensus/babe", default-features = false, features = ["serde"] } sp-genesis-builder = { path = "../../primitives/genesis-builder", default-features = false} @@ -21,11 +21,11 @@ sp-block-builder = { path = "../../primitives/block-builder", default-features = codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false, features = ["derive"] } scale-info = { version = "2.5.0", default-features = false, features = ["derive"] } sp-inherents = { path = "../../primitives/inherents", default-features = false} -sp-keyring = { path = "../../primitives/keyring", optional = true} +sp-keyring = { path = "../../primitives/keyring", default-features = false} sp-offchain = { path = "../../primitives/offchain", default-features = false} -sp-core = { path = "../../primitives/core", default-features = false} +sp-core = { path = "../../primitives/core", default-features = false, features=["full_crypto"]} sp-std = { path = "../../primitives/std", default-features = false} -sp-io = { path = "../../primitives/io", default-features = false} +sp-io = { path = "../../primitives/io", default-features = false, features = ["disable_panic_handler"]} frame-support = { path = "../../frame/support", default-features = false} sp-version = { path = "../../primitives/version", default-features = false} sp-session = { path = "../../primitives/session", default-features = false} @@ -92,7 +92,6 @@ std = [ "sp-genesis-builder/std", "sp-inherents/std", "sp-io/std", - "sp-keyring", "sp-offchain/std", "sp-runtime/std", "sp-session/std", diff --git a/substrate/test-utils/runtime/src/lib.rs b/substrate/test-utils/runtime/src/lib.rs index 687790f2ffaf..c945aa58666f 100644 --- a/substrate/test-utils/runtime/src/lib.rs +++ b/substrate/test-utils/runtime/src/lib.rs @@ -74,6 +74,8 @@ pub use pallet_balances::Call as BalancesCall; pub type AuraId = sp_consensus_aura::sr25519::AuthorityId; #[cfg(feature = "std")] pub use extrinsic::{ExtrinsicBuilder, Transfer}; +use sp_application_crypto::Ss58Codec; +use sp_keyring::AccountKeyring; const LOG_TARGET: &str = "substrate-test-runtime"; @@ -723,6 +725,7 @@ impl_runtime_apis! { impl sp_genesis_builder::GenesisBuilder for Runtime { fn create_default_config() -> Vec { + log::info!("{:#?}", AccountKeyring::Alice.public().to_ss58check()); create_default_config::() } From a6ee75491979eb6ef97079fd4d7c2bd38e7ae7f9 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Thu, 26 Oct 2023 13:39:53 +0200 Subject: [PATCH 04/52] wip: keyring 2 --- substrate/primitives/keyring/Cargo.toml | 9 ++++++++- substrate/primitives/keyring/src/ed25519.rs | 19 +++++++++++++------ substrate/primitives/keyring/src/sr25519.rs | 16 ++++++++++++---- 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/substrate/primitives/keyring/Cargo.toml b/substrate/primitives/keyring/Cargo.toml index 66dbe2513915..c69e8eb5ad47 100644 --- a/substrate/primitives/keyring/Cargo.toml +++ b/substrate/primitives/keyring/Cargo.toml @@ -16,10 +16,14 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] lazy_static = { version = "1.4.0", features = [ "spin_no_std" ], default-features = false } strum = { version = "0.24.1", features = ["derive"], default-features = false } -sp-core = { path = "../core", default-features = false, features = ["full_crypto"] } +sp-core = { path = "../core", default-features = false } sp-runtime = { path = "../runtime", default-features = false } sp-std = { path = "../std", default-features = false } +#todo: remove this (required for `cargo build --no-default-features`) +sp-io = { path = "../io", default-features = false, optional = true } +sp-runtime-interface = { path = "../runtime-interface", default-features = false, optional = true } + [features] default = [ "std" ] std = [ @@ -28,6 +32,9 @@ std = [ "sp-std/std", ] +#todo: remove this (required for `cargo build --no-default-features`) +compile = [ "sp-io/disable_panic_handler", "sp-runtime-interface/disable_target_static_assertions" ] + # This feature adds Bandersnatch crypto primitives. # It should not be used in production since the implementation and interface may still # be subject to significant changes. diff --git a/substrate/primitives/keyring/src/ed25519.rs b/substrate/primitives/keyring/src/ed25519.rs index dafce7a356e2..7cc2fefcee62 100644 --- a/substrate/primitives/keyring/src/ed25519.rs +++ b/substrate/primitives/keyring/src/ed25519.rs @@ -19,22 +19,28 @@ use lazy_static::lazy_static; pub use sp_core::ed25519; +#[cfg(feature = "full_crypto")] +use sp_core::Signature; use sp_core::{ - ed25519::{Pair, Public, Signature}, + ed25519::{Pair, Public}, ByteArray, Pair as PairT, H256, }; use sp_runtime::AccountId32; -#[cfg(not(feature = "std"))] -use sp_std::alloc::{format, string::String}; -#[cfg(not(feature = "std"))] -use sp_std::ops::Deref; use sp_std::vec::Vec; #[cfg(not(feature = "std"))] -use sp_std::{collections::btree_map::BTreeMap, prelude::*}; +use sp_std::{collections::btree_map::BTreeMap, ops::Deref, prelude::*}; #[cfg(feature = "std")] use std::{collections::BTreeMap, ops::Deref}; +// todo: this requires cleanup! +// #[cfg(not(feature = "std"))] +// use sp_std::{alloc::string::String, format}; +#[cfg(not(feature = "std"))] +extern crate alloc; +#[cfg(not(feature = "std"))] +use alloc::{format, string::String}; + /// Set of test accounts. #[derive( Debug, Clone, Copy, PartialEq, Eq, Hash, strum::Display, strum::EnumIter, Ord, PartialOrd, @@ -83,6 +89,7 @@ impl Keyring { self.to_raw_public().into() } + #[cfg(feature = "full_crypto")] pub fn sign(self, msg: &[u8]) -> Signature { Pair::from(self).sign(msg) } diff --git a/substrate/primitives/keyring/src/sr25519.rs b/substrate/primitives/keyring/src/sr25519.rs index f707393f1f63..b5586d3b3c2d 100644 --- a/substrate/primitives/keyring/src/sr25519.rs +++ b/substrate/primitives/keyring/src/sr25519.rs @@ -19,21 +19,28 @@ use lazy_static::lazy_static; pub use sp_core::sr25519; +#[cfg(feature = "full_crypto")] +use sp_core::sr25519::Signature; use sp_core::{ - sr25519::{Pair, Public, Signature}, + sr25519::{Pair, Public}, ByteArray, Pair as PairT, H256, }; use sp_runtime::AccountId32; #[cfg(not(feature = "std"))] -use sp_std::alloc::{format, string::String}; -#[cfg(not(feature = "std"))] use sp_std::ops::Deref; -use sp_std::vec::Vec; #[cfg(not(feature = "std"))] use sp_std::{collections::btree_map::BTreeMap, prelude::*}; #[cfg(feature = "std")] use std::{collections::BTreeMap, ops::Deref}; +// todo: this requires cleanup! +// #[cfg(not(feature = "std"))] +// use sp_std::{alloc::string::String, format}; +#[cfg(not(feature = "std"))] +extern crate alloc; +#[cfg(not(feature = "std"))] +use alloc::{format, string::String}; + /// Set of test accounts. #[derive( Debug, Clone, Copy, PartialEq, Eq, Hash, strum::Display, strum::EnumIter, Ord, PartialOrd, @@ -82,6 +89,7 @@ impl Keyring { self.to_raw_public().into() } + #[cfg(feature = "full_crypto")] pub fn sign(self, msg: &[u8]) -> Signature { Pair::from(self).sign(msg) } From a79bfb682b2c00d9eb263737535b47dcf94e66b2 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Thu, 26 Oct 2023 15:28:52 +0200 Subject: [PATCH 05/52] wip: core 2 --- substrate/primitives/core/Cargo.toml | 18 +++++------ substrate/primitives/core/src/crypto.rs | 11 ++----- substrate/primitives/core/src/ecdsa.rs | 40 ++++++++++-------------- substrate/primitives/core/src/ed25519.rs | 22 ++++--------- substrate/primitives/core/src/lib.rs | 2 -- substrate/primitives/core/src/sr25519.rs | 32 ++++++------------- 6 files changed, 42 insertions(+), 83 deletions(-) diff --git a/substrate/primitives/core/Cargo.toml b/substrate/primitives/core/Cargo.toml index f0bc7adf6f9a..8c00622828dc 100644 --- a/substrate/primitives/core/Cargo.toml +++ b/substrate/primitives/core/Cargo.toml @@ -44,14 +44,14 @@ bitflags = "1.3" paste = "1.0.7" # full crypto -array-bytes = { version = "6.1", optional = true } -ed25519-zebra = { version = "3.1.0", default-features = false, optional = true } +array-bytes = { version = "6.1" } +ed25519-zebra = { version = "3.1.0", default-features = false } blake2 = { version = "0.10.4", default-features = false, optional = true } libsecp256k1 = { version = "0.7", default-features = false, features = ["static-context"], optional = true } schnorrkel = { version = "0.9.1", features = ["preaudit_deprecated", "u64_backend"], default-features = false } merlin = { version = "2.0", default-features = false } -secp256k1 = { version = "0.24.0", default-features = false, features = ["recovery", "alloc"], optional = true } -sp-core-hashing = { path = "hashing", default-features = false, optional = true } +secp256k1 = { version = "0.24.0", default-features = false, features = ["recovery", "alloc"] } +sp-core-hashing = { path = "hashing", default-features = false } sp-runtime-interface = { path = "../runtime-interface", default-features = false} # bls crypto @@ -74,7 +74,6 @@ bench = false [features] default = [ "std" ] std = [ - "array-bytes", "bandersnatch_vrfs/getrandom", "blake2/std", "bounded-collections/std", @@ -117,7 +116,6 @@ std = [ # Serde support without relying on std features. serde = [ - "array-bytes", "blake2", "bounded-collections/serde", "bs58/alloc", @@ -125,7 +123,6 @@ serde = [ "impl-serde", "primitive-types/serde_no_std", "scale-info/serde", - "sp-core-hashing", "sp-storage/serde", ] @@ -133,12 +130,8 @@ serde = [ # or Intel SGX. # For the regular wasm runtime builds this should not be used. full_crypto = [ - "array-bytes", "blake2", - "ed25519-zebra", "libsecp256k1", - "secp256k1", - "sp-core-hashing", "sp-runtime-interface/disable_target_static_assertions", ] @@ -151,3 +144,6 @@ bls-experimental = [ "w3f-bls" ] # It should not be used in production since the implementation and interface may still # be subject to significant changes. bandersnatch-experimental = [ "bandersnatch_vrfs" ] + +#todo: remove this: +compile = [ "sp-runtime-interface/disable_target_static_assertions" ] diff --git a/substrate/primitives/core/src/crypto.rs b/substrate/primitives/core/src/crypto.rs index 782c947c0103..b08f41e521b7 100644 --- a/substrate/primitives/core/src/crypto.rs +++ b/substrate/primitives/core/src/crypto.rs @@ -20,7 +20,6 @@ use crate::{ed25519, sr25519}; #[cfg(feature = "std")] use bip39::MnemonicType; -#[cfg(feature = "full_crypto")] use bip39::{Language, Mnemonic}; use codec::{Decode, Encode, MaxEncodedLen}; #[cfg(feature = "std")] @@ -101,7 +100,6 @@ pub enum SecretStringError { /// An error when deriving a key. #[cfg_attr(feature = "std", derive(thiserror::Error))] #[derive(Debug, Clone, PartialEq, Eq)] -#[cfg(feature = "full_crypto")] pub enum DeriveError { /// A soft key was found in the path (and is unsupported). #[cfg_attr(feature = "std", error("Soft key in path"))] @@ -112,7 +110,6 @@ pub enum DeriveError { /// a new secret key from an existing secret key and, in the case of `SoftRaw` and `SoftIndex` /// a new public key from an existing public key. #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug, Encode, Decode)] -#[cfg(any(feature = "full_crypto", feature = "serde"))] pub enum DeriveJunction { /// Soft (vanilla) derivation. Public keys have a correspondent derivation. Soft([u8; JUNCTION_ID_LEN]), @@ -120,7 +117,6 @@ pub enum DeriveJunction { Hard([u8; JUNCTION_ID_LEN]), } -#[cfg(any(feature = "full_crypto", feature = "serde"))] impl DeriveJunction { /// Consume self to return a soft derive junction with the same chain code. pub fn soften(self) -> Self { @@ -179,7 +175,6 @@ impl DeriveJunction { } } -#[cfg(any(feature = "full_crypto", feature = "serde"))] impl> From for DeriveJunction { fn from(j: T) -> DeriveJunction { let j = j.as_ref(); @@ -796,7 +791,6 @@ mod dummy { /// assert_eq!("0xe5be9a5092b81bca64be81d212e7f2f9eba183bb7a90954f7b76361f6edb5c0a", suri.phrase.expose_secret()); /// assert!(suri.password.is_none()); /// ``` -#[cfg(feature = "full_crypto")] pub struct SecretUri { /// The phrase to derive the private key. /// @@ -808,7 +802,6 @@ pub struct SecretUri { pub junctions: Vec, } -#[cfg(feature = "full_crypto")] impl sp_std::str::FromStr for SecretUri { type Err = SecretStringError; @@ -836,7 +829,6 @@ impl sp_std::str::FromStr for SecretUri { /// Trait suitable for typical cryptographic PKI key pair type. /// /// For now it just specifies how to create a key from a phrase and derivation path. -#[cfg(feature = "full_crypto")] pub trait Pair: CryptoType + Sized { /// The type which is used to encode a public key. type Public: Public + Hash; @@ -916,9 +908,11 @@ pub trait Pair: CryptoType + Sized { fn from_seed_slice(seed: &[u8]) -> Result; /// Sign a message. + #[cfg(feature = "full_crypto")] fn sign(&self, message: &[u8]) -> Self::Signature; /// Verify a signature on a message. Returns true if the signature is good. + #[cfg(feature = "full_crypto")] fn verify>(sig: &Self::Signature, message: M, pubkey: &Self::Public) -> bool; /// Get the public key. @@ -1041,7 +1035,6 @@ where /// Type which has a particular kind of crypto associated with it. pub trait CryptoType { /// The pair key type of this crypto. - #[cfg(feature = "full_crypto")] type Pair: Pair; } diff --git a/substrate/primitives/core/src/ecdsa.rs b/substrate/primitives/core/src/ecdsa.rs index 05bc679386c3..fad81ff3b4dc 100644 --- a/substrate/primitives/core/src/ecdsa.rs +++ b/substrate/primitives/core/src/ecdsa.rs @@ -24,27 +24,25 @@ use sp_runtime_interface::pass_by::PassByInner; #[cfg(feature = "serde")] use crate::crypto::Ss58Codec; use crate::crypto::{ - ByteArray, CryptoType, CryptoTypeId, Derive, Public as TraitPublic, UncheckedFrom, + ByteArray, CryptoType, CryptoTypeId, Derive, DeriveError, DeriveJunction, Pair as TraitPair, + Public as TraitPublic, SecretStringError, UncheckedFrom, }; #[cfg(feature = "full_crypto")] -use crate::{ - crypto::{DeriveError, DeriveJunction, Pair as TraitPair, SecretStringError}, - hashing::blake2_256, -}; -#[cfg(all(feature = "full_crypto", not(feature = "std")))] +use crate::hashing::blake2_256; +#[cfg(feature = "full_crypto")] +use secp256k1::ecdsa::{RecoverableSignature, RecoveryId}; +#[cfg(feature = "full_crypto")] +use secp256k1::Message; +#[cfg(not(feature = "std"))] use secp256k1::Secp256k1; #[cfg(feature = "std")] use secp256k1::SECP256K1; -#[cfg(feature = "full_crypto")] -use secp256k1::{ - ecdsa::{RecoverableSignature, RecoveryId}, - Message, PublicKey, SecretKey, -}; +use secp256k1::{PublicKey, SecretKey}; #[cfg(feature = "serde")] use serde::{de, Deserialize, Deserializer, Serialize, Serializer}; #[cfg(all(not(feature = "std"), feature = "serde"))] use sp_std::alloc::{format, string::String}; -#[cfg(feature = "full_crypto")] +#[cfg(not(feature = "std"))] use sp_std::vec::Vec; /// An identifier used to match public keys against ecdsa keys @@ -53,11 +51,9 @@ pub const CRYPTO_ID: CryptoTypeId = CryptoTypeId(*b"ecds"); /// A secret seed (which is bytewise essentially equivalent to a SecretKey). /// /// We need it as a different type because `Seed` is expected to be AsRef<[u8]>. -#[cfg(feature = "full_crypto")] type Seed = [u8; 32]; /// The ECDSA compressed public key. -#[cfg_attr(feature = "full_crypto", derive(Hash))] #[derive( Clone, Copy, @@ -70,6 +66,7 @@ type Seed = [u8; 32]; PartialEq, PartialOrd, Ord, + Hash, )] pub struct Public(pub [u8; 33]); @@ -196,8 +193,7 @@ impl<'de> Deserialize<'de> for Public { } /// A signature (a 512-bit value, plus 8 bits for recovery ID). -#[cfg_attr(feature = "full_crypto", derive(Hash))] -#[derive(Encode, Decode, MaxEncodedLen, PassByInner, TypeInfo, PartialEq, Eq)] +#[derive(Hash, Encode, Decode, MaxEncodedLen, PassByInner, TypeInfo, PartialEq, Eq)] pub struct Signature(pub [u8; 65]); impl TryFrom<&[u8]> for Signature { @@ -353,20 +349,17 @@ impl From for Signature { } /// Derive a single hard junction. -#[cfg(feature = "full_crypto")] fn derive_hard_junction(secret_seed: &Seed, cc: &[u8; 32]) -> Seed { ("Secp256k1HDKD", secret_seed, cc).using_encoded(sp_core_hashing::blake2_256) } /// A key pair. -#[cfg(feature = "full_crypto")] #[derive(Clone)] pub struct Pair { public: Public, secret: SecretKey, } -#[cfg(feature = "full_crypto")] impl TraitPair for Pair { type Public = Public; type Seed = Seed; @@ -412,11 +405,13 @@ impl TraitPair for Pair { } /// Sign a message. + #[cfg(feature = "full_crypto")] fn sign(&self, message: &[u8]) -> Signature { self.sign_prehashed(&blake2_256(message)) } /// Verify a signature on a message. Returns true if the signature is good. + #[cfg(feature = "full_crypto")] fn verify>(sig: &Signature, message: M, public: &Public) -> bool { sig.recover(message).map(|actual| actual == *public).unwrap_or_default() } @@ -427,7 +422,6 @@ impl TraitPair for Pair { } } -#[cfg(feature = "full_crypto")] impl Pair { /// Get the seed for this key. pub fn seed(&self) -> Seed { @@ -447,6 +441,7 @@ impl Pair { } /// Sign a pre-hashed message + #[cfg(feature = "full_crypto")] pub fn sign_prehashed(&self, message: &[u8; 32]) -> Signature { let message = Message::from_slice(message).expect("Message is 32 bytes; qed"); @@ -460,6 +455,7 @@ impl Pair { /// Verify a signature on a pre-hashed message. Return `true` if the signature is valid /// and thus matches the given `public` key. + #[cfg(feature = "full_crypto")] pub fn verify_prehashed(sig: &Signature, message: &[u8; 32], public: &Public) -> bool { match sig.recover_prehashed(message) { Some(actual) => actual == *public, @@ -470,6 +466,7 @@ impl Pair { /// Verify a signature on a message. Returns true if the signature is good. /// Parses Signature using parse_overflowing_slice. #[deprecated(note = "please use `verify` instead")] + #[cfg(feature = "full_crypto")] pub fn verify_deprecated>(sig: &Signature, message: M, pubkey: &Public) -> bool { let message = libsecp256k1::Message::parse(&blake2_256(message.as_ref())); @@ -508,16 +505,13 @@ impl Drop for Pair { } impl CryptoType for Public { - #[cfg(feature = "full_crypto")] type Pair = Pair; } impl CryptoType for Signature { - #[cfg(feature = "full_crypto")] type Pair = Pair; } -#[cfg(feature = "full_crypto")] impl CryptoType for Pair { type Pair = Pair; } diff --git a/substrate/primitives/core/src/ed25519.rs b/substrate/primitives/core/src/ed25519.rs index 151a7229315e..24844c4592bf 100644 --- a/substrate/primitives/core/src/ed25519.rs +++ b/substrate/primitives/core/src/ed25519.rs @@ -19,7 +19,6 @@ //! Simple Ed25519 API. // end::description[] -#[cfg(feature = "full_crypto")] use sp_std::vec::Vec; use crate::{ @@ -32,13 +31,11 @@ use scale_info::TypeInfo; #[cfg(feature = "serde")] use crate::crypto::Ss58Codec; use crate::crypto::{ - CryptoType, CryptoTypeId, Derive, FromEntropy, Public as TraitPublic, UncheckedFrom, + CryptoType, CryptoTypeId, Derive, DeriveError, DeriveJunction, FromEntropy, Pair as TraitPair, + Public as TraitPublic, SecretStringError, UncheckedFrom, }; #[cfg(feature = "full_crypto")] -use crate::crypto::{DeriveError, DeriveJunction, Pair as TraitPair, SecretStringError}; -#[cfg(feature = "full_crypto")] use core::convert::TryFrom; -#[cfg(feature = "full_crypto")] use ed25519_zebra::{SigningKey, VerificationKey}; #[cfg(feature = "serde")] use serde::{de, Deserialize, Deserializer, Serialize, Serializer}; @@ -53,11 +50,9 @@ pub const CRYPTO_ID: CryptoTypeId = CryptoTypeId(*b"ed25"); /// A secret seed. It's not called a "secret key" because ring doesn't expose the secret keys /// of the key pair (yeah, dumb); as such we're forced to remember the seed manually if we /// will need it later (such as for HDKD). -#[cfg(feature = "full_crypto")] type Seed = [u8; 32]; /// A public key. -#[cfg_attr(feature = "full_crypto", derive(Hash))] #[derive( PartialEq, Eq, @@ -70,11 +65,11 @@ type Seed = [u8; 32]; PassByInner, MaxEncodedLen, TypeInfo, + Hash, )] pub struct Public(pub [u8; 32]); /// A key pair. -#[cfg(feature = "full_crypto")] #[derive(Copy, Clone)] pub struct Pair { public: VerificationKey, @@ -210,8 +205,7 @@ impl<'de> Deserialize<'de> for Public { } /// A signature (a 512-bit value). -#[cfg_attr(feature = "full_crypto", derive(Hash))] -#[derive(Encode, Decode, MaxEncodedLen, PassByInner, TypeInfo, PartialEq, Eq)] +#[derive(Encode, Decode, MaxEncodedLen, PassByInner, TypeInfo, PartialEq, Eq, Hash)] pub struct Signature(pub [u8; 64]); impl TryFrom<&[u8]> for Signature { @@ -370,12 +364,10 @@ impl TraitPublic for Public {} impl Derive for Public {} /// Derive a single hard junction. -#[cfg(feature = "full_crypto")] fn derive_hard_junction(secret_seed: &Seed, cc: &[u8; 32]) -> Seed { ("Ed25519HDKD", secret_seed, cc).using_encoded(sp_core_hashing::blake2_256) } -#[cfg(feature = "full_crypto")] impl TraitPair for Pair { type Public = Public; type Seed = Seed; @@ -414,6 +406,7 @@ impl TraitPair for Pair { } /// Sign a message. + #[cfg(feature = "full_crypto")] fn sign(&self, message: &[u8]) -> Signature { Signature::from_raw(self.secret.sign(message).into()) } @@ -421,6 +414,7 @@ impl TraitPair for Pair { /// Verify a signature on a message. /// /// Returns true if the signature is good. + #[cfg(feature = "full_crypto")] fn verify>(sig: &Signature, message: M, public: &Public) -> bool { let Ok(public) = VerificationKey::try_from(public.as_slice()) else { return false }; let Ok(signature) = ed25519_zebra::Signature::try_from(sig.as_ref()) else { return false }; @@ -433,7 +427,6 @@ impl TraitPair for Pair { } } -#[cfg(feature = "full_crypto")] impl Pair { /// Get the seed for this key. pub fn seed(&self) -> Seed { @@ -454,16 +447,13 @@ impl Pair { } impl CryptoType for Public { - #[cfg(feature = "full_crypto")] type Pair = Pair; } impl CryptoType for Signature { - #[cfg(feature = "full_crypto")] type Pair = Pair; } -#[cfg(feature = "full_crypto")] impl CryptoType for Pair { type Pair = Pair; } diff --git a/substrate/primitives/core/src/lib.rs b/substrate/primitives/core/src/lib.rs index 3a0e1f33f16c..e1cc017a9c15 100644 --- a/substrate/primitives/core/src/lib.rs +++ b/substrate/primitives/core/src/lib.rs @@ -46,7 +46,6 @@ pub use sp_debug_derive::RuntimeDebug; #[cfg(feature = "serde")] pub use impl_serde::serialize as bytes; -#[cfg(feature = "full_crypto")] pub mod hashing; #[cfg(feature = "full_crypto")] @@ -79,7 +78,6 @@ pub use self::{ hash::{convert_hash, H160, H256, H512}, uint::{U256, U512}, }; -#[cfg(feature = "full_crypto")] pub use crypto::{ByteArray, DeriveJunction, Pair, Public}; #[cfg(feature = "std")] diff --git a/substrate/primitives/core/src/sr25519.rs b/substrate/primitives/core/src/sr25519.rs index ffa52ef97d1f..bb345dcbb899 100644 --- a/substrate/primitives/core/src/sr25519.rs +++ b/substrate/primitives/core/src/sr25519.rs @@ -19,20 +19,16 @@ //! //! Note: `CHAIN_CODE_LENGTH` must be equal to `crate::crypto::JUNCTION_ID_LEN` //! for this to work. -#[cfg(any(feature = "full_crypto", feature = "serde"))] -use crate::crypto::DeriveJunction; #[cfg(feature = "serde")] use crate::crypto::Ss58Codec; +use crate::crypto::{DeriveError, DeriveJunction, Pair as TraitPair, SecretStringError}; #[cfg(feature = "full_crypto")] -use crate::crypto::{DeriveError, Pair as TraitPair, SecretStringError}; -#[cfg(feature = "full_crypto")] -use schnorrkel::{ - derive::CHAIN_CODE_LENGTH, signing_context, ExpansionMode, Keypair, MiniSecretKey, SecretKey, -}; -#[cfg(any(feature = "full_crypto", feature = "serde"))] +use schnorrkel::signing_context; +#[cfg(any(feature = "serde", feature = "full_crypto"))] +use schnorrkel::PublicKey; use schnorrkel::{ - derive::{ChainCode, Derivation}, - PublicKey, + derive::{ChainCode, Derivation, CHAIN_CODE_LENGTH}, + ExpansionMode, Keypair, MiniSecretKey, SecretKey, }; use sp_std::vec::Vec; @@ -47,7 +43,6 @@ use codec::{Decode, Encode, MaxEncodedLen}; use scale_info::TypeInfo; use sp_std::ops::Deref; -#[cfg(feature = "full_crypto")] use schnorrkel::keys::{MINI_SECRET_KEY_LENGTH, SECRET_KEY_LENGTH}; #[cfg(feature = "serde")] use serde::{de, Deserialize, Deserializer, Serialize, Serializer}; @@ -63,7 +58,6 @@ const SIGNING_CTX: &[u8] = b"substrate"; pub const CRYPTO_ID: CryptoTypeId = CryptoTypeId(*b"sr25"); /// An Schnorrkel/Ristretto x25519 ("sr25519") public key. -#[cfg_attr(feature = "full_crypto", derive(Hash))] #[derive( PartialEq, Eq, @@ -76,14 +70,13 @@ pub const CRYPTO_ID: CryptoTypeId = CryptoTypeId(*b"sr25"); PassByInner, MaxEncodedLen, TypeInfo, + Hash, )] pub struct Public(pub [u8; 32]); /// An Schnorrkel/Ristretto x25519 ("sr25519") key pair. -#[cfg(feature = "full_crypto")] pub struct Pair(Keypair); -#[cfg(feature = "full_crypto")] impl Clone for Pair { fn clone(&self) -> Self { Pair(schnorrkel::Keypair { @@ -216,8 +209,7 @@ impl<'de> Deserialize<'de> for Public { } /// An Schnorrkel/Ristretto x25519 ("sr25519") signature. -#[cfg_attr(feature = "full_crypto", derive(Hash))] -#[derive(Encode, Decode, MaxEncodedLen, PassByInner, TypeInfo, PartialEq, Eq)] +#[derive(Encode, Decode, MaxEncodedLen, PassByInner, TypeInfo, PartialEq, Eq, Hash)] pub struct Signature(pub [u8; 64]); impl TryFrom<&[u8]> for Signature { @@ -435,16 +427,13 @@ impl AsRef for Pair { } /// Derive a single hard junction. -#[cfg(feature = "full_crypto")] fn derive_hard_junction(secret: &SecretKey, cc: &[u8; CHAIN_CODE_LENGTH]) -> MiniSecretKey { secret.hard_derive_mini_secret_key(Some(ChainCode(*cc)), b"").0 } /// The raw secret seed, which can be used to recreate the `Pair`. -#[cfg(feature = "full_crypto")] type Seed = [u8; MINI_SECRET_KEY_LENGTH]; -#[cfg(feature = "full_crypto")] impl TraitPair for Pair { type Public = Public; type Seed = Seed; @@ -499,11 +488,13 @@ impl TraitPair for Pair { Ok((Self(result.into()), seed.map(|s| MiniSecretKey::to_bytes(&s)))) } + #[cfg(feature = "full_crypto")] fn sign(&self, message: &[u8]) -> Signature { let context = signing_context(SIGNING_CTX); self.0.sign(context.bytes(message)).into() } + #[cfg(feature = "full_crypto")] fn verify>(sig: &Signature, message: M, pubkey: &Public) -> bool { let Ok(signature) = schnorrkel::Signature::from_bytes(sig.as_ref()) else { return false }; let Ok(public) = PublicKey::from_bytes(pubkey.as_ref()) else { return false }; @@ -533,16 +524,13 @@ impl Pair { } impl CryptoType for Public { - #[cfg(feature = "full_crypto")] type Pair = Pair; } impl CryptoType for Signature { - #[cfg(feature = "full_crypto")] type Pair = Pair; } -#[cfg(feature = "full_crypto")] impl CryptoType for Pair { type Pair = Pair; } From d6f15306282e3de848a09c9aa9cba6f95a7811f0 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Thu, 26 Oct 2023 15:35:43 +0200 Subject: [PATCH 06/52] wip: application-crypto 2 --- .../primitives/application-crypto/Cargo.toml | 6 ++ .../application-crypto/src/ecdsa.rs | 4 +- .../application-crypto/src/ed25519.rs | 4 +- .../primitives/application-crypto/src/lib.rs | 85 +++++++++++++++++-- .../application-crypto/src/sr25519.rs | 4 +- .../application-crypto/src/traits.rs | 14 +-- 6 files changed, 88 insertions(+), 29 deletions(-) diff --git a/substrate/primitives/application-crypto/Cargo.toml b/substrate/primitives/application-crypto/Cargo.toml index 7c5e31730779..69ba2a19c657 100644 --- a/substrate/primitives/application-crypto/Cargo.toml +++ b/substrate/primitives/application-crypto/Cargo.toml @@ -22,6 +22,9 @@ serde = { version = "1.0.188", default-features = false, optional = true, featur sp-std = { path = "../std", default-features = false} sp-io = { path = "../io", default-features = false} +#todo: remove this: +sp-runtime-interface = { path = "../runtime-interface", default-features = false, optional = true } + [features] default = [ "std" ] std = [ @@ -34,6 +37,9 @@ std = [ "sp-std/std", ] +#todo: remove this: +compile = [ "sp-io/disable_panic_handler", "sp-runtime-interface/disable_target_static_assertions" ] + # Serde support without relying on std features. serde = [ "dep:serde", "scale-info/serde", "sp-core/serde" ] diff --git a/substrate/primitives/application-crypto/src/ecdsa.rs b/substrate/primitives/application-crypto/src/ecdsa.rs index 27ffe12579f5..439b51dc6045 100644 --- a/substrate/primitives/application-crypto/src/ecdsa.rs +++ b/substrate/primitives/application-crypto/src/ecdsa.rs @@ -27,9 +27,7 @@ mod app { crate::app_crypto!(super, sp_core::testing::ECDSA); } -#[cfg(feature = "full_crypto")] -pub use app::Pair as AppPair; -pub use app::{Public as AppPublic, Signature as AppSignature}; +pub use app::{Pair as AppPair, Public as AppPublic, Signature as AppSignature}; impl RuntimePublic for Public { type Signature = Signature; diff --git a/substrate/primitives/application-crypto/src/ed25519.rs b/substrate/primitives/application-crypto/src/ed25519.rs index bc05018370ed..addefe7daf64 100644 --- a/substrate/primitives/application-crypto/src/ed25519.rs +++ b/substrate/primitives/application-crypto/src/ed25519.rs @@ -27,9 +27,7 @@ mod app { crate::app_crypto!(super, sp_core::testing::ED25519); } -#[cfg(feature = "full_crypto")] -pub use app::Pair as AppPair; -pub use app::{Public as AppPublic, Signature as AppSignature}; +pub use app::{Pair as AppPair, Public as AppPublic, Signature as AppSignature}; impl RuntimePublic for Public { type Signature = Signature; diff --git a/substrate/primitives/application-crypto/src/lib.rs b/substrate/primitives/application-crypto/src/lib.rs index 5384220bc9ca..6388ac4befdc 100644 --- a/substrate/primitives/application-crypto/src/lib.rs +++ b/substrate/primitives/application-crypto/src/lib.rs @@ -20,12 +20,9 @@ #![warn(missing_docs)] #![cfg_attr(not(feature = "std"), no_std)] -pub use sp_core::crypto::{key_types, CryptoTypeId, KeyTypeId}; +pub use sp_core::crypto::{key_types, CryptoTypeId, DeriveJunction, KeyTypeId, Ss58Codec}; #[doc(hidden)] -#[cfg(feature = "full_crypto")] pub use sp_core::crypto::{DeriveError, Pair, SecretStringError}; -#[cfg(any(feature = "full_crypto", feature = "serde"))] -pub use sp_core::crypto::{DeriveJunction, Ss58Codec}; #[doc(hidden)] pub use sp_core::{ self, @@ -114,6 +111,7 @@ macro_rules! app_crypto { $module::CRYPTO_ID ); $crate::app_crypto_signature_common!($module::Signature, $key_type); + $crate::app_crypto_pair_not_full_crypto!($module::Pair, $key_type, $module::CRYPTO_ID); }; } @@ -191,6 +189,72 @@ macro_rules! app_crypto_pair { }; } +/// Declares `Pair` type which is functionally equivalent to `$pair`, but is +/// new application-specific type whose identifier is `$key_type`. +/// Can only be used without `full_crypto` feature. +/// `verify` and `sign` methods are not implemented. +#[macro_export] +macro_rules! app_crypto_pair_not_full_crypto { + ($pair:ty, $key_type:expr, $crypto_type:expr) => { + $crate::wrap! { + /// A generic `AppPublic` wrapper type over $pair crypto; this has no specific App. + #[derive(Clone)] + pub struct Pair($pair); + } + + impl $crate::CryptoType for Pair { + type Pair = Pair; + } + + impl $crate::Pair for Pair { + type Public = Public; + type Seed = <$pair as $crate::Pair>::Seed; + type Signature = Signature; + + $crate::app_crypto_pair_functions_if_std!($pair); + + fn derive>( + &self, + path: Iter, + seed: Option, + ) -> Result<(Self, Option), $crate::DeriveError> { + self.0.derive(path, seed).map(|x| (Self(x.0), x.1)) + } + fn from_seed(seed: &Self::Seed) -> Self { + Self(<$pair>::from_seed(seed)) + } + fn from_seed_slice(seed: &[u8]) -> Result { + <$pair>::from_seed_slice(seed).map(Self) + } + fn public(&self) -> Self::Public { + Public(self.0.public()) + } + fn to_raw_vec(&self) -> $crate::Vec { + self.0.to_raw_vec() + } + } + + impl $crate::AppCrypto for Pair { + type Public = Public; + type Pair = Pair; + type Signature = Signature; + const ID: $crate::KeyTypeId = $key_type; + const CRYPTO_ID: $crate::CryptoTypeId = $crypto_type; + } + + impl $crate::AppPair for Pair { + type Generic = $pair; + } + + impl Pair { + /// Convert into wrapped generic key pair type. + pub fn into_inner(self) -> $pair { + self.0 + } + } + }; +} + /// Implements functions for the `Pair` trait when `feature = "std"` is enabled. #[doc(hidden)] #[cfg(feature = "std")] @@ -265,7 +329,7 @@ macro_rules! app_crypto_public_not_full_crypto { $crate::wrap! { /// A generic `AppPublic` wrapper type over $public crypto; this has no specific App. #[derive( - Clone, Eq, PartialEq, Ord, PartialOrd, + Clone, Eq, Hash, PartialEq, Ord, PartialOrd, $crate::codec::Encode, $crate::codec::Decode, $crate::RuntimeDebug, @@ -275,10 +339,13 @@ macro_rules! app_crypto_public_not_full_crypto { pub struct Public($public); } - impl $crate::CryptoType for Public {} + impl $crate::CryptoType for Public { + type Pair = Pair; + } impl $crate::AppCrypto for Public { type Public = Public; + type Pair = Pair; type Signature = Signature; const ID: $crate::KeyTypeId = $key_type; const CRYPTO_ID: $crate::CryptoTypeId = $crypto_type; @@ -447,13 +514,17 @@ macro_rules! app_crypto_signature_not_full_crypto { $crate::RuntimeDebug, $crate::scale_info::TypeInfo, )] + #[derive(Hash)] pub struct Signature($sig); } - impl $crate::CryptoType for Signature {} + impl $crate::CryptoType for Signature { + type Pair = Pair; + } impl $crate::AppCrypto for Signature { type Public = Public; + type Pair = Pair; type Signature = Signature; const ID: $crate::KeyTypeId = $key_type; const CRYPTO_ID: $crate::CryptoTypeId = $crypto_type; diff --git a/substrate/primitives/application-crypto/src/sr25519.rs b/substrate/primitives/application-crypto/src/sr25519.rs index 7c91bfa7bb5f..d411cc253c0d 100644 --- a/substrate/primitives/application-crypto/src/sr25519.rs +++ b/substrate/primitives/application-crypto/src/sr25519.rs @@ -27,9 +27,7 @@ mod app { crate::app_crypto!(super, sp_core::testing::SR25519); } -#[cfg(feature = "full_crypto")] -pub use app::Pair as AppPair; -pub use app::{Public as AppPublic, Signature as AppSignature}; +pub use app::{Pair as AppPair, Public as AppPublic, Signature as AppSignature}; impl RuntimePublic for Public { type Signature = Signature; diff --git a/substrate/primitives/application-crypto/src/traits.rs b/substrate/primitives/application-crypto/src/traits.rs index e9b1080f63d9..0b59abf272dc 100644 --- a/substrate/primitives/application-crypto/src/traits.rs +++ b/substrate/primitives/application-crypto/src/traits.rs @@ -18,9 +18,7 @@ use codec::Codec; use scale_info::TypeInfo; -#[cfg(feature = "full_crypto")] -use sp_core::crypto::Pair; -use sp_core::crypto::{CryptoType, CryptoTypeId, IsWrappedBy, KeyTypeId, Public}; +use sp_core::crypto::{CryptoType, CryptoTypeId, IsWrappedBy, KeyTypeId, Pair, Public}; use sp_std::{fmt::Debug, vec::Vec}; /// Application-specific cryptographic object. @@ -45,24 +43,14 @@ pub trait AppCrypto: 'static + Sized + CryptoType { type Signature: AppSignature; /// The corresponding key pair type in this application scheme. - #[cfg(feature = "full_crypto")] type Pair: AppPair; } /// Type which implements Hash in std, not when no-std (std variant). -#[cfg(any(feature = "std", feature = "full_crypto"))] pub trait MaybeHash: sp_std::hash::Hash {} -#[cfg(any(feature = "std", feature = "full_crypto"))] impl MaybeHash for T {} -/// Type which implements Hash in std, not when no-std (no-std variant). -#[cfg(all(not(feature = "std"), not(feature = "full_crypto")))] -pub trait MaybeHash {} -#[cfg(all(not(feature = "std"), not(feature = "full_crypto")))] -impl MaybeHash for T {} - /// Application-specific key pair. -#[cfg(feature = "full_crypto")] pub trait AppPair: AppCrypto + Pair::Public, Signature = ::Signature> { From 0cbfefb3ce0319755d86583b95a4d4c34a6ab4b0 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Fri, 27 Oct 2023 19:18:24 +0200 Subject: [PATCH 07/52] fixes --- Cargo.lock | 93 ++++++++++++++----- substrate/frame/support/procedural/Cargo.toml | 4 +- .../frame/support/procedural/tools/Cargo.toml | 2 +- substrate/primitives/api/Cargo.toml | 2 +- substrate/primitives/core/Cargo.toml | 5 +- substrate/test-utils/runtime/Cargo.toml | 6 +- 6 files changed, 78 insertions(+), 34 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 48ac004a8597..d2a862fe4924 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3524,7 +3524,7 @@ dependencies = [ name = "cumulus-pallet-parachain-system-proc-macro" version = "0.1.0" dependencies = [ - "proc-macro-crate", + "proc-macro-crate 1.3.1", "proc-macro2", "quote", "syn 2.0.38", @@ -4863,7 +4863,7 @@ checksum = "f5aa1e3ae159e592ad222dc90c5acbad632b527779ba88486abe92782ab268bd" dependencies = [ "expander 0.0.4", "indexmap 1.9.3", - "proc-macro-crate", + "proc-macro-crate 1.3.1", "proc-macro2", "quote", "syn 1.0.109", @@ -5156,7 +5156,7 @@ dependencies = [ "frame-election-provider-support", "frame-support", "parity-scale-codec", - "proc-macro-crate", + "proc-macro-crate 1.3.1", "proc-macro2", "quote", "scale-info", @@ -5322,7 +5322,7 @@ name = "frame-support-procedural-tools" version = "4.0.0-dev" dependencies = [ "frame-support-procedural-tools-derive", - "proc-macro-crate", + "proc-macro-crate 2.0.0", "proc-macro2", "quote", "syn 2.0.38", @@ -6576,7 +6576,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "44e8ab85614a08792b9bff6c8feee23be78c98d0182d4c622c05256ab553892a" dependencies = [ "heck", - "proc-macro-crate", + "proc-macro-crate 1.3.1", "proc-macro2", "quote", "syn 1.0.109", @@ -6844,6 +6844,9 @@ name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +dependencies = [ + "spin 0.5.2", +] [[package]] name = "lazycell" @@ -7898,7 +7901,7 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc076939022111618a5026d3be019fd8b366e76314538ff9a1b59ffbcbf98bcd" dependencies = [ - "proc-macro-crate", + "proc-macro-crate 1.3.1", "proc-macro-error", "proc-macro2", "quote", @@ -8357,7 +8360,7 @@ dependencies = [ "itertools 0.10.5", "tar", "tempfile", - "toml_edit", + "toml_edit 0.19.14", ] [[package]] @@ -8670,7 +8673,7 @@ dependencies = [ "itertools 0.11.0", "layout-rs", "petgraph", - "proc-macro-crate", + "proc-macro-crate 1.3.1", "proc-macro2", "quote", "syn 1.0.109", @@ -10369,7 +10372,7 @@ dependencies = [ name = "pallet-staking-reward-curve" version = "4.0.0-dev" dependencies = [ - "proc-macro-crate", + "proc-macro-crate 1.3.1", "proc-macro2", "quote", "sp-runtime", @@ -10981,7 +10984,7 @@ version = "3.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a296c3079b5fefbc499e1de58dc26c09b1b9a5952d26694ee89f04a43ebbb3e" dependencies = [ - "proc-macro-crate", + "proc-macro-crate 1.3.1", "proc-macro2", "quote", "syn 1.0.109", @@ -13168,7 +13171,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919" dependencies = [ "once_cell", - "toml_edit", + "toml_edit 0.19.14", +] + +[[package]] +name = "proc-macro-crate" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e8366a6159044a37876a2b9817124296703c586a5c92e2c53751fa06d8d43e8" +dependencies = [ + "toml_edit 0.20.5", ] [[package]] @@ -14410,7 +14422,7 @@ dependencies = [ name = "sc-chain-spec-derive" version = "4.0.0-dev" dependencies = [ - "proc-macro-crate", + "proc-macro-crate 1.3.1", "proc-macro2", "quote", "syn 2.0.38", @@ -14453,7 +14465,7 @@ dependencies = [ "sp-version", "tempfile", "thiserror", - "tiny-bip39", + "tiny-bip39 1.0.0", "tokio", ] @@ -15622,7 +15634,7 @@ dependencies = [ name = "sc-tracing-proc-macro" version = "4.0.0-dev" dependencies = [ - "proc-macro-crate", + "proc-macro-crate 1.3.1", "proc-macro2", "quote", "syn 2.0.38", @@ -15712,7 +15724,7 @@ version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "912e55f6d20e0e80d63733872b40e1227c0bce1e1ab81ba67d696339bfd7fd29" dependencies = [ - "proc-macro-crate", + "proc-macro-crate 1.3.1", "proc-macro2", "quote", "syn 1.0.109", @@ -16481,7 +16493,7 @@ dependencies = [ "assert_matches", "blake2", "expander 2.0.0", - "proc-macro-crate", + "proc-macro-crate 1.3.1", "proc-macro2", "quote", "syn 2.0.38", @@ -16519,6 +16531,7 @@ dependencies = [ "serde", "sp-core", "sp-io", + "sp-runtime-interface", "sp-std", ] @@ -16860,7 +16873,7 @@ dependencies = [ "ss58-registry", "substrate-bip39", "thiserror", - "tiny-bip39", + "tiny-bip39 1.0.1", "tracing", "w3f-bls", "zeroize", @@ -16994,7 +17007,10 @@ version = "24.0.0" dependencies = [ "lazy_static", "sp-core", + "sp-io", "sp-runtime", + "sp-runtime-interface", + "sp-std", "strum", ] @@ -17156,7 +17172,7 @@ name = "sp-runtime-interface-proc-macro" version = "11.0.0" dependencies = [ "Inflector", - "proc-macro-crate", + "proc-macro-crate 1.3.1", "proc-macro2", "quote", "syn 2.0.38", @@ -17695,9 +17711,8 @@ dependencies = [ [[package]] name = "substrate-bip39" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49eee6965196b32f882dd2ee85a92b1dbead41b04e53907f269de3b0dc04733c" +version = "0.4.5" +source = "git+https://github.com/paritytech/substrate-bip39?branch=mku-support-for-no-std#b0ccbf720a0d6bdeea03c2e946ab186cef696fcb" dependencies = [ "hmac 0.11.0", "pbkdf2 0.8.0", @@ -18446,6 +18461,23 @@ dependencies = [ "zeroize", ] +[[package]] +name = "tiny-bip39" +version = "1.0.1" +source = "git+https://github.com/michalkucharczyk/tiny-bip39/?branch=mku-nodefaults-for-sha2#ca2eac6fb41bd9b017a47d81151c7451e31fc77b" +dependencies = [ + "anyhow", + "hmac 0.12.1", + "lazy_static", + "pbkdf2 0.11.0", + "rand 0.8.5", + "rustc-hash", + "sha2 0.10.7", + "unicode-normalization", + "wasm-bindgen", + "zeroize", +] + [[package]] name = "tiny-keccak" version = "2.0.2" @@ -18601,14 +18633,14 @@ dependencies = [ "serde", "serde_spanned", "toml_datetime", - "toml_edit", + "toml_edit 0.19.14", ] [[package]] name = "toml_datetime" -version = "0.6.3" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" +checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" dependencies = [ "serde", ] @@ -18626,6 +18658,17 @@ dependencies = [ "winnow", ] +[[package]] +name = "toml_edit" +version = "0.20.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "782bf6c2ddf761c1e7855405e8975472acf76f7f36d0d4328bd3b7a2fae12a85" +dependencies = [ + "indexmap 2.0.0", + "toml_datetime", + "winnow", +] + [[package]] name = "tower" version = "0.4.13" @@ -18728,7 +18771,7 @@ version = "1.0.0" dependencies = [ "assert_matches", "expander 2.0.0", - "proc-macro-crate", + "proc-macro-crate 1.3.1", "proc-macro2", "quote", "syn 2.0.38", diff --git a/substrate/frame/support/procedural/Cargo.toml b/substrate/frame/support/procedural/Cargo.toml index d2854a2a79f0..6c4d96d0fd4d 100644 --- a/substrate/frame/support/procedural/Cargo.toml +++ b/substrate/frame/support/procedural/Cargo.toml @@ -26,11 +26,11 @@ frame-support-procedural-tools = { path = "tools" } proc-macro-warning = { version = "0.4.2", default-features = false } macro_magic = { version = "0.4.2", features = ["proc_support"] } expander = "2.0.0" -sp-core-hashing = { path = "../../../primitives/core/hashing" } +sp-core-hashing = { path = "../../../primitives/core/hashing", default-features=false } [features] default = [ "std" ] -std = [] +std = [ "sp-core-hashing/std" ] no-metadata-docs = [] # Generate impl-trait for tuples with the given number of tuples. Will be needed as the number of # pallets in a runtime grows. Does increase the compile time! diff --git a/substrate/frame/support/procedural/tools/Cargo.toml b/substrate/frame/support/procedural/tools/Cargo.toml index fd42e18180d3..853e443f010b 100644 --- a/substrate/frame/support/procedural/tools/Cargo.toml +++ b/substrate/frame/support/procedural/tools/Cargo.toml @@ -12,7 +12,7 @@ description = "Proc macro helpers for procedural macros" targets = ["x86_64-unknown-linux-gnu"] [dependencies] -proc-macro-crate = "1.1.3" +proc-macro-crate = "2.0.0" proc-macro2 = "1.0.56" quote = "1.0.28" syn = { version = "2.0.38", features = ["full", "visit", "extra-traits"] } diff --git a/substrate/primitives/api/Cargo.toml b/substrate/primitives/api/Cargo.toml index 95b5dde37139..e9256f36f676 100644 --- a/substrate/primitives/api/Cargo.toml +++ b/substrate/primitives/api/Cargo.toml @@ -14,7 +14,7 @@ targets = ["x86_64-unknown-linux-gnu"] [dependencies] codec = { package = "parity-scale-codec", version = "3.6.1", default-features = false } -sp-api-proc-macro = { path = "proc-macro" } +sp-api-proc-macro = { path = "proc-macro", default-features = false } sp-core = { path = "../core", default-features = false} sp-std = { path = "../std", default-features = false} sp-runtime = { path = "../runtime", default-features = false} diff --git a/substrate/primitives/core/Cargo.toml b/substrate/primitives/core/Cargo.toml index 8c00622828dc..fe3dd73ae10a 100644 --- a/substrate/primitives/core/Cargo.toml +++ b/substrate/primitives/core/Cargo.toml @@ -24,8 +24,8 @@ hash-db = { version = "0.16.0", default-features = false } hash256-std-hasher = { version = "0.15.2", default-features = false } bs58 = { version = "0.5.0", default-features = false, optional = true } rand = { version = "0.8.5", features = ["small_rng"], optional = true } -substrate-bip39 = { version = "0.4.4" } -tiny-bip39 = { git = "https://github.com/michalkucharczyk/tiny-bip39/" , branch = "mku-rand-is-optional", default-features = false, features = [ "default-langs" ] } +substrate-bip39 = { version = "0.4.5", git = "https://github.com/paritytech/substrate-bip39", branch = "mku-support-for-no-std" } +tiny-bip39 = { version = "1.0.1", git = "https://github.com/michalkucharczyk/tiny-bip39/" , branch = "mku-nodefaults-for-sha2", default-features = false, features = [ "default-langs" ] } regex = { version = "1.6.0",default-features = false, features = ["unicode-perl"] } zeroize = { version = "1.4.3", default-features = false } secrecy = { version = "0.8.0", default-features = false, features = ["alloc"] } @@ -109,6 +109,7 @@ std = [ "sp-storage/std", "ss58-registry/std", "thiserror", + "tiny-bip39/std", "tiny-bip39/rand", "tracing", "zeroize/alloc", diff --git a/substrate/test-utils/runtime/Cargo.toml b/substrate/test-utils/runtime/Cargo.toml index d87aa36855fa..2fe72b6b7379 100644 --- a/substrate/test-utils/runtime/Cargo.toml +++ b/substrate/test-utils/runtime/Cargo.toml @@ -13,7 +13,7 @@ publish = false targets = ["x86_64-unknown-linux-gnu"] [dependencies] -sp-application-crypto = { path = "../../primitives/application-crypto", default-features = false, features = ["full_crypto"] } +sp-application-crypto = { path = "../../primitives/application-crypto", default-features = false, features = ["serde"] } sp-consensus-aura = { path = "../../primitives/consensus/aura", default-features = false, features = ["serde"] } sp-consensus-babe = { path = "../../primitives/consensus/babe", default-features = false, features = ["serde"] } sp-genesis-builder = { path = "../../primitives/genesis-builder", default-features = false} @@ -23,9 +23,9 @@ scale-info = { version = "2.5.0", default-features = false, features = ["derive" sp-inherents = { path = "../../primitives/inherents", default-features = false} sp-keyring = { path = "../../primitives/keyring", default-features = false} sp-offchain = { path = "../../primitives/offchain", default-features = false} -sp-core = { path = "../../primitives/core", default-features = false, features=["full_crypto"]} +sp-core = { path = "../../primitives/core", default-features = false, features=["serde"]} sp-std = { path = "../../primitives/std", default-features = false} -sp-io = { path = "../../primitives/io", default-features = false, features = ["disable_panic_handler"]} +sp-io = { path = "../../primitives/io", default-features = false } frame-support = { path = "../../frame/support", default-features = false} sp-version = { path = "../../primitives/version", default-features = false} sp-session = { path = "../../primitives/session", default-features = false} From cf11ccbded776a05e556a3b7710150166d804f6c Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Mon, 30 Oct 2023 19:22:26 +0100 Subject: [PATCH 08/52] substrate-bip39 bumped to 0.4.5 --- substrate/primitives/core/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/primitives/core/Cargo.toml b/substrate/primitives/core/Cargo.toml index 71d519e7b1e5..10ce3742074b 100644 --- a/substrate/primitives/core/Cargo.toml +++ b/substrate/primitives/core/Cargo.toml @@ -24,7 +24,7 @@ hash-db = { version = "0.16.0", default-features = false } hash256-std-hasher = { version = "0.15.2", default-features = false } bs58 = { version = "0.5.0", default-features = false, optional = true } rand = { version = "0.8.5", features = ["small_rng"], optional = true } -substrate-bip39 = { version = "0.4.5", git = "https://github.com/paritytech/substrate-bip39", branch = "mku-support-for-no-std" } +substrate-bip39 = "0.4.5" bip39 = { version = "2.0.0", default-features = false } regex = { version = "1.6.0",default-features = false, features = ["unicode-perl"] } zeroize = { version = "1.4.3", default-features = false } From 7e941ecf6e99a2c4baa67bfac20661a2766ae547 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Mon, 30 Oct 2023 19:22:51 +0100 Subject: [PATCH 09/52] use Mnemonic::parse_in_normalized in no-std --- substrate/primitives/core/src/crypto.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/substrate/primitives/core/src/crypto.rs b/substrate/primitives/core/src/crypto.rs index 92b9819ddd57..864384ae7c09 100644 --- a/substrate/primitives/core/src/crypto.rs +++ b/substrate/primitives/core/src/crypto.rs @@ -872,7 +872,16 @@ pub trait Pair: CryptoType + Sized { phrase: &str, password: Option<&str>, ) -> Result<(Self, Self::Seed), SecretStringError> { - let mnemonic = Mnemonic::parse_in(Language::English, phrase) + let mnemonic = { + #[cfg(feature = "std")] + { + Mnemonic::parse_in(Language::English, phrase) + } + #[cfg(not(feature = "std"))] + { + Mnemonic::parse_in_normalized(Language::English, phrase) + } + } .map_err(|_| SecretStringError::InvalidPhrase)?; let (entropy, entropy_len) = mnemonic.to_entropy_array(); From d3b803fff544cb4e0ae7fc43b86468778a897b3f Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Mon, 30 Oct 2023 19:23:13 +0100 Subject: [PATCH 10/52] Cargo.lock updated --- Cargo.lock | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 3227f7852f57..885c8367d45c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17962,7 +17962,8 @@ dependencies = [ [[package]] name = "substrate-bip39" version = "0.4.5" -source = "git+https://github.com/paritytech/substrate-bip39?branch=mku-support-for-no-std#b0ccbf720a0d6bdeea03c2e946ab186cef696fcb" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e620c7098893ba667438b47169c00aacdd9e7c10e042250ce2b60b087ec97328" dependencies = [ "hmac 0.11.0", "pbkdf2 0.8.0", From a5bc2367bfc7596bda159a8060033f677e388885 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Mon, 30 Oct 2023 19:35:55 +0100 Subject: [PATCH 11/52] keyring: features fix --- substrate/primitives/keyring/src/ed25519.rs | 6 +++--- substrate/primitives/keyring/src/sr25519.rs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/substrate/primitives/keyring/src/ed25519.rs b/substrate/primitives/keyring/src/ed25519.rs index 7b8c58860f86..f9876c2ffec6 100644 --- a/substrate/primitives/keyring/src/ed25519.rs +++ b/substrate/primitives/keyring/src/ed25519.rs @@ -19,8 +19,8 @@ use lazy_static::lazy_static; pub use sp_core::ed25519; -#[cfg(feature = "full_crypto")] -use sp_core::Signature; +#[cfg(feature = "std")] +use sp_core::ed25519::Signature; use sp_core::{ ed25519::{Pair, Public}, ByteArray, Pair as PairT, H256, @@ -95,7 +95,7 @@ impl Keyring { self.to_raw_public().into() } - #[cfg(feature = "full_crypto")] + #[cfg(feature = "std")] pub fn sign(self, msg: &[u8]) -> Signature { Pair::from(self).sign(msg) } diff --git a/substrate/primitives/keyring/src/sr25519.rs b/substrate/primitives/keyring/src/sr25519.rs index 33b77886c076..230d79ff4740 100644 --- a/substrate/primitives/keyring/src/sr25519.rs +++ b/substrate/primitives/keyring/src/sr25519.rs @@ -19,7 +19,7 @@ use lazy_static::lazy_static; pub use sp_core::sr25519; -#[cfg(feature = "full_crypto")] +#[cfg(feature = "std")] use sp_core::sr25519::Signature; use sp_core::{ sr25519::{Pair, Public}, @@ -95,7 +95,7 @@ impl Keyring { self.to_raw_public().into() } - #[cfg(feature = "full_crypto")] + #[cfg(feature = "std")] pub fn sign(self, msg: &[u8]) -> Signature { Pair::from(self).sign(msg) } From 8dc7d713ec3df81e8dc02834df10d40687673edb Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Mon, 30 Oct 2023 19:03:47 +0000 Subject: [PATCH 12/52] ".git/.scripts/commands/fmt/fmt.sh" --- substrate/primitives/core/src/crypto.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/primitives/core/src/crypto.rs b/substrate/primitives/core/src/crypto.rs index 864384ae7c09..b19f0174330f 100644 --- a/substrate/primitives/core/src/crypto.rs +++ b/substrate/primitives/core/src/crypto.rs @@ -882,7 +882,7 @@ pub trait Pair: CryptoType + Sized { Mnemonic::parse_in_normalized(Language::English, phrase) } } - .map_err(|_| SecretStringError::InvalidPhrase)?; + .map_err(|_| SecretStringError::InvalidPhrase)?; let (entropy, entropy_len) = mnemonic.to_entropy_array(); let big_seed = From 1c0b294b7c2edbf9eb2d9c957140f45ba35995d5 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 31 Oct 2023 09:11:29 +0100 Subject: [PATCH 13/52] bandersnatch fixes --- substrate/primitives/core/src/bandersnatch.rs | 28 ++++++--------- .../primitives/keyring/src/bandersnatch.rs | 35 ++++++++++++++----- 2 files changed, 38 insertions(+), 25 deletions(-) diff --git a/substrate/primitives/core/src/bandersnatch.rs b/substrate/primitives/core/src/bandersnatch.rs index 78b7f12f9ffd..2e98769f0f61 100644 --- a/substrate/primitives/core/src/bandersnatch.rs +++ b/substrate/primitives/core/src/bandersnatch.rs @@ -22,15 +22,14 @@ #[cfg(feature = "std")] use crate::crypto::Ss58Codec; +#[cfg(feature = "full_crypto")] +use crate::crypto::VrfSecret; use crate::crypto::{ - ByteArray, CryptoType, CryptoTypeId, Derive, Public as TraitPublic, UncheckedFrom, VrfPublic, + ByteArray, CryptoType, CryptoTypeId, Derive, DeriveError, DeriveJunction, Pair as TraitPair, + Public as TraitPublic, SecretStringError, UncheckedFrom, VrfPublic, }; -#[cfg(feature = "full_crypto")] -use crate::crypto::{DeriveError, DeriveJunction, Pair as TraitPair, SecretStringError, VrfSecret}; -use bandersnatch_vrfs::CanonicalSerialize; -#[cfg(feature = "full_crypto")] -use bandersnatch_vrfs::SecretKey; +use bandersnatch_vrfs::{CanonicalSerialize, SecretKey}; use codec::{Decode, Encode, EncodeLike, MaxEncodedLen}; use scale_info::TypeInfo; @@ -47,7 +46,6 @@ pub const SIGNING_CTX: &[u8] = b"BandersnatchSigningContext"; // Max ring domain size. const RING_DOMAIN_SIZE: usize = 1024; -#[cfg(feature = "full_crypto")] const SEED_SERIALIZED_LEN: usize = 32; // Short-Weierstrass form serialized sizes. @@ -63,7 +61,6 @@ const PREOUT_SERIALIZED_LEN: usize = 33; const RING_CONTEXT_SERIALIZED_LEN: usize = 147716; /// Bandersnatch public key. -#[cfg_attr(feature = "full_crypto", derive(Hash))] #[derive( Clone, Copy, @@ -76,6 +73,7 @@ const RING_CONTEXT_SERIALIZED_LEN: usize = 147716; PassByInner, MaxEncodedLen, TypeInfo, + Hash, )] pub struct Public(pub [u8; PUBLIC_SERIALIZED_LEN]); @@ -123,7 +121,6 @@ impl ByteArray for Public { impl TraitPublic for Public {} impl CryptoType for Public { - #[cfg(feature = "full_crypto")] type Pair = Pair; } @@ -146,8 +143,9 @@ impl sp_std::fmt::Debug for Public { /// /// The signature is created via the [`VrfSecret::vrf_sign`] using [`SIGNING_CTX`] as transcript /// `label`. -#[cfg_attr(feature = "full_crypto", derive(Hash))] -#[derive(Clone, Copy, PartialEq, Eq, Encode, Decode, PassByInner, MaxEncodedLen, TypeInfo)] +#[derive( + Clone, Copy, PartialEq, Eq, Encode, Decode, PassByInner, MaxEncodedLen, TypeInfo, Hash, +)] pub struct Signature([u8; SIGNATURE_SERIALIZED_LEN]); impl UncheckedFrom<[u8; SIGNATURE_SERIALIZED_LEN]> for Signature { @@ -186,7 +184,6 @@ impl ByteArray for Signature { } impl CryptoType for Signature { - #[cfg(feature = "full_crypto")] type Pair = Pair; } @@ -203,18 +200,15 @@ impl sp_std::fmt::Debug for Signature { } /// The raw secret seed, which can be used to reconstruct the secret [`Pair`]. -#[cfg(feature = "full_crypto")] type Seed = [u8; SEED_SERIALIZED_LEN]; /// Bandersnatch secret key. -#[cfg(feature = "full_crypto")] #[derive(Clone)] pub struct Pair { secret: SecretKey, seed: Seed, } -#[cfg(feature = "full_crypto")] impl Pair { /// Get the key seed. pub fn seed(&self) -> Seed { @@ -222,7 +216,6 @@ impl Pair { } } -#[cfg(feature = "full_crypto")] impl TraitPair for Pair { type Seed = Seed; type Public = Public; @@ -279,11 +272,13 @@ impl TraitPair for Pair { /// the constant label [`SIGNING_CTX`] and `data` without any additional data. /// /// See [`vrf::VrfSignData`] for additional details. + #[cfg(feature = "full_crypto")] fn sign(&self, data: &[u8]) -> Signature { let data = vrf::VrfSignData::new_unchecked(SIGNING_CTX, &[data], None); self.vrf_sign(&data).signature } + #[cfg(feature = "full_crypto")] fn verify>(signature: &Signature, data: M, public: &Public) -> bool { let data = vrf::VrfSignData::new_unchecked(SIGNING_CTX, &[data.as_ref()], None); let signature = @@ -297,7 +292,6 @@ impl TraitPair for Pair { } } -#[cfg(feature = "full_crypto")] impl CryptoType for Pair { type Pair = Pair; } diff --git a/substrate/primitives/keyring/src/bandersnatch.rs b/substrate/primitives/keyring/src/bandersnatch.rs index ce43c197e9b0..00ad9d2ddd8d 100644 --- a/substrate/primitives/keyring/src/bandersnatch.rs +++ b/substrate/primitives/keyring/src/bandersnatch.rs @@ -25,10 +25,28 @@ use sp_core::{ }; use lazy_static::lazy_static; -use sp_std::{collections::HashMap, ops::Deref, sync::Mutex}; +#[cfg(not(feature = "std"))] +use sp_std::ops::Deref; +#[cfg(not(feature = "std"))] +use sp_std::{collections::btree_map::BTreeMap, prelude::*}; +#[cfg(feature = "std")] +use std::{collections::BTreeMap, ops::Deref, sync::Mutex}; + +// todo: this requires cleanup! +// #[cfg(not(feature = "std"))] +// use sp_std::{alloc::string::String, format}; +#[cfg(not(feature = "std"))] +extern crate alloc; +#[cfg(not(feature = "std"))] +use alloc::{format, string::String}; + +#[cfg(not(feature = "std"))] +compile_error!("No support for bandersnatch in no-std yet."); /// Set of test accounts. -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, strum::Display, strum::EnumIter)] +#[derive( + Debug, Clone, Copy, PartialEq, Eq, Hash, strum::Display, strum::EnumIter, Ord, PartialOrd, +)] pub enum Keyring { Alice, Bob, @@ -59,6 +77,7 @@ impl Keyring { Public::from(self).to_raw_vec() } + #[cfg(feature = "std")] pub fn sign(self, msg: &[u8]) -> Signature { Pair::from(self).sign(msg) } @@ -105,16 +124,16 @@ impl From for &'static str { #[derive(Debug)] pub struct ParseKeyringError; -impl std::fmt::Display for ParseKeyringError { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl sp_std::fmt::Display for ParseKeyringError { + fn fmt(&self, f: &mut sp_std::fmt::Formatter<'_>) -> sp_std::fmt::Result { write!(f, "ParseKeyringError") } } -impl std::str::FromStr for Keyring { +impl sp_std::str::FromStr for Keyring { type Err = ParseKeyringError; - fn from_str(s: &str) -> Result::Err> { + fn from_str(s: &str) -> Result::Err> { match s { "Alice" => Ok(Keyring::Alice), "Bob" => Ok(Keyring::Bob), @@ -130,9 +149,9 @@ impl std::str::FromStr for Keyring { } lazy_static! { - static ref PRIVATE_KEYS: Mutex> = + static ref PRIVATE_KEYS: Mutex> = Mutex::new(Keyring::iter().map(|who| (who, who.pair())).collect()); - static ref PUBLIC_KEYS: HashMap = PRIVATE_KEYS + static ref PUBLIC_KEYS: BTreeMap = PRIVATE_KEYS .lock() .unwrap() .iter() From b26e6549d6ee039280cb5acdc65aea41e86ced4b Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 31 Oct 2023 09:22:24 +0100 Subject: [PATCH 14/52] compile feature removed --- substrate/primitives/application-crypto/Cargo.toml | 6 ------ substrate/primitives/core/Cargo.toml | 3 --- substrate/primitives/keyring/Cargo.toml | 7 ------- 3 files changed, 16 deletions(-) diff --git a/substrate/primitives/application-crypto/Cargo.toml b/substrate/primitives/application-crypto/Cargo.toml index f9ca8f514e70..a4a1bc44a69b 100644 --- a/substrate/primitives/application-crypto/Cargo.toml +++ b/substrate/primitives/application-crypto/Cargo.toml @@ -22,9 +22,6 @@ serde = { version = "1.0.188", default-features = false, optional = true, featur sp-std = { path = "../std", default-features = false} sp-io = { path = "../io", default-features = false} -#todo: remove this: -sp-runtime-interface = { path = "../runtime-interface", default-features = false, optional = true } - [features] default = [ "std" ] std = [ @@ -37,9 +34,6 @@ std = [ "sp-std/std", ] -#todo: remove this: -compile = [ "sp-io/disable_panic_handler", "sp-runtime-interface/disable_target_static_assertions" ] - # Serde support without relying on std features. serde = [ "dep:serde", "scale-info/serde", "sp-core/serde" ] diff --git a/substrate/primitives/core/Cargo.toml b/substrate/primitives/core/Cargo.toml index 10ce3742074b..28986049639c 100644 --- a/substrate/primitives/core/Cargo.toml +++ b/substrate/primitives/core/Cargo.toml @@ -149,6 +149,3 @@ bls-experimental = [ "w3f-bls" ] # It should not be used in production since the implementation and interface may still # be subject to significant changes. bandersnatch-experimental = [ "bandersnatch_vrfs" ] - -#todo: remove this: -compile = [ "sp-runtime-interface/disable_target_static_assertions" ] diff --git a/substrate/primitives/keyring/Cargo.toml b/substrate/primitives/keyring/Cargo.toml index c69e8eb5ad47..855682d0bfbe 100644 --- a/substrate/primitives/keyring/Cargo.toml +++ b/substrate/primitives/keyring/Cargo.toml @@ -20,10 +20,6 @@ sp-core = { path = "../core", default-features = false } sp-runtime = { path = "../runtime", default-features = false } sp-std = { path = "../std", default-features = false } -#todo: remove this (required for `cargo build --no-default-features`) -sp-io = { path = "../io", default-features = false, optional = true } -sp-runtime-interface = { path = "../runtime-interface", default-features = false, optional = true } - [features] default = [ "std" ] std = [ @@ -32,9 +28,6 @@ std = [ "sp-std/std", ] -#todo: remove this (required for `cargo build --no-default-features`) -compile = [ "sp-io/disable_panic_handler", "sp-runtime-interface/disable_target_static_assertions" ] - # This feature adds Bandersnatch crypto primitives. # It should not be used in production since the implementation and interface may still # be subject to significant changes. From 67de13d1c03ed4a23485e60f28bdd2ab2a8ca72c Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 31 Oct 2023 09:23:03 +0100 Subject: [PATCH 15/52] keyring: fixes --- substrate/primitives/keyring/src/bandersnatch.rs | 6 ++---- substrate/primitives/keyring/src/ed25519.rs | 2 -- substrate/primitives/keyring/src/sr25519.rs | 4 +--- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/substrate/primitives/keyring/src/bandersnatch.rs b/substrate/primitives/keyring/src/bandersnatch.rs index 00ad9d2ddd8d..feed8793fe71 100644 --- a/substrate/primitives/keyring/src/bandersnatch.rs +++ b/substrate/primitives/keyring/src/bandersnatch.rs @@ -17,6 +17,7 @@ //! A set of well-known keys used for testing. +use lazy_static::lazy_static; pub use sp_core::bandersnatch; use sp_core::{ bandersnatch::{Pair, Public, Signature}, @@ -24,11 +25,8 @@ use sp_core::{ ByteArray, Pair as PairT, }; -use lazy_static::lazy_static; -#[cfg(not(feature = "std"))] -use sp_std::ops::Deref; #[cfg(not(feature = "std"))] -use sp_std::{collections::btree_map::BTreeMap, prelude::*}; +use sp_std::{collections::btree_map::BTreeMap, ops::Deref, prelude::*}; #[cfg(feature = "std")] use std::{collections::BTreeMap, ops::Deref, sync::Mutex}; diff --git a/substrate/primitives/keyring/src/ed25519.rs b/substrate/primitives/keyring/src/ed25519.rs index f9876c2ffec6..96130a8a2828 100644 --- a/substrate/primitives/keyring/src/ed25519.rs +++ b/substrate/primitives/keyring/src/ed25519.rs @@ -26,8 +26,6 @@ use sp_core::{ ByteArray, Pair as PairT, H256, }; use sp_runtime::AccountId32; - -use sp_std::vec::Vec; #[cfg(not(feature = "std"))] use sp_std::{collections::btree_map::BTreeMap, ops::Deref, prelude::*}; #[cfg(feature = "std")] diff --git a/substrate/primitives/keyring/src/sr25519.rs b/substrate/primitives/keyring/src/sr25519.rs index 230d79ff4740..c448309b9c18 100644 --- a/substrate/primitives/keyring/src/sr25519.rs +++ b/substrate/primitives/keyring/src/sr25519.rs @@ -27,9 +27,7 @@ use sp_core::{ }; use sp_runtime::AccountId32; #[cfg(not(feature = "std"))] -use sp_std::ops::Deref; -#[cfg(not(feature = "std"))] -use sp_std::{collections::btree_map::BTreeMap, prelude::*}; +use sp_std::{collections::btree_map::BTreeMap, ops::Deref, prelude::*}; #[cfg(feature = "std")] use std::{collections::BTreeMap, ops::Deref}; From 0763902f5aeed1f271645f0e4530a65c6f834d33 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 31 Oct 2023 09:23:40 +0100 Subject: [PATCH 16/52] Cargo.lock --- Cargo.lock | 3 --- 1 file changed, 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 885c8367d45c..82b162286de4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -16874,7 +16874,6 @@ dependencies = [ "serde", "sp-core", "sp-io", - "sp-runtime-interface", "sp-std", ] @@ -17245,9 +17244,7 @@ version = "24.0.0" dependencies = [ "lazy_static", "sp-core", - "sp-io", "sp-runtime", - "sp-runtime-interface", "sp-std", "strum", ] From c07771362fde1ad6c74c53df0c4370046cc62999 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 31 Oct 2023 12:33:01 +0100 Subject: [PATCH 17/52] keyring: sp_std cleanup --- Cargo.lock | 1 - substrate/primitives/keyring/Cargo.toml | 2 -- .../primitives/keyring/src/bandersnatch.rs | 27 +++++++++---------- substrate/primitives/keyring/src/ed25519.rs | 12 ++------- substrate/primitives/keyring/src/sr25519.rs | 22 ++++++--------- 5 files changed, 22 insertions(+), 42 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 82b162286de4..1c4bdd2d2e4e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17245,7 +17245,6 @@ dependencies = [ "lazy_static", "sp-core", "sp-runtime", - "sp-std", "strum", ] diff --git a/substrate/primitives/keyring/Cargo.toml b/substrate/primitives/keyring/Cargo.toml index 855682d0bfbe..d8ea8b644613 100644 --- a/substrate/primitives/keyring/Cargo.toml +++ b/substrate/primitives/keyring/Cargo.toml @@ -18,14 +18,12 @@ lazy_static = { version = "1.4.0", features = [ "spin_no_std" ], default-feature strum = { version = "0.24.1", features = ["derive"], default-features = false } sp-core = { path = "../core", default-features = false } sp-runtime = { path = "../runtime", default-features = false } -sp-std = { path = "../std", default-features = false } [features] default = [ "std" ] std = [ "sp-core/std", "sp-runtime/std", - "sp-std/std", ] # This feature adds Bandersnatch crypto primitives. diff --git a/substrate/primitives/keyring/src/bandersnatch.rs b/substrate/primitives/keyring/src/bandersnatch.rs index feed8793fe71..3c588912df7b 100644 --- a/substrate/primitives/keyring/src/bandersnatch.rs +++ b/substrate/primitives/keyring/src/bandersnatch.rs @@ -17,26 +17,23 @@ //! A set of well-known keys used for testing. +use core::ops::Deref; use lazy_static::lazy_static; pub use sp_core::bandersnatch; +#[cfg(feature = "std")] +use sp_core::bandersnatch::Signature; use sp_core::{ - bandersnatch::{Pair, Public, Signature}, + bandersnatch::{Pair, Public}, crypto::UncheckedFrom, ByteArray, Pair as PairT, }; - -#[cfg(not(feature = "std"))] -use sp_std::{collections::btree_map::BTreeMap, ops::Deref, prelude::*}; #[cfg(feature = "std")] -use std::{collections::BTreeMap, ops::Deref, sync::Mutex}; +use std::sync::Mutex; -// todo: this requires cleanup! -// #[cfg(not(feature = "std"))] -// use sp_std::{alloc::string::String, format}; -#[cfg(not(feature = "std"))] extern crate alloc; -#[cfg(not(feature = "std"))] -use alloc::{format, string::String}; +use alloc::{ + collections::btree_map::BTreeMap, fmt, format, str::FromStr, string::String, vec::Vec, +}; #[cfg(not(feature = "std"))] compile_error!("No support for bandersnatch in no-std yet."); @@ -122,16 +119,16 @@ impl From for &'static str { #[derive(Debug)] pub struct ParseKeyringError; -impl sp_std::fmt::Display for ParseKeyringError { - fn fmt(&self, f: &mut sp_std::fmt::Formatter<'_>) -> sp_std::fmt::Result { +impl fmt::Display for ParseKeyringError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "ParseKeyringError") } } -impl sp_std::str::FromStr for Keyring { +impl FromStr for Keyring { type Err = ParseKeyringError; - fn from_str(s: &str) -> Result::Err> { + fn from_str(s: &str) -> Result::Err> { match s { "Alice" => Ok(Keyring::Alice), "Bob" => Ok(Keyring::Bob), diff --git a/substrate/primitives/keyring/src/ed25519.rs b/substrate/primitives/keyring/src/ed25519.rs index 96130a8a2828..b61b42eb5c6c 100644 --- a/substrate/primitives/keyring/src/ed25519.rs +++ b/substrate/primitives/keyring/src/ed25519.rs @@ -17,6 +17,7 @@ //! Support code for the runtime. A set of test accounts. +use core::ops::Deref; use lazy_static::lazy_static; pub use sp_core::ed25519; #[cfg(feature = "std")] @@ -26,18 +27,9 @@ use sp_core::{ ByteArray, Pair as PairT, H256, }; use sp_runtime::AccountId32; -#[cfg(not(feature = "std"))] -use sp_std::{collections::btree_map::BTreeMap, ops::Deref, prelude::*}; -#[cfg(feature = "std")] -use std::{collections::BTreeMap, ops::Deref}; -// todo: this requires cleanup! -// #[cfg(not(feature = "std"))] -// use sp_std::{alloc::string::String, format}; -#[cfg(not(feature = "std"))] extern crate alloc; -#[cfg(not(feature = "std"))] -use alloc::{format, string::String}; +use alloc::{collections::btree_map::BTreeMap, format, string::String, vec::Vec}; /// Set of test accounts. #[derive( diff --git a/substrate/primitives/keyring/src/sr25519.rs b/substrate/primitives/keyring/src/sr25519.rs index c448309b9c18..471f4719e803 100644 --- a/substrate/primitives/keyring/src/sr25519.rs +++ b/substrate/primitives/keyring/src/sr25519.rs @@ -17,6 +17,7 @@ //! Support code for the runtime. A set of test accounts. +use core::ops::Deref; use lazy_static::lazy_static; pub use sp_core::sr25519; #[cfg(feature = "std")] @@ -26,18 +27,11 @@ use sp_core::{ ByteArray, Pair as PairT, H256, }; use sp_runtime::AccountId32; -#[cfg(not(feature = "std"))] -use sp_std::{collections::btree_map::BTreeMap, ops::Deref, prelude::*}; -#[cfg(feature = "std")] -use std::{collections::BTreeMap, ops::Deref}; -// todo: this requires cleanup! -// #[cfg(not(feature = "std"))] -// use sp_std::{alloc::string::String, format}; -#[cfg(not(feature = "std"))] extern crate alloc; -#[cfg(not(feature = "std"))] -use alloc::{format, string::String}; +use alloc::{ + collections::btree_map::BTreeMap, fmt, format, str::FromStr, string::String, vec::Vec, +}; /// Set of test accounts. #[derive( @@ -157,16 +151,16 @@ impl From for sp_runtime::MultiSigner { #[derive(Debug)] pub struct ParseKeyringError; -impl sp_std::fmt::Display for ParseKeyringError { - fn fmt(&self, f: &mut sp_std::fmt::Formatter<'_>) -> sp_std::fmt::Result { +impl fmt::Display for ParseKeyringError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "ParseKeyringError") } } -impl sp_std::str::FromStr for Keyring { +impl FromStr for Keyring { type Err = ParseKeyringError; - fn from_str(s: &str) -> Result::Err> { + fn from_str(s: &str) -> Result::Err> { match s { "alice" => Ok(Keyring::Alice), "bob" => Ok(Keyring::Bob), From 3ba69e665b770e97476c02e28824bd45fcfc3059 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 31 Oct 2023 14:18:47 +0100 Subject: [PATCH 18/52] debug added --- substrate/test-utils/runtime/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/substrate/test-utils/runtime/src/lib.rs b/substrate/test-utils/runtime/src/lib.rs index 75edc5322558..08f2651ec1ec 100644 --- a/substrate/test-utils/runtime/src/lib.rs +++ b/substrate/test-utils/runtime/src/lib.rs @@ -727,6 +727,7 @@ impl_runtime_apis! { impl sp_genesis_builder::GenesisBuilder for Runtime { fn create_default_config() -> Vec { log::info!("{:#?}", AccountKeyring::Alice.public().to_ss58check()); + log::info!("{:#?}", AccountKeyring::Bob.public().to_ss58check()); create_default_config::() } From 6fc3c659f88595cc2cf069300f40351fb9c1d3fd Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Mon, 6 Nov 2023 14:20:33 +0100 Subject: [PATCH 19/52] unicode-normalization also supported in no-std --- substrate/primitives/core/src/crypto.rs | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/substrate/primitives/core/src/crypto.rs b/substrate/primitives/core/src/crypto.rs index b19f0174330f..a364c5ef88ce 100644 --- a/substrate/primitives/core/src/crypto.rs +++ b/substrate/primitives/core/src/crypto.rs @@ -872,18 +872,8 @@ pub trait Pair: CryptoType + Sized { phrase: &str, password: Option<&str>, ) -> Result<(Self, Self::Seed), SecretStringError> { - let mnemonic = { - #[cfg(feature = "std")] - { - Mnemonic::parse_in(Language::English, phrase) - } - #[cfg(not(feature = "std"))] - { - Mnemonic::parse_in_normalized(Language::English, phrase) - } - } - .map_err(|_| SecretStringError::InvalidPhrase)?; - + let mnemonic = Mnemonic::parse_in(Language::English, phrase) + .map_err(|_| SecretStringError::InvalidPhrase)?; let (entropy, entropy_len) = mnemonic.to_entropy_array(); let big_seed = substrate_bip39::seed_from_entropy(&entropy[0..entropy_len], password.unwrap_or("")) From d64694f7806f2148d5fdcd7ab74aee980822bd5c Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Mon, 6 Nov 2023 14:37:30 +0100 Subject: [PATCH 20/52] use fork of rust-bip39 --- substrate/primitives/core/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/primitives/core/Cargo.toml b/substrate/primitives/core/Cargo.toml index 28986049639c..fab565d49d02 100644 --- a/substrate/primitives/core/Cargo.toml +++ b/substrate/primitives/core/Cargo.toml @@ -25,7 +25,7 @@ hash256-std-hasher = { version = "0.15.2", default-features = false } bs58 = { version = "0.5.0", default-features = false, optional = true } rand = { version = "0.8.5", features = ["small_rng"], optional = true } substrate-bip39 = "0.4.5" -bip39 = { version = "2.0.0", default-features = false } +bip39 = { git = "https://github.com/michalkucharczyk/rust-bip39", branch="mku-unicode-normalization-in-no-std", version = "2.0.0", default-features = false, features = [ "alloc" ] } regex = { version = "1.6.0",default-features = false, features = ["unicode-perl"] } zeroize = { version = "1.4.3", default-features = false } secrecy = { version = "0.8.0", default-features = false, features = ["alloc"] } From 7b763d3b91415a25d5ecabb8ba87b1c1a0a8b522 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Mon, 6 Nov 2023 14:40:22 +0100 Subject: [PATCH 21/52] Cargo.lock updated --- Cargo.lock | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1c4bdd2d2e4e..042a7a4eb49c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1377,8 +1377,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "93f2635620bf0b9d4576eb7bb9a38a55df78bd1205d26fa994b25911a69f212f" dependencies = [ "bitcoin_hashes", - "rand 0.8.5", - "rand_core 0.6.4", + "serde", + "unicode-normalization", +] + +[[package]] +name = "bip39" +version = "2.0.0" +source = "git+https://github.com/michalkucharczyk/rust-bip39?branch=mku-unicode-normalization-in-no-std#e63f0b2f487a596450637be66b88c91b79e9adc7" +dependencies = [ + "bitcoin_hashes", + "rand 0.7.3", + "rand_core 0.5.1", "serde", "unicode-normalization", ] @@ -14739,7 +14749,7 @@ name = "sc-cli" version = "0.10.0-dev" dependencies = [ "array-bytes 6.1.0", - "bip39", + "bip39 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "chrono", "clap 4.4.6", "fdlimit", @@ -16667,7 +16677,7 @@ dependencies = [ "async-lock", "atomic-take", "base64 0.21.2", - "bip39", + "bip39 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "blake2-rfc", "bs58 0.5.0", "chacha20 0.9.1", @@ -17084,7 +17094,7 @@ version = "21.0.0" dependencies = [ "array-bytes 6.1.0", "bandersnatch_vrfs", - "bip39", + "bip39 2.0.0 (git+https://github.com/michalkucharczyk/rust-bip39?branch=mku-unicode-normalization-in-no-std)", "bitflags 1.3.2", "blake2 0.10.6", "bounded-collections", From 18db2bfaf5718c3cbcfdca3a10dbe04df36e3338 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Mon, 6 Nov 2023 15:41:39 +0100 Subject: [PATCH 22/52] more fixes --- Cargo.lock | 2 ++ substrate/client/cli/Cargo.toml | 2 +- substrate/primitives/core/src/crypto.rs | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 042a7a4eb49c..4f98ebf68953 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1377,6 +1377,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "93f2635620bf0b9d4576eb7bb9a38a55df78bd1205d26fa994b25911a69f212f" dependencies = [ "bitcoin_hashes", + "rand 0.7.3", + "rand_core 0.5.1", "serde", "unicode-normalization", ] diff --git a/substrate/client/cli/Cargo.toml b/substrate/client/cli/Cargo.toml index 5a98b43f43c2..696516950be4 100644 --- a/substrate/client/cli/Cargo.toml +++ b/substrate/client/cli/Cargo.toml @@ -29,7 +29,7 @@ rpassword = "7.0.0" serde = "1.0.188" serde_json = "1.0.107" thiserror = "1.0.48" -bip39 = "2.0.0" +bip39 = { version = "2.0.0", features = ["rand"] } tokio = { version = "1.22.0", features = ["signal", "rt-multi-thread", "parking_lot"] } sc-client-api = { path = "../api" } sc-client-db = { path = "../db", default-features = false} diff --git a/substrate/primitives/core/src/crypto.rs b/substrate/primitives/core/src/crypto.rs index a364c5ef88ce..aac19b03557d 100644 --- a/substrate/primitives/core/src/crypto.rs +++ b/substrate/primitives/core/src/crypto.rs @@ -861,7 +861,7 @@ pub trait Pair: CryptoType + Sized { #[cfg(feature = "std")] fn generate_with_phrase(password: Option<&str>) -> (Self, String, Self::Seed) { let mnemonic = Mnemonic::generate(12).expect("Mnemonic generation always works; qed"); - let phrase = mnemonic.word_iter().join(" "); + let phrase = mnemonic.words().join(" "); let (pair, seed) = Self::from_phrase(&phrase, password) .expect("All phrases generated by Mnemonic are valid; qed"); (pair, phrase.to_owned(), seed) From d77e3cc72f534fd3e9d6bdd01e295bf121767231 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Mon, 20 Nov 2023 15:37:57 +0100 Subject: [PATCH 23/52] address_uri support in no-std, no-full-crypto --- substrate/primitives/core/src/address_uri.rs | 2 +- substrate/primitives/core/src/crypto.rs | 6 +----- substrate/primitives/core/src/lib.rs | 1 - 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/substrate/primitives/core/src/address_uri.rs b/substrate/primitives/core/src/address_uri.rs index 862747c9a4b6..5a2a1a1275ad 100644 --- a/substrate/primitives/core/src/address_uri.rs +++ b/substrate/primitives/core/src/address_uri.rs @@ -17,7 +17,7 @@ //! Little util for parsing an address URI. Replaces regular expressions. -#[cfg(all(not(feature = "std"), any(feature = "serde", feature = "full_crypto")))] +#[cfg(all(not(feature = "std")))] use sp_std::{ alloc::string::{String, ToString}, vec::Vec, diff --git a/substrate/primitives/core/src/crypto.rs b/substrate/primitives/core/src/crypto.rs index bc716a48f116..f27eb80db160 100644 --- a/substrate/primitives/core/src/crypto.rs +++ b/substrate/primitives/core/src/crypto.rs @@ -39,10 +39,7 @@ pub use ss58_registry::{from_known_address_format, Ss58AddressFormat, Ss58Addres /// Trait to zeroize a memory buffer. pub use zeroize::Zeroize; -#[cfg(feature = "std")] -pub use crate::address_uri::AddressUri; -#[cfg(any(feature = "std", feature = "full_crypto"))] -pub use crate::address_uri::Error as AddressUriError; +pub use crate::address_uri::{AddressUri, Error as AddressUriError}; /// The root phrase for our publicly known keys. pub const DEV_PHRASE: &str = @@ -101,7 +98,6 @@ pub enum SecretStringError { InvalidPath, } -#[cfg(any(feature = "std", feature = "full_crypto"))] impl From for SecretStringError { fn from(e: AddressUriError) -> Self { Self::InvalidFormat(e) diff --git a/substrate/primitives/core/src/lib.rs b/substrate/primitives/core/src/lib.rs index b85cc039c0dc..c98a37ac5ee4 100644 --- a/substrate/primitives/core/src/lib.rs +++ b/substrate/primitives/core/src/lib.rs @@ -54,7 +54,6 @@ pub mod crypto; pub mod hexdisplay; pub use paste; -#[cfg(any(feature = "full_crypto", feature = "std"))] mod address_uri; #[cfg(feature = "bandersnatch-experimental")] pub mod bandersnatch; From 1b57b65aad7ed54f324d864e7a416280bbf47966 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Mon, 20 Nov 2023 16:08:20 +0100 Subject: [PATCH 24/52] verify available in non-full-crypto --- substrate/primitives/core/src/bandersnatch.rs | 2 -- substrate/primitives/core/src/crypto.rs | 1 - substrate/primitives/core/src/ecdsa.rs | 23 ++++++++----------- substrate/primitives/core/src/ed25519.rs | 1 - substrate/primitives/core/src/sr25519.rs | 6 +---- 5 files changed, 11 insertions(+), 22 deletions(-) diff --git a/substrate/primitives/core/src/bandersnatch.rs b/substrate/primitives/core/src/bandersnatch.rs index 2e98769f0f61..e2e034ca3d50 100644 --- a/substrate/primitives/core/src/bandersnatch.rs +++ b/substrate/primitives/core/src/bandersnatch.rs @@ -40,7 +40,6 @@ use sp_std::{boxed::Box, vec::Vec}; pub const CRYPTO_ID: CryptoTypeId = CryptoTypeId(*b"band"); /// Context used to produce a plain signature without any VRF input/output. -#[cfg(feature = "full_crypto")] pub const SIGNING_CTX: &[u8] = b"BandersnatchSigningContext"; // Max ring domain size. @@ -278,7 +277,6 @@ impl TraitPair for Pair { self.vrf_sign(&data).signature } - #[cfg(feature = "full_crypto")] fn verify>(signature: &Signature, data: M, public: &Public) -> bool { let data = vrf::VrfSignData::new_unchecked(SIGNING_CTX, &[data.as_ref()], None); let signature = diff --git a/substrate/primitives/core/src/crypto.rs b/substrate/primitives/core/src/crypto.rs index f27eb80db160..f4837ec8d905 100644 --- a/substrate/primitives/core/src/crypto.rs +++ b/substrate/primitives/core/src/crypto.rs @@ -912,7 +912,6 @@ pub trait Pair: CryptoType + Sized { fn sign(&self, message: &[u8]) -> Self::Signature; /// Verify a signature on a message. Returns true if the signature is good. - #[cfg(feature = "full_crypto")] fn verify>(sig: &Self::Signature, message: M, pubkey: &Self::Public) -> bool; /// Get the public key. diff --git a/substrate/primitives/core/src/ecdsa.rs b/substrate/primitives/core/src/ecdsa.rs index 9ec41a6b71d1..b57d4ee27942 100644 --- a/substrate/primitives/core/src/ecdsa.rs +++ b/substrate/primitives/core/src/ecdsa.rs @@ -23,21 +23,21 @@ use sp_runtime_interface::pass_by::PassByInner; #[cfg(feature = "serde")] use crate::crypto::Ss58Codec; -use crate::crypto::{ - ByteArray, CryptoType, CryptoTypeId, Derive, DeriveError, DeriveJunction, Pair as TraitPair, - Public as TraitPublic, SecretStringError, UncheckedFrom, +use crate::{ + crypto::{ + ByteArray, CryptoType, CryptoTypeId, Derive, DeriveError, DeriveJunction, + Pair as TraitPair, Public as TraitPublic, SecretStringError, UncheckedFrom, + }, + hashing::blake2_256, }; -#[cfg(feature = "full_crypto")] -use crate::hashing::blake2_256; -#[cfg(feature = "full_crypto")] -use secp256k1::ecdsa::{RecoverableSignature, RecoveryId}; -#[cfg(feature = "full_crypto")] -use secp256k1::Message; #[cfg(not(feature = "std"))] use secp256k1::Secp256k1; #[cfg(feature = "std")] use secp256k1::SECP256K1; -use secp256k1::{PublicKey, SecretKey}; +use secp256k1::{ + ecdsa::{RecoverableSignature, RecoveryId}, + Message, PublicKey, SecretKey, +}; #[cfg(feature = "serde")] use serde::{de, Deserialize, Deserializer, Serialize, Serializer}; #[cfg(all(not(feature = "std"), feature = "serde"))] @@ -322,13 +322,11 @@ impl Signature { } /// Recover the public key from this signature and a message. - #[cfg(feature = "full_crypto")] pub fn recover>(&self, message: M) -> Option { self.recover_prehashed(&blake2_256(message.as_ref())) } /// Recover the public key from this signature and a pre-hashed message. - #[cfg(feature = "full_crypto")] pub fn recover_prehashed(&self, message: &[u8; 32]) -> Option { let rid = RecoveryId::from_i32(self.0[64] as i32).ok()?; let sig = RecoverableSignature::from_compact(&self.0[..64], rid).ok()?; @@ -421,7 +419,6 @@ impl TraitPair for Pair { } /// Verify a signature on a message. Returns true if the signature is good. - #[cfg(feature = "full_crypto")] fn verify>(sig: &Signature, message: M, public: &Public) -> bool { sig.recover(message).map(|actual| actual == *public).unwrap_or_default() } diff --git a/substrate/primitives/core/src/ed25519.rs b/substrate/primitives/core/src/ed25519.rs index 24844c4592bf..85e8232b6f4c 100644 --- a/substrate/primitives/core/src/ed25519.rs +++ b/substrate/primitives/core/src/ed25519.rs @@ -414,7 +414,6 @@ impl TraitPair for Pair { /// Verify a signature on a message. /// /// Returns true if the signature is good. - #[cfg(feature = "full_crypto")] fn verify>(sig: &Signature, message: M, public: &Public) -> bool { let Ok(public) = VerificationKey::try_from(public.as_slice()) else { return false }; let Ok(signature) = ed25519_zebra::Signature::try_from(sig.as_ref()) else { return false }; diff --git a/substrate/primitives/core/src/sr25519.rs b/substrate/primitives/core/src/sr25519.rs index bb345dcbb899..05041086300a 100644 --- a/substrate/primitives/core/src/sr25519.rs +++ b/substrate/primitives/core/src/sr25519.rs @@ -24,11 +24,9 @@ use crate::crypto::Ss58Codec; use crate::crypto::{DeriveError, DeriveJunction, Pair as TraitPair, SecretStringError}; #[cfg(feature = "full_crypto")] use schnorrkel::signing_context; -#[cfg(any(feature = "serde", feature = "full_crypto"))] -use schnorrkel::PublicKey; use schnorrkel::{ derive::{ChainCode, Derivation, CHAIN_CODE_LENGTH}, - ExpansionMode, Keypair, MiniSecretKey, SecretKey, + ExpansionMode, Keypair, MiniSecretKey, PublicKey, SecretKey, }; use sp_std::vec::Vec; @@ -51,7 +49,6 @@ use sp_runtime_interface::pass_by::PassByInner; use sp_std::alloc::{format, string::String}; // signing context -#[cfg(feature = "full_crypto")] const SIGNING_CTX: &[u8] = b"substrate"; /// An identifier used to match public keys against sr25519 keys @@ -494,7 +491,6 @@ impl TraitPair for Pair { self.0.sign(context.bytes(message)).into() } - #[cfg(feature = "full_crypto")] fn verify>(sig: &Signature, message: M, pubkey: &Public) -> bool { let Ok(signature) = schnorrkel::Signature::from_bytes(sig.as_ref()) else { return false }; let Ok(public) = PublicKey::from_bytes(pubkey.as_ref()) else { return false }; From 06d53e4f950390bbc79aefee55e867ab6dc1515c Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Mon, 20 Nov 2023 16:27:34 +0100 Subject: [PATCH 25/52] application-crypto: app_crypto_pair_common added --- .../primitives/application-crypto/src/lib.rs | 110 +++++------------- 1 file changed, 30 insertions(+), 80 deletions(-) diff --git a/substrate/primitives/application-crypto/src/lib.rs b/substrate/primitives/application-crypto/src/lib.rs index 73012a6f3528..ea2e5a83127b 100644 --- a/substrate/primitives/application-crypto/src/lib.rs +++ b/substrate/primitives/application-crypto/src/lib.rs @@ -82,7 +82,7 @@ macro_rules! app_crypto { $module::CRYPTO_ID ); $crate::app_crypto_signature_common!($module::Signature, $key_type); - $crate::app_crypto_pair!($module::Pair, $key_type, $module::CRYPTO_ID); + $crate::app_crypto_pair_common!($module::Pair, $key_type, $module::CRYPTO_ID); }; } @@ -113,14 +113,15 @@ macro_rules! app_crypto { $module::CRYPTO_ID ); $crate::app_crypto_signature_common!($module::Signature, $key_type); - $crate::app_crypto_pair_not_full_crypto!($module::Pair, $key_type, $module::CRYPTO_ID); + $crate::app_crypto_pair_common!($module::Pair, $key_type, $module::CRYPTO_ID); }; } /// Declares `Pair` type which is functionally equivalent to `$pair`, but is /// new application-specific type whose identifier is `$key_type`. +/// It is a common part shared between full_crypto and non full_crypto environments. #[macro_export] -macro_rules! app_crypto_pair { +macro_rules! app_crypto_pair_common { ($pair:ty, $key_type:expr, $crypto_type:expr) => { $crate::wrap! { /// A generic `AppPublic` wrapper type over $pair crypto; this has no specific App. @@ -138,7 +139,14 @@ macro_rules! app_crypto_pair { type Signature = Signature; $crate::app_crypto_pair_functions_if_std!($pair); + $crate::app_crypto_pair_functions_if_full_crypto!($pair); + fn from_phrase( + phrase: &str, + password: Option<&str>, + ) -> Result<(Self, Self::Seed), $crate::SecretStringError> { + <$pair>::from_phrase(phrase, password).map(|r| (Self(r.0), r.1)) + } fn derive>( &self, path: Iter, @@ -152,9 +160,6 @@ macro_rules! app_crypto_pair { fn from_seed_slice(seed: &[u8]) -> Result { <$pair>::from_seed_slice(seed).map(Self) } - fn sign(&self, msg: &[u8]) -> Self::Signature { - Signature(self.0.sign(msg)) - } fn verify>( sig: &Self::Signature, message: M, @@ -191,72 +196,6 @@ macro_rules! app_crypto_pair { }; } -/// Declares `Pair` type which is functionally equivalent to `$pair`, but is -/// new application-specific type whose identifier is `$key_type`. -/// Can only be used without `full_crypto` feature. -/// `verify` and `sign` methods are not implemented. -#[macro_export] -macro_rules! app_crypto_pair_not_full_crypto { - ($pair:ty, $key_type:expr, $crypto_type:expr) => { - $crate::wrap! { - /// A generic `AppPublic` wrapper type over $pair crypto; this has no specific App. - #[derive(Clone)] - pub struct Pair($pair); - } - - impl $crate::CryptoType for Pair { - type Pair = Pair; - } - - impl $crate::Pair for Pair { - type Public = Public; - type Seed = <$pair as $crate::Pair>::Seed; - type Signature = Signature; - - $crate::app_crypto_pair_functions_if_std!($pair); - - fn derive>( - &self, - path: Iter, - seed: Option, - ) -> Result<(Self, Option), $crate::DeriveError> { - self.0.derive(path, seed).map(|x| (Self(x.0), x.1)) - } - fn from_seed(seed: &Self::Seed) -> Self { - Self(<$pair>::from_seed(seed)) - } - fn from_seed_slice(seed: &[u8]) -> Result { - <$pair>::from_seed_slice(seed).map(Self) - } - fn public(&self) -> Self::Public { - Public(self.0.public()) - } - fn to_raw_vec(&self) -> $crate::Vec { - self.0.to_raw_vec() - } - } - - impl $crate::AppCrypto for Pair { - type Public = Public; - type Pair = Pair; - type Signature = Signature; - const ID: $crate::KeyTypeId = $key_type; - const CRYPTO_ID: $crate::CryptoTypeId = $crypto_type; - } - - impl $crate::AppPair for Pair { - type Generic = $pair; - } - - impl Pair { - /// Convert into wrapped generic key pair type. - pub fn into_inner(self) -> $pair { - self.0 - } - } - }; -} - /// Implements functions for the `Pair` trait when `feature = "std"` is enabled. #[doc(hidden)] #[cfg(feature = "std")] @@ -267,13 +206,6 @@ macro_rules! app_crypto_pair_functions_if_std { let r = <$pair>::generate_with_phrase(password); (Self(r.0), r.1, r.2) } - - fn from_phrase( - phrase: &str, - password: Option<&str>, - ) -> Result<(Self, Self::Seed), $crate::SecretStringError> { - <$pair>::from_phrase(phrase, password).map(|r| (Self(r.0), r.1)) - } }; } @@ -284,6 +216,25 @@ macro_rules! app_crypto_pair_functions_if_std { ($pair:ty) => {}; } +/// Implements functions for the `Pair` trait when `feature = "full_crypto"` is enabled. +#[doc(hidden)] +#[cfg(feature = "full_crypto")] +#[macro_export] +macro_rules! app_crypto_pair_functions_if_full_crypto { + ($pair:ty) => { + fn sign(&self, msg: &[u8]) -> Self::Signature { + Signature(self.0.sign(msg)) + } + }; +} + +#[doc(hidden)] +#[cfg(not(feature = "full_crypto"))] +#[macro_export] +macro_rules! app_crypto_pair_functions_if_full_crypto { + ($pair:ty) => {}; +} + /// Declares `Public` type which is functionally equivalent to `$public` but is /// new application-specific type whose identifier is `$key_type`. /// For full functionality, `app_crypto_public_common!` must be called too. @@ -516,7 +467,6 @@ macro_rules! app_crypto_signature_not_full_crypto { $crate::RuntimeDebug, $crate::scale_info::TypeInfo, )] - #[derive(Hash)] pub struct Signature($sig); } From d0bf8bbf072b8e35ad7c0ac49cbd188484bf7987 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Mon, 20 Nov 2023 16:28:09 +0100 Subject: [PATCH 26/52] cargo.lock --- Cargo.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index e650c352832b..9ff0d197d9b5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17955,7 +17955,7 @@ version = "11.0.0" source = "git+https://github.com/paritytech/polkadot-sdk#82912acb33a9030c0ef3bf590a34fca09b72dc5f" dependencies = [ "Inflector", - "proc-macro-crate", + "proc-macro-crate 1.3.1", "proc-macro2", "quote", "syn 2.0.38", From 5783730b345e00345f67dc480c8b2c36b6f3c89b Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Mon, 20 Nov 2023 16:28:56 +0100 Subject: [PATCH 27/52] Update substrate/primitives/core/Cargo.toml Co-authored-by: Davide Galassi --- substrate/primitives/core/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/primitives/core/Cargo.toml b/substrate/primitives/core/Cargo.toml index daeb96238c7b..1751cc0b6ae4 100644 --- a/substrate/primitives/core/Cargo.toml +++ b/substrate/primitives/core/Cargo.toml @@ -26,7 +26,7 @@ bs58 = { version = "0.5.0", default-features = false, optional = true } rand = { version = "0.8.5", features = ["small_rng"], optional = true } substrate-bip39 = "0.4.5" bip39 = { git = "https://github.com/michalkucharczyk/rust-bip39", branch="mku-unicode-normalization-in-no-std", version = "2.0.0", default-features = false, features = [ "alloc" ] } -regex = { version = "1.6.0",default-features = false, features = ["unicode-perl"] } +regex = { version = "1.6.0", default-features = false, features = ["unicode-perl"] } zeroize = { version = "1.4.3", default-features = false } secrecy = { version = "0.8.0", default-features = false, features = ["alloc"] } parking_lot = { version = "0.12.1", optional = true } From 7d55ce2b6f0e61808b3dea8330bfbb986b696605 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Mon, 20 Nov 2023 16:29:17 +0100 Subject: [PATCH 28/52] Update substrate/frame/support/procedural/Cargo.toml Co-authored-by: Davide Galassi --- substrate/frame/support/procedural/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/frame/support/procedural/Cargo.toml b/substrate/frame/support/procedural/Cargo.toml index 344c96c4b6da..33afb8dc003b 100644 --- a/substrate/frame/support/procedural/Cargo.toml +++ b/substrate/frame/support/procedural/Cargo.toml @@ -26,7 +26,7 @@ frame-support-procedural-tools = { path = "tools" } macro_magic = { version = "0.5.0", features = ["proc_support"] } proc-macro-warning = { version = "1.0.0", default-features = false } expander = "2.0.0" -sp-core-hashing = { path = "../../../primitives/core/hashing", default-features=false } +sp-core-hashing = { path = "../../../primitives/core/hashing", default-features = false } [features] default = [ "std" ] From 617593e80fbad33e879a01bfa42a7824c49eff71 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Mon, 20 Nov 2023 16:29:34 +0100 Subject: [PATCH 29/52] Update substrate/test-utils/runtime/Cargo.toml Co-authored-by: Davide Galassi --- substrate/test-utils/runtime/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/test-utils/runtime/Cargo.toml b/substrate/test-utils/runtime/Cargo.toml index 9ca19eeeef99..4a5b51b1c00b 100644 --- a/substrate/test-utils/runtime/Cargo.toml +++ b/substrate/test-utils/runtime/Cargo.toml @@ -23,7 +23,7 @@ scale-info = { version = "2.10.0", default-features = false, features = ["derive sp-inherents = { path = "../../primitives/inherents", default-features = false} sp-keyring = { path = "../../primitives/keyring", default-features = false} sp-offchain = { path = "../../primitives/offchain", default-features = false} -sp-core = { path = "../../primitives/core", default-features = false, features=["serde"]} +sp-core = { path = "../../primitives/core", default-features = false, features = ["serde"]} sp-std = { path = "../../primitives/std", default-features = false} sp-io = { path = "../../primitives/io", default-features = false } frame-support = { path = "../../frame/support", default-features = false} From 9b03603d4bf095f4479c9fea1248d4c0f2a8d8f9 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Mon, 20 Nov 2023 17:17:35 +0100 Subject: [PATCH 30/52] proc-macro-crate version reverted --- Cargo.lock | 58 ++++++------------- .../frame/support/procedural/tools/Cargo.toml | 2 +- 2 files changed, 20 insertions(+), 40 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9ff0d197d9b5..2b5eef15c476 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3962,7 +3962,7 @@ dependencies = [ name = "cumulus-pallet-parachain-system-proc-macro" version = "0.1.0" dependencies = [ - "proc-macro-crate 1.3.1", + "proc-macro-crate", "proc-macro2", "quote", "syn 2.0.38", @@ -5344,7 +5344,7 @@ checksum = "f5aa1e3ae159e592ad222dc90c5acbad632b527779ba88486abe92782ab268bd" dependencies = [ "expander 0.0.4", "indexmap 1.9.3", - "proc-macro-crate 1.3.1", + "proc-macro-crate", "proc-macro2", "quote", "syn 1.0.109", @@ -5668,7 +5668,7 @@ dependencies = [ "frame-election-provider-support", "frame-support", "parity-scale-codec", - "proc-macro-crate 1.3.1", + "proc-macro-crate", "proc-macro2", "quote", "scale-info", @@ -5833,7 +5833,7 @@ name = "frame-support-procedural-tools" version = "4.0.0-dev" dependencies = [ "frame-support-procedural-tools-derive", - "proc-macro-crate 2.0.0", + "proc-macro-crate", "proc-macro2", "quote", "syn 2.0.38", @@ -7103,7 +7103,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "44e8ab85614a08792b9bff6c8feee23be78c98d0182d4c622c05256ab553892a" dependencies = [ "heck", - "proc-macro-crate 1.3.1", + "proc-macro-crate", "proc-macro2", "quote", "syn 1.0.109", @@ -8538,7 +8538,7 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc076939022111618a5026d3be019fd8b366e76314538ff9a1b59ffbcbf98bcd" dependencies = [ - "proc-macro-crate 1.3.1", + "proc-macro-crate", "proc-macro-error", "proc-macro2", "quote", @@ -8867,7 +8867,7 @@ dependencies = [ "itertools 0.10.5", "tar", "tempfile", - "toml_edit 0.19.14", + "toml_edit", ] [[package]] @@ -9182,7 +9182,7 @@ dependencies = [ "itertools 0.11.0", "layout-rs", "petgraph", - "proc-macro-crate 1.3.1", + "proc-macro-crate", "proc-macro2", "quote", "syn 1.0.109", @@ -10983,7 +10983,7 @@ dependencies = [ name = "pallet-staking-reward-curve" version = "4.0.0-dev" dependencies = [ - "proc-macro-crate 1.3.1", + "proc-macro-crate", "proc-macro2", "quote", "sp-runtime", @@ -11587,7 +11587,7 @@ version = "3.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a296c3079b5fefbc499e1de58dc26c09b1b9a5952d26694ee89f04a43ebbb3e" dependencies = [ - "proc-macro-crate 1.3.1", + "proc-macro-crate", "proc-macro2", "quote", "syn 1.0.109", @@ -13805,16 +13805,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919" dependencies = [ "once_cell", - "toml_edit 0.19.14", -] - -[[package]] -name = "proc-macro-crate" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e8366a6159044a37876a2b9817124296703c586a5c92e2c53751fa06d8d43e8" -dependencies = [ - "toml_edit 0.20.2", + "toml_edit", ] [[package]] @@ -15145,7 +15136,7 @@ dependencies = [ name = "sc-chain-spec-derive" version = "4.0.0-dev" dependencies = [ - "proc-macro-crate 1.3.1", + "proc-macro-crate", "proc-macro2", "quote", "syn 2.0.38", @@ -16395,7 +16386,7 @@ dependencies = [ name = "sc-tracing-proc-macro" version = "4.0.0-dev" dependencies = [ - "proc-macro-crate 1.3.1", + "proc-macro-crate", "proc-macro2", "quote", "syn 2.0.38", @@ -16485,7 +16476,7 @@ version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "abf2c68b89cafb3b8d918dd07b42be0da66ff202cf1155c5739a4e0c1ea0dc19" dependencies = [ - "proc-macro-crate 1.3.1", + "proc-macro-crate", "proc-macro2", "quote", "syn 1.0.109", @@ -17269,7 +17260,7 @@ dependencies = [ "assert_matches", "blake2 0.10.6", "expander 2.0.0", - "proc-macro-crate 1.3.1", + "proc-macro-crate", "proc-macro2", "quote", "syn 2.0.38", @@ -17943,7 +17934,7 @@ name = "sp-runtime-interface-proc-macro" version = "11.0.0" dependencies = [ "Inflector", - "proc-macro-crate 1.3.1", + "proc-macro-crate", "proc-macro2", "quote", "syn 2.0.38", @@ -17955,7 +17946,7 @@ version = "11.0.0" source = "git+https://github.com/paritytech/polkadot-sdk#82912acb33a9030c0ef3bf590a34fca09b72dc5f" dependencies = [ "Inflector", - "proc-macro-crate 1.3.1", + "proc-macro-crate", "proc-macro2", "quote", "syn 2.0.38", @@ -19649,7 +19640,7 @@ dependencies = [ "serde", "serde_spanned", "toml_datetime", - "toml_edit 0.19.14", + "toml_edit", ] [[package]] @@ -19674,17 +19665,6 @@ dependencies = [ "winnow", ] -[[package]] -name = "toml_edit" -version = "0.20.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "396e4d48bbb2b7554c944bde63101b5ae446cff6ec4a24227428f15eb72ef338" -dependencies = [ - "indexmap 2.0.0", - "toml_datetime", - "winnow", -] - [[package]] name = "tower" version = "0.4.13" @@ -19786,7 +19766,7 @@ version = "1.0.0" dependencies = [ "assert_matches", "expander 2.0.0", - "proc-macro-crate 1.3.1", + "proc-macro-crate", "proc-macro2", "quote", "syn 2.0.38", diff --git a/substrate/frame/support/procedural/tools/Cargo.toml b/substrate/frame/support/procedural/tools/Cargo.toml index 853e443f010b..80aecd728219 100644 --- a/substrate/frame/support/procedural/tools/Cargo.toml +++ b/substrate/frame/support/procedural/tools/Cargo.toml @@ -12,7 +12,7 @@ description = "Proc macro helpers for procedural macros" targets = ["x86_64-unknown-linux-gnu"] [dependencies] -proc-macro-crate = "2.0.0" +proc-macro-crate = "1.3.1" proc-macro2 = "1.0.56" quote = "1.0.28" syn = { version = "2.0.38", features = ["full", "visit", "extra-traits"] } From 89a06e208415f30566722fe2e4cccf6e1d552752 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Mon, 20 Nov 2023 17:27:06 +0100 Subject: [PATCH 31/52] zepter fix --- substrate/primitives/keyring/Cargo.toml | 5 +---- substrate/test-utils/runtime/Cargo.toml | 1 + 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/substrate/primitives/keyring/Cargo.toml b/substrate/primitives/keyring/Cargo.toml index d8ea8b644613..f161c33a017b 100644 --- a/substrate/primitives/keyring/Cargo.toml +++ b/substrate/primitives/keyring/Cargo.toml @@ -21,10 +21,7 @@ sp-runtime = { path = "../runtime", default-features = false } [features] default = [ "std" ] -std = [ - "sp-core/std", - "sp-runtime/std", -] +std = [ "sp-core/std", "sp-runtime/std", "strum/std" ] # This feature adds Bandersnatch crypto primitives. # It should not be used in production since the implementation and interface may still diff --git a/substrate/test-utils/runtime/Cargo.toml b/substrate/test-utils/runtime/Cargo.toml index 4a5b51b1c00b..b4a3c1652a29 100644 --- a/substrate/test-utils/runtime/Cargo.toml +++ b/substrate/test-utils/runtime/Cargo.toml @@ -94,6 +94,7 @@ std = [ "sp-genesis-builder/std", "sp-inherents/std", "sp-io/std", + "sp-keyring/std", "sp-offchain/std", "sp-runtime/std", "sp-session/std", From bec4955774dbe30bbee7b483ffb4a5c2df4f8916 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Mon, 20 Nov 2023 21:44:07 +0100 Subject: [PATCH 32/52] CI features checks added --- .gitlab/pipeline/check.yml | 16 ++++++++++++++++ .../check-features-variants.sh | 12 ++++++++++++ .../primitives/core/check-features-variants.sh | 11 +++++++++++ .../keyring/check-features-variants.sh | 8 ++++++++ 4 files changed, 47 insertions(+) create mode 100755 substrate/primitives/application-crypto/check-features-variants.sh create mode 100755 substrate/primitives/core/check-features-variants.sh create mode 100755 substrate/primitives/keyring/check-features-variants.sh diff --git a/.gitlab/pipeline/check.yml b/.gitlab/pipeline/check.yml index 429491fb1742..49d08e975061 100644 --- a/.gitlab/pipeline/check.yml +++ b/.gitlab/pipeline/check.yml @@ -234,3 +234,19 @@ find-fail-ci-phrase: echo "No $ASSERT_REGEX was found, exiting with 0"; exit 0; fi + +check-core-crypto-features: + stage: check + extends: + - .docker-env + - .common-refs + script: + - pushd substrate/primitives/core + - ./check-features-variants.sh + - popd + - pushd substrate/primitives/application-crypto + - ./check-features-variants.sh + - popd + - pushd substrate/primitives/keyring + - ./check-features-variants.sh + - popd diff --git a/substrate/primitives/application-crypto/check-features-variants.sh b/substrate/primitives/application-crypto/check-features-variants.sh new file mode 100755 index 000000000000..42f4c1359092 --- /dev/null +++ b/substrate/primitives/application-crypto/check-features-variants.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env -S bash -eux + +export RUSTFLAGS="-Cdebug-assertions=y -Dwarnings" +T=wasm32-unknown-unknown + +T=wasm32-unknown-unknown +cargo check --release +cargo check --release --target=$T --no-default-features +cargo check --release --target=$T --no-default-features --features="full_crypto" +cargo check --release --target=$T --no-default-features --features="serde" +cargo check --release --target=$T --no-default-features --features="serde,full_crypto" +cargo check --release --target=$T --no-default-features --features="bandersnatch-experimental" diff --git a/substrate/primitives/core/check-features-variants.sh b/substrate/primitives/core/check-features-variants.sh new file mode 100755 index 000000000000..35780ef1af3e --- /dev/null +++ b/substrate/primitives/core/check-features-variants.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env -S bash -eux + +export RUSTFLAGS="-Cdebug-assertions=y -Dwarnings" +T=wasm32-unknown-unknown + +cargo check --target=$T --release --no-default-features --features="bandersnatch-experimental" +cargo check --target=$T --release --no-default-features --features="full_crypto,serde,bandersnatch-experimental" +cargo check --target=$T --release --no-default-features --features="full_crypto,serde" +cargo check --target=$T --release --no-default-features --features="full_crypto" +cargo check --target=$T --release --no-default-features --features="serde" +cargo check --target=$T --release --no-default-features diff --git a/substrate/primitives/keyring/check-features-variants.sh b/substrate/primitives/keyring/check-features-variants.sh new file mode 100755 index 000000000000..9c28d8358946 --- /dev/null +++ b/substrate/primitives/keyring/check-features-variants.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env -S bash -eux + +export RUSTFLAGS="-Cdebug-assertions=y -Dwarnings" +T=wasm32-unknown-unknown + +cargo check --release +cargo check --release --features="bandersnatch-experimental" +cargo check --release --target=$T --no-default-features From 7519e750d8379281dfb383438405de5a55eb5ccb Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Mon, 11 Dec 2023 16:09:11 +0100 Subject: [PATCH 33/52] Cargo.lock updated --- Cargo.lock | 3 --- 1 file changed, 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 84107f398486..bda244ae97d1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7072,9 +7072,6 @@ name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" -dependencies = [ - "spin 0.5.2", -] [[package]] name = "lazycell" From 4aa562b4524cfcf1f82c10ae96f1073b44f38d65 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Mon, 11 Dec 2023 16:14:06 +0100 Subject: [PATCH 34/52] make taplo happy --- substrate/frame/support/procedural/Cargo.toml | 4 ++-- substrate/primitives/core/Cargo.toml | 2 +- substrate/primitives/keyring/Cargo.toml | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/substrate/frame/support/procedural/Cargo.toml b/substrate/frame/support/procedural/Cargo.toml index b01d771aab8f..e3a9813958d2 100644 --- a/substrate/frame/support/procedural/Cargo.toml +++ b/substrate/frame/support/procedural/Cargo.toml @@ -32,8 +32,8 @@ sp-core-hashing = { path = "../../../primitives/core/hashing", default-features regex = "1" [features] -default = [ "std" ] -std = [ "sp-core-hashing/std" ] +default = ["std"] +std = ["sp-core-hashing/std"] no-metadata-docs = [] # Generate impl-trait for tuples with the given number of tuples. Will be needed as the number of # pallets in a runtime grows. Does increase the compile time! diff --git a/substrate/primitives/core/Cargo.toml b/substrate/primitives/core/Cargo.toml index 1dd19af0cb24..4b939a734b82 100644 --- a/substrate/primitives/core/Cargo.toml +++ b/substrate/primitives/core/Cargo.toml @@ -25,7 +25,7 @@ hash256-std-hasher = { version = "0.15.2", default-features = false } bs58 = { version = "0.5.0", default-features = false, optional = true } rand = { version = "0.8.5", features = ["small_rng"], optional = true } substrate-bip39 = "0.4.5" -bip39 = { git = "https://github.com/michalkucharczyk/rust-bip39", branch="mku-unicode-normalization-in-no-std", version = "2.0.0", default-features = false, features = [ "alloc" ] } +bip39 = { git = "https://github.com/michalkucharczyk/rust-bip39", branch = "mku-unicode-normalization-in-no-std", version = "2.0.0", default-features = false, features = ["alloc"] } zeroize = { version = "1.4.3", default-features = false } secrecy = { version = "0.8.0", default-features = false, features = ["alloc"] } parking_lot = { version = "0.12.1", optional = true } diff --git a/substrate/primitives/keyring/Cargo.toml b/substrate/primitives/keyring/Cargo.toml index 884b261e71c8..32de0df4f82f 100644 --- a/substrate/primitives/keyring/Cargo.toml +++ b/substrate/primitives/keyring/Cargo.toml @@ -19,8 +19,8 @@ sp-core = { path = "../core", default-features = false } sp-runtime = { path = "../runtime", default-features = false } [features] -default = [ "std" ] -std = [ "sp-core/std", "sp-runtime/std", "strum/std" ] +default = ["std"] +std = ["sp-core/std", "sp-runtime/std", "strum/std"] # This feature adds Bandersnatch crypto primitives. # It should not be used in production since the implementation and interface may still From 4b58e505e94e0d83aad80568ba0af2affa9b180a Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Wed, 20 Dec 2023 14:02:45 +0100 Subject: [PATCH 35/52] Cargo.lock updated --- Cargo.lock | 2 -- 1 file changed, 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5198ca88c005..b864a7a2752b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -16181,9 +16181,7 @@ dependencies = [ "arrayref", "arrayvec 0.5.2", "curve25519-dalek 2.1.3", - "getrandom 0.1.16", "merlin 2.0.1", - "rand 0.7.3", "rand_core 0.5.1", "sha2 0.8.2", "subtle 2.4.1", From 093b1052ff661146d92cfcdfb485356330b8820a Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 2 Jan 2024 11:54:43 +0100 Subject: [PATCH 36/52] Cargo.lock updated --- Cargo.lock | 226 +++++++++++++++++++++++++---------------------------- 1 file changed, 107 insertions(+), 119 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bce297e14681..f108046f6abe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -164,7 +164,7 @@ dependencies = [ "hex-literal", "itoa", "proptest", - "rand 0.8.5", + "rand", "ruint", "serde", "tiny-keccak", @@ -684,7 +684,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1df2c09229cbc5a028b1d70e00fdb2acee28b1055dfb5ca73eea49c5a25c4e7c" dependencies = [ "num-traits", - "rand 0.8.5", + "rand", ] [[package]] @@ -694,7 +694,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94893f1e0c6eeab764ade8dc4c0db24caf4fe7cbbaafc0eba0a9030f447b5185" dependencies = [ "num-traits", - "rand 0.8.5", + "rand", "rayon", ] @@ -1435,7 +1435,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "93f2635620bf0b9d4576eb7bb9a38a55df78bd1205d26fa994b25911a69f212f" dependencies = [ "bitcoin_hashes", - "rand 0.8.5", + "rand", + "rand_core 0.6.4", + "serde", + "unicode-normalization", +] + +[[package]] +name = "bip39" +version = "2.0.0" +source = "git+https://github.com/michalkucharczyk/rust-bip39?branch=mku-unicode-normalization-in-no-std#c62f91bafa9df991aee4e33d74566c5fadad7e01" +dependencies = [ + "bitcoin_hashes", + "rand", "rand_core 0.6.4", "serde", "unicode-normalization", @@ -3775,7 +3787,7 @@ dependencies = [ "polkadot-overseer", "polkadot-primitives", "portpicker", - "rand 0.8.5", + "rand", "sc-cli", "sc-client-api", "sc-consensus", @@ -3883,7 +3895,7 @@ dependencies = [ "parity-scale-codec", "polkadot-parachain-primitives", "polkadot-runtime-parachains", - "rand 0.8.5", + "rand", "sc-client-api", "scale-info", "sp-core", @@ -4190,7 +4202,7 @@ dependencies = [ "parity-scale-codec", "pin-project", "polkadot-overseer", - "rand 0.8.5", + "rand", "sc-client-api", "sc-rpc-api", "sc-service", @@ -4329,7 +4341,7 @@ dependencies = [ "polkadot-service", "polkadot-test-service", "portpicker", - "rand 0.8.5", + "rand", "rococo-parachain-runtime", "sc-basic-authorship", "sc-block-builder", @@ -5319,7 +5331,7 @@ dependencies = [ "num-traits", "parity-scale-codec", "parking_lot 0.12.1", - "rand 0.8.5", + "rand", "scale-info", ] @@ -5342,7 +5354,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "835c052cb0c08c1acf6ffd71c022172e18723949c8282f2b9f27efbc51e64534" dependencies = [ "byteorder", - "rand 0.8.5", + "rand", "rustc-hex", "static_assertions", ] @@ -5487,7 +5499,7 @@ dependencies = [ "linked-hash-map", "log", "parity-scale-codec", - "rand 0.8.5", + "rand", "rand_pcg", "sc-block-builder", "sc-cli", @@ -5553,7 +5565,7 @@ dependencies = [ "frame-support", "frame-system", "parity-scale-codec", - "rand 0.8.5", + "rand", "scale-info", "sp-arithmetic", "sp-core", @@ -5573,7 +5585,7 @@ dependencies = [ "frame-support", "honggfuzz", "parity-scale-codec", - "rand 0.8.5", + "rand", "scale-info", "sp-arithmetic", "sp-npos-elections", @@ -6077,7 +6089,7 @@ version = "0.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6ea1015b5a70616b688dc230cfe50c8af89d972cb132d5a622814d29773b10b9" dependencies = [ - "rand 0.8.5", + "rand", "rand_core 0.6.4", ] @@ -6865,7 +6877,7 @@ dependencies = [ "hyper", "jsonrpsee-types", "parking_lot 0.12.1", - "rand 0.8.5", + "rand", "rustc-hash", "serde", "serde_json", @@ -7322,7 +7334,7 @@ dependencies = [ "parking_lot 0.12.1", "pin-project", "quick-protobuf", - "rand 0.8.5", + "rand", "rw-stream-sink", "smallvec", "thiserror", @@ -7378,7 +7390,7 @@ dependencies = [ "multiaddr", "multihash 0.17.0", "quick-protobuf", - "rand 0.8.5", + "rand", "sha2 0.10.7", "thiserror", "zeroize", @@ -7403,7 +7415,7 @@ dependencies = [ "libp2p-swarm", "log", "quick-protobuf", - "rand 0.8.5", + "rand", "sha2 0.10.7", "smallvec", "thiserror", @@ -7425,7 +7437,7 @@ dependencies = [ "libp2p-identity", "libp2p-swarm", "log", - "rand 0.8.5", + "rand", "smallvec", "socket2 0.4.9", "tokio", @@ -7461,7 +7473,7 @@ dependencies = [ "log", "once_cell", "quick-protobuf", - "rand 0.8.5", + "rand", "sha2 0.10.7", "snow", "static_assertions", @@ -7483,7 +7495,7 @@ dependencies = [ "libp2p-core", "libp2p-swarm", "log", - "rand 0.8.5", + "rand", "void", ] @@ -7503,7 +7515,7 @@ dependencies = [ "log", "parking_lot 0.12.1", "quinn-proto", - "rand 0.8.5", + "rand", "rustls 0.20.8", "thiserror", "tokio", @@ -7521,7 +7533,7 @@ dependencies = [ "libp2p-core", "libp2p-identity", "libp2p-swarm", - "rand 0.8.5", + "rand", "smallvec", ] @@ -7540,7 +7552,7 @@ dependencies = [ "libp2p-identity", "libp2p-swarm-derive", "log", - "rand 0.8.5", + "rand", "smallvec", "tokio", "void", @@ -7666,7 +7678,7 @@ dependencies = [ "libsecp256k1-core", "libsecp256k1-gen-ecmult", "libsecp256k1-gen-genmult", - "rand 0.8.5", + "rand", "serde", "sha2 0.9.9", "typenum", @@ -8051,7 +8063,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "69672161530e8aeca1d1400fbf3f1a1747ff60ea604265a4e906c2442df20532" dependencies = [ "futures", - "rand 0.8.5", + "rand", "thrift", ] @@ -8064,7 +8076,7 @@ dependencies = [ "hex", "lazy_static", "parity-scale-codec", - "rand 0.8.5", + "rand", "scale-info", "zeroize", ] @@ -8170,7 +8182,7 @@ dependencies = [ "lioness", "log", "parking_lot 0.12.1", - "rand 0.8.5", + "rand", "rand_chacha 0.3.1", "rand_distr", "subtle 2.4.1", @@ -8427,7 +8439,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7bddcd3bf5144b6392de80e04c347cd7fab2508f6df16a85fc496ecd5cec39bc" dependencies = [ "clap 3.2.25", - "rand 0.8.5", + "rand", ] [[package]] @@ -8562,7 +8574,7 @@ dependencies = [ "node-primitives", "node-testing", "parity-db", - "rand 0.8.5", + "rand", "sc-basic-authorship", "sc-client-api", "sc-transaction-pool", @@ -9263,7 +9275,7 @@ dependencies = [ "frame-election-provider-support", "honggfuzz", "pallet-bags-list", - "rand 0.8.5", + "rand", ] [[package]] @@ -9509,7 +9521,7 @@ dependencies = [ "pallet-session", "pallet-timestamp", "parity-scale-codec", - "rand 0.8.5", + "rand", "scale-info", "sp-consensus-aura", "sp-core", @@ -9577,7 +9589,7 @@ dependencies = [ "pallet-utility", "parity-scale-codec", "pretty_assertions", - "rand 0.8.5", + "rand", "rand_pcg", "scale-info", "serde", @@ -9797,7 +9809,7 @@ dependencies = [ "pallet-election-provider-support-benchmarking", "parity-scale-codec", "parking_lot 0.12.1", - "rand 0.8.5", + "rand", "scale-info", "sp-arithmetic", "sp-core", @@ -10133,7 +10145,7 @@ dependencies = [ "frame-system", "log", "parity-scale-codec", - "rand 0.8.5", + "rand", "rand_distr", "scale-info", "serde", @@ -10347,7 +10359,7 @@ dependencies = [ "honggfuzz", "log", "pallet-nomination-pools", - "rand 0.8.5", + "rand", "sp-io", "sp-runtime", "sp-tracing 10.0.0", @@ -10740,7 +10752,7 @@ dependencies = [ "pallet-staking-reward-curve", "pallet-timestamp", "parity-scale-codec", - "rand 0.8.5", + "rand", "scale-info", "sp-core", "sp-io", @@ -11427,7 +11439,7 @@ dependencies = [ "lz4", "memmap2", "parking_lot 0.12.1", - "rand 0.8.5", + "rand", "siphasher", "snap", ] @@ -12083,7 +12095,7 @@ dependencies = [ "polkadot-node-subsystem-util", "polkadot-primitives", "polkadot-primitives-test-helpers", - "rand 0.8.5", + "rand", "rand_chacha 0.3.1", "rand_core 0.6.4", "schnorrkel 0.11.4", @@ -12109,7 +12121,7 @@ dependencies = [ "polkadot-node-subsystem-test-helpers", "polkadot-node-subsystem-util", "polkadot-primitives", - "rand 0.8.5", + "rand", "rand_chacha 0.3.1", "sp-application-crypto", "sp-authority-discovery", @@ -12137,7 +12149,7 @@ dependencies = [ "polkadot-node-subsystem-util", "polkadot-primitives", "polkadot-primitives-test-helpers", - "rand 0.8.5", + "rand", "sc-network", "schnellru", "sp-core", @@ -12168,7 +12180,7 @@ dependencies = [ "polkadot-node-subsystem-util", "polkadot-primitives", "polkadot-primitives-test-helpers", - "rand 0.8.5", + "rand", "sc-network", "schnellru", "sp-application-crypto", @@ -12311,7 +12323,7 @@ dependencies = [ "polkadot-node-subsystem-util", "polkadot-primitives", "quickcheck", - "rand 0.8.5", + "rand", "rand_chacha 0.3.1", "sc-network", "sc-network-common", @@ -12401,7 +12413,7 @@ dependencies = [ "polkadot-overseer", "polkadot-primitives", "polkadot-primitives-test-helpers", - "rand 0.8.5", + "rand", "rand_chacha 0.3.1", "rand_core 0.6.4", "sc-keystore", @@ -12673,7 +12685,7 @@ dependencies = [ "polkadot-parachain-primitives", "polkadot-primitives", "procfs", - "rand 0.8.5", + "rand", "rococo-runtime", "rusty-fork", "sc-sysinfo", @@ -12857,7 +12869,7 @@ dependencies = [ "polkadot-node-jaeger", "polkadot-node-primitives", "polkadot-primitives", - "rand 0.8.5", + "rand", "rand_chacha 0.3.1", "sc-authority-discovery", "sc-network", @@ -12978,7 +12990,7 @@ dependencies = [ "polkadot-primitives", "polkadot-primitives-test-helpers", "prioritized-metered-channel", - "rand 0.8.5", + "rand", "sc-client-api", "schnellru", "sp-application-crypto", @@ -13157,7 +13169,7 @@ name = "polkadot-primitives-test-helpers" version = "1.0.0" dependencies = [ "polkadot-primitives", - "rand 0.8.5", + "rand", "sp-application-crypto", "sp-core", "sp-keyring", @@ -13296,7 +13308,7 @@ dependencies = [ "polkadot-primitives", "polkadot-primitives-test-helpers", "polkadot-runtime-metrics", - "rand 0.8.5", + "rand", "rand_chacha 0.3.1", "rustc-hex", "sc-keystore", @@ -13562,7 +13574,7 @@ dependencies = [ "prometheus", "pyroscope", "pyroscope_pprofrs", - "rand 0.8.5", + "rand", "sc-keystore", "sc-network", "sc-service", @@ -13630,7 +13642,7 @@ dependencies = [ "polkadot-node-subsystem-types", "polkadot-node-subsystem-util", "polkadot-primitives", - "rand 0.8.5", + "rand", "sp-core", "sp-keystore", "substrate-build-script-utils", @@ -13723,7 +13735,7 @@ dependencies = [ "polkadot-runtime-parachains", "polkadot-service", "polkadot-test-runtime", - "rand 0.8.5", + "rand", "sc-authority-discovery", "sc-chain-spec", "sc-cli", @@ -13839,7 +13851,7 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "be97d76faf1bfab666e1375477b23fde79eccf0276e9b63b92a39d676a889ba9" dependencies = [ - "rand 0.8.5", + "rand", ] [[package]] @@ -14127,7 +14139,7 @@ dependencies = [ "bitflags 2.4.0", "lazy_static", "num-traits", - "rand 0.8.5", + "rand", "rand_chacha 0.3.1", "rand_xorshift", "regex-syntax 0.8.2", @@ -14265,7 +14277,7 @@ checksum = "588f6378e4dd99458b60ec275b4477add41ce4fa9f64dcba6f15adccb19b50d6" dependencies = [ "env_logger 0.8.4", "log", - "rand 0.8.5", + "rand", ] [[package]] @@ -14286,7 +14298,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c956be1b23f4261676aed05a0046e204e8a6836e50203902683a718af0797989" dependencies = [ "bytes", - "rand 0.8.5", + "rand", "ring 0.16.20", "rustc-hash", "rustls 0.20.8", @@ -14312,19 +14324,6 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" -[[package]] -name = "rand" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" -dependencies = [ - "getrandom 0.1.16", - "libc", - "rand_chacha 0.2.2", - "rand_core 0.5.1", - "rand_hc", -] - [[package]] name = "rand" version = "0.8.5" @@ -14381,16 +14380,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32cb0b9bc82b0a0876c2dd994a7e7a2683d3e7390ca40e6886785ef0c7e3ee31" dependencies = [ "num-traits", - "rand 0.8.5", -] - -[[package]] -name = "rand_hc" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" -dependencies = [ - "rand_core 0.5.1", + "rand", ] [[package]] @@ -14990,7 +14980,7 @@ dependencies = [ "parity-scale-codec", "primitive-types", "proptest", - "rand 0.8.5", + "rand", "rlp", "ruint-macro", "serde", @@ -15263,7 +15253,7 @@ dependencies = [ "prost", "prost-build", "quickcheck", - "rand 0.8.5", + "rand", "sc-client-api", "sc-network", "sp-api", @@ -15362,7 +15352,7 @@ name = "sc-cli" version = "0.10.0-dev" dependencies = [ "array-bytes 6.1.0", - "bip39", + "bip39 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "chrono", "clap 4.4.11", "fdlimit", @@ -15373,7 +15363,7 @@ dependencies = [ "log", "names", "parity-scale-codec", - "rand 0.8.5", + "rand", "regex", "rpassword", "sc-client-api", @@ -15446,7 +15436,7 @@ dependencies = [ "parity-scale-codec", "parking_lot 0.12.1", "quickcheck", - "rand 0.8.5", + "rand", "sc-client-api", "sc-state-db", "schnellru", @@ -15685,7 +15675,7 @@ dependencies = [ "log", "parity-scale-codec", "parking_lot 0.12.1", - "rand 0.8.5", + "rand", "sc-block-builder", "sc-chain-spec", "sc-client-api", @@ -15981,7 +15971,7 @@ dependencies = [ "parking_lot 0.12.1", "partial_sort", "pin-project", - "rand 0.8.5", + "rand", "sc-client-api", "sc-network-common", "sc-network-light", @@ -16164,7 +16154,7 @@ dependencies = [ "libp2p", "log", "parking_lot 0.12.1", - "rand 0.8.5", + "rand", "sc-block-builder", "sc-client-api", "sc-consensus", @@ -16220,7 +16210,7 @@ dependencies = [ "once_cell", "parity-scale-codec", "parking_lot 0.12.1", - "rand 0.8.5", + "rand", "sc-block-builder", "sc-client-api", "sc-client-db", @@ -16388,7 +16378,7 @@ dependencies = [ "parity-scale-codec", "parking_lot 0.12.1", "pin-project", - "rand 0.8.5", + "rand", "sc-chain-spec", "sc-client-api", "sc-client-db", @@ -16543,7 +16533,7 @@ dependencies = [ "futures", "libc", "log", - "rand 0.8.5", + "rand", "rand_pcg", "regex", "sc-telemetry", @@ -16565,7 +16555,7 @@ dependencies = [ "log", "parking_lot 0.12.1", "pin-project", - "rand 0.8.5", + "rand", "sc-utils", "serde", "serde_json", @@ -16756,9 +16746,7 @@ dependencies = [ "arrayref", "arrayvec 0.5.2", "curve25519-dalek 2.1.3", - "getrandom 0.1.16", "merlin 2.0.1", - "rand 0.7.3", "rand_core 0.5.1", "sha2 0.8.2", "subtle 2.4.1", @@ -17384,7 +17372,7 @@ dependencies = [ "async-lock", "atomic-take", "base64 0.21.2", - "bip39", + "bip39 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "blake2-rfc", "bs58 0.5.0", "chacha20 0.9.1", @@ -17410,7 +17398,7 @@ dependencies = [ "pbkdf2 0.12.2", "pin-project", "poly1305 0.8.0", - "rand 0.8.5", + "rand", "rand_chacha 0.3.1", "ruzstd", "schnorrkel 0.10.2", @@ -17453,7 +17441,7 @@ dependencies = [ "no-std-net", "parking_lot 0.12.1", "pin-project", - "rand 0.8.5", + "rand", "rand_chacha 0.3.1", "serde", "serde_json", @@ -17544,7 +17532,7 @@ dependencies = [ "hex-literal", "parity-bytes", "parity-scale-codec", - "rand 0.8.5", + "rand", "rlp", "rustc-hex", "scale-info", @@ -17571,7 +17559,7 @@ dependencies = [ "log", "pallet-timestamp", "parity-scale-codec", - "rand 0.8.5", + "rand", "rlp", "scale-info", "serde", @@ -17872,7 +17860,7 @@ dependencies = [ "http", "httparse", "log", - "rand 0.8.5", + "rand", "sha-1 0.9.8", ] @@ -17966,7 +17954,7 @@ dependencies = [ "num-traits", "parity-scale-codec", "primitive-types", - "rand 0.8.5", + "rand", "scale-info", "serde", "sp-core", @@ -18171,7 +18159,7 @@ version = "21.0.0" dependencies = [ "array-bytes 6.1.0", "bandersnatch_vrfs", - "bip39", + "bip39 2.0.0 (git+https://github.com/michalkucharczyk/rust-bip39?branch=mku-unicode-normalization-in-no-std)", "bitflags 1.3.2", "blake2 0.10.6", "bounded-collections", @@ -18192,7 +18180,7 @@ dependencies = [ "parking_lot 0.12.1", "paste", "primitive-types", - "rand 0.8.5", + "rand", "regex", "scale-info", "schnorrkel 0.11.4", @@ -18397,7 +18385,7 @@ version = "0.27.0" dependencies = [ "parity-scale-codec", "parking_lot 0.12.1", - "rand 0.8.5", + "rand", "rand_chacha 0.2.2", "sp-core", "sp-externalities 0.19.0", @@ -18456,7 +18444,7 @@ name = "sp-npos-elections" version = "4.0.0-dev" dependencies = [ "parity-scale-codec", - "rand 0.8.5", + "rand", "scale-info", "serde", "sp-arithmetic", @@ -18472,7 +18460,7 @@ version = "2.0.0-alpha.5" dependencies = [ "clap 4.4.11", "honggfuzz", - "rand 0.8.5", + "rand", "sp-npos-elections", "sp-runtime", ] @@ -18516,7 +18504,7 @@ dependencies = [ "log", "parity-scale-codec", "paste", - "rand 0.8.5", + "rand", "scale-info", "serde", "serde_json", @@ -18675,7 +18663,7 @@ dependencies = [ "parity-scale-codec", "parking_lot 0.12.1", "pretty_assertions", - "rand 0.8.5", + "rand", "smallvec", "sp-core", "sp-externalities 0.19.0", @@ -18697,7 +18685,7 @@ dependencies = [ "ed25519-dalek", "hkdf", "parity-scale-codec", - "rand 0.8.5", + "rand", "scale-info", "sha2 0.10.7", "sp-api", @@ -18828,7 +18816,7 @@ dependencies = [ "nohash-hasher", "parity-scale-codec", "parking_lot 0.12.1", - "rand 0.8.5", + "rand", "scale-info", "schnellru", "sp-core", @@ -19035,7 +19023,7 @@ dependencies = [ "pallet-treasury", "parity-scale-codec", "platforms", - "rand 0.8.5", + "rand", "regex", "sc-authority-discovery", "sc-basic-authorship", @@ -19320,9 +19308,9 @@ dependencies = [ [[package]] name = "substrate-bip39" -version = "0.4.4" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49eee6965196b32f882dd2ee85a92b1dbead41b04e53907f269de3b0dc04733c" +checksum = "e620c7098893ba667438b47169c00aacdd9e7c10e042250ce2b60b087ec97328" dependencies = [ "hmac 0.11.0", "pbkdf2 0.8.0", @@ -20142,7 +20130,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f57eb36ecbe0fc510036adff84824dd3c24bb781e21bfa67b69d556aa85214f" dependencies = [ "pin-project", - "rand 0.8.5", + "rand", "tokio", ] @@ -20491,7 +20479,7 @@ dependencies = [ "idna 0.2.3", "ipnet", "lazy_static", - "rand 0.8.5", + "rand", "smallvec", "socket2 0.4.9", "thiserror", @@ -20602,7 +20590,7 @@ dependencies = [ "http", "httparse", "log", - "rand 0.8.5", + "rand", "sha-1 0.10.1", "thiserror", "url", @@ -20617,7 +20605,7 @@ checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675" dependencies = [ "cfg-if", "digest 0.10.7", - "rand 0.8.5", + "rand", "static_assertions", ] @@ -20832,7 +20820,7 @@ dependencies = [ "arrayref", "constcat", "digest 0.10.7", - "rand 0.8.5", + "rand", "rand_chacha 0.3.1", "rand_core 0.6.4", "sha2 0.10.7", @@ -21286,7 +21274,7 @@ dependencies = [ "memfd", "memoffset 0.8.0", "paste", - "rand 0.8.5", + "rand", "rustix 0.36.15", "wasmtime-asm-macros", "wasmtime-environ", @@ -21996,7 +21984,7 @@ dependencies = [ "log", "nohash-hasher", "parking_lot 0.12.1", - "rand 0.8.5", + "rand", "static_assertions", ] From 7029890ea4b8a1862ad7695d3feba49b483b1d34 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 16 Jan 2024 11:13:25 +0100 Subject: [PATCH 37/52] Update substrate/primitives/application-crypto/check-features-variants.sh Co-authored-by: Davide Galassi --- .../primitives/application-crypto/check-features-variants.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/substrate/primitives/application-crypto/check-features-variants.sh b/substrate/primitives/application-crypto/check-features-variants.sh index 42f4c1359092..05e103b33ea1 100755 --- a/substrate/primitives/application-crypto/check-features-variants.sh +++ b/substrate/primitives/application-crypto/check-features-variants.sh @@ -1,8 +1,6 @@ #!/usr/bin/env -S bash -eux export RUSTFLAGS="-Cdebug-assertions=y -Dwarnings" -T=wasm32-unknown-unknown - T=wasm32-unknown-unknown cargo check --release cargo check --release --target=$T --no-default-features From 3879d354e5689c123d538f3e2dc63ad64f314f69 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Thu, 1 Feb 2024 12:03:50 +0100 Subject: [PATCH 38/52] Cargo.lock updated --- Cargo.lock | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 724707321158..284480f2efd6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1413,6 +1413,18 @@ name = "bip39" version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "93f2635620bf0b9d4576eb7bb9a38a55df78bd1205d26fa994b25911a69f212f" +dependencies = [ + "bitcoin_hashes", + "rand", + "rand_core 0.5.1", + "serde", + "unicode-normalization", +] + +[[package]] +name = "bip39" +version = "2.0.0" +source = "git+https://github.com/michalkucharczyk/rust-bip39?branch=mku-unicode-normalization-in-no-std#c62f91bafa9df991aee4e33d74566c5fadad7e01" dependencies = [ "bitcoin_hashes", "rand", @@ -15353,7 +15365,7 @@ name = "sc-cli" version = "0.36.0" dependencies = [ "array-bytes 6.1.0", - "bip39", + "bip39 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "chrono", "clap 4.4.18", "fdlimit", @@ -17381,7 +17393,7 @@ dependencies = [ "async-lock", "atomic-take", "base64 0.21.2", - "bip39", + "bip39 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "blake2-rfc", "bs58 0.5.0", "chacha20 0.9.1", @@ -18216,7 +18228,7 @@ version = "28.0.0" dependencies = [ "array-bytes 6.1.0", "bandersnatch_vrfs", - "bip39", + "bip39 2.0.0 (git+https://github.com/michalkucharczyk/rust-bip39?branch=mku-unicode-normalization-in-no-std)", "bitflags 1.3.2", "blake2 0.10.6", "bounded-collections", From d1661db5ca6b3b653cf0fb53b74c0947de20546c Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Thu, 1 Feb 2024 18:25:34 +0100 Subject: [PATCH 39/52] fix --- Cargo.lock | 6 +----- substrate/client/cli/Cargo.toml | 3 ++- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 284480f2efd6..5983da58dbe2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1415,10 +1415,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "93f2635620bf0b9d4576eb7bb9a38a55df78bd1205d26fa994b25911a69f212f" dependencies = [ "bitcoin_hashes", - "rand", - "rand_core 0.5.1", - "serde", - "unicode-normalization", ] [[package]] @@ -15365,7 +15361,7 @@ name = "sc-cli" version = "0.36.0" dependencies = [ "array-bytes 6.1.0", - "bip39 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "bip39 2.0.0 (git+https://github.com/michalkucharczyk/rust-bip39?branch=mku-unicode-normalization-in-no-std)", "chrono", "clap 4.4.18", "fdlimit", diff --git a/substrate/client/cli/Cargo.toml b/substrate/client/cli/Cargo.toml index 7e08c8c5830a..a5e5dec78e60 100644 --- a/substrate/client/cli/Cargo.toml +++ b/substrate/client/cli/Cargo.toml @@ -32,7 +32,8 @@ rpassword = "7.0.0" serde = "1.0.195" serde_json = "1.0.111" thiserror = "1.0.48" -bip39 = { version = "2.0.0", features = ["rand"] } +# personal fork here as workaround for: https://github.com/rust-bitcoin/rust-bip39/pull/64 +bip39 = { features = ["rand"], git = "https://github.com/michalkucharczyk/rust-bip39.git", branch = "mku-unicode-normalization-in-no-std" } tokio = { version = "1.22.0", features = ["parking_lot", "rt-multi-thread", "signal"] } sc-client-api = { path = "../api" } sc-client-db = { path = "../db", default-features = false } From 667eda6e15b40d21e79f87407642ba901d5f28a0 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Thu, 1 Feb 2024 18:41:57 +0100 Subject: [PATCH 40/52] clippy --- substrate/client/cli/src/commands/generate.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/client/cli/src/commands/generate.rs b/substrate/client/cli/src/commands/generate.rs index c465bcc85a47..94769279e219 100644 --- a/substrate/client/cli/src/commands/generate.rs +++ b/substrate/client/cli/src/commands/generate.rs @@ -64,7 +64,7 @@ impl GenerateCmd { let password = self.keystore_params.read_password()?; let output = self.output_scheme.output_type; - let phrase = mnemonic.word_iter().join(" "); + let phrase = mnemonic.words().join(" "); with_crypto_scheme!( self.crypto_scheme.scheme, From 2eaa0d0be08dfe3c8aabb5c727d9fcc0b0f68367 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Fri, 2 Feb 2024 09:42:54 +0100 Subject: [PATCH 41/52] Update substrate/primitives/core/src/address_uri.rs Co-authored-by: Davide Galassi --- substrate/primitives/core/src/address_uri.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/primitives/core/src/address_uri.rs b/substrate/primitives/core/src/address_uri.rs index 7b4e1ea44073..2e32d0cd86df 100644 --- a/substrate/primitives/core/src/address_uri.rs +++ b/substrate/primitives/core/src/address_uri.rs @@ -17,7 +17,7 @@ //! Little util for parsing an address URI. Replaces regular expressions. -#[cfg(all(not(feature = "std")))] +#[cfg(not(feature = "std"))] use sp_std::{ alloc::string::{String, ToString}, vec::Vec, From 28ec96ca500113efa4072fe5826dad6b70030567 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Fri, 2 Feb 2024 09:48:01 +0100 Subject: [PATCH 42/52] review comments applied --- substrate/primitives/keyring/src/lib.rs | 4 ++-- substrate/test-utils/runtime/src/lib.rs | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/substrate/primitives/keyring/src/lib.rs b/substrate/primitives/keyring/src/lib.rs index 08f84cb0f404..f753bf4b0dd6 100644 --- a/substrate/primitives/keyring/src/lib.rs +++ b/substrate/primitives/keyring/src/lib.rs @@ -15,10 +15,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -#![cfg_attr(not(feature = "std"), no_std)] - //! Support code for the runtime. A set of test accounts. +#![cfg_attr(not(feature = "std"), no_std)] + /// Test account crypto for sr25519. pub mod sr25519; diff --git a/substrate/test-utils/runtime/src/lib.rs b/substrate/test-utils/runtime/src/lib.rs index de814da4d6df..33fbe7e88c1f 100644 --- a/substrate/test-utils/runtime/src/lib.rs +++ b/substrate/test-utils/runtime/src/lib.rs @@ -725,8 +725,6 @@ impl_runtime_apis! { impl sp_genesis_builder::GenesisBuilder for Runtime { fn create_default_config() -> Vec { - log::info!("{:#?}", AccountKeyring::Alice.public().to_ss58check()); - log::info!("{:#?}", AccountKeyring::Bob.public().to_ss58check()); create_default_config::() } From 8508715455e5788a57887e2a667dde538b84fa23 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Fri, 2 Feb 2024 14:20:46 +0100 Subject: [PATCH 43/52] clippy --- substrate/test-utils/runtime/src/lib.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/substrate/test-utils/runtime/src/lib.rs b/substrate/test-utils/runtime/src/lib.rs index 33fbe7e88c1f..8bc6f72a82ec 100644 --- a/substrate/test-utils/runtime/src/lib.rs +++ b/substrate/test-utils/runtime/src/lib.rs @@ -74,8 +74,6 @@ pub use pallet_balances::Call as BalancesCall; pub type AuraId = sp_consensus_aura::sr25519::AuthorityId; #[cfg(feature = "std")] pub use extrinsic::{ExtrinsicBuilder, Transfer}; -use sp_application_crypto::Ss58Codec; -use sp_keyring::AccountKeyring; const LOG_TARGET: &str = "substrate-test-runtime"; From 6cb449a49c4d6f78912d9ffd673e36b51213f48c Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Fri, 2 Feb 2024 14:23:54 +0100 Subject: [PATCH 44/52] bls + paired_crypto reworked --- .../check-features-variants.sh | 2 ++ .../application-crypto/src/bls377.rs | 5 ++--- .../application-crypto/src/ecdsa_bls377.rs | 1 + .../core/check-features-variants.sh | 2 ++ substrate/primitives/core/src/bls.rs | 19 +------------------ .../primitives/core/src/paired_crypto.rs | 18 +++--------------- 6 files changed, 11 insertions(+), 36 deletions(-) diff --git a/substrate/primitives/application-crypto/check-features-variants.sh b/substrate/primitives/application-crypto/check-features-variants.sh index 05e103b33ea1..dd45a212bae0 100755 --- a/substrate/primitives/application-crypto/check-features-variants.sh +++ b/substrate/primitives/application-crypto/check-features-variants.sh @@ -8,3 +8,5 @@ cargo check --release --target=$T --no-default-features --features="full_crypto cargo check --release --target=$T --no-default-features --features="serde" cargo check --release --target=$T --no-default-features --features="serde,full_crypto" cargo check --release --target=$T --no-default-features --features="bandersnatch-experimental" +cargo check --release --target=$T --no-default-features --features="bls-experimental" +cargo check --release --target=$T --no-default-features --features="bls-experimental,full_crypto" diff --git a/substrate/primitives/application-crypto/src/bls377.rs b/substrate/primitives/application-crypto/src/bls377.rs index ee17060564fa..3bd01de139c9 100644 --- a/substrate/primitives/application-crypto/src/bls377.rs +++ b/substrate/primitives/application-crypto/src/bls377.rs @@ -19,14 +19,13 @@ use crate::{KeyTypeId, RuntimePublic}; pub use sp_core::bls::bls377::*; +use sp_std::vec::Vec; mod app { crate::app_crypto!(super, sp_core::testing::BLS377); } -#[cfg(feature = "full_crypto")] -pub use app::Pair as AppPair; -pub use app::{Public as AppPublic, Signature as AppSignature}; +pub use app::{Pair as AppPair, Public as AppPublic, Signature as AppSignature}; impl RuntimePublic for Public { type Signature = Signature; diff --git a/substrate/primitives/application-crypto/src/ecdsa_bls377.rs b/substrate/primitives/application-crypto/src/ecdsa_bls377.rs index 70940587ceda..8dee73095fb2 100644 --- a/substrate/primitives/application-crypto/src/ecdsa_bls377.rs +++ b/substrate/primitives/application-crypto/src/ecdsa_bls377.rs @@ -18,6 +18,7 @@ //! ECDSA and BLS12-377 paired crypto applications. use crate::{KeyTypeId, RuntimePublic}; +use sp_std::vec::Vec; pub use sp_core::paired_crypto::ecdsa_bls377::*; diff --git a/substrate/primitives/core/check-features-variants.sh b/substrate/primitives/core/check-features-variants.sh index 35780ef1af3e..6d28212065a6 100755 --- a/substrate/primitives/core/check-features-variants.sh +++ b/substrate/primitives/core/check-features-variants.sh @@ -3,6 +3,8 @@ export RUSTFLAGS="-Cdebug-assertions=y -Dwarnings" T=wasm32-unknown-unknown +cargo check --target=$T --release --no-default-features --features="bls-experimental" +cargo check --target=$T --release --no-default-features --features="full_crypto,bls-experimental" cargo check --target=$T --release --no-default-features --features="bandersnatch-experimental" cargo check --target=$T --release --no-default-features --features="full_crypto,serde,bandersnatch-experimental" cargo check --target=$T --release --no-default-features --features="full_crypto,serde" diff --git a/substrate/primitives/core/src/bls.rs b/substrate/primitives/core/src/bls.rs index 452c6372d16b..089d35b44c77 100644 --- a/substrate/primitives/core/src/bls.rs +++ b/substrate/primitives/core/src/bls.rs @@ -20,10 +20,8 @@ #[cfg(feature = "serde")] use crate::crypto::Ss58Codec; use crate::crypto::{ByteArray, CryptoType, Derive, Public as TraitPublic, UncheckedFrom}; -#[cfg(feature = "full_crypto")] use crate::crypto::{DeriveError, DeriveJunction, Pair as TraitPair, SecretStringError}; -#[cfg(feature = "full_crypto")] use sp_std::vec::Vec; use codec::{Decode, Encode, MaxEncodedLen}; @@ -35,7 +33,6 @@ use serde::{de, Deserialize, Deserializer, Serialize, Serializer}; use sp_std::alloc::{format, string::String}; use w3f_bls::{DoublePublicKey, DoubleSignature, EngineBLS, SerializableToBytes, TinyBLS381}; -#[cfg(feature = "full_crypto")] use w3f_bls::{DoublePublicKeyScheme, Keypair, Message, SecretKey}; use sp_runtime_interface::pass_by::{self, PassBy, PassByInner}; @@ -51,7 +48,6 @@ pub mod bls377 { pub const CRYPTO_ID: CryptoTypeId = CryptoTypeId(*b"bls7"); /// BLS12-377 key pair. - #[cfg(feature = "full_crypto")] pub type Pair = super::Pair; /// BLS12-377 public key. pub type Public = super::Public; @@ -73,7 +69,6 @@ pub mod bls381 { pub const CRYPTO_ID: CryptoTypeId = CryptoTypeId(*b"bls8"); /// BLS12-381 key pair. - #[cfg(feature = "full_crypto")] pub type Pair = super::Pair; /// BLS12-381 public key. pub type Public = super::Public; @@ -90,7 +85,6 @@ trait BlsBound: EngineBLS + HardJunctionId + Send + Sync + 'static {} impl BlsBound for T {} /// Secret key serialized size -#[cfg(feature = "full_crypto")] const SECRET_KEY_SERIALIZED_SIZE: usize = as SerializableToBytes>::SERIALIZED_BYTES_SIZE; @@ -107,7 +101,6 @@ pub const SIGNATURE_SERIALIZED_SIZE: usize = /// It's not called a "secret key" because ring doesn't expose the secret keys /// of the key pair (yeah, dumb); as such we're forced to remember the seed manually if we /// will need it later (such as for HDKD). -#[cfg(feature = "full_crypto")] type Seed = [u8; SECRET_KEY_SERIALIZED_SIZE]; /// A public key. @@ -144,7 +137,6 @@ impl Ord for Public { } } -#[cfg(feature = "full_crypto")] impl sp_std::hash::Hash for Public { fn hash(&self, state: &mut H) { self.inner.hash(state) @@ -220,7 +212,6 @@ impl From> for [u8; PUBLIC_KEY_SERIALIZED_SIZE] { } } -#[cfg(feature = "full_crypto")] impl From> for Public { fn from(x: Pair) -> Self { x.public() @@ -290,7 +281,6 @@ impl TraitPublic for Public {} impl Derive for Public {} impl CryptoType for Public { - #[cfg(feature = "full_crypto")] type Pair = Pair; } @@ -316,7 +306,6 @@ impl PartialEq for Signature { impl Eq for Signature {} -#[cfg(feature = "full_crypto")] impl sp_std::hash::Hash for Signature { fn hash(&self, state: &mut H) { self.inner.hash(state) @@ -406,15 +395,12 @@ impl UncheckedFrom<[u8; SIGNATURE_SERIALIZED_SIZE]> for Signature { } impl CryptoType for Signature { - #[cfg(feature = "full_crypto")] type Pair = Pair; } /// A key pair. -#[cfg(feature = "full_crypto")] pub struct Pair(Keypair); -#[cfg(feature = "full_crypto")] impl Clone for Pair { fn clone(&self) -> Self { Pair(self.0.clone()) @@ -426,15 +412,12 @@ trait HardJunctionId { } /// Derive a single hard junction. -#[cfg(feature = "full_crypto")] fn derive_hard_junction(secret_seed: &Seed, cc: &[u8; 32]) -> Seed { (T::ID, secret_seed, cc).using_encoded(sp_crypto_hashing::blake2_256) } -#[cfg(feature = "full_crypto")] impl Pair {} -#[cfg(feature = "full_crypto")] impl TraitPair for Pair { type Seed = Seed; type Public = Public; @@ -473,6 +456,7 @@ impl TraitPair for Pair { Self::Public::unchecked_from(raw) } + #[cfg(feature = "full_crypto")] fn sign(&self, message: &[u8]) -> Self::Signature { let mut mutable_self = self.clone(); let r: [u8; SIGNATURE_SERIALIZED_SIZE] = @@ -516,7 +500,6 @@ impl TraitPair for Pair { } } -#[cfg(feature = "full_crypto")] impl CryptoType for Pair { type Pair = Pair; } diff --git a/substrate/primitives/core/src/paired_crypto.rs b/substrate/primitives/core/src/paired_crypto.rs index 960b8469249e..e12022ad2293 100644 --- a/substrate/primitives/core/src/paired_crypto.rs +++ b/substrate/primitives/core/src/paired_crypto.rs @@ -20,10 +20,8 @@ #[cfg(feature = "serde")] use crate::crypto::Ss58Codec; use crate::crypto::{ByteArray, CryptoType, Derive, Public as PublicT, UncheckedFrom}; -#[cfg(feature = "full_crypto")] use crate::crypto::{DeriveError, DeriveJunction, Pair as PairT, SecretStringError}; -#[cfg(feature = "full_crypto")] use sp_std::vec::Vec; use codec::{Decode, Encode, MaxEncodedLen}; @@ -40,10 +38,10 @@ use sp_std::convert::TryFrom; #[cfg(feature = "bls-experimental")] pub mod ecdsa_bls377 { #[cfg(feature = "full_crypto")] - use crate::Hasher; + use crate::{Hasher, crypto::{Pair as PairT, UncheckedFrom}}; use crate::{ bls377, - crypto::{CryptoTypeId, Pair as PairT, UncheckedFrom}, + crypto::{CryptoTypeId}, ecdsa, }; @@ -56,7 +54,6 @@ pub mod ecdsa_bls377 { ecdsa::SIGNATURE_SERIALIZED_SIZE + bls377::SIGNATURE_SERIALIZED_SIZE; /// (ECDSA,BLS12-377) key-pair pair. - #[cfg(feature = "full_crypto")] pub type Pair = super::Pair; /// (ECDSA,BLS12-377) public key pair. pub type Public = super::Public; @@ -64,16 +61,13 @@ pub mod ecdsa_bls377 { pub type Signature = super::Signature; impl super::CryptoType for Public { - #[cfg(feature = "full_crypto")] type Pair = Pair; } impl super::CryptoType for Signature { - #[cfg(feature = "full_crypto")] type Pair = Pair; } - #[cfg(feature = "full_crypto")] impl super::CryptoType for Pair { type Pair = Pair; } @@ -136,7 +130,6 @@ pub mod ecdsa_bls377 { /// Secure seed length. /// /// Currently only supporting sub-schemes whose seed is a 32-bytes array. -#[cfg(feature = "full_crypto")] const SECURE_SEED_LEN: usize = 32; /// A secret seed. @@ -144,14 +137,12 @@ const SECURE_SEED_LEN: usize = 32; /// It's not called a "secret key" because ring doesn't expose the secret keys /// of the key pair (yeah, dumb); as such we're forced to remember the seed manually if we /// will need it later (such as for HDKD). -#[cfg(feature = "full_crypto")] type Seed = [u8; SECURE_SEED_LEN]; /// A public key. #[derive(Clone, Encode, Decode, MaxEncodedLen, TypeInfo, PartialEq, Eq, PartialOrd, Ord)] pub struct Public([u8; LEFT_PLUS_RIGHT_LEN]); -#[cfg(feature = "full_crypto")] impl sp_std::hash::Hash for Public { fn hash(&self, state: &mut H) { self.0.hash(state); @@ -215,7 +206,6 @@ impl PassBy for Public { type PassBy = pass_by::Inner; } -#[cfg(feature = "full_crypto")] impl< LeftPair: PairT, RightPair: PairT, @@ -311,7 +301,6 @@ impl SignatureBound for T {} #[derive(Clone, Encode, Decode, MaxEncodedLen, TypeInfo, PartialEq, Eq)] pub struct Signature([u8; LEFT_PLUS_RIGHT_LEN]); -#[cfg(feature = "full_crypto")] impl sp_std::hash::Hash for Signature { fn hash(&self, state: &mut H) { self.0.hash(state); @@ -411,7 +400,6 @@ impl UncheckedFrom<[u8; LEFT_PLUS_RIGHT_LEN]> } /// A key pair. -#[cfg(feature = "full_crypto")] #[derive(Clone)] pub struct Pair< LeftPair: PairT, @@ -423,7 +411,6 @@ pub struct Pair< right: RightPair, } -#[cfg(feature = "full_crypto")] impl< LeftPair: PairT, RightPair: PairT, @@ -482,6 +469,7 @@ where Self::Public::unchecked_from(raw) } + #[cfg(feature = "full_crypto")] fn sign(&self, message: &[u8]) -> Self::Signature { let mut raw: [u8; SIGNATURE_LEN] = [0u8; SIGNATURE_LEN]; raw[..LeftPair::Signature::LEN].copy_from_slice(self.left.sign(message).as_ref()); From 86c7bc9b03e198c95df308173875530f2909288e Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Fri, 2 Feb 2024 13:29:23 +0000 Subject: [PATCH 45/52] ".git/.scripts/commands/fmt/fmt.sh" --- substrate/primitives/core/src/bls.rs | 12 ++++++++---- substrate/primitives/core/src/paired_crypto.rs | 13 +++++++------ 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/substrate/primitives/core/src/bls.rs b/substrate/primitives/core/src/bls.rs index 089d35b44c77..fcf8c53458c7 100644 --- a/substrate/primitives/core/src/bls.rs +++ b/substrate/primitives/core/src/bls.rs @@ -19,8 +19,10 @@ #[cfg(feature = "serde")] use crate::crypto::Ss58Codec; -use crate::crypto::{ByteArray, CryptoType, Derive, Public as TraitPublic, UncheckedFrom}; -use crate::crypto::{DeriveError, DeriveJunction, Pair as TraitPair, SecretStringError}; +use crate::crypto::{ + ByteArray, CryptoType, Derive, DeriveError, DeriveJunction, Pair as TraitPair, + Public as TraitPublic, SecretStringError, UncheckedFrom, +}; use sp_std::vec::Vec; @@ -32,8 +34,10 @@ use serde::{de, Deserialize, Deserializer, Serialize, Serializer}; #[cfg(all(not(feature = "std"), feature = "serde"))] use sp_std::alloc::{format, string::String}; -use w3f_bls::{DoublePublicKey, DoubleSignature, EngineBLS, SerializableToBytes, TinyBLS381}; -use w3f_bls::{DoublePublicKeyScheme, Keypair, Message, SecretKey}; +use w3f_bls::{ + DoublePublicKey, DoublePublicKeyScheme, DoubleSignature, EngineBLS, Keypair, Message, + SecretKey, SerializableToBytes, TinyBLS381, +}; use sp_runtime_interface::pass_by::{self, PassBy, PassByInner}; use sp_std::{convert::TryFrom, marker::PhantomData, ops::Deref}; diff --git a/substrate/primitives/core/src/paired_crypto.rs b/substrate/primitives/core/src/paired_crypto.rs index e12022ad2293..9168b31d5d8f 100644 --- a/substrate/primitives/core/src/paired_crypto.rs +++ b/substrate/primitives/core/src/paired_crypto.rs @@ -19,8 +19,10 @@ #[cfg(feature = "serde")] use crate::crypto::Ss58Codec; -use crate::crypto::{ByteArray, CryptoType, Derive, Public as PublicT, UncheckedFrom}; -use crate::crypto::{DeriveError, DeriveJunction, Pair as PairT, SecretStringError}; +use crate::crypto::{ + ByteArray, CryptoType, Derive, DeriveError, DeriveJunction, Pair as PairT, Public as PublicT, + SecretStringError, UncheckedFrom, +}; use sp_std::vec::Vec; @@ -37,12 +39,11 @@ use sp_std::convert::TryFrom; /// ECDSA and BLS12-377 paired crypto scheme #[cfg(feature = "bls-experimental")] pub mod ecdsa_bls377 { + use crate::{bls377, crypto::CryptoTypeId, ecdsa}; #[cfg(feature = "full_crypto")] - use crate::{Hasher, crypto::{Pair as PairT, UncheckedFrom}}; use crate::{ - bls377, - crypto::{CryptoTypeId}, - ecdsa, + crypto::{Pair as PairT, UncheckedFrom}, + Hasher, }; /// An identifier used to match public keys against BLS12-377 keys From e53f516bdc1b52958df733c84d8ca80195c3193e Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Sat, 9 Mar 2024 16:54:09 +0100 Subject: [PATCH 46/52] format --- substrate/primitives/core/src/ecdsa.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/substrate/primitives/core/src/ecdsa.rs b/substrate/primitives/core/src/ecdsa.rs index 0bfd6400f2dd..d0d00c84e2fc 100644 --- a/substrate/primitives/core/src/ecdsa.rs +++ b/substrate/primitives/core/src/ecdsa.rs @@ -27,7 +27,6 @@ use crate::crypto::{ ByteArray, CryptoType, CryptoTypeId, Derive, DeriveError, DeriveJunction, Pair as TraitPair, Public as TraitPublic, SecretStringError, UncheckedFrom, }; -use crate::crypto::{DeriveError, DeriveJunction, Pair as TraitPair, SecretStringError}; #[cfg(all(not(feature = "std"), feature = "full_crypto"))] use k256::ecdsa::SigningKey as SecretKey; From bf8455d98bc9e0507e209218dec04884eb118b79 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Sat, 9 Mar 2024 17:43:46 +0100 Subject: [PATCH 47/52] Cargo.lock --- Cargo.lock | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index bbde8e0ad3f7..473f701190a8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1435,6 +1435,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "93f2635620bf0b9d4576eb7bb9a38a55df78bd1205d26fa994b25911a69f212f" dependencies = [ "bitcoin_hashes", + "serde", + "unicode-normalization", ] [[package]] @@ -19751,7 +19753,7 @@ dependencies = [ name = "substrate-bip39" version = "0.4.7" dependencies = [ - "bip39", + "bip39 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "hmac 0.12.1", "pbkdf2", "rustc-hex", From 861ea0bd5fdb1f656d8be939ade4eb3f77906cde Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Sat, 9 Mar 2024 19:49:01 +0100 Subject: [PATCH 48/52] fixes --- substrate/primitives/core/Cargo.toml | 2 +- substrate/primitives/core/src/ecdsa.rs | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/substrate/primitives/core/Cargo.toml b/substrate/primitives/core/Cargo.toml index 7b79bdde2797..85269003abab 100644 --- a/substrate/primitives/core/Cargo.toml +++ b/substrate/primitives/core/Cargo.toml @@ -27,7 +27,7 @@ hash-db = { version = "0.16.0", default-features = false } hash256-std-hasher = { version = "0.15.2", default-features = false } bs58 = { version = "0.5.0", default-features = false, optional = true } rand = { version = "0.8.5", features = ["small_rng"], optional = true } -substrate-bip39 = { path = "../../utils/substrate-bip39" } +substrate-bip39 = { path = "../../utils/substrate-bip39", default-features = false } bip39 = { git = "https://github.com/michalkucharczyk/rust-bip39", branch = "mku-unicode-normalization-in-no-std", version = "2.0.0", default-features = false, features = ["alloc"] } zeroize = { version = "1.4.3", default-features = false } secrecy = { version = "0.8.0", default-features = false, features = ["alloc"] } diff --git a/substrate/primitives/core/src/ecdsa.rs b/substrate/primitives/core/src/ecdsa.rs index d0d00c84e2fc..3e3a4a7cf210 100644 --- a/substrate/primitives/core/src/ecdsa.rs +++ b/substrate/primitives/core/src/ecdsa.rs @@ -28,10 +28,8 @@ use crate::crypto::{ Public as TraitPublic, SecretStringError, UncheckedFrom, }; -#[cfg(all(not(feature = "std"), feature = "full_crypto"))] -use k256::ecdsa::SigningKey as SecretKey; #[cfg(not(feature = "std"))] -use k256::ecdsa::VerifyingKey; +use k256::ecdsa::{SigningKey as SecretKey, VerifyingKey}; #[cfg(all(feature = "std", feature = "full_crypto"))] use secp256k1::{ ecdsa::{RecoverableSignature, RecoveryId}, From 037f70c95ea7548495170bf41f55032a8f55247e Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Sat, 9 Mar 2024 21:07:53 +0100 Subject: [PATCH 49/52] ecdsa: more verify variants enabled w/o full_crypto --- substrate/primitives/core/Cargo.toml | 3 +-- substrate/primitives/core/src/ecdsa.rs | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/substrate/primitives/core/Cargo.toml b/substrate/primitives/core/Cargo.toml index 85269003abab..19a63a4d12d2 100644 --- a/substrate/primitives/core/Cargo.toml +++ b/substrate/primitives/core/Cargo.toml @@ -49,7 +49,7 @@ itertools = { version = "0.10.3", optional = true } array-bytes = { version = "6.1" } ed25519-zebra = { version = "3.1.0", default-features = false } blake2 = { version = "0.10.4", default-features = false, optional = true } -libsecp256k1 = { version = "0.7", default-features = false, features = ["static-context"], optional = true } +libsecp256k1 = { version = "0.7", default-features = false, features = ["static-context"] } schnorrkel = { version = "0.11.4", features = ["preaudit_deprecated"], default-features = false } merlin = { version = "3.0", default-features = false } sp-crypto-hashing = { path = "../crypto/hashing", default-features = false } @@ -145,7 +145,6 @@ serde = [ # For the regular wasm runtime builds this should not be used. full_crypto = [ "blake2", - "libsecp256k1", "sp-runtime-interface/disable_target_static_assertions", ] diff --git a/substrate/primitives/core/src/ecdsa.rs b/substrate/primitives/core/src/ecdsa.rs index 3e3a4a7cf210..9de3a3734494 100644 --- a/substrate/primitives/core/src/ecdsa.rs +++ b/substrate/primitives/core/src/ecdsa.rs @@ -505,7 +505,6 @@ impl Pair { /// Verify a signature on a pre-hashed message. Return `true` if the signature is valid /// and thus matches the given `public` key. - #[cfg(feature = "full_crypto")] pub fn verify_prehashed(sig: &Signature, message: &[u8; 32], public: &Public) -> bool { match sig.recover_prehashed(message) { Some(actual) => actual == *public, From c55ec33401a0db36f696db8b8dbcfa53379ebe07 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Sat, 9 Mar 2024 21:36:49 +0100 Subject: [PATCH 50/52] ecdsa: full_crypto guard removed where not needed --- substrate/primitives/core/src/ecdsa.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/substrate/primitives/core/src/ecdsa.rs b/substrate/primitives/core/src/ecdsa.rs index 9de3a3734494..fa071e1b03ff 100644 --- a/substrate/primitives/core/src/ecdsa.rs +++ b/substrate/primitives/core/src/ecdsa.rs @@ -30,7 +30,7 @@ use crate::crypto::{ #[cfg(not(feature = "std"))] use k256::ecdsa::{SigningKey as SecretKey, VerifyingKey}; -#[cfg(all(feature = "std", feature = "full_crypto"))] +#[cfg(feature = "std")] use secp256k1::{ ecdsa::{RecoverableSignature, RecoveryId}, Message, PublicKey, SecretKey, SECP256K1, @@ -373,7 +373,7 @@ impl From<(k256::ecdsa::Signature, k256::ecdsa::RecoveryId)> for Signature { } } -#[cfg(all(feature = "std", feature = "full_crypto"))] +#[cfg(feature = "std")] impl From for Signature { fn from(recsig: RecoverableSignature) -> Signature { let mut r = Self::default(); @@ -515,7 +515,6 @@ impl Pair { /// Verify a signature on a message. Returns true if the signature is good. /// Parses Signature using parse_overflowing_slice. #[deprecated(note = "please use `verify` instead")] - #[cfg(feature = "full_crypto")] pub fn verify_deprecated>(sig: &Signature, message: M, pubkey: &Public) -> bool { let message = libsecp256k1::Message::parse(&sp_crypto_hashing::blake2_256(message.as_ref())); @@ -542,7 +541,7 @@ impl Pair { // NOTE: this solution is not effective when `Pair` is moved around memory. // The very same problem affects other cryptographic backends that are just using // `zeroize`for their secrets. -#[cfg(all(feature = "std", feature = "full_crypto"))] +#[cfg(feature = "std")] impl Drop for Pair { fn drop(&mut self) { self.secret.non_secure_erase() From 4ec9e420d91a3189ce87440e8787a2959ca7943d Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 12 Mar 2024 11:21:33 +0100 Subject: [PATCH 51/52] Use parity-bip39 instead of git forks --- Cargo.lock | 57 +++++++++++++++++++--------- substrate/client/cli/Cargo.toml | 2 +- substrate/primitives/core/Cargo.toml | 3 +- 3 files changed, 43 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 473f701190a8..ee0f617480f2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1434,19 +1434,7 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "93f2635620bf0b9d4576eb7bb9a38a55df78bd1205d26fa994b25911a69f212f" dependencies = [ - "bitcoin_hashes", - "serde", - "unicode-normalization", -] - -[[package]] -name = "bip39" -version = "2.0.0" -source = "git+https://github.com/michalkucharczyk/rust-bip39?branch=mku-unicode-normalization-in-no-std#c62f91bafa9df991aee4e33d74566c5fadad7e01" -dependencies = [ - "bitcoin_hashes", - "rand", - "rand_core 0.6.4", + "bitcoin_hashes 0.11.0", "serde", "unicode-normalization", ] @@ -1466,12 +1454,28 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" +[[package]] +name = "bitcoin-internals" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9425c3bf7089c983facbae04de54513cce73b41c7f9ff8c845b54e7bc64ebbfb" + [[package]] name = "bitcoin_hashes" version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90064b8dee6815a6470d60bad07bbbaee885c0e12d04177138fa3291a01b7bc4" +[[package]] +name = "bitcoin_hashes" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1930a4dabfebb8d7d9992db18ebe3ae2876f0a305fab206fd168df931ede293b" +dependencies = [ + "bitcoin-internals", + "hex-conservative", +] + [[package]] name = "bitflags" version = "1.3.2" @@ -6358,6 +6362,12 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "hex-conservative" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30ed443af458ccb6d81c1e7e661545f94d3176752fb1df2f543b902a1e0f51e2" + [[package]] name = "hex-literal" version = "0.4.1" @@ -11421,6 +11431,19 @@ dependencies = [ "substrate-wasm-builder", ] +[[package]] +name = "parity-bip39" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e69bf016dc406eff7d53a7d3f7cf1c2e72c82b9088aac1118591e36dd2cd3e9" +dependencies = [ + "bitcoin_hashes 0.13.0", + "rand", + "rand_core 0.6.4", + "serde", + "unicode-normalization", +] + [[package]] name = "parity-bytes" version = "0.1.2" @@ -15641,7 +15664,6 @@ name = "sc-cli" version = "0.36.0" dependencies = [ "array-bytes 6.1.0", - "bip39 2.0.0 (git+https://github.com/michalkucharczyk/rust-bip39?branch=mku-unicode-normalization-in-no-std)", "chrono", "clap 4.5.1", "fdlimit", @@ -15651,6 +15673,7 @@ dependencies = [ "libp2p-identity", "log", "names", + "parity-bip39", "parity-scale-codec", "rand", "regex", @@ -17660,7 +17683,7 @@ dependencies = [ "async-lock 2.8.0", "atomic-take", "base64 0.21.2", - "bip39 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "bip39", "blake2-rfc", "bs58 0.5.0", "chacha20 0.9.1", @@ -18578,7 +18601,6 @@ version = "28.0.0" dependencies = [ "array-bytes 6.1.0", "bandersnatch_vrfs", - "bip39 2.0.0 (git+https://github.com/michalkucharczyk/rust-bip39?branch=mku-unicode-normalization-in-no-std)", "bitflags 1.3.2", "blake2 0.10.6", "bounded-collections", @@ -18596,6 +18618,7 @@ dependencies = [ "libsecp256k1", "log", "merlin", + "parity-bip39", "parity-scale-codec", "parking_lot 0.12.1", "paste", @@ -19753,7 +19776,7 @@ dependencies = [ name = "substrate-bip39" version = "0.4.7" dependencies = [ - "bip39 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "bip39", "hmac 0.12.1", "pbkdf2", "rustc-hex", diff --git a/substrate/client/cli/Cargo.toml b/substrate/client/cli/Cargo.toml index 9a899d2ad849..c70a0893c725 100644 --- a/substrate/client/cli/Cargo.toml +++ b/substrate/client/cli/Cargo.toml @@ -33,7 +33,7 @@ serde = { workspace = true, default-features = true } serde_json = { workspace = true, default-features = true } thiserror = { workspace = true } # personal fork here as workaround for: https://github.com/rust-bitcoin/rust-bip39/pull/64 -bip39 = { features = ["rand"], git = "https://github.com/michalkucharczyk/rust-bip39.git", branch = "mku-unicode-normalization-in-no-std" } +bip39 = { package = "parity-bip39", version = "2.0.1", features = ["rand"] } tokio = { version = "1.22.0", features = ["parking_lot", "rt-multi-thread", "signal"] } sc-client-api = { path = "../api" } sc-client-db = { path = "../db", default-features = false } diff --git a/substrate/primitives/core/Cargo.toml b/substrate/primitives/core/Cargo.toml index 19a63a4d12d2..b707d6139f2c 100644 --- a/substrate/primitives/core/Cargo.toml +++ b/substrate/primitives/core/Cargo.toml @@ -28,7 +28,8 @@ hash256-std-hasher = { version = "0.15.2", default-features = false } bs58 = { version = "0.5.0", default-features = false, optional = true } rand = { version = "0.8.5", features = ["small_rng"], optional = true } substrate-bip39 = { path = "../../utils/substrate-bip39", default-features = false } -bip39 = { git = "https://github.com/michalkucharczyk/rust-bip39", branch = "mku-unicode-normalization-in-no-std", version = "2.0.0", default-features = false, features = ["alloc"] } +# personal fork here as workaround for: https://github.com/rust-bitcoin/rust-bip39/pull/64 +bip39 = { package = "parity-bip39", version = "2.0.1", features = ["rand"] } zeroize = { version = "1.4.3", default-features = false } secrecy = { version = "0.8.0", default-features = false, features = ["alloc"] } parking_lot = { version = "0.12.1", optional = true } From 92fcab28e569df7d22256ba61497a45dd451d299 Mon Sep 17 00:00:00 2001 From: Michal Kucharczyk <1728078+michalkucharczyk@users.noreply.github.com> Date: Tue, 12 Mar 2024 11:32:42 +0100 Subject: [PATCH 52/52] fix --- substrate/primitives/core/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate/primitives/core/Cargo.toml b/substrate/primitives/core/Cargo.toml index b707d6139f2c..908f2498de53 100644 --- a/substrate/primitives/core/Cargo.toml +++ b/substrate/primitives/core/Cargo.toml @@ -29,7 +29,7 @@ bs58 = { version = "0.5.0", default-features = false, optional = true } rand = { version = "0.8.5", features = ["small_rng"], optional = true } substrate-bip39 = { path = "../../utils/substrate-bip39", default-features = false } # personal fork here as workaround for: https://github.com/rust-bitcoin/rust-bip39/pull/64 -bip39 = { package = "parity-bip39", version = "2.0.1", features = ["rand"] } +bip39 = { package = "parity-bip39", version = "2.0.1", default-features = false, features = ["alloc"] } zeroize = { version = "1.4.3", default-features = false } secrecy = { version = "0.8.0", default-features = false, features = ["alloc"] } parking_lot = { version = "0.12.1", optional = true }