Skip to content

Fix pk_len() for BareCtx #472

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

Merged
merged 1 commit into from
Oct 8, 2022

Conversation

afilini
Copy link
Contributor

@afilini afilini commented Oct 4, 2022

The pk_len() returned should account for the extra byte for the OP_PUSH opcode. This is true for all the other contexts, but not for BareCtx, so this commit fixes it.


This PR is based on the 7.0.0 tag because in my opinion it's worth applying this and releasing as 7.0.1 without waiting for 8.0.0 (BDK would naturally benefit from this because we are about to make one new release still based on 7.0.0 and it's tricky to workaround this issue in our code).

I think the patch is small enough that it can easily be applied on older releases as well, if you want to backport it too.

The `pk_len()` returned should account for the extra byte for the
OP_PUSH opcode. This is true for all the other contexts, but not for
`BareCtx`, so this commit fixes it.
Copy link
Contributor

@evanlinjin evanlinjin left a comment

Choose a reason for hiding this comment

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

ACK f3ae0d8

} else {
33
34
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Would it make sense to have 33 + 1 instead? This way we can explicitly show OP_PUSH... and <pk>.

Copy link

@vladimirfomene vladimirfomene Oct 6, 2022

Choose a reason for hiding this comment

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

Now I'm wondering if it is not better to have the 1 byte of the OP code outside of this function for all contexts. The name of the function pk_len communicates that it is calculating the length of the serialized public key but it does more than that by adding the byte for the PUSH opcode. Or maybe mention this fact in the docs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah it's mentioned in the docs:

/// Get the len of public key when serialized based on context
/// Note that this includes the serialization prefix. Returns
/// 34/66 for Bare/Legacy based on key compressedness
/// 34 for Segwitv0, 33 for Tap

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Re: 33 + 1 I'd be ok making that change, but let's see what the maintainers think about it

@apoelstra
Copy link
Member

concept ACK this. no preference about 34 vs 33 + 1 .

Can't test locally because of the honggfuzz arbitrary thing..maybe this needs a rebase or something, but no big deal in any case, the code is visibly correct.

Copy link
Member

@sanket1729 sanket1729 left a comment

Choose a reason for hiding this comment

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

ACK f3ae0d8

Copy link
Member

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

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

ACK f3ae0d8

@apoelstra apoelstra merged commit 2d113fb into rust-bitcoin:master Oct 8, 2022
sanket1729 added a commit to sanket1729/elements-miniscript that referenced this pull request Oct 21, 2022
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.

5 participants