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

Add integerToByteString and byteStringToInteger to PlutusV2 at PV10 #6056

Merged
merged 1 commit into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

### Added

- Primitives `integerToByteString` and `byteStringToInteger` are added to PlutusV2,
enabled at protocol version 10.
18 changes: 17 additions & 1 deletion plutus-ledger-api/src/PlutusLedgerApi/Common/ProtocolVersions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module PlutusLedgerApi.Common.ProtocolVersions
, vasilPV
, valentinePV
, conwayPV
, conwayPlus1PV
, knownPVs
, futurePV
) where
Expand Down Expand Up @@ -68,10 +69,25 @@ valentinePV = MajorProtocolVersion 8
conwayPV :: MajorProtocolVersion
conwayPV = MajorProtocolVersion 9

-- | The next HF after Conway. It doesn't yet have a name, and it's not
-- yet known whether it will be an intra-era HF or introduce a new era.
conwayPlus1PV :: MajorProtocolVersion
conwayPlus1PV = MajorProtocolVersion 10

-- | The set of protocol versions that are "known", i.e. that have been released
-- and have actual differences associated with them.
knownPVs :: Set.Set MajorProtocolVersion
knownPVs = Set.fromList [ shelleyPV, allegraPV, maryPV, alonzoPV, vasilPV, valentinePV, conwayPV ]
knownPVs =
Set.fromList
[ shelleyPV
, allegraPV
, maryPV
, alonzoPV
, vasilPV
, valentinePV
, conwayPV
, conwayPlus1PV
]

-- | This is a placeholder for when we don't yet know what protocol version will
-- be used for something. It's a very high protocol version that should never
Expand Down
12 changes: 7 additions & 5 deletions plutus-ledger-api/src/PlutusLedgerApi/Common/Versions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ instance Pretty PlutusLedgerLanguage where
pretty = viaShow

{-| A map indicating which builtin functions were introduced in which 'MajorProtocolVersion'.
Each builtin function should appear at most once.

This __must__ be updated when new builtins are added.
See Note [New builtins/language versions and protocol versions]
Expand All @@ -107,6 +106,9 @@ builtinsIntroducedIn = Map.fromList [
((PlutusV2, valentinePV), Set.fromList [
VerifyEcdsaSecp256k1Signature, VerifySchnorrSecp256k1Signature
]),
((PlutusV2, conwayPlus1PV), Set.fromList [
IntegerToByteString, ByteStringToInteger
]),
((PlutusV3, conwayPV), Set.fromList [
Bls12_381_G1_add, Bls12_381_G1_neg, Bls12_381_G1_scalarMul,
Bls12_381_G1_equal, Bls12_381_G1_hashToGroup,
Expand Down Expand Up @@ -173,10 +175,10 @@ and 'MajorProtocolVersion'?
See Note [New builtins/language versions and protocol versions]
-}
builtinsAvailableIn :: PlutusLedgerLanguage -> MajorProtocolVersion -> Set.Set DefaultFun
builtinsAvailableIn thisLv thisPv = fold $ Map.elems $
Map.takeWhileAntitone builtinAvailableIn builtinsIntroducedIn
builtinsAvailableIn thisLv thisPv = fold $
Map.filterWithKey (const . alreadyIntroduced) builtinsIntroducedIn
where
builtinAvailableIn :: (PlutusLedgerLanguage, MajorProtocolVersion) -> Bool
builtinAvailableIn (introducedInLv,introducedInPv) =
alreadyIntroduced :: (PlutusLedgerLanguage, MajorProtocolVersion) -> Bool
alreadyIntroduced (introducedInLv,introducedInPv) =
Comment on lines +179 to +182
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for doing that.

@kwxm you were going to take a look at it, did you manage to do it in the end?

Copy link
Contributor

Choose a reason for hiding this comment

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

@kwxm you were going to take a look at it, did you manage to do it in the end?

A look at what?

Copy link
Contributor

Choose a reason for hiding this comment

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

At the idea of replacing takeWhileAntitone with filterWithKey here.

Copy link
Contributor

Choose a reason for hiding this comment

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

I can see how the highlighted diff and my comment were really confusing. Sorry!

Copy link
Contributor

Choose a reason for hiding this comment

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

At the idea of replacing takeWhileAntitone with filterWithKey here.

I have no memory of that at all!

Copy link
Contributor

Choose a reason for hiding this comment

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

See this thread.

Copy link
Contributor

Choose a reason for hiding this comment

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

TBH, this whole Versions module needs some rework.

-- both should be satisfied
introducedInLv <= thisLv && introducedInPv <= thisPv