Skip to content

Commit 356b874

Browse files
committed
proof: add verification challenge option
1 parent 4dcdb21 commit 356b874

File tree

1 file changed

+39
-4
lines changed

1 file changed

+39
-4
lines changed

proof/verifier.go

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,14 +320,17 @@ func (p *Proof) verifyAssetStateTransition(ctx context.Context,
320320
// well-defined 1-in-1-out packet and verifying the witness is valid for that
321321
// virtual transaction.
322322
func (p *Proof) verifyChallengeWitness(ctx context.Context,
323-
chainLookup asset.ChainLookup) (bool, error) {
323+
chainLookup asset.ChainLookup,
324+
challengeBytes fn.Option[[32]byte]) (bool, error) {
324325

325326
// The challenge witness packet always has one input and one output,
326327
// independent of how the asset was created. The chain params are only
327328
// needed when encoding/decoding a vPkt, so it doesn't matter what
328329
// network we choose as we only need the packet to get the witness.
329330
ownedAsset := p.Asset.Copy()
330-
prevId, proofAsset := CreateOwnershipProofAsset(ownedAsset)
331+
prevId, proofAsset := CreateOwnershipProofAsset(
332+
ownedAsset, challengeBytes,
333+
)
331334

332335
// The 1-in-1-out packet for the challenge witness is well-defined, we
333336
// don't have to do any extra checks, just set the witness and then
@@ -497,6 +500,29 @@ type GroupVerifier func(groupKey *btcec.PublicKey) error
497500
type GroupAnchorVerifier func(gen *asset.Genesis,
498501
groupKey *asset.GroupKey) error
499502

503+
// ProofVerificationOption is an option that may be applied on
504+
// *proofVerificationOpts.
505+
type ProofVerificationOption func(p *proofVerificationParams)
506+
507+
// proofVerificationParams is a struct containing various options that may be used
508+
// during proof verification
509+
type proofVerificationParams struct {
510+
// ChallengeBytes is an optional field that is used when verifying an
511+
// ownership proof. This field is only populated when the corresponding
512+
// ProofVerificationOption option is defined.
513+
ChallengeBytes fn.Option[[32]byte]
514+
}
515+
516+
// WithChallengeBytes is a ProofVerificationOption that defines some challenge
517+
// bytes to be used when verifying this proof.
518+
func WithChallengeBytes(challenge [32]byte) ProofVerificationOption {
519+
return func(p *proofVerificationParams) {
520+
var byteCopy [32]byte
521+
copy(byteCopy[:], challenge[:])
522+
p.ChallengeBytes = fn.Some(byteCopy)
523+
}
524+
}
525+
500526
// Verify verifies the proof by ensuring that:
501527
//
502528
// 0. A proof has a valid version.
@@ -511,7 +537,14 @@ type GroupAnchorVerifier func(gen *asset.Genesis,
511537
func (p *Proof) Verify(ctx context.Context, prev *AssetSnapshot,
512538
headerVerifier HeaderVerifier, merkleVerifier MerkleVerifier,
513539
groupVerifier GroupVerifier,
514-
chainLookup asset.ChainLookup) (*AssetSnapshot, error) {
540+
chainLookup asset.ChainLookup,
541+
opts ...ProofVerificationOption) (*AssetSnapshot, error) {
542+
543+
var verificationParams proofVerificationParams
544+
545+
for _, opt := range opts {
546+
opt(&verificationParams)
547+
}
515548

516549
// 0. Check only for the proof version.
517550
if p.IsUnknownVersion() {
@@ -625,7 +658,9 @@ func (p *Proof) Verify(ctx context.Context, prev *AssetSnapshot,
625658
var splitAsset bool
626659
switch {
627660
case prev == nil && p.ChallengeWitness != nil:
628-
splitAsset, err = p.verifyChallengeWitness(ctx, chainLookup)
661+
splitAsset, err = p.verifyChallengeWitness(
662+
ctx, chainLookup, verificationParams.ChallengeBytes,
663+
)
629664

630665
default:
631666
splitAsset, err = p.verifyAssetStateTransition(

0 commit comments

Comments
 (0)