-
Notifications
You must be signed in to change notification settings - Fork 479
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Require PlutusV3 scripts to evaluate to BuiltinUnit (#6159)
- Loading branch information
Showing
15 changed files
with
379 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
plutus-ledger-api/changelog.d/20240530_113312_unsafeFixIO_unit.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
### Changed | ||
|
||
- `evaluateScriptRestricting` and `evaluateScriptCounting` now require Plutus V3 | ||
scripts to return `BuiltinUnit`, otherwise the evaluation is considered to | ||
have failed, and a `InvalidReturnValue` error is thrown. There is no such | ||
requirement on Plutus V1 and V2 scripts. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
{-# LANGUAGE BangPatterns #-} | ||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE GADTs #-} | ||
{-# LANGUAGE LambdaCase #-} | ||
{-# LANGUAGE MultiParamTypeClasses #-} | ||
{-# LANGUAGE NegativeLiterals #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# LANGUAGE PatternSynonyms #-} | ||
{-# LANGUAGE TemplateHaskell #-} | ||
{-# LANGUAGE ViewPatterns #-} | ||
{-# OPTIONS_GHC -fplugin-opt PlutusTx.Plugin:target-version=1.0.0 #-} | ||
|
||
module Spec.ReturnUnit.V1 where | ||
|
||
import PlutusLedgerApi.Common.Versions | ||
import PlutusLedgerApi.Test.V1.EvaluationContext qualified as V1 | ||
import PlutusLedgerApi.V1 as V1 | ||
import PlutusPrelude | ||
import PlutusTx.Builtins qualified as PlutusTx | ||
import PlutusTx.Code | ||
import PlutusTx.IsData qualified as PlutusTx | ||
import PlutusTx.Prelude (BuiltinUnit, check) | ||
import PlutusTx.TH (compile) | ||
|
||
import Test.Tasty (TestName, TestTree, testGroup) | ||
import Test.Tasty.HUnit | ||
|
||
import Control.Monad.Writer | ||
|
||
tests :: TestTree | ||
tests = | ||
testGroup | ||
"Plutus V1 validators may evaluate to any value" | ||
[ expectSuccess "should succeed" good (I 1) | ||
, expectSuccess "returns Bool" returnsBool (I 1) | ||
, expectSuccess "too many parameters" tooManyParameters (I 1) | ||
] | ||
|
||
evalCtx :: V1.EvaluationContext | ||
evalCtx = | ||
fst . unsafeFromRight . runWriterT . V1.mkEvaluationContext $ | ||
fmap snd V1.costModelParamsForTesting | ||
|
||
expectSuccess :: | ||
forall a. | ||
TestName -> | ||
CompiledCode (BuiltinData -> a) -> | ||
-- | Script argument | ||
Data -> | ||
TestTree | ||
expectSuccess name code arg = testCase name $ case res of | ||
Left _ -> assertFailure "fails" | ||
Right _ -> pure () | ||
where | ||
sScript = serialiseCompiledCode code | ||
script = either (error . show) id $ V1.deserialiseScript conwayPV sScript | ||
(_, res) = V1.evaluateScriptCounting conwayPV V1.Quiet evalCtx script [arg] | ||
|
||
good :: CompiledCode (BuiltinData -> BuiltinUnit) | ||
good = | ||
$$( compile | ||
[|| | ||
\d -> | ||
let n = PlutusTx.unsafeFromBuiltinData d | ||
in check (PlutusTx.greaterThanInteger n 0) | ||
||] | ||
) | ||
|
||
returnsBool :: CompiledCode (BuiltinData -> Bool) | ||
returnsBool = | ||
$$( compile | ||
[|| | ||
\d -> | ||
let n = PlutusTx.unsafeFromBuiltinData d | ||
in PlutusTx.greaterThanInteger n 0 | ||
||] | ||
) | ||
|
||
tooManyParameters :: CompiledCode (BuiltinData -> BuiltinData -> BuiltinUnit) | ||
tooManyParameters = | ||
$$( compile | ||
[|| | ||
\d _ -> | ||
let n = PlutusTx.unsafeFromBuiltinData d | ||
in check (PlutusTx.greaterThanInteger n 0) | ||
||] | ||
) |
Oops, something went wrong.