Repository navigation
Keep the on-chain bytes of Babbage and Conway witness datums - #27
Merged
Merged
Conversation
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.
Jimbo4350
approved these changes
Nov 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 as9f 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, andcoerce, which only changes the era label ofBinaryData. 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 02as 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 stored9f 01 02 ff. The unit suite passes with 454 examples.This was split out of the upstream sync PR, which keeps upstream's
upgradeDataconverters until this lands: