build: wire the frost_enrollment module into both build systems
Second of six commits adding the frost_enrollment module. This one is scaffolding only: the five entry points are stubs that validate their pointer arguments, zero their outputs and return 0. What is being verified here is that the module configures, compiles, links, exports its symbols and registers its test module in both build systems -- so that the next commit changes nothing but arithmetic. Ordering is the one thing in this commit that can go silently wrong, and it goes wrong in opposite directions in the two build systems: - configure.ac executes its `if` blocks in file order, and enable_module_frost defaults to no (configure.ac:243). A block placed after the frost block at :601 that sets enable_module_frost=yes flips the variable too late: AM_CONDITIONAL goes true, so the header is installed and the Makefile fragment is pulled in, but -DENABLE_MODULE_FROST=1 is never appended, so src/secp256k1.c never includes frost's implementation and every secp256k1_frost_* symbol fails to link. The new block therefore goes ahead of both the frost block and prefractal's, which documents the same trap. - src/CMakeLists.txt processes dependents FIRST, so the same block goes above the FROST block there, beside prefractal's. Verified rather than assumed: configuring with ONLY --enable-module-frost-enrollment emits -DENABLE_MODULE_FROST=1 alongside -DENABLE_MODULE_FROST_ENROLLMENT=1, and the CMake summary prints "frost ON" for the same configuration -- the latter is what the PARENT_SCOPE lift buys, since the summary runs after add_subdirectory(src) and would otherwise report a module it is compiling in as OFF. The dependency guard is prefractal's implies-frost idiom, copied verbatim along with its reasoning. frost is default-OFF, so the `test x"$enable_module_frost" = x"no"` / `DEFINED X AND NOT X` guard every other module uses -- which reads as "the user disabled it explicitly" for a default-ON dependency -- is true by default here and cannot tell an explicit --disable-module-frost from the default once both are in the cache. Enabling frost-enrollment simply implies frost, with no error. The one frost-module change in the whole series is in this commit: src/modules/frost/session.h gains a declaration for secp256k1_frost_sort_ids, which is defined at session_impl.h:517 and declared nowhere. The params hash needs it to canonicalize identifier order. Prefractal reaches frost's statics through translation-unit ordering alone; rather than inherit reuse-by-link-order, this declares the function where keygen.h:48 already declares derive_pubshare_at, so the reuse goes through an interface. No behavior change: it is a declaration for an existing static definition in the same TU. CI wiring is two files, and skipping either half fails quietly: - ci/ci.sh gets FROST_ENROLLMENT in the reproduction header's variable list and --enable-module-frost-enrollment="$FROST_ENROLLMENT" after the prefractal line. - .github/workflows/ci.yml gets FROST_ENROLLMENT at every PREFRACTAL site: the global default, 11 inline matrix entries and 10 job-level env blocks. Without the default, ci.sh runs under set -eux with an empty $FROST_ENROLLMENT, passes --enable-module-frost-enrollment="", `test x"" = x"yes"` is false, and the module is off in all of CI while ci.sh visibly has the plumbing. Verified programmatically over the parsed workflow: across the 106 effective job contexts, PREFRACTAL and FROST_ENROLLMENT now agree in every single one (45 set to yes, no mismatches), no context sets FROST_ENROLLMENT without FROST or without EXPERIMENTAL, and no context leaves it undefined. ci.sh passes sh -n. The stub test is not a placeholder that has to be deleted later: every entry point must reject an empty helper set and leave its output zeroed, which is true of the stubs and stays true of the finished implementation, so it doubles as the check that all five symbols are reachable from the test binary. Verification. Autotools: ./autogen.sh, then a frost-enrollment-only configure and a full configure with frost, chilldkg, iceberg, prefractal and frost-enrollment all on -- both build with zero warnings under the project's -Werror-grade flag set, ./tests and ./exhaustive_tests exit 0, and `./tests -l` lists the frost_enrollment module. CMake: configure with -DSECP256K1_EXPERIMENTAL=ON -DSECP256K1_ENABLE_MODULE_FROST_ENROLLMENT=ON builds clean and ctest passes 391 tests. nm shows the five new symbols exported from libsecp256k1.so; tools/symbol-check.py could not be run here because python3-lief is not installed in this environment, but all five carry the required secp256k1_ prefix. make dist succeeds and the tarball carries src/modules/frost_enrollment/frost_enrollment.md alongside the other module documents. One unrelated observation from this build: a stale src/ctime_tests-ctime_tests.o left over from an earlier configure with a different module set will fail to link, because automake does not track CPPFLAGS changes across reconfigures. make clean between configurations with different module sets, not a fault in this change. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -31,6 +31,13 @@ typedef struct {
|
||||
int g_times_gacc_parity;
|
||||
} secp256k1_frost_session_internal;
|
||||
|
||||
/* Sorts n_ids identifiers from ids into out (which must have room for
|
||||
* n_ids entries and must not alias ids) in ascending order. Used to
|
||||
* canonicalize a signer set before hashing it, so that parties holding the
|
||||
* same set in different orders agree on the digest. Requires n_ids <=
|
||||
* SECP256K1_FROST_MAX_PARTICIPANTS. */
|
||||
static void secp256k1_frost_sort_ids(uint32_t *out, const uint32_t *ids, size_t n_ids);
|
||||
|
||||
/* Saves the two secret scalars k[0], k[1] into a secnonce. */
|
||||
static void secp256k1_frost_secnonce_save(secp256k1_frost_secnonce *secnonce, const secp256k1_scalar *k);
|
||||
|
||||
|
||||
4
src/modules/frost_enrollment/Makefile.am.include
Normal file
4
src/modules/frost_enrollment/Makefile.am.include
Normal file
@@ -0,0 +1,4 @@
|
||||
include_HEADERS += include/secp256k1_frost_enrollment.h
|
||||
noinst_HEADERS += src/modules/frost_enrollment/main_impl.h
|
||||
noinst_HEADERS += src/modules/frost_enrollment/enrollment_impl.h
|
||||
noinst_HEADERS += src/modules/frost_enrollment/tests_impl.h
|
||||
105
src/modules/frost_enrollment/enrollment_impl.h
Normal file
105
src/modules/frost_enrollment/enrollment_impl.h
Normal file
@@ -0,0 +1,105 @@
|
||||
/***********************************************************************
|
||||
* Distributed under the MIT software license, see the accompanying *
|
||||
* file COPYING or https://www.opensource.org/licenses/mit-license.php.*
|
||||
***********************************************************************/
|
||||
|
||||
#ifndef SECP256K1_MODULE_FROST_ENROLLMENT_IMPL_H
|
||||
#define SECP256K1_MODULE_FROST_ENROLLMENT_IMPL_H
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "../../../include/secp256k1.h"
|
||||
#include "../../../include/secp256k1_frost_enrollment.h"
|
||||
|
||||
/* This module is compiled into the same translation unit as frost and is
|
||||
* included after it, so it may use frost's static internals. It adds nothing
|
||||
* to them: the Lagrange machinery, the identifier conventions and the id
|
||||
* canonicalization all come from there. */
|
||||
#include "../frost/keygen.h"
|
||||
#include "../frost/session.h"
|
||||
|
||||
#include "../../eckey.h"
|
||||
#include "../../group.h"
|
||||
#include "../../hash.h"
|
||||
#include "../../scalar.h"
|
||||
#include "../../util.h"
|
||||
|
||||
int secp256k1_frost_enrollment_params_hash(const secp256k1_context *ctx, unsigned char *out32, const secp256k1_pubkey *thresh_pk, const uint32_t *ids, size_t n_ids, uint32_t new_id, size_t n_participants, uint32_t threshold) {
|
||||
VERIFY_CHECK(ctx != NULL);
|
||||
ARG_CHECK(out32 != NULL);
|
||||
memset(out32, 0, 32);
|
||||
ARG_CHECK(thresh_pk != NULL);
|
||||
ARG_CHECK(ids != NULL);
|
||||
(void)n_ids;
|
||||
(void)new_id;
|
||||
(void)n_participants;
|
||||
(void)threshold;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int secp256k1_frost_enrollment_shares_gen(const secp256k1_context *ctx, unsigned char *shares32_out, unsigned char *params_hash32_out, unsigned char *session_secrand32, const unsigned char *secshare32, const secp256k1_pubkey *thresh_pk, const uint32_t *ids, size_t n_ids, uint32_t my_id, uint32_t new_id, size_t n_participants, uint32_t threshold) {
|
||||
VERIFY_CHECK(ctx != NULL);
|
||||
ARG_CHECK(shares32_out != NULL);
|
||||
ARG_CHECK(params_hash32_out != NULL);
|
||||
memset(params_hash32_out, 0, 32);
|
||||
ARG_CHECK(session_secrand32 != NULL);
|
||||
ARG_CHECK(secshare32 != NULL);
|
||||
ARG_CHECK(thresh_pk != NULL);
|
||||
ARG_CHECK(ids != NULL);
|
||||
(void)n_ids;
|
||||
(void)my_id;
|
||||
(void)new_id;
|
||||
(void)n_participants;
|
||||
(void)threshold;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int secp256k1_frost_enrollment_share_agg(const secp256k1_context *ctx, unsigned char *sigma32_out, uint32_t *mismatch_id, const unsigned char *all_shares32, const unsigned char *received_params_hashes32, const secp256k1_pubkey *thresh_pk, const uint32_t *ids, size_t n_ids, uint32_t my_id, uint32_t new_id, size_t n_participants, uint32_t threshold) {
|
||||
VERIFY_CHECK(ctx != NULL);
|
||||
ARG_CHECK(sigma32_out != NULL);
|
||||
memset(sigma32_out, 0, 32);
|
||||
if (mismatch_id != NULL) {
|
||||
*mismatch_id = UINT32_MAX;
|
||||
}
|
||||
ARG_CHECK(all_shares32 != NULL);
|
||||
ARG_CHECK(received_params_hashes32 != NULL);
|
||||
ARG_CHECK(thresh_pk != NULL);
|
||||
ARG_CHECK(ids != NULL);
|
||||
(void)n_ids;
|
||||
(void)my_id;
|
||||
(void)new_id;
|
||||
(void)n_participants;
|
||||
(void)threshold;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int secp256k1_frost_enrollment_pubshare_derive(const secp256k1_context *ctx, secp256k1_pubkey *new_pubshare_out, const secp256k1_pubkey *pubshares, const uint32_t *ids, size_t n_ids, uint32_t new_id, size_t n_participants, uint32_t threshold) {
|
||||
VERIFY_CHECK(ctx != NULL);
|
||||
ARG_CHECK(new_pubshare_out != NULL);
|
||||
memset(new_pubshare_out, 0, sizeof(*new_pubshare_out));
|
||||
ARG_CHECK(pubshares != NULL);
|
||||
ARG_CHECK(ids != NULL);
|
||||
(void)n_ids;
|
||||
(void)new_id;
|
||||
(void)n_participants;
|
||||
(void)threshold;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int secp256k1_frost_enrollment_secshare_gen(const secp256k1_context *ctx, unsigned char *secshare32_out, const unsigned char *sigmas32, const secp256k1_pubkey *thresh_pk, const uint32_t *ids, size_t n_ids, uint32_t new_id, size_t n_participants, uint32_t threshold, const unsigned char *expected_params_hash32, const secp256k1_pubkey *expected_pubshare) {
|
||||
VERIFY_CHECK(ctx != NULL);
|
||||
ARG_CHECK(secshare32_out != NULL);
|
||||
memset(secshare32_out, 0, 32);
|
||||
ARG_CHECK(sigmas32 != NULL);
|
||||
ARG_CHECK(thresh_pk != NULL);
|
||||
ARG_CHECK(ids != NULL);
|
||||
(void)n_ids;
|
||||
(void)new_id;
|
||||
(void)n_participants;
|
||||
(void)threshold;
|
||||
(void)expected_params_hash32;
|
||||
(void)expected_pubshare;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
14
src/modules/frost_enrollment/main_impl.h
Normal file
14
src/modules/frost_enrollment/main_impl.h
Normal file
@@ -0,0 +1,14 @@
|
||||
/***********************************************************************
|
||||
* Distributed under the MIT software license, see the accompanying *
|
||||
* file COPYING or https://www.opensource.org/licenses/mit-license.php.*
|
||||
***********************************************************************/
|
||||
|
||||
#ifndef SECP256K1_MODULE_FROST_ENROLLMENT_MAIN_H
|
||||
#define SECP256K1_MODULE_FROST_ENROLLMENT_MAIN_H
|
||||
|
||||
/* One layer only. Enrollment is three rounds of scalar arithmetic over key
|
||||
* material the frost module already knows how to load and save, so there is
|
||||
* no keygen, no serialization and no state of its own here. */
|
||||
#include "enrollment_impl.h"
|
||||
|
||||
#endif
|
||||
52
src/modules/frost_enrollment/tests_impl.h
Normal file
52
src/modules/frost_enrollment/tests_impl.h
Normal file
@@ -0,0 +1,52 @@
|
||||
/***********************************************************************
|
||||
* Distributed under the MIT software license, see the accompanying *
|
||||
* file COPYING or https://www.opensource.org/licenses/mit-license.php.*
|
||||
***********************************************************************/
|
||||
|
||||
#ifndef SECP256K1_MODULE_FROST_ENROLLMENT_TESTS_IMPL_H
|
||||
#define SECP256K1_MODULE_FROST_ENROLLMENT_TESTS_IMPL_H
|
||||
|
||||
#include "../../../include/secp256k1_frost_enrollment.h"
|
||||
|
||||
/* Every entry point must reject an empty helper set and leave its output
|
||||
* zeroed. This holds for the stubs this commit adds and for the finished
|
||||
* implementation alike, so it doubles as the check that all five symbols are
|
||||
* reachable from the test binary. */
|
||||
static void run_frost_enrollment_rejects_empty_set_test(void) {
|
||||
secp256k1_pubkey pk;
|
||||
secp256k1_pubkey pubshare;
|
||||
unsigned char buf32[32];
|
||||
unsigned char secrand32[32];
|
||||
unsigned char hash32[32];
|
||||
uint32_t ids[1] = { 0 };
|
||||
|
||||
memset(&pk, 0, sizeof(pk));
|
||||
memset(&pubshare, 0xff, sizeof(pubshare));
|
||||
memset(secrand32, 0x11, sizeof(secrand32));
|
||||
|
||||
memset(buf32, 0xff, sizeof(buf32));
|
||||
CHECK(secp256k1_frost_enrollment_params_hash(CTX, buf32, &pk, ids, 0, 0, 1, 2) == 0);
|
||||
CHECK(secp256k1_is_zero_array(buf32, sizeof(buf32)));
|
||||
|
||||
memset(buf32, 0xff, sizeof(buf32));
|
||||
memset(hash32, 0xff, sizeof(hash32));
|
||||
CHECK(secp256k1_frost_enrollment_shares_gen(CTX, buf32, hash32, secrand32, buf32, &pk, ids, 0, 0, 1, 1, 2) == 0);
|
||||
CHECK(secp256k1_is_zero_array(hash32, sizeof(hash32)));
|
||||
|
||||
memset(buf32, 0xff, sizeof(buf32));
|
||||
CHECK(secp256k1_frost_enrollment_share_agg(CTX, buf32, NULL, buf32, hash32, &pk, ids, 0, 0, 1, 1, 2) == 0);
|
||||
CHECK(secp256k1_is_zero_array(buf32, sizeof(buf32)));
|
||||
|
||||
CHECK(secp256k1_frost_enrollment_pubshare_derive(CTX, &pubshare, &pk, ids, 0, 0, 1, 2) == 0);
|
||||
CHECK(secp256k1_is_zero_array((unsigned char *)&pubshare, sizeof(pubshare)));
|
||||
|
||||
memset(buf32, 0xff, sizeof(buf32));
|
||||
CHECK(secp256k1_frost_enrollment_secshare_gen(CTX, buf32, buf32, &pk, ids, 0, 0, 1, 2, NULL, NULL) == 0);
|
||||
CHECK(secp256k1_is_zero_array(buf32, sizeof(buf32)));
|
||||
}
|
||||
|
||||
static const struct tf_test_entry tests_frost_enrollment[] = {
|
||||
CASE1(run_frost_enrollment_rejects_empty_set_test),
|
||||
};
|
||||
|
||||
#endif /* SECP256K1_MODULE_FROST_ENROLLMENT_TESTS_IMPL_H */
|
||||
Reference in New Issue
Block a user