Skip to content

Commit 5f8281f

Browse files
committed
change pairing return type to bool
1 parent b6b9ea6 commit 5f8281f

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

sdk/pinocchio/src/curves/bn254/pairing.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,26 @@ pub const ALT_BN128_PAIRING_ELEMENT_SIZE: usize = ALT_BN128_G1_POINT_SIZE + ALT_
88

99
const ALT_BN128_PAIRING_BE: u64 = 3;
1010

11-
/// Perform a pairing operation on the BN254 curve in big-endian (EIP-197) encoding.
11+
/// Checks whether the product of pairings of a sequence of G1 and G2 points (in big-endian EIP-197 encoding)
12+
/// on the BN254 curve evaluates to the identity element (1).
1213
///
1314
/// # Arguments
1415
///
1516
/// * `input` - A sequence of pairs of G1 and G2 points in big-endian (EIP-197) encoding.
1617
///
1718
/// # Returns
1819
///
19-
/// A `Result` containing the result of the pairing operation, or an error if the input is invalid.
20+
/// A `Result` containing:
21+
/// - `Ok(true)` if the pairing product equals 1,
22+
/// - `Ok(false)` otherwise,
23+
/// - `Err(ProgramError)` if the input is invalid.
2024
///
2125
/// Note: This function does **not** check if the input has the correct length.
2226
/// Currently, if the length is invalid, it will not return an error; instead it will use only
2327
/// multiples of [`ALT_BN128_PAIRING_ELEMENT_SIZE`] bytes and discard the rest.
2428
/// After SIMD-0334 is implemented, it will return an error if the length is invalid,
2529
/// incurring the cost of the syscall.
2630
#[inline(always)]
27-
pub fn alt_bn128_pairing_be(input: &[u8]) -> Result<u8, ProgramError> {
28-
alt_bn128_group_op::<32>(input, ALT_BN128_PAIRING_BE).map(|data| data[31])
31+
pub fn alt_bn128_is_pairing_valid_be(input: &[u8]) -> Result<bool, ProgramError> {
32+
alt_bn128_group_op::<32>(input, ALT_BN128_PAIRING_BE).map(|data| data[31] == 1)
2933
}

0 commit comments

Comments
 (0)