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

tapgarden: tapscript tree support for minting anchor outputs #768

Merged
merged 19 commits into from
Feb 27, 2024

Conversation

jharveyb
Copy link
Contributor

@jharveyb jharveyb commented Jan 16, 2024

Fixes #343.

Adding support for a batch key tapscript sibling first (BTC anchor-level), which would be supplied during the Finalize call for the batch. This should be a smaller change than per-asset support, while still using similar interfaces and DB changes.

TODOs:

  • unit tests for taptree en/decode
  • unit tests for tapscript sibling during Finalize call

I think given the related DB changes the per-asset sibling support should be in this PR (adding further TODOs) vs. a separate PR, but that may cause some commit reordering later on.


This change is Reviewable

@jharveyb jharveyb self-assigned this Jan 17, 2024
@jharveyb jharveyb linked an issue Jan 17, 2024 that may be closed by this pull request
3 tasks
@jharveyb
Copy link
Contributor Author

itests are panicking as the DB-backed implementation of TapscriptTreeStore is not wired up yet.

@dstadulis dstadulis requested a review from Roasbeef January 22, 2024 16:37
@dstadulis dstadulis added this to the v0.4 milestone Jan 22, 2024
@dstadulis
Copy link
Collaborator

Next milestone for the PR:
Have the unit tests passing

We will try to split up the PR. if the itest test be modified to be independent to the DB changes, PR would be possible to be split.

@jharveyb jharveyb force-pushed the minting_tap_tree_support branch from 026d404 to 77cf410 Compare January 23, 2024 07:03
@jharveyb jharveyb marked this pull request as ready for review January 23, 2024 17:53
@jharveyb jharveyb requested review from guggero and ffranr and removed request for Roasbeef January 23, 2024 17:53
@jharveyb
Copy link
Contributor Author

Proof generation during minting now includes the tapscript sibling, and this includes the fixes for tapscript preimage verification.

The DB implementation will be a follow-on PR.

@jharveyb jharveyb changed the title WIP: tapscript tree support during minting tapgarden: tapscript tree support for minting anchor outputs Jan 23, 2024
@Roasbeef Roasbeef requested review from Roasbeef and removed request for guggero January 23, 2024 19:53
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.

Nice work! This helps us cover the ability to use custom tapscript trees at the top-level Bitcoin output. Spotted a few areas we can use some new types to avoid nil pointer checks when we want an arg to actually be optional w/o relying on any specific pointer semantics.

I think to round out this PR, we'll want to make a concrete implementation for the new tree store in the DB. We can denormalize a bit by having a table that refs an internal key and then build out the tree storage in another table to be ref'd as a foreign key. This'll let us de-dup a bit, as we can have the tree storage primary key be the root hash.

Then we can add an itest to ensure that we can spend from the output using normal keypend. From there we can opt to push out the final component of accepting a valid witness somehow (send call that uses a PSBT?) so we can make further progess on the group key component.

