Merge bitcoin-core/secp256k1#1929: silentpayments: perform tweak addition with actual scalars
What changed, and why it matters
This change simplifies how Silent Payments scanning adds a small tweak value to a secret-derived value. It replaces a function meant for secret-key tweaking with plain scalar (modular number) addition. The old code had a special case that set the result to zero if the addition 'failed' (produced zero). The new code no longer does that, and it also no longer rejects malformed tweak values larger than the group order. The commit author treats these as user errors with no meaningful security difference, but the behavior does change subtly.
Review whether allowing zero tweak results and non-reduced label tweaks affects downstream spendability or wallet behavior. If the Silent Payments BIP expects reduced, non-zero tweaks in this path, add explicit validation and tests for the overflow and zero cases. Otherwise, document the new behavior and add regression tests covering label_tweak = 0, label_tweak = N, and label_tweak = -t_k_scalar mod N.
Security signals we found
Behavior change: zero-result tweak addition is no longer forced to zero; scalar addition allows zero
Behavior change: label tweaks >= group order N are no longer rejected by the secret-key API
Removal of defensive comment explaining failure modes of secret-key tweak addition
Author explicitly frames changes as user-error edge cases, not security fixes
No CVE, advisory, or vendor security disclosure language present in commit
Evidence from the diff
In secp256k1_silentpayments_recipient_scan_outputs, the patch removes secp256k1_ec_seckey_tweak_add and its fallback-to-zero behavior, replacing it with secp256k1_scalar_add over final_tweak_scalar and label_tweak_scalar. secp256k1_ec_seckey_tweak_add rejects a zero result and treats it as failure; scalar_add accepts zero. Additionally, scalar_set_b32 with NULL overflow flag no longer rejects label tweaks >= N, whereas the previous secret-key path would have rejected malformed 32-byte inputs. The author notes this as an acceptable user-error edge case. The diff is a refactor with a documented, subtle behavior change rather than a clear vulnerability fix.
Changed components
src/modules/silentpayments/main_impl.hsecp256k1_silentpayments_recipient_scan_outputsInspect captured patch +7 / −16
### src/modules/silentpayments/main_impl.h
@@ -749,34 +749,25 @@ 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];
- secp256k1_scalar_get_b32(found_outputs[k]->tweak, &t_k_scalar);
/* 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) {
+ secp256k1_scalar label_tweak_scalar;
found_outputs[k]->found_with_label = 1;
- /* This is extremely unlikely to fail in that it can only really happen if label_tweak
- * is the negation of the shared secret tweak. But since both tweak and label_tweak are
- * created by hashing data, practically speaking this would only happen if an attacker
- * tricked us into using a particular label_tweak (deviating from the protocol).
- * Note that this call could also fail due to a malformed label_tweak data from the
- * label cache, but we generally assume the passed in data is created using the API
- * functions and thus have already been checked for correctness.
- *
- * Furthermore, although technically a failure for ec_seckey_tweak_add, this is not treated
- * as a failure for Silent Payments because the output is still spendable with just the
- * spend secret key. We set `tweak = 0` for this case.
- */
- if (!secp256k1_ec_seckey_tweak_add(ctx, found_outputs[k]->tweak, label_tweak)) {
- memset(found_outputs[k]->tweak, 0, 32);
- }
+ 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);
} else {
found_outputs[k]->found_with_label = 0;
/* Set the label to an invalid value. */
memset(&found_outputs[k]->label, 0, sizeof(found_outputs[k]->label));
}
+ 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. */
label_tweak = NULL;
} else {Why this scored 26/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.