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

Part 1: Asset Minting with V1 Asset Group Key and Chantools Cold Storage Support #1272

Merged
merged 27 commits into from
Jan 16, 2025

Conversation

ffranr
Copy link
Contributor

@ffranr ffranr commented Jan 3, 2025

This PR builds on Oli's WIP to demonstrate asset minting using the new V1 asset group key formulation. It integrates chantools to mint assets with an external asset group signing key (taproot internal key), offering a viable option for users who wish to keep their asset group signing key in cold storage.

A new integration test is included to simulate user behavior by leveraging chantools via the command line. The test verifies that the minter can successfully sign an asset into the asset group using the external asset group signing key.


Notes for Reviewers

Work which will be included in a future PR(s), ordered by most important first:

TODO(guggero/ffranr): Replace this step by allowing the CLI to take the signed
PSBT instead. We can list the batch to get the asset ID of each pending asset
and match the PSBT's input previous output to find out what signed PSBT belongs
to what asset (in case there are multiple).
  • itest: ensure minter can spend asset minted using external key.
  • Unit tests for ExternalKey type and methods (draft: Add unit test for method ExternalKey.PubKey #1284)
  • Unit tests for method PendingAssetGroup.PSBT.
  • Add unit tests for CLI arg parsing before calling into RPC.

@ffranr ffranr self-assigned this Jan 3, 2025
@dstadulis dstadulis requested a review from GeorgeTsagk January 6, 2025 15:32
@dstadulis dstadulis added this to the v0.6 milestone Jan 6, 2025
@ffranr ffranr force-pushed the cold-group-key branch 3 times, most recently from c766bbe to cabfd1d Compare January 8, 2025 15:30
@coveralls
Copy link

coveralls commented Jan 8, 2025

Pull Request Test Coverage Report for Build 12808414882

Details

  • 214 of 772 (27.72%) changed or added relevant lines in 11 files are covered.
  • 20 unchanged lines in 7 files lost coverage.
  • Overall coverage decreased (-0.2%) to 40.723%

Changes Missing Coverage Covered Lines Changed/Added Lines %
proof/mint.go 7 11 63.64%
tapdb/assets_common.go 40 47 85.11%
cmd/tapcli/assets.go 0 49 0.0%
rpcserver.go 0 68 0.0%
tapgarden/planter.go 106 193 54.92%
itest/utils.go 0 112 0.0%
asset/asset.go 46 161 28.57%
itest/chantools_harness.go 0 116 0.0%
Files with Coverage Reduction New Missed Lines %
tapdb/addrs.go 2 75.12%
commitment/tap.go 2 84.32%
asset/asset.go 2 75.59%
tapgarden/planter.go 3 71.15%
rpcserver.go 3 0.0%
universe/interface.go 4 51.95%
tapgarden/caretaker.go 4 68.87%
Totals Coverage Status
Change from base Build 12791730946: -0.2%
Covered Lines: 26528
Relevant Lines: 65142

💛 - Coveralls

@ffranr ffranr force-pushed the cold-group-key branch 2 times, most recently from 8af293f to 4666b23 Compare January 9, 2025 02:19
@ffranr ffranr marked this pull request as ready for review January 9, 2025 02:19
@ffranr ffranr requested a review from gijswijs January 9, 2025 02:19
@ffranr ffranr force-pushed the cold-group-key branch 2 times, most recently from 1e543e2 to e61d638 Compare January 9, 2025 02:29
@ffranr
Copy link
Contributor Author

ffranr commented Jan 9, 2025

I think these are the necessary changes. This PR can't really be made smaller in any meaningful way.

@ffranr ffranr changed the title Asset Minting with V1 Asset Group Key and Chantools Cold Storage Support Part 1: Asset Minting with V1 Asset Group Key and Chantools Cold Storage Support Jan 9, 2025
@ffranr
Copy link
Contributor Author

ffranr commented Jan 10, 2025

As mentioned during our last call, I’ve updated taproot-assets/tapdb/sqlc/migrations/000026_asset_group_version_customsubtree.down.sql to include the recreation of the previous version of key_group_info_view as part of the down migration. While we’re not actively using down migrations, it’s still beneficial to have this in place as a precaution.

taprpc/mintrpc/mint.proto Show resolved Hide resolved
asset/asset.go Show resolved Hide resolved
cmd/tapcli/assets.go Show resolved Hide resolved
cmd/tapcli/assets.go Show resolved Hide resolved
taprpc/mintrpc/mint.proto Show resolved Hide resolved
tapgarden/planter.go Show resolved Hide resolved
taprpc/mintrpc/mint.proto Show resolved Hide resolved
tapdb/assets_common.go Show resolved Hide resolved
itest/mint_fund_seal_test.go Show resolved Hide resolved
Copy link
Contributor

@gijswijs gijswijs left a comment

Choose a reason for hiding this comment

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

Great work. I have added some small comments throughout.

nit: the commit message of commit a993070 claims the commit populates the external key in the seedling instance, but I don't think that happens in that commit.

I would love to see a itest that tests the re-issuance of an asset with cold minting.

Would also like to see a unit test that tests both the V0 and the V1 flow re GroupTapscriptRoot and a custom tapscript root. Whatever approach we take regarding implicit or explicit flow @Roasbeef suggested, we will end up with two separate flows that are currently not fully covered by unit tests.

asset/asset.go Outdated Show resolved Hide resolved
taprpc/mintrpc/mint.proto Show resolved Hide resolved
asset/asset.go Show resolved Hide resolved
tapdb/sqlc/queries/assets.sql Outdated Show resolved Hide resolved
Introduce a new method to support future usage in the tapgarden package.
Refactored the `FundBatch` method to use a general return type,
`FundBatchResp`. This change improves code health and allows for
easier extension by enabling the state machine to return additional
fields in the future.
ffranr and others added 5 commits January 15, 2025 21:31
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.
@ffranr ffranr requested review from Roasbeef and removed request for Roasbeef January 16, 2025 00:29
@ffranr ffranr disabled auto-merge January 16, 2025 00:47
Copy link
Member

@GeorgeTsagk GeorgeTsagk left a comment

Choose a reason for hiding this comment

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

LGTM, +tACK 🥇
great work!

ffranr and others added 10 commits January 16, 2025 10:56
Extended the `asset_groups` database table with two new columns:
`version` and `custom_subtree_root_id`. These fields are required
to store and retrieve new GroupKey data for use during mint proof
generation, where the group key reveal is formulated.

`custom_subtree_root_id` is a foreign key referencing the `root_id` in
the `tapscript_roots` table. It links a custom tapscript subtree to the
asset group, enabling an upgrade path towards storing user-defined asset
group key scripts. This column can be `NULL` when no custom subtree is
associated.
Write the group key version and custom subtree root to the database.
Read group key version and custom subtree root 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.
Add a new integration test, `testMintExternalGroupKeyChantools`, to
validate minting two assets into the same asset group across two
different batches. The test ensures asset group signatures are
generated using chantools with an externally managed signing key for
each batch.
Add externalKey and customTapscriptRoot arguments to the mock function
NewGroupKeyRequestNoErr, enabling them to be specified during testing.
Add TestAssetGroupV1 to verify the ability to store and load an
asset group of version 1.
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.

7 participants