Skip to content

Say which order the k of a silent payment output follows (#768) - #894

Merged
fametrano merged 1 commit into
mainfrom
sp-docstring
Aug 14, 2026
Merged

Say which order the k of a silent payment output follows (#768)#894
fametrano merged 1 commit into
mainfrom
sp-docstring

Conversation

@fametrano

@fametrano fametrano commented Aug 14, 2026

Copy link
Copy Markdown
Member

btclib/psbt/silent_payments.py's module docstring described BIP375's
prose -- the codes sharing a scan key sorted lexicographically by spend
key -- and named _ordered_sp_outputs as that sort. The function is
output index order, and its own docstring says so and says why, so the
file contradicted itself and the published API docs carried the half that
is not the code.

The function's own account gains the correction the discrepancy needed:
the two invalid vectors named after ordering are refused under either rule
because each carries a k assignment no ascending rule produces (two
values swapped in one, three permuted in the other), not because they
match none at all -- measured by deriving every candidate k for each
output with BIP375's own compute_silent_payment_output_script. It also
names bips PR 2207, which
would settle the question the other way by correcting the vectors and the
validator to the prose; against those vectors the test that pins index
order is what fails.

No behaviour change. Gates run locally: uv run pytest (27808 passed),
uv run pre-commit run --files ..., and the sphinx -W build.

Issue #768

Summary by Sourcery

Clarify documentation around silent payment output ordering to match the implemented index-order behavior and explicitly document the discrepancy with BIP375 prose and test vectors.

Enhancements:

  • Refine _ordered_sp_outputs documentation to accurately describe why invalid BIP375 test vectors are rejected under any ascending rule and reference bips PR 2207 as the proposed resolution.

Documentation:

  • Update psbt.silent_payments module and function docstrings to state that k counts outputs in index order per scan key and to explain the mismatch with BIP375 prose, reference vectors, and validator.

The module docstring described BIP375's prose -- the codes sharing a scan
key sorted lexicographically by spend key -- and named
`_ordered_sp_outputs` as that sort. The function is output index order,
and its own docstring says so and says why, so the file contradicted
itself and the API docs carried the half that is not the code.

The function's own account gains the correction the discrepancy needed:
the two invalid vectors named after ordering are refused under either
rule because each carries a k assignment no ascending rule produces, two
values swapped in one and three permuted in the other, not because they
match none at all. It also names bips PR 2207, which would settle the
question the other way by correcting the vectors and the validator to the
prose, and against which the test that pins index order is what fails.

Issue #768

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @fametrano, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@sourcery-ai

sourcery-ai Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Clarifies and documents that the silent payments k-ordering implementation uses output index order (matching BIP375 test vectors and reference validator) rather than the prose-described lexicographic spend-key order, and updates comments/changelog to explain how invalid vectors are rejected and to reference the relevant BIPs PR.

File-Level Changes

Change Details Files
Updated silent_payments module and helper docstrings to accurately describe k-ordering as output index order and to explain the discrepancy with BIP375 prose and test vectors.
  • Adjusted the module-level docstring in psbt.silent_payments to state that k counts per scan key over outputs in index order, not lexicographically by spend key.
  • Clarified that _ordered_sp_outputs documents the discrepancy between BIP375 prose and its vectors/validator, and that specific tests pin the behavior.
  • Extended the _ordered_sp_outputs docstring to describe how invalid vectors are rejected under any ascending rule, detailing the swapped/permuted k assignments and referencing bips PR 2207.
btclib/psbt/silent_payments.py
Documented the k-ordering clarification and behavior in the project changelog.
  • Added a changelog entry explaining the previous contradiction between the module docstring and implementation for k-ordering in psbt.silent_payments.
  • Documented that the module docstring now aligns with the implementation and points to _ordered_sp_outputs for the BIP375 discrepancy.
  • Noted how invalid vectors are handled under both ordering rules and that bips PR 2207 may change the BIP, with tests guarding current behavior.
CHANGELOG.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@fametrano
fametrano merged commit 9e1cb9c into main Aug 14, 2026
20 checks passed
@fametrano
fametrano deleted the sp-docstring branch August 14, 2026 17:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant