Skip to content

Generate array builtin scripts for all Plutus version combinations #14

@Unisay

Description

@Unisay

Context

PR #12 added array builtin validators (indexArray, lengthOfArray, listToArray) targeting PlutusV3 with Plutus language 1.1.0, generating 3 scripts.

At Protocol Version 11, array builtins become available across all Plutus versions and language versions:

  • Plutus versions: V1, V2, V3
  • Language versions: 1.0.0, 1.1.0
  • Functions: indexArray, lengthOfArray, listToArray

Total combinations needed: 3 × 3 × 2 = 18 scripts

Current status: Only 3 scripts exist (V3/1.1.0)
Missing: 15 scripts need to be generated

Related: cardano-node-tests PR #3227 implements test infrastructure for full version matrix.

Tasks

1. Create Compilation Modules

Create 5 new Haskell modules in plutus-scripts/PlutusScripts/Array/:

  • V1_1_0_0.hs - PlutusV1 targeting language 1.0.0
  • V1_1_1_0.hs - PlutusV1 targeting language 1.1.0
  • V2_1_0_0.hs - PlutusV2 targeting language 1.0.0
  • V2_1_1_0.hs - PlutusV2 targeting language 1.1.0
  • V3_1_0_0.hs - PlutusV3 targeting language 1.0.0
  • Rename V_1_1.hsV3_1_1_0.hs (PlutusV3/1.1.0, already exists)

2. Pattern to Follow

Each module should follow this structure (example for V1/1.0.0):

{-# LANGUAGE DataKinds #-}
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}

