-
Notifications
You must be signed in to change notification settings - Fork 349
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add docs and clarifications to verify_g1/verify_g2
- Loading branch information
1 parent
34afd26
commit bcfae4f
Showing
1 changed file
with
13 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,34 @@ | ||
use cosmwasm_std::{Api, HashFunction, StdResult, BLS12_381_G1_GENERATOR, BLS12_381_G2_GENERATOR}; | ||
|
||
/// Signature verification with public key in G1 (e.g. drand classic mainnet, ETH2 block headers). | ||
/// | ||
/// See https://hackmd.io/@benjaminion/bls12-381#Verification. | ||
pub fn verify_g1( | ||
api: &dyn Api, | ||
signature: &[u8], | ||
pubkey: &[u8], | ||
msg: &[u8], | ||
dst: &[u8], | ||
) -> StdResult<bool> { | ||
let s = api.bls12_381_hash_to_g2(HashFunction::Sha256, msg, dst)?; | ||
api.bls12_381_pairing_equality(&BLS12_381_G1_GENERATOR, signature, pubkey, &s) | ||
// The H(m) from the docs | ||
let msg_hash = api.bls12_381_hash_to_g2(HashFunction::Sha256, msg, dst)?; | ||
api.bls12_381_pairing_equality(&BLS12_381_G1_GENERATOR, signature, pubkey, &msg_hash) | ||
.map_err(Into::into) | ||
} | ||
|
||
/// Signature verification with public key in G2 (e.g. drand Quicknet) | ||
/// | ||
/// See https://hackmd.io/@benjaminion/bls12-381#Verification in combination with | ||
/// https://hackmd.io/@benjaminion/bls12-381#Swapping-G1-and-G2. | ||
pub fn verify_g2( | ||
api: &dyn Api, | ||
signature: &[u8], | ||
pubkey: &[u8], | ||
msg: &[u8], | ||
dst: &[u8], | ||
) -> StdResult<bool> { | ||
let s = api.bls12_381_hash_to_g1(HashFunction::Sha256, msg, dst)?; | ||
api.bls12_381_pairing_equality(signature, &BLS12_381_G2_GENERATOR, &s, pubkey) | ||
// The H(m) from the docs | ||
let msg_hash = api.bls12_381_hash_to_g1(HashFunction::Sha256, msg, dst)?; | ||
api.bls12_381_pairing_equality(signature, &BLS12_381_G2_GENERATOR, &msg_hash, pubkey) | ||
.map_err(Into::into) | ||
} |