2

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.

1 Answer 1

1

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 helped me with this.

1
  • Thanks, this worked!
    – ZDust283
    Dec 18, 2021 at 22:12

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.