Skip to content
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

Bump to latest Plutarch #52

Merged
merged 6 commits into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 0.7.0 - Bump plutus version to 1.23.0.0
kozross marked this conversation as resolved.
Show resolved Hide resolved

- Renamed `ValidatorRole` and `MintingPolicyRole` to `ThreeArgumentScript` and `TwoArgumentScript`.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the point behind this change. I think it's not only unnecessary, but perhaps also backwards.

The roles communicate to the user the purpose of a script. We have not removed any ambiguity, but added more. TwoArgumentScript does not tell us whether it's a minting policy or a staking validator, yet their usage is vastly different.

Unifying should not be done at a type level. After all, type aliases are almost always inferior to newtypes. This is the same concept. Unifying should instead be done at the instance and usage level. You could have parseStakeValidator and parseMintingPolicy both use common helpers, but it's important for both of them to actually check the role.

The argument that "runMintingPolicy" and "runStakingValidator" have the same implementation seems moot. Just alias them. They are usage site, it's fine to alias them there. Or even have runScriptWithDatum and runScript depending on how you want the interface to be. Notice how all these changes are losing information downstream. It doesn't seem correct to lose the information at the source.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Furthermore, the ecosystem is much more aware of the terms "StakingValidator", "Validator", "MintingPolicy". Introducing new terms (though they are very simple terms) seems weird. I have never seen any project so far refer to them as "ThreeArgumentScript" and "TwoArgumentScript" - but this point is far less relevant than the fact that we are losing information by this transformation.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @TotallyNotChase, I'm the one who introduced the naming in the last PR. This comes from the idea that we cannot distinguish between a stake validator and a minting policy. I don't know what is more confusing: having a staking validator with the role MintingPolicyRole or one with the role TwoArgumentScript. The only information that got lost in the script role is, as far as I remember, the script's versioning. I agree that the script role does not make sense anymore. Perhaps we should drop it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My point is that there can be a new role for StakeValidator. Again, this is not redundant because this is essentially a typing component. Same way as newtypes often carry invariants, therefore not being redundant.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that role description really relevant? In V3, we will have even more unified scripts. From that perspective, I don't think keeping those roles will be very useful in the future; it might increase confusion. Adding a new role for StakeValidator does not add much value and is not particularly future-proof IMHO

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is the CIP: CIP-0069

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see, It's this one! It's been a long time but I remember this from back when Maks actually proposed it (he used to work at MLabs).

Anyway, this isn't actually an approved CIP and it has been in talks for awhile. There's no actual indication that it'll be approved and implemented. I remember Las liked the idea back when me and him were initially building Plutarch but it never ended up affecting any development since it was never even close to being actually approved.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless we're talking about this one: cardano-foundation/CIPs#784 ?

It seems like this one's different from the one linked at cardano.org, but it seems more promising.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like this one's different from the one linked at cardano.org, but it seems more promising.

What do you mean? Do you see differences between the link I've shared and that PR? To me it seems the diffs into that branch were ported into cardano.org (actually I assume that page is automatically generated). Am I missing something?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The linked CIP PR in the cardano.org page is the original old PR (the latest comment on it just says that it is not approved). But looks like the diffs are indeed from an updated PR that seems more promising.

I can see that happening in the future. And so, as I mentioned before, I'm totally open to removing roles entirely. But please not in this PR. In a separate PR in the future, when that CIP is actually implemented and the ecosystem has started moving towards it.

- Dropped V1 support for `Ply.Plutarch`.

# 0.6.0 - Bump plutus version to 1.7.0.0

