Remove Crypto parametrization #4223
Labels
enhancement
New feature or request
performance
simplification
A nice to have improvement that simplifies the implementation
In light of recent discovery of crypto parametrization having serious overhead on the cardano-node due to lost specialization with ghc-9.x we decided that it will be a good idea to remove crypto parametrization completely.
I was very much aware of the fact that Crypto adds a significant cognitive overhead, but previously I only speculated that it could have performance overhead. Now we have confirmation that this is indeed the case.
I believe, originally the goal for crypto parametrization was to allow using different cryptographic primitives for testing, which turned out to be only a partially useful idea.
Last year while investigating potentially adding BatchVRF I questioned the usefulness of
Crypto
and we came to few realizations:HASH
,ADDRHASH
andDSIGN
, which can never change. Therefore there is no point in them being a type family.VRF
andKES
are used by the consensus codebase for things like block header validation, etc. Which means ledger has no need for those type families and they should only be able to change for different block header types.These two discoveries made us realize that we do not need crypto parametrization in ledger at all. If we were to remove it, regression with performance would go away. So, not only GHC would have a much easier time with specializing, but the codebase and downstream uses of ledger would become much simpler, thus leading to less confusion about ledger types, which have enough complexity in them already. I lost count how many times I had to explain type errors when people confused era and crypto type parameters.
So, there are two major tasks that need to be done in order to get rid of Crypto:
VRF
andKES
fromCrypto
to something likeHeaderCrypto
and make block header parametrized by crypto, which was implemented as proof of concept a year ago: Split Crypto into Crypto and HeaderCrypto #3388Both of those tasks will require significant amount of work because they would touch a lot of code, but they be would very well worth it. Therefore, we can't tackle this task until after Conway is released.
Few related notes:
c ~ StandardCrypto
will not work as interim solution, because that would require us removing a whole bunch of tests that use MockCrypto for dealing with fake VRF and KESThe text was updated successfully, but these errors were encountered: