silentpayments: return 0 instead of `ARG_CHECK`ing for empty inputs/outputs
What changed, and why it matters
This change fixes two functions in the Silent Payments module so they return a normal failure value (0) instead of triggering an internal abort when given a transaction with no eligible inputs or no taproot outputs. Previously, callers scanning many transactions could have their program crash if they passed such a transaction to these functions. The patch aligns behavior with the documented API and prevents denial-of-service crashes in normal scanning workflows.
Upgrade to a release containing this commit if you use the Silent Payments scanning API with untrusted transaction data. Until then, callers should pre-filter transactions to ensure at least one eligible input and one taproot output before invoking these functions, or install a non-aborting illegal callback.
Security signals we found
ARG_CHECK default behavior is abort(), turning an expected non-Silent-Payments transaction into a potential DoS crash
API contract promised return 0 for non-Silent-Payments transactions, but implementation violated it for empty input/output edge cases
Callers scanning blocks would need special-case handling before the fix to avoid crashes
No cryptographic weakness introduced; change is purely defensive API hardening
Evidence from the diff
secp256k1_silentpayments_recipient_prevouts_summary_create and secp256k1_silentpayments_recipient_scan_outputs used ARG_CHECK to reject n_pubkeys/n_xonly_pubkeys == 0 and n_tx_outputs == 0 respectively. ARG_CHECK calls the illegal-callback, which defaults to abort(). The API docs state these functions return 0 for non-Silent-Payments transactions. The patch removes the ARG_CHECK guards and lets the existing logic return 0 naturally (point-at-infinity sum for empty inputs, early return for zero outputs). Tests are updated to expect return 0 instead of CHECK_ILLEGAL.
Changed components
src/modules/silentpayments/main_impl.hinclude/secp256k1_silentpayments.hsrc/modules/silentpayments/tests_impl.hInspect captured patch +27 / −22
### include/secp256k1_silentpayments.h
@@ -261,7 +261,9 @@ typedef struct secp256k1_silentpayments_prevouts_summary {
* The resulting data can be used for scanning on the recipient side.
*
* Returns: 1 if prevouts summary creation was successful.
- * 0 if the transaction is not a Silent Payments transaction.
+ * 0 if the transaction is not a Silent Payments transaction, e.g.,
+ * if no public keys are passed (the transaction has no eligible
+ * inputs) or if the public keys sum to the point at infinity.
*
* Args: ctx: pointer to a context object
* Out: prevouts_summary: pointer to prevouts_summary object containing the
@@ -347,7 +349,8 @@ typedef struct secp256k1_silentpayments_found_output {
* key group than this limit.
*
* Returns: 1 if output scanning was successful.
- * 0 if the transaction is not a Silent Payments transaction,
+ * 0 if the transaction is not a Silent Payments transaction (e.g.,
+ * if it has no taproot outputs, i.e., n_tx_outputs is 0),
* or if the arguments are invalid.
*
* Args: ctx: pointer to a context object
### src/modules/silentpayments/main_impl.h
@@ -497,7 +497,6 @@ int secp256k1_silentpayments_recipient_prevouts_summary_create(
ARG_CHECK(prevouts_summary != NULL);
memset(prevouts_summary, 0, sizeof(*prevouts_summary));
ARG_CHECK(outpoint_smallest36 != NULL);
- ARG_CHECK((n_pubkeys > 0) || (n_xonly_pubkeys > 0));
if (n_xonly_pubkeys > 0) {
ARG_CHECK(xonly_pubkeys != NULL);
for (i = 0; i < n_xonly_pubkeys; i++) {
@@ -516,7 +515,8 @@ int secp256k1_silentpayments_recipient_prevouts_summary_create(
* Since an attacker can maliciously craft transactions where the public keys sum to zero, fail early here
* to avoid making the caller do extra work, e.g., when building an index or scanning a malicious transaction.
*
- * This will also fail if any of the provided prevout public keys are malformed.
+ * This will also fail if any of the provided prevout public keys are malformed, or if no public keys were
+ * provided at all (i.e., the transaction has no eligible inputs), as the sum is then the point at infinity.
*/
secp256k1_gej_set_infinity(&prevouts_pubkey_sum_gej);
for (i = 0; i < n_pubkeys; i++) {
@@ -615,7 +615,6 @@ int secp256k1_silentpayments_recipient_scan_outputs(
ARG_CHECK(n_found_outputs != NULL);
*n_found_outputs = 0;
ARG_CHECK(tx_outputs != NULL);
- ARG_CHECK(n_tx_outputs > 0);
for (i = 0; i < n_tx_outputs; i++) {
ARG_CHECK(found_outputs[i] != NULL);
ARG_CHECK(tx_outputs[i] != NULL);
@@ -632,6 +631,10 @@ int secp256k1_silentpayments_recipient_scan_outputs(
if (label_context != NULL) {
ARG_CHECK(label_lookup != NULL);
}
+ /* A transaction without any taproot outputs is not a Silent Payments transaction. */
+ if (n_tx_outputs == 0) {
+ return 0;
+ }
valid_scan_key = secp256k1_scalar_set_b32_seckey(&scan_key_scalar, scan_key32);
secp256k1_declassify(ctx, &valid_scan_key, sizeof(valid_scan_key));
if (!valid_scan_key) {
### src/modules/silentpayments/tests_impl.h
@@ -556,8 +556,10 @@ static void test_recipient_api(void) {
CHECK(secp256k1_silentpayments_recipient_prevouts_summary_create(CTX, &ps, SMALLEST_OUTPOINT, tp, 0, pp, 1));
CHECK(secp256k1_silentpayments_recipient_prevouts_summary_create(CTX, &ps, SMALLEST_OUTPOINT, tp, 1, NULL, 0));
CHECK(secp256k1_silentpayments_recipient_prevouts_summary_create(CTX, &ps, SMALLEST_OUTPOINT, tp, 1, pp, 0));
- CHECK_ILLEGAL(CTX, secp256k1_silentpayments_recipient_prevouts_summary_create(CTX, &ps, SMALLEST_OUTPOINT, NULL, 0, pp, 0));
- CHECK_ILLEGAL(CTX, secp256k1_silentpayments_recipient_prevouts_summary_create(CTX, &ps, SMALLEST_OUTPOINT, NULL, 0, NULL, 0));
+ /* A transaction without any eligible inputs is not a Silent Payments transaction (no illegal argument) */
+ CHECK(secp256k1_silentpayments_recipient_prevouts_summary_create(CTX, &ps, SMALLEST_OUTPOINT, NULL, 0, pp, 0) == 0);
+ CHECK(secp256k1_silentpayments_recipient_prevouts_summary_create(CTX, &ps, SMALLEST_OUTPOINT, tp, 0, pp, 0) == 0);
+ CHECK(secp256k1_silentpayments_recipient_prevouts_summary_create(CTX, &ps, SMALLEST_OUTPOINT, NULL, 0, NULL, 0) == 0);
CHECK(secp256k1_silentpayments_recipient_prevouts_summary_create(CTX, &ps, SMALLEST_OUTPOINT, tp, 1, pp, 1));
/* check the _recipient_scan_outputs cornercase where internal tweaking would fail;
@@ -634,8 +636,11 @@ static void test_recipient_api(void) {
CHECK_ILLEGAL(CTX, secp256k1_silentpayments_recipient_scan_outputs(CTX, fp, &n_f, tp, 1, NULL, &ps, &p, &label_lookup, &labels_cache));
CHECK_ILLEGAL(CTX, secp256k1_silentpayments_recipient_scan_outputs(CTX, fp, &n_f, tp, 1, ALICE_SECKEY, NULL, &p, &label_lookup, &labels_cache));
CHECK_ILLEGAL(CTX, secp256k1_silentpayments_recipient_scan_outputs(CTX, fp, &n_f, tp, 1, ALICE_SECKEY, &ps, NULL, &label_lookup, &labels_cache));
- CHECK_ILLEGAL(CTX, secp256k1_silentpayments_recipient_scan_outputs(CTX, fp, &n_f, tp, 0, ALICE_SECKEY, &ps, &p, &label_lookup, &labels_cache));
CHECK_ILLEGAL(CTX, secp256k1_silentpayments_recipient_scan_outputs(CTX, fp, &n_f, tp, 1, ALICE_SECKEY, &ps, &p, NULL, &labels_cache));
+ /* A transaction without any taproot outputs is not a Silent Payments transaction (no illegal argument) */
+ n_f = 1;
+ CHECK(secp256k1_silentpayments_recipient_scan_outputs(CTX, fp, &n_f, tp, 0, ALICE_SECKEY, &ps, &p, &label_lookup, &labels_cache) == 0);
+ CHECK(n_f == 0);
/* Check that malformed secret key, public keys, and prevouts_summary arguments are handled */
CHECK_ILLEGAL(CTX, secp256k1_silentpayments_recipient_scan_outputs(CTX, fp, &n_f, tp, 1, ALICE_SECKEY, &ps, &malformed_p, NULL, NULL));
@@ -876,20 +881,14 @@ void run_silentpayments_test_vector_receive(const struct bip352_test_vector *tes
CHECK(secp256k1_xonly_pubkey_parse(CTX, &xonly_pubkeys_objs[i], test->xonly_pubkeys[i]));
xonly_pubkeys[i] = &xonly_pubkeys_objs[i];
}
- {
- int32_t ecount = 0;
- secp256k1_context_set_illegal_callback(CTX, counting_callback_fn, &ecount);
- ret = secp256k1_silentpayments_recipient_prevouts_summary_create(CTX, &prevouts_summary,
- test->outpoint_smallest,
- test->num_taproot_inputs > 0 ? xonly_pubkeys : NULL, test->num_taproot_inputs,
- test->num_plain_inputs > 0 ? pubkeys : NULL, test->num_plain_inputs
- );
- secp256k1_context_set_illegal_callback(CTX, NULL, NULL);
- /* We expect exactly one ARG_CHECK if the number of input keys was 0. */
- CHECK(ecount == ((test->num_taproot_inputs + test->num_plain_inputs) == 0));
- }
- /* If we are unable to create the prevouts_summary object, e.g., the input public keys sum to
- * zero, check that the expected number of recipient outputs for this test case is zero
+ ret = secp256k1_silentpayments_recipient_prevouts_summary_create(CTX, &prevouts_summary,
+ test->outpoint_smallest,
+ xonly_pubkeys, test->num_taproot_inputs,
+ pubkeys, test->num_plain_inputs
+ );
+ /* If we are unable to create the prevouts_summary object, e.g., there are no eligible inputs or
+ * the input public keys sum to zero, check that the expected number of recipient outputs for
+ * this test case is zero
*/
if (!ret) {
CHECK(subtest->num_found_output_pubkeys == 0);Why this scored 60/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.