# 0.5.0 - More detailed parameter type encoding that supports data encoded parameters.
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ Ply allows you to serialize your Plutarch validators/minting policies (with opti

This facilitates the onchain/offchain split that is often utilized, without forcing the user to manage the intricacies of the types and their UPLC representation when it comes to parameterized scripts. i.e scripts that take extra parameters before being submitted to the chain.

> N.B: Ply currently integrates with Plutarch 1.3, **with a minor revision**. You **MUST** ensure you're using a commit that includes [this patch](https://github.com/Plutonomicon/plutarch-plutus/pull/601).

# Goals

- Efficiency: Applying constants with `Ply` should be equally efficient as using `pconstant`/`pconstantData` in the Plutarch function body directly.
Expand Down
6 changes: 3 additions & 3 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ repository cardano-haskell-packages

source-repository-package
type: git
--sha256: sha256-aeaZMW5Y3r5GdSyrfrrKOuGahcL5MVkDUNggunbmtv0=
--sha256: sha256-Vg0U0QHolNHhBH2EaMHmFxeMt+Mv+thbY58PuVpWRlQ=
location: https://github.com/Plutonomicon/plutarch-plutus.git
tag: 288d9140468ae98abe1c9a4c0bb1c19a82eb7cd6
tag: 7913e2d883530f569b16c02878989d3394bab727
subdir:
.
plutarch-ledger-api
plutarch-extra

write-ghc-environment-files: never
Expand All @@ -32,7 +33,6 @@ test-show-details: direct

constraints:
, dependent-sum >= 0.7.1.0
, plutus-core >= 1.7.0.0

package nothunks
flags: +vector
4 changes: 2 additions & 2 deletions example/compiler-app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ module Main (main) where

import System.FilePath ((</>))

import Plutarch (Config (Config, tracingMode), TracingMode (DoTracing))
import Plutarch (Config (Tracing), LogLevel (LogInfo), TracingMode (DoTracing))
import Ply.Plutarch

import Example.NftM (nftMp)

main :: IO ()
main =
writeTypedScript
(Config {tracingMode = DoTracing})
(Tracing LogInfo DoTracing)
"NFT Minting Policy (DoTracing)"
("compiled" </> "nftMp.plutus")
nftMp
1 change: 1 addition & 0 deletions example/example.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ common common-deps
build-depends:
, base
, plutarch
, plutarch-ledger-api
, plutus-core
, plutus-ledger-api
, plutus-tx
Expand Down
4 changes: 2 additions & 2 deletions example/reader-app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import qualified Data.ByteString.Base16 as Base16
import qualified Data.ByteString.Short as SBS
import qualified Data.Text as Text
import qualified Data.Text.Encoding as Text
import PlutusLedgerApi.V1
import PlutusLedgerApi.V2
import Ply
import UntypedPlutusCore

Expand All @@ -21,7 +21,7 @@ instance Show MintingPolicy where
. serialiseUPLC
. (\(MintingPolicy x) -> x)

toMintingPolicy :: TypedScript 'MintingPolicyRole '[] -> MintingPolicy
toMintingPolicy :: TypedScript 'TwoArgumentScript '[] -> MintingPolicy
toMintingPolicy (TypedScript _ s) = MintingPolicy s

usePolicy :: MintingPolicy -> IO ()
Expand Down
9 changes: 3 additions & 6 deletions example/src/Example/NftM.hs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module Example.NftM (nftMp) where

import Plutarch.Api.V1
import qualified Plutarch.Api.V1.Value as PValue
import Plutarch.LedgerApi
kozross marked this conversation as resolved.
Show resolved Hide resolved
import qualified Plutarch.LedgerApi.Value as PValue
import Plutarch.Prelude

nftMp :: ClosedTerm (PTxOutRef :--> PTokenName :--> PMintingPolicy)
nftMp :: ClosedTerm (PTxOutRef :--> PTokenName :--> PData :--> PScriptContext :--> POpaque)
nftMp = plam $ \ref tn _ ctx' -> popaque $
unTermCont $ do
ctx <- tcont $ pletFields @'["txInfo", "purpose"] ctx'
Expand All @@ -17,6 +17,3 @@ nftMp = plam $ \ref tn _ ctx' -> popaque $
pguardC "Wrong NFT mint amount" $
PValue.pvalueOf # getField @"mint" txInfo # ownSym # tn #== 1
pure $ pconstant ()

pguardC :: Term s PString -> Term s PBool -> TermCont s ()
pguardC s cond = tcont $ \f -> pif cond (f ()) $ ptraceError s
97 changes: 93 additions & 4 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
flake = false;
};
pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix";
iohk-nix.url = "github:input-output-hk/iohk-nix";
};

outputs = { nixpkgs, flake-utils, haskellNix, CHaP, pre-commit-hooks, ... }:
outputs = { nixpkgs, flake-utils, haskellNix, CHaP, pre-commit-hooks, iohk-nix, ... }:
let
# NOTE: nix flake (show | check) --allow-import-from-derivation --impure
systems =
Expand Down Expand Up @@ -45,13 +46,15 @@
inherit system;
overlays = [
haskellNix.overlay
iohk-nix.overlays.crypto
iohk-nix.overlays.haskell-nix-crypto
];
inherit (haskellNix) config;
};

