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

Reference script to_bytes() includes tag 24 cbor wrapper #669

Closed
Scitz0 opened this issue Apr 3, 2024 · 10 comments
Closed

Reference script to_bytes() includes tag 24 cbor wrapper #669

Scitz0 opened this issue Apr 3, 2024 · 10 comments
Milestone

Comments

@Scitz0
Copy link

Scitz0 commented Apr 3, 2024

When creating the json request to pass along to Ledger and Trezor hardware wallets we use CSL to deserialize the transaction cbor. For reference scripts in outputs, we noticed that when calling output.script_ref().to_bytes() it included the tag 24 cbor wrapper (not sure of proper nomenclature), ie d8 18 (tag(24)) + 59 04db (bytes(1243)) as in below example cbor. I didn't find a way to access the actual bytes of the value (82025904d...) for the reference script using CSL.

In comparison with inline datum in same example, defined as [ 0, $hash32 // 1, data ] where data = #6.24(bytes .cbor plutus_data) in CDDL.

82 01 d8 18 43 d87980 
=> 
82     = array
01     = inline datum
d8 18  = tag(24)
43     = bytes(3)
d87980 = actual value

When we access the inline datum using output.plutus_data().to_bytes() we only get the actual value d87980, not the additional tag(24) and byte count.

Privously I have noticed that there was two functions available, to_bytes() and as_bytes() with the latter returning wrapping code and former didn't (could be misremembering). For reference script, I can only see the to_bytes() function while for inline datum both are present. Could the same behavior be replicated for reference script as for inline datum?

Example cbor:

84a40081825820e26168fc2295e1ff6437cb6099dd9c009aee8fb9440536dda839e44572e1093a050182a400581d7151936f3c98a04b6609aa9b5c832ba1182cf43a58e534fcc05db09d69011a005fd1f6028201d81843d8798003d8185904db82025904d65904d3010000332323232323232323232323232323232222323232533300f3370e90000010991919192999809991919800925114a06601e4a66602a66ebc030c064c06c004488c00800c4894004004dd6180b8020a999809999119baf374c0046e98004cc0352401104753542073796d626f6c20656e7472790033233011232223002003375660380026ea4004dd7180b8029bab30170023322332233574066ec00080052f5bded8c06ea4008dd4000a45004800854ccc04cc8c94cc034c8c8c8c94cc044cdc4a40006eb4c07401054cc044cdc4a40006eb4c07400c54cc044cdc4a40006eb4c07400854cc044cdc4a40006eb4c0740044cdc4a40006eb4c074c078004c074004c070004c06c004dd6180c8010a99806991919191929980919b8948000dd6980f0028a9980919b8948000dd6980f0020a9980919b8948000dd6980f0018a9980919b8948000dd6980f0010a9980919b8948000dd6980f0008a9980919b8948000dd6980f180f8008a51301e001301d001301c001301b0013758603200226466e212000001375a60326034002603260320026601a9211e476f7665726e6f72206f75747075742073686f756c642070726573656e74003300e23253330153370e664466664466660284a66603466ebc00cc074004488c00800c48940040048c888c00800cc0840044894004dd4801000919991180c11299980d80088018998021810000980118108009119b80375a604200400290001bab001148000dd7180c8039bab3019001480084c044dd61991191980090008b199119800919111801001980180089128009191919191919191919191919191919191919191919191919191919299981999b89480000044c8c8c94ccc0d8cdc4a40000022646464a66607266e2520000011323232533303c3371290000008991919299981f99b89480000044c8c8c94ccc108cdc4a400000226464646464a66608e66e25200000113232323232035533304a001149858c13c00cdd6800982600098260018b1bad001304900130490165333042001149858c11c00c58dd6800982200098220018b1bad0013041001304100316375a002607c002607c0062c6eb4004c0ec004c0ec00c58dd6800981c000981c0018b1bad00130350013758002606600260660066eb4004c0c0004c0c004d4ccc0a400452616302e003375a002605600260560066eb4004c0a0004c0a000cdd6800981280098128019bad00130220013022003375a002603e0026eb0004c074004dd6000991919299980d19b8748000008406c54ccc068cdc3a40080042602c603c00226646603046444600400660460026ea4004dd7180f0008021810001180d8009baa0023019301a00137566032602e6034006202c603260340026eb0c05c00c5261616163014301700130163016001301530150013015301330150041630150023010001375460206022602400244666014004002006294088cc0048004588c010894ccc01c00448940044ccc00cc030004888c00800c4c008c034004888c00800c888cc010894ccc01c004489400454ccc020cdd798059806000802098029806000898011806800800919180111980100100091801119801001000aab9f573444a002460086008002aae755d0aba2230023754002aae793012bd8799fd8799f582004c99b5b1985e29d88b8f97802e08dc47743c2db8ba72d72d46122ea388aec80ff00ff000182583901491dea0aafeadf1527ae681d9e842b6d05fc2fb9405027042cc3ebc3aed05c32244fa25d10c7e3c90da58e8e528e8f198128f5eb3747d7d91a002a50d7021a000375e90f01a204800580f5f6

Using CSL 12 alpha 22

@lisicky
Copy link
Contributor

lisicky commented Apr 3, 2024

Hi @Scitz0 ! If I understand you correctly you need to have original plutus script bytes of inlined script, right ?
To do it you can call output.script_ref().plutus_script() , if it is a plutus script

@Scitz0
Copy link
Author

Scitz0 commented Apr 3, 2024

@lisicky incorrect :)

We need to pass along bytes (in hex) including the "type" plutus vs native that I assume the first two bytes represent.
If I decode above cbor through https://cbor.nemo157.com/ and look at reference script section it looks like this:
Screenshot_20240403_161122
If I call output.script_ref().plutus_script().to_bytes() I'm missing the first two bytes 8202 that I assume describe that its a plutus script and not a native script. But if I call output.script_ref().to_bytes() I get too much, ie like I described also the tag(24) and byte count.

@lisicky
Copy link
Contributor

lisicky commented Apr 3, 2024

Okay here script_ref CDDL and you need just CBOR of script part of it ?

@Scitz0
Copy link
Author

Scitz0 commented Apr 3, 2024

Correct, so bytes of entire script thing. This is what Ledger and Trezor expect that we pass along in the request.

@lisicky
Copy link
Contributor

lisicky commented Apr 3, 2024

@Scitz0 if it is not urgent I guess we can add it in next two weeks

@lisicky
Copy link
Contributor

lisicky commented Apr 3, 2024

You can also decode cbor via https://cardananium.github.io/cquisitor/ , it is more user friendly in some cases

@Scitz0
Copy link
Author

Scitz0 commented Apr 3, 2024

Its not urgent no, just good to have option to get bytes this way in a future version. For now we solved it by utilizing another cbor lib to extract the bytes.

@lisicky
Copy link
Contributor

lisicky commented Jun 25, 2024

Sorry @Scitz0 for delay. ScriptRef now has to_unwrapped_bytes function, in the latest 12.0.0 beta release. Could you check it ?

@Scitz0
Copy link
Author

Scitz0 commented Jun 25, 2024

Ok great, I will leave on a two week vacation shortly so bad timing. Though I'm sure its working properly.

@lisicky lisicky added this to the 12.0.0 milestone Aug 28, 2024
@lisicky
Copy link
Contributor

lisicky commented Aug 28, 2024

Implemented in the CSL 12.0.0

@lisicky lisicky closed this as completed Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants