silentpayments: reject label tweaks that overflow the group order
What changed, and why it matters
This change tightens error handling in the silent payments scanning code. Previously, if a caller-supplied label tweak was as large as or larger than the elliptic curve group order, it was silently wrapped around (reduced modulo the order). Now the function rejects such tweaks and aborts scanning. The tweak value comes from a caller-provided callback/cache, not from untrusted network data, so this is treated as a caller bug rather than an externally exploitable vulnerability. The patch also ensures that if this rejection happens, sensitive intermediate values are cleared from memory and the output entry is not partially written.
Review callers' label cache construction and serialization to ensure they cannot produce group-order-or-larger tweaks; the library now aborts on such input. No immediate network-facing mitigation is required because the input originates from caller-controlled state, not untrusted data.
Security signals we found
silent reduction modulo group order replaced with explicit overflow rejection
sensitive scalars and shared secret explicitly cleared before aborting on invalid input
output assignment reordered to avoid partial state update on failure path
new test injects group-order tweak and verifies API misuse rejection
Evidence from the diff
In secp256k1_silentpayments_recipient_scan_outputs, label tweaks from the label_lookup callback were converted to a scalar with secp256k1_scalar_set_b32(…, NULL), ignoring overflow. Because valid label tweaks are always generated by secp256k1_silentpayments_recipient_label_create as scalars less than the group order, an overflowing tweak implies a corrupted or incorrectly constructed label cache. The patch captures the overflow flag, clears label_tweak_scalar, final_tweak_scalar, and shared_secret on overflow, then uses ARG_CHECK(!tweak_overflow) to abort. It also moves the found_outputs[k]->output assignment after the overflow check so the entry remains untouched on failure, and adds a test that sets the tweak equal to the group order and expects the call to be illegal.
Changed components
src/modules/silentpayments/main_impl.h: secp256k1_silentpayments_recipient_scan_outputssrc/modules/silentpayments/tests_impl.h: test_recipient_apiInspect captured patch +13 / −2
### src/modules/silentpayments/main_impl.h
@@ -750,14 +750,21 @@ int secp256k1_silentpayments_recipient_scan_outputs(
}
if (found_idx != -1) {
secp256k1_scalar final_tweak_scalar = t_k_scalar;
- found_outputs[k]->output = *tx_outputs[found_idx];
/* Clear the t_k_scalar since we no longer need it and leaking this value would
* break indistinguishability of the transaction. */
secp256k1_scalar_clear(&t_k_scalar);
if (label_tweak != NULL) {
+ int tweak_overflow;
secp256k1_scalar label_tweak_scalar;
+ secp256k1_scalar_set_b32(&label_tweak_scalar, label_tweak, &tweak_overflow);
+ if (tweak_overflow) {
+ /* Leaking these values would break indistinguishability of the transaction, so clear them. */
+ secp256k1_scalar_clear(&label_tweak_scalar);
+ secp256k1_scalar_clear(&final_tweak_scalar);
+ secp256k1_memclear_explicit(&shared_secret, sizeof(shared_secret));
+ }
+ ARG_CHECK(!tweak_overflow);
found_outputs[k]->found_with_label = 1;
- secp256k1_scalar_set_b32(&label_tweak_scalar, label_tweak, NULL);
secp256k1_scalar_add(&final_tweak_scalar, &final_tweak_scalar, &label_tweak_scalar);
secp256k1_scalar_clear(&label_tweak_scalar);
secp256k1_silentpayments_label_save(&found_outputs[k]->label, &label_ge);
@@ -766,6 +773,7 @@ int secp256k1_silentpayments_recipient_scan_outputs(
/* Set the label to an invalid value. */
memset(&found_outputs[k]->label, 0, sizeof(found_outputs[k]->label));
}
+ found_outputs[k]->output = *tx_outputs[found_idx];
secp256k1_scalar_get_b32(found_outputs[k]->tweak, &final_tweak_scalar);
secp256k1_scalar_clear(&final_tweak_scalar);
/* Reset everything for the next round of scanning. */
### src/modules/silentpayments/tests_impl.h
@@ -588,6 +588,9 @@ static void test_recipient_api(void) {
CHECK(secp256k1_silentpayments_recipient_label_serialize(CTX, found_label_ser, &fp[0]->label));
CHECK(secp256k1_memcmp_var(found_label_ser, labels_cache.entries[0].label, 33) == 0);
}
+ /* check that a label tweak overflowing the group order is rejected */
+ memcpy(labels_cache.entries[0].label_tweak, secp256k1_group_order_bytes, 32);
+ CHECK_ILLEGAL(CTX, secp256k1_silentpayments_recipient_scan_outputs(CTX, fp, &found, output_xonly_ptrs, 1, ALICE_SECKEY, &ps, &spk, &label_lookup, &labels_cache));
}
n_f = 0;Why this scored 31/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.