Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove usage of libsecp256k1 for secp256k1 in claims pallet #5841

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions Cargo.lock

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

168 changes: 86 additions & 82 deletions polkadot/runtime/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ pallet-babe = { optional = true, workspace = true }

polkadot-primitives = { workspace = true }
libsecp256k1 = { workspace = true }
secp256k1 = { workspace = true }
polkadot-runtime-parachains = { workspace = true }

slot-range-helper = { workspace = true }
Expand All @@ -68,96 +69,99 @@ sp-keystore = { workspace = true, default-features = true }
sp-keyring = { workspace = true, default-features = true }
serde_json = { workspace = true, default-features = true }
libsecp256k1 = { workspace = true, default-features = true }
secp256k1 = { workspace = true, default-features = true }
polkadot-primitives-test-helpers = { workspace = true }

[features]
default = ["std"]
no_std = []
std = [
"bitvec/std",
"codec/std",
"frame-benchmarking?/std",
"frame-election-provider-support/std",
"frame-support/std",
"frame-system/std",
"libsecp256k1/std",
"log/std",
"pallet-asset-rate?/std",
"pallet-authorship/std",
"pallet-balances/std",
"pallet-broker/std",
"pallet-election-provider-multi-phase/std",
"pallet-fast-unstake/std",
"pallet-identity/std",
"pallet-session/std",
"pallet-staking-reward-fn/std",
"pallet-staking/std",
"pallet-timestamp/std",
"pallet-transaction-payment/std",
"pallet-treasury/std",
"pallet-vesting/std",
"polkadot-primitives/std",
"polkadot-runtime-parachains/std",
"rustc-hex/std",
"scale-info/std",
"serde/std",
"slot-range-helper/std",
"sp-api/std",
"sp-core/std",
"sp-inherents/std",
"sp-io/std",
"sp-npos-elections/std",
"sp-runtime/std",
"sp-session/std",
"sp-staking/std",
"xcm-builder/std",
"xcm-executor/std",
"xcm/std",
"bitvec/std",
"codec/std",
"frame-benchmarking?/std",
"frame-election-provider-support/std",
"frame-support/std",
"frame-system/std",
"libsecp256k1/std",
"log/std",
"pallet-asset-rate?/std",
"pallet-authorship/std",
"pallet-balances/std",
"pallet-broker/std",
"pallet-election-provider-multi-phase/std",
"pallet-fast-unstake/std",
"pallet-identity/std",
"pallet-session/std",
"pallet-staking-reward-fn/std",
"pallet-staking/std",
"pallet-timestamp/std",
"pallet-transaction-payment/std",
"pallet-treasury/std",
"pallet-vesting/std",
"polkadot-primitives/std",
"polkadot-runtime-parachains/std",
"rustc-hex/std",
"scale-info/std",
"secp256k1/global-context",
"secp256k1/std",
"serde/std",
"slot-range-helper/std",
"sp-api/std",
"sp-core/std",
"sp-inherents/std",
"sp-io/std",
"sp-npos-elections/std",
"sp-runtime/std",
"sp-session/std",
"sp-staking/std",
"xcm-builder/std",
"xcm-executor/std",
"xcm/std",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-election-provider-support/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"libsecp256k1/hmac",
"libsecp256k1/static-context",
"pallet-asset-rate/runtime-benchmarks",
"pallet-babe/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-broker/runtime-benchmarks",
"pallet-election-provider-multi-phase/runtime-benchmarks",
"pallet-fast-unstake/runtime-benchmarks",
"pallet-identity/runtime-benchmarks",
"pallet-staking/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
"pallet-treasury/runtime-benchmarks",
"pallet-vesting/runtime-benchmarks",
"polkadot-primitives/runtime-benchmarks",
"polkadot-runtime-parachains/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"sp-staking/runtime-benchmarks",
"xcm-builder/runtime-benchmarks",
"xcm-executor/runtime-benchmarks",
"frame-benchmarking/runtime-benchmarks",
"frame-election-provider-support/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"libsecp256k1/hmac",
"libsecp256k1/static-context",
"pallet-asset-rate/runtime-benchmarks",
"pallet-babe/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-broker/runtime-benchmarks",
"pallet-election-provider-multi-phase/runtime-benchmarks",
"pallet-fast-unstake/runtime-benchmarks",
"pallet-identity/runtime-benchmarks",
"pallet-staking/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
"pallet-treasury/runtime-benchmarks",
"pallet-vesting/runtime-benchmarks",
"polkadot-primitives/runtime-benchmarks",
"polkadot-runtime-parachains/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"sp-staking/runtime-benchmarks",
"xcm-builder/runtime-benchmarks",
"xcm-executor/runtime-benchmarks",
]
try-runtime = [
"frame-election-provider-support/try-runtime",
"frame-support-test/try-runtime",
"frame-support/try-runtime",
"frame-system/try-runtime",
"pallet-asset-rate/try-runtime",
"pallet-authorship/try-runtime",
"pallet-babe?/try-runtime",
"pallet-balances/try-runtime",
"pallet-broker/try-runtime",
"pallet-election-provider-multi-phase/try-runtime",
"pallet-fast-unstake/try-runtime",
"pallet-identity/try-runtime",
"pallet-session/try-runtime",
"pallet-staking/try-runtime",
"pallet-timestamp/try-runtime",
"pallet-transaction-payment/try-runtime",
"pallet-treasury/try-runtime",
"pallet-vesting/try-runtime",
"polkadot-runtime-parachains/try-runtime",
"sp-runtime/try-runtime",
"frame-election-provider-support/try-runtime",
"frame-support-test/try-runtime",
"frame-support/try-runtime",
"frame-system/try-runtime",
"pallet-asset-rate/try-runtime",
"pallet-authorship/try-runtime",
"pallet-babe?/try-runtime",
"pallet-balances/try-runtime",
"pallet-broker/try-runtime",
"pallet-election-provider-multi-phase/try-runtime",
"pallet-fast-unstake/try-runtime",
"pallet-identity/try-runtime",
"pallet-session/try-runtime",
"pallet-staking/try-runtime",
"pallet-timestamp/try-runtime",
"pallet-transaction-payment/try-runtime",
"pallet-treasury/try-runtime",
"pallet-vesting/try-runtime",
"polkadot-runtime-parachains/try-runtime",
"sp-runtime/try-runtime",
Comment on lines -114 to +166
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will fix this, probably my editor did something, sorry

]
58 changes: 31 additions & 27 deletions polkadot/runtime/common/src/claims.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
pub use pallet::*;
use polkadot_primitives::ValidityError;
use scale_info::TypeInfo;
use secp256k1::{PublicKey, Secp256k1, SecretKey};

