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

fix(frost-secp256k1-tr): empty merkle root tweak should still hash the x-only pk #815

Merged
merged 1 commit into from
Dec 30, 2024

Conversation

0xBEEFCAF3
Copy link
Contributor

@0xBEEFCAF3 0xBEEFCAF3 commented Dec 18, 2024

I noticed that the addresses I was deriving with rust-bitcoin and the ones I created with the taptweak'd key using this library were not the same. The problem is in how the tweak is calculated in the absence of script paths.

Per BIP-341, if there are no script paths, the internal key should still be tapTweak'd by tG, where t = TaggedHash(P_x). Before this commit, the internal key and the Taproot output key were the same if no script paths were used. This is because the tweak was the 0 scalar value, so Q = P + tG = P.

It is worth noting that Bitcoin's consensus rules will accept a non-taptweak'd internal key as it verifies a signature against whatever public key is used in the witness program. So the outputs are still spendable; however, they deviate from the BIP-341 spec.

I also noticed that in post_dkg, we are tweaking by [0u8; 0]. However, the comment above it correctly states the tweak should be int(hashTapTweak(bytes(P)))G. I can change this code slightly to be:

Ok((
    key_package.tweak::<&[u8]>(None),
    public_key_package.tweak::<&[u8]>(None),
))

This should just tweak with the hash of the x-only pk. Just lmk, happy to make this change as well.

@mpguerra mpguerra requested a review from conradoplg December 19, 2024 14:28
Copy link
Contributor

@conradoplg conradoplg left a comment

Choose a reason for hiding this comment

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

Good catch, thanks. Looks good, but please include the change you mentioned to post_dkg if you can. Thanks!

Copy link

codecov bot commented Dec 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.54%. Comparing base (5f4ac6e) to head (4f57f63).
Report is 81 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #815      +/-   ##
==========================================
+ Coverage   82.18%   82.54%   +0.36%     
==========================================
  Files          31       41      +10     
  Lines        3188     4338    +1150     
==========================================
+ Hits         2620     3581     +961     
- Misses        568      757     +189     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

…e x-only pk

Per BIP-341 if there is no script paths the internal key should still be
tapTweak'd by tG where t = TaggedHash(P_x). Before this commit the
internal key and the taproot output key are the same if no script paths
are used. This is because the tweak is the 0 scalar value so Q = P + tG
= P.

It is worth noting that Bitcoin's consensus would still accept a
non-taptweak'd internal key as it verifies a signature against whatever
pk is used in the witness program. So the outputs are still spendable, however it deviates from the spec.
@0xBEEFCAF3
Copy link
Contributor Author

Good catch, thanks. Looks good, but please include the change you mentioned to post_dkg if you can. Thanks!

Done!

mergify bot added a commit that referenced this pull request Dec 30, 2024
@mergify mergify bot merged commit 39b61ec into ZcashFoundation:main Dec 30, 2024
20 checks passed
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