You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Plutus data has no encoder of its own. Data.toCBORBytes turns a Data value into a generic CBOR tree and hands it to the CBOR encoder, which applies one set of options to the whole tree. Some Plutus data rules do not fit that model, so they are missing or live in CBOR.ts:
Rule (plutus PlutusCore/Data.hsencodeData)
SDK today
Tag 102 writes its [index, fields] pair as a definite 2-element array; only the fields follow the list encoding
done by CBOR.BoundedBytes, a Plutus-specific node in the generic CBOR type
The node splits this the same way: the ledger delegates Plutus data to the Plutus encoder (cardano-ledger Plutus/Data.hs L86-87, encCBOR (PlutusData d) = fromPlainEncoding $ Cborg.encode d).
Proposal
Give Data its own encoder that walks a Data value straight to bytes:
Constructor, list, map, integer and byte-string rules as in encodeData, including the four rows above.
Lists, maps and constructor fields follow the codec options, so PLUTUS_DATA_OPTIONS, CML_DATA_DEFAULT_OPTIONS, CML_DATA_DEFINITE_OPTIONS and CANONICAL_OPTIONS keep their meaning.
Data.toCBORBytes, Data.toCBORHex, Data.toDatumHash and the Data encode schemas use it. The transaction encoders already join datum and redeemer bytes from Data.toCBORBytes (feat(cbor): write witness datums and redeemer data with TxCodecOptions #610), inline datums do too (DatumOption.ts), so they pick it up without changes.
After the switch, deprecate CBOR.BoundedBytes, so CBOR holds no Plutus data rules.
Order
Add the encoder next to the current path and prove it byte-identical to today's output for every data preset on random data, except the cases in the table.
Summary
Plutus data has no encoder of its own.
Data.toCBORBytesturns aDatavalue into a generic CBOR tree and hands it to the CBOR encoder, which applies one set of options to the whole tree. Some Plutus data rules do not fit that model, so they are missing or live inCBOR.ts:PlutusCore/Data.hsencodeData)[index, fields]pair as a definite 2-element array; only the fields follow the list encodingCBOR.BoundedBytes, a Plutus-specific node in the genericCBORtypeThe node splits this the same way: the ledger delegates Plutus data to the Plutus encoder (cardano-ledger
Plutus/Data.hsL86-87,encCBOR (PlutusData d) = fromPlainEncoding $ Cborg.encode d).Proposal
Give
Dataits own encoder that walks aDatavalue straight to bytes:encodeData, including the four rows above.PLUTUS_DATA_OPTIONS,CML_DATA_DEFAULT_OPTIONS,CML_DATA_DEFINITE_OPTIONSandCANONICAL_OPTIONSkeep their meaning.Data.toCBORBytes,Data.toCBORHex,Data.toDatumHashand theDataencode schemas use it. The transaction encoders already join datum and redeemer bytes fromData.toCBORBytes(feat(cbor): write witness datums and redeemer data with TxCodecOptions #610), inline datums do too (DatumOption.ts), so they pick it up without changes.CBOR.BoundedBytes, soCBORholds no Plutus data rules.Order
Datato it. This fixes Data: constructors with an index above 127 write the tag 102 pair with the wrong header #601 and CBOR: bignum payloads bypass bounded_bytes chunking above 64 bytes #530 and the -2^64 boundary from CBOR: align Data map encoding default and fix negative int bignum boundary #395.CBOR.BoundedBytes.PLUTUS_DATA_OPTIONS(CBOR: align Data map encoding default and fix negative int bignum boundary #395).Regression test
Data, outside the table's cases.Constr 128 [1]andConstr 1000 [1]underPLUTUS_DATA_OPTIONSequal the cardano-cli 10.5.1hash-script-databytes in Data: constructors with an index above 127 write the tag 102 pair with the wrong header #601.serialise_data.