Skip to content

plutus-tx-plugin 1.70.0.0 and 1.71.0.0 crash when compiling unsafeFromBuiltinData for PlutusLedgerApi.V4.ScriptContext #7970

Closed

Description

@carbolymer

Summary

Any Plinth validator that decodes a PlutusLedgerApi.V4.ScriptContext with unsafeFromBuiltinData makes plutus-tx-plugin abort with an internal error.
Reproduced on 1.70.0.0 and on 1.71.0.0 (release commit 261766a), with identical output.
The crash happens while deriving the UnsafeFromData dictionary for ProposalProcedure, reached transitively through TxInfo.
A validator that ignores its argument compiles fine, so the problem is specific to the V4 context decoders.

Environment

  • plutus-core, plutus-ledger-api, plutus-tx, plutus-tx-plugin 1.70.0.0, and again 1.71.0.0 built from the release commit
  • GHC 9.6.7, cabal-install 3.18.1.0, nix shell of plinth-template on the bump-plutus-1.70.0.0 branch:
  • Same GHC options as the template's AuctionValidator.hs.

Minimal reproduction

Add this module to the template's plinth-validators library and build it.

module V4Repro (reproCode) where

import PlutusLedgerApi.V4 (ScriptContext (..))
import PlutusTx
import PlutusTx.Prelude

{-# INLINEABLE repro #-}
repro :: BuiltinData -> BuiltinUnit
repro d = check (case (unsafeFromBuiltinData d :: ScriptContext) of ScriptContext {} -> True)

reproCode :: CompiledCode (BuiltinData -> BuiltinUnit)
reproCode = $$(PlutusTx.compile [||repro||])

Error

<no location info>: error:
    Plinth Compilation Error:
Context: Compiling code:
         \ (d [Occ=Once1!] :: PlutusTx.Builtins.Internal.BuiltinData) -> ...
...
Context: Compiling code:
         PlutusTx.Builtins.Internal.caseData
           @(PlutusLedgerApi.V1.Value.Lovelace,
             PlutusLedgerApi.V1.Credential.Credential,
             PlutusLedgerApi.V4.Contexts.GovernanceAction)
           d1
           PlutusLedgerApi.V4.Contexts.$fUnsafeFromDataProposalProcedure2
Error: Unexpected error during compilation, please report this to the Plutus team: Unexpected expression where a list constructor was expected

The full log is about 36k lines of nested Context: Compiling code: frames descending from ScriptContext through TxInfo to ProposalProcedure, GovernanceAction and Committee.

What we tried

  • -fplugin-opt PlutusTx.Plugin:conservative-optimisation: same crash.
  • Decoding the context by hand with PlutusTx.Builtins.Internal.unsafeDataAsConstr and only decoding small field types (ScriptHash, CurrencySymbol, AccountId, [TxInInfo]): compiles cleanly.
    This is the workaround we use for our V4 test validators.
  • An always-succeeds validator that ignores its argument compiles and produces the same bytes as its V3 build (46450101002499).

Why it matters

Decoding the script context is the first thing almost every real V4 validator does, so with 1.70.0.0 or 1.71.0.0 no non-trivial V4 script can be compiled with Plinth.
We hit this while producing Plutus V4 test fixtures for cardano-api, cardano-cli and cardano-node.

Possibly related

The message is raised by compileHaskellList in plutus-tx-plugin/src/PlutusTx/Compiler/Expr.hs (line 871 at tag 1.70.0.0).
The failing instance is a single-constructor ledger type, which recently moved to a Data.List based encoding, so these may be connected:

A search of the tracker found no existing report of this crash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions