Emurgo / cardano-serialization-lib

This is a library, written in Rust, for serialization & deserialization of data structures used in Cardano's Haskell implementation of Alonzo along with useful utility functions.
Other
231 stars 125 forks source link

Transaction deserialization simplifies outputs to `legacy_transaction_output` when possible #609

Closed sourabhxyz closed 1 year ago

sourabhxyz commented 1 year ago

All the outputs in my transaction had outputs in post_alonzo_transaction_output format but after deserialization, outputs which could be simplified to legacy_transaction_output format, got simplified into it. Is this intentional? I can see it happening at wallet level (when wallet performs deserialization in signTx method) and this changing of transaction cbor is leading to inconsistency with what transaction hash we expect and what actually turns out to be.

lisicky commented 1 year ago

Hi @sourabhxyz ! CSL serializes an output to legacy_transaction_output format if the output doesn't have inlined datum and inlined script, because of takes less bytes in CBOR. If the output contains inlined datum or inlined script the output will be serialized to post_alonzo_transaction_output format. For case when you need to deserialized and serialized a tx to add a signature you can use the FixedTransaction type https://github.com/Emurgo/cardano-serialization-lib/releases/tag/11.3.0 . It keeps tx body bytes unchanged until you change it. You can see an example here https://github.com/Emurgo/cardano-serialization-lib/issues/604

sourabhxyz commented 1 year ago

Thanks @lisicky! Really appreciate it. This will work if we have access to private key but here we are bind to use signTx method provided by a compatible CIP-30 wallet. If I understand you correctly, we would need these wallets to get updated to use FixedTransaction type internally when signing?

sourabhxyz commented 1 year ago

@lisicky It is not an issue an with Nami & Eternl but is an issue with Lace. Thanks!