IntersectMBO / cardano-ledger

The ledger implementation and specifications of the Cardano blockchain.
Apache License 2.0
257 stars 158 forks source link

Cost Model serialization should be canonical CBOR #2512

Closed JaredCorduan closed 2 years ago

JaredCorduan commented 3 years ago

The intention was for all the CBOR in the LangDepView to be canonical CBOR. The CostModel, however, is using an indefinite length list encoding: https://github.com/input-output-hk/cardano-ledger-specs/blob/3ff2b08c7e094a3b9035fafb170e0e1da9b75401/eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Scripts.hs#L172-L175

The tests here:

https://github.com/input-output-hk/cardano-ledger-specs/blob/3ff2b08c7e094a3b9035fafb170e0e1da9b75401/eras/alonzo/test-suite/test/Test/Cardano/Ledger/Alonzo/Serialisation/Canonical.hs#L36-L43

failed to catch this bug since we have a cbor-in-cbor encoding.

We need to now:

JaredCorduan commented 2 years ago

more details about how to fix this:

The function encodeLangViews is the problem.

https://github.com/input-output-hk/cardano-ledger/blob/4e2d082d3a01d8a172d0659b9c6d7f56689570ca/eras/alonzo/impl/src/Cardano/Ledger/Alonzo/PParams.hs#L505-L509

There are two problems:

The right thing to do is

JaredCorduan commented 2 years ago

the actual encoding for plutus V1 is now described here: https://github.com/input-output-hk/cardano-ledger/blob/7155301bcddc9cc2efe9cd98ad9c2521e9a0d085/eras/alonzo/test-suite/cddl-files/alonzo.cddl#L111-L115