Check failure on line 33 in polkadot/runtime/common/src/claims.rs

View workflow job for this annotation

GitHub Actions / cargo-check-all-crate-macos

unused imports: `PublicKey`, `Secp256k1`, `SecretKey`
use serde::{self, Deserialize, Deserializer, Serialize, Serializer};
use sp_io::{crypto::secp256k1_ecdsa_recover, hashing::keccak_256};
use sp_runtime::{
Expand Down Expand Up @@ -87,14 +88,16 @@
/// Convert this to the (English) statement it represents.
fn to_text(self) -> &'static [u8] {
match self {
StatementKind::Regular =>
StatementKind::Regular => {
&b"I hereby agree to the terms of the statement whose SHA-256 multihash is \
Qmc1XYqT6S39WNp2UeiRUrZichUWUPpGEThDE6dAb3f6Ny. (This may be found at the URL: \
https://statement.polkadot.network/regular.html)"[..],
StatementKind::Saft =>
https://statement.polkadot.network/regular.html)"[..]
},
StatementKind::Saft => {
&b"I hereby agree to the terms of the statement whose SHA-256 multihash is \
QmXEkMahfhHJPzT3RjkXiZVFi77ZeVeuxtAjhojGRNYckz. (This may be found at the URL: \
https://statement.polkadot.network/saft.html)"[..],
https://statement.polkadot.network/saft.html)"[..]
},
}
}
}
Expand Down Expand Up @@ -556,7 +559,7 @@

let vesting = Vesting::<T>::get(&signer);
if vesting.is_some() && T::VestingSchedule::vesting_balance(&dest).is_some() {
return Err(Error::<T>::VestedBalanceExists.into())
return Err(Error::<T>::VestedBalanceExists.into());
}

// We first need to deposit the balance to ensure that the account exists.
Expand Down Expand Up @@ -669,16 +672,17 @@
mod secp_utils {
use super::*;

pub fn public(secret: &libsecp256k1::SecretKey) -> libsecp256k1::PublicKey {
libsecp256k1::PublicKey::from_secret_key(secret)
pub fn public(secret: &secp256k1::SecretKey) -> secp256k1::PublicKey {
let secp = Secp256k1::new();
PublicKey::from_secret_key(&secp, secret)
}
pub fn eth(secret: &libsecp256k1::SecretKey) -> EthereumAddress {
pub fn eth(secret: &secp256k1::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: &libsecp256k1::SecretKey,
secret: &secp256k1::SecretKey,
what: &[u8],
extra: &[u8],
) -> EcdsaSignature {
Expand Down Expand Up @@ -776,20 +780,20 @@
type WeightInfo = TestWeightInfo;
}

fn alice() -> libsecp256k1::SecretKey {
libsecp256k1::SecretKey::parse(&keccak_256(b"Alice")).unwrap()
fn alice() -> secp256k1::SecretKey {
secp256k1::SecretKey::from_slice(&keccak_256(b"Alice")).unwrap()
}
fn bob() -> libsecp256k1::SecretKey {
libsecp256k1::SecretKey::parse(&keccak_256(b"Bob")).unwrap()
fn bob() -> secp256k1::SecretKey {
secp256k1::SecretKey::from_slice(&keccak_256(b"Bob")).unwrap()
}
fn dave() -> libsecp256k1::SecretKey {
libsecp256k1::SecretKey::parse(&keccak_256(b"Dave")).unwrap()
fn dave() -> secp256k1::SecretKey {
secp256k1::SecretKey::from_slice(&keccak_256(b"Dave")).unwrap()
}
fn eve() -> libsecp256k1::SecretKey {
libsecp256k1::SecretKey::parse(&keccak_256(b"Eve")).unwrap()
fn eve() -> secp256k1::SecretKey {
secp256k1::SecretKey::from_slice(&keccak_256(b"Eve")).unwrap()
}
fn frank() -> libsecp256k1::SecretKey {
libsecp256k1::SecretKey::parse(&keccak_256(b"Frank")).unwrap()
fn frank() -> secp256k1::SecretKey {
secp256k1::SecretKey::from_slice(&keccak_256(b"Frank")).unwrap()
}

// This function basically just builds a genesis storage key/value store according to
Expand Down Expand Up @@ -1443,7 +1447,7 @@
const VALUE: u32 = 1_000_000;

fn create_claim<T: Config>(input: u32) -> DispatchResult {
let secret_key = libsecp256k1::SecretKey::parse(&keccak_256(&input.encode())).unwrap();
let secret_key = secp256k1::SecretKey::from_slice(&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 @@ -1457,7 +1461,7 @@
}

fn create_claim_attest<T: Config>(input: u32) -> DispatchResult {
let secret_key = libsecp256k1::SecretKey::parse(&keccak_256(&input.encode())).unwrap();
let secret_key = secp256k1::SecretKey::from_slice(&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 @@ -1480,7 +1484,7 @@
create_claim_attest::<T>(u32::MAX - c)?;
}

let secret_key = libsecp256k1::SecretKey::parse(&keccak_256(&c.encode())).unwrap();
let secret_key = secp256k1::SecretKey::from_slice(&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 @@ -1530,7 +1534,7 @@

// Crate signature
let attest_c = u32::MAX - c;
let secret_key = libsecp256k1::SecretKey::parse(&keccak_256(&attest_c.encode())).unwrap();
let secret_key = secp256k1::SecretKey::from_slice(&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 @@ -1564,7 +1568,7 @@
}

let attest_c = u32::MAX - c;
let secret_key = libsecp256k1::SecretKey::parse(&keccak_256(&attest_c.encode())).unwrap();
let secret_key = secp256k1::SecretKey::from_slice(&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 @@ -1605,10 +1609,10 @@
}

let attest_c = u32::MAX - c;
let secret_key = libsecp256k1::SecretKey::parse(&keccak_256(&attest_c.encode())).unwrap();
let secret_key = secp256k1::SecretKey::from_slice(&keccak_256(&attest_c.encode())).unwrap();
let eth_address = eth(&secret_key);

let new_secret_key = libsecp256k1::SecretKey::parse(&keccak_256(&(u32::MAX/2).encode())).unwrap();
let new_secret_key = secp256k1::SecretKey::from_slice(&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 @@ -1638,7 +1642,7 @@
eth_recover {
let i in 0 .. 1_000;
// Crate signature
let secret_key = libsecp256k1::SecretKey::parse(&keccak_256(&i.encode())).unwrap();
let secret_key = secp256k1::SecretKey::from_slice(&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
Loading