From 05da7678ecd51234b9983a2933c08b778d662e2e Mon Sep 17 00:00:00 2001 From: ffranr Date: Tue, 3 Oct 2023 19:05:08 +0100 Subject: [PATCH] rpc+universe: ensure inserted proof type matches universe proof type --- rpcserver.go | 7 +++++++ universe/base.go | 6 ++++++ universe/interface.go | 16 ++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/rpcserver.go b/rpcserver.go index 9c429fdf4..04c66e2b6 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -3082,6 +3082,13 @@ func (r *rpcServer) InsertProof(ctx context.Context, } } + // Ensure that the new proof is of the correct type for the target + // universe. + err = universe.ValidateProofUniverseType(assetLeaf.Proof, universeID) + if err != nil { + return nil, err + } + rpcsLog.Debugf("[InsertProof]: inserting proof at "+ "(universeID=%x, leafKey=%x)", universeID, leafKey.UniverseKey()) diff --git a/universe/base.go b/universe/base.go index 1274e1530..d2fd749b6 100644 --- a/universe/base.go +++ b/universe/base.go @@ -157,6 +157,12 @@ func (a *MintingArchive) RegisterIssuance(ctx context.Context, id Identifier, } } + // Ensure the proof is of the correct type for the target universe. + err := ValidateProofUniverseType(newProof, id) + if err != nil { + return nil, err + } + // We'll first check to see if we already know of this leaf within the // multiverse. If so, then we'll return the existing issuance proof. issuanceProofs, err := a.cfg.Multiverse.FetchProofLeaf(ctx, id, key) diff --git a/universe/interface.go b/universe/interface.go index 9873f6347..986942519 100644 --- a/universe/interface.go +++ b/universe/interface.go @@ -80,6 +80,22 @@ func (i *Identifier) StringForLog() string { i.String(), i.AssetID[:], groupKey, i.ProofType) } +// ValidateProofUniverseType validates that the proof type matches the universe +// identifier proof type. +func ValidateProofUniverseType(proof *proof.Proof, uniID Identifier) error { + expectedProofType, err := NewProofTypeFromAssetProof(proof) + if err != nil { + return err + } + + if expectedProofType != uniID.ProofType { + return fmt.Errorf("proof type mismatch: expected %s, got %s", + expectedProofType, uniID.ProofType) + } + + return nil +} + // GenesisWithGroup is a two tuple that groups the genesis of an asset with the // group key it's associated with (if that exists). type GenesisWithGroup struct {