Skip to content

Commit e8edfaf

Browse files
jharveybguggero
authored andcommitted
proof: set altLeaves in transition proofs
1 parent d739a1b commit e8edfaf

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

proof/append.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,16 @@ func CreateTransitionProof(prevOut wire.OutPoint,
135135

136136
proof.Asset = *params.NewAsset.Copy()
137137

138+
// Copy any AltLeaves from the anchor commitment to the proof.
139+
altLeaves, err := params.TaprootAssetRoot.FetchAltLeaves()
140+
if err != nil {
141+
return nil, err
142+
}
143+
144+
if len(altLeaves) > 0 {
145+
proof.AltLeaves = asset.ToAltLeaves(altLeaves)
146+
}
147+
138148
// With the base information contained, we'll now need to generate our
139149
// series of MS-SMT inclusion proofs that prove the existence of the
140150
// asset.

proof/append_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@ func runAppendTransitionTest(t *testing.T, assetType asset.Type, amt uint64,
133133
tapCommitment, err := commitment.NewTapCommitment(nil, assetCommitment)
134134
require.NoError(t, err)
135135

136+
// Add some alt leaves to the commitment anchoring the asset transfer.
137+
altLeaves := asset.ToAltLeaves(asset.RandAltLeaves(t, true))
138+
err = tapCommitment.MergeAltLeaves(altLeaves)
139+
require.NoError(t, err)
140+
136141
tapscriptRoot := tapCommitment.TapscriptRoot(nil)
137142
taprootKey := txscript.ComputeTaprootOutputKey(
138143
recipientTaprootInternalKey, tapscriptRoot[:],
@@ -213,6 +218,7 @@ func runAppendTransitionTest(t *testing.T, assetType asset.Type, amt uint64,
213218
require.NoError(t, err)
214219
require.Greater(t, len(transitionBlob), len(genesisBlob))
215220
require.Equal(t, txMerkleProof, &transitionProof.TxMerkleProof)
221+
asset.CompareAltLeaves(t, altLeaves, transitionProof.AltLeaves)
216222
verifyBlob(t, transitionBlob)
217223

218224
// Stop here if we don't test asset splitting.
@@ -281,18 +287,27 @@ func runAppendTransitionTest(t *testing.T, assetType asset.Type, amt uint64,
281287
split3AssetNoSplitProof,
282288
)
283289
require.NoError(t, err)
290+
split1AltLeaves := asset.ToAltLeaves(asset.RandAltLeaves(t, true))
291+
split2AltLeaves := asset.ToAltLeaves(asset.RandAltLeaves(t, true))
292+
split3AltLeaves := asset.ToAltLeaves(asset.RandAltLeaves(t, true))
284293
tap1Commitment, err := commitment.NewTapCommitment(
285294
nil, split1Commitment,
286295
)
287296
require.NoError(t, err)
297+
err = tap1Commitment.MergeAltLeaves(split1AltLeaves)
298+
require.NoError(t, err)
288299
tap2Commitment, err := commitment.NewTapCommitment(
289300
nil, split2Commitment,
290301
)
291302
require.NoError(t, err)
303+
err = tap2Commitment.MergeAltLeaves(split2AltLeaves)
304+
require.NoError(t, err)
292305
tap3Commitment, err := commitment.NewTapCommitment(
293306
nil, split3Commitment,
294307
)
295308
require.NoError(t, err)
309+
err = tap3Commitment.MergeAltLeaves(split3AltLeaves)
310+
require.NoError(t, err)
296311

297312
tapscript1Root := tap1Commitment.TapscriptRoot(nil)
298313
tapscript2Root := tap2Commitment.TapscriptRoot(nil)
@@ -412,6 +427,7 @@ func runAppendTransitionTest(t *testing.T, assetType asset.Type, amt uint64,
412427
require.NoError(t, err)
413428
require.Greater(t, len(split1Blob), len(transitionBlob))
414429
require.Equal(t, splitTxMerkleProof, &split1Proof.TxMerkleProof)
430+
asset.CompareAltLeaves(t, split1AltLeaves, split1Proof.AltLeaves)
415431
split1Snapshot := verifyBlob(t, split1Blob)
416432
require.False(t, split1Snapshot.SplitAsset)
417433

@@ -454,6 +470,7 @@ func runAppendTransitionTest(t *testing.T, assetType asset.Type, amt uint64,
454470
require.NoError(t, err)
455471
require.Greater(t, len(split2Blob), len(transitionBlob))
456472
require.Equal(t, splitTxMerkleProof, &split2Proof.TxMerkleProof)
473+
asset.CompareAltLeaves(t, split2AltLeaves, split2Proof.AltLeaves)
457474
split2Snapshot := verifyBlob(t, split2Blob)
458475

459476
require.True(t, split2Snapshot.SplitAsset)
@@ -497,6 +514,7 @@ func runAppendTransitionTest(t *testing.T, assetType asset.Type, amt uint64,
497514
require.NoError(t, err)
498515
require.Greater(t, len(split3Blob), len(transitionBlob))
499516
require.Equal(t, splitTxMerkleProof, &split3Proof.TxMerkleProof)
517+
asset.CompareAltLeaves(t, split3AltLeaves, split3Proof.AltLeaves)
500518
split3Snapshot := verifyBlob(t, split3Blob)
501519

502520
require.True(t, split3Snapshot.SplitAsset)

0 commit comments

Comments
 (0)