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

PoC: Use tweaked NUMS key for non-spendable Taproot script leaves #1289

Closed
wants to merge 23 commits into from

Conversation

ffranr
Copy link
Contributor

@ffranr ffranr commented Jan 10, 2025

This serves as a PoC which we should be able to use to test hardware wallets. This PR does not include all necessary doc updates.

This PR updates the NewNonSpendableScriptLeaf function to use a deterministic tweaked NUMS (Nothing-Up-My-Sleeve) key for generating non-spendable Taproot leaves. The previous OP_RETURN-based approach is replaced with a pk(data) Miniscript script (<pubkey> OP_CHECKSIG), ensuring broader compatibility with modern hardware wallets.


Notes for Reviewers

@ffranr ffranr self-assigned this Jan 10, 2025
@ffranr
Copy link
Contributor Author

ffranr commented Jan 10, 2025

With this change. tapd nodes v0.5 and older will fail to validate new group key V1 assets.

@ffranr ffranr requested a review from gijswijs January 10, 2025 17:04
@coveralls
Copy link

coveralls commented Jan 10, 2025

Pull Request Test Coverage Report for Build 12773308187

Details

  • 22 of 22 (100.0%) changed or added relevant lines in 1 file are covered.
  • 25 unchanged lines in 7 files lost coverage.
  • Overall coverage increased (+0.02%) to 40.785%

Files with Coverage Reduction New Missed Lines %
internal/test/helpers.go 2 86.95%
fn/option.go 3 43.3%
asset/mock.go 3 92.42%
tapgarden/caretaker.go 4 68.5%
commitment/tap.go 4 83.86%
asset/asset.go 4 75.7%
universe/interface.go 5 50.65%
Totals Coverage Status
Change from base Build 12772802270: 0.02%
Covered Lines: 26523
Relevant Lines: 65032

💛 - Coveralls

@ffranr ffranr force-pushed the nums-non-spend-leaves branch from af75235 to f6a7f79 Compare January 10, 2025 19:50
@ffranr ffranr changed the title Use tweaked NUMS key for non-spendable Taproot script leaves PoC: Use tweaked NUMS key for non-spendable Taproot script leaves Jan 10, 2025
@dstadulis dstadulis added this to the v0.6 milestone Jan 10, 2025
@ffranr ffranr force-pushed the nums-non-spend-leaves branch 2 times, most recently from d09b5bf to a8ddd78 Compare January 12, 2025 19:34
@ffranr ffranr removed the request for review from gijswijs January 13, 2025 15:00
ffranr and others added 20 commits January 14, 2025 16:12
Introduced a `newVerboseBatch` function to create a verbose mint
batch from a regular mint batch. This functionality is extracted
from the existing list batch logic as part of a refactor.

The function will be used in a future commit to include a verbose
batch in the response of the FundBatch RPC endpoint.
Added comments to the planter function `buildGroupReqs` to improve
code readability and explain the logic more clearly.
Introduce a guide outlining the workflow for using external group
keys. Future commits in this PR will add features and implement
changes to support the described workflow.
The FundBatch RPC endpoint now returns a verbose batch instead of a
regular batch. The verbose batch includes additional asset group
information required by external signers.
Added a new `ExternalKey` message type to represent an external key
used for deriving and managing HD wallet addresses per BIP-86.

A new field of type `ExternalKey` was added to the `MintAsset` message,
enabling the specification of an external key when a mint request is
added to the batch.
Introduce a new `ExternalKey` type and add external key fields of this
type to `Seedling` and `GroupKeyRequest`.
Add unmarshalling support for the new `Asset.ExternalGroupKey` field
in the `MintAsset` RPC endpoint.
Add an `external_key` field to the `GroupKeyRequest` RPC message,
which will also make it available in the `UnsealedAsset` RPC message.

Include marshalling functionality for the new field.
Added the following command line minting flags:
- group_key_xpub
- group_key_derivation_path
- group_key_fingerprint
Updated the documentation for the `MintAsset.group_tapscript_root`
field to clarify its purpose: it now represents the custom tapscript
subtree root for V1 group key reveals and serves as the tapscript tree
root for V0 group key reveals.
Add the `CustomTapscriptRoot` field to both the `GroupKey` and
`GroupKeyRequest` types. This field stores the user-defined custom
tapscript subtree root, which is committed to by the asset group key.

Update the `buildGroupReqs` function to leverage this new field when
constructing group key requests for generating asset group keys.
Introduce a new `GroupKeyVersion` type to represent the group key
version in `asset.GroupKey` and `asset.GroupKeyRequest`.

Add a `version` field to both `asset.GroupKey` and
`asset.GroupKeyRequest`, with logic to populate it. Enhance the
verification process by adding version-specific checks.
Update `GroupKeyRequest` methods to support the generation of
version 1 (V1) group keys.
Add a new PSBT field to the `UnsealedAssets` RPC message type, which
contains the byte-serialized PSBT equivalent of the group virtual
transaction for unsealed assets. As a result, the `FundBatch` and
`ListBatches` RPC endpoints now return group virtual PSBTs.

Include logic to generate the group virtual PSBT. The PSBT is unsigned
and is provided to allow signing with an external cold private key.
Extended the `asset_groups` database table with two new columns:
`rows_version` and `custom_subtree_root`. These fields are required
to store and retrieve new GroupKey data for use during mint proof
generation, where the group key reveal is formulated.
Ensured the `version` and `custom_subtree_root` columns are
populated with the appropriate GroupKey data when storing a
group key in the database.
Implemented parsing logic for the `version` and `custom_subtree_root`
fields when reading from the database.
Added support for group key reveal V1 alongside the existing
group key reveal V0 when generating mint proofs.
Adds a test to ensure the new PSBT field introduced in the previous
commit can be used to derive a transaction identical to the group
virtual transaction.
Update the `build-itest` Makefile target, used as a subcommand during
`make itest`, to ensure `chantools` is properly set up for integration
tests.

Additionally, update `.gitignore` to exclude the `chantools` build
directory.
Add a test harness to execute the chantools binary via the command line
and parse its output.
Added a new integration test, `testMintExternalGroupKeyChantools`,
to verify the ability to mint an asset and generate an asset group
signature using chantools with an externally managed signing key.
This Proof-of-Concept demonstrates the NUMS-tweak formulation for
hardware wallet testing.

The NewNonSpendableScriptLeaf function now generates non-spendable
Taproot leaves using a deterministic NUMS (Nothing-Up-My-Sleeve) key,
tweaked with arbitrary data. This replaces the previous raw OP_RETURN
approach with a `pk(data)` Miniscript script (`<pubkey> OP_CHECKSIG`),
improving compatibility with current hardware wallets.
@ffranr ffranr force-pushed the nums-non-spend-leaves branch from a8ddd78 to f277228 Compare January 14, 2025 17:41
@ffranr ffranr force-pushed the cold-group-key branch 4 times, most recently from b801f9f to 5ca4168 Compare January 16, 2025 12:01
@guggero
Copy link
Member

guggero commented Jan 16, 2025

I agree that this mathematically is correct as well. But let's go with #1290 instead, as that's a bit more formal and introduces code that we might be able to use in another context in the future.

Base automatically changed from cold-group-key to main January 16, 2025 12:33
@ffranr
Copy link
Contributor Author

ffranr commented Jan 16, 2025

Close in favour of #1290

@ffranr ffranr closed this Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

4 participants