<p>I've ran into similar issue. You can try to use <code>fromHex</code> function form <code>Ledger.Bytes</code> module, which will return the pubkeyhash as bytes representation.</p>
<p>This <a href="https://cardano.stackexchange.com/a/2579/5071">answer</a> helped me with this.</p>

CC BY-SA 4.0
2021-12-18T22:12:42.873Z
Thanks, this worked!
ZDust283
CC BY-SA 4.0
2021-12-15T10:30:38.093Z
2021-12-15T10:30:38.093Z
Kirill Elizarov
<p>I have a simple validator script that checks if a transaction is signed by a specific public key with the hash: <code>12f2f3e44e6e310abc78802d7078ec1fd0fa220ff47ad1bdb43397e2</code></p>
<pre><code>{-# INLINABLE getHolder #-}
getHolder :: PubKeyHash
getHolder = PubKeyHash &quot;12f2f3e44e6e310abc78802d7078ec1fd0fa220ff47ad1bdb43397e2&quot;


{-# INLINABLE mkValidator #-}
mkValidator :: BuiltinData -&gt; BuiltinData -&gt; ScriptContext -&gt; Bool
mkValidator _ _ ctx = txSignedBy (scriptContextTxInfo ctx) getHolder
</code></pre>
<p>The validator always fails when attempting to spend an output with the correct key using the CLI, <code>--required-signer</code> is being used. The transaction is never built.</p>
<hr />
<p>I attempt to log the txInfoSignatories in the validator using the following code:</p>
<pre><code>{-# INLINABLE mkValidator #-}
mkValidator :: BuiltinData -&gt; BuiltinData -&gt; ScriptContext -&gt; Bool
mkValidator _ _ ctx = traceError $ decodeUtf8 $ getPubKeyHash $ P.head signatories
    where
        info :: TxInfo
        info = scriptContextTxInfo ctx

        signatories :: [PubKeyHash]
        signatories = txInfoSignatories info
</code></pre>
<p>Even though the decoding function throws an error, I still get the following:</p>
<pre><code>The provided Plutus code called 'error'.
Caused by: [
  (builtin decodeUtf8)
  (con bytestring #12f2f3e44e6e310abc78802d7078ec1fd0fa220ff47ad1bdb43397e2)
]
</code></pre>
<p>Which shows that the correct key hash is in the script context, but the way the hash is constructed by the script context is clearly not the same as the one I've made and I'm not sure how to proceed.</p>
<p>Thanks!</p>
<p>EDIT: In fact, this happens to any validator I try to use that compares scriptContextTxInfo with any compile time input I give it. The bytestrings that I hardcode are never seen as equal to the bytestrings in scriptContextTxInfo. The validator traces leave me completely in the dark as my code seems to be identical to other examples that apparently work.</p>

<plutus><cardano-cli>
Validator fails comparing two (assumed equivalent) PubKeyHashes
# Validator fails comparing two (assumed equivalent) PubKeyHashes

(Asked by: username_0 on 2021-12-10)

I have a simple validator script that checks if a transaction is signed by a specific public key with the hash: 12f2f3e44e6e310abc78802d7078ec1fd0fa220ff47ad1bdb43397e2
{-# INLINABLE getHolder #-}
getHolder :: PubKeyHash
getHolder = PubKeyHash "12f2f3e44e6e310abc78802d7078ec1fd0fa220ff47ad1bdb43397e2"


{-# INLINABLE mkValidator #-}
mkValidator :: BuiltinData -> BuiltinData -> ScriptContext -> Bool
mkValidator _ _ ctx = txSignedBy (scriptContextTxInfo ctx) getHolder

The validator always fails when attempting to spend an output with the correct key using the CLI, --required-signer is being used. The transaction is never built.

I attempt to log the txInfoSignatories in the validator using the following code:
{-# INLINABLE mkValidator #-}
mkValidator :: BuiltinData -> BuiltinData -> ScriptContext -> Bool
mkValidator _ _ ctx = traceError $ decodeUtf8 $ getPubKeyHash $ P.head signatories
    where
        info :: TxInfo
        info = scriptContextTxInfo ctx

        signatories :: [PubKeyHash]
        signatories = txInfoSignatories info

Even though the decoding function throws an error, I still get the following:
The provided Plutus code called 'error'.
Caused by: [
  (builtin decodeUtf8)
  (con bytestring #12f2f3e44e6e310abc78802d7078ec1fd0fa220ff47ad1bdb43397e2)
]

Which shows that the correct key hash is in the script context, but the way the hash is constructed by the script context is clearly not the same as the one I've made and I'm not sure how to proceed.
Thanks!
EDIT: In fact, this happens to any validator I try to use that compares scriptContextTxInfo with any compile time input I give it. The bytestrings that I hardcode are never seen as equal to the bytestrings in scriptContextTxInfo. The validator traces leave me completely in the dark as my code seems to be identical to other examples that apparently work.

**Tags:** plutus, cardano-cli

---

## 1 answers

### Answer by username_1 on 2021-12-15. Score: 1 | Accepted answer

I've ran into similar issue. You can try to use `fromHex` function form `Ledger.Bytes` module, which will return the pubkeyhash as bytes representation.

This [answer](https://cardano.stackexchange.com/a/2579/5071) helped me with this.

> **Comments:**
> **username_0**: Thanks, this worked!  

---

