IntersectMBO / plutus

The Plutus language implementation and tools
Apache License 2.0
1.57k stars 476 forks source link

takeByteString causes Core to PLC error #3747

Closed anton-k closed 3 years ago

anton-k commented 3 years ago

Area

[x] Plutus Foundation Related to the GHC plugin, Haskell-to-Plutus compiler, on-chain code [] Plutus Application Framework Related to the Plutus application backend (PAB), emulator, Plutus libraries [] Marlowe Related to Marlowe [] Other Any other topic (Playgrounds, etc.)

Summary

After update to the newest plutus version I get error of converting to PlutusCore while using takeByteString

GHC Core to PLC plugin: E043:Error: Reference to a name which is not a local, a builtin, or an external INLINABLE function: Variable GHC.Integer.Type.minusInteger
            No unfolding
Context: Compiling expr: GHC.Integer.Type.minusInteger
Context: Compiling expr: GHC.Integer.Type.minusInteger n
Context: Compiling expr: GHC.Integer.Type.minusInteger n 1
Context: Compiling expr: PlutusTx.Builtins.Internal.sliceByteString
                           0 (GHC.Integer.Type.minusInteger n 1)
Context: Compiling expr: PlutusTx.Builtins.Internal.sliceByteString
                           0 (GHC.Integer.Type.minusInteger n 1) bs
Context: Compiling expr: \ (bs [Occ=Once]
                              :: PlutusTx.Builtins.Internal.BuiltinByteString) ->
                           PlutusTx.Builtins.Internal.sliceByteString
                             0 (GHC.Integer.Type.minusInteger n 1) bs
Context: Compiling expr: \ (n [Occ=Once] :: GHC.Integer.Type.Integer)
                           (bs [Occ=Once] :: PlutusTx.Builtins.Internal.BuiltinByteString) ->
                           PlutusTx.Builtins.Internal.sliceByteString
                             0 (GHC.Integer.Type.minusInteger n 1) bs
Context: Compiling definition of: PlutusTx.Builtins.takeByteString
Context: Compiling expr: PlutusTx.Builtins.takeByteString
Context: Compiling expr: PlutusTx.Builtins.takeByteString 31
Context: Compiling expr: PlutusTx.Builtins.takeByteString
                           31
                           (PlutusTx.Builtins.Internal.sha2_256
                              (Sundae.Contracts.catPair coinA coinB))
Context: Compiling expr: PlutusTx.Builtins.Internal.appendByteString
                           Sundae.Contracts.computeEscrowTokenName3
                           (PlutusTx.Builtins.takeByteString

haskell code:

{-# inlinable catPair #-}
catPair (AssetClass (acs,atn)) (AssetClass (bcs,btn)) =
   unCurrencySymbol acs <>
   pairDelim <>
   unTokenName atn <>
   pairDelim <>
   unCurrencySymbol bcs <>
   pairDelim <>
   unTokenName btn

{-# inlinable computeLiquidityTokenName #-}
computeLiquidityTokenName :: AssetClass -> AssetClass -> TokenName
computeLiquidityTokenName coinA coinB =
  TokenName $ snd liquidityTokenNamePrefix <> takeByteString 31 (sha2_256 $ catPair coinA coinB)

pairDelim = "//" :: BuiltinByteString
liquidityTokenNamePrefix = (1, "l" :: BuiltinByteString)
ghost commented 3 years ago

Thanks for the issue! And sorry for the inconvenience. Will be fixed in #3743.

anton-k commented 3 years ago

Thanks for that, very quick fix!