Skip to content

Commit

Permalink
rpc+universe: ensure inserted proof type matches universe proof type
Browse files Browse the repository at this point in the history
  • Loading branch information
ffranr committed Oct 3, 2023
1 parent 7b7b1e5 commit e00273b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
6 changes: 6 additions & 0 deletions rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
6 changes: 6 additions & 0 deletions universe/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 21 additions & 0 deletions universe/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit e00273b

Please sign in to comment.