-
Notifications
You must be signed in to change notification settings - Fork 483
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
Introduce hashScriptWithPrefix which produces the ScriptHash corresponding to a SerialisedScript #6527
base: master
Are you sure you want to change the base?
Conversation
…hash from a serialised script
@zliu41 Who should I request for review? |
PlutusV2 -> 0x2 | ||
PlutusV3 -> 0x3 | ||
-} | ||
hashScriptWithPrefix :: Word8 -> SerialisedScript -> BS.ByteString |
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.
hashScriptWithPrefix :: Word8 -> SerialisedScript -> BS.ByteString | |
hashScriptWithPrefix :: PlutusLedgerLanguage -> SerialisedScript -> BS.ByteString |
This way one can't pass invalid prefix?
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.
How about:
-- | Hash a 'SerialisedScript' with the Plutus language version 1 prefix.
hashScriptV1 :: SerialisedScript -> BS.ByteString
hashScriptV1 = hashScriptWithPrefix 0x1
-- | Hash a 'SerialisedScript' with the Plutus language version 2 prefix.
hashScriptV2 :: SerialisedScript -> BS.ByteString
hashScriptV2 = hashScriptWithPrefix 0x2
-- | Hash a 'SerialisedScript' with the Plutus language version 3 prefix.
hashScriptV3 :: SerialisedScript -> BS.ByteString
hashScriptV3 = hashScriptWithPrefix 0x3
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 approach also makes invalid prefixes un-representable. I wouldn't stop here though:
PlutusLedgerApi.Common.hashScriptV1
move to PlutusLedgerApi.V1.hashScript
PlutusLedgerApi.Common.hashScriptV2
move to PlutusLedgerApi.V2.hashScript
PlutusLedgerApi.Common.hashScriptV3
move to PlutusLedgerApi.V3.hashScript
wdyt?
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.
Also replace this with the new functions.
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 approach also makes invalid prefixes un-representable. I wouldn't stop here though:
PlutusLedgerApi.Common.hashScriptV1
move toPlutusLedgerApi.V1.hashScript
PlutusLedgerApi.Common.hashScriptV2
move toPlutusLedgerApi.V2.hashScript
PlutusLedgerApi.Common.hashScriptV3
move toPlutusLedgerApi.V3.hashScript
wdyt?
Yes and we probably don't need hashScriptWithPrefix
at all, you can just copy-paste the body of that definition within each V*
file. I'm just nitpicking though, feel free to ignore.
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.
Also replace this with the new functions.
This introduces a cyclic dependency between plutus-tx
and plutus-ledger-api
.
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.
Personally I'd do what @effectfully suggests: inline the hasScriptWithPrefix
into V1/V2/V3 hashScript
s.
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.
The reason I want to keep it is because hashScriptWithPrefix
as an export is useful to me in creating and testing new language versions that I use in Midgard (optimistic rollup building on Cardano), and it will also be useful for the Hydra team for the same reason.
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 introduces a cyclic dependency between plutus-tx and plutus-ledger-api.
Right, so this should really exist in a plutus-script-utils
package, which users should depend on, rather than plutus-ledger-api
which is intended to be stuff the ledger needs. This is the reason why a number of functions similar to this one was removed from plutus-ledger-api
in the first place. This nonetheless can be future work.
plutus-ledger-api/src/PlutusLedgerApi/Common/SerialisedScript.hs
Outdated
Show resolved
Hide resolved
Co-authored-by: Yura Lazarev <[email protected]>
PlutusV2 -> 0x2 | ||
PlutusV3 -> 0x3 | ||
-} | ||
hashScriptWithPrefix :: Word8 -> SerialisedScript -> BS.ByteString |
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.
Also replace this with the new functions.
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.
Thank you!
PlutusV2 -> 0x2 | ||
PlutusV3 -> 0x3 | ||
-} | ||
hashScriptWithPrefix :: Word8 -> SerialisedScript -> BS.ByteString |
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 approach also makes invalid prefixes un-representable. I wouldn't stop here though:
PlutusLedgerApi.Common.hashScriptV1
move toPlutusLedgerApi.V1.hashScript
PlutusLedgerApi.Common.hashScriptV2
move toPlutusLedgerApi.V2.hashScript
PlutusLedgerApi.Common.hashScriptV3
move toPlutusLedgerApi.V3.hashScript
wdyt?
Yes and we probably don't need hashScriptWithPrefix
at all, you can just copy-paste the body of that definition within each V*
file. I'm just nitpicking though, feel free to ignore.
plutus-ledger-api/src/PlutusLedgerApi/Common/SerialisedScript.hs
Outdated
Show resolved
Hide resolved
@@ -0,0 +1 @@ | |||
590a19010000332323232322232323223223232533533300a3333573466e1cd55cea804240004646464246660020080060046eb4d5d09aba25009375a6ae854020dd69aba1500823263533573802001e01c01a6666ae68cdc3a80224004424400446666ae68cdc3a802a40004244002464c6a66ae7004404003c038034cccd5cd19b8735573aa004900011991091980080180119191919191919191919191999ab9a3370e6aae754029200023333333333222222222212333333333300100b00a00900800700600500400300235742a01466a03040026ae854024d5d0a8041aba1500735742a00c6ae854014d5d0a80219a80c3ae35742a0066ae854008d5d09aba2500223263533573803803603403226ae8940044d5d1280089aba25001135744a00226ae8940044d5d1280089aba25001135744a00226aae7940044dd50009aba150023232323333573466e1d400520062321222230040053232323232323333573466e1d4005200c21222222200323333573466e1d4009200a21222222200423333573466e1d400d2008233221222222233001009008375c6ae854014dd69aba135744a00a46666ae68cdc3a8022400c4664424444444660040120106eb8d5d0a8039bae357426ae89401c8cccd5cd19b875005480108cc8848888888cc018024020c070d5d0a8049bae357426ae8940248cccd5cd19b875006480088c848888888c01c020c074d5d09aab9e500b23333573466e1d401d2000232122222223005008301e357426aae7940308c98d4cd5ce01081000f80f00e80e00d80d00c80c09aab9d5004135573ca00626aae7940084d55cf280089baa001357426aae79400c8cccd5cd19b875002480108c848888c008014c048d5d09aab9e500423333573466e1d400d20022321222230010053232323333573466e1cd55cea8012400046644246600200600464646666ae68cdc39aab9d5001480008dd71aba135573ca004464c6a66ae7007407006c0684dd50009aba15002375a6ae84d5d1280111931a99ab9c01a019018017135573ca00226ea8004d5d09aab9e500523333573466e1d40112000232122223003005375c6ae84d55cf280311931a99ab9c017016015014013012011135573aa00226ea8004d5d09aba2500223263533573802001e01c01a201c264c6a66ae71241035054350000e00d135573ca00226ea80044d55ce9baa001135744a00226aae7940044dd50008919118011bac00132001323001001223233335573e00442440044664424466002008006600a6ae8400cc008d5d100180398010011191919191999ab9a3370ea002900111999110911998008028020019bad35742a0086eb4d5d0a8019bad357426ae89400c8cccd5cd19b875002480008c8488c00800cc8c8c8cccd5cd19b875001480088c8488c00400cdd71aba135573ca00646666ae68cdc3a8012400046424460040066eb8d5d09aab9e500423263533573801e01c01a01801626aae7540044dd50009aba135573ca00c464c6a66ae7002802402001c0184d55cea80189aba25001135573ca00226ea8005261200149010350543100332332233223232323232323232323222232322300235323232323253353333333574800a46666ae68cdc39aab9d5005480008cccd55cfa8029280d91999aab9f50052501c233335573ea00a4a03a46666aae7cd5d128031299a991919191999999aba400423333573466e1cd55cea8022400046666aae7d4010940948cccd55cfa8021281311999aab9f35744a00a4a66a603e6ae85401c854cd4cd407c8c8c8c8c8c8ccccccd5d200311999ab9a3370ea004900111999aab9f500625031233335573ea00c4a06446666aae7d4018940cc8cccd55cf9aba2500725335302a35742a01442a66a60566ae854028854cd4c0b0d5d0a805109a81c0911998008028020018a81b0a81a8a81a1281a01801781701691999ab9a3370ea006900011999aab9f500725032233335573e6ae89402094cd4c0acd5d0a804909a81a89118010018a81992819817817128188160159281792817928179281781589aab9d5004135744a00226ae8940044d55cf280089baa00135742a00e426a05424660020060042a0502a04e4a04e0460440424a04803e4a0464a0464a0464a04603e26ae8940044d55cf280089baa00135742a01242a66a666aa02603066aa02603002a6ae854024854cd4cd405c064d5d0a804909a811091998008020018010a8100a80f8a80f1280f00d00c80c00b9280d00a9280c9280c9280c9280c80a9080089ab1309aba25001135744a00226aae7940044dd500099a9806890009a800911a8011111111111004a4004444004640026aa02644a66a00220224426a00444a66a666ae68cdc780100380b00a880b098030019a80191111111a8039100108911911999999aba4001550052533530033756004426a0260022a022aa00aaa00aaa00a01a640026aa02044646666aae7c0088d404c48800894cd4c018d55cea80110a99a98031aab9e500321533530063574400a426a02c24466002246600200c00a0062a0282a0262a02401c26ae8400444940308ccccccd5d200092806128061280611a8069bad0022500c0081223232323333333574800846666ae68cdc3a8012400046666aae7d4010940448cccd55cf9aba2500525335300935742a00c426a0286a0280022a0244a02401c01a46666ae68cdc3a801a400446666aae7d40148d404d4048940480389404403002c9403c9403c9403c9403c02c4d55cea80109aab9e50011375400246464646666666ae900108cccd5cd19b875002480088cccd55cfa8021280791999aab9f35744a00a4a66a60126ae85401884d4048488c00400c540409404003002c8cccd5cd19b875003480008cccd55cfa8029280811999aab9f35744a00c4a66a60146ae85401c84d404c488c00800c54044940440340309403c028024940349403494034940340244d55cea80109aab9e50011375400246666666ae90004940249402494024940248d4028dd7001002990009aa80411091299a999ab9a33710002900000480409a802a481035054360015335002135005490103505437002215335333573466e1c00d200000b00a10021335300612001001337020069001091931a99ab9c0010030024984800448800848800448488c00800c4488004448c8c00400488cc00cc008008004cd4488ccd44888cd4488cd4488ccccccc008cd540112211c4d07e0ceae00e6c53598cea00a53c54a94c6b6aa071482244cc0adb50048810f567946695f43726564656e7469616c0033550044891c96c31772282e6ae5c629120471c5bbcdef538226b31b97d74c50ca3c00488100488110567946695f4144412f534e454b5f4c500033300948303df9c052014480a0cd540112210048810033550044891c279c909f348e533da5808898f87f9a14bb2c3dfbbacccd631d927a3f00488104534e454b00350074891ce023d4ef74967fc841a5e77fe82e41a1b20f0c94de4e2d9d33a2aabe0022222221233333330010080070060050040030022001112212330010030021120011212230020031122001120012221233300100400300220011 |
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.
its unfortunate that we have to include an opaque test fixture: I'd rather prefer to include sources of the scripts and compile them with plugin together with tests. However, tests for the plutus-ledger-api
dont use plugin, so, maybe, you can consider placing tests in the:
-- A suite for tests that use the Plutus Tx plugin. We don't merge those into
-- @plutus-ledger-api-test@, because @plutus-ledger-api@ has to be buildable for older versions of
-- GHC (a requirement imposed by @cardano-node@) and while its tests don't have to, we don't want to
-- give up on all @plutus-ledger-api@ tests for older versions of GHC.
test-suite plutus-ledger-api-plugin-test
?
The old versions of
PlutusLedgerApi
exposed the functionscriptHash
which could be used to produce theScriptHash
associated with a givenSerialisedScript
. The fact that the newPlutusLedgerApi
does not expose such a function means these projects are forced to implement their own variant of the function (which often involves introducing crypto/hashing library dependencies) or introduce additional heavy dependencies such asCardanoApi
. This PR introduces the functionhashScriptWithPrefix
toPlutusLedgerApi.Common
so that downstream applications can avoid redundant work.Pre-submit checklist: