-
Notifications
You must be signed in to change notification settings - Fork 476
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Require PlutusV3 scripts to evaluate to BuiltinUnit #6159
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bf50cca
Require PlutusV3 scripts to evaluate to BuiltinUnit
zliu41 a57f342
fix build
zliu41 5dad08e
Merge branch 'master' of github.com:IntersectMBO/plutus into zliu41/unit
zliu41 5507065
Address comments
zliu41 7f17ccb
Merge branch 'master' of github.com:IntersectMBO/plutus into zliu41/unit
zliu41 85e8a35
Address some comments
zliu41 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 | ||
effectfully marked this conversation as resolved.
Show resolved
Hide resolved
|
||
(_, 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 = | ||
effectfully marked this conversation as resolved.
Show resolved
Hide resolved
|
||
$$( compile | ||
[|| | ||
\d _ -> | ||
let n = PlutusTx.unsafeFromBuiltinData d | ||
in check (PlutusTx.greaterThanInteger n 0) | ||
||] | ||
) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we over-constrain ourselves to
BuiltinUnit
? Theoretically we would be fine with any constant? I was tempted and usedasConstant
to see what happens and it works, but I am not sure if it is as safe asreadKnown
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what the CIP proposed. To quote @michaelpj 's words:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough.