IntersectMBO / plutus

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

Plutus Relese 1.21.0.0 with plcVersion110 causing AlwaysPassValidator to fail #5889

Closed reeshavacharya closed 7 months ago

reeshavacharya commented 7 months ago

Summary

I recently updated my project to plutus tag-1.21.0.0 for a minting contract, the validator is:

{-# INLINEABLE mkValidator #-}
mkValidator :: MintScriptParameter -> MintRedeemer -> ScriptContext -> Bool
mkValidator parameter redeemer ctx = case redeemer of
  FirstMint -> True
  FutureMint -> True

{-# INLINEABLE mkWrappedValidator #-}
mkWrappedValidator :: MintScriptParameter -> BuiltinData -> BuiltinData -> ()
mkWrappedValidator parameter redeemer context =
  check $
    mkValidator
      parameter
      (unsafeFromBuiltinData redeemer)
      (unsafeFromBuiltinData context)

mintTokenValidator parameter =
          $$(PlutusTx.compile [||mkWrappedValidator||])
            `applyCode` PlutusTx.liftCode plcVersion110 parameter

but while compiling the transaction, i get {"message":"","type":"PlutusScriptError"}

trying to resolve this by using plcVersion100 in all the smart contract validators, i get the following error:

Cannot apply two programs together: the first program has version Version {_versionMajor = 1, _versionMinor = 1, _versionPatch = 0} but the second program has version Version {_versionMajor = 1, _versionMinor = 0, _versionPatch = 0}
CallStack (from HasCallStack):
  error, called at prelude/PlutusPrelude.hs:250:29 in plutus-core-1.21.0.0-558ad5ec54ffdc1365ea689f545446419a80d20ff2991118785bc2d8240605e1:PlutusPrelude

Steps to reproduce the behavior

  1. Try out this example:
    
    data MintScriptParameter = MintScriptParameter
    { proposalTokenName :: TokenName,
    quorumNFTName :: TokenName,
    txOutRef :: TxOutRef
    }
    deriving (Generic, Prelude.Show)
    PlutusTx.makeIsDataIndexed 'MintScriptParameter [('MintScriptParameter, 0)]
    PlutusTx.makeLift ''MintScriptParameter

data MintRedeemer = FirstMint | FutureMint

PlutusTx.makeIsDataIndexed ''MintRedeemer [ ('FirstMint, 0), ('FutureMint, 1) ]

