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

update TranslatePk again #493

Merged
merged 4 commits into from
May 24, 2023
Merged

Conversation

sanket1729
Copy link
Member

This PR has lot of cleanups that I had planned but did not have time for a long time.

  • All places now use constructors that do invariant checking on the struct being created.
  • Translate* APIs had a soundness bug you could create uncompressed keys in segwit descriptors etc.

@apoelstra
Copy link
Member

These look great! Only nits are that I think in a couple cases you could've cleaned up some map_err calls, but I'm not sure and I didn't feel strongly enough to actually try my ideas to see if they compiled.

I'm not thrilled about some of the expects done during translation of keys, say, but they're fine for now. I'm a little tempted to add a translate_pk_unchecked or something but that can wait for a future PR and more discussion.

apoelstra
apoelstra previously approved these changes Dec 3, 2022
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 2b40679

@sanket1729
Copy link
Member Author

sanket1729 commented Dec 3, 2022

These look great! Only nits are that I think in a couple cases you could've cleaned up some map_err calls,

Perhaps, it might be time for clippy in rust-miniscript? It is great is suggesting idiomatic things when possible. Given that it is already existing in rust-bitcoin, we can add it here.

@sanket1729
Copy link
Member Author

Rebased. But based on #537

@sanket1729
Copy link
Member Author

Rebased after #537

src/lib.rs Outdated
/// # Errors
///
/// This function will return an error if the Error is OutError.
pub fn try_into_translator_err(self) -> Result<E, Self> {
Copy link
Member

Choose a reason for hiding this comment

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

In a3019c7:

Since you exclusively use this function to assert, I think you should just call it unwrap_translator_err and have it panic if it gets an OuterError. I find the current name try_into_translator_err hard to understand, and each time you call it you've got a separate variant of expect("outer errors can't happen") which is also hard to understand.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think the point of try into is to explicitly have this message. There are different reasons why this might not fail. BIP32 derivations/translations we know that are not going to be fail etc.

And having a string message as a small comment is helpful rather than unwrap thing because it at least forces me to think and write why it might not fail

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 call it expect_translator_err and take a string?

@apoelstra
Copy link
Member

ack a3019c7 except for the one comment.

@sanket1729
Copy link
Member Author

Added one commit to address the issue.

@apoelstra
Copy link
Member

3ebdf4c does not compile.

But ACK 1a3a944 otherwise.

Miniscript should only be called with two constructors. from_ast and
from_components_unchecked
Each context has slightly different rules on what Pks are allowed in descriptors

Legacy/Bare does not allow x_only keys
SegwitV0 does not allow uncompressed keys and x_only keys
Tapscript does not allow uncompressed keys

Note that String types are allowed everywhere
This fixes of the long last standing bug in rust-miniscript that allowed
creating unsound miniscript using the translate APIs
@sanket1729
Copy link
Member Author

Fixed and force pushed

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 b90cdda

@apoelstra apoelstra merged commit ad3d736 into rust-bitcoin:master May 24, 2023
gruve-p pushed a commit to Groestlcoin/rust-miniscript that referenced this pull request Aug 28, 2023
b90cdda Change try_into_translator_err to expect_translator_err (sanket1729)
be07a9c Update TranslatePk again (sanket1729)
ee8de9a Cleanly check validity rules for DescriptorKeys (sanket1729)
fa2e8b4 Cleanup Miniscript constructors (sanket1729)

Pull request description:

  This PR has lot of cleanups that I had planned but did not have time for a long time.

  - All places now use constructors that do invariant checking on the struct being created.
  - Translate* APIs had a soundness bug you could create uncompressed keys in segwit descriptors etc.

ACKs for top commit:
  apoelstra:
    ACK b90cdda

Tree-SHA512: d1c7001650b55c018d6e395628cb3cb8e5d15540c24b696946d370202e6ccc82b376b7f18c1138fdbd83a550fef0e39dc8b44fd670019dc4854b87a67cdc41c7
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.

2 participants