test: add BIP352 scanning to the functional test framework #36835

Manually merged
rustaceanrob merged 2 commits from sp-recv-functional into master 2026-11-20 23:48:14 +00:00 AGit
rustaceanrob commented 2026-11-11 13:45:58 +00:00 (Migrated from github.com)

Picked from #35302 as an isolated change that can be evaluated independently. This should make #35302 a bit easier to review. This adds a Python implementation of BIP352 scanning, without labels, so the functional tests can check silent payments outputs independently of bitcoind support. It is tested against the BIP352 receiving test vectors.

Picked from #35302 as an isolated change that can be evaluated independently. This should make #35302 a bit easier to review. This adds a Python implementation of BIP352 scanning, without labels, so the functional tests can check silent payments outputs independently of `bitcoind` support. It is tested against the BIP352 receiving test vectors.
DrahtBot commented 2026-11-11 13:46:10 +00:00 (Migrated from github.com)

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

External sites

Reviews

See the guideline and AI policy for information on the review process.

Type Reviewers
ACK theStack, ismaelsadeeq, Eunovo, achow101

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #35302 (Silent Payments: Sending (take 2) by Eunovo)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/36835 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36835.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36835#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. | Type | Reviewers | | ---- | --------- | | ACK | [theStack](https://github.com/bitcoin/bitcoin/pull/36835#pullrequestreview-5941351662), [ismaelsadeeq](https://github.com/bitcoin/bitcoin/pull/36835#pullrequestreview-5941477053), [Eunovo](https://github.com/bitcoin/bitcoin/pull/36835#issuecomment-6978106070), [achow101](https://github.com/bitcoin/bitcoin/pull/36835#issuecomment-7053300748) | If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore. <!--174a7506f384e20aa4161008e828411d--> ### Conflicts Reviewers, this pull request conflicts with the following ones: * [#35302](https://github.com/bitcoin/bitcoin/pull/35302) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35302.svg"></sub> (Silent Payments: Sending (take 2) by Eunovo) If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. <!--5faf32d7da4f0f540f40219e4f7537a3-->
First-time contributor

Earlier concerns remain unresolved; see the Run archive linked from the Review report.

🔵 Suggestion · Witness-version skip rule lacks Python coverage

The Python receiving vectors contain no witness-version-2-or-higher prevouts, so removing the transaction-wide skip guard from scan() would leave the existing assertions unchanged.

Location: test/functional/test_framework/bip352.py:60 (head).

Review coverage was incomplete.


