Skip to content

Commit 08b70b5

Browse files
Move IntrinsicCurve trait definition to lib.rs (since it's common to weierstrass and edwards curves)
1 parent 7bf1f13 commit 08b70b5

File tree

7 files changed

+19
-19
lines changed

7 files changed

+19
-19
lines changed

extensions/ecc/guest/src/ecdsa.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use elliptic_curve::PrimeCurve;
55
use openvm_algebra_guest::{DivUnsafe, IntMod, Reduce};
66

77
use crate::{
8-
weierstrass::{FromCompressed, IntrinsicCurve, WeierstrassPoint},
9-
CyclicGroup, Group,
8+
weierstrass::{FromCompressed, WeierstrassPoint},
9+
CyclicGroup, Group, IntrinsicCurve,
1010
};
1111

1212
pub type Coordinate<C> = <<C as IntrinsicCurve>::Point as WeierstrassPoint>::Coordinate;

extensions/ecc/guest/src/ed25519.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use num_bigint::BigUint;
66
use openvm_algebra_guest::{Field, IntMod};
77

88
use super::group::{CyclicGroup, Group};
9+
use crate::IntrinsicCurve;
910

1011
#[cfg(not(target_os = "zkvm"))]
1112
lazy_static! {

extensions/ecc/guest/src/k256.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use openvm_algebra_moduli_setup::moduli_declare;
1010
use openvm_ecc_sw_setup::sw_declare;
1111

1212
use super::group::{CyclicGroup, Group};
13-
use crate::weierstrass::{CachedMulTable, IntrinsicCurve};
13+
use crate::{weierstrass::CachedMulTable, IntrinsicCurve};
1414

1515
#[cfg(not(target_os = "zkvm"))]
1616
lazy_static! {

extensions/ecc/guest/src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,15 @@ pub enum TeBaseFunct7 {
6868
impl TeBaseFunct7 {
6969
pub const TWISTED_EDWARDS_MAX_KINDS: u8 = 8;
7070
}
71+
72+
/// A trait for elliptic curves that bridges the openvm types and external types with CurveArithmetic etc.
73+
/// Implement this for external curves with corresponding openvm point and scalar types.
74+
pub trait IntrinsicCurve {
75+
type Scalar: Clone;
76+
type Point: Clone;
77+
78+
/// Multi-scalar multiplication.
79+
/// The implementation may be specialized to use properties of the curve
80+
/// (e.g., if the curve order is prime).
81+
fn msm(coeffs: &[Self::Scalar], bases: &[Self::Point]) -> Self::Point;
82+
}

extensions/ecc/guest/src/p256.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use num_bigint::BigUint;
88
use openvm_algebra_guest::{Field, IntMod};
99

1010
use super::group::{CyclicGroup, Group};
11-
use crate::weierstrass::{CachedMulTable, IntrinsicCurve};
11+
use crate::{weierstrass::CachedMulTable, IntrinsicCurve};
1212

1313
#[cfg(not(target_os = "zkvm"))]
1414
lazy_static! {

extensions/ecc/guest/src/weierstrass.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use core::ops::{AddAssign, Mul};
44
use openvm_algebra_guest::{Field, IntMod};
55

66
use super::group::Group;
7+
use crate::IntrinsicCurve;
78

89
/// Short Weierstrass curve affine point.
910
pub trait WeierstrassPoint: Sized {
@@ -91,18 +92,6 @@ pub trait FromCompressed<Coordinate> {
9192
fn hint_decompress(x: &Coordinate, rec_id: &u8) -> Coordinate;
9293
}
9394

94-
/// A trait for elliptic curves that bridges the openvm types and external types with CurveArithmetic etc.
95-
/// Implement this for external curves with corresponding openvm point and scalar types.
96-
pub trait IntrinsicCurve {
97-
type Scalar: Clone;
98-
type Point: Clone;
99-
100-
/// Multi-scalar multiplication.
101-
/// The implementation may be specialized to use properties of the curve
102-
/// (e.g., if the curve order is prime).
103-
fn msm(coeffs: &[Self::Scalar], bases: &[Self::Point]) -> Self::Point;
104-
}
105-
10695
// MSM using preprocessed table (windowed method)
10796
// Reference: modified from https://github.com/arkworks-rs/algebra/blob/master/ec/src/scalar_mul/mod.rs
10897
//

extensions/pairing/guest/src/bls12_381/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
use core::ops::Neg;
2-
31
use openvm_algebra_guest::{Field, IntMod};
42
use openvm_algebra_moduli_setup::moduli_declare;
5-
use openvm_ecc_guest::{weierstrass::IntrinsicCurve, CyclicGroup, Group};
3+
use openvm_ecc_guest::{CyclicGroup, Group, IntrinsicCurve};
64

75
mod fp12;
86
mod fp2;

0 commit comments

Comments
 (0)