Skip to content

Conversation

@aniketd
Copy link
Contributor

@aniketd aniketd commented Oct 14, 2025

Description

This addresses the initial part of #5194 .

  1. Switch from exporting everything and hiding in the new era to exporting just the reusable parts and import the whole module in the new era.
  2. Move some more field definitions into core and reuse them.
  3. Name every field that is new in an era prefixed by that era-name.

Follow-up PRs would be to actually address the heart of #5194 to reduce duplication to a minimum.

Checklist

  • Commits in meaningful sequence and with useful messages.
  • Tests added or updated when needed.
  • CHANGELOG.md files updated for packages with externally visible changes.
    NOTE: New section is never added with the code changes. (See RELEASING.md).
  • Versions updated in .cabal and CHANGELOG.md files when necessary, according to the
    versioning process.
  • Version bounds in .cabal files updated when necessary.
    NOTE: If bounds change in a cabal file, that package itself must have a version increase. (See RELEASING.md).
  • Code formatted (use scripts/fourmolize.sh).
  • Cabal files formatted (use scripts/cabal-format.sh).
  • CDDL files are up to date (use scripts/gen-cddl.sh)
  • hie.yaml updated (use scripts/gen-hie.sh).
  • Self-reviewed the diff.

@aniketd aniketd changed the title Rename CDDL fields to better reflect their origin and more reuse Rename CDDL fields to better reflect their origin and be more reusable Oct 14, 2025
@aniketd aniketd force-pushed the aniketd/deduplicate-cddl branch from 9594784 to e2e3e15 Compare October 15, 2025 14:58
@aniketd aniketd marked this pull request as ready for review October 15, 2025 15:25
@aniketd aniketd requested a review from a team as a code owner October 15, 2025 15:25
Copy link
Contributor

@neilmayhew neilmayhew left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from the potential irregularity I commented on, this refactoring seems like it should make no difference to the CDDL.

Perhaps the test failures are due to the issue I pointed out?

Comment on lines -47 to +51
protocol_version = (major_protocol_version, uint)
protocol_version = [major_protocol_version, uint]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change from group to array seems significant. However, I don't see any change in the .hs that matches this. I wonder where it's coming from?

I saw the same difference in some of the other eras.

Copy link
Contributor

@teodanciu teodanciu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a first pass and left some comments.
In addition, I'm also wondering if it's beneficial to remove the distinction between the types in cddl that represent hashes vs just bytes (so the replacement of hash32 with bytes32).
Even though they boil down to the same thing, it might bring some value to distinguish them? What do you think?

MultiSig,
ProposedPPUpdates,
Update,
-- Update,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Presumably left by accident

Suggested change
-- Update,

Comment on lines +285 to +286
pint :: Rule
pint = "pint" =:= (1 :: Integer) ... max_word64
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this is an improvement, to me it seems less consistent (since we still have nonnegative_interval and positive_coin. I would prefer the longer "positive_" prefix for all of the above, but would be good to know what others think about it

posWord32 :: Rule
posWord32 = "posWord32" =:= (1 :: Integer) ... maxWord32
pword32 :: Rule
pword32 = "pword32" =:= (1 :: Integer) ... max_word32
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the p or positive prefix necessary for word? I would have thought it's implied that it's positive, since Word is unsigned, no?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Word implies that it is non-negative 😉 which is different from positive.

On a different note, I believe posWord/pos_word or even positiveWord/positive_word would be better prefixes than just p

Comment on lines +397 to +398
transaction_ix :: Rule
transaction_ix = "transaction_ix" =:= VUInt `sized` (2 :: Word64)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is better than what we have now, transaction_index. Is it in order to be more consistent with the code? Or any other reason in particular for this abbreviation?


negInt64 :: Rule
negInt64 = "negInt64" =:= minInt64 ... (-1 :: Integer)
nint64 :: Rule
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as before about pint - i think negative_int64 is better, less vague, easier to find, consistent with others like nonzero-int64

|]
$ "script_hash" =:= hash28
shelley_epoch :: Rule
shelley_epoch = "epoch" =:= VUInt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit strange - isn't it the same for all eras? Seems more like something for core to me - any reason to have it shelley-specific?

Comment on lines +281 to +291
script_pubkey :: Named Group
script_pubkey = "script_pubkey" =:~ grp [0, a addr_keyhash]

epoch :: Rule
epoch = "epoch" =:= VUInt
script_all :: Named Group
script_all = "script_all" =:~ grp [1, a (arr [0 <+ a shelley_native_script])]

genesis_delegate_hash :: Rule
genesis_delegate_hash = "genesis_delegate_hash" =:= hash28
script_any :: Named Group
script_any = "script_any" =:~ grp [2, a (arr [0 <+ a shelley_native_script])]

genesis_hash :: Rule
genesis_hash = "genesis_hash" =:= hash28
script_n_of_k :: Named Group
script_n_of_k = "script_n_of_k" =:~ grp [3, "n" ==> VUInt, a (arr [0 <+ a shelley_native_script])]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer here to be so consistent and explicit at the cost of verbosity and use native_script prefix instead of script , both in the name of the rules and in the keys - but curious to know what others think about it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