{-# HLINT ignore "Use underscore" #-}

module PlutusScripts.Array.V1_1_0_0 where

import PlutusCore.Version (plcVersion100)
import PlutusLedgerApi.Common (SerialisedScript, serialiseCompiledCode)
import PlutusLedgerApi.V1 qualified as PlutusV1
import PlutusTx qualified

import PlutusScripts.Array.Common qualified as Common

indexArrayPolicyScriptSerialised :: SerialisedScript
indexArrayPolicyScriptSerialised = serialiseCompiledCode
  $$(PlutusTx.compile [|| wrap ||])
  where wrap = PlutusV1.mkMintingPolicyScript ($$Common.mkIndexArrayPolicy)

lengthOfArrayPolicyScriptSerialised :: SerialisedScript
lengthOfArrayPolicyScriptSerialised = serialiseCompiledCode
  $$(PlutusTx.compile [|| wrap ||])
  where wrap = PlutusV1.mkMintingPolicyScript ($$Common.mkLengthOfArrayPolicy)

listToArrayPolicyScriptSerialised :: SerialisedScript
listToArrayPolicyScriptSerialised = serialiseCompiledCode
  $$(PlutusTx.compile [|| wrap ||])
  where wrap = PlutusV1.mkMintingPolicyScript ($$Common.mkListToArrayPolicy)

Key changes per version:

  • V1: Use PlutusLedgerApi.V1 and PlutusV1.mkMintingPolicyScript
  • V2: Use PlutusLedgerApi.V2 and PlutusV2.mkMintingPolicyScript
  • V3: Use PlutusLedgerApi.V3 and PlutusV3.mkMintingPolicyScript
  • Language 1.0.0: Import plcVersion100
  • Language 1.1.0: Import plcVersion110

3. Update Main.hs

Add envelope generation for all 18 scripts in app/Main.hs:

import PlutusScripts.Array.V1_1_0_0 qualified as ArrayV1_1_0_0
import PlutusScripts.Array.V1_1_1_0 qualified as ArrayV1_1_1_0
import PlutusScripts.Array.V2_1_0_0 qualified as ArrayV2_1_0_0
import PlutusScripts.Array.V2_1_1_0 qualified as ArrayV2_1_1_0
import PlutusScripts.Array.V3_1_0_0 qualified as ArrayV3_1_0_0
import PlutusScripts.Array.V3_1_1_0 qualified as ArrayV3_1_1_0

main :: IO ()
main = do
  -- ... existing code ...
  
  -- Array V1/1.0.0
  writeEnvelope "succeedingIndexArrayPolicyScriptV1_1_0_0.plutus"
    ArrayV1_1_0_0.indexArrayPolicyScriptSerialised
  writeEnvelope "succeedingLengthOfArrayPolicyScriptV1_1_0_0.plutus"
    ArrayV1_1_0_0.lengthOfArrayPolicyScriptSerialised
  writeEnvelope "succeedingListToArrayPolicyScriptV1_1_0_0.plutus"
    ArrayV1_1_0_0.listToArrayPolicyScriptSerialised
    
  -- Repeat for V1/1.1.0, V2/1.0.0, V2/1.1.0, V3/1.0.0, V3/1.1.0

4. Generate Scripts

cabal run envelopes

Verify 18 script files generated in serialised-plutus-scripts/:

  • succeedingIndexArrayPolicyScriptV1_1_0_0.plutus
  • succeedingIndexArrayPolicyScriptV1_1_1_0.plutus
  • ... (all 18 combinations)

5. Update plutus-scripts.cabal

Add new modules to exposed-modules:

exposed-modules:
    PlutusScripts.Array.Common
    PlutusScripts.Array.V1_1_0_0
    PlutusScripts.Array.V1_1_1_0
    PlutusScripts.Array.V2_1_0_0
    PlutusScripts.Array.V2_1_1_0
    PlutusScripts.Array.V3_1_0_0
    PlutusScripts.Array.V3_1_1_0

6. Copy Scripts to cardano-node-tests

Once generated, copy scripts to respective directories in cardano-node-tests:

# V1 scripts
cp succeedingIndexArrayPolicyScriptV1_1_0_0.plutus \
   cardano-node-tests/cardano_node_tests/tests/data/plutus/v1/batch6/1.0.0/

cp succeedingIndexArrayPolicyScriptV1_1_1_0.plutus \
   cardano-node-tests/cardano_node_tests/tests/data/plutus/v1/batch6/1.1.0/

# Repeat for V2 and V3...

See READMEs in each directory for exact file paths:

  • cardano-node-tests/cardano_node_tests/tests/data/plutus/v1/batch6/README.md
  • cardano-node-tests/cardano_node_tests/tests/data/plutus/v2/batch6/README.md
  • cardano-node-tests/cardano_node_tests/tests/data/plutus/v3/batch6/README.md

Expected Files

V1 (6 scripts)

  • v1/batch6/1.0.0/succeedingIndexArrayPolicyScriptV1_1_0_0.plutus
  • v1/batch6/1.0.0/succeedingLengthOfArrayPolicyScriptV1_1_0_0.plutus
  • v1/batch6/1.0.0/succeedingListToArrayPolicyScriptV1_1_0_0.plutus
  • v1/batch6/1.1.0/succeedingIndexArrayPolicyScriptV1_1_1_0.plutus
  • v1/batch6/1.1.0/succeedingLengthOfArrayPolicyScriptV1_1_1_0.plutus
  • v1/batch6/1.1.0/succeedingListToArrayPolicyScriptV1_1_1_0.plutus

V2 (6 scripts)

  • v2/batch6/1.0.0/succeedingIndexArrayPolicyScriptV2_1_0_0.plutus
  • v2/batch6/1.0.0/succeedingLengthOfArrayPolicyScriptV2_1_0_0.plutus
  • v2/batch6/1.0.0/succeedingListToArrayPolicyScriptV2_1_0_0.plutus
  • v2/batch6/1.1.0/succeedingIndexArrayPolicyScriptV2_1_1_0.plutus
  • v2/batch6/1.1.0/succeedingLengthOfArrayPolicyScriptV2_1_1_0.plutus
  • v2/batch6/1.1.0/succeedingListToArrayPolicyScriptV2_1_1_0.plutus

V3 (6 scripts)

  • v3/batch6/1.0.0/succeedingIndexArrayPolicyScriptV3_1_0_0.plutus
  • v3/batch6/1.0.0/succeedingLengthOfArrayPolicyScriptV3_1_0_0.plutus
  • v3/batch6/1.0.0/succeedingListToArrayPolicyScriptV3_1_0_0.plutus
  • v3/batch6/1.1.0/succeedingIndexArrayPolicyScriptV3_1_1_0.plutus ✅ (exists)
  • v3/batch6/1.1.0/succeedingLengthOfArrayPolicyScriptV3_1_1_0.plutus ✅ (exists)
  • v3/batch6/1.1.0/succeedingListToArrayPolicyScriptV3_1_1_0.plutus ✅ (exists)

Benefits

  • Complete E2E test coverage for array builtins at PV11
  • Same pattern applies to other batch6 builtins (dropList, etc.)
  • Test infrastructure already implemented in cardano-node-tests PR #3227

References

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions