Skip to content

Commit

Permalink
BLS verification (#460)
Browse files Browse the repository at this point in the history
  • Loading branch information
tbraun96 authored Feb 7, 2024
1 parent 7b25b6a commit 68fca9b
Show file tree
Hide file tree
Showing 21 changed files with 247 additions and 38 deletions.
26 changes: 13 additions & 13 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 @@ -77,6 +77,8 @@ hex = { version = "0.4.3", default-features = false }
paste = "1.0.6"
slices = "0.2.0"
schnorrkel = { version = "0.9.1", default-features = false }
blst = "0.3.11"


tangle-testnet-runtime = { package = "tangle-testnet-runtime", path = "runtime/testnet" }
tangle-runtime = { package = "tangle-runtime", path = "runtime/mainnet" }
Expand Down
1 change: 1 addition & 0 deletions pallets/dkg/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ frost-ristretto255 = { package = "frost-ristretto255", workspace = true, default
frost-secp256k1 = { package = "frost-secp256k1", workspace = true, default-features = false }
frost-p256 = { package = "frost-p256", workspace = true, default-features = false }
frost-p384 = { package = "frost-p384", workspace = true, default-features = false }
blst = { workspace = true, default-features = false, features = ["portable", "no-threads"] }

# FROST RedJubjub is not yet no_std compatible
# TODO: Update this once it is.
Expand Down
2 changes: 1 addition & 1 deletion pallets/dkg/frost/frost-ed25519/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ description = "A Schnorr signature scheme over Ed25519 that supports FROST."
parity-scale-codec = { workspace = true }
curve25519-dalek = { version = "=4.1.1", default-features = false }
frost-core = { workspace = true }
rand_core = { version = "0.6", default-features = false, optional = true }
rand_core = { version = "0.6", optional = true }
sha2 = { version = "0.10.2", default-features = false }
subtle = { workspace = true }

Expand Down
2 changes: 1 addition & 1 deletion pallets/dkg/frost/frost-ed448/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ rustdoc-args = ["--cfg", "docsrs"]
parity-scale-codec = { workspace = true }
ed448-goldilocks = { git = "https://github.com/drewstone/Ed448-Goldilocks.git", branch = "drew/zeroize", package = "ed448-goldilocks-plus", default-features = false }
frost-core = { workspace = true }
rand_core = { version = "0.6", default-features = false, optional = true }
rand_core = { version = "0.6", optional = true }
sha3 = { version = "0.10", default-features = false }
subtle = { workspace = true }

Expand Down
2 changes: 1 addition & 1 deletion pallets/dkg/frost/frost-p256/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ description = "A Schnorr signature scheme over Ed25519 that supports FROST."
parity-scale-codec = { workspace = true }
p256 = { version = "0.13.0", features = ["hash2curve", "alloc"], default-features = false }
frost-core = { workspace = true }
rand_core = { version = "0.6", default-features = false, optional = true }
rand_core = { version = "0.6", optional = true }
sha2 = { version = "0.10.2", default-features = false }
subtle = { workspace = true }

Expand Down
2 changes: 1 addition & 1 deletion pallets/dkg/frost/frost-p384/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ rustdoc-args = ["--cfg", "docsrs"]
parity-scale-codec = { workspace = true }
p384 = { version = "0.13.0", features = ["hash2curve", "alloc"], git = "https://github.com/LIT-Protocol/elliptic-curves.git", default-features = false }
frost-core = { workspace = true }
rand_core = { version = "0.6", default-features = false, optional = true }
rand_core = { version = "0.6", optional = true }
sha2 = { version = "0.10.2", default-features = false }
subtle = { workspace = true }

Expand Down
2 changes: 1 addition & 1 deletion pallets/dkg/frost/frost-redjubjub/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ parity-scale-codec = { workspace = true }
jubjub = { version = "0.10", git = "https://github.com/LIT-Protocol/jubjub.git", features = ["alloc"], default-features = false }
group = { version = "0.13", features = ["alloc"], default-features = false }
frost-core = { workspace = true }
rand_core = { version = "0.6", default-features = false, optional = true }
rand_core = { version = "0.6", optional = true }
sha2 = { version = "0.10.2", default-features = false }
subtle = { workspace = true }

Expand Down
2 changes: 1 addition & 1 deletion pallets/dkg/frost/frost-ristretto255/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ description = "A Schnorr signature scheme over Ed25519 that supports FROST."
parity-scale-codec = { workspace = true }
curve25519-dalek = { version = "=4.1.1", default-features = false }
frost-core = { workspace = true }
rand_core = { version = "0.6", default-features = false, optional = true }
rand_core = { version = "0.6", optional = true }
sha2 = { version = "0.10.2", default-features = false }
subtle = { workspace = true }

Expand Down
2 changes: 1 addition & 1 deletion pallets/dkg/frost/frost-secp256k1/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ rustdoc-args = ["--cfg", "docsrs"]
parity-scale-codec = { workspace = true }
k256 = { version = "0.13.0", features = ["arithmetic", "expose-field", "hash2curve", "alloc"], default-features = false }
frost-core = { workspace = true }
rand_core = { version = "0.6", default-features = false, optional = true }
rand_core = { version = "0.6", optional = true }
sha2 = { version = "0.10.2", default-features = false }
subtle = { workspace = true }

Expand Down
1 change: 1 addition & 0 deletions pallets/dkg/frost/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub mod verifying_key;

#[cfg(feature = "std")]
use rand_core::{CryptoRng, RngCore};
#[cfg(feature = "std")]
use traits::{Ciphersuite, Field, Group, Scalar};

/// Generates a random nonzero scalar.
Expand Down
5 changes: 3 additions & 2 deletions pallets/dkg/frost/src/signing_key.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
//! Schnorr signature signing keys
use crate::{
challenge::challenge,
error::Error,
signature::Signature,
traits::{Ciphersuite, Field, Group, Scalar},
util::scalar_is_valid,
verifying_key::VerifyingKey,
};

#[cfg(feature = "std")]
use crate::{challenge::challenge, signature::Signature};

#[cfg(feature = "std")]
use crate::random_nonzero;
#[cfg(feature = "std")]
Expand Down
30 changes: 30 additions & 0 deletions pallets/dkg/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ impl<T: Config> Pallet<T> {
DigitalSignatureScheme::Ecdsa => verify_generated_dkg_key_ecdsa::<T>(data),
DigitalSignatureScheme::SchnorrSr25519 =>
verify_generated_dkg_key_schnorr_sr25519::<T>(data),
DigitalSignatureScheme::Bls381 => verify_generated_dkg_key_ecdsa::<T>(data),
_ => Err(Error::<T>::InvalidSignature.into()),
}
}
Expand All @@ -145,6 +146,7 @@ impl<T: Config> Pallet<T> {
&data.signature,
&data.signing_key,
),
DigitalSignatureScheme::Bls381 => Self::verify_bls_signature(&data),
DigitalSignatureScheme::SchnorrEd25519 |
DigitalSignatureScheme::SchnorrEd448 |
DigitalSignatureScheme::SchnorrP256 |
Expand Down Expand Up @@ -197,4 +199,32 @@ impl<T: Config> Pallet<T> {
_ => Err(Error::<T>::InvalidSignature.into()), // unimplemented
}
}

