Skip to content
Open
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
16 changes: 10 additions & 6 deletions crypto/bls/src/generic_aggregate_signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,27 +124,31 @@ where
/// Aggregates a signature onto `self`.
pub fn add_assign(&mut self, other: &GenericSignature<Pub, Sig>) {
if let Some(other_point) = other.point() {
self.is_infinity = self.is_infinity && other.is_infinity;
if let Some(self_point) = &mut self.point {
self_point.add_assign(other_point)
self_point.add_assign(other_point);
self.is_infinity = self.is_infinity && other.is_infinity;
} else {
let mut self_point = AggSig::infinity();
self_point.add_assign(other_point);
self.point = Some(self_point)
self.point = Some(self_point);
// the result is infinity, if `other` is
self.is_infinity = other.is_infinity;
}
}
}

/// Aggregates an aggregate signature onto `self`.
pub fn add_assign_aggregate(&mut self, other: &Self) {
if let Some(other_point) = other.point() {
self.is_infinity = self.is_infinity && other.is_infinity;
if let Some(self_point) = &mut self.point {
self_point.add_assign_aggregate(other_point)
self_point.add_assign_aggregate(other_point);
self.is_infinity = self.is_infinity && other.is_infinity;
} else {
let mut self_point = AggSig::infinity();
self_point.add_assign_aggregate(other_point);
self.point = Some(self_point)
self.point = Some(self_point);
// the result is infinity, if `other` is
self.is_infinity = other.is_infinity;
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions crypto/bls/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,17 @@ macro_rules! test_suite {
.assert_single_message_verify(true)
}

#[test]
fn empty_aggregate_plus_infinity_should_be_infinity() {
let mut agg = AggregateSignature::empty();
let infinity_sig = Signature::deserialize(&INFINITY_SIGNATURE).unwrap();
agg.add_assign(&infinity_sig);
assert!(
agg.is_infinity(),
"is_infinity flag should be true after adding infinity to empty"
);
}

#[test]
fn deserialize_infinity_public_key() {
PublicKey::deserialize(&bls::INFINITY_PUBLIC_KEY).unwrap_err();
Expand Down
Loading