Kgothatso Ngako 89b253b50e frost_enrollment: implement the three rounds
Third of six commits. Replaces the Phase 1 stubs with the real
arithmetic, adds a smoke test that a 2-of-3 group really does grow into
a working 2-of-4 one, and wires the entry points into ctime_tests.

The Lagrange machinery is frost's, called in place. pubshare_derive is a
skin over secp256k1_frost_derive_pubshare_at
(src/modules/frost/keygen_impl.h:150) evaluated at identifier new_id,
and the id canonicalization is secp256k1_frost_sort_ids, reached through
the declaration the previous commit added.

The one piece frost could not supply is the scalar Lagrange coefficient
at an arbitrary point. frost's secp256k1_frost_derive_interpolating_value
evaluates at x-coordinate 0, which is what reconstructing the group
secret needs; enrollment needs the basis polynomial at the TARGET
x-coordinate. secp256k1_frost_enrollment_lagrange_at is that, and it is
deliberately the same product derive_pubshare_at applies to each
pubshare, in the same identifier space -- so the scalar path and the
point path agree by construction rather than by coincidence. Working in
identifier space is what makes the id-to-x-coordinate +1 cancel: an
x-coordinate difference x_j - x_i is the identifier difference
id_j - id_i.

Round 1.1 computes v = lambda * secshare and splits it. Every share but
the one kept locally is masking randomness derived as

  Scalar.from_bytes_wrapping(
      TH("FROST enrollment/share_split",
         rand32 || params_hash32 || ser32(my_id) || ser32(recipient_id)))

with rand32 = TH(same tag, session_secrand32) XOR secshare32; the kept
share absorbs the remainder so the set sums to v. Three details:

- The reduction wraps rather than rejects, chilldkg's
  from_bytes_wrapping (src/modules/chilldkg/util_impl.h:394). A 256-bit
  hash mod the group order is about 2^-128 from uniform; rejection
  sampling would buy that back in exchange for a variable-time loop.
- Masking with the secret share is the secp256k1_frost_nonce_gen pattern
  (session_impl.h:340), so a broken RNG alone does not reveal the split.
- The derivation is indexed by the recipient's IDENTIFIER, not by its
  position in the caller's ids array. The plan called for a counter;
  identifiers are unique, so they are one, and using them makes the
  split independent of the order a caller lists the helper set in. What
  the binding buys is DOMAIN SEPARATION only: params_hash32 carries the
  group key and the whole parameter tuple, so two runs sharing a seed
  but differing in either cannot produce the same deltas. It cannot
  detect a disagreement between helpers, because nothing cross-checks
  per-helper private randomness. That is the params hash's job.

session_secrand32 is wiped whether the call succeeds or fails, so a
caller cannot retry a failed run on the same randomness.

Round 1.2 recomputes its own params hash from the group key and the
tuple, compares every received hash against it, then sums. The slot at
the caller's own position in received_params_hashes32 is skipped, while
the same position in all_shares32 is read -- the asymmetry the header
documents, and the thing that makes this a recomputation rather than a
string comparison. The mode and bounds are re-validated here rather than
trusted from the round 1.1 call site, since the full tuple is present.
An out-of-range share is reported through mismatch_id the way
secp256k1_frost_partial_sig_agg reports an unparseable partial
signature.

Round 2 compares the params hash against its own recomputation over the
authenticated group key, sums, rejects a zero share, and checks
secshare*G against the expected public share.

Three deviations from the plan, all to match what the tree already does:

- Value ranges return 0; only pointers get ARG_CHECK. The plan called
  for an ARG_CHECK on the n_ids bound, but the frost module's split is
  the one used here (secp256k1_frost_trusted_dealer_keygen,
  keygen_impl.h:227), and the header already documents these as
  return-0 conditions. The bound is still enforced in production builds
  -- params_are_valid requires 2 <= threshold <= n_ids <= n_participants
  <= 128 -- so it does not ride on the VERIFY_CHECK inside
  secp256k1_frost_sort_ids, which is what the plan was guarding against.
