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 docs to mention ECDSA #643

Merged
merged 1 commit into from
Aug 20, 2023

Conversation

tcharding
Copy link
Member

PublicKey types are for verifying ECDSA signatures, when these docs where written there were no other types of signatures. With the addition of taproot these docs have become stale.

@tcharding
Copy link
Member Author

tcharding commented Aug 9, 2023

@apoelstra is this PR correct? If it is, why do we provide conversion from one pubkey to another (PublicKey and XOnlyPublicKey) and back? Is it just out of convenience because both pubkeys could come from the same secret even though they are used for different things?

@apoelstra
Copy link
Member

The PR is fine, but public keys are used for other things (and were used for other things even when this text was written). Do you want it to reflect the exact set of all things public keys are used for? If so, it needs to be significantly broadened.

@tcharding
Copy link
Member Author

tcharding commented Aug 11, 2023

That was cool, I just got lost, as they say, down the rabbit hole, reading cryptography stuff. How'd I go?

src/key.rs Outdated
/// Secret key - a 256-bit key used to create ECDSA and schnorr signatures.
///
/// A point on the secp256k1 curve i.e., a positive 256-bit integer guaranteed to be less than the
/// secp256k1 curve order.
Copy link
Member

Choose a reason for hiding this comment

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

A scalar isn't a point -- and while we often encode scalars as integers, mathematically they aren't integers, so I think describing them as such is a little misleading.

Copy link
Member Author

Choose a reason for hiding this comment

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

Gee I botched that up. I removed the whole line. They aren't referred to as integers because we don't do integer math on them? Is it because they are members of a field, is that right? (Not adding as docs, just for my understanding.)

Copy link
Collaborator

@Kixunil Kixunil Oct 28, 2023

Choose a reason for hiding this comment

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

@tcharding integers are in Z, scalars are in Zn where n is the curve order.

Copy link
Member Author

Choose a reason for hiding this comment

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

Cool, cheers.

src/key.rs Outdated
/// A Secp256k1 public key, used for verification of signatures.
/// Public key - a point on the secp256k1 curve.
///
/// Obtained by multiplying a secret key scalar by G (the generator point).
Copy link
Member

Choose a reason for hiding this comment

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

This is true, but I think it's a little too technical for a doccomment.

Copy link
Member Author

Choose a reason for hiding this comment

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

No worries, removed.

src/key.rs Outdated
/// An x-only public key - the X co-ordinate of a point on the secp256k1 curve.
///
/// To convert to a point (`PublicKey`) one must choose the [`Parity`] of the Y co-ordinate. When
/// used to create schnorr signatures the Y co-ordinate is always positive.
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 coordinate shouldn't have a -. I would also say "Taproot signature" rather than "schnorr signature".

Copy link
Member Author

Choose a reason for hiding this comment

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

re: schnorr vs taproot I thought here in secp we used schnorr and in bitcoin used "taproot". There are zero other occurrences of "taproot" currently in this crate (except some secp-sys test code)? I'm not arguing for or against just asking.

@tcharding
Copy link
Member Author

This is low priority @apoelstra, I'm basically taking free lessons from you :)

@tcharding tcharding force-pushed the 08-09-pubkey-docs branch 2 times, most recently from e8e9ce9 to 7fd90f7 Compare August 11, 2023 21:22
@tcharding
Copy link
Member Author

O boy, there are many uses x vs X (y vs Y) and coordinate vs co-ordinate all over this crate. Leaving that for another brain fried Friday afternoon job.

@apoelstra
Copy link
Member

I dunno about describing keys as "ponits on the secp256k1 curve". I guess that's fine, and technically correct, but it's really not relevant to users and it doesn't expose any methods to do generic EC operations on it.

@tcharding
Copy link
Member Author

tcharding commented Aug 11, 2023

Ok, I think you better tell me, or point me to some docs please about what exactly public keys can be used for so I can write these docs. Again, its totally non-urgent though. I can also look it up later on, its Saturday morning here, I was just doing a quick thing or two before the kids woke up.

@apoelstra
Copy link
Member

I think it's fine to say that public keys can be used to verify signatures. They can also be used for ECDH handshakes and for Taproot tweaks.

@tcharding
Copy link
Member Author

Another attempt at the worlds hardest trivial PR :)

@tcharding
Copy link
Member Author

Note that I change the docs for XOnlyPublicKey to say "- used to verify Taproot signatures". Should we mention anything else e.g., about tweaking?

@apoelstra
Copy link
Member

@tcharding I think this one goes in the wrong direction. What's important about a public key is that it can be used to verify signatures, not that it's a point on an elliptic curve. If you want to mention EC stuff that's probably fine but it shouldn't be the primary thing.

@tcharding tcharding force-pushed the 08-09-pubkey-docs branch 2 times, most recently from 844277e to f140750 Compare August 17, 2023 00:16
@tcharding
Copy link
Member Author

Removed the changes to XOnlyPublicKey.

@apoelstra
Copy link
Member

Looking better :). I would replace schnorr with Taproot or BIP340. I also think we could drop the mention of ECDH from the PublicKey description. Yes, pubkeys are used for ECDH, but this is a bit of a niche usecase.

@tcharding
Copy link
Member Author

Now includes one change of schnorr -> Taproot, there are more places we could do this but I think that is scope creep. I'm not sure if we want the "and serialized according to BIP-340" bit on XOnlyPublicKey when none of the other keys mention serialization in the comment header?

/// An x-only public key, used for verification of Taproot signatures and serialized according to BIP-340.

@apoelstra
Copy link
Member

I think it's fine to mention the encoding. We arguably could mention that other public keys are serialized according to SEC 2, but it's less informative since SEC2 is the standard (and pretty-much only) serialization for normal public keys. Vs x-only keys which are a creation of BIP340.

@apoelstra
Copy link
Member

@tcharding can you rebase this since #591 was merged?

Crypto is _hard_. Make an effort to improve the docs with a minimum of
exactly correct information.
@tcharding
Copy link
Member Author

Rebase only, no other changes.

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 aa4489c

@apoelstra apoelstra merged commit 83a2245 into rust-bitcoin:master Aug 20, 2023
@tcharding tcharding deleted the 08-09-pubkey-docs branch August 24, 2023 02:35
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