silentpayments: document rule for recipients sharing a scan pubkey #1990

pull theStack wants to merge 1 commits into bitcoin-core:master from theStack:sp-shared_scan_pubkey-same-owner-req3 changing 1 files +39 −1
  1. theStack commented at 5:12 PM on November 5, 2026: contributor

    Background: An adversary can create a fake SP address reusing another owner's scan public key. If such an address is batched together with that owner's address, the owner's output may be ordered after the adversary's (resulting in an output with a k value > 0) and is then not found by the BIP352 scanning algorithm. This PR adds an API doc comment on the SP sending function to raise awareness of this issue.

    Independently of Silent Payments, the general observation that it's the senders responsibility to ensure the recipient addresses belong to the owner seems trivial; if a recipient doesn't control the keys behind the provided address, the payment obviously fails. The crucial difference in the BIP-352 scenario with shared scan public keys is that the presence of incorrect recipient addresses could make payments to correct recipient addresses unfindable for the owner (not unspendable though), so this is worth to point out explicitly.

    Note that the issue only exists if the incorrect addresses have a lower k value than the correct ones, so we could e.g. recommend to to put all recipients that are known to be correct in an earlier recipient position, but that might be a level of detail that is creating even more confusion. At the moment the SP ecosystem seems to be far away from multi-party sending, so it seems reasonable to give a conservative recommendation and possibly re-evaluate that at a later point.

    A very restrictive alternative could be to limit the group size to 1 (i.e. effectively only ever creating k=0 outputs) to be on the safe side, but this suggestion didn't have consensus for the BIP-352 authors, and I don't think the libsecp256k1 implementation should be more restrictive than the BIP. An in-between solution could be to e.g. introduce a "dangerous" flag parameter that has to be set to allow group sizes of > 1, or introduce a safer variant of _sender_create_outputs with that limitation, but I'm not sure if it's worth it to extend/change the API at this point.

    See also Ruben's write-up for a more detailed description of the problem and potential future mitigations. The various AI scanner findings are included as a comment below there for additional context.

    Thanks to l0rinc for first finding this issue (PRed in Bitcoin Red Team's bitcoin-security-council/secp256k1 repository on Sep. 19th). Similar vulnerability reports were later submitted by the Anthropic OSS scanner (Oct. 16th) and Project Loupe (Oct. 29th).

  2. theStack commented at 5:13 PM on November 5, 2026: contributor
  3. theStack added this to the milestone 0.8.1 on Nov 5, 2026
  4. theStack added the label user-documentation on Nov 5, 2026
  5. RubenSomsen commented at 9:52 PM on November 5, 2026: none

    Looks good to me. It matches the conclusion I landed on after my write-up exploring the possible ways of dealing with this particular case.

  6. Yudis-bit commented at 3:06 AM on November 7, 2026: contributor

    If this cannot be established, the recipients in question should instead be paid in separate transactions.

    recipient_sort_cmp already falls back to r->index on identical scan keys, and secondary sorting on spend keys would be unnecessary since grinding an earlier spend key takes only two curve multiplications. Enforcing uniqueness inside _sender_create_outputs would break legitimate labeled batching, while relaxing the receiver's early-break invariant degrades mobile scanning from O(1) to O(outputs) scalar multiplications per transaction. Documenting the caller contract keeps policy outside the C library.

    ACK 9a80949cb.

  7. fametrano commented at 12:38 AM on November 11, 2026: contributor

    ACK 9a80949cbab56d0d2023791b0144d4865ef0887e

    The description weighs recommending that recipients known to be correct go first, and leaves it out. For PSBT senders that advice would not hold, so the doc is right without it.

    Here k within a scan-key group follows the caller's index. BIP375 orders the group by spend key, then output index ("sort the codes lexicographically in ascending order to determine the ordering of the k value"), so a PSBT sender cannot choose who gets k=0: an address reusing the scan key with a lower spend key takes it wherever its output sits. Separate transactions work in both flows.

    Measured at this head with two spend keys indexed against spend-key order, against btclib-wallet's BIP375 derivation: the k values swap, and match once index follows spend-key order (details).

  8. real-or-random commented at 9:30 PM on November 20, 2026: contributor

    Concept ACK on changing the docs as a short term solution but Approach NACK

    I don't think the new paragraph gives the caller a requirement it can act on. It asks the caller to ensure that each scan/spend public key pair "actually belongs to the intended recipient". In the attack, the address with the copied scan key passes every check available to a sender: the attacker provided the address, and the attacker is the party that the sender intends to pay with that output. The address is harmful because the owner of the scan key does not scan for its spend key, and a sender cannot determine that from the two public keys.

    I suggest the following text instead. It states the condition under which the outputs are found, and a rule that the caller can check:

     *  Recipient objects that share a scan public key form a group. The owner of
     *  the scan key is guaranteed to find the outputs for a group only if it
     *  scans for the spend public key of every recipient object in the group,
     *  i.e., if each of them is its unlabeled spend public key or one of its
     *  labeled spend public keys. The caller cannot determine this from the
     *  public keys. A third party can exploit this by providing a recipient that
     *  combines the scan public key of another recipient (or of the caller) with
     *  a spend public key of its own. If such a recipient is passed in the same
     *  call, the outputs for the other recipients in the group may be unfindable
     *  by the owner of the scan key.
     *
     *  Therefore, recipient objects with the same scan public key and different
     *  spend public keys MUST NOT be passed in the same call, unless one of the
     *  following holds:
     *    - The caller obtained all of them from the same party. A wrong spend
     *      public key then affects only payments that this party requested.
     *    - The scan public key is the caller's own (e.g., because the group
     *      contains the caller's change), and the caller has checked that every
     *      spend public key in the group is its own unlabeled spend public key
     *      or one of its own labeled spend public keys.
     *  Recipient objects with the same scan public key and the same spend public
     *  key can always be passed in the same call. Public keys can be compared
     *  with `secp256k1_ec_pubkey_cmp`.
     *
     *  Recipients that cannot be passed in the same call need to be paid in
     *  separate transactions. This can be harmful to privacy: a party that
     *  provides a recipient and observes that it is treated differently learns
     *  that the caller is paying another recipient with the same scan public
     *  key. A caller that never passes recipients obtained from different
     *  parties in the same call avoids this.
    

    and for the recipients parameter:

     *                            if they carry different indices (but see above
     *                            for recipient objects that share a scan public
     *                            key).
    

    Some remarks on this text:

    The two exceptions. These are the cases in which a sender can establish the condition. The second one needs to be explicit because the victim is then the sender itself. BIP352 creates change by paying the sender's own address with label m = 0. An address that copies the sender's scan key can therefore precede the change output in its group, and the sender's wallet will not find the change when it rescans, e.g., when it is restored from a backup.

    No advice on ordering. Ordering the addresses does not help outside the two exceptions, because the sender does not know which of two spend keys the owner of the scan key scans for. (In BIP375, the order within a group is determined by the spend keys anyway, as fametrano notes.)

    Privacy. A sender that rejects, delays, or moves a payment to another transaction because its scan key collides with that of another pending payment reveals whom it is paying. Anyone who knows a silent payment address can request a payment to an address with the same scan key and an arbitrary spend key. If the sender's reaction is observable, the requester learns that the sender is paying the owner of that scan key at that time, and probably also in which transaction. Silent payments are supposed to hide this link between an address and a transaction. A sender that never pays addresses from different parties in the same transaction does not leak this, but it cannot batch.

    The condition is a property of the protocol and not of this API, so BIP352 and BIP375 should state it as well.

    Beyond documentation. A usage rule cannot be the final answer, because a sender must choose between not batching and the leak described above, and because two parties in a collaborative transaction cannot pay different labeled addresses of the same receiver. A few options for protocol updates are written up (by Claude Fable 5.2 with my guidance) in this document. I don't claim to be the first to come up with any of them.

  9. Yudis-bit commented at 10:55 AM on November 21, 2026: contributor

    The scan public key is the caller's own (e.g., because the group contains the caller's change), and the caller has checked that every spend public key in the group is its own unlabeled spend public key or one of its own labeled spend public keys.

    Would putting the wallet's own spend keys first avoid a separate tx here? Splitting or rejecting on a collision with your own scan key still leaks who's paying, even without batching: anyone with your address can hand out your scan key plus a random spend key and see how the wallet reacts.

    Giving own spend keys (change and own labels) a smaller index than an external recipient puts them at lower k, so rescanning still finds them. Core #35302 and spdk-wallet both append change last right now, and the header doesn't mention the index tie-breaker.

  10. real-or-random commented at 10:55 AM on November 23, 2026: contributor

    Would putting the wallet's own spend keys first avoid a separate tx here?

    Yes, I think this works (edit: but not in BIP375 which mandates a specific order IIUC), and it is better than what I suggested. For its own scan key, the sender knows which spend keys are its own, so these keys can get smaller k than any other spend key in the group. A rescan then finds all of the sender's outputs and stops at the first foreign spend key.

    The order is not observable, so a caller that always gives the sender's own spend keys the lower index leaks nothing, whereas rejecting the payment reveals that the scan key is the sender's own.

    I would change my suggestion as follows. I also overhauled the text once more to make it clearer:

     *  Recipient objects with the same scan public key MUST NOT be passed in the
     *  same call, unless one of the following holds:
     *    - The same party requested the payments for all of these recipient
     *      objects. (For example, all of them have been created from addresses
     *      obtained from the intended recipient in a single payment request.)
     *    - The scan public key is the sender's own (e.g., because the sender's
     *      change is among these recipient objects), and the caller gives the
     *      recipient objects with the sender's own (unlabeled or labeled) spend
     *      public keys a lower `index` than the other ones.
     *    - All of these recipient objects have the same spend public key.
     *  Use `secp256k1_ec_pubkey_cmp` to compare public keys.
     *
     *  Payments whose recipient objects cannot be passed in the same call need
     *  to be made in separate transactions. This can be harmful to privacy: a
     *  party that requests a payment and observes that it is treated differently
     *  learns that the sender is paying another recipient with the same scan
     *  public key. A caller that never passes recipient objects for payments
     *  requested by different parties in the same call avoids this.
     *
     *  The reason for this rule is as follows. The recipient objects that share
     *  a scan public key are called a group. The owner of the scan key is
     *  guaranteed to find the outputs for a group only if the spend public key
     *  of every recipient object in the group is one of its own (unlabeled or
     *  labeled) spend public keys. This cannot be determined from the public
     *  keys alone, which is why the rule refers to the party that requested a
     *  payment.
     *
     *  Concretely, a malicious party can request a payment for a recipient
     *  object that combines the scan public key of another recipient (or of the
     *  sender) with a spend public key of its own. If such a recipient object is
     *  passed in the same call, the outputs for the recipient objects in the
     *  group with a higher `index` are unfindable by the owner of the scan key.
    

    One thing I'm unsure about is whether we should rather have two functions, as the PR description considers: a simple one whose callers do not need to follow any of these rules, and the existing one for callers that need them. Since every sender has change, the simple function cannot just fail when two recipient objects have the same scan public key: it would fail whenever a payment is requested to a recipient object with the sender's scan public key, and the caller would have to handle this in a way that the requesting party cannot observe. The simple function could instead have a separate change argument for the recipient objects that pay back to the sender, and order these first by itself. It would then fail only if two of the other recipient objects have the same scan public key.

    If we do this, there is the question of naming and backward compatibility. Giving the existing name to the simple function would break every caller, because the simple function has a different list of arguments. I lean towards deprecating the existing function in favor of two new ones: the simple function, and a copy of the existing function with a loud suffix such as _unsafe.

  11. Yudis-bit commented at 2:19 PM on November 23, 2026: contributor

    Would separating the interface into a safe default with an explicit change argument and an _unsafe variant work best here? The safe variant can enforce the tie-breaker internally, while callers with multi-party batching retain the low-level contract.

  12. real-or-random commented at 2:31 PM on November 23, 2026: contributor

    Would separating the interface into a safe default with an explicit change argument and an _unsafe variant work best here? The safe variant can enforce the tie-breaker internally, while callers with multi-party batching retain the low-level contract.

    Yes. I think that's the best thing, and this is what I was trying to express here:

    I lean towards deprecating the existing function in favor of two new ones: the simple function, and a copy of the existing function with a loud suffix such as _unsafe.

  13. theStack renamed this:
    silentpayments: document recipient correctness requirement for sender
    silentpayments: document rule for recipients sharing a scan pubkey
    on Nov 23, 2026
  14. theStack force-pushed on Nov 23, 2026
  15. theStack commented at 3:59 PM on November 23, 2026: contributor

    @real-or-random: Thanks for the alternative suggestions, I've updated the commit with your latest iteration (and updated PR and commit titles, since "correctness requirement" doesn't apply anymore). My initial idea was to update the docs in the most simple and generic way without going too deep into underlying protocol details, but I agree that the requirement was too vague to be useful.

    I don't think the new paragraph gives the caller a requirement it can act on. It asks the caller to ensure that each scan/spend public key pair "actually belongs to the intended recipient". In the attack, the address with the copied scan key passes every check available to a sender: the attacker provided the address, and the attacker is the party that the sender intends to pay with that output. The address is harmful because the owner of the scan key does not scan for its spend key, and a sender cannot determine that from the two public keys.

    What I had concretely in mind with the "address actually belongs to the intended recipient" phrasing was "recipient owns secret keys material to spend it", and assuming the sender has some way to verify that (e.g. by requesting a signature off-band, or by the fact that it's well-known that a recipient regularly requests payment on this address) an adversary would not be able to pass this criteria for their provided address, as they copy the scan public key, but still don't know the corresponding secret key. Of course, this is all very fuzzy and doesn't help much if no concrete verification mechanism is proposed, so yeah I'd agree that this is nothing to act on.

    Privacy. A sender that rejects, delays, or moves a payment to another transaction because its scan key collides with that of another pending payment reveals whom it is paying. Anyone who knows a silent payment address can request a payment to an address with the same scan key and an arbitrary spend key. If the sender's reaction is observable, the requester learns that the sender is paying the owner of that scan key at that time, and probably also in which transaction. Silent payments are supposed to hide this link between an address and a transaction. A sender that never pays addresses from different parties in the same transaction does not leak this, but it cannot batch.

    Hmm, that's a very interesting point. Thought a bit more about this over the weekend, but I'm still somewhat skeptical how such an observation would be possible in practice without severe negligence of the sender. I left a corresponding comment in the gist to discuss further (mostly to understand and get the full picture; I don't think the course of discussion would change anything in this PR, even if we ended up agreeing that this is far-fetched, a special note on privacy makes sense to be on the safe side).

    One thing I'm unsure about is whether we should rather have two functions, as the PR description considers: a simple one whose callers do not need to follow any of these rules, and the existing one for callers that need them. [...]

    Good question, I'm on the fence here. For the cross-party batching case alone I wouldn't be too worried, as services doing that kind of batching are probably still some way off.

    What I didn't have on my radar before is the change case: it needs no batching at all, only a payee who knows the sender's SP address and requests a payment to an address that reuses the sender's scan pubkey. The new doc text covers this, and following it is easy (always give the change the lowest index). But the intuitive choice is probably to place the change last, which is exactly the ordering that makes it unfindable, so an implementer who misses that paragraph gets the bad behaviour silently. Whether that justifies a second function, I'm still not sure.

    Another aspect is that a simple ("safe") function alone would not cover the full BIP, as some of the official test vectors send to multiple recipients sharing a scan pubkey, so those could only be exercised through the existing (_unsafe) function. I don't think that's a reason against it though, as the BIP should be updated with this finding anyway.

  16. theStack force-pushed on Nov 23, 2026
  17. Yudis-bit commented at 4:05 AM on November 24, 2026: contributor

    reACK af37d0deae5402a93bf6b05d80c73d81d3d38f64

    The contract now gives callers an actionable tie-breaker rule for change outputs. Keeping this documentation update self-contained makes sense, while the separate safe function can be designed in a follow-up PR.

  18. in include/secp256k1_silentpayments.h:85 in af37d0deae
      80 | + *      objects. (For example, all of them have been created from addresses
      81 | + *      obtained from the intended recipient in a single payment request.)
      82 | + *    - The scan public key is the sender's own (e.g., because the sender's
      83 | + *      change is among these recipient objects), and the caller gives the
      84 | + *      recipient objects with the sender's own (unlabeled or labeled) spend
      85 | + *      public keys a lower `index` than the other ones.
    


    real-or-random commented at 9:48 AM on November 24, 2026:

    nit: since index must equal the position in the recipients array, the caller has to put these recipient objects first in the array, not only change their index. Maybe say so explicitly:

     *      change is among these recipient objects), and the caller puts the
     *      recipient objects with the sender's own (unlabeled or labeled) spend
     *      public keys before the other ones in the `recipients` array (i.e.,
     *      gives them a lower `index`).
    
  19. in include/secp256k1_silentpayments.h:108 in af37d0deae
     103 | + *
     104 | + *  Concretely, a malicious party can request a payment for a recipient
     105 | + *  object that combines the scan public key of another recipient (or of the
     106 | + *  sender) with a spend public key of its own. If such a recipient object is
     107 | + *  passed in the same call, the outputs for the recipient objects in the
     108 | + *  group with a higher `index` are unfindable by the owner of the scan key.
    


    real-or-random commented at 9:48 AM on November 24, 2026:

    nit: "a higher index" leaves open what it is compared to. Maybe phrase it in terms of the position in the array, as in the rule above:

     *  sender) with a spend public key of its own. If such a recipient object is
     *  passed in the same call, the owner of the scan key cannot find the
     *  outputs for the recipient objects in the group that come after the
     *  malicious one in the `recipients` array (i.e., that have a higher
     *  `index`).
    
  20. real-or-random approved
  21. real-or-random commented at 9:49 AM on November 24, 2026: contributor

    ACK af37d0deae5402a93bf6b05d80c73d81d3d38f64

    Two small wording nits (in my own text) below.

  22. silentpayments: document rule for recipients sharing a scan pubkey
    Background:
    An adversary can create an address reusing another owner's scan public
    key. If such an address is batched together with that owner's address,
    the owner's output may be ordered after the adversary's and is then not
    found by the BIP352 scanning algorithm.
    
    Thanks to l0rinc for first finding this issue (PRed in Bitcoin Red
    Team's bitcoin-security-council/secp256k1 repository on Sep. 19th).
    Similar vulnerability reports were later submitted by the Anthropic OSS
    scanner (ANT-2026-X2ZAAB2N, Oct. 16th) and Project Loupe (Oct. 29th).
    c44f9d66e8
  23. theStack force-pushed on Nov 25, 2026
  24. theStack commented at 12:28 PM on November 25, 2026: contributor

    Force-pushed with the nits regarding recipient position (https://github.com/bitcoin-core/secp256k1/pull/1990#discussion_r4678165351, #1990 (review)) addressed.

  25. real-or-random approved
  26. real-or-random commented at 3:19 PM on November 25, 2026: contributor

    ACK c44f9d66e8fd04891d7cb9531e2ac3da79a74c40

  27. real-or-random added the label needs-changelog on Nov 25, 2026
  28. real-or-random commented at 3:19 PM on November 25, 2026: contributor

    @fametrano Want to re-review this?


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin-core/secp256k1. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-12-02 10:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me