Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bolt11: Don't push the size of the witness program for v1+ scripts #6435

Merged

Conversation

niftynei
Copy link
Collaborator

For non-v0 witness programs we weren't stripping the data push byte before writing into the fallback address.

According to BIP14, all witness scripts will be data pushes (up to 40-bytes) so trimming the datapush byte should be kosher.

From BIP141:

A scriptPubKey (or redeemScript as defined in BIP16/P2SH) that
consists of a 1-byte push opcode (for 0 to 16) followed by a
data push between 2 and 40 bytes gets a new special meaning.
The value of the first push is called the "version byte". The
following byte vector pushed is called the "witness program".

Changelog-Fixed: Adding a >0 version witness program to a fallback address now is just the witness program, as per bolt11 spec

For non-v0 witness programs we weren't stripping the data push byte
before writing into the fallback address.

According to BIP14, all witness scripts will be data pushes (up to 40-bytes)
so trimming the datapush byte should be kosher.

From BIP141:

	A scriptPubKey (or redeemScript as defined in BIP16/P2SH) that
	consists of a 1-byte push opcode (for 0 to 16) followed by a
	data push between 2 and 40 bytes gets a new special meaning.
	The value of the first push is called the "version byte". The
	following byte vector pushed is called the "witness program".

Changelog-Fixed: Adding a >0 version witness program to a fallback address now is *just* the witness program, as per bolt11 spec
Copy link
Collaborator

@vincenzopalazzo vincenzopalazzo left a comment

Choose a reason for hiding this comment

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

LGTM, just a tiny comment on the code style!

Comment on lines +415 to +425
if (version == 1 && tal_count(f) != 32) {
return tal_fmt(b11,
"f: witness v1 bad length %zu",
tal_count(f));
}
if (tal_count(f) > 40) {
return tal_fmt(b11,
"f: witness v%ld bad length %zu",
version,
tal_count(f));
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

we can avoid the {....} here

@rustyrussell rustyrussell merged commit bcdfac7 into ElementsProject:master Jul 25, 2023
38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants