Skip to content

Commit

Permalink
Add derivation path (#557)
Browse files Browse the repository at this point in the history
* replace custom tx-pause pallet with substrate

* add tx-pause calls to filter

* cargo fmt

* fix clippy

* disable default-features for starknet-crypto

* fix signature verifying issue and update tests

* remove print statements

* Add derivation path var to TSS jobs

* Merge other PR, fix up all tests

* remove print, fix clippy

---------

Co-authored-by: salman01zp <[email protected]>
  • Loading branch information
drewstone and salman01zp authored Mar 14, 2024
1 parent 768aa63 commit 264c9a8
Show file tree
Hide file tree
Showing 43 changed files with 1,060 additions and 1,072 deletions.
75 changes: 39 additions & 36 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ pallet-jobs-rpc = { path = "pallets/jobs/rpc" }
k256 = { version = "0.13.0", default-features = false }
p256 = { version = "0.13.0", default-features = false }
ecdsa-core = { package = "ecdsa", version = "0.16.9", default-features = false }
starknet-crypto = { version = "0.6.1", no-default-features = true }
starknet-crypto = { version = "0.6.1", default-features = false, features = ["signature-display","alloc"] }
frost-core = { path = "pallets/dkg/frost", default-features = false }
frost-ed25519 = { path = "pallets/dkg/frost/frost-ed25519", default-features = false }
frost-ed448 = { path = "pallets/dkg/frost/frost-ed448", default-features = false }
Expand Down Expand Up @@ -226,6 +226,7 @@ pallet-nomination-pools = { git = "https://github.com/paritytech/polkadot-sdk.gi
pallet-preimage = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.7.0", default-features = false }
pallet-scheduler = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.7.0", default-features = false }
pallet-treasury = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.7.0", default-features = false }
pallet-tx-pause = { git = "https://github.com/paritytech/polkadot-sdk.git", branch = "release-polkadot-v1.7.0", default-features = false }

pallet-authorship = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.7.0", default-features = false }
pallet-balances = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.7.0", default-features = false }
Expand Down Expand Up @@ -314,7 +315,6 @@ sc-consensus-manual-seal = { git = "https://github.com/paritytech/polkadot-sdk",
# Tangle dependencies
tangle-primitives = { path = "primitives", default-features = false }
tangle-crypto-primitives = { path = "primitives/crypto", default-features = false }
pallet-transaction-pause = { path = "pallets/transaction-pause", default-features = false }
pallet-staking = { path = "pallets/staking", default-features = false }
pallet-staking-reward-curve = { path = "pallets/staking/reward-curve", default-features = false }

Expand Down
1 change: 1 addition & 0 deletions node/src/chainspec/mainnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ fn mainnet_genesis(
im_online: ImOnlineConfig { keys: vec![] },
nomination_pools: Default::default(),
transaction_payment: Default::default(),
tx_pause: Default::default(),
// EVM compatibility
evm_chain_id: EVMChainIdConfig { chain_id, ..Default::default() },
evm: Default::default(),
Expand Down
2 changes: 2 additions & 0 deletions node/src/chainspec/testnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,8 @@ fn testnet_genesis(
im_online: ImOnlineConfig { keys: vec![] },
nomination_pools: Default::default(),
transaction_payment: Default::default(),
tx_pause: Default::default(),

// EVM compatibility
evm_chain_id: EVMChainIdConfig { chain_id, ..Default::default() },
evm: EVMConfig {
Expand Down
4 changes: 3 additions & 1 deletion pallets/dkg/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ generic-ec-zkp = { workspace = true, default-features = false, features = ["serd
starknet-crypto = { workspace = true, default-features = false }
k256 = { workspace = true, features = ["arithmetic", "expose-field", "hash2curve", "alloc"], default-features = false }
p256 = { workspace = true, default-features = false, features = ["hash2curve", "alloc", "ecdsa"] }
ecdsa-core = { workspace = true, default-features = false, features = ["der"] }
ecdsa-core = { workspace = true, default-features = false }
generic-array = { version = "0.14.7", default-features = false }

# FROST specific dependencies
frost-core = { workspace = true, default-features = false }
Expand Down Expand Up @@ -94,6 +95,7 @@ std = [
"frost-p384/std",
# "frost-redjubjub/std",
"snowbridge-milagro-bls/std",
"starknet-crypto/std",
]
serde = []
try-runtime = ["frame-support/try-runtime"]
Expand Down
28 changes: 24 additions & 4 deletions pallets/dkg/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,14 @@ impl<T: Config> Pallet<T> {
/// # Returns
///
/// Returns the calculated fee as a `BalanceOf<T>` type.
#[allow(clippy::type_complexity)]
pub fn job_to_fee(
job: &JobSubmission<
T::AccountId,
BlockNumberFor<T>,
T::MaxParticipants,
T::MaxSubmissionLen,
T::MaxAdditionalParamsLen,
>,
) -> BalanceOf<T> {
let fee_info = FeeInfo::<T>::get();
Expand Down Expand Up @@ -99,6 +101,7 @@ impl<T: Config> Pallet<T> {
T::MaxSignatureLen,
T::MaxDataLen,
T::MaxProofLen,
T::MaxAdditionalParamsLen,
>,
) -> DispatchResult {
match data {
Expand Down Expand Up @@ -142,7 +145,12 @@ impl<T: Config> Pallet<T> {
/// * `data` - The DKG signature result containing the message data, signature, signing key, and
/// key type.
fn verify_dkg_signature(
data: DKGTSSSignatureResult<T::MaxDataLen, T::MaxKeyLen, T::MaxSignatureLen>,
data: DKGTSSSignatureResult<
T::MaxDataLen,
T::MaxKeyLen,
T::MaxSignatureLen,
T::MaxAdditionalParamsLen,
>,
) -> DispatchResult {
match data.signature_scheme {
DigitalSignatureScheme::EcdsaSecp256k1 => verify_secp256k1_ecdsa_signature::<T>(
Expand Down Expand Up @@ -196,9 +204,13 @@ impl<T: Config> Pallet<T> {
/// Returns a `DispatchResult` indicating whether the key rotation verification was successful
/// or encountered an error.
fn verify_dkg_key_rotation(
data: DKGTSSKeyRotationResult<T::MaxKeyLen, T::MaxSignatureLen>,
data: DKGTSSKeyRotationResult<T::MaxKeyLen, T::MaxSignatureLen, T::MaxAdditionalParamsLen>,
) -> DispatchResult {
let emit_event = |data: DKGTSSKeyRotationResult<T::MaxKeyLen, T::MaxSignatureLen>| {
let emit_event = |data: DKGTSSKeyRotationResult<
T::MaxKeyLen,
T::MaxSignatureLen,
T::MaxAdditionalParamsLen,
>| {
Self::deposit_event(Event::KeyRotated {
from_job_id: data.phase_one_id,
to_job_id: data.new_phase_one_id,
Expand All @@ -213,11 +225,19 @@ impl<T: Config> Pallet<T> {
let signature = data.signature.clone();
let verifying_key = data.key.clone();
let signature_scheme = data.signature_scheme.clone();
let derivation_path = data.derivation_path.clone();
let sig_result_data: DKGTSSSignatureResult<
T::MaxDataLen,
T::MaxKeyLen,
T::MaxSignatureLen,
> = DKGTSSSignatureResult { data: encoded_data, signature, verifying_key, signature_scheme };
T::MaxAdditionalParamsLen,
> = DKGTSSSignatureResult {
data: encoded_data,
signature,
verifying_key,
signature_scheme,
derivation_path,
};

Self::verify_dkg_signature(sig_result_data).and_then(|_| emit_event(data))
}
Expand Down
3 changes: 3 additions & 0 deletions pallets/dkg/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ pub mod pallet {
/// The maximum size of proof allowed
type MaxProofLen: Get<u32> + Clone + TypeInfo + Debug + Eq + PartialEq;

/// The maximum size of additional parameters
type MaxAdditionalParamsLen: Get<u32> + Clone + TypeInfo + Debug + Eq + PartialEq;

/// Weight info for pallet
type WeightInfo: WeightInfo;
}
Expand Down
3 changes: 3 additions & 0 deletions pallets/dkg/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ parameter_types! {
pub const MaxSignatureLen: u32 = 256;
#[derive(Clone, Debug, Eq, PartialEq, TypeInfo)]
pub const MaxProofLen: u32 = 256;
#[derive(Clone, Debug, Eq, PartialEq, TypeInfo)]
pub const MaxAdditionalParamsLen: u32 = 256;
}

impl pallet_dkg::Config for Runtime {
Expand All @@ -102,6 +104,7 @@ impl pallet_dkg::Config for Runtime {
type MaxDataLen = MaxDataLen;
type MaxSignatureLen = MaxSignatureLen;
type MaxProofLen = MaxProofLen;
type MaxAdditionalParamsLen = MaxAdditionalParamsLen;
type WeightInfo = ();
}

Expand Down
Loading

0 comments on commit 264c9a8

Please sign in to comment.