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 5, 2023
1 parent f0d1707 commit 5557ce6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
7 changes: 7 additions & 0 deletions rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
6 changes: 6 additions & 0 deletions universe/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,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
16 changes: 16 additions & 0 deletions universe/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 5557ce6

Please sign in to comment.