Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
P1, P2 definition
Browse files Browse the repository at this point in the history
  • Loading branch information
NikVolf committed Mar 31, 2017
1 parent d146ae7 commit 3d2e9ef
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions ethcore/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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};
Expand Down

0 comments on commit 3d2e9ef

Please sign in to comment.