Skip to content

Commit 120c83b

Browse files
webmaster128aumetra
authored andcommitted
Add bls12_381_pairing_equality docs
1 parent 3597b14 commit 120c83b

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

packages/std/src/traits.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,32 @@ pub trait Api {
197197
unimplemented!()
198198
}
199199

200+
/// Checks the following pairing equality:
201+
///
202+
/// e(p_1, q_1) × e(p_2, q_2) × … × e(p_n, q_n) = e(s, q)
203+
///
204+
/// The argument `ps` contain the points p_1, ..., p_n ∈ G1 as a concatenation of 48 byte elements.
205+
/// The argument `qs` contain the points q_1, ..., q_n ∈ G2 as a concatenation of 96 byte elements.
206+
///
207+
/// ## Examples
208+
///
209+
/// A simple signature check with one pairing on the left hand side (e(p, q) = e(s, q)):
210+
///
211+
/// ```
212+
/// # use cosmwasm_std::{Api, HashFunction, StdResult};
213+
/// pub fn verify(
214+
/// api: &dyn Api,
215+
/// g1_generator: &[u8],
216+
/// signature: &[u8],
217+
/// pubkey: &[u8],
218+
/// msg: &[u8],
219+
/// dst: &[u8],
220+
/// ) -> StdResult<bool> {
221+
/// let msg_hashed = api.bls12_381_hash_to_g2(HashFunction::Sha256, msg, dst)?;
222+
/// api.bls12_381_pairing_equality(g1_generator, signature, pubkey, &msg_hashed)
223+
/// .map_err(Into::into)
224+
/// }
225+
/// ```
200226
#[allow(unused_variables)]
201227
fn bls12_381_pairing_equality(
202228
&self,

0 commit comments

Comments
 (0)