Skip to content

Commit bcfae4f

Browse files
webmaster128aumetra
authored andcommitted
Add docs and clarifications to verify_g1/verify_g2
1 parent 34afd26 commit bcfae4f

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed
Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,34 @@
11
use cosmwasm_std::{Api, HashFunction, StdResult, BLS12_381_G1_GENERATOR, BLS12_381_G2_GENERATOR};
22

3+
/// Signature verification with public key in G1 (e.g. drand classic mainnet, ETH2 block headers).
4+
///
5+
/// See https://hackmd.io/@benjaminion/bls12-381#Verification.
36
pub fn verify_g1(
47
api: &dyn Api,
58
signature: &[u8],
69
pubkey: &[u8],
710
msg: &[u8],
811
dst: &[u8],
912
) -> StdResult<bool> {
10-
let s = api.bls12_381_hash_to_g2(HashFunction::Sha256, msg, dst)?;
11-
api.bls12_381_pairing_equality(&BLS12_381_G1_GENERATOR, signature, pubkey, &s)
13+
// The H(m) from the docs
14+
let msg_hash = api.bls12_381_hash_to_g2(HashFunction::Sha256, msg, dst)?;
15+
api.bls12_381_pairing_equality(&BLS12_381_G1_GENERATOR, signature, pubkey, &msg_hash)
1216
.map_err(Into::into)
1317
}
1418

19+
/// Signature verification with public key in G2 (e.g. drand Quicknet)
20+
///
21+
/// See https://hackmd.io/@benjaminion/bls12-381#Verification in combination with
22+
/// https://hackmd.io/@benjaminion/bls12-381#Swapping-G1-and-G2.
1523
pub fn verify_g2(
1624
api: &dyn Api,
1725
signature: &[u8],
1826
pubkey: &[u8],
1927
msg: &[u8],
2028
dst: &[u8],
2129
) -> StdResult<bool> {
22-
let s = api.bls12_381_hash_to_g1(HashFunction::Sha256, msg, dst)?;
23-
api.bls12_381_pairing_equality(signature, &BLS12_381_G2_GENERATOR, &s, pubkey)
30+
// The H(m) from the docs
31+
let msg_hash = api.bls12_381_hash_to_g1(HashFunction::Sha256, msg, dst)?;
32+
api.bls12_381_pairing_equality(signature, &BLS12_381_G2_GENERATOR, &msg_hash, pubkey)
2433
.map_err(Into::into)
2534
}

0 commit comments

Comments
 (0)