Skip to content

Commit 34afd26

Browse files
webmaster128aumetra
authored andcommitted
Remove _COMPRESSED from BLS points
1 parent 177c9c3 commit 34afd26

File tree

9 files changed

+36
-31
lines changed

9 files changed

+36
-31
lines changed
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
use cosmwasm_std::{
2-
Api, HashFunction, StdResult, BLS12_381_G1_GENERATOR_COMPRESSED,
3-
BLS12_381_G2_GENERATOR_COMPRESSED,
4-
};
1+
use cosmwasm_std::{Api, HashFunction, StdResult, BLS12_381_G1_GENERATOR, BLS12_381_G2_GENERATOR};
52

63
pub fn verify_g1(
74
api: &dyn Api,
@@ -11,7 +8,7 @@ pub fn verify_g1(
118
dst: &[u8],
129
) -> StdResult<bool> {
1310
let s = api.bls12_381_hash_to_g2(HashFunction::Sha256, msg, dst)?;
14-
api.bls12_381_pairing_equality(&BLS12_381_G1_GENERATOR_COMPRESSED, signature, pubkey, &s)
11+
api.bls12_381_pairing_equality(&BLS12_381_G1_GENERATOR, signature, pubkey, &s)
1512
.map_err(Into::into)
1613
}
1714

@@ -23,6 +20,6 @@ pub fn verify_g2(
2320
dst: &[u8],
2421
) -> StdResult<bool> {
2522
let s = api.bls12_381_hash_to_g1(HashFunction::Sha256, msg, dst)?;
26-
api.bls12_381_pairing_equality(signature, &BLS12_381_G2_GENERATOR_COMPRESSED, &s, pubkey)
23+
api.bls12_381_pairing_equality(signature, &BLS12_381_G2_GENERATOR, &s, pubkey)
2724
.map_err(Into::into)
2825
}

packages/crypto/benches/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use cosmwasm_crypto::{
1919
bls12_381_aggregate_g1, bls12_381_aggregate_g2, bls12_381_hash_to_g1, bls12_381_hash_to_g2,
2020
bls12_381_pairing_equality, ed25519_batch_verify, ed25519_verify, secp256k1_recover_pubkey,
2121
secp256k1_verify, secp256r1_recover_pubkey, secp256r1_verify, HashFunction,
22-
BLS12_381_G1_GENERATOR_COMPRESSED, BLS12_381_G1_POINT_LEN, BLS12_381_G2_POINT_LEN,
22+
BLS12_381_G1_GENERATOR, BLS12_381_G1_POINT_LEN, BLS12_381_G2_POINT_LEN,
2323
};
2424
use std::cmp::min;
2525

@@ -192,7 +192,7 @@ where
192192
let is_valid = black_box(bls12_381_pairing_equality(
193193
&serialized_pubkeys,
194194
&serialized_messages,
195-
&BLS12_381_G1_GENERATOR_COMPRESSED,
195+
&BLS12_381_G1_GENERATOR,
196196
&serialized_signature,
197197
))
198198
.unwrap();
@@ -224,7 +224,7 @@ where
224224
});
225225

226226
group.bench_function("bls12_381_verify", |b| {
227-
let generator = BLS12_381_G1_GENERATOR_COMPRESSED;
227+
let generator = BLS12_381_G1_GENERATOR;
228228
let message = bls12_381_hash_to_g2(HashFunction::Sha256, &BLS_MESSAGE, BLS_DST);
229229

230230
b.iter(|| {

packages/crypto/src/bls12_318/constants.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
pub const BLS12_381_G1_POINT_LEN: usize = 48;
22
pub const BLS12_381_G2_POINT_LEN: usize = 96;
33

4-
pub const BLS12_381_G1_GENERATOR_COMPRESSED: [u8; BLS12_381_G1_POINT_LEN] = [
4+
/// A generator in G1 (in compressed serialization).
5+
///
6+
/// This can be used directly for signature verification
7+
/// (see e.g. https://twitter.com/simon_warta/status/1786342207106019765)
8+
pub const BLS12_381_G1_GENERATOR: [u8; BLS12_381_G1_POINT_LEN] = [
59
151, 241, 211, 167, 49, 151, 215, 148, 38, 149, 99, 140, 79, 169, 172, 15, 195, 104, 140, 79,
610
151, 116, 185, 5, 161, 78, 58, 63, 23, 27, 172, 88, 108, 85, 232, 63, 249, 122, 26, 239, 251,
711
58, 240, 10, 219, 34, 198, 187,
812
];
9-
pub const BLS12_381_G2_GENERATOR_COMPRESSED: [u8; BLS12_381_G2_POINT_LEN] = [
13+
14+
/// A generator in G2 (in compressed serialization).
15+
///
16+
/// This can be used directly for signature verification
17+
/// (see e.g. https://twitter.com/simon_warta/status/1786342207106019765)
18+
pub const BLS12_381_G2_GENERATOR: [u8; BLS12_381_G2_POINT_LEN] = [
1019
147, 224, 43, 96, 82, 113, 159, 96, 125, 172, 211, 160, 136, 39, 79, 101, 89, 107, 208, 208,
1120
153, 32, 182, 26, 181, 218, 97, 187, 220, 127, 80, 73, 51, 76, 241, 18, 19, 148, 93, 87, 229,
1221
172, 125, 5, 93, 4, 43, 126, 2, 74, 162, 178, 240, 143, 10, 145, 38, 8, 5, 39, 45, 197, 16, 81,
@@ -21,9 +30,10 @@ mod test {
2130
use ark_serialize::CanonicalSerialize;
2231
use hex_literal::hex;
2332

24-
use super::{BLS12_381_G1_GENERATOR_COMPRESSED, BLS12_381_G2_GENERATOR_COMPRESSED};
25-
26-
use crate::{BLS12_381_G1_POINT_LEN, BLS12_381_G2_POINT_LEN};
33+
use super::{
34+
BLS12_381_G1_GENERATOR, BLS12_381_G1_POINT_LEN, BLS12_381_G2_GENERATOR,
35+
BLS12_381_G2_POINT_LEN,
36+
};
2737

2838
fn bls12_381_g1_generator() -> [u8; BLS12_381_G1_POINT_LEN] {
2939
let mut point = [0_u8; BLS12_381_G1_POINT_LEN];
@@ -51,7 +61,7 @@ mod test {
5161
let mut generator = hex!("17f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb");
5262
generator[0] |= 0b1000_0000;
5363
assert_eq!(generator, bls12_381_g1_generator());
54-
assert_eq!(bls12_381_g1_generator(), BLS12_381_G1_GENERATOR_COMPRESSED);
64+
assert_eq!(bls12_381_g1_generator(), BLS12_381_G1_GENERATOR);
5565
}
5666

5767
#[test]
@@ -64,6 +74,6 @@ mod test {
6474
let mut generator = hex!("13e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb8");
6575
generator[0] |= 0b1000_0000;
6676
assert_eq!(generator, bls12_381_g2_generator());
67-
assert_eq!(bls12_381_g2_generator(), BLS12_381_G2_GENERATOR_COMPRESSED);
77+
assert_eq!(bls12_381_g2_generator(), BLS12_381_G2_GENERATOR);
6878
}
6979
}

packages/crypto/src/bls12_318/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
mod constants;
22

33
pub use self::constants::{
4-
BLS12_381_G1_GENERATOR_COMPRESSED, BLS12_381_G1_POINT_LEN, BLS12_381_G2_GENERATOR_COMPRESSED,
5-
BLS12_381_G2_POINT_LEN,
4+
BLS12_381_G1_GENERATOR, BLS12_381_G1_POINT_LEN, BLS12_381_G2_GENERATOR, BLS12_381_G2_POINT_LEN,
65
};
76

87
cfg_if::cfg_if! {

packages/crypto/src/bls12_318/points.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,21 +195,21 @@ pub fn bls12_381_g2_is_identity(g2: &[u8; BLS12_381_G2_POINT_LEN]) -> Result<boo
195195

196196
#[cfg(test)]
197197
mod tests {
198-
use crate::{BLS12_381_G1_GENERATOR_COMPRESSED, BLS12_381_G2_GENERATOR_COMPRESSED};
198+
use crate::{BLS12_381_G1_GENERATOR, BLS12_381_G2_GENERATOR};
199199

200200
use super::*;
201201
use hex_literal::hex;
202202

203203
#[test]
204204
fn g1_generator_works() {
205205
let generator = G1::generator();
206-
assert_eq!(generator.to_compressed(), BLS12_381_G1_GENERATOR_COMPRESSED);
206+
assert_eq!(generator.to_compressed(), BLS12_381_G1_GENERATOR);
207207
}
208208

209209
#[test]
210210
fn g2_generator_works() {
211211
let generator = G2::generator();
212-
assert_eq!(generator.to_compressed(), BLS12_381_G2_GENERATOR_COMPRESSED);
212+
assert_eq!(generator.to_compressed(), BLS12_381_G2_GENERATOR);
213213
}
214214

215215
#[test]

packages/crypto/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ pub use crate::bls12_318::{
2929

3030
#[doc(hidden)]
3131
pub use crate::bls12_318::{
32-
BLS12_381_G1_GENERATOR_COMPRESSED, BLS12_381_G1_POINT_LEN, BLS12_381_G2_GENERATOR_COMPRESSED,
33-
BLS12_381_G2_POINT_LEN,
32+
BLS12_381_G1_GENERATOR, BLS12_381_G1_POINT_LEN, BLS12_381_G2_GENERATOR, BLS12_381_G2_POINT_LEN,
3433
};
3534
#[doc(hidden)]
3635
pub use crate::ecdsa::{ECDSA_PUBKEY_MAX_LEN, ECDSA_SIGNATURE_LEN, MESSAGE_HASH_MAX_LEN};

packages/crypto/tests/bls12_381.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use base64_serde::base64_serde_type;
88
use cosmwasm_crypto::{
99
bls12_381_aggregate_g1, bls12_381_aggregate_g2, bls12_381_g1_is_identity,
1010
bls12_381_g2_is_identity, bls12_381_hash_to_g2, bls12_381_pairing_equality, HashFunction,
11-
BLS12_381_G1_GENERATOR_COMPRESSED, BLS12_381_G2_POINT_LEN,
11+
BLS12_381_G1_GENERATOR, BLS12_381_G2_POINT_LEN,
1212
};
1313

1414
const PROOF_OF_POSSESSION_DST: &[u8] = b"BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_";
@@ -261,7 +261,7 @@ fn bls12_381_verify_works() {
261261
let bool_result = bls12_381_pairing_equality(
262262
&pubkey,
263263
&message_point,
264-
&BLS12_381_G1_GENERATOR_COMPRESSED,
264+
&BLS12_381_G1_GENERATOR,
265265
&signature,
266266
)?;
267267

@@ -337,7 +337,7 @@ fn bls12_381_aggregate_verify_works() {
337337
let bool_result = bls12_381_pairing_equality(
338338
&pubkeys,
339339
&messages,
340-
&BLS12_381_G1_GENERATOR_COMPRESSED,
340+
&BLS12_381_G1_GENERATOR,
341341
&signature,
342342
)?;
343343

@@ -412,7 +412,7 @@ fn bls12_381_fast_aggregate_verify_works() {
412412
let bool_result = bls12_381_pairing_equality(
413413
&pubkey,
414414
&message_point,
415-
&BLS12_381_G1_GENERATOR_COMPRESSED,
415+
&BLS12_381_G1_GENERATOR,
416416
&signature,
417417
)?;
418418

packages/std/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,6 @@ pub use cosmwasm_core::{
122122
#[cfg(not(target_arch = "wasm32"))]
123123
pub use cosmwasm_core::assert_approx_eq;
124124

125-
pub use cosmwasm_crypto::{BLS12_381_G1_GENERATOR_COMPRESSED, BLS12_381_G2_GENERATOR_COMPRESSED};
125+
pub use cosmwasm_crypto::{BLS12_381_G1_GENERATOR, BLS12_381_G2_GENERATOR};
126126

127127
pub use cosmwasm_derive::entry_point;

packages/std/src/testing/mock.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,7 +1168,7 @@ mod tests {
11681168
#[cfg(feature = "staking")]
11691169
use crate::{Decimal, Delegation};
11701170
use base64::{engine::general_purpose, Engine};
1171-
use cosmwasm_crypto::BLS12_381_G1_GENERATOR_COMPRESSED;
1171+
use cosmwasm_crypto::BLS12_381_G1_GENERATOR;
11721172
use hex_literal::hex;
11731173
use serde::Deserialize;
11741174

@@ -1377,7 +1377,7 @@ mod tests {
13771377
let s = hex!("9104e74b9dfd3ad502f25d6a5ef57db0ed7d9a0e00f3500586d8ce44231212542fcfaf87840539b398bf07626705cf1105d246ca1062c6c2e1a53029a0f790ed5e3cb1f52f8234dc5144c45fc847c0cd37a92d68e7c5ba7c648a8a339f171244");
13781378

13791379
let is_valid = api
1380-
.bls12_381_pairing_equality(&ps, &qs, &BLS12_381_G1_GENERATOR_COMPRESSED, &s)
1380+
.bls12_381_pairing_equality(&ps, &qs, &BLS12_381_G1_GENERATOR, &s)
13811381
.unwrap();
13821382
assert!(is_valid);
13831383
}
@@ -1439,7 +1439,7 @@ mod tests {
14391439

14401440
let is_valid = api
14411441
.bls12_381_pairing_equality(
1442-
&BLS12_381_G1_GENERATOR_COMPRESSED,
1442+
&BLS12_381_G1_GENERATOR,
14431443
&signature,
14441444
&PK_LEO_MAINNET,
14451445
&msg_point,

0 commit comments

Comments
 (0)