From 85f19a54bf2a757c5dcbcd0e6bf688aee20e8584 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Tue, 20 Jul 2021 11:25:49 +0200 Subject: [PATCH 1/3] Update secp256k1 and remove unrequired usage --- Cargo.lock | 78 ++++++++++++++++++++++++++++----- runtime/common/Cargo.toml | 4 +- runtime/common/src/claims.rs | 32 +++++++------- runtime/kusama/Cargo.toml | 1 - runtime/parachains/Cargo.toml | 3 -- runtime/polkadot/Cargo.toml | 1 - runtime/test-runtime/Cargo.toml | 1 - runtime/westend/Cargo.toml | 1 - 8 files changed, 83 insertions(+), 38 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9d48d68a7fff..7f4e2e9aec42 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2688,6 +2688,17 @@ dependencies = [ "hmac 0.7.1", ] +[[package]] +name = "hmac-drbg" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17ea0a1394df5b6574da6e0c1ade9e78868c9fb0a4e5ef4428e32da4676b85b1" +dependencies = [ + "digest 0.9.0", + "generic-array 0.14.4", + "hmac 0.8.1", +] + [[package]] name = "hostname" version = "0.3.1" @@ -3363,7 +3374,6 @@ dependencies = [ "frame-system-rpc-runtime-api", "frame-try-runtime", "hex-literal", - "libsecp256k1", "log", "pallet-authority-discovery", "pallet-authorship", @@ -3582,7 +3592,7 @@ dependencies = [ "futures 0.3.15", "futures-timer 3.0.2", "lazy_static", - "libsecp256k1", + "libsecp256k1 0.3.5", "log", "multihash", "multistream-select", @@ -3984,13 +3994,61 @@ dependencies = [ "arrayref", "crunchy", "digest 0.8.1", - "hmac-drbg", + "hmac-drbg 0.2.0", "rand 0.7.3", "sha2 0.8.2", "subtle 2.2.3", "typenum", ] +[[package]] +name = "libsecp256k1" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9d220bc1feda2ac231cb78c3d26f27676b8cf82c96971f7aeef3d0cf2797c73" +dependencies = [ + "arrayref", + "base64 0.12.3", + "digest 0.9.0", + "hmac-drbg 0.3.0", + "libsecp256k1-core", + "libsecp256k1-gen-ecmult", + "libsecp256k1-gen-genmult", + "rand 0.7.3", + "serde", + "sha2 0.9.2", + "typenum", +] + +[[package]] +name = "libsecp256k1-core" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0f6ab710cec28cef759c5f18671a27dae2a5f952cdaaee1d8e2908cb2478a80" +dependencies = [ + "crunchy", + "digest 0.9.0", + "subtle 2.2.3", +] + +[[package]] +name = "libsecp256k1-gen-ecmult" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccab96b584d38fac86a83f07e659f0deafd0253dc096dab5a36d53efe653c5c3" +dependencies = [ + "libsecp256k1-core", +] + +[[package]] +name = "libsecp256k1-gen-genmult" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67abfe149395e3aa1c48a2beb32b068e2334402df8181f818d3aee2b304c4f5d" +dependencies = [ + "libsecp256k1-core", +] + [[package]] name = "libz-sys" version = "1.0.25" @@ -4736,7 +4794,7 @@ dependencies = [ "frame-support", "frame-system", "hex", - "libsecp256k1", + "libsecp256k1 0.3.5", "log", "pallet-beefy", "pallet-mmr", @@ -6733,7 +6791,6 @@ dependencies = [ "frame-system-rpc-runtime-api", "frame-try-runtime", "hex-literal", - "libsecp256k1", "log", "pallet-authority-discovery", "pallet-authorship", @@ -6810,7 +6867,7 @@ dependencies = [ "frame-system", "hex-literal", "impl-trait-for-tuples", - "libsecp256k1", + "libsecp256k1 0.6.0", "log", "pallet-authorship", "pallet-babe", @@ -6863,7 +6920,6 @@ dependencies = [ "frame-system", "futures 0.3.15", "hex-literal", - "libsecp256k1", "log", "pallet-authority-discovery", "pallet-authorship", @@ -7143,7 +7199,6 @@ dependencies = [ "frame-system", "frame-system-rpc-runtime-api", "hex-literal", - "libsecp256k1", "log", "pallet-authority-discovery", "pallet-authorship", @@ -8522,7 +8577,7 @@ source = "git+https://github.com/paritytech/substrate?branch=master#bfca1a91f760 dependencies = [ "derive_more", "lazy_static", - "libsecp256k1", + "libsecp256k1 0.3.5", "log", "parity-scale-codec", "parity-wasm 0.42.2", @@ -9789,7 +9844,7 @@ dependencies = [ "hex", "impl-serde", "lazy_static", - "libsecp256k1", + "libsecp256k1 0.3.5", "log", "merlin", "num-traits", @@ -9885,7 +9940,7 @@ source = "git+https://github.com/paritytech/substrate?branch=master#bfca1a91f760 dependencies = [ "futures 0.3.15", "hash-db", - "libsecp256k1", + "libsecp256k1 0.3.5", "log", "parity-scale-codec", "parking_lot 0.11.1", @@ -11988,7 +12043,6 @@ dependencies = [ "frame-system-rpc-runtime-api", "frame-try-runtime", "hex-literal", - "libsecp256k1", "log", "pallet-authority-discovery", "pallet-authorship", diff --git a/runtime/common/Cargo.toml b/runtime/common/Cargo.toml index cd259361956d..f1fcfb9ca966 100644 --- a/runtime/common/Cargo.toml +++ b/runtime/common/Cargo.toml @@ -41,7 +41,7 @@ frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = pallet-babe = { git = "https://github.com/paritytech/substrate", branch = "master", default-features=false, optional = true } primitives = { package = "polkadot-primitives", path = "../../primitives", default-features = false } -libsecp256k1 = { version = "0.3.5", default-features = false } +libsecp256k1 = { version = "0.6.0", default-features = false } runtime-parachains = { package = "polkadot-runtime-parachains", path = "../parachains", default-features = false } slot-range-helper = { path = "slot_range_helper", default-features = false } @@ -59,7 +59,7 @@ pallet-treasury = { git = "https://github.com/paritytech/substrate", branch = "m sp-keystore = { git = "https://github.com/paritytech/substrate", branch = "master" } trie-db = "0.22.3" serde_json = "1.0.61" -libsecp256k1 = "0.3.5" +libsecp256k1 = "0.6.0" [features] default = ["std"] diff --git a/runtime/common/src/claims.rs b/runtime/common/src/claims.rs index c06db1d0d9cc..8bac1741bb87 100644 --- a/runtime/common/src/claims.rs +++ b/runtime/common/src/claims.rs @@ -618,19 +618,18 @@ impl SignedExtension for PrevalidateAttests where #[cfg(any(test, feature = "runtime-benchmarks"))] mod secp_utils { use super::*; - use secp256k1; - pub fn public(secret: &secp256k1::SecretKey) -> secp256k1::PublicKey { - secp256k1::PublicKey::from_secret_key(secret) + pub fn public(secret: &libsecp256k1::SecretKey) -> libsecp256k1::PublicKey { + libsecp256k1::PublicKey::from_secret_key(secret) } - pub fn eth(secret: &secp256k1::SecretKey) -> EthereumAddress { + pub fn eth(secret: &libsecp256k1::SecretKey) -> EthereumAddress { let mut res = EthereumAddress::default(); res.0.copy_from_slice(&keccak_256(&public(secret).serialize()[1..65])[12..]); res } - pub fn sig(secret: &secp256k1::SecretKey, what: &[u8], extra: &[u8]) -> EcdsaSignature { + pub fn sig(secret: &libsecp256k1::SecretKey, what: &[u8], extra: &[u8]) -> EcdsaSignature { let msg = keccak_256(&>::ethereum_signable_message(&to_ascii_hex(what)[..], extra)); - let (sig, recovery_id) = secp256k1::sign(&secp256k1::Message::parse(&msg), secret); + let (sig, recovery_id) = libsecp256k1::sign(&libsecp256k1::Message::parse(&msg), secret); let mut r = [0u8; 65]; r[0..64].copy_from_slice(&sig.serialize()[..]); r[64] = recovery_id.serialize(); @@ -640,7 +639,6 @@ mod secp_utils { #[cfg(test)] mod tests { - use secp256k1; use hex_literal::hex; use super::*; use secp_utils::*; @@ -751,20 +749,20 @@ mod tests { type WeightInfo = TestWeightInfo; } - fn alice() -> secp256k1::SecretKey { - secp256k1::SecretKey::parse(&keccak_256(b"Alice")).unwrap() + fn alice() -> libsecp256k1::SecretKey { + libsecp256k1::SecretKey::parse(&keccak_256(b"Alice")).unwrap() } - fn bob() -> secp256k1::SecretKey { - secp256k1::SecretKey::parse(&keccak_256(b"Bob")).unwrap() + fn bob() -> libsecp256k1::SecretKey { + libsecp256k1::SecretKey::parse(&keccak_256(b"Bob")).unwrap() } - fn dave() -> secp256k1::SecretKey { - secp256k1::SecretKey::parse(&keccak_256(b"Dave")).unwrap() + fn dave() -> libsecp256k1::SecretKey { + libsecp256k1::SecretKey::parse(&keccak_256(b"Dave")).unwrap() } - fn eve() -> secp256k1::SecretKey { - secp256k1::SecretKey::parse(&keccak_256(b"Eve")).unwrap() + fn eve() -> libsecp256k1::SecretKey { + libsecp256k1::SecretKey::parse(&keccak_256(b"Eve")).unwrap() } - fn frank() -> secp256k1::SecretKey { - secp256k1::SecretKey::parse(&keccak_256(b"Frank")).unwrap() + fn frank() -> libsecp256k1::SecretKey { + libsecp256k1::SecretKey::parse(&keccak_256(b"Frank")).unwrap() } // This function basically just builds a genesis storage key/value store according to diff --git a/runtime/kusama/Cargo.toml b/runtime/kusama/Cargo.toml index cf1838bc91b9..d325efca2862 100644 --- a/runtime/kusama/Cargo.toml +++ b/runtime/kusama/Cargo.toml @@ -90,7 +90,6 @@ xcm-builder = { package = "xcm-builder", path = "../../xcm/xcm-builder", default [dev-dependencies] hex-literal = "0.3.1" -libsecp256k1 = "0.3.5" tiny-keccak = "2.0.2" keyring = { package = "sp-keyring", git = "https://github.com/paritytech/substrate", branch = "master" } sp-trie = { git = "https://github.com/paritytech/substrate", branch = "master" } diff --git a/runtime/parachains/Cargo.toml b/runtime/parachains/Cargo.toml index 0a766af14c66..6b2af9cfe44e 100644 --- a/runtime/parachains/Cargo.toml +++ b/runtime/parachains/Cargo.toml @@ -38,7 +38,6 @@ frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = xcm = { package = "xcm", path = "../../xcm", default-features = false } xcm-executor = { package = "xcm-executor", path = "../../xcm/xcm-executor", default-features = false } primitives = { package = "polkadot-primitives", path = "../../primitives", default-features = false } -libsecp256k1 = { version = "0.3.5", default-features = false, optional = true } rand = { version = "0.8.3", default-features = false } rand_chacha = { version = "0.3.1", default-features = false } @@ -54,7 +53,6 @@ pallet-staking-reward-curve = { git = "https://github.com/paritytech/substrate", pallet-treasury = { git = "https://github.com/paritytech/substrate", branch = "master" } frame-support-test = { git = "https://github.com/paritytech/substrate", branch = "master" } serde_json = "1.0.61" -libsecp256k1 = "0.3.5" sp-version = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } sc-keystore = { git = "https://github.com/paritytech/substrate", branch = "master" } @@ -90,7 +88,6 @@ std = [ "log/std", ] runtime-benchmarks = [ - "libsecp256k1/hmac", "frame-benchmarking", "frame-support/runtime-benchmarks", "frame-system/runtime-benchmarks", diff --git a/runtime/polkadot/Cargo.toml b/runtime/polkadot/Cargo.toml index 5655a0ae5ee8..3d44d4ab7f37 100644 --- a/runtime/polkadot/Cargo.toml +++ b/runtime/polkadot/Cargo.toml @@ -80,7 +80,6 @@ primitives = { package = "polkadot-primitives", path = "../../primitives", defau [dev-dependencies] hex-literal = "0.3.1" -libsecp256k1 = "0.3.5" tiny-keccak = "2.0.2" keyring = { package = "sp-keyring", git = "https://github.com/paritytech/substrate", branch = "master" } sp-trie = { git = "https://github.com/paritytech/substrate", branch = "master" } diff --git a/runtime/test-runtime/Cargo.toml b/runtime/test-runtime/Cargo.toml index 1bd2c7882990..f0ecc70caf4c 100644 --- a/runtime/test-runtime/Cargo.toml +++ b/runtime/test-runtime/Cargo.toml @@ -60,7 +60,6 @@ polkadot-runtime-parachains = { path = "../parachains", default-features = false [dev-dependencies] hex-literal = "0.3.1" -libsecp256k1 = "0.3.5" tiny-keccak = "2.0.2" keyring = { package = "sp-keyring", git = "https://github.com/paritytech/substrate", branch = "master" } sp-trie = { git = "https://github.com/paritytech/substrate", branch = "master" } diff --git a/runtime/westend/Cargo.toml b/runtime/westend/Cargo.toml index 1ecfbf43a078..090b45006af3 100644 --- a/runtime/westend/Cargo.toml +++ b/runtime/westend/Cargo.toml @@ -88,7 +88,6 @@ xcm-builder = { package = "xcm-builder", path = "../../xcm/xcm-builder", default [dev-dependencies] hex-literal = "0.3.1" -libsecp256k1 = "0.3.5" tiny-keccak = "2.0.2" keyring = { package = "sp-keyring", git = "https://github.com/paritytech/substrate", branch = "master" } sp-trie = { git = "https://github.com/paritytech/substrate", branch = "master" } From 21b0c63a86af1b035dcec46e4741a1ba2700e831 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Tue, 20 Jul 2021 16:23:42 +0200 Subject: [PATCH 2/3] Rename missed old crate names --- runtime/common/src/claims.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/runtime/common/src/claims.rs b/runtime/common/src/claims.rs index 8bac1741bb87..686006f7646f 100644 --- a/runtime/common/src/claims.rs +++ b/runtime/common/src/claims.rs @@ -1194,7 +1194,7 @@ mod benchmarking { const VALUE: u32 = 1_000_000; fn create_claim(input: u32) -> DispatchResult { - let secret_key = secp256k1::SecretKey::parse(&keccak_256(&input.encode())).unwrap(); + let secret_key = libsecp256k1::SecretKey::parse(&keccak_256(&input.encode())).unwrap(); let eth_address = eth(&secret_key); let vesting = Some((100_000u32.into(), 1_000u32.into(), 100u32.into())); super::Pallet::::mint_claim(RawOrigin::Root.into(), eth_address, VALUE.into(), vesting, None)?; @@ -1202,7 +1202,7 @@ mod benchmarking { } fn create_claim_attest(input: u32) -> DispatchResult { - let secret_key = secp256k1::SecretKey::parse(&keccak_256(&input.encode())).unwrap(); + let secret_key = libsecp256k1::SecretKey::parse(&keccak_256(&input.encode())).unwrap(); let eth_address = eth(&secret_key); let vesting = Some((100_000u32.into(), 1_000u32.into(), 100u32.into())); super::Pallet::::mint_claim( @@ -1225,7 +1225,7 @@ mod benchmarking { create_claim_attest::(u32::MAX - c)?; } - let secret_key = secp256k1::SecretKey::parse(&keccak_256(&c.encode())).unwrap(); + let secret_key = libsecp256k1::SecretKey::parse(&keccak_256(&c.encode())).unwrap(); let eth_address = eth(&secret_key); let account: T::AccountId = account("user", c, SEED); let vesting = Some((100_000u32.into(), 1_000u32.into(), 100u32.into())); @@ -1270,7 +1270,7 @@ mod benchmarking { // Crate signature let attest_c = u32::MAX - c; - let secret_key = secp256k1::SecretKey::parse(&keccak_256(&attest_c.encode())).unwrap(); + let secret_key = libsecp256k1::SecretKey::parse(&keccak_256(&attest_c.encode())).unwrap(); let eth_address = eth(&secret_key); let account: T::AccountId = account("user", c, SEED); let vesting = Some((100_000u32.into(), 1_000u32.into(), 100u32.into())); @@ -1298,7 +1298,7 @@ mod benchmarking { } let attest_c = u32::MAX - c; - let secret_key = secp256k1::SecretKey::parse(&keccak_256(&attest_c.encode())).unwrap(); + let secret_key = libsecp256k1::SecretKey::parse(&keccak_256(&attest_c.encode())).unwrap(); let eth_address = eth(&secret_key); let account: T::AccountId = account("user", c, SEED); let vesting = Some((100_000u32.into(), 1_000u32.into(), 100u32.into())); @@ -1336,10 +1336,10 @@ mod benchmarking { } let attest_c = u32::MAX - c; - let secret_key = secp256k1::SecretKey::parse(&keccak_256(&attest_c.encode())).unwrap(); + let secret_key = libsecp256k1::SecretKey::parse(&keccak_256(&attest_c.encode())).unwrap(); let eth_address = eth(&secret_key); - let new_secret_key = secp256k1::SecretKey::parse(&keccak_256(&(u32::MAX/2).encode())).unwrap(); + let new_secret_key = libsecp256k1::SecretKey::parse(&keccak_256(&(u32::MAX/2).encode())).unwrap(); let new_eth_address = eth(&new_secret_key); let account: T::AccountId = account("user", c, SEED); @@ -1369,7 +1369,7 @@ mod benchmarking { eth_recover { let i in 0 .. 1_000; // Crate signature - let secret_key = secp256k1::SecretKey::parse(&keccak_256(&i.encode())).unwrap(); + let secret_key = libsecp256k1::SecretKey::parse(&keccak_256(&i.encode())).unwrap(); let account: T::AccountId = account("user", i, SEED); let signature = sig::(&secret_key, &account.encode(), &[][..]); let data = account.using_encoded(to_ascii_hex); From cea32721f9521afdfabd6b86f7ce51ba7f92be54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Tue, 20 Jul 2021 16:38:11 +0200 Subject: [PATCH 3/3] Enable required feature --- runtime/common/Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/runtime/common/Cargo.toml b/runtime/common/Cargo.toml index f1fcfb9ca966..ebd4294ffc20 100644 --- a/runtime/common/Cargo.toml +++ b/runtime/common/Cargo.toml @@ -99,6 +99,7 @@ std = [ ] runtime-benchmarks = [ "libsecp256k1/hmac", + "libsecp256k1/static-context", "frame-benchmarking", "frame-support/runtime-benchmarks", "frame-system/runtime-benchmarks",