Skip to content

Use zeroize crate for SigningKey. #735

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

FilipLaurentiu
Copy link

@FilipLaurentiu FilipLaurentiu commented May 28, 2025

fn secret_scalar returns a reference to the secret scalar so the value is still zeroed on drop

Update starknet-types-core version to 0.1.8 everywhere to use the zeroize feature starknet-io/types-rs@67468ff

`fn secret_scalar` returns a reference to the secret scalar so the value is still zeroed on drop

Update `starknet-types-core` version to `0.1.8` everywhere to use the `zeroize` feature
@FilipLaurentiu
Copy link
Author

In case this is needed I will create a PR for eth_keystore crate as well.

@@ -13,7 +13,7 @@ Stark curve
keywords = ["ethereum", "starknet", "web3", "no_std"]

[dependencies]
starknet-types-core = { version = "0.1.7", default-features = false, features = ["curve"] }
starknet-types-core = { version = "0.1.8", default-features = false, features = ["curve"] }
Copy link
Author

Choose a reason for hiding this comment

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

Latest version of starknet-types-core support operations on EC points as well starknet-io/types-rs@e0eff28

@@ -100,8 +101,8 @@ impl SigningKey {
}

/// Gets the secret scalar in the signing key.
pub const fn secret_scalar(&self) -> Felt {
self.secret_scalar
pub const fn secret_scalar(&self) -> &Felt {
Copy link
Contributor

Choose a reason for hiding this comment

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

What motivated a change to & when Felt is copiable? Most usage takes a Felt as argument which would lead to a copy while dereferencing.

Copy link
Author

@FilipLaurentiu FilipLaurentiu May 30, 2025

Choose a reason for hiding this comment

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

What motivated a change to & when Felt is copiable? Most usage takes a Felt as argument which would lead to a copy while dereferencing.

For this case, the motivation is to avoid creating another copy of a Felt that will not be zeroized on drop and stay in memory. Returning just a reference to the internal value will solve this problem, the value will still be zeroized at the end.

@FilipLaurentiu FilipLaurentiu marked this pull request as draft May 30, 2025 12:23
@FilipLaurentiu FilipLaurentiu requested a review from glihm June 2, 2025 15:33
@FilipLaurentiu FilipLaurentiu marked this pull request as ready for review June 2, 2025 15:34
… takes a `Felt` as a value but `Felt` is copied and the initial value is left on the stack at the end.

New method `fn from_secret` use `SecretString` that implement zeroize and will not leak.

Add `test_keystore` test for the keystore

Fix tests and examples
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.

2 participants