Skip to content

Commit c679543

Browse files
committed
perf: switch SW_EC to projective coordinates - guest macros (INT-6135)
1 parent aa1d833 commit c679543

File tree

9 files changed

+399
-414
lines changed

9 files changed

+399
-414
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

extensions/ecc/circuit/src/weierstrass_chip/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ pub use double::*;
88
#[cfg(test)]
99
mod tests;
1010

11-
1211
use openvm_circuit::arch::{VmAirWrapper, VmChipWrapper};
1312
use openvm_mod_circuit_builder::{FieldExpressionCoreAir, FieldExpressionFiller};
1413
use openvm_rv32_adapters::{Rv32VecHeapAdapterAir, Rv32VecHeapAdapterFiller};

extensions/ecc/guest/src/ecdsa.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ where
9797
pub fn from_affine(point: AffinePoint<C>) -> Result<Self> {
9898
// Internally this calls `is_eq` on `x` and `y` coordinates, which will assert `x, y` are
9999
// reduced.
100-
if point.is_identity() {
100+
if Group::is_identity(&point) {
101101
Err(Error::new())
102102
} else {
103103
Ok(Self { point })
@@ -148,11 +148,11 @@ where
148148
}
149149

150150
pub fn to_sec1_bytes(&self, compress: bool) -> Vec<u8> {
151-
if self.point.is_identity() {
151+
if Group::is_identity(&self.point) {
152152
return vec![0x00];
153153
}
154154

155-
let (x, y) = self.point.clone().into_coords();
155+
let (x, y, _) = self.point.normalize().into_coords();
156156

157157
if compress {
158158
let mut bytes = Vec::<u8>::with_capacity(1 + Coordinate::<C>::NUM_LIMBS);
@@ -534,12 +534,12 @@ where
534534
// public key
535535
let Q = pubkey;
536536
let R = <C as IntrinsicCurve>::msm(&[u1, u2], &[G, Q]);
537-
// For Coordinate<C>: IntMod, the internal implementation of is_identity will assert x, y
538-
// coordinates of R are both reduced.
539-
if R.is_identity() {
537+
// For Coordinate<C>: IntMod, the internal implementation of is_identity will assert z
538+
// coordinate of R is reduced.
539+
if Group::is_identity(&R) {
540540
return Err(Error::new());
541541
}
542-
let (x_1, _) = R.into_coords();
542+
let (x_1, _, _) = R.normalize().into_coords();
543543
// Scalar and Coordinate may be different byte lengths, so we use an inefficient reduction
544544
let x_mod_n = Scalar::<C>::reduce_le_bytes(x_1.as_le_bytes());
545545
if x_mod_n == r {

extensions/ecc/guest/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ pub const SW_FUNCT3: u8 = 0b001;
2929
#[derive(Debug, Copy, Clone, PartialEq, Eq, FromRepr)]
3030
#[repr(u8)]
3131
pub enum SwBaseFunct7 {
32-
SwAddNe = 0,
33-
SwDouble,
32+
SwAddProj = 0,
33+
SwDoubleProj,
3434
SwSetup,
3535
}
3636

0 commit comments

Comments
 (0)