Module sui::bls12381
Group operations of BLS12-381.
- Struct
Scalar
- Struct
G1
- Struct
G2
- Struct
GT
- Struct
UncompressedG1
- Constants
- Function
bls12381_min_sig_verify
- Function
bls12381_min_pk_verify
- Function
scalar_from_bytes
- Function
scalar_from_u64
- Function
scalar_zero
- Function
scalar_one
- Function
scalar_add
- Function
scalar_sub
- Function
scalar_mul
- Function
scalar_div
- Function
scalar_neg
- Function
scalar_inv
- Function
g1_from_bytes
- Function
g1_identity
- Function
g1_generator
- Function
g1_add
- Function
g1_sub
- Function
g1_mul
- Function
g1_div
- Function
g1_neg
- Function
hash_to_g1
- Function
g1_multi_scalar_multiplication
- Function
g1_to_uncompressed_g1
- Function
g2_from_bytes
- Function
g2_identity
- Function
g2_generator
- Function
g2_add
- Function
g2_sub
- Function
g2_mul
- Function
g2_div
- Function
g2_neg
- Function
hash_to_g2
- Function
g2_multi_scalar_multiplication
- Function
gt_identity
- Function
gt_generator
- Function
gt_add
- Function
gt_sub
- Function
gt_mul
- Function
gt_div
- Function
gt_neg
- Function
pairing
- Function
uncompressed_g1_to_g1
- Function
uncompressed_g1_sum
use std::ascii;
use std::bcs;
use std::option;
use std::string;
use std::vector;
use sui::address;
use sui::bcs;
use sui::group_ops;
use sui::hex;
Struct Scalar
public struct Scalar
Fields
Struct G1
public struct G1
Fields
Struct G2
public struct G2
Fields
Struct GT
public struct GT
Fields
Struct UncompressedG1
public struct UncompressedG1
Fields
Constants
const SCALAR_ZERO_BYTES: vector<u8> = vector[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
const SCALAR_ONE_BYTES: vector<u8> = vector[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1];
const G1_IDENTITY_BYTES: vector<u8> = vector[192, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
const G1_GENERATOR_BYTES: vector<u8> = vector[151, 241, 211, 167, 49, 151, 215, 148, 38, 149, 99, 140, 79, 169, 172, 15, 195, 104, 140, 79, 151, 116, 185, 5, 161, 78, 58, 63, 23, 27, 172, 88, 108, 85, 232, 63, 249, 122, 26, 239, 251, 58, 240, 10, 219, 34, 198, 187];
const G2_IDENTITY_BYTES: vector<u8> = vector[192, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
const G2_GENERATOR_BYTES: vector<u8> = vector[147, 224, 43, 96, 82, 113, 159, 96, 125, 172, 211, 160, 136, 39, 79, 101, 89, 107, 208, 208, 153, 32, 182, 26, 181, 218, 97, 187, 220, 127, 80, 73, 51, 76, 241, 18, 19, 148, 93, 87, 229, 172, 125, 5, 93, 4, 43, 126, 2, 74, 162, 178, 240, 143, 10, 145, 38, 8, 5, 39, 45, 197, 16, 81, 198, 228, 122, 212, 250, 64, 59, 2, 180, 81, 11, 100, 122, 227, 209, 119, 11, 172, 3, 38, 168, 5, 187, 239, 212, 128, 86, 200, 193, 33, 189, 184];
const GT_IDENTITY_BYTES: vector<u8> = vector[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
const GT_GENERATOR_BYTES: vector<u8> = vector[18, 80, 235, 216, 113, 252, 10, 146, 167, 178, 216, 49, 104, 208, 215, 39, 39, 45, 68, 27, 239, 161, 92, 80, 61, 216, 233, 12, 233, 141, 179, 231, 182, 209, 148, 246, 8, 57, 197, 8, 168, 67, 5, 170, 202, 23, 137, 182, 8, 154, 28, 91, 70, 229, 17, 11, 134, 117, 14, 198, 165, 50, 52, 136, 104, 168, 64, 69, 72, 60, 146, 183, 175, 90, 246, 137, 69, 46, 175, 171, 241, 168, 148, 62, 80, 67, 159, 29, 89, 136, 42, 152, 234, 160, 23, 15, 25, 242, 99, 55, 210, 5, 251, 70, 156, 214, 189, 21, 195, 213, 160, 77, 200, 135, 132, 251, 179, 208, 178, 219, 222, 165, 77, 67, 178, 183, 63, 44, 187, 18, 213, 131, 134, 168, 112, 62, 15, 148, 130, 38, 228, 126, 232, 157, 6, 251, 162, 62, 183, 197, 175, 13, 159, 128, 148, 12, 167, 113, 182, 255, 213, 133, 123, 170, 242, 34, 235, 149, 167, 210, 128, 157, 97, 191, 224, 46, 27, 253, 27, 104, 255, 2, 240, 184, 16, 42, 225, 194, 213, 213, 171, 26, 19, 104, 187, 68, 92, 124, 45, 32, 151, 3, 242, 57, 104, 156, 227, 76, 3, 120, 166, 142, 114, 166, 179, 178, 22, 218, 14, 34, 165, 3, 27, 84, 221, 255, 87, 48, 147, 150, 179, 140, 136, 28, 76, 132, 158, 194, 62, 135, 25, 53, 2, 184, 110, 219, 136, 87, 194, 115, 250, 7, 90, 80, 81, 41, 55, 224, 121, 78, 30, 101, 167, 97, 124, 144, 216, 189, 102, 6, 91, 31, 255, 229, 29, 122, 87, 153, 115, 177, 49, 80, 33, 236, 60, 25, 147, 79, 17, 184, 180, 36, 205, 72, 191, 56, 252, 239, 104, 8, 59, 11, 14, 197, 200, 26, 147, 179, 48, 238, 26, 103, 125, 13, 21, 255, 123, 152, 78, 137, 120, 239, 72, 136, 30, 50, 250, 201, 27, 147, 180, 115, 51, 226, 186, 87, 3, 53, 15, 85, 167, 174, 252, 211, 195, 27, 79, 203, 108, 229, 119, 28, 198, 160, 233, 120, 106, 181, 151, 51, 32, 200, 6, 173, 54, 8, 41, 16, 123, 168, 16, 197, 160, 159, 253, 217, 190, 34, 145, 160, 194, 90, 153, 162, 1, 178, 245, 34, 71, 61, 23, 19, 145, 18, 91, 168, 77, 196, 0, 124, 251, 242, 248, 218, 117, 47, 124, 116, 24, 82, 3, 252, 202, 88, 154, 199, 25, 195, 77, 255, 187, 170, 216, 67, 29, 173, 28, 31, 181, 151, 170, 165, 1, 129, 7, 21, 79, 37, 167, 100, 189, 60, 121, 147, 122, 69, 184, 69, 70, 218, 99, 75, 143, 107, 225, 74, 128, 97, 229, 92, 206, 186, 71, 139, 35, 247, 218, 202, 163, 92, 140, 167, 139, 234, 233, 98, 64, 69, 180, 182, 4, 197, 129, 35, 77, 8, 106, 153, 2, 36, 155, 100, 114, 143, 253, 33, 161, 137, 232, 121, 53, 169, 84, 5, 28, 124, 219, 167, 179, 135, 38, 41, 164, 250, 252, 5, 6, 98, 69, 203, 145, 8, 240, 36, 45, 15, 227, 239, 15, 65, 229, 134, 99, 191, 8, 207, 6, 134, 114, 203, 208, 26, 126, 199, 59, 172, 164, 215, 44, 169, 53, 68, 222, 255, 104, 107, 253, 109, 245, 67, 212, 142, 170, 36, 175, 228, 126, 30, 253, 228, 73, 56, 59, 103, 102, 49];
const SCALAR_TYPE: u8 = 0;
const G1_TYPE: u8 = 1;
const G2_TYPE: u8 = 2;
const GT_TYPE: u8 = 3;
const UNCOMPRESSED_G1_TYPE: u8 = 4;
Function bls12381_min_sig_verify
@param signature: A 48-bytes signature that is a point on the G1 subgroup. @param public_key: A 96-bytes public key that is a point on the G2 subgroup. @param msg: The message that we test the signature against.
If the signature is a valid signature of the message and public key according to BLS_SIG_BLS12381G1_XMD:SHA-256_SSWU_RO_NUL_, return true. Otherwise, return false.
public fun bls12381_min_sig_verify(signature: &vector<u8>, public_key: &vector<u8>, msg: &vector<u8>): bool
Implementation
Function bls12381_min_pk_verify
@param signature: A 96-bytes signature that is a point on the G2 subgroup. @param public_key: A 48-bytes public key that is a point on the G1 subgroup. @param msg: The message that we test the signature against.
If the signature is a valid signature of the message and public key according to BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_NUL_, return true. Otherwise, return false.
public fun bls12381_min_pk_verify(signature: &vector<u8>, public_key: &vector<u8>, msg: &vector<u8>): bool
Implementation
Function scalar_from_bytes
public fun scalar_from_bytes(bytes: &vector<u8>): sui::group_ops::Element<sui::bls12381::Scalar>
Implementation
Function scalar_from_u64
public fun scalar_from_u64(x: u64): sui::group_ops::Element<sui::bls12381::Scalar>
Implementation
Function scalar_zero
public fun scalar_zero(): sui::group_ops::Element<sui::bls12381::Scalar>
Implementation
Function scalar_one
public fun scalar_one(): sui::group_ops::Element<sui::bls12381::Scalar>
Implementation
Function scalar_add
public fun scalar_add(e1: &sui::group_ops::Element<sui::bls12381::Scalar>, e2: &sui::group_ops::Element<sui::bls12381::Scalar>): sui::group_ops::Element<sui::bls12381::Scalar>
Implementation
Function scalar_sub
public fun scalar_sub(e1: &sui::group_ops::Element<sui::bls12381::Scalar>, e2: &sui::group_ops::Element<sui::bls12381::Scalar>): sui::group_ops::Element<sui::bls12381::Scalar>
Implementation
Function scalar_mul
public fun scalar_mul(e1: &sui::group_ops::Element<sui::bls12381::Scalar>, e2: &sui::group_ops::Element<sui::bls12381::Scalar>): sui::group_ops::Element<sui::bls12381::Scalar>
Implementation
Function scalar_div
Returns e2/e1, fails if a is zero.
public fun scalar_div(e1: &sui::group_ops::Element<sui::bls12381::Scalar>, e2: &sui::group_ops::Element<sui::bls12381::Scalar>): sui::group_ops::Element<sui::bls12381::Scalar>
Implementation
Function scalar_neg
public fun scalar_neg(e: &sui::group_ops::Element<sui::bls12381::Scalar>): sui::group_ops::Element<sui::bls12381::Scalar>
Implementation
Function scalar_inv
public fun scalar_inv(e: &sui::group_ops::Element<sui::bls12381::Scalar>): sui::group_ops::Element<sui::bls12381::Scalar>
Implementation
Function g1_from_bytes
public fun g1_from_bytes(bytes: &vector<u8>): sui::group_ops::Element<sui::bls12381::G1>
Implementation
Function g1_identity
public fun g1_identity(): sui::group_ops::Element<sui::bls12381::G1>
Implementation
Function g1_generator
public fun g1_generator(): sui::group_ops::Element<sui::bls12381::G1>
Implementation
Function g1_add
public fun g1_add(e1: &sui::group_ops::Element<sui::bls12381::G1>, e2: &sui::group_ops::Element<sui::bls12381::G1>): sui::group_ops::Element<sui::bls12381::G1>
Implementation
Function g1_sub
public fun g1_sub(e1: &sui::group_ops::Element<sui::bls12381::G1>, e2: &sui::group_ops::Element<sui::bls12381::G1>): sui::group_ops::Element<sui::bls12381::G1>
Implementation
Function g1_mul
public fun g1_mul(e1: &sui::group_ops::Element<sui::bls12381::Scalar>, e2: &sui::group_ops::Element<sui::bls12381::G1>): sui::group_ops::Element<sui::bls12381::G1>
Implementation
Function g1_div
Returns e2 / e1, fails if scalar is zero.
public fun g1_div(e1: &sui::group_ops::Element<sui::bls12381::Scalar>, e2: &sui::group_ops::Element<sui::bls12381::G1>): sui::group_ops::Element<sui::bls12381::G1>
Implementation
Function g1_neg
public fun g1_neg(e: &sui::group_ops::Element<sui::bls12381::G1>): sui::group_ops::Element<sui::bls12381::G1>
Implementation
Function hash_to_g1
Hash using DST = BLS_SIG_BLS12381G1_XMD:SHA-256_SSWU_RO_NUL_
public fun hash_to_g1(m: &vector<u8>): sui::group_ops::Element<sui::bls12381::G1>
Implementation
Function g1_multi_scalar_multiplication
Let 'scalars' be the vector [s1, s2, ..., sn] and 'elements' be the vector [e1, e2, ..., en]. Returns s1e1 + s2e2 + ... + sn*en. Aborts with EInputTooLong if the vectors are larger than 32 (may increase in the future).
public fun g1_multi_scalar_multiplication(scalars: &vector<sui::group_ops::Element<sui::bls12381::Scalar>>, elements: &vector<sui::group_ops::Element<sui::bls12381::G1>>): sui::group_ops::Element<sui::bls12381::G1>
Implementation
Function g1_to_uncompressed_g1
Convert an Element<G1> to uncompressed form.
public fun g1_to_uncompressed_g1(e: &sui::group_ops::Element<sui::bls12381::G1>): sui::group_ops::Element<sui::bls12381::UncompressedG1>
Implementation
Function g2_from_bytes
public fun g2_from_bytes(bytes: &vector<u8>): sui::group_ops::Element<sui::bls12381::G2>
Implementation
Function g2_identity
public fun g2_identity(): sui::group_ops::Element<sui::bls12381::G2>
Implementation
Function g2_generator
public fun g2_generator(): sui::group_ops::Element<sui::bls12381::G2>
Implementation
Function g2_add
public fun g2_add(e1: &sui::group_ops::Element<sui::bls12381::G2>, e2: &sui::group_ops::Element<sui::bls12381::G2>): sui::group_ops::Element<sui::bls12381::G2>
Implementation
Function g2_sub
public fun g2_sub(e1: &sui::group_ops::Element<sui::bls12381::G2>, e2: &sui::group_ops::Element<sui::bls12381::G2>): sui::group_ops::Element<sui::bls12381::G2>
Implementation
Function g2_mul
public fun g2_mul(e1: &sui::group_ops::Element<sui::bls12381::Scalar>, e2: &sui::group_ops::Element<sui::bls12381::G2>): sui::group_ops::Element<sui::bls12381::G2>
Implementation
Function g2_div
Returns e2 / e1, fails if scalar is zero.
public fun g2_div(e1: &sui::group_ops::Element<sui::bls12381::Scalar>, e2: &sui::group_ops::Element<sui::bls12381::G2>): sui::group_ops::Element<sui::bls12381::G2>
Implementation
Function g2_neg
public fun g2_neg(e: &sui::group_ops::Element<sui::bls12381::G2>): sui::group_ops::Element<sui::bls12381::G2>
Implementation
Function hash_to_g2
Hash using DST = BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_NUL_
public fun hash_to_g2(m: &vector<u8>): sui::group_ops::Element<sui::bls12381::G2>
Implementation
Function g2_multi_scalar_multiplication
Let 'scalars' be the vector [s1, s2, ..., sn] and 'elements' be the vector [e1, e2, ..., en]. Returns s1e1 + s2e2 + ... + sn*en. Aborts with EInputTooLong if the vectors are larger than 32 (may increase in the future).
public fun g2_multi_scalar_multiplication(scalars: &vector<sui::group_ops::Element<sui::bls12381::Scalar>>, elements: &vector<sui::group_ops::Element<sui::bls12381::G2>>): sui::group_ops::Element<sui::bls12381::G2>
Implementation
Function gt_identity
public fun gt_identity(): sui::group_ops::Element<sui::bls12381::GT>
Implementation
Function gt_generator
public fun gt_generator(): sui::group_ops::Element<sui::bls12381::GT>
Implementation
Function gt_add
public fun gt_add(e1: &sui::group_ops::Element<sui::bls12381::GT>, e2: &sui::group_ops::Element<sui::bls12381::GT>): sui::group_ops::Element<sui::bls12381::GT>
Implementation
Function gt_sub
public fun gt_sub(e1: &sui::group_ops::Element<sui::bls12381::GT>, e2: &sui::group_ops::Element<sui::bls12381::GT>): sui::group_ops::Element<sui::bls12381::GT>
Implementation
Function gt_mul
public fun gt_mul(e1: &sui::group_ops::Element<sui::bls12381::Scalar>, e2: &sui::group_ops::Element<sui::bls12381::GT>): sui::group_ops::Element<sui::bls12381::GT>
Implementation
Function gt_div
Returns e2 / e1, fails if scalar is zero.
public fun gt_div(e1: &sui::group_ops::Element<sui::bls12381::Scalar>, e2: &sui::group_ops::Element<sui::bls12381::GT>): sui::group_ops::Element<sui::bls12381::GT>
Implementation
Function gt_neg
public fun gt_neg(e: &sui::group_ops::Element<sui::bls12381::GT>): sui::group_ops::Element<sui::bls12381::GT>
Implementation
Function pairing
public fun pairing(e1: &sui::group_ops::Element<sui::bls12381::G1>, e2: &sui::group_ops::Element<sui::bls12381::G2>): sui::group_ops::Element<sui::bls12381::GT>
Implementation
Function uncompressed_g1_to_g1
UncompressedG1 group operations /// Create a Element<G1> from its uncompressed form.
public fun uncompressed_g1_to_g1(e: &sui::group_ops::Element<sui::bls12381::UncompressedG1>): sui::group_ops::Element<sui::bls12381::G1>
Implementation
Function uncompressed_g1_sum
Compute the sum of a list of uncompressed elements. This is significantly faster and cheaper than summing the elements.
public fun uncompressed_g1_sum(terms: &vector<sui::group_ops::Element<sui::bls12381::UncompressedG1>>): sui::group_ops::Element<sui::bls12381::UncompressedG1>