2

When modifying the week5 code in e.g. Signed.hs from

mkPolicy pkh () ctx = txSignedBy (scriptContextTxInfo ctx) $ unPaymentPubKeyHash pkh

to the hard-coded pkh from Wallet 1,

mkPolicy pkh () ctx = txSignedBy (scriptContextTxInfo ctx) $ PubKeyHash "a2c20c77887ace1cd986193e4e75babd8993cfd56995cd5cfce609c2"

the validation fails with

CONTRACT STOPPED WITH ERROR: "\"WalletError (ValidationError (ScriptFailure (EvaluationError [\\\"PT5\\\"] \\\"CekEvaluationFailure\\\")))\""

I verified in the repl:

mockWalletPaymentPubKeyHash (knownWallet 1)
a2c20c77887ace1cd986193e4e75babd8993cfd56995cd5cfce609c2

and also in the offchain code logging Contract.ownPaymentPubKeyHash gives the same a2c2...09c2 hash.

What is going wrong here?

I unsuccessfully tried to debug it with

mkPolicy pkh () ctx = traceError $ decodeUtf8 $ getPubKeyHash $ head $ txInfoSignatories (scriptContextTxInfo ctx)

which resulted in an error as well.

CONTRACT STOPPED WITH ERROR: "\"WalletError (ValidationError (ScriptFailure (EvaluationError [] \\\"BuiltinEvaluationFailure of DecodeUtf8\\\")))\""

What is the correct way to debug this? e.g. in this case to check what the pkh used in the onchain code was? Is decodeUtf8 the right function at all for BuiltinByteString -> BuiltinString in this case or is it a special byte string?

2
  • Both wallets call mint endpoint and if you explicitly allow only one of the wallets to mint then it will of course throw error. Try removing or commenting the other wallet's call to endpoint. Feb 18, 2022 at 8:01
  • @Tuvshintsenguun thanks, forgot to mention this: the EmulatorTrace was adjusted to only have 1 mint call from wallet 1. Feb 18, 2022 at 9:25

1 Answer 1

2

This was answered in PPP Q&A, the issue was the string literals in Plutus Core code. Instead, one has to use variables

{-# INLINABLE mkPolicy #-}
mkPolicy :: PaymentPubKeyHash -> () -> ScriptContext -> Bool
mkPolicy pkh () ctx = txSignedBy (scriptContextTxInfo ctx) $ 
unPaymentPubKeyHash pkh

and put the literal into the liftCode expression:

policy :: Scripts.MintingPolicy
policy = mkMintingPolicyScript $
$$(PlutusTx.compile [|| Scripts.wrapMintingPolicy . mkPolicy ||])
`PlutusTx.applyCode`
PlutusTx.liftCode (PaymentPubKeyHash "a2c20c77887ace1cd986193e4e75babd8993cfd56995cd5cfce609c2")

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.