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

commitment: splits shouldn't inherit locktime from inputs #1103

Merged
merged 3 commits into from
Aug 24, 2024

Conversation

Roasbeef
Copy link
Member

In this commit, we fix an existing bug related to lock times and split commitments. Before this commit, if an input had a relative lock time, then when we went to make the new split assets, we would copy that value into the split. This isn't correct as the input is valid/confirmed, so we don't need to copy over the lock time information.

The prior behavior would cause certain classes of spends to fail, as we would be validating a new root asset that has no lock time, but the root asset split inserted into the split commitment would be carrying the old lock time. When verifying the split, we would set the lock times of the split to that of the new asset:

taproot-assets/vm/vm.go

Lines 305 to 307 in e893dee

// Lock times should not invalidate the split commitment proof.
splitNoWitness.LockTime = vm.newAsset.LockTime
splitNoWitness.RelativeLockTime = vm.newAsset.RelativeLockTime
.

As we copied over the lock time from the input, we would now effectively invalid the split commitment.

Fixes #1099

@Roasbeef Roasbeef added this to the v0.4.2 milestone Aug 23, 2024
@coveralls
Copy link

coveralls commented Aug 23, 2024

Pull Request Test Coverage Report for Build 10533902922

Details

  • 26 of 31 (83.87%) changed or added relevant lines in 5 files are covered.
  • 14 unchanged lines in 5 files lost coverage.
  • Overall coverage increased (+0.02%) to 40.328%

Changes Missing Coverage Covered Lines Changed/Added Lines %
tapfreighter/wallet.go 0 1 0.0%
proof/courier.go 0 4 0.0%
Files with Coverage Reduction New Missed Lines %
tapdb/addrs.go 2 79.04%
tapgarden/planter.go 2 74.87%
asset/asset.go 2 81.61%
universe/interface.go 4 50.22%
tapgarden/caretaker.go 4 68.5%
Totals Coverage Status
Change from base Build 10516988158: 0.02%
Covered Lines: 23972
Relevant Lines: 59442

💛 - Coveralls

In this commit, we fix an existing bug related to lock times and split
commitments. Before this commit, if an input had a relative lock time,
then when we went to make the new split assets, we would _copy_ that
value into the split. This isn't correct as the input is
valid/confirmed, so we don't need to copy over the lock time
information.

The prior behavior would cause certain classes of spends to fail, as
we would be validating a new root asset that has no lock time, but the
root asset split inserted into the split commitment would be carrying
the old lock time. When verifying the split, we would set the lock times
of the split to that of the new asset:
https://github.com/lightninglabs/taproot-assets/blob/e893dee87e9d8f0de53b8ee9e2527add80df6491/vm/vm.go#L305-L307.

As we copied over the lock time from the input, we would now effectively
invalid the split commitment.

Fixes #1099
@guggero guggero force-pushed the fix-split-locktime branch from 523d723 to 317559c Compare August 23, 2024 15:29
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.

Nice find! I pushed an updated commit that also updates some other call sites.
Perhaps we should extract this "copy for descendant asset" functionality into a generic function?

@guggero
Copy link
Member

guggero commented Aug 23, 2024

Updated lightninglabs/lightning-terminal#825 to confirm this fully fixes the issue.

@jharveyb jharveyb self-requested a review August 23, 2024 17:57
Copy link
Contributor

@jharveyb jharveyb left a comment

Choose a reason for hiding this comment

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

LGTM! Wondering if we shouldn't bundle the SplitCommitment and locktime resetting into another method similar to Copy(), to make this more explicit / easier in the future.

@Roasbeef
Copy link
Member Author

Perhaps we should extract this "copy for descendant asset" functionality into a generic function?

SGTM, was thinking that too, can tack it on.

It appears that the underlying library may `nil` out the `rawConn` after
the transfer is finished. We can avoid a panic here by only closing if
the `rawConn` is non-nil.
`CopySpendTemplate` is similar to `Copy` but sheds some fields that
don't need to be carried along when making a copy of an input to spend.
This includes the split commitment root, and time lock information.
@Roasbeef
Copy link
Member Author

Implemented here: 881ecaf

@Roasbeef Roasbeef merged commit 842d367 into main Aug 24, 2024
17 checks passed
@guggero guggero deleted the fix-split-locktime branch August 25, 2024 06:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

[custom channels]: proof invalid after sweeping delayed to_local from commitment TX
4 participants