Skip to content

Commit 6514b1f

Browse files
authored
refactor: eliminate byte round-trip in NonZeroScalar to ScalarValue conversion (#2296)
The `From<&NonZeroScalar<C>>` for `ScalarValue<C>` implementation was converting through a byte representation: `to_repr` -> `from_bytes`, which performs unnecessary encode-decode-validate steps. Since `CurveArithmetic::Scalar` already has `Into<ScalarValue<Self>>` bound, use it directly instead: `scalar.scalar.into()`. This removes the intermediate `FieldBytes` round-trip and redundant range check. before: <img width="958" height="607" alt="image" src="https://github.com/user-attachments/assets/96d1a926-583d-4c33-af32-2abf393f9170" /> after: <img width="969" height="592" alt="image" src="https://github.com/user-attachments/assets/9254c2b3-27db-4994-89cc-f99339d86033" />
1 parent 4e6cca0 commit 6514b1f

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

elliptic-curve/src/scalar/nonzero.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ where
212212
C: CurveArithmetic,
213213
{
214214
fn from(scalar: &NonZeroScalar<C>) -> ScalarValue<C> {
215-
ScalarValue::from_bytes(&scalar.to_repr()).unwrap()
215+
scalar.scalar.into()
216216
}
217217
}
218218

0 commit comments

Comments
 (0)