Skip to content

Instantly share code, notes, and snippets.

@kayvank
Last active June 11, 2024 14:29
Show Gist options
  • Save kayvank/135fd4d98fecf16a4d7a2a0ccac14f77 to your computer and use it in GitHub Desktop.
Save kayvank/135fd4d98fecf16a4d7a2a0ccac14f77 to your computer and use it in GitHub Desktop.

plutus-tx upgrade

Upgrade trustless-sidechain ghc and plutus-tx per code review from the plutus team.

Problem

We can not upgreade to newer versions of plutus-tx. Consequently, we can not upgrade to newer cardano-node. The nature of upgrade is very similar to this snipet of code:

import PlutusLedgerApi.Common (serialiseCompiledCode)
import Data.ByteString.Short (fromShort)

scriptToCBOR = Short.fromShort . serialiseCompiledCode

Summary:

This older CTL code from the module:

Ctl.Internal.Serialization.PlutusScript

that used these FFIs:

foreign import plutusScriptBytes :: PlutusScript -> ByteArray
foreign import newPlutusV1Script :: ByteArray -> PlutusScript
foreign import newPlutusV2Script :: ByteArray -> PlutusScript

is not compatable with plutus-tx 1.27 or newer.

Detail

As part of the upgrade, we changed to plutus-tx-1.27. The onchain code generates a purscript module that contains the contracts CBOR script hashes, RawScripts.purs. When applying the associated contract parameters to these newly generated CBOR hashes, we get parsing errors such as this:

☠ Failed: Calling `InitCandidatePermissionToken` because (InvalidScriptArgs (ApplyArgsError "Error applying argument to script: Parse error: So far we parsed\n\n[ (lam i[ (lam i[ (lam i[ (lam i[ (lam i[ (lam i[ (lam i(lam i(lam i(lam i(lam i(force parse error)))))) not parsed]) not parsed]) not parsed]) not parsed]) not parsed]) not parsed]) not parsed]\n\nand we ran into error: Unknown term constructor tag: 9.\n\nHere are the buffer bytes (5 preceding) [32, 32, 22, 22, 59, 32, 32, 32, 32, 90]\n\nBuffer position is 13 and buffer length is 844"))

The source of the errors are from this line in Utils.Scripts.purs and points to this import:

import Contract.Scripts 

which uses this import:

import Ctl.Internal.ApplyArgs 

which has these 2 year old FFIs that are the issue

foreign import plutusScriptBytes :: PlutusScript -> ByteArray
foreign import newPlutusV1Script :: ByteArray -> PlutusScript
foreign import newPlutusV2Script :: ByteArray -> PlutusScript
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment