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

Fix reference scripts fetched from ogmios #254

Merged
merged 4 commits into from
Sep 3, 2023

Conversation

nielstron
Copy link
Contributor

@nielstron nielstron commented Jun 8, 2023

Same fix as for kupo (#253) for #252

@KtorZ maybe you can chime in on what exactly the format of scripts in utxos is in kupo/ogmios? Its mentioned to be "raw script" from which I would actually understand 0 cbor wrapping but it appears to be exactly once?

@nielstron
Copy link
Contributor Author

This fixed the issue I had in #252 in the tool I was using

@codecov-commenter
Copy link

codecov-commenter commented Jun 8, 2023

Codecov Report

Merging #254 (a8d1b0d) into main (0d5b3d7) will decrease coverage by 0.01%.
The diff coverage is 0.00%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the GitHub App Integration for your organization. Read more.

@@            Coverage Diff             @@
##             main     #254      +/-   ##
==========================================
- Coverage   85.14%   85.14%   -0.01%     
==========================================
  Files          26       26              
  Lines        2996     2995       -1     
  Branches      719      719              
==========================================
- Hits         2551     2550       -1     
  Misses        335      335              
  Partials      110      110              
Files Changed Coverage Δ
pycardano/backend/ogmios.py 59.69% <0.00%> (-0.16%) ⬇️

@KtorZ
Copy link
Contributor

KtorZ commented Jun 8, 2023

The scripts are provided in the format that correspond to the preimage of the various hashes calculated from scripts. For some unknown reasons, few interfaces like the cardano-cli have opted for encoding an already cbor-encoded binary object as cbor, resulting in this double-cbor-wrapping (dare I say it?) non-sense (albeit I have no doubt it wasn't intentional).

Using only the "raw" flat-encoded binary form of the script is unsatisfactory IMO because it still requires being cbor-encoded before hashing to obtain a valid preimage. So the most meaningful form is the cbor-flat-encoded script. Now, why do we have 2 different binary encoding format, and one of them sometimes applied twice is a discussion for another day.

@nielstron
Copy link
Contributor Author

Thanks for this insight. So

  • if the binary is always singly-cbor wrapped i would like to ask for this being clarified in the kupo/ogmios docs
  • if not, does this mean the preimage for the hash can be either singly or doubly wrapped? as discussed in Fix kupo plutusv2 script from kupo #253 (comment)

@@ -467,9 +467,9 @@ def _utxo_from_ogmios_result(self, result) -> UTxO:
script = output.get("script", None)
if script:
if "plutus:v2" in script:
script = PlutusV2Script(cbor2.loads(bytes.fromhex(script["plutus:v2"])))
script = PlutusV2Script(bytes.fromhex(script["plutus:v2"]))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was suggested by @cffls to use _try_fix_script here. However, ogmios does not return the script hash required to call the fixing method, so we can not know what the desired hash looks like.

@cffls cffls added the bug Something isn't working label Jun 20, 2023
@nielstron
Copy link
Contributor Author

@cffls bump, this needs a decision and IMO should be merged as is

@nielstron
Copy link
Contributor Author

nielstron commented Jun 29, 2023

Maybe we should add a test case for it? Ogmios is run in the test environment afaik

@cffls
Copy link
Collaborator

cffls commented Jul 17, 2023

Maybe we should add a test case for it? Ogmios is run in the test environment afaik

Yes, we should add a test case for it before merging. I will try add one and see if it works.

@cffls cffls merged commit 0a95536 into Python-Cardano:main Sep 3, 2023
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants