@@ -20,6 +20,7 @@ import (
20
20
"github.com/btcsuite/btcd/txscript"
21
21
"github.com/btcsuite/btcd/wire"
22
22
"github.com/davecgh/go-spew/spew"
23
+ "github.com/decred/dcrd/dcrec/secp256k1/v4"
23
24
"github.com/lightninglabs/taproot-assets/asset"
24
25
"github.com/lightninglabs/taproot-assets/commitment"
25
26
"github.com/lightninglabs/taproot-assets/internal/test"
@@ -338,8 +339,9 @@ func TestProofEncoding(t *testing.T) {
338
339
339
340
func genRandomGenesisWithProof (t testing.TB , assetType asset.Type ,
340
341
amt * uint64 , tapscriptPreimage * commitment.TapscriptPreimage ,
341
- noMetaHash bool , metaReveal * MetaReveal ,
342
- genesisMutator genMutator ,
342
+ noMetaHash bool , metaReveal * MetaReveal , genesisMutator genMutator ,
343
+ genesisRevealMutator genRevealMutator ,
344
+ groupRevealMutator groupRevealMutator ,
343
345
assetVersion asset.Version ) (Proof , * btcec.PrivateKey ) {
344
346
345
347
t .Helper ()
@@ -372,13 +374,17 @@ func genRandomGenesisWithProof(t testing.TB, assetType asset.Type,
372
374
asset .WithAssetVersion (assetVersion ),
373
375
)
374
376
assetGroupKey := asset .RandGroupKey (t , assetGenesis , protoAsset )
375
- groupKeyReveal := asset.GroupKeyReveal {
377
+ groupKeyReveal := & asset.GroupKeyReveal {
376
378
RawKey : asset .ToSerialized (
377
379
assetGroupKey .RawKey .PubKey ,
378
380
),
379
381
TapscriptRoot : assetGroupKey .TapscriptRoot ,
380
382
}
381
383
384
+ if groupRevealMutator != nil {
385
+ groupRevealMutator (groupKeyReveal )
386
+ }
387
+
382
388
tapCommitment , assets , err := commitment .Mint (
383
389
assetGenesis , assetGroupKey , & commitment.AssetDetails {
384
390
Type : assetType ,
@@ -436,6 +442,11 @@ func genRandomGenesisWithProof(t testing.TB, assetType asset.Type,
436
442
txMerkleProof , err := NewTxMerkleProof ([]* wire.MsgTx {genesisTx }, 0 )
437
443
require .NoError (t , err )
438
444
445
+ genReveal := & assetGenesis
446
+ if genesisRevealMutator != nil {
447
+ genReveal = genesisRevealMutator (genReveal )
448
+ }
449
+
439
450
return Proof {
440
451
PrevOut : assetGenesis .FirstPrevOut ,
441
452
BlockHeader : * blockHeader ,
@@ -455,13 +466,17 @@ func genRandomGenesisWithProof(t testing.TB, assetType asset.Type,
455
466
MetaReveal : metaReveal ,
456
467
ExclusionProofs : nil ,
457
468
AdditionalInputs : nil ,
458
- GenesisReveal : & assetGenesis ,
459
- GroupKeyReveal : & groupKeyReveal ,
469
+ GenesisReveal : genReveal ,
470
+ GroupKeyReveal : groupKeyReveal ,
460
471
}, genesisPrivKey
461
472
}
462
473
463
474
type genMutator func (* asset.Genesis )
464
475
476
+ type groupRevealMutator func (* asset.GroupKeyReveal )
477
+
478
+ type genRevealMutator func (* asset.Genesis ) * asset.Genesis
479
+
465
480
func TestGenesisProofVerification (t * testing.T ) {
466
481
t .Parallel ()
467
482
@@ -476,15 +491,18 @@ func TestGenesisProofVerification(t *testing.T) {
476
491
amount := uint64 (5000 )
477
492
478
493
testCases := []struct {
479
- name string
480
- assetType asset.Type
481
- amount * uint64
482
- assetVersion asset.Version
483
- tapscriptPreimage * commitment.TapscriptPreimage
484
- metaReveal * MetaReveal
485
- noMetaHash bool
486
- genesisMutator genMutator
487
- expectedErr error
494
+ name string
495
+ assetType asset.Type
496
+ amount * uint64
497
+ assetVersion asset.Version
498
+ tapscriptPreimage * commitment.TapscriptPreimage
499
+ metaReveal * MetaReveal
500
+ noMetaHash bool
501
+ noGroup bool
502
+ genesisMutator genMutator
503
+ genesisRevealMutator genRevealMutator
504
+ groupRevealMutator groupRevealMutator
505
+ expectedErr error
488
506
}{
489
507
{
490
508
name : "collectible genesis" ,
@@ -584,6 +602,78 @@ func TestGenesisProofVerification(t *testing.T) {
584
602
assetType : asset .Collectible ,
585
603
expectedErr : ErrGenesisRevealMetaRevealRequired ,
586
604
},
605
+ {
606
+ name : "missing genesis reveal" ,
607
+ assetType : asset .Collectible ,
608
+ noMetaHash : true ,
609
+ genesisRevealMutator : func (
610
+ g * asset.Genesis ) * asset.Genesis {
611
+
612
+ return nil
613
+ },
614
+ expectedErr : ErrGenesisRevealRequired ,
615
+ },
616
+ {
617
+ name : "genesis reveal asset ID mismatch" ,
618
+ assetType : asset .Normal ,
619
+ amount : & amount ,
620
+ noMetaHash : true ,
621
+ genesisRevealMutator : func (
622
+ g * asset.Genesis ) * asset.Genesis {
623
+
624
+ gCopy := * g
625
+ gCopy .Tag += "mismatch"
626
+ return & gCopy
627
+ },
628
+ expectedErr : ErrGenesisRevealAssetIDMismatch ,
629
+ },
630
+ {
631
+ name : "genesis reveal prev out mismatch" ,
632
+ assetType : asset .Collectible ,
633
+ genesisRevealMutator : func (
634
+ g * asset.Genesis ) * asset.Genesis {
635
+
636
+ gCopy := * g
637
+ gCopy .FirstPrevOut = test .RandOp (t )
638
+ return & gCopy
639
+ },
640
+ expectedErr : ErrGenesisRevealPrevOutMismatch ,
641
+ },
642
+ {
643
+ name : "genesis reveal output index mismatch" ,
644
+ assetType : asset .Normal ,
645
+ amount : & amount ,
646
+ noMetaHash : true ,
647
+ genesisRevealMutator : func (
648
+ g * asset.Genesis ) * asset.Genesis {
649
+
650
+ gCopy := * g
651
+ gCopy .OutputIndex = uint32 (
652
+ test .RandInt [int32 ](),
653
+ )
654
+ return & gCopy
655
+ },
656
+ expectedErr : ErrGenesisRevealOutputIndexMismatch ,
657
+ },
658
+ {
659
+ name : "group key reveal invalid key" ,
660
+ assetType : asset .Collectible ,
661
+ noMetaHash : true ,
662
+ groupRevealMutator : func (gkr * asset.GroupKeyReveal ) {
663
+ gkr .RawKey [0 ] = 0x01
664
+ },
665
+ expectedErr : secp256k1 .ErrPubKeyInvalidFormat ,
666
+ },
667
+ {
668
+ name : "group key reveal mismatched tweaked key" ,
669
+ assetType : asset .Normal ,
670
+ amount : & amount ,
671
+ noMetaHash : true ,
672
+ groupRevealMutator : func (gkr * asset.GroupKeyReveal ) {
673
+ gkr .TapscriptRoot = test .RandBytes (32 )
674
+ },
675
+ expectedErr : ErrGroupKeyRevealMismatch ,
676
+ },
587
677
}
588
678
589
679
testVectors := & TestVectors {}
@@ -595,6 +685,7 @@ func TestGenesisProofVerification(t *testing.T) {
595
685
tt , tc .assetType , tc .amount ,
596
686
tc .tapscriptPreimage , tc .noMetaHash ,
597
687
tc .metaReveal , tc .genesisMutator ,
688
+ tc .genesisRevealMutator , tc .groupRevealMutator ,
598
689
tc .assetVersion ,
599
690
)
600
691
_ , err := genesisProof .Verify (
@@ -635,7 +726,7 @@ func TestProofBlockHeaderVerification(t *testing.T) {
635
726
t .Parallel ()
636
727
637
728
proof , _ := genRandomGenesisWithProof (
638
- t , asset .Collectible , nil , nil , true , nil , nil , 0 ,
729
+ t , asset .Collectible , nil , nil , true , nil , nil , nil , nil , 0 ,
639
730
)
640
731
641
732
// Create a base reference for the block header and block height. We
@@ -793,7 +884,7 @@ func TestProofReplacement(t *testing.T) {
793
884
amt := uint64 (i + 1 )
794
885
assetVersion := asset .Version (i % 2 )
795
886
lotsOfProofs [i ], _ = genRandomGenesisWithProof (
796
- t , asset .Normal , & amt , nil , false , nil , nil ,
887
+ t , asset .Normal , & amt , nil , false , nil , nil , nil , nil ,
797
888
assetVersion ,
798
889
)
799
890
}
@@ -822,7 +913,7 @@ func TestProofReplacement(t *testing.T) {
822
913
// We'll generate a random proof, and then replace a random
823
914
// proof in the file with it.
824
915
proof , _ := genRandomGenesisWithProof (
825
- t , asset .Normal , & amt , nil , false , nil , nil ,
916
+ t , asset .Normal , & amt , nil , false , nil , nil , nil , nil ,
826
917
assetVersion ,
827
918
)
828
919
idx := test .RandIntn (numProofs )
@@ -836,15 +927,15 @@ func TestProofReplacement(t *testing.T) {
836
927
// boundary conditions).
837
928
amt := uint64 (1337 )
838
929
firstProof , _ := genRandomGenesisWithProof (
839
- t , asset .Normal , & amt , nil , false , nil , nil , asset .V1 ,
930
+ t , asset .Normal , & amt , nil , false , nil , nil , nil , nil , asset .V1 ,
840
931
)
841
932
err = f .ReplaceProofAt (0 , firstProof )
842
933
require .NoError (t , err )
843
934
assertIndex (0 , 1337 )
844
935
845
936
amt = uint64 (2016 )
846
937
lastProof , _ := genRandomGenesisWithProof (
847
- t , asset .Normal , & amt , nil , false , nil , nil , asset .V0 ,
938
+ t , asset .Normal , & amt , nil , false , nil , nil , nil , nil , asset .V0 ,
848
939
)
849
940
err = f .ReplaceProofAt (uint32 (f .NumProofs ()- 1 ), lastProof )
850
941
require .NoError (t , err )
@@ -870,7 +961,7 @@ func BenchmarkProofEncoding(b *testing.B) {
870
961
871
962
// Start with a minted genesis asset.
872
963
genesisProof , _ := genRandomGenesisWithProof (
873
- b , asset .Normal , & amt , nil , false , nil , nil , asset .V0 ,
964
+ b , asset .Normal , & amt , nil , false , nil , nil , nil , nil , asset .V0 ,
874
965
)
875
966
876
967
// We create a file with 10k proofs (the same one) and test encoding/
0 commit comments