Skip to content

Commit 9a69407

Browse files
Add a bunch of #[inline(always)] for te curves
1 parent 02d07b6 commit 9a69407

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

extensions/ecc/guest/src/edwards.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub trait TwistedEdwardsPoint: Sized {
3131

3232
fn add_impl(&self, p2: &Self) -> Self;
3333

34+
#[inline(always)]
3435
fn from_xy(x: Self::Coordinate, y: Self::Coordinate) -> Option<Self>
3536
where
3637
for<'a> &'a Self::Coordinate: Mul<&'a Self::Coordinate, Output = Self::Coordinate>,
@@ -45,15 +46,15 @@ pub trait TwistedEdwardsPoint: Sized {
4546
}
4647

4748
/// Macro to generate a newtype wrapper for [AffinePoint](crate::AffinePoint)
48-
/// that implements elliptic curve operations by using the underlying field operations according to the
49-
/// [formulas](https://en.wikipedia.org/wiki/Twisted_Edwards_curve) for twisted Edwards curves.
49+
/// that implements elliptic curve operations by using the underlying field operations according to
50+
/// the [formulas](https://en.wikipedia.org/wiki/Twisted_Edwards_curve) for twisted Edwards curves.
5051
///
5152
/// The following imports are required:
5253
/// ```rust
5354
/// use core::ops::AddAssign;
5455
///
5556
/// use openvm_algebra_guest::{DivUnsafe, Field};
56-
/// use openvm_ecc_guest::{AffinePoint, Group, edwards::TwistedEdwardsPoint};
57+
/// use openvm_ecc_guest::{edwards::TwistedEdwardsPoint, AffinePoint, Group};
5758
/// ```
5859
#[macro_export]
5960
macro_rules! impl_te_affine {
@@ -148,8 +149,8 @@ macro_rules! impl_te_affine {
148149
}
149150
}
150151

151-
/// Implements `Group` on `$struct_name` assuming that `$struct_name` implements `TwistedEdwardsPoint`.
152-
/// Assumes that `Neg` is implemented for `&$struct_name`.
152+
/// Implements `Group` on `$struct_name` assuming that `$struct_name` implements
153+
/// `TwistedEdwardsPoint`. Assumes that `Neg` is implemented for `&$struct_name`.
153154
#[macro_export]
154155
macro_rules! impl_te_group_ops {
155156
($struct_name:ident, $field:ty) => {
@@ -273,8 +274,8 @@ macro_rules! impl_te_group_ops {
273274

274275
// This is the same as the Weierstrass version, but for Edwards curves we use
275276
// TwistedEdwardsPoint::add_impl instead of WeierstrassPoint::add_ne_nonidentity, etc.
276-
// Unlike the Weierstrass version, we do not require the bases to have prime order, since our addition
277-
// formulas are complete.
277+
// Unlike the Weierstrass version, we do not require the bases to have prime order, since our
278+
// addition formulas are complete.
278279

279280
// MSM using preprocessed table (windowed method)
280281
// Reference: modified from https://github.com/arkworks-rs/algebra/blob/master/ec/src/scalar_mul/mod.rs

extensions/ecc/te-macros/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ pub fn te_declare(input: TokenStream) -> TokenStream {
139139

140140
// Helper function to call the setup instruction on first use
141141
#[cfg(target_os = "zkvm")]
142+
#[inline(always)]
142143
fn set_up_once() {
143144
static is_setup: ::openvm_ecc_guest::once_cell::race::OnceBool = ::openvm_ecc_guest::once_cell::race::OnceBool::new();
144145
is_setup.get_or_init(|| {
@@ -149,6 +150,7 @@ pub fn te_declare(input: TokenStream) -> TokenStream {
149150
}
150151

151152
#[cfg(not(target_os = "zkvm"))]
153+
#[inline(always)]
152154
fn set_up_once() {
153155
// No-op for non-ZKVM targets
154156
}
@@ -163,34 +165,42 @@ pub fn te_declare(input: TokenStream) -> TokenStream {
163165

164166
/// SAFETY: assumes that #intmod_type has a memory representation
165167
/// such that with repr(C), two coordinates are packed contiguously.
168+
#[inline(always)]
166169
fn as_le_bytes(&self) -> &[u8] {
167170
unsafe { &*core::ptr::slice_from_raw_parts(self as *const Self as *const u8, <#intmod_type as openvm_algebra_guest::IntMod>::NUM_LIMBS * 2) }
168171
}
169172

173+
#[inline(always)]
170174
fn from_xy_unchecked(x: Self::Coordinate, y: Self::Coordinate) -> Self {
171175
Self { x, y }
172176
}
173177

178+
#[inline(always)]
174179
fn x(&self) -> &Self::Coordinate {
175180
&self.x
176181
}
177182

183+
#[inline(always)]
178184
fn y(&self) -> &Self::Coordinate {
179185
&self.y
180186
}
181187

188+
#[inline(always)]
182189
fn x_mut(&mut self) -> &mut Self::Coordinate {
183190
&mut self.x
184191
}
185192

193+
#[inline(always)]
186194
fn y_mut(&mut self) -> &mut Self::Coordinate {
187195
&mut self.y
188196
}
189197

198+
#[inline(always)]
190199
fn into_coords(self) -> (Self::Coordinate, Self::Coordinate) {
191200
(self.x, self.y)
192201
}
193202

203+
#[inline(always)]
194204
fn add_impl(&self, p2: &Self) -> Self {
195205
Self::add_chip(self, p2)
196206
}

0 commit comments

Comments
 (0)