Merge bitcoin-core/secp256k1#1974: silentpayments: reject label tweaks that overflow the group order
What changed, and why it matters
This change fixes a silent handling problem in Bitcoin's silent payments feature. When a user-supplied label tweak value was larger than the cryptographic group order, the code previously reduced it silently, which could lead to incorrect payment scanning results. Now the code rejects such oversized values as API misuse. This is a defensive correctness fix rather than an active remote exploit.
Merge the patch. It is a low-risk defensive fix that improves API contract enforcement and prevents silent incorrect behavior from malformed caller label caches. No immediate incident response is warranted unless callers were relying on the previous silent reduction behavior, which should be considered a bug.
Security signals we found
silent modular reduction of attacker/caller-controlled scalar
API misuse now rejected via ARG_CHECK
sensitive scalar clearing before early return to avoid leaking transaction indistinguishability data
silent payments output matching correctness
Evidence from the diff
In secp256k1’s silentpayments module, the label_lookup callback returns a 32-byte label tweak. Previously secp256k1_silentpayments_recipient_scan_outputs called secp256k1_scalar_set_b32 with the overflow flag ignored, so tweaks >= the curve order were silently reduced modulo n. This could cause the wrong output to be matched or missed during scanning. The patch captures the overflow flag, clears sensitive intermediate scalars and the shared secret before the ARG_CHECK, and rejects the call with ARG_CHECK (illegal callback, return 0). A test is added that feeds secp256k1_group_order_bytes as the tweak and verifies CHECK_ILLEGAL.
Changed components
src/modules/silentpayments/main_impl.hsecp256k1_silentpayments_recipient_scan_outputssilentpayments label_lookup callback handlingInspect captured patch +13 / −2
### src/modules/silentpayments/main_impl.h
@@ -755,14 +755,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);
@@ -771,6 +778,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
@@ -608,6 +608,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 35/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.