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

Round trip plutus datum serialization/deserialization error #330

Closed
theeldermillenial opened this issue Mar 12, 2024 · 4 comments · May be fixed by #331
Closed

Round trip plutus datum serialization/deserialization error #330

theeldermillenial opened this issue Mar 12, 2024 · 4 comments · May be fixed by #331
Labels
bug Something isn't working

Comments

@theeldermillenial
Copy link
Contributor

theeldermillenial commented Mar 12, 2024

Describe the bug
When adding a script input to a transaction in the transaction builder, the datum is improperly serialized.

To Reproduce
I will create a small working example later today, but the basic steps are:

  1. Create a custom plutus data class
  2. Create a datum, print the datum hash
  3. Create a transaction with the transaction builder, add a script input
  4. Build the transaction and serialize to cbor
  5. Deserialize the transaction, generate the hash of the datum in the witness set

Additional context: Generating the hash of the datum before serialization is correct.

Expected behavior
Roundtrip serializing and deserializing of a transaction without mutations in the data.

Environment and software version (please complete the following information):

  • OS: Ubuntu
  • PyCardano Version 0.10.0 (also tried with latest on Github)
@theeldermillenial
Copy link
Contributor Author

theeldermillenial commented Mar 12, 2024

I was able to recreate just by adding another test to test_transactions.py

def test_datum_witness():
    @dataclass
    class TestDatum(PlutusData):
        CONSTR_ID = 0
        a: int
        b: bytes

    tx_body = make_transaction_body()
    signed_tx = Transaction(
        tx_body, TransactionWitnessSet(plutus_data=[TestDatum(1, b"test")])
    )
    restored_tx = Transaction.from_cbor(signed_tx.to_cbor())
    assert signed_tx.to_cbor_hex() == restored_tx.to_cbor_hex()

Edit: Compare cbor instead of using the utility function that compares objects. Maybe that doesn't matter.

@nielstron
Copy link
Contributor

Is there any fundamental difference between this and #311 ?

@theeldermillenial
Copy link
Contributor Author

Originally I wasn't sure, but now that I've looked into it I think they are the same. It all traces back to the decoder not properly distinguishing between definite/indefinite lists.

I think either of these could be closed, maybe copying over some of the info from one to the other.

In other news, I've been making progress on the cbor2 updates. Slowly but surely.

@cffls
Copy link
Collaborator

cffls commented Apr 17, 2024

Closing this issue due to duplication #311

@cffls cffls closed this as completed Apr 17, 2024
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 a pull request may close this issue.

3 participants