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

Update secp256k1 and remove unrequired usage #3502

Merged
merged 3 commits into from
Jul 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 66 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions runtime/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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"]
Expand Down Expand Up @@ -99,6 +99,7 @@ std = [
]
runtime-benchmarks = [
"libsecp256k1/hmac",
"libsecp256k1/static-context",
"frame-benchmarking",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
Expand Down
48 changes: 23 additions & 25 deletions runtime/common/src/claims.rs
Original file line number Diff line number Diff line change
Expand Up @@ -618,19 +618,18 @@ impl<T: Config + Send + Sync> SignedExtension for PrevalidateAttests<T> 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<T: Config>(secret: &secp256k1::SecretKey, what: &[u8], extra: &[u8]) -> EcdsaSignature {
pub fn sig<T: Config>(secret: &libsecp256k1::SecretKey, what: &[u8], extra: &[u8]) -> EcdsaSignature {
let msg = keccak_256(&<super::Pallet<T>>::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();
Expand All @@ -640,7 +639,6 @@ mod secp_utils {

#[cfg(test)]
mod tests {
use secp256k1;
use hex_literal::hex;
use super::*;
use secp_utils::*;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1196,15 +1194,15 @@ mod benchmarking {
const VALUE: u32 = 1_000_000;

fn create_claim<T: Config>(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::<T>::mint_claim(RawOrigin::Root.into(), eth_address, VALUE.into(), vesting, None)?;
Ok(())
}

fn create_claim_attest<T: Config>(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::<T>::mint_claim(
Expand All @@ -1227,7 +1225,7 @@ mod benchmarking {
create_claim_attest::<T>(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()));
Expand Down Expand Up @@ -1272,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()));
Expand Down Expand Up @@ -1300,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()));
Expand Down Expand Up @@ -1338,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);
Expand Down Expand Up @@ -1371,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::<T>(&secret_key, &account.encode(), &[][..]);
let data = account.using_encoded(to_ascii_hex);
Expand Down
1 change: 0 additions & 1 deletion runtime/kusama/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
3 changes: 0 additions & 3 deletions runtime/parachains/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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" }

Expand Down Expand Up @@ -90,7 +88,6 @@ std = [
"log/std",
]
runtime-benchmarks = [
"libsecp256k1/hmac",
"frame-benchmarking",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
Expand Down
1 change: 0 additions & 1 deletion runtime/polkadot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
1 change: 0 additions & 1 deletion runtime/test-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
1 change: 0 additions & 1 deletion runtime/westend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down