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: Add taproot address and signing capabilities #792

Merged
merged 10 commits into from Mar 22, 2022

Conversation

@Roasbeef
Copy link
Member

Dependent PR has been merged.

wallet/txauthor/go.mod Outdated Show resolved Hide resolved

replace github.com/btcsuite/btcd/btcec/v2 => github.com/guggero/btcd/btcec/v2 v2.0.0-20220214155024-51fd177d32c0

replace github.com/btcsuite/btcwallet/wallet/txauthor => ./wallet/txauthor
Copy link
Member

Choose a reason for hiding this comment

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

FWIW this was removed in a prior PR, but I can see how it's helpful to fully integrate things in one swoop. Otherwise, we can make a new PR that adds the new txscript stuff, then does a tag, then to have it integrated here ultimately.

wallet/createtx.go Show resolved Hide resolved
wallet/psbt.go Show resolved Hide resolved
waddrmgr/address.go Show resolved Hide resolved
waddrmgr/manager_test.go Outdated Show resolved Hide resolved
wallet/txauthor/author.go Outdated Show resolved Hide resolved
wallet/txauthor/author.go Show resolved Hide resolved
wallet/txauthor/author.go Outdated Show resolved Hide resolved
wallet/txauthor/author.go Show resolved Hide resolved
go.mod Outdated Show resolved Hide resolved
wallet/txauthor/go.mod Outdated Show resolved Hide resolved
@guggero guggero force-pushed the schnorr-taproot branch 2 times, most recently from 6e96598 to aca9822 Compare February 18, 2022 18:44
@guggero guggero force-pushed the schnorr-taproot branch 2 times, most recently from da559a8 to 6a78190 Compare February 21, 2022 16:42
@guggero guggero marked this pull request as ready for review February 22, 2022 15:59
@guggero
Copy link
Collaborator Author

guggero commented Feb 22, 2022

The PR is now ready for review! I'll take a look at the linter and unit test failures in a bit.

@guggero guggero force-pushed the schnorr-taproot branch 2 times, most recently from c253f14 to 6d1c60c Compare February 22, 2022 20:16
Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

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

Excellent PR!

Completed an initial review pass through the latest set of commits. I like how we don't bind the caller/user into a particular way and allow them to either use a single script path or just import the entire tree for tracking/spending purposes. This'll really be useful once we start to implement more advanced multi-sig and other script operations using the wallet.

Ultimately, we may want to start (from an lnd perspective) also importing our scripts into the wallet, but possibly with a non-default account type. In any case, that's beyond the scope of this PR.

Only lingering design question IMO is if we really need to distinguish between pure-keyspend and a mixed variant for addresses. I guess as is, we assume usage of BIP 86, so anything that doesn't use that should use this new import API instead.

wallet/txauthor/author.go Outdated Show resolved Hide resolved
waddrmgr/db.go Show resolved Hide resolved
waddrmgr/scoped_manager.go Outdated Show resolved Hide resolved
waddrmgr/address.go Outdated Show resolved Hide resolved
waddrmgr/address.go Show resolved Hide resolved
waddrmgr/tapscript.go Show resolved Hide resolved
waddrmgr/tapscript.go Show resolved Hide resolved
waddrmgr/tlv.go Show resolved Hide resolved
@Roasbeef
Copy link
Member

@carlaKC

@guggero guggero force-pushed the schnorr-taproot branch 2 times, most recently from f656436 to 2b6e334 Compare March 7, 2022 19:05
Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

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

Amazing PR!

The diff is looking really good from my PoV now. I think the only two things we'll want to do as follow up are:

  1. Ensure that on the lnd side, we have proper recovery working, which may need some additional modifications to the recovery/rescan logic. I think since it works at mostly a higher level and lets the waddrmgr derive the addresses it should be ok. It can also make optimizations like not scan for taproot addrs if an address was created before a certain height, but that may generate some false positives.
  2. (this one is a bonus imo) implement the PSBT parsing and assembly functionality.

waddrmgr/scoped_manager.go Show resolved Hide resolved
@guggero guggero force-pushed the schnorr-taproot branch 3 times, most recently from 75369b4 to cb37aec Compare March 9, 2022 19:01
As a preparation for when the identifier of a script isn't the hash of a
script in every case anymore, we extract that part out of the
importScriptAddress method and rename it.
Pay-to-Taproot script addresses use the x-only coordinates of a tweaked
public key as the address identifier.
To make integration of the upcoming taproot script address type a bit
easier, we allow returning a ManagedScriptAddress interface type in
newWitnessScriptAddress so we can re-use that function for the taproot
script address too.
@guggero
Copy link
Collaborator Author

guggero commented Mar 16, 2022

Rebased after the dependent PR has been merged.
Still need to verify the recovery of taproot addresses on the lnd side. But can always merge and create a bugfix later (will need a PR to remove the local replaces after pushing a tag anyway).

@Roasbeef
Copy link
Member

Still need to verify the recovery of taproot addresses on the lnd side. But can always merge and create a bugfix later (will need a PR to remove the local replaces after pushing a tag anyway).

Definitely, I think we can easily parametrize our existing integration tests for that, as they already test p2wkh/np2wkh, etc.

@guggero
Copy link
Collaborator Author

guggero commented Mar 18, 2022

Definitely, I think we can easily parametrize our existing integration tests for that, as they already test p2wkh/np2wkh, etc.

I added that integration test to lightningnetwork/lnd#6263, no issues found.

I also added a commit that exposes the ImportTaprootScript method on the wallet level (and not only on the scoped manager level). That method is now also used in a unit test in lnd.

I think with those two things tested end-to-end, this PR is ready to be merged.

Copy link

@positiveblue positiveblue left a comment

Choose a reason for hiding this comment

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

Great job on this one @guggero, really excited to see this ready to be merged 🎉

Copy link
Contributor

@carlaKC carlaKC left a comment

Choose a reason for hiding this comment

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

Great PR! Did a high level santiy pass, looks great.

I think that the distinction between TaprootAddress and TaprootScript discussed here will be useful, the two different use cases make sense to me.

)
}

// importScriptAddress imports a new pay-to-script or pay-to-witness-script
// address.
func (s *ScopedKeyManager) importScriptAddress(ns walletdb.ReadWriteBucket,
script []byte, bs *BlockStamp, addrType AddressType,
identity Identity, script []byte, bs *BlockStamp, addrType AddressType,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need to pass the identity closure in here vs just []byte?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

See comment here: #792 (comment)
Gives us the ability to use nicely named, pre-defined identity functions.

waddrmgr/address.go Outdated Show resolved Hide resolved
@Roasbeef Roasbeef merged commit b0001c2 into btcsuite:master Mar 22, 2022
@guggero guggero deleted the schnorr-taproot branch March 22, 2022 18:30
buck54321 pushed a commit to buck54321/btcwallet that referenced this pull request Apr 21, 2024
Taproot: Add taproot address and signing capabilities
buck54321 pushed a commit to buck54321/btcwallet that referenced this pull request Apr 21, 2024
Taproot: Add taproot address and signing capabilities
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.

None yet

5 participants