Skip to content

Do not allow uncompressed pubkey in wpkh(KEY) output descriptor #88

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

Conversation

kiminuo
Copy link
Contributor

@kiminuo kiminuo commented May 13, 2020

wpkh(KEY) (not inside wsh): P2WPKH output for the given compressed pubkey.

@kiminuo
Copy link
Contributor Author

kiminuo commented May 13, 2020

Fuzz crash is thanks to #89. Hopefully.

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.

Hi, thanks for tackling this. I think this can be extended to include wsh cases too. We can use MiniscriptKey::from_str() instead of str::from_str and that would guide rest of implementation.
You would have to pass the compressed flag from the Terminal::from_tree().
For sh, pkh, pk: the flag would be false
For everything else, the compressed_only flag should be true

@@ -405,7 +405,7 @@ where
Ok(Descriptor::ShWsh(sub))
}
("wpkh", 1) => expression::terminal(&newtop.args[0], |pk| {
Pk::from_str(pk).map(Descriptor::ShWpkh)
str::FromStr::from_str(pk).map(Descriptor::ShWpkh)
Copy link
Member

Choose a reason for hiding this comment

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

I think Segwit rules would apply here and has to be strict compressed only.

expression::terminal(&top.args[0], |x| Pk::from_str(x).map(Terminal::PkK))
}
("pk_k", 1) => expression::terminal(&top.args[0], |x| {
str::FromStr::from_str(x).map(Terminal::PkK)
Copy link
Member

Choose a reason for hiding this comment

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

Can we use MiniscriptKey::from_str here? That should also help for extending the PR to wsh/sh.
See the following comment on a suggestion for the implementation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed

@@ -381,7 +381,9 @@ where
}
}
match (frag_name, top.args.len() as u32) {
("pk", 1) => expression::terminal(&top.args[0], |pk| Pk::from_str(pk).map(Policy::Key)),
("pk", 1) => expression::terminal(&top.args[0], |pk| {
Copy link
Member

Choose a reason for hiding this comment

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

I think we can relax the compiler here to allow 65 bytes keys.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure I follow. Could you elaborate on that?

@kiminuo kiminuo force-pushed the feature/issue-73-uncompressed-pubkey-in-witness-descriptors branch from 38206f3 to 360afcd Compare June 3, 2020 07:00
@kiminuo kiminuo force-pushed the feature/issue-73-uncompressed-pubkey-in-witness-descriptors branch from 360afcd to 4f50f44 Compare June 3, 2020 07:06
@kiminuo kiminuo force-pushed the feature/issue-73-uncompressed-pubkey-in-witness-descriptors branch from 9865694 to f337f24 Compare June 3, 2020 13:13
@kiminuo
Copy link
Contributor Author

kiminuo commented Jun 3, 2020

@sanket1729

You would have to pass the compressed flag from the Terminal::from_tree().

I'll just rephrase what you said to make sure I understand correctly. So we have fixed wpkh - line:

https://github.com/kiminuo/rust-miniscript/blob/f337f249ee545257676634e56e17173e67218666/src/descriptor/mod.rs#L408

and now we would like to continue with wsh here:

https://github.com/kiminuo/rust-miniscript/blob/f337f249ee545257676634e56e17173e67218666/src/descriptor/mod.rs#L404

where we would like to pass compressed_only=true. Meaning, one would need to modify Miniscript::from_tree(arg) to Miniscript::from_tree(arg, compressed_only). Right? Is that what you suggest? I can see it's not exactly what you wrote but that's what would make sense to me.. So I'll be glad for any feedback.

@kiminuo
Copy link
Contributor Author

kiminuo commented Jun 3, 2020

In the mean time, I have added a new commit that should address some of your suggestions. The goal is to squash the commits when everything is done.

@sanket1729
Copy link
Member

Hi @kiminuo ,

Meaning, one would need to modify Miniscript::from_tree(arg) to Miniscript::from_tree(arg, compressed_only)

Sorry for being unclear. I will leave detailed feedback in the following review.

@sanket1729
Copy link
Member

On second thought, I think maybe altering the trait for FromTree might not be a good idea as this will result in passing the flag in all recursive calls of from_tree() .

Maybe there is a better way than doing this, but I can't think as of now. I am wondering if selectively supporting 65 bytes keys for non-segwit is a good idea given the code changes. @apoelstra, what are your opinions on this?

@apoelstra
Copy link
Member

I wouldn't be opposed to alterning the trait. It is annoying and ugly but not overly so.

What I'd really like though is to somehow use the type system to eliminate these checks entirely. Like, to make it impossible to construct a segwit Miniscript with 65-byte keys. But this might not be (cleanly) possible in Rust.

@apoelstra
Copy link
Member

Consider also that in segwit v1 we will lose the ThreshM node (and gain some new one). I wonder if we should think about a more general way to split out Miniscripts for the different descriptor contexts.

@sanket1729
Copy link
Member

Hey @kiminuo , sorry about this. We decided to overrule this approach with a generic script context parameter that should allow us for an easier transition to tapscript.

@kiminuo
Copy link
Contributor Author

kiminuo commented Jun 18, 2020

No problem :)

@sanket1729
Copy link
Member

Closing in favor of #97

@sanket1729 sanket1729 closed this Jun 18, 2020
@kiminuo kiminuo deleted the feature/issue-73-uncompressed-pubkey-in-witness-descriptors branch May 26, 2021 07:59
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.

3 participants