From 2c2d36a6be23fed25af854259c78e2c1b11f039f Mon Sep 17 00:00:00 2001 From: Nicholas Ward Date: Wed, 10 Nov 2021 11:49:50 -0800 Subject: [PATCH] merge --- src/curve/mod.rs | 2 +- src/curve/secp256k1_curve.rs | 6 +++--- src/field/secp256k1_scalar.rs | 4 ++-- src/gadgets/mod.rs | 1 + src/gadgets/secp256k1.rs | 32 ++++++++++++++++++++++++++++++++ 5 files changed, 39 insertions(+), 6 deletions(-) create mode 100644 src/gadgets/secp256k1.rs diff --git a/src/curve/mod.rs b/src/curve/mod.rs index e1bcb291..c65f2acd 100644 --- a/src/curve/mod.rs +++ b/src/curve/mod.rs @@ -2,4 +2,4 @@ pub mod curve_adds; pub mod curve_multiplication; pub mod curve_summation; pub mod curve_types; -pub mod secp256k1_curve; \ No newline at end of file +pub mod secp256k1_curve; diff --git a/src/curve/secp256k1_curve.rs b/src/curve/secp256k1_curve.rs index 4e74a5f7..21340c64 100644 --- a/src/curve/secp256k1_curve.rs +++ b/src/curve/secp256k1_curve.rs @@ -22,7 +22,7 @@ impl Curve for Secp256K1 { }; } -const SECP256K1_GENERATOR_X: Secp256K1Base = Secp256K1Base([ +const SECP256K1_GENERATOR_X: Secp256K1Base = Secp256K1Base([ 0x59F2815B16F81798, 0x029BFCDB2DCE28D9, 0x55A06295CE870B07, @@ -39,10 +39,10 @@ const SECP256K1_GENERATOR_Y: Secp256K1Base = Secp256K1Base([ #[cfg(test)] mod tests { - use crate::field::field_types::Field; - use crate::field::secp256k1_scalar::Secp256K1Scalar; use crate::curve::curve_types::{Curve, ProjectivePoint}; use crate::curve::secp256k1_curve::Secp256K1; + use crate::field::field_types::Field; + use crate::field::secp256k1_scalar::Secp256K1Scalar; /*#[test] fn test_double_affine() { diff --git a/src/field/secp256k1_scalar.rs b/src/field/secp256k1_scalar.rs index 4423f726..0c406b86 100644 --- a/src/field/secp256k1_scalar.rs +++ b/src/field/secp256k1_scalar.rs @@ -81,7 +81,7 @@ impl Field for Secp256K1Scalar { 0xBFD25E8CD0364140, 0xBAAEDCE6AF48A03B, 0xFFFFFFFFFFFFFC2F, - 0xFFFFFFFFFFFFFFFF + 0xFFFFFFFFFFFFFFFF, ]); // TODO: fix @@ -106,7 +106,7 @@ impl Field for Secp256K1Scalar { fn order() -> BigUint { BigUint::from_slice(&[ 0xD0364141, 0xBFD25E8C, 0xAF48A03B, 0xBAAEDCE6, 0xFFFFFC2F, 0xFFFFFFFF, 0xFFFFFFFF, - 0xFFFFFFFF + 0xFFFFFFFF, ]) } diff --git a/src/gadgets/mod.rs b/src/gadgets/mod.rs index 8b6e60f6..42b3044c 100644 --- a/src/gadgets/mod.rs +++ b/src/gadgets/mod.rs @@ -11,6 +11,7 @@ pub mod permutation; pub mod polynomial; pub mod random_access; pub mod range_check; +pub mod secp256k1; pub mod select; pub mod sorting; pub mod split_base; diff --git a/src/gadgets/secp256k1.rs b/src/gadgets/secp256k1.rs new file mode 100644 index 00000000..36d8d145 --- /dev/null +++ b/src/gadgets/secp256k1.rs @@ -0,0 +1,32 @@ +use crate::curve::curve_types::{AffinePoint, Curve}; +use crate::field::extension_field::Extendable; +use crate::field::field_types::RichField; +use crate::gadgets::nonnative::ForeignFieldTarget; +use crate::plonk::circuit_builder::CircuitBuilder; + +#[derive(Clone, Debug)] +pub struct AffinePointTarget { + pub x: ForeignFieldTarget, + pub y: ForeignFieldTarget, +} + +impl AffinePointTarget { + pub fn to_vec(&self) -> Vec> { + vec![self.x.clone(), self.y.clone()] + } +} + +impl, const D: usize> CircuitBuilder { + pub fn constant_affine_point>( + &mut self, + point: AffinePoint, + ) -> AffinePointTarget { + debug_assert!(!point.zero); + AffinePointTarget { + x: self.constant_ff(point.x), + y: self.constant_ff(point.y), + } + } +} + +mod tests {}