diff --git a/dash/Cargo.toml b/dash/Cargo.toml index c1407b163..27ff95c79 100644 --- a/dash/Cargo.toml +++ b/dash/Cargo.toml @@ -66,7 +66,7 @@ hex = { version= "0.4" } bincode = { version= "=2.0.0-rc.3", optional = true } bincode_derive = { version= "=2.0.0-rc.3", optional = true } bitflags = "2.9.0" -blsful = { git = "https://github.com/dashpay/agora-blsful", rev = "5f017aa1a0452ebc73e47f219f50c906522df4ea", optional = true } +blsful = { git = "https://github.com/dashpay/agora-blsful", rev = "be108b2cf6ac64eedbe04f91c63731533c8956bc", optional = true } ed25519-dalek = { version = "2.1", features = ["rand_core"], optional = true } blake3 = "1.8.1" thiserror = "2" diff --git a/dash/src/sml/quorum_entry/validation.rs b/dash/src/sml/quorum_entry/validation.rs index 3625c3183..a11e9bd37 100644 --- a/dash/src/sml/quorum_entry/validation.rs +++ b/dash/src/sml/quorum_entry/validation.rs @@ -1,10 +1,10 @@ -use blsful::verify_secure_basic_with_mode; -use blsful::{Bls12381G2Impl, PublicKey, SerializationFormat, Signature, SignatureSchemes}; -use hashes::Hash; - use crate::sml::masternode_list_entry::MasternodeListEntry; use crate::sml::quorum_entry::qualified_quorum_entry::QualifiedQuorumEntry; use crate::sml::quorum_validation_error::QuorumValidationError; +use blsful::inner_types::GroupEncoding; +use blsful::verify_secure_basic_with_mode; +use blsful::{Bls12381G2Impl, PublicKey, SerializationFormat, Signature, SignatureSchemes}; +use hashes::Hash; impl QualifiedQuorumEntry { /// Verifies the aggregated commitment signature for the quorum. @@ -36,18 +36,12 @@ impl QualifiedQuorumEntry { let message = message.as_slice(); // Collect public keys with proper legacy/modern deserialization - let mut uses_any_legacy = false; let public_keys: Vec> = operator_keys .into_iter() .filter_map(|masternode_list_entry| { let bytes = masternode_list_entry.operator_public_key.as_ref(); let is_legacy = masternode_list_entry.use_legacy_bls_keys(); - // Track if any key uses legacy format - if is_legacy { - uses_any_legacy = true; - } - let format = if is_legacy { SerializationFormat::Legacy } else { @@ -68,55 +62,12 @@ impl QualifiedQuorumEntry { .collect(); // Deserialize the aggregated signature - // Note: We may need to handle legacy format for signatures as well - let sig_bytes = self.quorum_entry.all_commitment_aggregated_signature.as_bytes(); - let sig_format = if uses_any_legacy { - SerializationFormat::Legacy - } else { - SerializationFormat::Modern - }; - let signature = Signature::::from_bytes_with_mode( - sig_bytes, - SignatureSchemes::Basic, - sig_format, // Use same format as keys - ) - .map_err(|e| { - QuorumValidationError::AllCommitmentAggregatedSignatureNotValid(e.to_string()) - })?; - - // Extract the inner signature for verify_secure - let inner_sig = match signature { - Signature::Basic(sig) => sig, - _ => { - return Err(QuorumValidationError::AllCommitmentAggregatedSignatureNotValid( - "Expected Basic signature scheme".to_string(), - )); - } - }; + let signature: Signature = + self.quorum_entry.all_commitment_aggregated_signature.try_into()?; - // Verify using secure aggregation - // The legacy flag must match whether ANY of the keys used legacy format - let verified = verify_secure_basic_with_mode::( - &public_keys, - inner_sig, - message, - sig_format, // Use same format as keys and signature - ) - .is_ok(); - - if verified { - Ok(()) - } else { - Err(QuorumValidationError::AllCommitmentAggregatedSignatureNotValid(format!( - "Signature verification failed: {} keys parsed, {} format used", - public_keys.len(), - if uses_any_legacy { - "legacy" - } else { - "modern" - } - ))) - } + signature.verify_secure(&public_keys, message).map_err(|e| { + QuorumValidationError::AllCommitmentAggregatedSignatureNotValid(e.to_string()) + }) } /// Verifies the quorum's threshold signature.