P1, P2 definition
This commit is contained in:
parent
d146ae7275
commit
3d2e9efb1e
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -180,7 +180,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "bn"
|
name = "bn"
|
||||||
version = "0.4.3"
|
version = "0.4.3"
|
||||||
source = "git+https://github.com/paritytech/bn#59d848e642ad1ff0d60e39348576a6f11ee123b8"
|
source = "git+https://github.com/paritytech/bn#5df8d83c19f3fb97ae3fdefa5bad5279babe795e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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)",
|
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -191,6 +191,9 @@ struct Bn128AddImpl;
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct Bn128MulImpl;
|
struct Bn128MulImpl;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct Bn128ParingImpl;
|
||||||
|
|
||||||
impl Impl for Identity {
|
impl Impl for Identity {
|
||||||
fn execute(&self, input: &[u8], output: &mut BytesRef) -> Result<(), Error> {
|
fn execute(&self, input: &[u8], output: &mut BytesRef) -> Result<(), Error> {
|
||||||
output.write(0, input);
|
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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::{Builtin, Linear, ethereum_builtin, Pricer, Modexp};
|
use super::{Builtin, Linear, ethereum_builtin, Pricer, Modexp};
|
||||||
|
Loading…
Reference in New Issue
Block a user