100% agree

Comment on lines +302 to +303
shelley_nonce :: Rule
shelley_nonce = "nonce" =:= arr [0] / arr [1, a (VBytes `sized` (32 :: Word64))]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also seems era-generic, I think it would be better in core and called "nonce"

Comment on lines +63 to +70
allegra_script_all :: Named Group
allegra_script_all = "script_all" =:~ grp [1, a (arr [0 <+ a allegra_native_script])]

script_any :: Named Group
script_any = "script_any" =:~ grp [2, a (arr [0 <+ a native_script])]
allegra_script_any :: Named Group
allegra_script_any = "script_any" =:~ grp [2, a (arr [0 <+ a allegra_native_script])]

script_n_of_k :: Named Group
script_n_of_k = "script_n_of_k" =:~ grp [3, "n" ==> int64, a (arr [0 <+ a native_script])]
script_n_of_k = "script_n_of_k" =:~ grp [3, "n" ==> int64, a (arr [0 <+ a allegra_native_script])]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we could parameterize these rules by the native_script rule, and then use them in each era with the respenctive native_script definition

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a great idea!

Comment on lines +60 to +61
allegra_script_pubkey :: Named Group
allegra_script_pubkey = "script_pubkey" =:~ grp [0, a addr_keyhash]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the same as in shelley, don't think there is a point to redefine it

Copy link
Collaborator

@lehins lehins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only took a quick look at this PR. I'll do a more thorough review tomorrow.



hash32 = bytes .size 32
bytes32 = bytes .size 32
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was hash switched to bytes? It is really good to indicate that it is not some bytes but a hash

auxiliary_data =
metadata
/ [transaction_metadata : metadata, auxiliary_scripts : auxiliary_scripts]
shelley_auxiliary_data
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is incorrect. It just so happens that in Shelley auxiliary_data is set to just metadata. But metadata is it own concept: Map Word64 Metadatum

Suggested change
shelley_auxiliary_data
metadata

Comment on lines +63 to +70
allegra_script_all :: Named Group
allegra_script_all = "script_all" =:~ grp [1, a (arr [0 <+ a allegra_native_script])]

script_any :: Named Group
script_any = "script_any" =:~ grp [2, a (arr [0 <+ a native_script])]
allegra_script_any :: Named Group
allegra_script_any = "script_any" =:~ grp [2, a (arr [0 <+ a allegra_native_script])]

script_n_of_k :: Named Group
script_n_of_k = "script_n_of_k" =:~ grp [3, "n" ==> int64, a (arr [0 <+ a native_script])]
script_n_of_k = "script_n_of_k" =:~ grp [3, "n" ==> int64, a (arr [0 <+ a allegra_native_script])]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a great idea!

/ sarr
[ "transaction_metadata" ==> metadata
, "auxiliary_scripts" ==> auxiliary_scripts
[ "transaction_metadata" ==> shelley_auxiliary_data
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, yeah, this should be metadata

Suggested change
[ "transaction_metadata" ==> shelley_auxiliary_data
[ "transaction_metadata" ==> metadata

Comment on lines +268 to +271
shelley_auxiliary_data :: Rule
shelley_auxiliary_data =
"shelley_auxiliary_data"
=:= mp [0 <+ asKey shelley_transaction_metadatum_label ==> transaction_metadatum]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how I would write it:

Suggested change
shelley_auxiliary_data :: Rule
shelley_auxiliary_data =
"shelley_auxiliary_data"
=:= mp [0 <+ asKey shelley_transaction_metadatum_label ==> transaction_metadatum]
metadatum :: Rule
metadatum =
"metadatum"
=:= smp [0 <+ asKey metadatum ==> metadatum]
/ sarr [0 <+ a metadatum]
/ VInt
/ (VBytes `sized` (0 :: Word64, 64 :: Word64))
/ (VText `sized` (0 :: Word64, 64 :: Word64))
metadatum_label :: Rule
metadatum_label = "metadatum_label" =:= VUInt
metadata :: Rule
metadata = "metadata" =:= mp [0 <+ asKey metadatum_label ==> metadatum]
shelley_auxiliary_data :: Rule
shelley_auxiliary_data = "auxiliary_data" =:= metadata

I'd also put metadata in core and then reuse it in other eras, instead of shelley_auxiliary_data.

nonnegative_interval = #6.30([uint, pint])

positive_int = 1 .. maxWord64
pint = 1 .. max_word64
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

positive_ is a much better prefix than p. Otherwise someone might think it is a definition for a pint of beer or something 🤣

Suggested change
pint = 1 .. max_word64
positive_int = 1 .. max_word64

; "\x02" for Plutus V2 scripts
; "\x03" for Plutus V3 scripts
script_hash = hash28
; "\x04" for Plutus V4 scripts
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is something definitely wrong with this comment. Tags for plutus scripts should not be relevant for Allegra CDDL

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.

4 participants