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

taproot signatures should be serialized as 64 bytes #5

Merged
merged 2 commits into from
Apr 26, 2024

Conversation

conduition
Copy link

updates ZcashFoundation#584 to serialize taproot signatures as 64 bytes, in compliance with BIP340.

BIP340 signatures are supposed to be serialized as a 64-byte array: 32 bytes for the x-only nonce point $R$, and 32 bytes for the signature component $s$. This PR customizes the frost-secp256k1-tr crate so that signatures are serialized with x-only nonces, omitting the leading parity byte. Instead of embedding global serialization logic in the methods of Signature, we now endow Ciphersuite with two optional methods to serialize and deserialize a Signature, and then replace those methods in the frost-secp256k1-tr crate.

To maintain reusability of the Signature type, i had to modify the DKG proof-of-knowledge so that we always hash the participant's effective verifying key, which in taproot is always the even-parity point. This allows the PoK to also be serialized as a 64-byte BIP340 signature. For all other ciphersuites, this change has no effect.

@@ -76,7 +76,7 @@ where
// h * ( z * B - c * A - R) == 0
//
// where h is the cofactor
let R = C::effective_nonce_element(signature.R);
let R = signature.R;
Copy link
Author

Choose a reason for hiding this comment

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

Before this PR, a Signature's R point could be either even or odd parity. When verifying, we were coercing R to be even, so that BIP340 verification logic would work.

After this PR, the Signature's R point is always even parity (unless someone manually constructs one with an odd-parity outside the scope of this library). We no longer need to do this coercion during verification.

BIP340 signatures are usually represented with x-only (even parity)
nonce points. As a step towards normalizing this for the frost-secp256k1-tr
crate, we should ensure all Signature struct instances always use the
effective nonce point, including the DKG proof-of-knowledge.
BIP340 signatures are supposed to be serialized as a 64-byte array:
32 bytes for the x-only nonce point 'R', and 32 bytes for the signature
component 's'. This commit customizes the frost-secp256k1-tr crate so
that signatures are serialized with x-only nonces, omitting the leading
parity byte.
@zebra-lucky
Copy link
Owner

Haha!)

Screenshot from 2024-04-26 20-32-57

@zebra-lucky
Copy link
Owner

zebra-lucky commented Apr 26, 2024

git fetch origin pull/5/head:pr5
git checkout pr5

@zebra-lucky
Copy link
Owner

cargo test

@zebra-lucky zebra-lucky merged commit d580241 into zebra-lucky:add-secp256k1-tr Apr 26, 2024
@zebra-lucky
Copy link
Owner

Tests seems to be passed. I'm tankful for @conduition.
Merging.

@conduition
Copy link
Author

My pleasure :D

@zebra-lucky
Copy link
Owner

I'm sorry for my slow reaction.
Your code look estimating.

@zebra-lucky
Copy link
Owner

I'm lost control by the last time...
Then thys slow reaction...

@zebra-lucky
Copy link
Owner

zebra-lucky commented Apr 26, 2024

estimating

wrong worlds -- I'm sorry... Your coding practices is impressive...
glad to se this..

i'm periodical off..

https://www.youtube.com/watch?v=NwC48kejSR8

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