Skip to content

Commit

Permalink
Remove error checks about empty pairing equality
Browse files Browse the repository at this point in the history
  • Loading branch information
aumetra committed May 7, 2024
1 parent ee64b92 commit 0765c32
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 61 deletions.
16 changes: 0 additions & 16 deletions packages/core/src/errors/verification_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ pub enum AggregationError {
#[derive(Display, Debug, PartialEq)]

Check warning on line 18 in packages/core/src/errors/verification_error.rs

View check run for this annotation

Codecov / codecov/patch

packages/core/src/errors/verification_error.rs#L18

Added line #L18 was not covered by tests
#[cfg_attr(feature = "std", derive(thiserror::Error))]
pub enum PairingEqualityError {
#[display("List of G1 points is empty")]
EmptyG1,
#[display("List of G2 points is empty")]
EmptyG2,
#[display("List is not a multiple of 48")]
NotMultipleG1,
#[display("List is not a multiple of 96")]
Expand Down Expand Up @@ -125,18 +121,6 @@ impl From<CryptoError> for VerificationError {
} => VerificationError::Aggregation {
source: AggregationError::NotMultiple,
},

Check warning on line 123 in packages/core/src/errors/verification_error.rs

View check run for this annotation

Codecov / codecov/patch

packages/core/src/errors/verification_error.rs#L121-L123

Added lines #L121 - L123 were not covered by tests
CryptoError::PairingEquality {
source: cosmwasm_crypto::PairingEqualityError::EmptyG1,
..
} => VerificationError::PairingEquality {
source: PairingEqualityError::EmptyG1,
},
CryptoError::PairingEquality {
source: cosmwasm_crypto::PairingEqualityError::EmptyG2,
..
} => VerificationError::PairingEquality {
source: PairingEqualityError::EmptyG2,
},
CryptoError::PairingEquality {
source: cosmwasm_crypto::PairingEqualityError::NotMultipleG1 { .. },
..
Expand Down
24 changes: 1 addition & 23 deletions packages/crypto/src/bls12_318/pairing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ pub fn bls12_381_pairing_equality(
r: &[u8],
s: &[u8],
) -> Result<bool, CryptoError> {
if ps.is_empty() {
return Err(PairingEquality::EmptyG1.into());
} else if qs.is_empty() {
return Err(PairingEquality::EmptyG2.into());
} else if ps.len() % BLS12_381_G1_POINT_LEN != 0 {
if ps.len() % BLS12_381_G1_POINT_LEN != 0 {
return Err(PairingEquality::NotMultipleG1 {
remainder: ps.len() % BLS12_381_G1_POINT_LEN,
}
Expand Down Expand Up @@ -159,24 +155,6 @@ mod test {

#[test]
fn pairing_equality_error_cases_work() {
let result = bls12_381_pairing_equality(&[], &[12], &[12], &[12]);
assert!(matches!(
result,
Err(CryptoError::PairingEquality {
source: PairingEqualityError::EmptyG1,
..
})
));

let result = bls12_381_pairing_equality(&[12], &[], &[12], &[12]);
assert!(matches!(
result,
Err(CryptoError::PairingEquality {
source: PairingEqualityError::EmptyG2,
..
})
));

let result = bls12_381_pairing_equality(&[12], &[0; 96], &[12], &[12]);
assert!(matches!(
result,
Expand Down
16 changes: 2 additions & 14 deletions packages/crypto/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ pub enum Aggregation {
#[derive(Debug, Display)]
#[cfg_attr(feature = "std", derive(thiserror::Error))]

Check warning on line 22 in packages/crypto/src/errors.rs

View check run for this annotation

Codecov / codecov/patch

packages/crypto/src/errors.rs#L21-L22

Added lines #L21 - L22 were not covered by tests
pub enum PairingEquality {
#[display("List of G1 points is empty")]
EmptyG1,
#[display("List of G2 points is empty")]
EmptyG2,
#[display("List is not a multiple of 48. Remainder: {remainder}")]
NotMultipleG1 { remainder: usize },
#[display("List is not a multiple of 96. Remainder: {remainder}")]
Expand Down Expand Up @@ -139,22 +135,14 @@ impl CryptoError {
source: PairingEquality::UnequalPointAmount { .. },
..
} => 13,

Check warning on line 137 in packages/crypto/src/errors.rs

View check run for this annotation

Codecov / codecov/patch

packages/crypto/src/errors.rs#L137

Added line #L137 was not covered by tests
CryptoError::PairingEquality {
source: PairingEquality::EmptyG1 { .. },
..
} => 14,
CryptoError::PairingEquality {
source: PairingEquality::EmptyG2 { .. },
..
} => 15,
CryptoError::Aggregation {
source: Aggregation::Empty,
..
} => 16,
} => 14,

Check warning on line 141 in packages/crypto/src/errors.rs

View check run for this annotation

Codecov / codecov/patch

packages/crypto/src/errors.rs#L141

Added line #L141 was not covered by tests
CryptoError::Aggregation {
source: Aggregation::NotMultiple { .. },
..
} => 17,
} => 15,

Check warning on line 145 in packages/crypto/src/errors.rs

View check run for this annotation

Codecov / codecov/patch

packages/crypto/src/errors.rs#L145

Added line #L145 was not covered by tests
}
}
}
Expand Down
10 changes: 2 additions & 8 deletions packages/std/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,10 +420,10 @@ impl Api for ExternalApi {
match result {
0 => Ok(point),
8 => Err(VerificationError::InvalidPoint),
16 => Err(VerificationError::Aggregation {
14 => Err(VerificationError::Aggregation {
source: AggregationError::Empty,
}),
17 => Err(VerificationError::Aggregation {
15 => Err(VerificationError::Aggregation {
source: AggregationError::NotMultiple,
}),
error_code => Err(VerificationError::unknown_err(error_code)),
Expand Down Expand Up @@ -463,12 +463,6 @@ impl Api for ExternalApi {
13 => Err(VerificationError::PairingEquality {
source: PairingEqualityError::UnequalPointAmount,
}),
14 => Err(VerificationError::PairingEquality {
source: PairingEqualityError::EmptyG1,
}),
15 => Err(VerificationError::PairingEquality {
source: PairingEqualityError::EmptyG2,
}),
error_code => Err(VerificationError::unknown_err(error_code)),
}
}
Expand Down

0 comments on commit 0765c32

Please sign in to comment.