<p>It turns out directly referencing the <strong>spending</strong> 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 <code>PlutusTx.liftCode</code> and <code>PlutusTx.applyCode</code>.</p>
<p>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.</p>
<pre><code>{-# INLINABLE mkMintPolicy #-}
mkMintPolicy :: Address -&gt; ScriptAction -&gt; ScriptContext -&gt; Bool
mkMintPolicy addr sa ctx = 
    ...
    isScriptAddress :: Address -&gt; Bool
    isScriptAddress a = a == addr
    ...



policy :: Scripts.MintingPolicy
policy = mkMintingPolicyScript $ 
    $$(PlutusTx.compile [|| wrap ||]) 
    `PlutusTx.applyCode` PlutusTx.liftCode mySpendingValidatorAddress
    where
        wrap addr = Scripts.wrapMintingPolicy $ policy addr
</code></pre>

CC BY-SA 4.0
2022-05-23T16:11:00.807Z
2022-05-23T16:11:00.807Z
Will
<p>I want to check within a <strong>minting</strong> policy whether a specific <strong>spending</strong> validator script is being run by checking if I can find an input that belongs to that <strong>spending</strong> validator's script address.</p>
<p>If there is an easier way please let me know but I am running in to the following problem:</p>
<p>I have a function that returns a <em>Maybe</em> of the transaction input matching my <strong>spending</strong> validator.</p>
<pre><code>scriptInput :: Maybe TxInInfo
scriptInput =
    let isScriptInput i = (isScriptAddress . txOutAddress . txInInfoResolved) i
        xs = [i | i &lt;- txInfoInputs info, isScriptInput i]
    in
        case xs of
            [i] -&gt; Just i
            _   -&gt; Nothing

isScriptAddress :: Address -&gt; Bool
isScriptAddress
    Address { addressCredential=ScriptCredential vh
            , addressStakingCredential=Nothing
            } = vh == scriptValidatorHash -- comes from validator definition in same file
isScriptAddress _ = False
</code></pre>
<p>When I replace the <code>vh == scriptValidatorHash</code> with <code>True</code> I get no interpreter error, but if I leave it as described above I get the following error:</p>
<pre><code>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 -&gt; ...
</code></pre>

<plutus><minting><validator><ghci>
How to check if validator ran inside minting policy
# How to check if validator ran inside minting policy

(Asked by: username_0 on 2022-05-23)

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]
    in
        case xs of
            [i] -> Just i
            _   -> Nothing

isScriptAddress :: Address -> Bool
isScriptAddress
    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 -> ...

**Tags:** plutus, minting, validator, ghci

---

## 1 answers

### Answer by username_0 on 2022-05-23. Score: 0 | Accepted answer

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
    where
        wrap addr = Scripts.wrapMintingPolicy $ policy addr


---

