Autogenerated CDDL files are not following the CDDL Specification with regard to the root type.
Eg, https://github.com/IntersectMBO/cardano-ledger/blob/master/eras/conway/impl/cddl-files/conway.cddl
Defines the root type as $hash28.
The RFC in section 2.2.4 defines the root type as:
There is no special syntax to identify the root of a CDDL data
structure definition: that role is simply taken by the first rule
defined in the file.
Disobeying this rule can cause breakage in tooling that consumes the file for code generation or automation purposes. This is because these tools are entitled to take the first rule, and discard anything in the file which is not referenced by it.
If the root rule of conway.cddl is the block, then it should always be listed first in the file.
Compare the new file to the old one: https://github.com/IntersectMBO/cardano-ledger/blob/78b32d585fd4a0340fb2b184959fb0d46f32c8d2/eras/conway/impl/cddl-files/conway.cddl
Which does correctly have the root type as a block.
Also, I just saw this:
address = h'001000000000000000000000000000000000000000000000000000000011000000000000000000000000000000000000000000000000000000'
/ h'102000000000000000000000000000000000000000000000000000000022000000000000000000000000000000000000000000000000000000'
/ h'203000000000000000000000000000000000000000000000000000000033000000000000000000000000000000000000000000000000000000'
/ h'304000000000000000000000000000000000000000000000000000000044000000000000000000000000000000000000000000000000000000'
/ h'405000000000000000000000000000000000000000000000000000000087680203'
/ h'506000000000000000000000000000000000000000000000000000000087680203'
/ h'6070000000000000000000000000000000000000000000000000000000'
/ h'7080000000000000000000000000000000000000000000000000000000'
Thats literally saying that an address can only be one of these fixed values. Pretty sure thats not correct, though I could be wrong?
I also just noticed that the vast majority of the documentation comments have been stripped from the file, so its much less useful a file for anyone who would want to use it to integrate to cardano. I find myself now constantly having to refer to the original version because the information I need no longer exists in the file.
Thats literally saying that an address can only be one of these fixed values.
Yes, that is an unfortunate hack we have to use for testing conformance of our deserializers to the cddl spec. We have tests that generate randomg data from the cddl spec and deserialize it using ledger decoders. Address binary format is not defined in CBOR, so we can't really specify it in CDDL. Neither can we specify that it is bytes of a specific size, because that would not be true either, since not only binary size of addresses varies, but also our deserializers will fail if they are not adhering to their internal format.
Here is a ticket that talks about the useful comment about it being removed: https://github.com/IntersectMBO/cardano-ledger/issues/4522
I also just noticed that the vast majority of the documentation comments have been stripped from the file
Yes that is an oversight. It'll get fixed.
@nc6 Could you please address this ticket and #4522 next, before switching to huddle spec for other eras.
Just for clarity on the original issue, as long as the first type defined was block for this CDDL, all the other types can be defined in any order and it would be compliant with the root type section of the cddl spec.
Also something like:
root_type = block
right at the top of the file would also satisfy the CDDL spec.
Good catch.
Interestingly, this was never actually valid for the original CDDL files. In particular, transaction is not referenced from block. That's why in https://github.com/IntersectMBO/cardano-ledger/blob/72fe2464a790908dee7b1f24a5daddff8d1f3edd/eras/conway/impl/testlib/Test/Cardano/Ledger/Conway/CDDL.hs#L22, the collectFrom call has to specify multiple root types.
I'll take your suggestion and generate a single root_defs element at the top. This will then allow referencing all of the required entities, rather than just block as before.
Will be addressed in Cuddle 0.3.1.0 - https://github.com/input-output-hk/cuddle/commit/79d6a7800c26e61181a806c5766de88403d17f5e