From a6da0223557c5756092be84b95d7a9f6c6f4ad00 Mon Sep 17 00:00:00 2001 From: Federica Date: Tue, 2 Jan 2024 16:49:43 -0300 Subject: [PATCH 1/7] Add methods from_affine & double to ProjectivePoint --- crates/starknet-types-core/Cargo.toml | 2 +- .../src/curve/projective_point.rs | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/crates/starknet-types-core/Cargo.toml b/crates/starknet-types-core/Cargo.toml index 01a451e..1b81280 100644 --- a/crates/starknet-types-core/Cargo.toml +++ b/crates/starknet-types-core/Cargo.toml @@ -12,7 +12,7 @@ readme = "README.md" [dependencies] bitvec = { version = "1.0.1", default-features = false } -lambdaworks-math = {version = "0.3.0", default-features = false} +lambdaworks-math = {git = "https://github.com/lambdaclass/lambdaworks.git", rev = "55731492f8d919523a692265b1c34e7ca6387a0d", default-features = false} num-traits = { version = "0.2.16", default-features = false } num-bigint = { version = "0.4.4", default-features = false } diff --git a/crates/starknet-types-core/src/curve/projective_point.rs b/crates/starknet-types-core/src/curve/projective_point.rs index 5d174fb..f5c1d39 100644 --- a/crates/starknet-types-core/src/curve/projective_point.rs +++ b/crates/starknet-types-core/src/curve/projective_point.rs @@ -6,6 +6,7 @@ use lambdaworks_math::cyclic_group::IsGroup; use lambdaworks_math::elliptic_curve::short_weierstrass::curves::stark_curve::StarkCurve; use lambdaworks_math::elliptic_curve::short_weierstrass::point::ShortWeierstrassProjectivePoint; use lambdaworks_math::elliptic_curve::traits::EllipticCurveError::InvalidPoint; +use lambdaworks_math::elliptic_curve::traits::FromAffine; use lambdaworks_math::unsigned_integer::traits::IsUnsignedInteger; /// Represents a projective point on the Stark elliptic curve. @@ -33,6 +34,13 @@ impl ProjectivePoint { Ok(AffinePoint(self.0.to_affine())) } + pub fn from_affine(x: Felt, y: Felt) -> Result { + Ok(Self( + ShortWeierstrassProjectivePoint::from_affine(x.0, y.0) + .map_err(CurveError::EllipticCurveError)?, + )) + } + /// Returns the `x` coordinate of the point. pub fn x(&self) -> Felt { Felt(*self.0.x()) @@ -47,6 +55,10 @@ impl ProjectivePoint { pub fn z(&self) -> Felt { Felt(*self.0.z()) } + + pub fn double(&self) -> Self { + Self(self.0.double()) + } } impl ops::Add<&ProjectivePoint> for &ProjectivePoint { From 2cdd735eda7d225ce801e8fa62cdf534f960fc04 Mon Sep 17 00:00:00 2001 From: Federica Date: Tue, 2 Jan 2024 16:55:56 -0300 Subject: [PATCH 2/7] Fix version issues --- crates/starknet-types-core/Cargo.toml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/starknet-types-core/Cargo.toml b/crates/starknet-types-core/Cargo.toml index 1b81280..521ff55 100644 --- a/crates/starknet-types-core/Cargo.toml +++ b/crates/starknet-types-core/Cargo.toml @@ -12,6 +12,7 @@ readme = "README.md" [dependencies] bitvec = { version = "1.0.1", default-features = false } +# FIXME: Update after release lambdaworks-math = {git = "https://github.com/lambdaclass/lambdaworks.git", rev = "55731492f8d919523a692265b1c34e7ca6387a0d", default-features = false} num-traits = { version = "0.2.16", default-features = false } @@ -24,7 +25,8 @@ lazy_static = { version = "1.4.0", default-features = false, features = [ # Optional arbitrary = { version = "1.3.0", optional = true } serde = { version = "1.0.163", optional = true, default-features = false, features = ["alloc"] } -lambdaworks-crypto = { version = "0.3.0", default-features = false, optional = true } +# FIXME: Update after release +lambdaworks-crypto = { git = "https://github.com/lambdaclass/lambdaworks.git", rev = "55731492f8d919523a692265b1c34e7ca6387a0d", default-features = false, optional = true } parity-scale-codec = { version = "3.2.2", default-features = false, optional = true } [features] From 86af5f9b145f49e9327529d48577734dc27920a5 Mon Sep 17 00:00:00 2001 From: Federica Date: Tue, 2 Jan 2024 17:36:57 -0300 Subject: [PATCH 3/7] Add test --- .../src/curve/projective_point.rs | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/crates/starknet-types-core/src/curve/projective_point.rs b/crates/starknet-types-core/src/curve/projective_point.rs index f5c1d39..a1fecc8 100644 --- a/crates/starknet-types-core/src/curve/projective_point.rs +++ b/crates/starknet-types-core/src/curve/projective_point.rs @@ -224,4 +224,36 @@ mod test { .unwrap() ) } + + #[test] + // Results checked against starknet-rs https://github.com/xJonathanLEI/starknet-rs/ + fn double_operations() { + let projective_point = ProjectivePoint::new( + Felt::from_dec_str( + "874739451078007766457464989774322083649278607533249481151382481072868806602", + ) + .unwrap(), + Felt::from_dec_str( + "152666792071518830868575557812948353041420400780739481342941381225525861407", + ) + .unwrap(), + Felt::from(1), + ); + + assert_eq!( + projective_point.double().to_affine().unwrap(), + AffinePoint::new( + Felt::from_dec_str( + "3324833730090626974525872402899302150520188025637965566623476530814354734325", + ) + .unwrap(), + Felt::from_dec_str( + "3147007486456030910661996439995670279305852583596209647900952752170983517249", + ) + .unwrap() + ) + .unwrap() + ); + } + } From 6e0be57887c7cb83d2185361ac0f8cf0776d1810 Mon Sep 17 00:00:00 2001 From: Federica Date: Tue, 2 Jan 2024 18:24:55 -0300 Subject: [PATCH 4/7] Use commit from main --- crates/starknet-types-core/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/starknet-types-core/Cargo.toml b/crates/starknet-types-core/Cargo.toml index 521ff55..143d32f 100644 --- a/crates/starknet-types-core/Cargo.toml +++ b/crates/starknet-types-core/Cargo.toml @@ -13,7 +13,7 @@ readme = "README.md" [dependencies] bitvec = { version = "1.0.1", default-features = false } # FIXME: Update after release -lambdaworks-math = {git = "https://github.com/lambdaclass/lambdaworks.git", rev = "55731492f8d919523a692265b1c34e7ca6387a0d", default-features = false} +lambdaworks-math = {git = "https://github.com/lambdaclass/lambdaworks.git", rev = "7b41a9998d79593286ccd32bca6a8b80fd8ec95d", default-features = false} num-traits = { version = "0.2.16", default-features = false } num-bigint = { version = "0.4.4", default-features = false } From 7e3bea9efc92ee62eafa0bc8ad30d5b239bc967f Mon Sep 17 00:00:00 2001 From: Federica Date: Wed, 3 Jan 2024 11:18:57 -0300 Subject: [PATCH 5/7] fmt --- crates/starknet-types-core/src/curve/projective_point.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/starknet-types-core/src/curve/projective_point.rs b/crates/starknet-types-core/src/curve/projective_point.rs index a1fecc8..694cfec 100644 --- a/crates/starknet-types-core/src/curve/projective_point.rs +++ b/crates/starknet-types-core/src/curve/projective_point.rs @@ -255,5 +255,4 @@ mod test { .unwrap() ); } - } From f894cbfcea99742ac3e7b8e2fbd38e8f3fbd914a Mon Sep 17 00:00:00 2001 From: Federica Date: Wed, 3 Jan 2024 13:25:21 -0300 Subject: [PATCH 6/7] Update dep --- crates/starknet-types-core/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/starknet-types-core/Cargo.toml b/crates/starknet-types-core/Cargo.toml index 143d32f..5dddd7b 100644 --- a/crates/starknet-types-core/Cargo.toml +++ b/crates/starknet-types-core/Cargo.toml @@ -26,7 +26,7 @@ lazy_static = { version = "1.4.0", default-features = false, features = [ arbitrary = { version = "1.3.0", optional = true } serde = { version = "1.0.163", optional = true, default-features = false, features = ["alloc"] } # FIXME: Update after release -lambdaworks-crypto = { git = "https://github.com/lambdaclass/lambdaworks.git", rev = "55731492f8d919523a692265b1c34e7ca6387a0d", default-features = false, optional = true } +lambdaworks-crypto = { git = "https://github.com/lambdaclass/lambdaworks.git", rev = "7b41a9998d79593286ccd32bca6a8b80fd8ec95d", default-features = false, optional = true } parity-scale-codec = { version = "3.2.2", default-features = false, optional = true } [features] From 8eb09819516f3dcb40e1696be9edeae473f339dd Mon Sep 17 00:00:00 2001 From: Federica Date: Wed, 3 Jan 2024 16:26:42 -0300 Subject: [PATCH 7/7] Update lambdaworks version --- crates/starknet-types-core/Cargo.toml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/crates/starknet-types-core/Cargo.toml b/crates/starknet-types-core/Cargo.toml index 5dddd7b..ecc88f9 100644 --- a/crates/starknet-types-core/Cargo.toml +++ b/crates/starknet-types-core/Cargo.toml @@ -12,8 +12,7 @@ readme = "README.md" [dependencies] bitvec = { version = "1.0.1", default-features = false } -# FIXME: Update after release -lambdaworks-math = {git = "https://github.com/lambdaclass/lambdaworks.git", rev = "7b41a9998d79593286ccd32bca6a8b80fd8ec95d", default-features = false} +lambdaworks-math = { version = "0.4.0", default-features = false} num-traits = { version = "0.2.16", default-features = false } num-bigint = { version = "0.4.4", default-features = false } @@ -25,8 +24,7 @@ lazy_static = { version = "1.4.0", default-features = false, features = [ # Optional arbitrary = { version = "1.3.0", optional = true } serde = { version = "1.0.163", optional = true, default-features = false, features = ["alloc"] } -# FIXME: Update after release -lambdaworks-crypto = { git = "https://github.com/lambdaclass/lambdaworks.git", rev = "7b41a9998d79593286ccd32bca6a8b80fd8ec95d", default-features = false, optional = true } +lambdaworks-crypto = { version = "0.4.0", default-features = false, optional = true } parity-scale-codec = { version = "3.2.2", default-features = false, optional = true } [features]