Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions crates/precompile/src/bn128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::{
};
use bn::{AffineG1, AffineG2, Fq, Fq2, Group, Gt, G1, G2};
use revm_primitives::PrecompileOutput;
use std::vec::Vec;

pub mod add {
use super::*;
Expand Down Expand Up @@ -179,7 +180,9 @@ pub fn run_pair(
} else {
let elements = input.len() / PAIR_ELEMENT_LEN;

let mut mul = Gt::one();
let mut points = Vec::with_capacity(elements);

// read points
for idx in 0..elements {
let read_fq_at = |n: usize| {
debug_assert!(n < PAIR_ELEMENT_LEN / 32);
Expand All @@ -200,16 +203,19 @@ pub fn run_pair(
let b = {
let ba = Fq2::new(bax, bay);
let bb = Fq2::new(bbx, bby);
// TODO: check whether or not we need these zero checks
if ba.is_zero() && bb.is_zero() {
G2::zero()
} else {
G2::from(AffineG2::new(ba, bb).map_err(|_| Error::Bn128AffineGFailedToCreate)?)
}
};

mul = mul * bn::pairing(a, b);
points.push((a, b));
}

let mul = bn::pairing_batch(&points);

mul == Gt::one()
};
Ok(PrecompileOutput::new(gas_used, bool_to_bytes32(success)))
Expand Down