-
Notifications
You must be signed in to change notification settings - Fork 54
Implement starknet_core_types::curve module #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
922eee7
Create stark-cuve crate + naive implement ProjectivePoint
pefontana 5bff6a9
Implement AffinePoint
pefontana 05945f1
Add froms
pefontana 0a1bd07
Implement ops::Add<&ProjectivePoint> for &ProjectivePoint
pefontana b9ff318
remove starknet-types-core
pefontana 79a7461
Update .gitignore
pefontana c39043a
rename stark-felt -> starknet-types-core && Implement curve mod
pefontana f541949
remove todo
pefontana 6d92354
Remove crates/stark-curve
pefontana ffca830
fix ensure_no_std
pefontana a7bf4eb
Update commit
pefontana c9a337b
implement x(), y(), z() methods
pefontana fd14bf5
little fix
pefontana ee74daa
Divide the curve into two mods projective_point affine_point
pefontana 0ddba75
minor fixes
pefontana eff975d
Update Readme.md
pefontana abd9d51
Fix to_affine method
pefontana 6bafc48
Remove AffinePoint operations
pefontana 6862fd6
Add tests
pefontana b54dbdb
Add Error handle to to_affine method
pefontana 3239971
Add CurveError
pefontana e5609a2
docs
pefontana 495c0da
Update Cargo.toml
pefontana 5d2a260
docs
pefontana b4da689
Restore .gitignore
pefontana 93d5f0a
Docs
pefontana 900cea3
Remove crates/.DS_Store
pefontana 15bed72
Add curve feature
pefontana 971bef6
Doc
pefontana df43f6c
Add #[repr(transparent)]
pefontana 3a20aed
Add struct docs
pefontana 8787772
Re export curve types
pefontana File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
[workspace] | ||
members = [ | ||
"crates/stark-felt", | ||
"crates/starknet-types-core", | ||
"crates/starknet-types-rpc", | ||
] | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,31 @@ | ||
[package] | ||
name = "starknet-types-core" | ||
version = "0.0.2" | ||
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 = "Starknet core types." | ||
description = "Core types representation for Starknet" | ||
readme = "README.md" | ||
|
||
[dependencies] | ||
bitvec = { version = "1.0.1", default-features = false } | ||
serde = { version = "1.0.163", optional = true, default-features = false } | ||
lambdaworks-math = { git = "https://github.com/lambdaclass/lambdaworks.git", rev = "f940e14ed17370d29fe129951448037d11b65ce8", default-features = false} | ||
|
||
|
||
arbitrary = { version = "1.3.0", optional = true, default-features = false } | ||
num-traits = { version = "0.2.16", default-features = false } | ||
|
||
[features] | ||
default = ["std", "serde", "curve"] | ||
curve = [] | ||
std = [] | ||
alloc = ["serde?/alloc"] | ||
arbitrary = ["std", "dep:arbitrary"] | ||
|
||
[dev-dependencies] | ||
proptest = "1.1.0" | ||
serde_test = "1.0.1" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use crate::curve::curve_errors::CurveError; | ||
use crate::felt::Felt; | ||
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::FromAffine; | ||
|
||
/// Represents a point on the Stark elliptic curve. | ||
/// Doc: https://docs.starkware.co/starkex/crypto/stark-curve.html | ||
#[repr(transparent)] | ||
#[derive(Debug, Clone, PartialEq, Eq)] | ||
pub struct AffinePoint(pub(crate) ShortWeierstrassProjectivePoint<StarkCurve>); | ||
pefontana marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
impl AffinePoint { | ||
pub fn new(x: Felt, y: Felt) -> Result<AffinePoint, CurveError> { | ||
Ok(Self(ShortWeierstrassProjectivePoint::from_affine( | ||
x.0, y.0, | ||
)?)) | ||
} | ||
|
||
/// The point at infinity. | ||
pub fn identity() -> AffinePoint { | ||
Self(ShortWeierstrassProjectivePoint::neutral_element()) | ||
} | ||
|
||
/// Returns the `x` coordinate of the point. | ||
pub fn x(&self) -> Felt { | ||
Felt(*self.0.x()) | ||
} | ||
|
||
/// Returns the `y` coordinate of the point. | ||
pub fn y(&self) -> Felt { | ||
Felt(*self.0.y()) | ||
} | ||
tdelabro marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use super::*; | ||
|
||
#[test] | ||
fn affine_point_identity() { | ||
let identity = AffinePoint::identity(); | ||
|
||
assert_eq!(identity.x(), Felt::from(0)); | ||
assert_eq!(identity.y(), Felt::from(1)); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use core::fmt::Debug; | ||
use lambdaworks_math::elliptic_curve::traits::EllipticCurveError; | ||
|
||
#[derive(Debug, PartialEq, Eq)] | ||
pub enum CurveError { | ||
EllipticCurveError(EllipticCurveError), | ||
} | ||
|
||
impl From<EllipticCurveError> for CurveError { | ||
fn from(error: EllipticCurveError) -> CurveError { | ||
CurveError::EllipticCurveError(error) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
mod affine_point; | ||
mod curve_errors; | ||
mod projective_point; | ||
|
||
pub use self::affine_point::*; | ||
pub use self::curve_errors::*; | ||
pub use self::projective_point::*; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.