Skip to content

bip360: exit nonzero when a test vector fails - #2380

Merged
jonatack merged 1 commit into
bitcoin:masterfrom
rioyu123:fix/bip360-vector-exit-status
Dec 4, 2026
Merged

jonatack merged 1 commit into
bitcoin:masterfrom
rioyu123:fix/bip360-vector-exit-status

Conversation

@rioyu123

@rioyu123 rioyu123 commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

The BIP 360 reference script prints FAILED when a construction vector does not match the expected output, but still exits with status 0. A caller checking the exit status misses the failure.

Count failures across both vector files and exit with status 1 after the negative structure tests have run, so all diagnostics are still printed.

I ran the script against the checked-in vectors (9/9 and 7/7) and all three negative structure checks. I then changed one expected scriptPubKey in temporary copies of the first vector file, the second, and both. On master all three runs exited 0. With this change each reported the mismatch and exited 1. The unmodified vectors exit 0.

I used Codex to implement and test the change and Claude to review it.

@cryptoquick

Copy link
Copy Markdown
Contributor

@jonatack let's come back to this once #2232 is merged.

@rioyu123 please watch for that to get into master and then rebase this on top of that. appreciate the work, just would be good to get the new vectors in before we tweak the tests they rely on.

@jonatack jonatack added the Fixups Minor fixups not worth bothering the BIP author(s) for label Dec 3, 2026
@devdavidejesus

Copy link
Copy Markdown
Contributor

tACK f40146f

Tested on macOS with Python 3.15.2: with the unmodified vectors the script exits 0; with a tampered merkleRoot in p2mr_single_leaf_script_tree it reports the failure and exits 1.

I also checked that the branch merges cleanly on current master (78255e0); p2mr.py doesn't read the new p2mr_spending.json, so the results are unchanged. Happy to re-ACK after the rebase.

One minor observation: running p2mr.py with python3 -O strips the assert checks in run_single_test(). With the corrupted merkleRoot, the script then reports all vectors as passing and exits 0.

3c8190e already replaced the library's validation asserts with explicit raises so malformed trees still fail under -O (see the negative_structure_tests() docstring). It might be worth doing the same for the vector checks, e.g. if ...: raise AssertionError(...), which the existing except AssertionError would still catch.

@jonatack jonatack left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ACK

One minor observation: running p2mr.py with python3 -O strips the assert checks in run_single_test(). With the corrupted merkleRoot, the script then reports all vectors as passing and exits 0.

Agree with @devdavidejesus's comment and suggestion for a follow-up.

@jonatack
jonatack merged commit 3042727 into bitcoin:master Dec 4, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Fixups Minor fixups not worth bothering the BIP author(s) for

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants