From f2a0ffb6ce998fe0cdac413cc5273318db32f28e Mon Sep 17 00:00:00 2001 From: Antonio Sanso Date: Wed, 7 Dec 2022 16:16:36 +0100 Subject: [PATCH 1/4] Adding further deserialization tests taken from https://github.com/ethereum/bls12-381-tests/ --- crypto/src/engine/mod.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/crypto/src/engine/mod.rs b/crypto/src/engine/mod.rs index f61fd50..053128e 100644 --- a/crypto/src/engine/mod.rs +++ b/crypto/src/engine/mod.rs @@ -14,6 +14,7 @@ mod blst; mod both; use crate::{CeremonyError, F, G1, G2}; +use hex_literal::hex; pub use secrecy::Secret; #[cfg(feature = "arkworks")] @@ -116,6 +117,10 @@ pub mod tests { let g1 = G1([0u8; 48]); assert!(BLST::validate_g1(&[g1]).is_err()); assert!(Arkworks::validate_g1(&[g1]).is_err()); + + let g1 = G1(hex!("8123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")); + assert!(BLST::validate_g1(&[g1]).is_err()); + assert!(Arkworks::validate_g1(&[g1]).is_err()); } #[test] From 6ab4ef81da317de86e926033f92b6ecaf9da49d2 Mon Sep 17 00:00:00 2001 From: Antonio Sanso Date: Wed, 7 Dec 2022 16:19:23 +0100 Subject: [PATCH 2/4] Adding further deserialization tests taken from https://github.com/ethereum/bls12-381-tests/ --- crypto/src/engine/mod.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crypto/src/engine/mod.rs b/crypto/src/engine/mod.rs index 053128e..ff58940 100644 --- a/crypto/src/engine/mod.rs +++ b/crypto/src/engine/mod.rs @@ -118,9 +118,15 @@ pub mod tests { assert!(BLST::validate_g1(&[g1]).is_err()); assert!(Arkworks::validate_g1(&[g1]).is_err()); + //deserialization_fails_not_in_G1 let g1 = G1(hex!("8123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")); assert!(BLST::validate_g1(&[g1]).is_err()); assert!(Arkworks::validate_g1(&[g1]).is_err()); + + //ddeserialization_fails_not_in_curve + let g1 = G1(hex!("8123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcde0")); + assert!(BLST::validate_g1(&[g1]).is_err()); + assert!(Arkworks::validate_g1(&[g1]).is_err()); } #[test] From de2a7f850d915a82f77916e24748f127b59def96 Mon Sep 17 00:00:00 2001 From: Antonio Sanso Date: Wed, 14 Dec 2022 14:46:52 +0100 Subject: [PATCH 3/4] Adding further deserialization tests taken from https://github.com/ethereum/bls12-381-tests/ --- crypto/src/engine/mod.rs | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/crypto/src/engine/mod.rs b/crypto/src/engine/mod.rs index ff58940..fa0f552 100644 --- a/crypto/src/engine/mod.rs +++ b/crypto/src/engine/mod.rs @@ -123,10 +123,45 @@ pub mod tests { assert!(BLST::validate_g1(&[g1]).is_err()); assert!(Arkworks::validate_g1(&[g1]).is_err()); - //ddeserialization_fails_not_in_curve + //deserialization_fails_not_in_curve let g1 = G1(hex!("8123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcde0")); assert!(BLST::validate_g1(&[g1]).is_err()); assert!(Arkworks::validate_g1(&[g1]).is_err()); + + //Exactly the modulus, q + let g1 = G1(hex!("9a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab")); + assert!(BLST::validate_g1(&[g1]).is_err()); + assert!(Arkworks::validate_g1(&[g1]).is_err()); + + //One more than the modulus, q + let g1 = G1(hex!("9a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaac")); + assert!(BLST::validate_g1(&[g1]).is_err()); + assert!(Arkworks::validate_g1(&[g1]).is_err()); + + //deserialization_fails_infinity_with_true_b_flag + let g1 = G1(hex!("c01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")); + assert!(BLST::validate_g1(&[g1]).is_err()); + assert!(Arkworks::validate_g1(&[g1]).is_err()); + + //deserialization_fails_infinity_with_false_b_flag + let g1 = G1(hex!("800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")); + assert!(BLST::validate_g1(&[g1]).is_err()); + assert!(Arkworks::validate_g1(&[g1]).is_err()); + + //deserialization_fails_with_wrong_c_flag + let g1 = G1(hex!("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")); + assert!(BLST::validate_g1(&[g1]).is_err()); + assert!(Arkworks::validate_g1(&[g1]).is_err()); + + //deserialization_fails_with_b_flag_and_x_nonzero + let g1 = G1(hex!("c123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")); + assert!(BLST::validate_g1(&[g1]).is_err()); + assert!(Arkworks::validate_g1(&[g1]).is_err()); + + //deserialization_fails_with_b_flag_and_a_flag_true + let g1 = G1(hex!("e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")); + assert!(BLST::validate_g1(&[g1]).is_err()); + assert!(Arkworks::validate_g1(&[g1]).is_err()); } #[test] From adc71b95d8d4dbc86f95bc128ff94055c23ca204 Mon Sep 17 00:00:00 2001 From: Antonio Sanso Date: Wed, 14 Dec 2022 15:13:53 +0100 Subject: [PATCH 4/4] Adding further deserialization tests taken from https://github.com/ethereum/bls12-381-tests/ --- crypto/src/engine/mod.rs | 55 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/crypto/src/engine/mod.rs b/crypto/src/engine/mod.rs index fa0f552..58fd35a 100644 --- a/crypto/src/engine/mod.rs +++ b/crypto/src/engine/mod.rs @@ -169,6 +169,61 @@ pub mod tests { let g2 = G2([0u8; 96]); assert!(BLST::validate_g2(&[g2]).is_err()); assert!(Arkworks::validate_g2(&[g2]).is_err()); + + //xRe is exactly the modulus, q, xIm is zero + let g2 = G2(hex!("8000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab")); + assert!(BLST::validate_g2(&[g2]).is_err()); + assert!(Arkworks::validate_g2(&[g2]).is_err()); + + //xIm is exactly the modulus, q, xRe is zero + let g2 = G2(hex!("9a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")); + assert!(BLST::validate_g2(&[g2]).is_err()); + assert!(Arkworks::validate_g2(&[g2]).is_err()); + + //xRe is the modulus plus 1, xIm is zero + let g2 = G2(hex!("8000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaac")); + assert!(BLST::validate_g2(&[g2]).is_err()); + assert!(Arkworks::validate_g2(&[g2]).is_err()); + + //xIm is the modulus plus 1, xRe is zero + let g2 = G2(hex!("9a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaac000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")); + assert!(BLST::validate_g2(&[g2]).is_err()); + assert!(Arkworks::validate_g2(&[g2]).is_err()); + + //deserialization_fails_not_in_G2 + let g2 = G2(hex!("8123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")); + assert!(BLST::validate_g2(&[g2]).is_err()); + assert!(Arkworks::validate_g2(&[g2]).is_err()); + + //deserialization_fails_not_in_curve + let g2 = G2(hex!("8123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcde0")); + assert!(BLST::validate_g2(&[g2]).is_err()); + assert!(Arkworks::validate_g2(&[g2]).is_err()); + + //deserialization_fails_infinity_with_true_b_flag + let g2 = G2(hex!("c01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")); + assert!(BLST::validate_g2(&[g2]).is_err()); + assert!(Arkworks::validate_g2(&[g2]).is_err()); + + //deserialization_fails_infinity_with_false_b_flag + let g2 = G2(hex!("800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")); + assert!(BLST::validate_g2(&[g2]).is_err()); + assert!(Arkworks::validate_g2(&[g2]).is_err()); + + //deserialization_fails_with_wrong_c_flag + let g2 = G2(hex!("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")); + assert!(BLST::validate_g2(&[g2]).is_err()); + assert!(Arkworks::validate_g2(&[g2]).is_err()); + + //deserialization_fails_with_b_flag_and_x_nonzero + let g2 = G2(hex!("c123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")); + assert!(BLST::validate_g2(&[g2]).is_err()); + assert!(Arkworks::validate_g2(&[g2]).is_err()); + + //deserialization_fails_with_b_flag_and_a_flag_true + let g2 = G2(hex!("e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")); + assert!(BLST::validate_g2(&[g2]).is_err()); + assert!(Arkworks::validate_g2(&[g2]).is_err()); } }