From 7b813c11d7999b595fd9ee412f11218fb2bd138f 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 31766f3a6..1dcc815c8 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -3056,6 +3056,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 745ec3a09..6d1c2f44f 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 597806317..85cb7d5be 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 {