- The public-share check declassifies the derived point and compares
  with secp256k1_ge_eq_var, rather than comparing 33 serialized bytes in
  constant time. There is no constant-time memcmp in this tree, and
  secshare*G is a public key: secp256k1_frost_sign declassifies exactly
  this quantity before exactly this comparison
  (src/modules/frost/session_impl.h:770, :789). Inventing a primitive to
  avoid following that precedent would be the worse trade.
- params_hash's public entry point delegates to the same internal
  routine every gate uses, so the encoding has exactly one
  implementation to keep in step with the vectors.

One real bug found by the tooling rather than by reading. Accumulators
were initialized with secp256k1_scalar_clear, and
secp256k1_memclear_explicit marks its target UNDEFINED in VERIFY builds
(src/util.h:295) precisely so that reading cleared memory is caught. It
was: valgrind reported 143752 errors in share_agg's summation loop.
Accumulators now start at secp256k1_scalar_set_int(x, 0); scalar_clear
is used only where it means "done with this secret". Worth stating
plainly because the failure mode is invisible in a production build,
where memclear_explicit only zeroes.

ctime_tests gains a 2-of-3-enrolls-a-fourth block covering all three
rounds, following prefractal's b66c757b. The threshold key, the secret
shares, the session randomness and every delta and sigma on the wire are
marked secret; the identifiers, public shares, group key, parameters
hashes and derived public share are not. Under valgrind: 0 errors from 0
contexts, so no branch or memory access in the new code depends on
secret data.

Verification: ./tests, ./noverify_tests and ./exhaustive_tests exit 0;
the frost_enrollment module runs clean under valgrind (0 errors); a
separate CPPFLAGS='-DVERIFY' build compiles without warnings and passes;
the module builds warning-free alongside frost, chilldkg, iceberg and
prefractal.

The smoke test is the substantive check: after a 2-of-3 group enrolls
participant 3, every pair {i, 3} for i in 0..2 reconstructs the original
threshold secret and matches the threshold public key, and the untouched
pair {0, 1} still does too.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-04 04:06:59 +02:00
2026-09-04 02:56:23 +02:00
2026-08-31 12:25:09 +02:00
2013-05-09 15:24:32 +02:00

libsecp256k1-zkp

Dependencies: None

A fork of libsecp256k1 with support for advanced and experimental features

Added features:

  • Experimental module for ECDSA adaptor signatures.
  • Experimental module for ECDSA sign-to-contract.
  • Experimental modules for Confidential Assets (Pedersen commitments, range proofs, and surjection proofs).
  • Experimental module for address whitelisting.
  • Experimental module for Schnorr signature half-aggregation.
  • Experimental module for FROST (BIP 445).
  • Experimental module for ChillDKG, distributed key generation for FROST (bip-frost-dkg draft).
  • Experimental module for Iceberg, a threshold scheme that lets a group of parties stand in for a single MuSig2 (BIP 327) participant.
  • Experimental module for Prefractal, a nested FROST+MuSig2 signer that lets a FROST group occupy one participant slot of an ordinary MuSig2 (BIP 327) session.

Experimental features are made available for testing and review by the community. The APIs of these features should not be considered stable.

Build steps

Obtaining and verifying

The git tag for each release (e.g. v0.6.0) is GPG-signed by one of the maintainers. For a fully verified build of this project, it is recommended to obtain this repository via git, obtain the GPG keys of the signing maintainer(s), and then verify the release tag's signature using git.

