-
-
Notifications
You must be signed in to change notification settings - Fork 79
Closed
Description
Describe the bug:
script_data_hash encodes script data incorrectly:
- If datums present and redeemers empty, spec requires [0x80 | datums | 0xA0]; pycardano emits an empty map for the first field via CBOR-encoding RedeemerMap.
- In the general case, the third field must be the cost models’ language views encoding, not cbor2.dumps(cost_models).
Compare this, to this Rust solution
To reproduce (unit-level):
- pycardano 0.15.0 (also occurs on 0.14.0), Python 3.11, cbor2 5.7.0.
- Create any datum (e.g., PlutusData(42)); set datums=[datum], redeemers empty (RedeemerMap()).
- Call script_data_hash(redeemers, datums, cost_models=None).
- Observe: pycardano encodes the first field as an empty CBOR map; expected is 0x80 (empty list). Also, for non-empty redeemers, the third field should be language views encoding, not cbor2.dumps(cost_models).
End-to-end repro (real tx):
- Build unsigned tx (e.g., Lucid Evo) that includes datums but no redeemers.
- Sign body and attach a vkey witness with pycardano (don’t alter body).
- Submit to a node.
- Ledger rejects with PPViewHashesDontMatch (Conway), indicating the script data hash in the body doesn’t match the node’s view due to the encoding issues above.
Logs:
{"txId": "55c701f...2372def", "status": 400, "submitResponse": "{\"contents\":{\"contents\":{\"contents\":{\"era\":\"ShelleyBasedEraConway\",\"error\":[\"ConwayUtxowFailure (PPViewHashesDontMatch (SJust (SafeHash \\\"105d23ade722bf809631a5b0f92176640f32e669ae1fda21c98dc0eaec8eb4a7\\\")) (SJust (SafeHash \\\"ed760ad389dc18f4a5058b8b208a27bdcbfccb99d32d6897e61e0b82908ea1b9\\\")))\"],\"kind\":\"ShelleyTxValidationError\"},\"tag\":\"TxValidationErrorInCardanoMode\"},\"tag\":\"TxCmdTxSubmitValidationError\"},\"tag\":\"TxSubmitFail\"}", "witnessKeyHash": "<unknown>"}
Expected behavior:
When datums present and redeemers empty: encode [0x80 | datums | 0xA0].
Otherwise: third field = cost_models.language_views_encoding().
Environment and software version:
- Windows 11
- Python 3.11
- PyCardano 0.15.0
- cbor2 5.7.0
- Tx CBOR sourced from Lucid Evo (Conway mainnet)
Metadata
Metadata
Assignees
Labels
No labels