Skip to content
Draft
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
37 changes: 37 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ members = [
"substrate/client/consensus/pow",
"substrate/client/consensus/slots",
"substrate/client/db",
"substrate/client/dkg",
"substrate/client/executor",
"substrate/client/executor/common",
"substrate/client/executor/polkavm",
Expand Down Expand Up @@ -743,6 +744,7 @@ cumulus-pallet-weight-reclaim = { path = "cumulus/pallets/weight-reclaim", defau
cumulus-pallet-xcm = { path = "cumulus/pallets/xcm", default-features = false }
cumulus-pallet-xcmp-queue = { path = "cumulus/pallets/xcmp-queue", default-features = false }
cumulus-ping = { path = "cumulus/parachains/pallets/ping", default-features = false }
cumulus-keygen = { path = "cumulus/parachains/pallets/keygen-verifier", default-features = false }
cumulus-primitives-aura = { path = "cumulus/primitives/aura", default-features = false }
cumulus-primitives-core = { path = "cumulus/primitives/core", default-features = false }
cumulus-primitives-parachain-inherent = { path = "cumulus/primitives/parachain-inherent", default-features = false }
Expand Down
10 changes: 10 additions & 0 deletions cumulus/test/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ sp-runtime = { workspace = true }
sp-session = { workspace = true }
sp-transaction-pool = { workspace = true }
sp-version = { workspace = true }
sp-std = { workspace = true }

# Cumulus
cumulus-pallet-aura-ext = { workspace = true }
Expand All @@ -49,12 +50,20 @@ cumulus-primitives-aura = { workspace = true }
cumulus-primitives-core = { workspace = true }
parachain-info = { workspace = true }

ark-ec = { version = "0.5", default-features = false }
ark-poly = { version = "0.5", default-features = false }
ark-std = { version = "0.5", default-features = false }


[build-dependencies]
substrate-wasm-builder = { optional = true, workspace = true, default-features = true }

[features]
default = ["std"]
std = [
"ark-ec/std",
"ark-poly/std",
"ark-std/std",
"codec/std",
"cumulus-pallet-aura-ext/std",
"cumulus-pallet-parachain-system/std",
Expand Down Expand Up @@ -84,6 +93,7 @@ std = [
"sp-genesis-builder/std",
"sp-inherents/std",
"sp-io/std",
"sp-std/std",
"sp-keyring/std",
"sp-offchain/std",
"sp-runtime/std",
Expand Down
98 changes: 98 additions & 0 deletions cumulus/test/runtime/src/key_gen.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
pub use pallet::*;


#[frame_support::pallet(dev_mode)]
pub mod pallet {
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
use sp_std::vec::Vec;

use ark_ec::pairing::Pairing;
use ark_ec::{CurveGroup, PrimeGroup};
use ark_poly::GeneralEvaluationDomain;
use ark_std::test_rng;
use adkg_vrf::bls::threshold::ThresholdVk;


#[pallet::pallet]
pub struct Pallet<T>(_);

#[pallet::config]
pub trait Config: frame_system::Config {
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
}

#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
ProofVerified { who: T::AccountId },
}

#[pallet::error]
pub enum Error<T> {
VerificationFailed,
DeserializationFailed,
}

#[pallet::storage]
#[pallet::getter(fn aggregated_transcript)]
pub type AggregatedTranscript<T: Config> = StorageValue<_, Vec<u8>, OptionQuery>;

#[pallet::call]
impl<T: Config> Pallet<T> {
#[pallet::call_index(0)]
#[pallet::weight(10_000_000)]
pub fn add_transcript(
origin: OriginFor<T>,
transcript_bytes: Vec<u8>,
) -> DispatchResult {
let who = ensure_signed(origin)?;

let new_transcript = Transcript::<ark_bls12_381::Bls12_381>::deserialize_compressed(&transcript_bytes[..])
.map_err(|_| Error::<T>::DeserializationFailed)?;

// Get existing aggregated transcript if it exists
let aggregated = if let Some(existing_bytes) = AggregatedTranscript::<T>::get() {
// Deserialize existing
let existing = Transcript::<ark_bls12_381::Bls12_381>::deserialize_compressed(&existing_bytes[..])
.map_err(|_| Error::<T>::DeserializationFailed)?;

// Merge with new transcript using merge_with
existing.merge_with(&vec![new_transcript])
} else {
// First transcript, just use it as is
new_transcript
};

// Serialize and store the aggregated transcript
let mut aggregated_bytes = Vec::new();
aggregated.serialize_compressed(&mut aggregated_bytes)
.map_err(|_| Error::<T>::SerializationFailed)?;
AggregatedTranscript::<T>::put(aggregated_bytes);

ensure!(is_valid, Error::<T>::VerificationFailed);

Self::deposit_event(Event::ProofVerified { who });
Ok(())
}

#[pallet::call_index(0)]
#[pallet::weight(10_000_000)]
pub fn compute_vk(
origin: OriginFor<T>,
) -> DispatchResult {
let who = ensure_signed(origin)?;
// Get the aggregated transcript
let transcript_bytes = AggregatedTranscript::<T>::get()
.ok_or(Error::<T>::NoAggregatedTranscript)?;

let agg_transcript = Transcript::<ark_bls12_381::Bls12_381>::deserialize_compressed(&transcript_bytes[..])
.map_err(|_| Error::<T>::DeserializationFailed)?;

let threshold_vk = adkg_vrf::ThresholdVk::from_share(&agg_transcript.payload);

Ok(())
}
}
}

1 change: 1 addition & 0 deletions cumulus/test/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub mod sync_backing {

mod genesis_config_presets;
mod test_pallet;
mod key_gen;

extern crate alloc;

Expand Down
63 changes: 63 additions & 0 deletions substrate/client/dkg/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
[package]
name = "sc-dkg"
version = "1.0.0"
authors.workspace = true
edition.workspace = true
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
repository.workspace = true
description = "DKG Client gadget for substrate"
homepage.workspace = true

[lints]
workspace = true

[dependencies]
array-bytes = { workspace = true, default-features = true }
async-channel = { workspace = true }
async-trait = { workspace = true }
codec = { features = ["derive"], workspace = true, default-features = true }
futures = { workspace = true }
log = { workspace = true, default-features = true }
parking_lot = { workspace = true, default-features = true }
prometheus-endpoint = { workspace = true, default-features = true }
rand = { workspace = true }
scale-info = { features = ["derive"], workspace = true }
sc-client-api = { workspace = true, default-features = true }
sc-consensus = { workspace = true, default-features = true }
sc-network = { workspace = true, default-features = true }
sc-network-gossip = { workspace = true, default-features = true }
sc-network-sync = { workspace = true, default-features = true }
sc-network-types = { workspace = true, default-features = true }
sc-utils = { workspace = true, default-features = true }
sp-api = { workspace = true, default-features = true }
sp-application-crypto = { workspace = true, default-features = true }
sp-arithmetic = { workspace = true, default-features = true }
sp-blockchain = { workspace = true, default-features = true }
sp-consensus = { workspace = true, default-features = true }
sp-core = { workspace = true, default-features = true }
sp-keystore = { workspace = true, default-features = true }
sp-runtime = { workspace = true, default-features = true }
thiserror = { workspace = true }
tokio = { workspace = true, default-features = true }
wasm-timer = { workspace = true }

adkg-vrf = { git = "https://github.com/w3f/adkg-vrf.git" }

ark-ec = { version = "0.5", default-features = false }
ark-poly = { version = "0.5", default-features = false }


[dev-dependencies]
sc-block-builder = { workspace = true, default-features = true }
sc-network-test = { workspace = true }
serde = { workspace = true, default-features = true }
sp-tracing = { workspace = true, default-features = true }
substrate-test-runtime-client = { workspace = true }

[features]
# This feature adds BLS crypto primitives. It should not be used in production since
# the BLS implementation and interface may still be subject to significant change.
bls-experimental = [
"sp-application-crypto/bls-experimental",
"sp-core/bls-experimental",
]
Loading
Loading