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

Proper way to construct a WrappedScalar #12

Open
apyrgio opened this issue Jan 27, 2023 · 0 comments
Open

Proper way to construct a WrappedScalar #12

apyrgio opened this issue Jan 27, 2023 · 0 comments

Comments

@apyrgio
Copy link

apyrgio commented Jan 27, 2023

The secp256k1::WrappedScalar has the following constructors:

From<k256::arithmetic::scalar::Scalar>>
From<u64>>

The problems with these constructors are:

  • The first constructor requires a Scalar type, which must match the exact same k256 version that vsss_rs uses (currently 0.11, but 0.12 is out). Else, we have this problem:

    error[E0277]: the trait bound `vsss_rs::secp256k1::WrappedScalar: From<Scalar>` is not satisfied
    ...
      = help: the following other types implement trait `From<T>`:
                <vsss_rs::secp256k1::WrappedScalar as From<k256::arithmetic::scalar::Scalar>>
                <vsss_rs::secp256k1::WrappedScalar as From<u64>>
      = note: required for `Scalar` to implement `Into<vsss_rs::secp256k1::WrappedScalar>`
    
  • The second constructor will not work with 256-bit keys, if I understand correctly.

There also some other constructors (e.g., from_be_bytes_reduced), but it's not clear how one can use them (not a fault of this repo, the elliptic_curves is a bit lacking in this regard).

Why is the above a problem? Consider someone running the examples in this repo:

use k256::{NonZeroScalar, SecretKey};
[...]

let sk = SecretKey::random(&mut osrng);
let secret = WrappedScalar(*sk.to_nonzero_scalar());

Rust will complain that the Scalar type that vsss_rs expects (0.11) is different from the provided k256::Scalar type (0.12). The only way I've found to circumvent this limitation is to use an older version of k256 (0.11), specifically for importing a k256::SecretKey, which will produce a proper k256::Scalar type (0.11).

This is of course a bit esoteric, and prone to breakage. A better suggestion would be to re-export k256::SecretKey from this module (as k256 already does for the elliptic_curves::SecretKey), and let library consumers use that.

Do you agree, do you perhaps have a better suggestion?

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

No branches or pull requests

1 participant