Reviewed: cd6d7e240bb2 · Review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:2b20819f882b885f79f242c01722f54f2a55e27dcfa7d5e13701b4a0b5214248:c39fdacfa3b84799844a5e841c04997e3cd1142653dfad8e36dbb07c4b1e684b --> <!-- ralph-base:e211dd0186e9646167d063a16f0da88e5f72e05f --> <!-- ralph-head:cd6d7e240bb22e5d9515bd8cf8dbc081ff471dc8 --> <!-- ralph-case:41232b590002f20fbba4decd5dbda5ccdda294c8ac8d81a24e29b4e37b4c41f2 --> Earlier concerns remain unresolved; see the Run archive linked from the Review report. **🔵 Suggestion · Witness-version skip rule lacks Python coverage** The Python receiving vectors contain no witness-version-2-or-higher prevouts, so removing the transaction-wide skip guard from `scan()` would leave the existing assertions unchanged. Location: [`test/functional/test_framework/bip352.py:60`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/cd6d7e240bb22e5d9515bd8cf8dbc081ff471dc8/test/functional/test_framework/bip352.py#L60>) (head). Review coverage was incomplete. <!-- Review tier: standard --> --- Reviewed: [`cd6d7e240bb2`](<https://git.fish.foo/bitcoin/bitcoin/commit/cd6d7e240bb22e5d9515bd8cf8dbc081ff471dc8>) · [Review report](<https://review.fish.foo/report/36835-cd6d7e240bb22e5d9515bd8cf8dbc081ff471dc8-2758-8.html>) · [Previous reports](<https://review.fish.foo/traces/36835/>) [permalink](<https://review.fish.foo/report/36835-cd6d7e240bb22e5d9515bd8cf8dbc081ff471dc8-2758-8.html>)
ismaelsadeeq (Migrated from github.com) reviewed 2026-11-12 13:43:43 +00:00
ismaelsadeeq (Migrated from github.com) left a comment

Concept ACK, well scoped change.

I did a brief review, see comments below

Concept ACK, well scoped change. I did a brief review, see comments below
ismaelsadeeq (Migrated from github.com) commented 2026-11-12 13:25:09 +00:00

nit: could add a small comment here, explaining the function?

nit: could add a small comment here, explaining the function?
ismaelsadeeq (Migrated from github.com) commented 2026-11-12 13:25:34 +00:00

too many magic nums here and other places

too many magic nums here and other places
ismaelsadeeq (Migrated from github.com) commented 2026-11-12 13:42:17 +00:00

Isn't this an issue when the output is in a transaction that is confirmed? getrawtransaction will return confirmed tx too when tx index is enabled.

I can include an old payment, and you may think it's a new payment during this scan, so you want to check the utxo set and getmempool entry or gate and only return the output when getmempool entry also returns the tx?

Isn't this an issue when the output is in a transaction that is confirmed? getrawtransaction will return confirmed tx too when tx index is enabled. I can include an old payment, and you may think it's a new payment during this scan, so you want to check the utxo set and getmempool entry or gate and only return the output when getmempool entry also returns the tx?
ismaelsadeeq (Migrated from github.com) commented 2026-11-12 13:43:01 +00:00

nit: too many nested loops; can u simplify? It would make it easy to follow.

nit: too many nested loops; can u simplify? It would make it easy to follow.
theStack (Migrated from github.com) reviewed 2026-11-12 13:53:39 +00:00
theStack (Migrated from github.com) left a comment

Concept ACK

Concept ACK
theStack (Migrated from github.com) commented 2026-11-12 13:44:55 +00:00

non-blocking suggestion: I wonder if introducing is_{p2tr,p2pkh...}_script helpers (or a Solver equivalent) in script_util.py would make sense to keep the output script matching logic out of this file, kind of surprised that we don't have that already in the functional test framework

non-blocking suggestion: I wonder if introducing `is_{p2tr,p2pkh...}_script` helpers (or a `Solver` equivalent) in `script_util.py` would make sense to keep the output script matching logic out of this file, kind of surprised that we don't have that already in the functional test framework
rustaceanrob (Migrated from github.com) reviewed 2026-11-12 14:06:48 +00:00
rustaceanrob (Migrated from github.com) commented 2026-11-12 14:06:48 +00:00

I don't think extracting into a separate function would help much for readability

I don't think extracting into a separate function would help much for readability
rustaceanrob (Migrated from github.com) reviewed 2026-11-12 14:22:46 +00:00
rustaceanrob (Migrated from github.com) commented 2026-11-12 14:22:46 +00:00

re https://github.com/bitcoin/bitcoin/pull/36835#discussion_r4551222771

I think this suggestion makes sense, so the magic numbers and such can move to script_util.py

re https://github.com/bitcoin/bitcoin/pull/36835#discussion_r4551222771 I think this suggestion makes sense, so the magic numbers and such can move to `script_util.py`
rustaceanrob (Migrated from github.com) reviewed 2026-11-12 14:26:03 +00:00
rustaceanrob (Migrated from github.com) commented 2026-11-12 14:26:03 +00:00

getrawtransaction will return confirmed tx too

This is by design. We check for confirmed payments here as well, whose inputs will inherently not be in the UTXO set. See this commit for the use cases. FWIW, a "real" scanner would use the undo data and block rather than -txindex and getrawtransaction.

Side note related to thsee calls, either we assume -txindex is enabled as is done here, or the user has to pass a block hash they expect the payment to be in, which would be cumbersome for writing tests IMO.

> getrawtransaction will return confirmed tx too This is by design. We check for confirmed payments here as well, whose inputs will inherently not be in the UTXO set. See [this commit](https://github.com/bitcoin/bitcoin/pull/35302/changes/6cbb0ea9dc96cf4ab4a225a4d97e2dae70369b05) for the use cases. FWIW, a "real" scanner would use the undo data and block rather than `-txindex` and `getrawtransaction`. Side note related to thsee calls, either we assume `-txindex` is enabled as is done here, or the user has to pass a block hash they expect the payment to be in, which would be cumbersome for writing tests IMO.
rustaceanrob (Migrated from github.com) reviewed 2026-11-12 20:16:05 +00:00
rustaceanrob (Migrated from github.com) commented 2026-11-12 20:16:05 +00:00

It did a bit. I added a function that creates an iterator for the receiving test vectors after parsing the json.

It did a bit. I added a function that creates an iterator for the receiving test vectors after parsing the json.
rustaceanrob (Migrated from github.com) reviewed 2026-11-12 20:17:06 +00:00
rustaceanrob (Migrated from github.com) commented 2026-11-12 20:17:06 +00:00

Added fdfd7467cf with some is_p2* utilities and a witness version function

Added fdfd7467cf77bdbea4d2c8bfdff137172006834a with some `is_p2*` utilities and a witness version function
DrahtBot commented 2026-11-12 20:21:22 +00:00 (Migrated from github.com)

🚧 At least one of the CI tasks failed.
Task lint: https://github.com/bitcoin/bitcoin/actions/runs/43298469093/job/131462961033
LLM reason (✨ experimental): CI failed in Python lint: bip352.py:35 passes an int to is_p2wpkh, which expects bytes.

Hints

Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:

  • Possibly due to a silent merge conflict (the changes in this pull request being
    incompatible with the current code in the target branch). If so, make sure to rebase on the latest
    commit of the target branch.

  • A sanitizer issue, which can only be found by compiling with the sanitizer and running the
    affected test.

  • An intermittent issue.

Leave a comment here, if you need help tracking down a confusing failure.

<!--85328a0da195eb286784d51f73fa0af9--> 🚧 At least one of the CI tasks failed. <sub>Task `lint`: https://github.com/bitcoin/bitcoin/actions/runs/43298469093/job/131462961033</sub> <sub>LLM reason (✨ experimental): CI failed in Python lint: `bip352.py:35` passes an `int` to `is_p2wpkh`, which expects `bytes`.</sub> <details><summary>Hints</summary> Try to run the tests locally, according to the documentation. However, a CI failure may still happen due to a number of reasons, for example: * Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch. * A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test. * An intermittent issue. Leave a comment here, if you need help tracking down a confusing failure. </details>
rustaceanrob (Migrated from github.com) reviewed 2026-11-12 20:37:45 +00:00
rustaceanrob (Migrated from github.com) commented 2026-11-12 20:37:45 +00:00

Moved to fdfd7467cf with a description

Moved to fdfd7467cf77bdbea4d2c8bfdff137172006834a with a description
bartoli (Migrated from github.com) reviewed 2026-11-12 21:51:55 +00:00
bartoli (Migrated from github.com) commented 2026-11-12 21:51:55 +00:00

Shouldn't we loop on outputs and see if they match an output for the current (increasing) k instead? Here, there is a very minimal, but non null, chance that there is a k that matches, but is not actually a sp output?

OR, if we keep the loop in that way because it is 'safe enough', then maybe we should at least stop the range at min(K_MAX, len(outputs)) to save on scan time?

Shouldn't we loop on outputs and see if they match an output for the current (increasing) k instead? Here, there is a very minimal, but non null, chance that there is a k that matches, but is not actually a sp output? OR, if we keep the loop in that way because it is 'safe enough', then maybe we should at least stop the range at min(K_MAX, len(outputs)) to save on scan time?
rustaceanrob (Migrated from github.com) reviewed 2026-11-13 07:32:00 +00:00
rustaceanrob (Migrated from github.com) commented 2026-11-13 07:32:00 +00:00

Shouldn't we loop on outputs and see if they match an output for the current (increasing) k instead?

This matches the BIP.

then maybe we should at least stop the range at min(K_MAX, len(outputs)) to save on scan time?

k = 0 and no found outputs exits the loop.

> Shouldn't we loop on outputs and see if they match an output for the current (increasing) k instead? This [matches the BIP](https://github.com/bitcoin/bips/blob/master/bip-0352.mediawiki#user-content-Scanning). > then maybe we should at least stop the range at min(K_MAX, len(outputs)) to save on scan time? `k = 0` and no found outputs exits the loop.
bartoli (Migrated from github.com) reviewed 2026-11-13 07:56:07 +00:00
bartoli (Migrated from github.com) commented 2026-11-13 07:56:07 +00:00

Oh you're right. I read the loop assuming the function would have to scan for potentially multiple scan keys of multiple sp receive addresses of the wallet. Now i understand.

Oh you're right. I read the loop assuming the function would have to scan for potentially multiple scan keys of multiple sp receive addresses of the wallet. Now i understand.
rustaceanrob commented 2026-11-16 12:32:21 +00:00 (Migrated from github.com)

6ad35e8686 added the make_sp_addr function from #35302 along with tests. Also included a short note on -txindex in the scan_tx function.

6ad35e8686075cdc51ebb8ff3857ea50e13325fb added the `make_sp_addr` function from #35302 along with tests. Also included a short note on `-txindex` in the `scan_tx` function.
Eunovo (Migrated from github.com) approved these changes 2026-11-17 11:29:50 +00:00
Eunovo (Migrated from github.com) left a comment
ACK https://github.com/bitcoin/bitcoin/pull/36835/commits/6ad35e8686075cdc51ebb8ff3857ea50e13325fb Modulo some nits.
Eunovo (Migrated from github.com) commented 2026-11-17 10:49:29 +00:00
https://github.com/bitcoin/bitcoin/pull/36835/commits/6ad35e8686075cdc51ebb8ff3857ea50e13325fb: nit: Can return early if `outputs` is empty.
Eunovo (Migrated from github.com) commented 2026-11-17 11:29:17 +00:00

https://github.com/bitcoin/bitcoin/pull/36835/commits/6ad35e8686075cdc51ebb8ff3857ea50e13325fb:

When a Coinbase TX is supplied, txid will be 000...00, and getrawtransaction will fail with test_framework.util.JSONRPCException: No such mempool or blockchain transaction. Use gettransaction for wallet transactions. (-5).

Not sure what approach is most appropriate here; on the one hand, a user shouldn't try to scan a coinbase tx, and maybe the code should crash and force the user to adjust the test, but I also see this happening when a user tries to scan a block, and an argument could be made that the function should simply skip a coinbase tx the way the production scanning function would.

https://github.com/bitcoin/bitcoin/pull/36835/commits/6ad35e8686075cdc51ebb8ff3857ea50e13325fb: When a Coinbase TX is supplied, txid will be `000...00`, and `getrawtransaction` will fail with `test_framework.util.JSONRPCException: No such mempool or blockchain transaction. Use gettransaction for wallet transactions. (-5)`. Not sure what approach is most appropriate here; on the one hand, a user shouldn't try to scan a coinbase tx, and maybe the code should crash and force the user to adjust the test, but I also see this happening when a user tries to scan a block, and an argument could be made that the function should simply skip a coinbase tx the way the production scanning function would.
rustaceanrob commented 2026-11-17 13:09:21 +00:00 (Migrated from github.com)

c4580eae58 skips coinbases, per the BIP, and also adds the early return in the case there are no PT2R outputs in the transaction

c4580eae5817a22d3630f996ff5455b9f7b23581 skips coinbases, per the BIP, and also adds the early return in the case there are no PT2R outputs in the transaction
Eunovo commented 2026-11-17 13:37:50 +00:00 (Migrated from github.com)
ReACK https://github.com/bitcoin/bitcoin/pull/36835/commits/c4580eae5817a22d3630f996ff5455b9f7b23581
ismaelsadeeq (Migrated from github.com) reviewed 2026-11-17 14:50:55 +00:00
ismaelsadeeq (Migrated from github.com) commented 2026-11-17 14:50:55 +00:00

scan_tx is dead for now; we are not sure it compiles in C.I, and it does not seem like a utility because it needs state and a -txindex requirement. Probably fits better as a helper in the actual test?

`scan_tx` is dead for now; we are not sure it compiles in C.I, and it does not seem like a utility because it needs state and a `-txindex` requirement. Probably fits better as a helper in the actual test?
ismaelsadeeq (Migrated from github.com) reviewed 2026-11-17 14:52:31 +00:00
ismaelsadeeq (Migrated from github.com) commented 2026-11-17 14:52:31 +00:00

Thanks, this reads much better now.

Thanks, this reads much better now.
rustaceanrob (Migrated from github.com) reviewed 2026-11-17 14:56:06 +00:00
rustaceanrob (Migrated from github.com) commented 2026-11-17 14:56:06 +00:00

Sure, we can have this module be self tested entirely. I don't think #35302 uses this in multiple files anyway.

Sure, we can have this module be self tested entirely. I don't think #35302 uses this in multiple files anyway.
DrahtBot commented 2026-11-17 15:09:31 +00:00 (Migrated from github.com)

🚧 At least one of the CI tasks failed.
Task lint: https://github.com/bitcoin/bitcoin/actions/runs/44109510291/job/134130936328
LLM reason (✨ experimental): CI failed because Python linting found three unused imports in test/functional/test_framework/bip352.py (ruff F401 errors).

Hints

Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:

  • Possibly due to a silent merge conflict (the changes in this pull request being
    incompatible with the current code in the target branch). If so, make sure to rebase on the latest
    commit of the target branch.

  • A sanitizer issue, which can only be found by compiling with the sanitizer and running the
    affected test.

  • An intermittent issue.

Leave a comment here, if you need help tracking down a confusing failure.

<!--85328a0da195eb286784d51f73fa0af9--> 🚧 At least one of the CI tasks failed. <sub>Task `lint`: https://github.com/bitcoin/bitcoin/actions/runs/44109510291/job/134130936328</sub> <sub>LLM reason (✨ experimental): CI failed because Python linting found three unused imports in `test/functional/test_framework/bip352.py` (ruff F401 errors).</sub> <details><summary>Hints</summary> Try to run the tests locally, according to the documentation. However, a CI failure may still happen due to a number of reasons, for example: * Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch. * A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test. * An intermittent issue. Leave a comment here, if you need help tracking down a confusing failure. </details>
theStack (Migrated from github.com) approved these changes 2026-11-17 15:30:59 +00:00
theStack (Migrated from github.com) left a comment

ACK cd6d7e240b

I agree that deferring the introduction of scan_tx to another PR (likely #35302) makes sense, given that it it's currently unused/untested.

ACK cd6d7e240bb22e5d9515bd8cf8dbc081ff471dc8 I agree that deferring the introduction of `scan_tx` to another PR (likely #35302) makes sense, given that it it's currently unused/untested.
theStack (Migrated from github.com) commented 2026-11-17 15:28:11 +00:00

nit: could consider moving this function (and the decoding counterpart) to address.py in the future

nit: could consider moving this function (and the decoding counterpart) to `address.py` in the future
ismaelsadeeq (Migrated from github.com) reviewed 2026-11-17 15:34:49 +00:00
ismaelsadeeq (Migrated from github.com) commented 2026-11-17 15:34:49 +00:00

nit: reference the bip here.

nit: reference the bip here.
ismaelsadeeq (Migrated from github.com) approved these changes 2026-11-17 15:35:03 +00:00
ismaelsadeeq (Migrated from github.com) left a comment
ACK cd6d7e240bb22e5d9515bd8cf8dbc081ff471dc8
Eunovo commented 2026-11-18 12:07:56 +00:00 (Migrated from github.com)
ReACK https://github.com/bitcoin/bitcoin/pull/36835/commits/cd6d7e240bb22e5d9515bd8cf8dbc081ff471dc8
achow101 commented 2026-11-20 23:36:44 +00:00 (Migrated from github.com)
ACK cd6d7e240bb22e5d9515bd8cf8dbc081ff471dc8
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!36835
No description provided.