asset/encoding.go Outdated Show resolved Hide resolved
asset/encoding.go Outdated Show resolved Hide resolved
asset/encoding.go Outdated Show resolved Hide resolved
asset/mock.go Outdated Show resolved Hide resolved
internal/test/helpers.go Show resolved Hide resolved
tapgarden/batch.go Outdated Show resolved Hide resolved
tapgarden/caretaker.go Show resolved Hide resolved
tapgarden/caretaker.go Outdated Show resolved Hide resolved
// Enforce that it is not including another Taproot Asset commitment.
if bytes.Contains(preimage, TaprootAssetsMarker[:]) {
// Verify that the script is not including a Taproot Asset commitment.
if IsTaprootAssetCommitmentScript(script) {
Copy link
Member

Choose a reason for hiding this comment

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

I think ok as is if we want to keep the exiting control flow, but in the future I'd like to re-work the control flow to assert all the preconditions up front, then have this just be a dumb method that computes the tap leaf hash.

Choose a reason for hiding this comment

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

agree.. Dumb method "TapLeafHash" and smart method which checks whatever validity constraints on the leaf

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Went with always enforcing these checks before computing the TapHash, as sometimes we're initializing TapscriptPreimage from a decoded Proof vs. using a safe constructor.

commitment/taproot.go Outdated Show resolved Hide resolved
commitment/taproot.go Outdated Show resolved Hide resolved
commitment/taproot.go Outdated Show resolved Hide resolved
commitment/taproot.go Outdated Show resolved Hide resolved
@jharveyb
Copy link
Contributor Author

Expanding this PR to include the DB implementation and a itest that will cover a key-spend & script spend of the minting output.

commitment/taproot.go Outdated Show resolved Hide resolved
@ffranr ffranr removed their request for review January 25, 2024 16:50
@jharveyb jharveyb force-pushed the minting_tap_tree_support branch 3 times, most recently from 2f06c7c to fb4df87 Compare January 30, 2024 23:43
asset/asset.go Outdated Show resolved Hide resolved
asset/asset.go Outdated Show resolved Hide resolved
asset/asset.go Show resolved Hide resolved
asset/encoding.go Show resolved Hide resolved
asset/encoding.go Show resolved Hide resolved
commitment/taproot.go Outdated Show resolved Hide resolved
commitment/taproot.go Outdated Show resolved Hide resolved
rpcserver.go Outdated Show resolved Hide resolved
rpcserver.go Outdated Show resolved Hide resolved
tapgarden/planter_test.go Show resolved Hide resolved
@jharveyb jharveyb force-pushed the minting_tap_tree_support branch 3 times, most recently from 268dd37 to 7b130ff Compare February 5, 2024 16:34
@jharveyb
Copy link
Contributor Author

jharveyb commented Feb 5, 2024

Latest push adds a DB implementation of TapscriptTreeManager, without unit tests. We also flesh out the TapscriptTreeNodes type, which represents the two formats we'll accept for tapscript trees on the RPC, and store tapscript trees on disk.

Remaining TODOs, in descending priority order:

  • tapdb unit tests for implementation of TapscriptTreeManager
  • DB changes to add tapscript sibling hash for minting batches + accompanying unit test coverage
  • Itest with a non-empty minting batch tapscript tree + script path spend of minting UTXO
  • Refactor commitment.TapscriptPreimage type to use safe constructors and getters, extend test coverage for tapscript sibling validation
  • Examine restart-safety for TapscriptTreeManager operations

@jharveyb jharveyb force-pushed the minting_tap_tree_support branch from f17b2d7 to cbac1e1 Compare February 23, 2024 18:22
@jharveyb jharveyb requested review from guggero and Roasbeef February 23, 2024 18:42
@jharveyb
Copy link
Contributor Author

Pushed final update with some commits in the middle to finish making commitment.TapscriptPreimage a safer type. Added extra validation logic to constructors but also TapHash() itself, as that gets used in proof validation logic on a preimage decoded directly from a proof file (so no checks were performed before that call).

Looks like I've introduced a flake to the multi-asset group itest + changed the preimage encoding unintentionally, investigating now. The intent is to not change the preimage encoded format in this PR.

Rebased + test issues are resolved, ready for final review.

Copy link
Member

@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.

Awesome, LGTM 🎉

asset/interface.go Outdated Show resolved Hide resolved
tapgarden/interface.go Show resolved Hide resolved
tapgarden/planter.go Show resolved Hide resolved
In this commit, we introduce the TapscriptTreeManager. This interface
stores a tapscript tree associated with a root hash, which could be a
stored alongside a batch key, asset script key, or group key.
This commit adds three new tables that enable us to store tapscript
trees, with deduplication of tapscript leaves. A tree can also be stored
as two TapHashes representing a TapBranch, allowing for externally
managed tapscript trees. These tables are not intended to be modified
with the basic queries added in this commit, but wrapper functions in
the next commit.
In this commit, we expose helpers to upsert and delete tapscript trees.
These are used to add support for tapscript trees during minting.
In this commit, we remove an overly strict version check when asserting
that a Tapscript script is not a Taproot Asset Commitment. All versions,
including unknown future versions, should be rejected in this context.
In this commit, we update how tapscript preimages are validated before
use. We define safe constructors for tapscript preimages, and require
their use by making the raw preimage bytes private. We also add checks
when decoding a preimage to further prevent improper construction.
@jharveyb jharveyb force-pushed the minting_tap_tree_support branch from cbac1e1 to 35c8156 Compare February 26, 2024 20:02
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.

LGTM 🦖

@Roasbeef Roasbeef merged commit bab8f11 into main Feb 27, 2024
14 checks passed
@guggero guggero deleted the minting_tap_tree_support branch February 27, 2024 07:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

tapgarden/taprpc: permit providing a tapscript sibling hash for minting calls
5 participants