P1, P2 definition

This commit is contained in:
NikVolf 2017-03-27 18:39:21 +03:00
parent d146ae7275
commit 3d2e9efb1e
2 changed files with 29 additions and 1 deletions

2
Cargo.lock generated
View File

@ -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)",

View File

@ -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};