/// Verifies the DKG signature result for BLS signatures.
///
/// This function uses the BLS signature algorithm to verify the provided signature
/// based on the message data, signature, and signing key in the DKG signature result.
///
/// # Arguments
///
/// * `data` - The DKG signature result containing the message data, BLS signature, and signing
/// key.
fn verify_bls_signature(
data: &DKGTSSSignatureResult<T::MaxDataLen, T::MaxKeyLen, T::MaxSignatureLen>,
) -> DispatchResult {
let public_key = blst::min_pk::PublicKey::deserialize(&data.signing_key)
.map_err(|_err| Error::<T>::InvalidBlsPublicKey)?;
let signature = blst::min_pk::Signature::deserialize(&data.signature)
.map_err(|_err| Error::<T>::InvalidSignatureData)?;
let dst = &mut [0u8; 48];
let signed_data = &data.data;

if signature.verify(true, signed_data, dst, &[], &public_key, true) !=
blst::BLST_ERROR::BLST_SUCCESS
{
return Err(Error::<T>::InvalidSignature.into())
}

Ok(())
}
}
2 changes: 2 additions & 0 deletions pallets/dkg/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ pub mod pallet {
SigningKeyMismatch,
/// Invalid participant public key
InvalidParticipantPublicKey,
/// Invalid BLS public key
InvalidBlsPublicKey,
}

#[pallet::call]
Expand Down
Loading

0 comments on commit 68fca9b

Please sign in to comment.