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

Add PSBT field to UnsealedAsset RPC message #1214

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ffranr
Copy link
Contributor

@ffranr ffranr commented Nov 22, 2024

The unsealed asset RPC message already includes a group_virtual_tx field. This PR enhances the message by adding a new field that contains the byte-serialized PSBT equivalent. This addition is intended to assist external signers in producing a group witness.

For an example of the external signer workflow, refer to testMintFundSealAssets.

This PR addresses the request in #1207.

Adds a new field to the ListBatches RPC endpoint response. This field
contains the byte-serialized PSBT equivalent of the group virtual
transaction field for unsealed assets.
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.
@coveralls
Copy link

Pull Request Test Coverage Report for Build 11977983479

Details

  • 0 of 22 (0.0%) changed or added relevant lines in 1 file are covered.
  • 47 unchanged lines in 9 files lost coverage.
  • Overall coverage decreased (-0.05%) to 41.185%

Changes Missing Coverage Covered Lines Changed/Added Lines %
rpcserver.go 0 22 0.0%
Files with Coverage Reduction New Missed Lines %
rpcserver.go 1 0.0%
tappsbt/create.go 2 53.22%
commitment/tap.go 2 83.91%
asset/asset.go 2 81.13%
asset/mock.go 3 92.2%
tapdb/universe.go 4 80.91%
tapdb/multiverse.go 6 68.21%
tapgarden/caretaker.go 12 68.5%
universe/interface.go 15 50.65%
Totals Coverage Status
Change from base Build 11955833805: -0.05%
Covered Lines: 25531
Relevant Lines: 61991

💛 - Coveralls

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.

Thanks for the PR. Though I'm not sure this alone gives us anything in terms of being able to sign for such a key.
PSBTs are all about the meta information contained to tell an offline device what it's signing and what key it has to sign with.
We have some of that information available (see inline comment).
But other stuff we just don't know. Like the derivation path for the signing key.

And because you can't easily edit a PSBT (or at least I haven't found a good editor that doesn't suck), it's not trivial to add that information if you're just a user and not in a Golang code environment.

IMO we have a couple of options here:

  • Go down the path we talked about offline: force the user to provide a template PSBT (generated using lnd for example, see gist linked above) that contains the derivation path. The template would be provided in a previous step and then merged into the actual group VM TX. --> Maybe a bit too clunky for now?
  • Force the group key to be known to lnd's wallet, for example by importing the xpub as a watch-only wallet. That would tie things very much into lnd, but it would also simplify some things (for example you wouldn't need to do a dummy on-chain TX as shown in the Gist, just to be able to create a template, we could instead just query the derivation path of the key through an RPC when the PSBT group key option is requested). --> Perhaps the easiest solution to go for right now, wouldn't make other solutions impossible in the future.
  • Force the user to provide all that meta information through the RPC (kind of defeats the purpose of the PSBT, as that's the "transportation medium" for such meta info.

Whatever route we go with, we definitely MUST accompany it with a document that runs you through the process step-by-step.
Feel free to use whatever you seem useful from this gist mentioned above: https://gist.github.com/guggero/569241aa9fec57e287101187bd28d1c5

@@ -4218,12 +4219,32 @@ func marshalUnsealedSeedling(verbose bool,
if err != nil {
return nil, err
}

// Generate PSBT equivalent of the group virtual tx.
groupVirtualPsbt, err := psbt.NewFromUnsignedTx(
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't really give us anything... This can trivially also be bitcoin-cli converttopsbt <tx>.
If we want to give a signer any chance of being able to sign this, we need to add the minimum amount of metadata we have available:

		groupVirtualPsbt.Inputs[0].WitnessUtxo = &wire.TxOut{
			Value:    0, // Probably needs to be set to the equal amount as the VM TX's output value?
			PkScript: nil, // Needs to be the p2tr script for the script key Taproot key.
		}
		groupVirtualPsbt.Inputs[0].TaprootInternalKey = ? // I think we can set this from the script key's internal key, which I assume we need to know at this point?
		groupVirtualPsbt.Inputs[0].TaprootMerkleRoot = ? // Same as above, should be the tweak of the script key.

		groupVirtualPsbt.Outputs[0].TaprootInternalKey = ? // Same as above.

@lightninglabs-deploy
Copy link

lightninglabs-deploy commented Dec 16, 2024

@ffranr, remember to re-request review from reviewers when ready

@Roasbeef Roasbeef added the P0 label Dec 18, 2024
@dstadulis dstadulis requested review from GeorgeTsagk and removed request for jharveyb December 19, 2024 18:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 🏗 In progress
Development

Successfully merging this pull request may close these issues.

6 participants