frost_enrollment: verify shares with VSS commitments
This commit is contained in:
1 parent
49272f1b2f
commit
45adcaf540
3 files changed
+175
No files matched your search
@@ -343,6 +343,36 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_frost_enrollment_pubsha
|
||||
uint32_t threshold
|
||||
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4);
|
||||
|
||||
/** Derive a public share from an aggregate VSS commitment polynomial.
|
||||
*
|
||||
* commitments33 contains threshold 33-byte commitments C[0], ..., C[t-1] in
|
||||
* ascending coefficient order, where C[k] commits to the coefficient of x^k
|
||||
* in the group's joint polynomial. n_commitments is the threshold t and must
|
||||
* be at least 2. Each entry uses compressed encoding, except that 33 zero
|
||||
* bytes represent the point at infinity for a zero coefficient.
|
||||
*
|
||||
* Computes sum_k (new_id+1)^k*C[k], checks that C[0] equals thresh_pk, and
|
||||
* rejects an infinity result. Both enrollment (new_id == n_participants) and
|
||||
* repair (new_id < n_participants) follow the same bounds as pubshare_derive.
|
||||
*
|
||||
* AUTHENTICATION: this arithmetic does not authenticate the commitments.
|
||||
* thresh_pk and commitments33 must come from group state authenticated
|
||||
* independently of the enrollment helpers. Otherwise colluding helpers can
|
||||
* supply a different polynomial with the same constant-term commitment.
|
||||
*
|
||||
* Returns: 0 if the arguments, encodings, constant commitment or result are
|
||||
* invalid, 1 otherwise. new_pubshare_out is zeroed on failure.
|
||||
*/
|
||||
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_frost_enrollment_pubshare_derive_from_commitments(
|
||||
const secp256k1_context *ctx,
|
||||
secp256k1_pubkey *new_pubshare_out,
|
||||
const secp256k1_pubkey *thresh_pk,
|
||||
const unsigned char *commitments33,
|
||||
size_t n_commitments,
|
||||
uint32_t new_id,
|
||||
size_t n_participants
|
||||
) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4);
|
||||
|
||||
/** Round 2: derive the target participant's secret share.
|
||||
*
|
||||
* In order:
|
||||
@@ -520,6 +550,13 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_frost_enrollment_reduce
|
||||
* thresh_pk and the data used to derive expected_pubshare MUST be
|
||||
* authenticated independently of the helpers' enrollment messages. Otherwise
|
||||
* colluding helpers can provide a consistent fabricated polynomial.
|
||||
*
|
||||
* After a successful enrollment, every participant must append the same
|
||||
* expected_pubshare to its public-share table and update n_participants to
|
||||
* n_participants+1. Validate the extended table with
|
||||
* secp256k1_frost_threshold_info_validate before using it for signing. Repair
|
||||
* leaves the table and n_participants unchanged. Transport, consensus and
|
||||
* atomic persistent state updates remain caller responsibilities.
|
||||
*/
|
||||
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_frost_enrollment_reduced_secshare_gen(
|
||||
const secp256k1_context *ctx,
|
||||
|
||||
@@ -605,6 +605,76 @@ int secp256k1_frost_enrollment_pubshare_derive(const secp256k1_context *ctx, sec
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int secp256k1_frost_enrollment_commitment_load(secp256k1_ge *out, const unsigned char *in33) {
|
||||
static const unsigned char zeros33[33] = { 0 };
|
||||
|
||||
if (secp256k1_memcmp_var(in33, zeros33, 33) == 0) {
|
||||
secp256k1_ge_set_infinity(out);
|
||||
return 1;
|
||||
}
|
||||
return secp256k1_eckey_pubkey_parse(out, in33, 33);
|
||||
}
|
||||
|
||||
int secp256k1_frost_enrollment_pubshare_derive_from_commitments(const secp256k1_context *ctx, secp256k1_pubkey *new_pubshare_out, const secp256k1_pubkey *thresh_pk, const unsigned char *commitments33, size_t n_commitments, uint32_t new_id, size_t n_participants) {
|
||||
secp256k1_ge expected_pk, result;
|
||||
secp256k1_gej resultj;
|
||||
secp256k1_scalar x, power;
|
||||
size_t j;
|
||||
int ret = 0;
|
||||
|
||||
VERIFY_CHECK(ctx != NULL);
|
||||
ARG_CHECK(new_pubshare_out != NULL);
|
||||
memset(new_pubshare_out, 0, sizeof(*new_pubshare_out));
|
||||
ARG_CHECK(thresh_pk != NULL);
|
||||
ARG_CHECK(commitments33 != NULL);
|
||||
|
||||
if (n_participants < 1 || n_participants > SECP256K1_FROST_MAX_PARTICIPANTS
|
||||
|| n_commitments < 2 || n_commitments > n_participants
|
||||
|| (size_t)new_id > n_participants
|
||||
|| ((size_t)new_id == n_participants && n_participants >= SECP256K1_FROST_MAX_PARTICIPANTS)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
secp256k1_scalar_set_int(&x, new_id);
|
||||
secp256k1_scalar_add(&x, &x, &secp256k1_scalar_one);
|
||||
secp256k1_scalar_set_int(&power, 1);
|
||||
secp256k1_gej_set_infinity(&resultj);
|
||||
|
||||
if (!secp256k1_pubkey_load(ctx, &expected_pk, thresh_pk)) {
|
||||
goto cleanup;
|
||||
}
|
||||
for (j = 0; j < n_commitments; j++) {
|
||||
secp256k1_ge com;
|
||||
|
||||
if (!secp256k1_frost_enrollment_commitment_load(&com, &commitments33[33 * j])) {
|
||||
goto cleanup;
|
||||
}
|
||||
if (j == 0) {
|
||||
if (secp256k1_ge_is_infinity(&com) || !secp256k1_ge_eq_var(&com, &expected_pk)) {
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
if (!secp256k1_ge_is_infinity(&com)) {
|
||||
secp256k1_gej term;
|
||||
secp256k1_gej_set_ge(&term, &com);
|
||||
secp256k1_ecmult(&term, &term, &power, NULL);
|
||||
secp256k1_gej_add_var(&resultj, &resultj, &term, NULL);
|
||||
}
|
||||
secp256k1_scalar_mul(&power, &power, &x);
|
||||
}
|
||||
if (secp256k1_gej_is_infinity(&resultj)) {
|
||||
goto cleanup;
|
||||
}
|
||||
secp256k1_ge_set_gej_var(&result, &resultj);
|
||||
secp256k1_pubkey_save(new_pubshare_out, &result);
|
||||
ret = 1;
|
||||
|
||||
cleanup:
|
||||
secp256k1_scalar_clear(&x);
|
||||
secp256k1_scalar_clear(&power);
|
||||
return ret;
|
||||
}
|
||||
|
||||
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) {
|
||||
secp256k1_scalar secshare, term;
|
||||
unsigned char params_hash32[32];
|
||||
|
||||
@@ -119,6 +119,31 @@ static void frost_enrollment_test_helper_pubshares(const frost_enrollment_test_r
|
||||
}
|
||||
}
|
||||
|
||||
/* Serializes the trusted dealer's polynomial as an aggregate VSS commitment,
|
||||
* in ascending coefficient order and with the constant commitment first. */
|
||||
static void frost_enrollment_test_commitments(const frost_enrollment_test_run *r, unsigned char *out33) {
|
||||
secp256k1_scalar coeff;
|
||||
size_t k;
|
||||
|
||||
for (k = 0; k < r->t; k++) {
|
||||
secp256k1_gej comj;
|
||||
secp256k1_ge com;
|
||||
|
||||
if (k == 0) {
|
||||
CHECK(secp256k1_scalar_set_b32_seckey(&coeff, r->thresh_sk) == 1);
|
||||
} else {
|
||||
CHECK(secp256k1_frost_derive_coefficient(secp256k1_get_hash_context(CTX), &coeff, r->thresh_sk, (uint32_t)(r->t - k)) == 1);
|
||||
}
|
||||
secp256k1_ecmult_gen_gej(&CTX->ecmult_gen_ctx, &comj, &coeff);
|
||||
secp256k1_ge_set_gej(&com, &comj);
|
||||
CHECK(!secp256k1_ge_is_infinity(&com));
|
||||
secp256k1_eckey_pubkey_serialize33(&com, &out33[33 * k]);
|
||||
secp256k1_ge_clear(&com);
|
||||
secp256k1_gej_clear(&comj);
|
||||
}
|
||||
secp256k1_scalar_clear(&coeff);
|
||||
}
|
||||
|
||||
/* Runs round 2, with both optional checks enabled. */
|
||||
static void frost_enrollment_test_round2(frost_enrollment_test_run *r) {
|
||||
secp256k1_pubkey helper_pubshares[SECP256K1_FROST_MAX_PARTICIPANTS];
|
||||
@@ -365,6 +390,48 @@ static void run_frost_enrollment_reduced_roundtrip_test(void) {
|
||||
CHECK(secp256k1_memcmp_var(&reduced.new_pubshare, &reduced.pubshares[1], sizeof(reduced.new_pubshare)) == 0);
|
||||
}
|
||||
|
||||
static void run_frost_enrollment_reduced_commitments_test(void) {
|
||||
static frost_enrollment_test_run r;
|
||||
unsigned char commitments[SECP256K1_FROST_MAX_PARTICIPANTS * 33];
|
||||
unsigned char saved[33];
|
||||
unsigned char out[32];
|
||||
secp256k1_pubkey derived;
|
||||
|
||||
frost_enrollment_test_reduced_full_run(&r, 4, 3, 3, 4);
|
||||
frost_enrollment_test_commitments(&r, commitments);
|
||||
CHECK(secp256k1_frost_enrollment_pubshare_derive_from_commitments(CTX, &derived, &r.thresh_pk, commitments, r.t, r.new_id, r.n) == 1);
|
||||
CHECK(secp256k1_memcmp_var(&derived, &r.new_pubshare, sizeof(derived)) == 0);
|
||||
CHECK(secp256k1_frost_enrollment_reduced_secshare_gen(CTX, out, r.sigmas, &r.params_hashes[0][0], &r.thresh_pk, r.ids, r.u, r.new_id, r.n, (uint32_t)r.t, r.session_id, &derived) == 1);
|
||||
CHECK(secp256k1_memcmp_var(out, r.new_secshare, 32) == 0);
|
||||
|
||||
/* A different valid nonconstant commitment produces a different expected
|
||||
* public share, against which the actual secret share does not verify. */
|
||||
memcpy(saved, &commitments[33], 33);
|
||||
commitments[33] ^= 1;
|
||||
CHECK(secp256k1_frost_enrollment_pubshare_derive_from_commitments(CTX, &derived, &r.thresh_pk, commitments, r.t, r.new_id, r.n) == 1);
|
||||
CHECK(secp256k1_memcmp_var(&derived, &r.new_pubshare, sizeof(derived)) != 0);
|
||||
memset(out, 0xff, sizeof(out));
|
||||
CHECK(secp256k1_frost_enrollment_reduced_secshare_gen(CTX, out, r.sigmas, &r.params_hashes[0][0], &r.thresh_pk, r.ids, r.u, r.new_id, r.n, (uint32_t)r.t, r.session_id, &derived) == 0);
|
||||
CHECK(secp256k1_is_zero_array(out, sizeof(out)));
|
||||
|
||||
/* Infinity is a valid nonconstant coefficient commitment. */
|
||||
memset(&commitments[33], 0, 33);
|
||||
CHECK(secp256k1_frost_enrollment_pubshare_derive_from_commitments(CTX, &derived, &r.thresh_pk, commitments, r.t, r.new_id, r.n) == 1);
|
||||
CHECK(secp256k1_memcmp_var(&derived, &r.new_pubshare, sizeof(derived)) != 0);
|
||||
memcpy(&commitments[33], saved, 33);
|
||||
|
||||
/* The constant commitment must match the authenticated group key. */
|
||||
commitments[0] ^= 1;
|
||||
memset(&derived, 0xff, sizeof(derived));
|
||||
CHECK(secp256k1_frost_enrollment_pubshare_derive_from_commitments(CTX, &derived, &r.thresh_pk, commitments, r.t, r.new_id, r.n) == 0);
|
||||
CHECK(secp256k1_is_zero_array((unsigned char *)&derived, sizeof(derived)));
|
||||
commitments[0] ^= 1;
|
||||
|
||||
/* A nonzero entry with an invalid prefix is not the infinity encoding. */
|
||||
commitments[33] = 0;
|
||||
CHECK(secp256k1_frost_enrollment_pubshare_derive_from_commitments(CTX, &derived, &r.thresh_pk, commitments, r.t, r.new_id, r.n) == 0);
|
||||
}
|
||||
|
||||
/* Repair mode: participant 1 "loses" its share and the same protocol run at
|
||||
* new_id = 1 reproduces it, byte for byte. The share is f(x_1), a fixed value,
|
||||
* not a fresh random one, so anything short of exact equality is a bug. */
|
||||
@@ -1268,6 +1335,7 @@ static const struct tf_test_entry tests_frost_enrollment[] = {
|
||||
CASE1(run_frost_enrollment_reconstruction_test),
|
||||
CASE1(run_frost_enrollment_signing_test),
|
||||
CASE1(run_frost_enrollment_reduced_roundtrip_test),
|
||||
CASE1(run_frost_enrollment_reduced_commitments_test),
|
||||
CASE1(run_frost_enrollment_repair_test),
|
||||
CASE1(run_frost_enrollment_oversized_set_test),
|
||||
CASE1(run_frost_enrollment_fault_injection_test),
|
||||
|
||||
Reference in new issue
Block a user