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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/miniscript/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -739,9 +739,9 @@ impl ScriptContext for BareCtx {

fn pk_len<Pk: MiniscriptKey>(pk: &Pk) -> usize {
if pk.is_uncompressed() {
65
66
} 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

}
}

Expand Down