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
230 stars 124 forks source link

Inconsistency between Transaction from_bytes() and to_bytes() #630

Closed evanzbitgo closed 1 year ago

evanzbitgo commented 1 year ago

Hi I am troubleshooting some inconsistent behaviors for CardanoWasm.Transaction.

import * as CardanoWasm from '@emurgo/cardano-serialization-lib-nodejs';

const txn = CardanoWasm.Transaction.from_bytes(Buffer.from(<rawTx1>, 'hex'));
const rawTx2 = Buffer.from(txn.to_bytes()).toString('hex');

<rawTx1> suppose to be equal to <rawTx2>. However it is not unfortunately. Anyone could help to understand why?

@emurgo/cardano-serialization-lib-nodejs version is 11.4.0 I used the latest cardano-cli to generate a test which is as following:

84a5008282582078e05b7941011b5275552d0e5074056273125e18aac81643bfc3de59abac0e8600825820ce6d283af95b4da0e4b86f20ddf25dfb0343a7402e35877307c1465bd7beeafa000181a2005839006d57dea46753025b2c4e0fd9244df6a08fdd059dd1432af5eb7abbec6d57dea46753025b2c4e0fd9244df6a08fdd059dd1432af5eb7abbec011a59682f00021a000f42400319ea6004828a03581c10324dc34187735de46f6260d94620cdcc819f7ed1f93e3fc58d06a058201cc18daee56cb67a5dfb860194cd1e878be38401f3990efd92e16c5f8f4d959c1a05f5e1001a1dcd6500d81e820314581de0a9fd4c265da033970e0b22b06422e12b3479e8dbd35abc82d405a16181581ca9fd4c265da033970e0b22b06422e12b3479e8dbd35abc82d405a161818301191770782572656c6179732d6e65772e63617264616e6f2d746573746e65742e696f686b6465762e696f827368747470733a2f2f72622e67792f697a747a71582010c343fe0f6c01291df08de0ddc8fcbc07bccb503c51ffc051785e783b8d2f4483028200581ca9fd4c265da033970e0b22b06422e12b3479e8dbd35abc82d405a161581c10324dc34187735de46f6260d94620cdcc819f7ed1f93e3fc58d06a0a0f5f6

klntsky commented 1 year ago

That's because there are multiple way to serialize a tx and cardano-cli does not follow the same conventions as CSL.

See https://github.com/Emurgo/cardano-serialization-lib/issues/550

lisicky commented 1 year ago

There are plenty ways how the same data can be serialized into CBOR and most of CSL types does not guarantee that deserialization/serialization round trip will have the same CBOR representation as original bytes. But for transaction we have a FixedTransaction type that preserves original bytes of a transaction. See release notes of 11.3.0 and https://github.com/Emurgo/cardano-serialization-lib/issues/604