Skip to content

Commit 6585405

Browse files
gijswijsguggero
authored andcommitted
multi: remove AltLeaves from vInputs
Because we retrieve AltLeaves from the proof during anchor input validation, we don't need to store them in the vInputs struct. This commit removes the AltLeaves field from the vInputs struct and the associated methods.
1 parent 1660f9c commit 6585405

File tree

9 files changed

+194
-290
lines changed

9 files changed

+194
-290
lines changed

tapfreighter/fund.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -460,16 +460,6 @@ func createAndSetInput(vPkt *tappsbt.VPacket, idx int,
460460
}
461461
vPkt.SetInputAsset(idx, assetInput.Asset)
462462

463-
inputAltLeaves, err := assetInput.Commitment.FetchAltLeaves()
464-
if err != nil {
465-
return fmt.Errorf("cannot fetch alt leaves from input: %w", err)
466-
}
467-
468-
err = vPkt.Inputs[idx].SetAltLeaves(inputAltLeaves)
469-
if err != nil {
470-
return fmt.Errorf("cannot set alt leaves on vInput: %w", err)
471-
}
472-
473463
return nil
474464
}
475465

tapfreighter/wallet.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,7 @@ func (f *AssetWallet) FundAddressSend(ctx context.Context,
278278
func createPassivePacket(passiveAsset *asset.Asset,
279279
activePackets []*tappsbt.VPacket, anchorOutputIndex uint32,
280280
anchorOutputInternalKey keychain.KeyDescriptor, prevOut wire.OutPoint,
281-
inputProof *proof.Proof,
282-
inputAltLeaves []*asset.Asset) (*tappsbt.VPacket, error) {
281+
inputProof *proof.Proof) (*tappsbt.VPacket, error) {
283282

284283
if len(activePackets) == 0 {
285284
return nil, errors.New("no active packets provided")
@@ -299,12 +298,8 @@ func createPassivePacket(passiveAsset *asset.Asset,
299298
SighashType: txscript.SigHashDefault,
300299
},
301300
}
302-
err := vInput.SetAltLeaves(inputAltLeaves)
303-
if err != nil {
304-
return nil, err
305-
}
306301

307-
err = tapsend.ValidateVPacketVersions(activePackets)
302+
err := tapsend.ValidateVPacketVersions(activePackets)
308303
if err != nil {
309304
return nil, err
310305
}
@@ -958,7 +953,7 @@ func CreatePassiveAssets(ctx context.Context, keyRing KeyRing,
958953
// removing the active assets. But we don't want to count the
959954
// alt leaves as "assets" in this context, so we'll trim them
960955
// out.
961-
trimmedPassives, altLeaves, err := commitment.TrimAltLeaves(
956+
trimmedPassives, _, err := commitment.TrimAltLeaves(
962957
passiveCommitments,
963958
)
964959
if err != nil {
@@ -994,7 +989,7 @@ func CreatePassiveAssets(ctx context.Context, keyRing KeyRing,
994989
passivePacket, err := createPassivePacket(
995990
passiveAsset, activePackets,
996991
anchorOutIdx, *anchorOutDesc, prevID.OutPoint,
997-
inputProof, altLeaves,
992+
inputProof,
998993
)
999994
if err != nil {
1000995
return nil, fmt.Errorf("unable to create "+

tappsbt/decode.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,6 @@ func (i *VInput) decode(pIn psbt.PInput) error {
173173
}, {
174174
key: PsbtKeyTypeInputTapAssetProof,
175175
decoder: proofDecoder(&i.Proof),
176-
}, {
177-
key: PsbtKeyTypeInputAltLeaves,
178-
decoder: altLeavesDecoder(&i.AltLeaves),
179176
}}
180177

181178
for idx := range mapping {

tappsbt/decode_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,6 @@ func TestEncodingDecoding(t *testing.T) {
255255
firstLeaf, secondLeaf,
256256
}
257257

258-
pkt.Inputs[0].AltLeaves = asset.CopyAltLeaves(altLeaves)
259258
pkt.Outputs[0].AltLeaves = asset.CopyAltLeaves(
260259
altLeaves,
261260
)
@@ -279,7 +278,6 @@ func TestEncodingDecoding(t *testing.T) {
279278
altLeaves[idx] = asset.RandAltLeaf(t)
280279
}
281280

282-
pkt.Inputs[0].AltLeaves = altLeaves
283281
pkt.Outputs[0].AltLeaves = altLeaves
284282
pkt.Outputs[1].AltLeaves = altLeaves
285283

tappsbt/encode.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,6 @@ func (i *VInput) encode() (psbt.PInput, error) {
183183
{
184184
key: PsbtKeyTypeInputTapAssetProof,
185185
encoder: proofEncoder(i.Proof),
186-
}, {
187-
key: PsbtKeyTypeInputAltLeaves,
188-
encoder: altLeavesEncoder(i.AltLeaves),
189186
},
190187
}
191188

tappsbt/interface.go

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ var (
4343
PsbtKeyTypeInputTapAnchorTapscriptSibling = []byte{0x78}
4444
PsbtKeyTypeInputTapAsset = []byte{0x79}
4545
PsbtKeyTypeInputTapAssetProof = []byte{0x7a}
46-
PsbtKeyTypeInputAltLeaves = []byte{0x7b}
4746

4847
PsbtKeyTypeOutputTapType = []byte{0x70}
4948
PsbtKeyTypeOutputTapIsInteractive = []byte{0x71}
@@ -394,12 +393,6 @@ type VInput struct {
394393
// Proof is a transition proof that proves the asset being spent was
395394
// committed to in the anchor transaction above.
396395
Proof *proof.Proof
397-
398-
// AltLeaves represent data used to construct an Asset commitment, that
399-
// will be inserted in the input anchor Tap commitment. These
400-
// data-carrying leaves are used for a purpose distinct from
401-
// representing individual Taproot Assets.
402-
AltLeaves []asset.AltLeaf[asset.Asset]
403396
}
404397

405398
// Copy creates a deep copy of the VInput.
@@ -417,8 +410,7 @@ func (i *VInput) Copy() *VInput {
417410
// We never expect the individual fields of the proof to change
418411
// while it is assigned to a virtual input. So not deep copying
419412
// it here is fine.
420-
Proof: i.Proof,
421-
AltLeaves: asset.CopyAltLeaves(i.AltLeaves),
413+
Proof: i.Proof,
422414
}
423415
}
424416

@@ -427,27 +419,6 @@ func (i *VInput) Asset() *asset.Asset {
427419
return i.asset
428420
}
429421

430-
// SetAltLeaves asserts that a set of AltLeaves are valid, and updates a VInput
431-
// to set the AltLeaves. Setting the input's AltLeaves twice is disallowed.
432-
func (i *VInput) SetAltLeaves(altLeafAssets []*asset.Asset) error {
433-
// AltLeaves can be set exactly once on a VInput.
434-
if len(i.AltLeaves) != 0 {
435-
return fmt.Errorf("%w: input", ErrAltLeavesAlreadySet)
436-
}
437-
438-
// Each asset must be a valid AltLeaf, and the set of AltLeaves must be
439-
// valid, by not having overlapping keys in the AltCommitment.
440-
altLeaves := asset.ToAltLeaves(altLeafAssets)
441-
err := asset.ValidAltLeaves(altLeaves)
442-
if err != nil {
443-
return err
444-
}
445-
446-
i.AltLeaves = asset.CopyAltLeaves(altLeaves)
447-
448-
return nil
449-
}
450-
451422
// serializeScriptKey serializes the input asset's script key as the PSBT
452423
// derivation information on the virtual input.
453424
func (i *VInput) serializeScriptKey(key asset.ScriptKey, coinType uint32) {

tappsbt/mock.go

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,8 @@ func RandPacket(t testing.TB, setVersion, altLeaves bool) *VPacket {
173173
}
174174

175175
if altLeaves {
176-
inputLeaves := asset.RandAltLeaves(t, true)
177176
output1Leaves := asset.RandAltLeaves(t, true)
178177
output2Leaves := asset.RandAltLeaves(t, true)
179-
randVInput.AltLeaves = asset.ToAltLeaves(inputLeaves)
180178
randVOutput1.AltLeaves = asset.ToAltLeaves(output1Leaves)
181179
randVOutput2.AltLeaves = asset.ToAltLeaves(output2Leaves)
182180
}
@@ -308,22 +306,6 @@ func NewTestFromVInput(t testing.TB, i *VInput) *TestVInput {
308306
ti.Proof = proof.NewTestFromProof(t, i.Proof)
309307
}
310308

311-
if len(i.AltLeaves) > 0 {
312-
// Assert that the concrete type of AltLeaf is supported.
313-
require.IsTypef(
314-
t, &asset.Asset{}, i.AltLeaves[0],
315-
"AltLeaves must be of type *asset.Asset",
316-
)
317-
318-
ti.AltLeaves = make([]*asset.TestAsset, 0, len(i.AltLeaves))
319-
for idx := range i.AltLeaves {
320-
leaf := i.AltLeaves[idx].(*asset.Asset)
321-
ti.AltLeaves = append(
322-
ti.AltLeaves, asset.NewTestFromAsset(t, leaf),
323-
)
324-
}
325-
}
326-
327309
return ti
328310
}
329311

@@ -336,7 +318,6 @@ type TestVInput struct {
336318
Anchor *TestAnchor `json:"anchor"`
337319
Asset *asset.TestAsset `json:"asset"`
338320
Proof *proof.TestProof `json:"proof"`
339-
AltLeaves []*asset.TestAsset `json:"alt_leaves"`
340321
}
341322

342323
func (ti *TestVInput) ToVInput(t testing.TB) *VInput {
@@ -379,15 +360,6 @@ func (ti *TestVInput) ToVInput(t testing.TB) *VInput {
379360
vi.Proof = ti.Proof.ToProof(t)
380361
}
381362

382-
if len(ti.AltLeaves) > 0 {
383-
vi.AltLeaves = make(
384-
[]asset.AltLeaf[asset.Asset], len(ti.AltLeaves),
385-
)
386-
for idx, leaf := range ti.AltLeaves {
387-
vi.AltLeaves[idx] = leaf.ToAsset(t)
388-
}
389-
}
390-
391363
return vi
392364
}
393365

0 commit comments

Comments
 (0)