From 213e007a4b6f181921da4a6bb8757c5b05ab4147 Mon Sep 17 00:00:00 2001 From: Seun LanLege Date: Thu, 20 Jun 2019 22:16:11 +0100 Subject: [PATCH] Updated Bn128PairingImpl to use optimized batch pairing (#10765) * Bn128PairingImpl uses pairing_batch method in bn * updated Cargo.lock --- Cargo.lock | 4 +++- ethcore/src/builtin.rs | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0fd6289f6..f5fc14cad 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -264,11 +264,13 @@ dependencies = [ [[package]] name = "bn" version = "0.4.4" -source = "git+https://github.com/paritytech/bn#2a71dbde5ca93451c8da2135767896a64483759e" +source = "git+https://github.com/paritytech/bn#6beba2ed6c9351622f9e948ccee4063846b2b39a" dependencies = [ "byteorder 1.2.6 (registry+https://github.com/rust-lang/crates.io-index)", "crunchy 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] diff --git a/ethcore/src/builtin.rs b/ethcore/src/builtin.rs index 76d00ba52..bae1c75da 100644 --- a/ethcore/src/builtin.rs +++ b/ethcore/src/builtin.rs @@ -498,7 +498,7 @@ impl Impl for Bn128PairingImpl { impl Bn128PairingImpl { fn execute_with_error(&self, input: &[u8], output: &mut BytesRef) -> Result<(), Error> { - use bn::{AffineG1, AffineG2, Fq, Fq2, pairing, G1, G2, Gt, Group}; + use bn::{AffineG1, AffineG2, Fq, Fq2, pairing_batch, G1, G2, Gt, Group}; let elements = input.len() / 192; // (a, b_a, b_b - each 64-byte affine coordinates) let ret_val = if input.len() == 0 { @@ -539,7 +539,7 @@ impl Bn128PairingImpl { vals.push((a, b)); }; - let mul = vals.into_iter().fold(Gt::one(), |s, (a, b)| s * pairing(a, b)); + let mul = pairing_batch(&vals); if mul == Gt::one() { U256::one()