Skip to content

BIP-322: add clarifications and more test vectors#2136

Open
guggero wants to merge 3 commits intobitcoin:masterfrom
guggero:bip-0322-clarifications
Open

BIP-322: add clarifications and more test vectors#2136
guggero wants to merge 3 commits intobitcoin:masterfrom
guggero:bip-0322-clarifications

Conversation

@guggero
Copy link
Copy Markdown
Contributor

@guggero guggero commented Apr 9, 2026

While implementing a Golang implementation of BIP-322, I noticed a couple of things that weren't super clear.

I also added more test vectors for both the "simple" and "full" variants.

Copy link
Copy Markdown
Member

@murchandamus murchandamus left a comment

Choose a reason for hiding this comment

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

cc: @kallewoof for sign-off

@murchandamus murchandamus added Proposed BIP modification Pending acceptance This BIP modification requires sign-off by the champion of the BIP being modified labels Apr 9, 2026
@guggero guggero force-pushed the bip-0322-clarifications branch 2 times, most recently from 1131532 to 2b051e2 Compare April 9, 2026 18:58
@guggero guggero requested a review from murchandamus April 9, 2026 19:00
@guggero
Copy link
Copy Markdown
Contributor Author

guggero commented Apr 9, 2026

I think we might be able to change the test vectors to just a single signature if we get clarity on bitcoin/bitcoin#24058 (comment). I suspect that buidl-python either derives a sub-key from a WIF (what does it use as the chain code in that case?) or just interprets the private key in a WIF differently.
IMO there shouldn't be the need for two different valid signatures being defined in a BIP.

Copy link
Copy Markdown
Contributor

@kallewoof kallewoof left a comment

Choose a reason for hiding this comment

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

LGTM. Two nits, feel free to disregard.

! Signature format
|-
| Legacy
| <code>P2PKH, P2SH-P2WPKH, P2WPKH</code>
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.

This should only list P2PKH, I think. See "Legacy" section below in which it states

The legacy format MAY be used, but must be restricted to the legacy P2PKH invoice address format.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, I see what you mean. My intention was to show what's possible with the different variants. But we should discourage using the legacy format, I agree. I added a clarification hint, I hope that makes it clearer and also more readable.

@@ -0,0 +1,181 @@
{
"tx_hashes": null,
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.

Can this be removed since it's null? Or is this here to demonstrate that the tx hash is not forgotten but intentionally not set?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Just an artifact of the JSON serialization. Removed.

@guggero guggero force-pushed the bip-0322-clarifications branch from 2b051e2 to df702f7 Compare April 10, 2026 07:05
guggero added 3 commits April 10, 2026 09:06
This commit adds a table that clarifies what script types are compatible
with what signing variant and also makes more clear what the exact
format for the signatures of the different variants are.
Before this commit it was not clear that non-native SegWit outputs
(e.g. P2PKH or P2SH-P2WPKH) only work if the correct scriptSig is
provided.
This then also makes it more clear why P2SH-P2WPKH outputs are NOT
supported by the "simple" variant.
This commit turns the existing test vectors into a JSON and then adds
more test cases covering the most common script types.
@guggero guggero force-pushed the bip-0322-clarifications branch from df702f7 to 3ab70c9 Compare April 10, 2026 07:06
@guggero
Copy link
Copy Markdown
Contributor Author

guggero commented Apr 10, 2026

I added some negative test cases as well.

@kallewoof
Copy link
Copy Markdown
Contributor

I didn't look at the test cases, but LGTM otherwise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Pending acceptance This BIP modification requires sign-off by the champion of the BIP being modified Proposed BIP modification

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants