Skip to content

Commit ee6e92b

Browse files
build: bump Lambdaworks to 0.12.0 (#151)
1 parent 6371943 commit ee6e92b

File tree

4 files changed

+43
-28
lines changed

4 files changed

+43
-28
lines changed

crates/starknet-types-core/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ description = "Core types representation for Starknet"
1111
readme = "README.md"
1212

1313
[dependencies]
14-
lambdaworks-math = { version = "0.10.0", default-features = false }
14+
lambdaworks-math = { version = "0.12.0", default-features = false }
1515
num-traits = { version = "0.2", default-features = false }
1616
num-bigint = { version = "0.4", default-features = false }
1717
num-integer = { version = "0.1", default-features = false }
@@ -23,7 +23,7 @@ digest = { version = "0.10.7", optional = true }
2323
serde = { version = "1", optional = true, default-features = false, features = [
2424
"alloc", "derive"
2525
] }
26-
lambdaworks-crypto = { version = "0.10.0", default-features = false, optional = true }
26+
lambdaworks-crypto = { version = "0.12.0", default-features = false, optional = true }
2727
parity-scale-codec = { version = "3.6", default-features = false, optional = true }
2828
lazy_static = { version = "1.5", default-features = false, optional = true }
2929
zeroize = { version = "1.8.1", default-features = false, optional = true }

crates/starknet-types-core/src/curve/affine_point.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::{curve::curve_errors::CurveError, felt::Felt};
22
use lambdaworks_math::{
33
cyclic_group::IsGroup,
44
elliptic_curve::{
5+
point::ProjectivePoint,
56
short_weierstrass::{
67
curves::stark_curve::StarkCurve, point::ShortWeierstrassProjectivePoint,
78
traits::IsShortWeierstrass,
@@ -27,11 +28,11 @@ impl AffinePoint {
2728
/// This method should be used with caution, as it does not validate whether the provided coordinates
2829
/// correspond to a valid point on the curve.
2930
pub const fn new_unchecked(x: Felt, y: Felt) -> AffinePoint {
30-
Self(ShortWeierstrassProjectivePoint::new([
31+
Self(ShortWeierstrassProjectivePoint(ProjectivePoint::new([
3132
x.0,
3233
y.0,
3334
Felt::ONE.0,
34-
]))
35+
])))
3536
}
3637

3738
/// Construct new affine point from the `x` coordinate and the parity bit `y_parity`.

crates/starknet-types-core/src/curve/projective_point.rs

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::curve::curve_errors::CurveError;
33
use crate::felt::Felt;
44
use core::ops;
55
use lambdaworks_math::cyclic_group::IsGroup;
6+
use lambdaworks_math::elliptic_curve::point::ProjectivePoint as LambdaworksProjectivePoint;
67
use lambdaworks_math::elliptic_curve::short_weierstrass::curves::stark_curve::StarkCurve;
78
use lambdaworks_math::elliptic_curve::short_weierstrass::point::ShortWeierstrassProjectivePoint;
89
use lambdaworks_math::elliptic_curve::traits::EllipticCurveError::InvalidPoint;
@@ -15,8 +16,23 @@ use lambdaworks_math::unsigned_integer::traits::IsUnsignedInteger;
1516
pub struct ProjectivePoint(pub(crate) ShortWeierstrassProjectivePoint<StarkCurve>);
1617

1718
impl ProjectivePoint {
18-
pub fn new(x: Felt, y: Felt, z: Felt) -> ProjectivePoint {
19-
Self(ShortWeierstrassProjectivePoint::new([x.0, y.0, z.0]))
19+
pub fn new(x: Felt, y: Felt, z: Felt) -> Result<ProjectivePoint, CurveError> {
20+
Ok(Self(ShortWeierstrassProjectivePoint::new([x.0, y.0, z.0])?))
21+
}
22+
23+
/// Creates a new short Weierstrass projective point, assuming the coordinates are valid.
24+
///
25+
/// The coordinates are valid if the equation `y^2 * z = x^3 + a * x * z^2 + b * z^3`
26+
/// holds, Where `a` and `b` are the short Weierstrass coefficients of the Stark
27+
/// curve. Furthermore, the coordinates in the form `[0, _, 0]` all satisfy the
28+
/// equation, and should be always transformed to the infinity value `[0, 1, 0]`.
29+
///
30+
/// SAFETY: Failing to guarantee this assumptions could lead to a runtime panic
31+
/// while operating with the value.
32+
pub const fn new_unchecked(x: Felt, y: Felt, z: Felt) -> ProjectivePoint {
33+
Self(ShortWeierstrassProjectivePoint(
34+
LambdaworksProjectivePoint::new([x.0, y.0, z.0]),
35+
))
2036
}
2137

2238
/// The point at infinity.
@@ -49,11 +65,9 @@ impl ProjectivePoint {
4965
/// This method should be used with caution, as it does not validate whether the provided coordinates
5066
/// correspond to a valid point on the curve.
5167
pub fn from_affine_unchecked(x: Felt, y: Felt) -> Self {
52-
Self(ShortWeierstrassProjectivePoint::new([
53-
x.0,
54-
y.0,
55-
Felt::ONE.0,
56-
]))
68+
Self(ShortWeierstrassProjectivePoint(
69+
LambdaworksProjectivePoint::new([x.0, y.0, Felt::ONE.0]),
70+
))
5771
}
5872

5973
/// Returns the `x` coordinate of the point.
@@ -201,7 +215,7 @@ mod test {
201215

202216
#[test]
203217
fn try_from_affine() {
204-
let projective_point = ProjectivePoint::new(
218+
let projective_point = ProjectivePoint::new_unchecked(
205219
Felt::from_dec_str(
206220
"874739451078007766457464989774322083649278607533249481151382481072868806602",
207221
)
@@ -265,15 +279,15 @@ mod test {
265279
assert!(identity.is_identity());
266280
assert_eq!(
267281
identity,
268-
ProjectivePoint::new(Felt::from(0), Felt::from(1), Felt::from(0))
282+
ProjectivePoint::new_unchecked(Felt::from(0), Felt::from(1), Felt::from(0))
269283
);
270284

271285
assert_eq!(
272286
identity.to_affine(),
273287
Err(CurveError::EllipticCurveError(InvalidPoint))
274288
);
275289

276-
let a = ProjectivePoint::new(
290+
let a = ProjectivePoint::new_unchecked(
277291
Felt::from_dec_str(
278292
"874739451078007766457464989774322083649278607533249481151382481072868806602",
279293
)
@@ -290,7 +304,7 @@ mod test {
290304
#[test]
291305
// Results checked against starknet-rs https://github.com/xJonathanLEI/starknet-rs/
292306
fn add_operations() {
293-
let projective_point_1 = ProjectivePoint::new(
307+
let projective_point_1 = ProjectivePoint::new_unchecked(
294308
Felt::from_dec_str(
295309
"874739451078007766457464989774322083649278607533249481151382481072868806602",
296310
)
@@ -325,7 +339,7 @@ mod test {
325339
#[test]
326340
// Results checked against starknet-rs https://github.com/xJonathanLEI/starknet-rs/
327341
fn add_operations_with_affine() {
328-
let projective_point = ProjectivePoint::new(
342+
let projective_point = ProjectivePoint::new_unchecked(
329343
Felt::from_dec_str(
330344
"874739451078007766457464989774322083649278607533249481151382481072868806602",
331345
)
@@ -358,7 +372,7 @@ mod test {
358372
#[test]
359373
// Results checked against starknet-rs https://github.com/xJonathanLEI/starknet-rs/
360374
fn add_operations_with_affine_no_pointer() {
361-
let projective_point = ProjectivePoint::new(
375+
let projective_point = ProjectivePoint::new_unchecked(
362376
Felt::from_dec_str(
363377
"874739451078007766457464989774322083649278607533249481151382481072868806602",
364378
)
@@ -391,7 +405,7 @@ mod test {
391405
#[test]
392406
// Results checked against starknet-rs https://github.com/xJonathanLEI/starknet-rs/
393407
fn add_assign_operations() {
394-
let mut projective_point_1 = ProjectivePoint::new(
408+
let mut projective_point_1 = ProjectivePoint::new_unchecked(
395409
Felt::from_dec_str(
396410
"874739451078007766457464989774322083649278607533249481151382481072868806602",
397411
)
@@ -427,7 +441,7 @@ mod test {
427441
#[test]
428442
// Results checked against starknet-rs https://github.com/xJonathanLEI/starknet-rs/
429443
fn add_assign_operations_with_affine() {
430-
let mut projective_point = ProjectivePoint::new(
444+
let mut projective_point = ProjectivePoint::new_unchecked(
431445
Felt::from_dec_str(
432446
"874739451078007766457464989774322083649278607533249481151382481072868806602",
433447
)
@@ -463,7 +477,7 @@ mod test {
463477
#[test]
464478
// Results checked against starknet-rs https://github.com/xJonathanLEI/starknet-rs/
465479
fn add_assign_operations_with_affine_no_pointer() {
466-
let mut projective_point = ProjectivePoint::new(
480+
let mut projective_point = ProjectivePoint::new_unchecked(
467481
Felt::from_dec_str(
468482
"874739451078007766457464989774322083649278607533249481151382481072868806602",
469483
)
@@ -507,7 +521,7 @@ mod test {
507521
identity
508522
);
509523

510-
let projective_point_1 = ProjectivePoint::new(
524+
let projective_point_1 = ProjectivePoint::new_unchecked(
511525
Felt::from_dec_str(
512526
"685118385380464480289795596422487144864558069280897344382334516257395969277",
513527
)
@@ -539,7 +553,7 @@ mod test {
539553

540554
#[test]
541555
fn mul_by_scalar_operations_with_felt() {
542-
let a = ProjectivePoint::new(
556+
let a = ProjectivePoint::new_unchecked(
543557
Felt::from_dec_str(
544558
"685118385380464480289795596422487144864558069280897344382334516257395969277",
545559
)
@@ -564,7 +578,7 @@ mod test {
564578
#[test]
565579
// Results checked against starknet-rs https://github.com/xJonathanLEI/starknet-rs/
566580
fn double_operations() {
567-
let projective_point = ProjectivePoint::new(
581+
let projective_point = ProjectivePoint::new_unchecked(
568582
Felt::from_dec_str(
569583
"874739451078007766457464989774322083649278607533249481151382481072868806602",
570584
)
@@ -594,7 +608,7 @@ mod test {
594608

595609
#[test]
596610
fn neg_operations() {
597-
let a = ProjectivePoint::new(
611+
let a = ProjectivePoint::new_unchecked(
598612
Felt::from_dec_str(
599613
"685118385380464480289795596422487144864558069280897344382334516257395969277",
600614
)
@@ -606,7 +620,7 @@ mod test {
606620
Felt::from(1),
607621
);
608622

609-
let b = ProjectivePoint::new(
623+
let b = ProjectivePoint::new_unchecked(
610624
Felt::from_dec_str(
611625
"685118385380464480289795596422487144864558069280897344382334516257395969277",
612626
)
@@ -623,7 +637,7 @@ mod test {
623637

624638
#[test]
625639
fn sub_operations_pointers() {
626-
let mut a = ProjectivePoint::new(
640+
let mut a = ProjectivePoint::new_unchecked(
627641
Felt::from_dec_str(
628642
"685118385380464480289795596422487144864558069280897344382334516257395969277",
629643
)
@@ -645,7 +659,7 @@ mod test {
645659

646660
#[test]
647661
fn sub_operations() {
648-
let mut a = ProjectivePoint::new(
662+
let mut a = ProjectivePoint::new_unchecked(
649663
Felt::from_dec_str(
650664
"685118385380464480289795596422487144864558069280897344382334516257395969277",
651665
)

crates/starknet-types-core/src/felt/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ impl Felt {
234234

235235
/// Finite field division.
236236
pub fn field_div(&self, rhs: &NonZeroFelt) -> Self {
237-
Self(self.0 / rhs.0)
237+
Self((self.0 / rhs.0).expect("dividing by a non zero felt will never fail"))
238238
}
239239

240240
/// Truncated quotient between `self` and `rhs`.

0 commit comments

Comments
 (0)