Skip to content

Commit

Permalink
Create stark-cuve crate + naive implement ProjectivePoint
Browse files Browse the repository at this point in the history
  • Loading branch information
pefontana committed Oct 18, 2023
1 parent ea52b64 commit 922eee7
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[workspace]
members = [
"crates/stark-felt",
"crates/stark-curve",
"crates/starknet-types-core",
"crates/starknet-types-rpc",
]
Expand Down
18 changes: 18 additions & 0 deletions crates/stark-curve/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "stark-curve"
version = "0.0.3"
edition = "2021"
license = "MIT"
homepage = "https://github.com/starknet-io/types-rs"
repository = "https://github.com/starknet-io/types-rs"
categories = ["types", "math", "crypto"]
keywords = ["stark", "zkp", "cairo"]
description = "A stark curve type for Cairo."
readme = "README.md"

[dependencies]
lambdaworks-math = { git = "https://github.com/Lambdaclass/lambdaworks.git" ,rev = "23154c1b2b7c1cb1620e40ee53fbb446a2923923", default_features = true }
num-traits = { version = "0.2.16", default-features = false }

stark-felt = {path = "../stark-felt"}

Empty file added crates/stark-curve/README.md
Empty file.
24 changes: 24 additions & 0 deletions crates/stark-curve/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use core::ops;
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 stark_felt::Felt;

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ProjectivePoint(ShortWeierstrassProjectivePoint<StarkCurve>);

impl ProjectivePoint {
pub fn new(x: Felt, y: Felt, z: Felt) -> ProjectivePoint {
Self(ShortWeierstrassProjectivePoint::new([x.0, y.0, z.0]))
}

pub fn identity() -> ProjectivePoint {
Self(ShortWeierstrassProjectivePoint::neutral_element())
}
}

impl ops::AddAssign<&ProjectivePoint> for ProjectivePoint {
fn add_assign(&mut self, rhs: &ProjectivePoint) {
self.0 = self.0.operate_with(&rhs.0);
}
}
3 changes: 2 additions & 1 deletion crates/stark-felt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ readme = "README.md"
[dependencies]
bitvec = { version = "1.0.1", default-features = false }
serde = { version = "1.0.163", optional = true, default-features = false }
lambdaworks-math = { version = "0.2.0", default_features = false }
lambdaworks-math = { git = "https://github.com/Lambdaclass/lambdaworks.git" ,rev = "23154c1b2b7c1cb1620e40ee53fbb446a2923923", default_features = false }

arbitrary = { version = "1.3.0", optional = true, default-features = false }
num-traits = { version = "0.2.16", default-features = false }

Expand Down
2 changes: 1 addition & 1 deletion crates/stark-felt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use arbitrary::{self, Arbitrary, Unstructured};

/// Definition of the Field Element type.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Felt(FieldElement<Stark252PrimeField>);
pub struct Felt(pub FieldElement<Stark252PrimeField>);

/// A non-zero [Felt].
pub struct NonZeroFelt(FieldElement<Stark252PrimeField>);
Expand Down

0 comments on commit 922eee7

Please sign in to comment.