Drop p256k1 in favour of RustCrypto k256, pending MSM benchmarks

Open
#243 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
rust
Domain
cryptography

Research direction

Start by re-benchmarking k256 MSM against the current p256k1/libsecp256k1 path at both 20 keys and 1000+ keys. If MSM remains slow, check whether it is the bottleneck in CheckPrivateShares::MultiMult in common.rs, compute::aggregate_nonce, and the lambda/binding loops in both aggregators; benches/v2_bench.rs covers DKG, party signing, and aggregation. Done means establishing the performance gap and bottleneck; any migration is a major-version change and is explicitly contingent on those results.

Written by the indexing model from the issue text.

Description

Proposal: drop the p256k1 wrapper and move to RustCrypto k256, contingent on benchmarking where the performance gap actually is.

Why now

p256k1 is a single-maintainer C wrapper that exists because libsecp256k1 exposes no public API for raw scalar and point arithmetic. The costs have accumulated:

  • Every consumer needs a C toolchain. with_p256k1_bindgen is in wsts's default features and forwards to p256k1/with_bindgen, so a plain cargo build runs bindgen over C libsecp256k1 and requires libclang. #29 is a user who simply could not build the crate because of this (clang diagnostics, then NoRustfmt panicking inside p256k1's build.rs).
  • The no-bindgen escape hatch is broken. cargo check --no-default-features fails today: p256k1's pre-generated bindings are missing all five secp256k1_context_preallocated_* symbols, so _rename.rs does not compile. In practice wsts cannot be used with default-features = false at all.
  • Fixing that means regenerating bindings against libsecp, which is the operation that has historically gone badly, and it is work thrown away if we migrate anyway.
  • The repository was never transferred. Trust-Machines/p256k1 remains the unarchived upstream and xoloki/p256k1 is a fork of it (currently identical). Published 7.2.2 dates from 2025-01-31 and its crates.io repository field still points at the old org. So keeping it means re-homing a repo and cutting a release purely to fix metadata on a dependency we would rather delete.

Dropping it removes the C toolchain requirement outright, which is the largest ergonomic cost wsts currently imposes on consumers.

The blocker, and what to measure

The reason this has not happened is performance: k256's multi-scalar multiplication benchmarked substantially slower than libsecp256k1 when last tested. That measurement is old and may no longer hold — RustCrypto has moved on since.

It also matters less than the raw numbers suggest. The MSM cost only becomes significant with large polynomials, on the order of 1000+ keys; at that scale it dominates, but at the sizes used in normal testing it is visible without being decisive.

So the first step is measurement, not migration:

  1. Re-benchmark k256 MSM against the current p256k1/libsecp path. If it has been fixed upstream, the blocker is gone.
  2. If it is still slow, determine whether MSM is actually the bottleneck for wsts rather than assuming it. The hot paths are concentrated: CheckPrivateShares's MultiMult impl in common.rs, compute::aggregate_nonce, and the lambda/binding loops in both aggregators. benches/v2_bench.rs already covers DKG, party signing and aggregation, so a k256-backed branch behind a feature flag can be compared against existing numbers directly.
  3. Benchmark at both ends of the range — small (the current 20 keys / 4 signers) and large (1000+ keys) — since the gap only bites at scale and a small-N benchmark could wrongly clear or wrongly condemn it.

If MSM is slow and is the bottleneck, contributing a Pippenger improvement to k256 is an attractive path: it is self-contained, benchmarkable, carries no protocol risk to wsts, and if it lands we delete a crate.

Scope of the migration itself

Not small. src/lib.rs has pub use p256k1 as curve;, so wsts::curve::{Point, Scalar} is public API and downstream code depends on those types. Point and Scalar appear throughout common.rs, compute.rs, schnorr.rs, traits.rs, v1.rs, v2.rs and both state machines. This is a major-version change for consumers, and worth batching with other breaking work.

Note this is unrelated to #60, which is about converting WSTS signatures into ZCash FROST format for verification, not about the underlying curve implementation.

Dominant language
Rust
Stars
34
Forks
19
Avg merge
9h 19m
Merged PRs (30d)
12

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from xoloki/wsts

All issues in xoloki/wsts

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.