Skip to content

Keep the on-chain bytes of Babbage and Conway witness datums - #27

Merged
carbolymer merged 1 commit into
masterfrom
mgalazyn/feature/witness-datum-bytes
Nov 26, 2026
Merged

carbolymer merged 1 commit into
masterfrom
mgalazyn/feature/witness-datum-bytes

Conversation

@carbolymer

Copy link
Copy Markdown

Kupo converted the witness-set datums and spend redeemers of Babbage and Conway transactions to its Dijkstra-era type with upgradeData, which rebuilds the value and re-encodes it in Plutus's own encoding. When the on-chain bytes used a different encoding, for example a list with a definite length (82 01 02, which Plutus writes as 9f 01 02 ff), Kupo stored the datum under its on-chain hash but with re-encoded bytes that do not hash to it. A client that takes these bytes from /datums/{hash} to supply the datum when spending the output builds a transaction that the ledger rejects.

The converters now use dataToBinaryData, which keeps the bytes the ledger decoded, and coerce, which only changes the era label of BinaryData. The ledger does the same for inline datums when it upgrades outputs at a hard fork (translateDatum). Alonzo moves to the same form: it already kept its bytes, but decoded them again on the way. Nothing is decoded or re-encoded any more.

Babbage datums have been affected since the Conway era was added upstream, and Conway datums only since the Dijkstra dependency bump on master, which no release contains. Databases built by earlier versions keep the re-encoded bytes, and the changelog says so.

A regression test decodes 82 01 02 as a datum of each era from Alonzo to Dijkstra and checks the stored bytes, the hash and the bytes written to the database. Before the fix, the Babbage and Conway cases stored 9f 01 02 ff. The unit suite passes with 454 examples.

This was split out of the upstream sync PR, which keeps upstream's upgradeData converters until this lands:

Converting a Babbage or Conway witness datum went through upgradeData, which rebuilds the datum from the Plutus data and so re-encodes it. A datum that was not in Plutus's own encoding, such as a list with a definite length, was stored under its on-chain hash but with re-encoded bytes, which do not hash to that value. Spend redeemers were re-encoded in the same way. Alonzo, Babbage and Conway datums now go through dataToBinaryData, which keeps the bytes the ledger decoded, and coerce, which only changes the era label, as the ledger does for inline datums when it upgrades outputs. Nothing is decoded or re-encoded on the way.
@carbolymer
carbolymer marked this pull request as ready for review November 24, 2026 15:59
@carbolymer carbolymer self-assigned this Nov 24, 2026
@carbolymer
carbolymer merged commit 82b5d58 into master Nov 26, 2026
6 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants