Skip to content

Commit f0132ea

Browse files
authored
chore: CRP-2832 Check that the BLS public key is not the identity (#141)
1 parent dd255c8 commit f0132ea

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

backend/rs/ic_vetkeys/src/utils/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,9 +703,15 @@ pub fn verify_bls_signature(dpk: &DerivedPublicKey, input: &[u8], signature: &[u
703703
/// Returns true if and only if the provided signature is valid with respect to
704704
/// the provided public key and input
705705
fn verify_bls_signature_pt(dpk: &DerivedPublicKey, input: &[u8], signature: &G1Affine) -> bool {
706+
if dpk.point.is_identity().into() {
707+
return false;
708+
}
709+
706710
let msg = augmented_hash_to_g1(&dpk.point, input);
707711
let dpk_prep = G2Prepared::from(dpk.point);
708712

713+
// Check that `e(sig, G2) == e(msg, dpk)` using a multipairing
714+
709715
use pairing::group::Group;
710716
let is_valid =
711717
gt_multipairing(&[(signature, &G2PREPARED_NEG_G), (&msg, &dpk_prep)]).is_identity();

backend/rs/ic_vetkeys/tests/utils.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,19 @@ fn test_bls_signature_verification() {
5656
assert!(!verify_bls_signature(&dpk, wrong_msg, &signature));
5757
}
5858

59+
#[test]
60+
fn test_bls_signature_verification_using_identity() {
61+
// Check that the identity element is rejected as a public key
62+
63+
let dpk = DerivedPublicKey::deserialize(&ic_bls12_381::G2Affine::identity().to_compressed()).unwrap();
64+
65+
let msg = b"wrong message";
66+
67+
let signature = ic_bls12_381::G1Affine::identity().to_compressed();
68+
69+
assert!(!verify_bls_signature(&dpk, msg, &signature));
70+
}
71+
5972
#[test]
6073
fn test_second_level_public_key_derivation() {
6174
let canister_key = DerivedPublicKey::deserialize(&hex::decode("8bf165ea580742abf5fd5123eb848aa116dcf75c3ddb3cd3540c852cf99f0c5394e72dfc2f25dbcb5f9220f251cd04040a508a0bcb8b2543908d6626b46f09d614c924c5deb63a9949338ae4f4ac436bd77f8d0a392fd29de0f392a009fa61f3").unwrap()).unwrap();

0 commit comments

Comments
 (0)