Skip to content

Commit db28a03

Browse files
authored
Merge pull request #1465 from lightninglabs/extract-refactors-from-proof-v1
Extract non-controversion commits from Proof-system-v1 PR
2 parents e5c6e98 + c8a7971 commit db28a03

File tree

10 files changed

+557
-968
lines changed

10 files changed

+557
-968
lines changed

asset/asset.go

+9-4
Original file line numberDiff line numberDiff line change
@@ -1395,6 +1395,13 @@ func (a *Asset) HasSplitCommitmentWitness() bool {
13951395
return IsSplitCommitWitness(a.PrevWitnesses[0])
13961396
}
13971397

1398+
// IsTransferRoot returns true if this asset represents a root transfer. A root
1399+
// transfer is an asset that is neither a genesis asset nor contains split
1400+
// commitment witness data.
1401+
func (a *Asset) IsTransferRoot() bool {
1402+
return !a.IsGenesisAsset() && !a.HasSplitCommitmentWitness()
1403+
}
1404+
13981405
// IsUnSpendable returns true if an asset uses the un-spendable script key and
13991406
// has zero value.
14001407
func (a *Asset) IsUnSpendable() bool {
@@ -1919,9 +1926,7 @@ type AltLeaf[T any] interface {
19191926
}
19201927

19211928
// NewAltLeaf instantiates a new valid AltLeaf.
1922-
func NewAltLeaf(key ScriptKey, keyVersion ScriptVersion,
1923-
prevWitness []Witness) (*Asset, error) {
1924-
1929+
func NewAltLeaf(key ScriptKey, keyVersion ScriptVersion) (*Asset, error) {
19251930
if key.PubKey == nil {
19261931
return nil, fmt.Errorf("script key must be non-nil")
19271932
}
@@ -1932,7 +1937,7 @@ func NewAltLeaf(key ScriptKey, keyVersion ScriptVersion,
19321937
Amount: 0,
19331938
LockTime: 0,
19341939
RelativeLockTime: 0,
1935-
PrevWitnesses: prevWitness,
1940+
PrevWitnesses: nil,
19361941
SplitCommitmentRoot: nil,
19371942
GroupKey: nil,
19381943
ScriptKey: key,

asset/asset_test.go

-3
Original file line numberDiff line numberDiff line change
@@ -364,9 +364,6 @@ func TestAssetEncoding(t *testing.T) {
364364
})
365365

366366
assertAssetEncoding("minimal asset", &Asset{
367-
Genesis: Genesis{
368-
MetaHash: [MetaHashLen]byte{},
369-
},
370367
ScriptKey: NewScriptKey(pubKey),
371368
})
372369

asset/encoding.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ func AltLeavesDecoder(r io.Reader, val any, buf *[8]byte, l uint64) error {
864864
return err
865865
}
866866

867-
leaves := make([]AltLeaf[Asset], 0, numItems)
867+
leaves := make([]AltLeaf[Asset], numItems)
868868
leafKeys := make(map[SerializedKey]struct{})
869869
for i := uint64(0); i < numItems; i++ {
870870
var streamBytes []byte
@@ -890,7 +890,7 @@ func AltLeavesDecoder(r io.Reader, val any, buf *[8]byte, l uint64) error {
890890
}
891891

892892
leafKeys[leafKey] = struct{}{}
893-
leaves = append(leaves, AltLeaf[Asset](&leaf))
893+
leaves[i] = AltLeaf[Asset](&leaf)
894894
}
895895

896896
*typ = leaves

asset/mock.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -678,12 +678,9 @@ func RandAssetWithValues(t testing.TB, genesis Genesis, groupKey *GroupKey,
678678

679679
// RandAltLeaf generates a random Asset that is a valid AltLeaf.
680680
func RandAltLeaf(t testing.TB) *Asset {
681-
randWitness := []Witness{
682-
{TxWitness: test.RandTxWitnesses(t)},
683-
}
684681
randKey := RandScriptKey(t)
685682
randVersion := ScriptVersion(test.RandInt[uint16]())
686-
randLeaf, err := NewAltLeaf(randKey, randVersion, randWitness)
683+
randLeaf, err := NewAltLeaf(randKey, randVersion)
687684
require.NoError(t, err)
688685
require.NoError(t, randLeaf.ValidateAltLeaf())
689686

proof/taproot.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ func (p TaprootProof) DeriveByAssetExclusion(assetCommitmentKey,
411411

412412
return deriveCommitmentKeys(
413413
tapCommitment, p.InternalKey,
414-
p.CommitmentProof.TapSiblingPreimage, true, true,
414+
p.CommitmentProof.TapSiblingPreimage, false, true,
415415
)
416416
}
417417

proof/testdata/proof_tlv_encoding_generated.json

+385-521
Large diffs are not rendered by default.

tappsbt/testdata/psbt_encoding_generated.json

+151-425
Large diffs are not rendered by default.

tapsend/proof.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -336,13 +336,13 @@ func addOtherOutputExclusionProofs(outputs []*tappsbt.VOutput,
336336
for idx := range outputs {
337337
vOut := outputs[idx]
338338

339-
haveIProof := params.HaveInclusionProof(vOut.AnchorOutputIndex)
340-
haveEProof := params.HaveExclusionProof(vOut.AnchorOutputIndex)
339+
outIndex := vOut.AnchorOutputIndex
340+
haveIProof := params.HaveInclusionProof(outIndex)
341+
haveEProof := params.HaveExclusionProof(outIndex)
341342
if haveIProof || haveEProof {
342343
continue
343344
}
344345

345-
outIndex := vOut.AnchorOutputIndex
346346
tapTree := outputCommitments[outIndex]
347347

348348
_, splitExclusionProof, err := tapTree.Proof(

tapsend/send.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -2075,9 +2075,9 @@ func ValidateAnchorInputs(anchorPacket *psbt.Packet, packets []*tappsbt.VPacket,
20752075
}
20762076

20772077
// This is the most important check. This ensures that the
2078-
// assets in the outputs of the virtual transactions match
2079-
// exactly the assets that are committed to in the anchor
2080-
// output script.
2078+
// assets in the inputs of the virtual transactions match
2079+
// exactly the assets committed to in the anchor output script
2080+
// that is being spent.
20812081
anchorScript := inputScripts[anchorOutpoint]
20822082
if !bytes.Equal(anchorScript, script) {
20832083
// The commitment may not be V2; let's check against

tapsend/send_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ func createPacket(t *testing.T, addr address.Tap, prevInput asset.PrevID,
388388
for range numAltLeaves {
389389
scriptKey := asset.NewScriptKey(test.RandPubKey(t))
390390
baseLeaf, err := asset.NewAltLeaf(
391-
scriptKey, asset.ScriptV0, nil,
391+
scriptKey, asset.ScriptV0,
392392
)
393393
require.NoError(t, err)
394394

@@ -1195,7 +1195,7 @@ var createOutputCommitmentsTestCases = []testCase{{
11951195

11961196
altLeafScriptKey := asset.NewScriptKey(test.RandPubKey(t))
11971197
newAltLeaf, err := asset.NewAltLeaf(
1198-
altLeafScriptKey, asset.ScriptV0, nil,
1198+
altLeafScriptKey, asset.ScriptV0,
11991199
)
12001200
require.NoError(t, err)
12011201

0 commit comments

Comments
 (0)