From 3d2e9efb1ed856f68a42662875e4e9df97908958 Mon Sep 17 00:00:00 2001 From: NikVolf Date: Mon, 27 Mar 2017 18:39:21 +0300 Subject: [PATCH] P1, P2 definition --- Cargo.lock | 2 +- ethcore/src/builtin.rs | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 1a25c8553..3b5eded0a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -180,7 +180,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "bn" version = "0.4.3" -source = "git+https://github.com/paritytech/bn#59d848e642ad1ff0d60e39348576a6f11ee123b8" +source = "git+https://github.com/paritytech/bn#5df8d83c19f3fb97ae3fdefa5bad5279babe795e" dependencies = [ "byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/ethcore/src/builtin.rs b/ethcore/src/builtin.rs index bdedd5739..c240250df 100644 --- a/ethcore/src/builtin.rs +++ b/ethcore/src/builtin.rs @@ -191,6 +191,9 @@ struct Bn128AddImpl; #[derive(Debug)] struct Bn128MulImpl; +#[derive(Debug)] +struct Bn128ParingImpl; + impl Impl for Identity { fn execute(&self, input: &[u8], output: &mut BytesRef) -> Result<(), Error> { output.write(0, input); @@ -393,6 +396,31 @@ impl Impl for Bn128MulImpl { } } +impl Impl for Bn128ParingImpl { + // Can fail if any of the 2 points does not belong the bn128 curve + fn execute(&self, input: &[u8], output: &mut BytesRef) -> Result<(), Error> { + use bn::{Fq, Fq2, AffineG1, AffineG2}; + + let p1 = AffineG1::new( + Fq::from_str("1").expect("1 is a valid field element"), + Fq::from_str("2").expect("2 is a valid field element"), + ).expect("Generator P1(1, 2) is a valid curve point"); + + let p2 = AffineG2::new( + Fq2::new( + Fq::from_str("1").expect("1 is a valid field element"), + Fq::from_str("2").expect("2 is a valid field element"), + ), + Fq2::new( + Fq::from_str("1").expect("1 is a valid field element"), + Fq::from_str("2").expect("2 is a valid field element"), + ), + ).expect("Generator P2(i+2b, i+2b) is a valid curve point"); + + Ok(()) + } +} + #[cfg(test)] mod tests { use super::{Builtin, Linear, ethereum_builtin, Pricer, Modexp};