Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions asset/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -1855,8 +1855,13 @@ func (a *Asset) UpdateTxWitness(prevWitnessIndex int,

targetPrevWitness := &a.PrevWitnesses[prevWitnessIndex]
if a.HasSplitCommitmentWitness() {
rootAsset := targetPrevWitness.SplitCommitment.RootAsset
targetPrevWitness = &rootAsset.PrevWitnesses[prevWitnessIndex]
// When a split commitment is present, the witness must be
// written back to the root asset within the split commitment
// itself to ensure the change is persisted.
rootAsset := &targetPrevWitness.SplitCommitment.RootAsset
rootAsset.PrevWitnesses[prevWitnessIndex].TxWitness = witness

return nil
}

targetPrevWitness.TxWitness = witness
Expand Down
35 changes: 35 additions & 0 deletions asset/asset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,41 @@ func TestAssetEncoding(t *testing.T) {
test.WriteTestVectors(t, generatedTestVectorName, testVectors)
}

// TestUpdateTxWitnessSplitCommitment ensures witnesses are written back to the
// split commitment root asset.
func TestUpdateTxWitnessSplitCommitment(t *testing.T) {
t.Parallel()

// First, create a root asset that will be the root of our split
// commitment. We'll nil out its witness to ensure our update is what
// populates it.
root := testRootAsset.Copy()
root.PrevWitnesses[0].TxWitness = nil

// Next, create the split asset which contains a split commitment
// pointing to our root asset.
split := testSplitAsset.Copy()
split.PrevWitnesses[0].SplitCommitment = &SplitCommitment{
Proof: *mssmt.RandProof(t),
RootAsset: *root,
}

// Now, create a new witness and update the split asset.
newWitness := wire.TxWitness{{1, 2, 3}}
err := split.UpdateTxWitness(0, newWitness)
require.NoError(t, err)

// Finally, assert that the witness was written to the root asset within
// the split commitment, and that the split asset's own witness remains
// empty.
require.Equal(
t, newWitness,
split.PrevWitnesses[0].SplitCommitment.RootAsset.
PrevWitnesses[0].TxWitness,
)
require.Empty(t, split.PrevWitnesses[0].TxWitness)
}

// TestAltLeafEncoding runs a property test for AltLeaf validation, encoding,
// and decoding.
func TestAltLeafEncoding(t *testing.T) {
Expand Down
3 changes: 3 additions & 0 deletions docs/release-notes/release-notes-0.8.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@

## Code Health

- [PR#1897](https://github.com/lightninglabs/taproot-assets/pull/1897)
Fix witness writeback issue when a split commitment is present.

## Breaking Changes

## Performance Improvements
Expand Down
Loading