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

BIP 0340 followups #253

Merged

Conversation

apoelstra
Copy link
Member

Couple things on #237 that weren't done in the original PR.

let err = ffi::secp256k1_xonly_pubkey_tweak_add_check(
secp.ctx,
tweaked_ser.as_c_ptr(),
if tweaked_parity { 1 } else { 0 },
Copy link
Member

Choose a reason for hiding this comment

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

You can do tweaked_parity as u8

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh nice. Though I'd have to cast to a c_int ... with the export, the if statement is actually shorter, and in any case it's more explicit.

secp.ctx,
tweaked_ser.as_c_ptr(),
if tweaked_parity { 1 } else { 0 },
&self.0 as *const _,
Copy link
Member

Choose a reason for hiding this comment

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

Can you replace with self.0.as_c_ptr()?

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 don't think so, this is a FFI type not a byte array

Copy link
Contributor

Choose a reason for hiding this comment

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

References coerce to pointers, so you wouldn't actually need the cast: &self.0.

Copy link
Member Author

Choose a reason for hiding this comment

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

lol I had no idea. Added a commit which fixes this across the library.

tweaked_key: &Self,
tweaked_parity: bool,
tweak: &[u8],
) -> Result<(), Error> {
Copy link
Member

Choose a reason for hiding this comment

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

What do you think about passing tweak: [u8; 32] and then returning bool instead of a Result?
In general I feel like it would be nicer to use the type system to require sizes instead of adding dozens of results/errors (especially with TryFrom that let's you slice.try_into()? for converting to array, but that's 1.34)

Copy link
Member

Choose a reason for hiding this comment

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

if for ergonomic pre 1.34 reasons you want to keep it as a slice then that's ok

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah I think it'd be reasonable to use arrays here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Welll, for what it's worth we already have an error return here if the user passes an invalid tweak. If you know you're giving a hash then it can't fail, but that's still an error you have to .unwrap away.

I'm not sure there's any additonal ergonomics loss to using a slice.

Copy link
Member

@elichai elichai left a comment

Choose a reason for hiding this comment

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

LGTM

@apoelstra apoelstra merged commit 11e9641 into rust-bitcoin:master Dec 9, 2020
@apoelstra apoelstra deleted the 2020-11--schnorrsig-followup branch December 9, 2020 20:31
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.

None yet

3 participants