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 10, 2024
1 parent 246ce02 commit fc70c3e
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)]
#[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,
},
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))]
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,
CryptoError::PairingEquality {
source: PairingEquality::EmptyG1 { .. },
..
} => 14,
CryptoError::PairingEquality {
source: PairingEquality::EmptyG2 { .. },
..
} => 15,
CryptoError::Aggregation {
source: Aggregation::Empty,
..
} => 16,
} => 14,
CryptoError::Aggregation {
source: Aggregation::NotMultiple { .. },
..
} => 17,
} => 15,
}
}
}
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 @@ -428,10 +428,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 @@ -471,12 +471,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 fc70c3e

Please sign in to comment.