Skip to content

script_data_hash mis-encodes script data (empty redeemers + datums; cost models language views) → PPViewHashesDontMatch #455

@BrockCruess

Description

@BrockCruess

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):

  1. pycardano 0.15.0 (also occurs on 0.14.0), Python 3.11, cbor2 5.7.0.
  2. Create any datum (e.g., PlutusData(42)); set datums=[datum], redeemers empty (RedeemerMap()).
  3. Call script_data_hash(redeemers, datums, cost_models=None).
  4. 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):

  1. Build unsigned tx (e.g., Lucid Evo) that includes datums but no redeemers.
  2. Sign body and attach a vkey witness with pycardano (don’t alter body).
  3. Submit to a node.
  4. 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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions