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

txscript: modify TweakTaprootPrivKey to operate on private key copy #1905

Merged
merged 1 commit into from
Nov 8, 2022

Conversation

Roasbeef
Copy link
Member

In this commit, we fix an inadvertent mutation bug that would at times cause the private key passed into the tweak function to actually be modified in place.

We fix this by accepting the value instead of a pointer. The actual private key struct itself contains no pointer fields, so this is effectively a deep copy via dereference.

We also add a new unit test that fails w/o this change, to show that the private key was indeed being modified.

In this commit, we fix an inadvertent mutation bug that would at times
cause the private key passed into the tweak function to actually be
*modified* in place.

We fix this by accepting the value instead of a pointer. The actual
private key struct itself contains no pointer fields, so this is
effectively a deep copy via dereference.

We also add a new unit test that fails w/o this change, to show that the
private key was indeed being modified.
@coveralls
Copy link

Pull Request Test Coverage Report for Build 3341596452

  • 1 of 2 (50.0%) changed or added relevant lines in 2 files are covered.
  • 20 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.3%) to 73.301%

Changes Missing Coverage Covered Lines Changed/Added Lines %
txscript/sign.go 0 1 0.0%
Files with Coverage Reduction New Missed Lines %
connmgr/connmanager.go 2 86.07%
peer/peer.go 18 73.2%
Totals Coverage Status
Change from base Build 3325120972: 0.3%
Covered Lines: 14430
Relevant Lines: 19686

💛 - Coveralls

@guggero guggero self-requested a review October 28, 2022 07:31
Copy link
Collaborator

@guggero guggero left a comment

Choose a reason for hiding this comment

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

Nice, fix, LGTM 🎉

Copy link
Collaborator

@Crypt-iQ Crypt-iQ left a comment

Choose a reason for hiding this comment

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

very tricky

@guggero guggero merged commit 14bb56f into btcsuite:master Nov 8, 2022
Roasbeef added a commit to Roasbeef/btcd that referenced this pull request Nov 9, 2022
This is a fix similar to btcsuite#1905.
We'll always make a copy of the key in the local scope before passing it
around elsewhere. Depending on the parity of the public key, the private
key itself might need to be negated.

A similar test is added here that fails without the patch to the
signature.go file.
Roasbeef added a commit to Roasbeef/btcd that referenced this pull request Nov 9, 2022
This is a fix similar to btcsuite#1905.
We'll always make a copy of the key in the local scope before passing it
around elsewhere. Depending on the parity of the public key, the private
key itself might need to be negated.

A similar test is added here that fails without the patch to the
signature.go file.
guggero pushed a commit that referenced this pull request Nov 9, 2022
This is a fix similar to #1905.
We'll always make a copy of the key in the local scope before passing it
around elsewhere. Depending on the parity of the public key, the private
key itself might need to be negated.

A similar test is added here that fails without the patch to the
signature.go file.
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.

4 participants