{-# INLINEABLE mkValidator #-} mkValidator :: MintScriptParameter -> MintRedeemer -> ScriptContext -> Bool mkValidator parameter redeemer ctx = case redeemer of FirstMint -> True -- setting redeemer cases to True for "AlwaysPass" FutureMint -> True

{-# INLINEABLE mkWrappedValidator #-} mkWrappedValidator :: MintScriptParameter -> BuiltinData -> BuiltinData -> () mkWrappedValidator parameter redeemer context = check $ mkValidator parameter (unsafeFromBuiltinData redeemer) (unsafeFromBuiltinData context)

mintTokenValidator parameter = $$(PlutusTx.compile [||mkWrappedValidator||]) applyCode PlutusTx.liftCode plcVersion100 parameter

2. Use the following function to generate the cbor as ByteString: 

mintingScript a = case mintTokenValidator a of Left _ -> error "Error Parsing MintingScript" Right compiledCode -> BS8.unpack $ parseToScript compiledCode where parseToScript :: CompiledCode a -> BS8.ByteString parseToScript compiledCode = Base16.encode $ fromShort $ serialiseCompiledCode compiledCode

3. compile the minting transaction

{ "mint": [ { "script": { "cborHex": "58910101003222328001919192999ab9a3370e90000010c00054ccd5cd19b874800800860042c6aae78008d55ce8009baa002335122333335122002222800801c00a0022129002800922010850726f706f73616c0048810651756f72756d0033002489200d967444377dd05f4a5e9d9bfdf168b959bed43655635f8daa63a07f1bd2ff7c00480108a002005001109480140041", "description": "", "type": "PlutusScriptV2" }, "redeemer": { "constructor": 0, "fields": [] }, "amount": { "Token1": 1, "Token2": 1 } } ], "outputs": [ { "address": "addr_test1wq3zhud8la6u6ygmpu30at3vt8k3juathxxjujhklzapxtsj3lx7f", "value": "934d8750c215e0a05232c34cadf5dac5825d78f0820dd5178ab784f4.Token1", "datum": { "constructor": 0, "fields": [] } }, { "address": "addr_test1wq3zhud8la6u6ygmpu30at3vt8k3juathxxjujhklzapxtsj3lx7f", "value": "934d8750c215e0a05232c34cadf5dac5825d78f0820dd5178ab784f4.Token2", "datum": { "constructor": 0, "fields": [] } } ] }


### Actual Result

The transaction generates a ScriptError:
`{"message":"","type":"PlutusScriptError"}`

### Expected Result

The transaction should compile with no errors as the minting policy is generated in such a way that no-matter what the redeemer is, the validation will always be True. 

### Describe the approach you would take to fix this

_No response_

### System info

Plutus Tag : 1.21.0.0 

Cabal.Project uses: 

-- Custom repository for cardano haskell packages, see CONTRIBUTING for more repository cardano-haskell-packages url: https://chap.intersectmbo.org/ secure: True root-keys: 3e0cce471cf09815f930210f7827266fd09045445d65923e6d0238a6cd15126f 443abb7fb497a134c343faf52f0b659bd7999bc06b7f63fa76dc99d631f9bea1 a86a1f6ce86c449c46666bda44268677abf29b5b2d2eb5ec7af903ec2f117a82 bcec67e8e99cabfa7764d75ad9b158d72bfacf70ca1d0ec8bc6b4406d1bf8413 c00aae8461a256275598500ea0e187588c35a5d5d7454fb57eac18d9edb86a56 d4a35cd3121aa00d18544bb0ac01c3e1691d618f462c46129271bccf39f7e8ee

-- See CONTRIBUTING for information about these, including some Nix commands -- you need to run if you change them index-state: , hackage.haskell.org 2024-03-20T14:55:30Z , cardano-haskell-packages 2024-03-20T14:22:58Z

... Package Descriptions

-- You never, ever, want this. write-ghc-environment-files: never

-- Always build tests and benchmarks. tests: True benchmarks: False

source-repository-package type: git location: https://github.com/dquadrant/kuber tag: 0bfea4fea31eb20ce9fbc33cfe9907f92a11e5f1

constraints: hedgehog >= 1.0 , bimap >= 0.4.0 , libsystemd-journal >= 1.4.4 , systemd >= 2.3.0 -- systemd-2.3.0 requires at least network 3.1.1.0 but it doesn't declare -- that dependency , network >= 3.1.1.0 , HSOpenSSL >= 0.11.7.2

package snap-server flags: +openssl

package comonad flags: -test-doctests

allow-newer: *:aeson, monoidal-containers:aeson, size-based:template-haskell

Unisay commented 7 months ago

This error, {"message":"","type":"PlutusScriptError"} - where does it come from? Do you have any additional information about the error, e.g. logs or stack traces?

reeshavacharya commented 7 months ago

The error is produced while calculating execution units from Cardano-API here's the code for evaluating ex-units: here

Unisay commented 7 months ago

The error is produced while calculating execution units from Cardano-API

When Plutus script evaluation fails Cardano.Api captures it as a ScriptExecutionError

    ScriptErrorEvaluationFailed evalErr logs ->
      mconcat
        [ "The Plutus script evaluation failed: " <> pretty evalErr
        , "\nScript debugging logs: " <> mconcat (map (\t -> pretty $ t `Text.append` "\n") logs)
        ]

There isn't enough information in the error as it is presented in this ticket:

Cardano API's error embeds Plutus.EvaluationError together with additional textual information:

ScriptErrorEvaluationFailed Plutus.EvaluationError [Text.Text]

I assume this information is lost somewhere between Cardano API and Kuber.

Without seeing the Plutus.EvaluationError and without knowing the used plutus-ledger-api version its impossible for Plutus developers to reason about the problem.

Please contact maintainers of these repositories for the details.

reeshavacharya commented 7 months ago

We logged the error: {"message":"CodecError Deserialization : PlutusCoreLanguageNotAvailableError {sdeAffectedVersion = Version {_versionMajor = 1, _versionMinor = 1, _versionPatch = 0}, sdeThisPv = 9} : []","type":"PlutusScriptError"}

we are testing on sanchonet. the plutus-ledger-api version is 1.21.0.0 cardano-api version is 8.39.3.0, cardano-node version is 8.8.1

Unisay commented 7 months ago

One potential reason you are getting this error is that you are using either Plutus Language Version V1 or V2, but the Plutus Core version 1.1.0 is only supported by the V3. (Different versions are explained here)

We have improved the error message in the plutus-ledger-api 1.22.1.0

Unisay commented 7 months ago

@reeshavacharya please report back if you have fixed the problem so that we can close this issue. Thank you!

reeshavacharya commented 7 months ago

@Unisay i have not fixed it yet. but this issue can be closed.