|
2 | 2 | // SPDX-License-Identifier: Apache-2.0, MIT |
3 | 3 |
|
4 | 4 | use super::BLSVerifier; |
| 5 | +use crate::bdn::BDNAggregation; |
5 | 6 | use bls_signatures::{PrivateKey, Serialize}; |
6 | 7 | use filecoin_f3_gpbft::PubKey; |
7 | 8 | use filecoin_f3_gpbft::api::Verifier; |
@@ -68,3 +69,49 @@ fn test_invalid_signature() { |
68 | 69 | "corrupted signature should fail verification" |
69 | 70 | ); |
70 | 71 | } |
| 72 | + |
| 73 | +#[test] |
| 74 | +fn test_aggregate_signature_verification() { |
| 75 | + let verifier = BLSVerifier::new(); |
| 76 | + let message = b"consensus message"; |
| 77 | + |
| 78 | + // Generate 10 validators for the power table |
| 79 | + let mut signers = Vec::new(); |
| 80 | + let mut power_table = Vec::new(); |
| 81 | + for _ in 0..10 { |
| 82 | + let private_key = PrivateKey::generate(&mut rand::thread_rng()); |
| 83 | + let signer = BLSSigner::new(private_key); |
| 84 | + power_table.push(signer.public_key().clone()); |
| 85 | + signers.push(signer); |
| 86 | + } |
| 87 | + |
| 88 | + // Only 5 validators sign (indices 0, 2, 4, 6, 8) |
| 89 | + let signers_subset = vec![0u64, 2, 4, 6, 8]; |
| 90 | + let sigs: Vec<Vec<u8>> = signers_subset |
| 91 | + .iter() |
| 92 | + .map(|&i| signers[i as usize].sign(message)) |
| 93 | + .collect(); |
| 94 | + |
| 95 | + // Aggregate using BDN with full power table |
| 96 | + let typed_pub_keys: Vec<_> = power_table |
| 97 | + .iter() |
| 98 | + .map(|pk| bls_signatures::PublicKey::from_bytes(&pk.0).unwrap()) |
| 99 | + .collect(); |
| 100 | + let typed_sigs: Vec<_> = sigs |
| 101 | + .iter() |
| 102 | + .map(|sig| bls_signatures::Signature::from_bytes(sig).unwrap()) |
| 103 | + .collect(); |
| 104 | + |
| 105 | + let bdn = BDNAggregation::new(typed_pub_keys).expect("BDN creation should succeed"); |
| 106 | + let agg_sig = bdn |
| 107 | + .aggregate_sigs(&signers_subset, &typed_sigs) |
| 108 | + .expect("aggregation should succeed"); |
| 109 | + |
| 110 | + // Verify aggregate using full power table and signer indices |
| 111 | + let result = |
| 112 | + verifier.verify_aggregate(message, &agg_sig.as_bytes(), &power_table, &signers_subset); |
| 113 | + assert!( |
| 114 | + result.is_ok(), |
| 115 | + "aggregate signature verification should succeed" |
| 116 | + ); |
| 117 | +} |
0 commit comments