ply = pkgs.haskell-nix.cabalProject' {
src = ./.;
compiler-nix-name = "ghc963";
compiler-nix-name = "ghc96";
shell = {
# This is used by `nix develop .` to open a shell for use with
# `cabal`, `hlint` and `haskell-language-server` etc
Expand Down
2 changes: 1 addition & 1 deletion genPurs/genPurs.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 3.0
name: ply-ctl
version: 0.6.0
version: 0.7.0
author: Seungheon <Seungheon@mlabs.city>
license: MIT

Expand Down
2 changes: 1 addition & 1 deletion ply-core/ply-core.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 3.0
name: ply-core
version: 0.6.0
version: 0.7.0
author: Chase <chase@mlabs.city>
license: MIT

Expand Down
4 changes: 2 additions & 2 deletions ply-core/src/Ply.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import Ply.Core.Typename (plyTypeName)
import Ply.Core.Types (
AsData (..),
ScriptReaderException (..),
ScriptRole (MintingPolicyRole, ValidatorRole),
ScriptRole (ThreeArgumentScript, TwoArgumentScript),
ScriptVersion (..),
TypedScript (TypedScriptConstr),
TypedScriptEnvelope (..),
Expand All @@ -47,7 +47,7 @@ For example, if using 'plutus-apps' - you can create a function that determines
`plutusV1OtherScript` or `plutusV2OtherScript` in your script lookups:

@
unifiedOtherScript :: TypedScript ValidatorRole '[] -> ScriptLookups a
unifiedOtherScript :: TypedScript ThreeArgumentScript '[] -> ScriptLookups a
unifiedOtherScript (TypedScript ver s) = (if ver == ScriptV1 then plutusV1OtherScript else plutusV2OtherScript) vald
where
ver = Ply.getPlutusVersion ts
Expand Down
6 changes: 3 additions & 3 deletions ply-core/src/Ply/Core/Class.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Data.Text (Text)
import GHC.TypeLits (ErrorMessage (ShowType, Text))
import Ply.Core.Types (AsData (AsData))

import PlutusCore (DefaultUni, Includes, Some, ValueOf)
import PlutusCore (DefaultUni, HasTermLevel, Some, ValueOf)
import qualified PlutusCore as PLC
import qualified PlutusTx.AssocMap as PlutusMap

Expand Down Expand Up @@ -53,7 +53,7 @@ As a result, 'toBuiltinArg' is partial for types that don't hold their invariant

4. 'toBuiltinArgData' implementation must perform the same validations/normalizations as 'toBuiltinArg'.
-}
class DefaultUni `Includes` UPLCRep a => PlyArg a where
class DefaultUni `HasTermLevel` UPLCRep a => PlyArg a where
type UPLCRep a :: Type
type ToDataConstraint a :: Constraint
type ToDataConstraint a = ()
Expand Down Expand Up @@ -153,7 +153,7 @@ instance PlyArg Value where
( \(cs, tkMap) ->
( toBuiltinArgData cs
, toBuiltinArgData
. PlutusMap.fromList
. PlutusMap.unsafeFromList
$ map (bimap toBuiltinArg toBuiltinArg) tkMap
)
)
Expand Down
8 changes: 4 additions & 4 deletions ply-core/src/Ply/Core/Internal/Reify.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ instance ReifyVersion ScriptV1 where
instance ReifyVersion ScriptV2 where
reifyVersion _ = ScriptV2

instance ReifyRole ValidatorRole where
reifyRole _ = ValidatorRole
instance ReifyRole ThreeArgumentScript where
reifyRole _ = ThreeArgumentScript

instance ReifyRole MintingPolicyRole where
reifyRole _ = MintingPolicyRole
instance ReifyRole TwoArgumentScript where
reifyRole _ = TwoArgumentScript

instance ReifyTypenames '[] where
reifyTypenames _ = []
Expand Down
4 changes: 2 additions & 2 deletions ply-core/src/Ply/Core/TypedReader.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Ply.Core.Deserialize (readEnvelope)
import Ply.Core.Internal.Reify
import Ply.Core.Types (
ScriptReaderException (ScriptRoleError, ScriptTypeError),
ScriptRole (ValidatorRole),
ScriptRole (ThreeArgumentScript),
TypedScript (TypedScriptConstr),
TypedScriptEnvelope (..),
)
Expand All @@ -34,7 +34,7 @@ mkTypedScript ::
TypedScriptEnvelope ->
Either ScriptReaderException (TypedScript rl params)
mkTypedScript (TypedScriptEnvelope ver rol params _ prog) = do
unless (rol == reifyRole (Proxy @rl)) . Left $ ScriptRoleError ValidatorRole rol
unless (rol == reifyRole (Proxy @rl)) . Left $ ScriptRoleError ThreeArgumentScript rol
let expectedParams = reifyTypenames $ Proxy @params
unless (expectedParams == params) . Left $ ScriptTypeError expectedParams params
pure $ TypedScriptConstr ver prog
Expand Down
2 changes: 1 addition & 1 deletion ply-core/src/Ply/Core/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ data TypedScript r a = TypedScriptConstr !ScriptVersion !UPLCProgram
deriving stock (Show)

-- | Script role: either a validator or a minting policy.
data ScriptRole = ValidatorRole | MintingPolicyRole
data ScriptRole = ThreeArgumentScript | TwoArgumentScript
deriving stock (Bounded, Enum, Eq, Ord, Show, Generic)
deriving anyclass (ToJSON, FromJSON)

Expand Down
Loading