diff --git a/rpcserver.go b/rpcserver.go index 7cc70937f..6a519a169 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -3043,6 +3043,12 @@ func (r *rpcServer) InsertProof(ctx context.Context, return nil, err } + // Ensure the 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 14e160f46..4e45d3d5d 100644 --- a/universe/base.go +++ b/universe/base.go @@ -143,6 +143,12 @@ func (a *MintingArchive) RegisterIssuance(ctx context.Context, id Identifier, newProof := leaf.Proof + // 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 5723340f9..45155dcae 100644 --- a/universe/interface.go +++ b/universe/interface.go @@ -92,6 +92,27 @@ func (i *Identifier) StringForLog() string { i.MsSmtNamespace(), 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 { + proofType := uniID.ProofType + + isIssuanceProof := proof.Asset.HasGenesisWitness() + isTransferProof := !isIssuanceProof + + if isIssuanceProof && proofType != ProofTypeIssuance { + return fmt.Errorf("proof is an issuance proof, but universe "+ + "identifier is not set to issuance: %v", uniID) + } + + if isTransferProof && proofType != ProofTypeTransfer { + return fmt.Errorf("proof is a transfer proof, but universe "+ + "identifier is not set to transfer: %v", uniID) + } + + 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 {