0

I get the following GHC error for code that I am trying to update to Plutus V2. I can reproduce the error using the plutus-scripts below. Is this a bug with Plutus V2 or can anyone explain how to resolve it. I don’t have this issue with Plutus V1. Thank you.

Steps to reproduce

Git clone https://github.com/james-iohk/plutus-scripts.git
Git clone https://github.com/input-output-hk/plutus-apps.git
Go into plutus-apps directory and checkout 87b647b05902a7cef37340fda9acb175f962f354 
Type nix-shell --extra-experimental-features flakes
Cd ../plutus-scripts/src
Make the following changes 1,2,3,4 below

vi NFTMint.hs


     53 data NFTParams = NFTParams --  doesn't need more than the TxOutRef
     54     {  mpTokenName :: !PlutusV2.TokenName  -- << 1. uncommented code here
     55     , mpAmount   :: !Integer
     56     , mpTxOutRef :: !PlutusV2.TxOutRef
     57     --, mpPubKeyHs  :: !Plutus.PubKeyHash
     58     } deriving Show
     59 
     60 PlutusTx.makeLift ''NFTParams
     61 PlutusTx.unstableMakeIsData ''NFTParams
     62 
     63 tn :: PlutusV2.TokenName  -- << 2. added helper function definition
     64 tn = PlutusV2.TokenName "test" -- << 3. and here function body
     65 
     66 redeemer :: NFTParams
     67 redeemer = NFTParams { mpTokenName = tn,  -- << 4. added tn to param
     68                        mpAmount = 1,
     69                        mpTxOutRef = PlutusV2.TxOutRef {txOutRefId = "82669eddc629c8ce5cc3cb908cec6de339281bb0a0ec111880ff0936132ac8b0", txOutRefIdx = 0}
     70                      }

This will generate the following error when running cabal build from the plutus-scripts directory.

GHC Core to PLC plugin: E042:Error: Unsupported feature: Type constructor: GHC.Prim.Addr#
Context: Compiling type: GHC.Prim.Addr#
Context: Compiling data constructor type: Data.ByteString.Internal.PS
Context: Compiling type: Data.ByteString.Internal.ByteString
Context: Compiling data constructor type: NFTMint.NFTParams
Context: Compiling type: NFTMint.NFTParams
Context: Compiling expr: \ (mp' [Occ=OnceL1] :: NFTMint.NFTParams) ->
                           PlutusTx.Base.$
                             @ (PlutusTx.Builtins.Internal.BuiltinData
                                -> Plutus.V2.Ledger.Contexts.ScriptContext -> GHC.Types.Bool)
                             @ Plutus.Script.Utils.V1.Typed.Scripts.MonetaryPolicies.UntypedMintingPolicy
                             (Plutus.Script.Utils.V2.Typed.Scripts.MonetaryPolicies.mkUntypedMintingPolicy
                                @ PlutusTx.Builtins.Internal.BuiltinData
                                PlutusTx.IsData.Class.$fUnsafeFromDataBuiltinData)
                             (\ _ [Occ=Dead] (ctx :: Plutus.V2.Ledger.Contexts.ScriptContext) ->
                                let {
                                  info :: Plutus.V2.Ledger.Contexts.TxInfo
                                  [LclId,
                                   Unf=Unf{Src=<vanilla>, TopLvl=False, Value=False, ConLike=False,
                                           WorkFree=False, Expandable=True, Guidance=IF_ARGS [] 20 0}]
                                  info = Plutus.V2.Ledger.Contexts.scriptContextTxInfo ctx } in
                                PlutusTx.Bool.&&
                                  (PlutusTx.Trace.traceIfFalse
                                     (Data.String.fromString
                                        @ PlutusTx.Builtins.Internal.BuiltinString
                                        PlutusTx.Builtins.Class.$fIsStringBuiltinString
                                        (GHC.CString.unpackCString# "UTxO not consumed"#))
                                     (PlutusTx.Base.$
                                        @ [Plutus.V2.Ledger.Contexts.TxInInfo]
                                        @ GHC.Types.Bool
                                        (PlutusTx.Foldable.any
                                           @ []
                                           @ Plutus.V2.Ledger.Contexts.TxInInfo
                                           PlutusTx.Foldable.$fFoldable[]
                                           (\ (i [Occ=Once1] :: Plutus.V2.Ledger.Contexts.TxInInfo) ->
                                              PlutusTx.Eq.==
                                                @ Plutus.V1.Ledger.Tx.TxOutRef
                                                Plutus.V1.Ledger.Tx.$fEqTxOutRef
                                                (Plutus.V2.Ledger.Contexts.txInInfoOutRef i)
                                                (NFTMint.mpTxOutRef mp')))
                                        (Plutus.V2.Ledger.Contexts.txInfoInputs info)))
                                  (PlutusTx.Trace.traceIfFalse
                                     (Data.String.fromString
                                        @ PlutusTx.Builtins.Internal.BuiltinString
                                        PlutusTx.Builtins.Class.$fIsStringBuiltinString
                                        (GHC.CString.unpackCString# "wrong amount minted"#))
                                     (join {
                                        fail_dCmD [Occ=Once2!T[1]] :: GHC.Prim.Void# -> GHC.Types.Bool
                                        [LclId[JoinId(1)],
                                         Arity=1,
                                         Str=<L,U>,
                                         Unf=Unf{Src=<vanilla>, TopLvl=False, Value=True, ConLike=True,
                                                 WorkFree=True, Expandable=True,
                                                 Guidance=ALWAYS_IF(arity=1,unsat_ok=True,boring_ok=True)}]
                                        fail_dCmD _ [Occ=Dead, OS=OneShot] = GHC.Types.False } in
                                      case Plutus.V1.Ledger.Value.flattenValue
                                             (Plutus.V2.Ledger.Contexts.txInfoMint info)
                                      of {
                                        [] -> jump fail_dCmD GHC.Prim.void#;
                                        : ds_dCmB [Occ=Once1!] ds_dCmC [Occ=Once1!] ->
                                          case ds_dCmB of
                                          { (cs [Occ=Once1], tn' [Occ=Once1], amt [Occ=Once1]) ->
                                          case ds_dCmC of {
                                            [] ->
                                              PlutusTx.Bool.&&
                                                (PlutusTx.Eq.==
                                                   @ Plutus.V1.Ledger.Value.CurrencySymbol
                                                   Plutus.V1.Ledger.Value.$fEqCurrencySymbol0
                                                   cs
                                                   (Plutus.V2.Ledger.Contexts.ownCurrencySymbol ctx))
                                                (PlutusTx.Bool.&&
                                                   (PlutusTx.Eq.==
                                                      @ Plutus.V1.Ledger.Value.TokenName
                                                      Plutus.V1.Ledger.Value.$fEqTokenName0
                                                      tn'
                                                      ((Data.String.fromString
                                                          @ PlutusTx.Builtins.Internal.BuiltinByteString
                                                          PlutusTx.Builtins.Class.$fIsStringBuiltinByteString
                                                          (GHC.Types.[] @ GHC.Types.Char))
                                                       `cast` (Sym (Plutus.V1.Ledger.Value.N:TokenName[0])
                                                               :: GHC.Types.Coercible
                                                                    PlutusTx.Builtins.Internal.BuiltinByteString
                                                                    Plutus.V1.Ledger.Value.TokenName)))
                                                   (PlutusTx.Eq.==
                                                      @ GHC.Integer.Type.Integer
                                                      PlutusTx.Eq.$fEqInteger
                                                      amt
                                                      1));
                                            : _ [Occ=Dead] _ [Occ=Dead] -> jump fail_dCmD GHC.Prim.void#
                                          }
                                          }
                                      })))
Context: Compiling expr at "plutus-script-0.1.0.0-inplace:NFTMint:(98,8)-(98,37)"

1 Answer 1

1

The issue is not with the Plutus version but the compiler. You need to remove ! from where mpTokenName is defined. This should be fixed in the near future.

3
  • Thanks James, greatly appreciated. This will work for now but had to remove other ! references in custom datatypes I have used in my code to get it to work. Let me know if there is a bug logged for this.
    – lley154
    Sep 27, 2022 at 0:48
  • My pleasure @lley154! This bug has been reopened with reference to this question: github.com/input-output-hk/plutus/issues/4193
    – james
    Sep 27, 2022 at 8:45
  • Great - thanks James.
    – lley154
    Sep 27, 2022 at 23:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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