surjectionproof: make sure that n_used_pubkeys > 0 in generate

If the proof was generated with surjectionproof_initialize (as mandated by the
API docs), then n_used_pubkeys can never be 0. Without this commit, compilers
will (rightfully) warn that borromean_s[ring_input_index] is not initialized in
surjectionproof_generate. Therefore, this commit makes sure that n_used_pubkeys
is greater than 0 which ensures that the array is initialized at
ring_input_index.
This commit is contained in:
Jonas Nick
2022-08-09 20:05:42 +00:00
parent 4fd7e1eabd
commit 5ac8fb035e
2 changed files with 27 additions and 9 deletions

View File

@@ -298,6 +298,10 @@ int secp256k1_surjectionproof_generate(const secp256k1_context* ctx, secp256k1_s
CHECK(proof->initialized == 1);
#endif
n_used_pubkeys = secp256k1_surjectionproof_n_used_inputs(ctx, proof);
/* This must be true if the proof was created with surjectionproof_initialize */
ARG_CHECK(n_used_pubkeys > 0);
/* Compute secret key */
secp256k1_scalar_set_b32(&tmps, input_blinding_key, &overflow);
if (overflow) {
@@ -321,7 +325,7 @@ int secp256k1_surjectionproof_generate(const secp256k1_context* ctx, secp256k1_s
/* Compute public keys */
n_total_pubkeys = secp256k1_surjectionproof_n_total_inputs(ctx, proof);
n_used_pubkeys = secp256k1_surjectionproof_n_used_inputs(ctx, proof);
if (n_used_pubkeys > n_total_pubkeys || n_total_pubkeys != n_ephemeral_input_tags) {
return 0;
}