Skip to content
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

Implement starknet_core_types::curve module #8

Merged
merged 32 commits into from
Nov 1, 2023

Conversation

pefontana
Copy link
Collaborator

@pefontana pefontana commented Oct 18, 2023

Implement starknet_core_types::curve module

  • Move the Felt implementation to starknet_core_types
  • Implement Implement starknet_core_types::curve module:
    • affine_point
    • projective_point
    • curve_errors

Does this introduce a breaking change?

Yes

@pefontana pefontana changed the title Add stark curve crate Implement stark curve crate Oct 18, 2023
@pefontana pefontana changed the title Implement stark curve crate Implement stark curve Oct 20, 2023
@pefontana pefontana changed the title Implement stark curve Implement starknet_core_types::curve module Oct 20, 2023
@pefontana pefontana marked this pull request as ready for review October 25, 2023 21:01
@nils-mathieu
Copy link
Contributor

nils-mathieu commented Oct 25, 2023

I'm not sure whether moving the Felt type to the core crate is a good idea. If we have starknet-types-rpc depend on it, it will bring a whole range of types that regular Starknet clients just don't care about.

Felt might not be the only type for which this matters though.

The question to be asked is whether the "rpc types" crate should depend on the "core types" crate. It's not clear to me.

Obvious pro is simplicity. Less crates to worry about = less time auditing dependencies and thinking about dependency trees. Obvious con is bringing a whole range of types that people might not need. Just using feature flags a bit aggressively might suffice to solve the issue though.

I don't have a strong opinion on that.

@pefontana
Copy link
Collaborator Author

I'm not sure whether moving the Felt type to the core crate is a good idea. If we have starknet-types-rpc depend on it, it will bring a whole range of types that regular Starknet clients just don't care about.

Felt might not be the only type for which this matters though.

The question to be asked is whether the "rpc types" crate should depend on the "core types" crate. It's not clear to me.

Obvious pro is simplicity. Less crates to worry about = less time auditing dependencies and thinking about dependency trees. Obvious con is bringing a whole range of types that people might not need. Just using feature flags a bit aggressively might suffice to solve the issue though.

I don't have a strong opinion on that.

great @nils-mathieu
As we talked on telegram, I added a feature flag with the curve implementation
15bed72

I think it is okay to leave these implementations inside the starknet-types-core crate since I dont think there are plans to add many more structs inside the crates. In case there is any problem I can move all to a new starknet-arithmetic

@nils-mathieu
Copy link
Contributor

nils-mathieu commented Oct 27, 2023

Of note, if we do end up using unsafe code to return references, I'd say we should create a private function on those lines:

#[repr(transparent)]
struct Felt(FieldElement< /* ... */ >);

impl Felt {
    // no-op function to turn a field element reference into a `Felt`
    #[inline(always)]
    fn wrap(inner: &FieldElement< /* ... */ >) -> &Self {
        // SAFETY:
        //  `Felt` is a `#[repr(transparent)]` wrapper around `FieldElement< /* ... */ >`,
        //  which ensures that its memory layout is always the same as its content.
        unsafe { &*(inner as *const _ as *const Self) }
    }
}

to avoid putting the same bit of unsafe code everywhere

@pefontana pefontana mentioned this pull request Oct 27, 2023
Copy link
Collaborator

@0xLucqs 0xLucqs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a curve feature flag plz

@tdelabro
Copy link
Collaborator

Even if we don't do the unsafe stuff, I think we should still add #[repr(transparent)] to the wrappers types.

@pefontana
Copy link
Collaborator Author

Can you add a curve feature flag plz

Hi @LucasLvy !
The feature flag is already added
https://github.com/starknet-io/types-rs/pull/8/files#diff-5fc4f24b82d50a8341933bd608f0a88b530790f6a4a38d9c8d0583646bf5762fR2

@pefontana
Copy link
Collaborator Author

df43f6c

Sure @tdelabro
Done df43f6c

Copy link
Contributor

@nils-mathieu nils-mathieu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@AbdelStark AbdelStark merged commit 14b58ff into starknet-io:main Nov 1, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants