Skip to content

taproot signatures should be serialized as 64 bytes#5

Merged
zebra-lucky merged 2 commits into
zebra-lucky:add-secp256k1-trfrom
conduition:add-secp256k1-tr
Apr 26, 2024
Merged

taproot signatures should be serialized as 64 bytes#5
zebra-lucky merged 2 commits into
zebra-lucky:add-secp256k1-trfrom
conduition:add-secp256k1-tr

Conversation

@conduition
Copy link
Copy Markdown

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.

//
// where h is the cofactor
let R = C::effective_nonce_element(signature.R);
let R = signature.R;
Copy link
Copy Markdown
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
Copy Markdown
Owner

Haha!)

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

@zebra-lucky
Copy link
Copy Markdown
Owner

zebra-lucky commented Apr 26, 2024

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

@zebra-lucky
Copy link
Copy Markdown
Owner

cargo test

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

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

@conduition
Copy link
Copy Markdown
Author

My pleasure :D

@zebra-lucky
Copy link
Copy Markdown
Owner

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

@zebra-lucky
Copy link
Copy Markdown
Owner

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

@zebra-lucky
Copy link
Copy Markdown
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