I want to check within a minting policy whether a specific spending validator script is being run by checking if I can find an input that belongs to that spending validator's script address.

If there is an easier way please let me know but I am running in to the following problem:

I have a function that returns a Maybe of the transaction input matching my spending validator.

scriptInput :: Maybe TxInInfo
scriptInput =
    let isScriptInput i = (isScriptAddress . txOutAddress . txInInfoResolved) i
        xs = [i | i <- txInfoInputs info, isScriptInput i]
        case xs of
            [i] -> Just i
            _   -> Nothing

isScriptAddress :: Address -> Bool
    Address { addressCredential=ScriptCredential vh
            , addressStakingCredential=Nothing
            } = vh == scriptValidatorHash -- comes from validator definition in same file
isScriptAddress _ = False

When I replace the vh == scriptValidatorHash with True I get no interpreter error, but if I leave it as described above I get the following error:

GHC Core to PLC plugin: E042:Error: Unsupported feature: Type constructor: GHC.Prim.ByteArray# Context: Compiling type: GHC.Prim.ByteArray# Context: Compiling data constructor type: GHC.Natural.NatJ# Context: Compiling type: GHC.Natural.Natural Context: Compiling data constructor type: PlutusCore.Core.Type.Version Context: Compiling type: PlutusCore.Core.Type.Version ann Context: Compiling data constructor type: UntypedPlutusCore.Core.Type.Program Context: Compiling type: UntypedPlutusCore.Core.Type.Program PlutusCore.DeBruijn.Internal.DeBruijn PlutusCore.Default.Universe.DefaultUni PlutusCore.Default.Builtins.DefaultFun () Context: Compiling type: Plutus.V1.Ledger.Scripts.Script Context: Compiling type: Plutus.V1.Ledger.Scripts.Validator Context: Compiling data constructor type: Ledger.Typed.Scripts.Validators.TypedValidator Context: Compiling type: Ledger.Typed.Scripts.Validators.TypedValidator a Context: Compiling type: Ledger.Typed.Scripts.Validators.TypedValidator a -> ...

1 Answer 1


It turns out directly referencing the spending validator hash computes the hash of the spending validator which runs the PLC plugin again. That leads to problems of some kind. Therefore the best solution for referencing script hashes inside scripts is by lifting them with the help of PlutusTx.liftCode and PlutusTx.applyCode.

So I made the following changes to my minting policy to get it to work: I am passing along an address parameter which allows me to check for equality - essentially, making my minting policy a parameterized policy.

{-# INLINABLE mkMintPolicy #-}
mkMintPolicy :: Address -> ScriptAction -> ScriptContext -> Bool
mkMintPolicy addr sa ctx = 
    isScriptAddress :: Address -> Bool
    isScriptAddress a = a == addr

policy :: Scripts.MintingPolicy
policy = mkMintingPolicyScript $ 
    $$(PlutusTx.compile [|| wrap ||]) 
    `PlutusTx.applyCode` PlutusTx.liftCode mySpendingValidatorAddress
        wrap addr = Scripts.wrapMintingPolicy $ policy addr

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.