This can be done with the following steps:

  1. Obtain the GPG keys listed in SECURITY.md.
  2. If possible, cross-reference these key IDs with another source controlled by its owner (e.g. social media, personal website). This is to mitigate the unlikely case that incorrect content is being presented by this repository.
  3. Clone the repository:
    git clone https://github.com/bitcoin-core/secp256k1
    
  4. Check out the latest release tag, e.g.
    git checkout v0.7.1
    
  5. Use git to verify the GPG signature:
    % git tag -v v0.7.1 | grep -C 3 'Good signature'
    
    gpg: Signature made Mon 26 Jan 2026 07:42:46 PM UTC
    gpg:                using RSA key 2840EAABF4BC9F0FFD716AFAFBAFCC46DE2D3FE2
    gpg: Good signature from "Pieter Wuille <pieter@wuille.net>" [unknown]
    gpg:                 aka "Pieter Wuille <pieter.wuille@gmail.com>" [full]
    gpg:                 aka "[jpeg image of size 5996]" [undefined]
    gpg: WARNING: This key is not certified with a trusted signature!
    gpg:          There is no indication that the signature belongs to the owner.
    Primary key fingerprint: 133E AC17 9436 F14A 5CF1  B794 860F EB80 4E66 9320
         Subkey fingerprint: 2840 EAAB F4BC 9F0F FD71  6AFA FBAF CC46 DE2D 3FE2
    

Building with Autotools

$ ./autogen.sh       # Generate a ./configure script
$ ./configure        # Generate a build system
$ make               # Run the actual build process
$ make check         # Run the test suite
$ sudo make install  # Install the library into the system (optional)

To compile optional modules (such as Schnorr signatures), you need to run ./configure with additional flags (such as --enable-module-schnorrsig). Run ./configure --help to see the full list of available flags. For experimental modules, you will also need --enable-experimental as well as a flag for each individual module, e.g. --enable-module-rangeproof.

Building with CMake

To maintain a pristine source tree, CMake encourages to perform an out-of-source build by using a separate dedicated build tree.

Building on POSIX systems

$ cmake -B build              # Generate a build system in subdirectory "build"
$ cmake --build build         # Run the actual build process
$ ctest --test-dir build      # Run the test suite
$ sudo cmake --install build  # Install the library into the system (optional)

To compile optional modules (such as Schnorr signatures), you need to run cmake with additional flags (such as -DSECP256K1_ENABLE_MODULE_SCHNORRSIG=ON). Run cmake -B build -LH or ccmake -B build to see the full list of available flags.

Cross compiling

To alleviate issues with cross compiling, preconfigured toolchain files are available in the cmake directory. For example, to cross compile for Windows:

$ cmake -B build -DCMAKE_TOOLCHAIN_FILE=cmake/x86_64-w64-mingw32.toolchain.cmake

To cross compile for Android with NDK (using NDK's toolchain file, and assuming the ANDROID_NDK_ROOT environment variable has been set):

$ cmake -B build -DCMAKE_TOOLCHAIN_FILE="${ANDROID_NDK_ROOT}/build/cmake/android.toolchain.cmake" -DANDROID_ABI=arm64-v8a -DANDROID_PLATFORM=28

Building on Windows

The following example assumes Visual Studio 2022. Using clang-cl is recommended.

In "Developer Command Prompt for VS 2022":

>cmake -B build -T ClangCL
>cmake --build build --config RelWithDebInfo

Usage examples

Usage examples can be found in the examples directory. To compile them you need to configure with --enable-examples.

To compile the examples, make sure the corresponding modules are enabled.

Benchmark

If configured with --enable-benchmark (which is the default), binaries for benchmarking the libsecp256k1-zkp functions will be present in the root directory after the build.

To print the benchmark result to the command line:

$ ./bench_name

To create a CSV file for the benchmark result :

$ ./bench_name | sed '2d;s/ \{1,\}//g' > bench_name.csv

Reporting a vulnerability

See SECURITY.md

Contributing to libsecp256k1

See CONTRIBUTING.md

Description
Experimental fork of libsecp256k1 with support for pedersen commitments and range proofs.
Readme 15 MiB
Languages
C 94.5%
Python 2%
CMake 0.9%
Sage 0.8%
M4 0.7%
Other 1%