Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP Split Crypto into standard Crypto and HeaderCrypto #3262

Closed
wants to merge 7 commits into from

Conversation

yogeshsajanikar
Copy link
Contributor

@yogeshsajanikar yogeshsajanikar commented Jan 18, 2023

Description

VRF and KES have new optimized implementations that need to be used for Conway era. This is the first step to use separate KES/VRF from Crypto such that it can be parametrized separately. Also since consensus is the primary consumer of the VRF/KES and ledger uses them for the bookkeeping, this PR moves HeaderCrypto into TPraos protocol.

This branch is based on a #lehins/no-vrf-usage-in-ledger (ported on the ledger release) to get conensus code compiled.

Checklist

  • Commit sequence broadly makes sense
  • Commits have useful messages
  • New tests are added if needed and existing tests are updated
  • Any changes are noted in the changelog
  • Code is formatted with fourmolu (which can be run with scripts/fourmolize.sh
  • Self-reviewed the diff

This is still the work in progress and is rough at edges

- Split Crypto class into Crypto (DSIGN, ADDRHASH) and HeaderCrypto (KES, VRF)
- Move HeaderCrypto into Cardano.Protocol
- Use PoolStakeVRF and GenesisVRF as a proxy to VRF in ledger code
- Parametrize TPrao protcol code with Crypto and HeaderCrypto
  Many functions are parametrized by Era and HeaderCrypto as Era implicitly
  implies Crypto (Crypto Era).

TODO: Get examples and tests compiled
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.

Yeah, this is looking good. I only had a couple of questions.

@@ -156,22 +163,22 @@ defaultShelleyLedgerExamples mkWitnesses mkAlonzoTx value txBody auxData transla
-------------------------------------------------------------------------------}

exampleShelleyLedgerBlock ::
forall era.
(EraSegWits era, ShelleyBasedEra' era) =>
forall era hcrypto.
Copy link
Collaborator

Choose a reason for hiding this comment

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

We've switched everywhere in the repo from crypto type parameter to c, at least that is the way it is now on master, so I think it would be best to name it hc

Suggested change
forall era hcrypto.
forall era hc.

MaxKESEvolutionsUnsupported
sgMaxKESEvolutions
(totalPeriodsKES (Proxy @(KES (Crypto era))))
-- TODO: This is the only place where KES is required and that too for a
Copy link
Collaborator

Choose a reason for hiding this comment

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

The whole validateGenesis function can be moved into cardano-protocol-praos, since it is not used anywhere in ledger.

Comment on lines 588 to 589
-- where
-- poolKeys = exampleKeys @c @hc @'StakePool
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
-- where
-- poolKeys = exampleKeys @c @hc @'StakePool

@@ -271,7 +284,7 @@ tickChainState
Origin -> NeutralNonce
At (LastAppliedBlock {labHash}) -> hashHeaderToNonce labHash
}
lv = either (error . show) id $ futureLedgerView testGlobals chainNes slotNo
-- lv = either (error . show) id $ futureLedgerView testGlobals chainNes slotNo
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
-- lv = either (error . show) id $ futureLedgerView testGlobals chainNes slotNo

@@ -245,7 +253,7 @@ instance CC.Crypto c => GetLedgerView (ConwayEra c) where
$ TRC ((), ss, slot)

-- | Data required by the Transitional Praos protocol from the Shelley ledger.
data LedgerView crypto = LedgerView
data LedgerView crypto hcrypto = LedgerView
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do you need hcrypto in the LedgerView? It does not seem to being used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not required. It is something that needs cleanup.

- ALl the ledger code is separated from header crypto (KES/VRF)
- Proxy VRFs are PoolStakeVRF and GenesisVRF
Format as per the style
- Use Data.Proxy instead of a locally defined data type
yogeshsajanikar added a commit to IntersectMBO/ouroboros-network that referenced this pull request Jan 25, 2023
- Use HeaderCrypto to separately parametrise HeaderBody
- The ledger Era is only bound to standard Crypto
- The consensus protocol is parametrised by Crypto and HeaderCrypto

Note that
- Only ouroboros-consensus-protocol is compiled
- ouroboros-consenus-cardano libarry is WIP, and only Block.hs is
  changed to reflect the fact that it is possible to use a separate
  HeaderCrypto for an era (and define the the cardano eras) parametrized
  by different crypto version. Each version reflecting a unique
  combination of standard Crypto and Header Crypto.

This repo is compiled against ledger branch (see
IntersectMBO/cardano-ledger#3262). You might
have to change cabal.project to compile against git repository
@ghost
Copy link

ghost commented Feb 8, 2023

@lehins I am taking this over this PR from @yogeshsajanikar, as this is part of IntersectMBO/ouroboros-network#4151. Would you have some time to help me understand better what's the situation? I think I understand the overall goal of this work (eg. support evolving crypto primitives over eras) but it's not clear to me what's been done, what remains to be done, what's the deadline, whether there are intermediate steps we could do, etc.

@lehins
Copy link
Collaborator

lehins commented Feb 8, 2023

It's not clear to me what's been done, what remains to be done, what's the deadline, whether there are intermediate steps we could do, etc.

@abailly-iohk I'll be happy to chat about it, however I am not too sure about the progress on this work or what the actual time line is. Considering that this PR is using 1.1 release branch as base this work is definitely outdated.

@yogeshsajanikar
Copy link
Contributor Author

The changes are done to the release branch as the main purpose was to

1 Split the crypto into two parts, header and body
2 Test these changes against consensus code.

Hence I changed release branch against which consensus code was compiled. Initially I targeted the ledger master branch, but the porting changes required in consensus were non-trivial.

The current status of the change is

  • the changes off the 1.1 release is compiled against consensus protocol library.

Having said that I agree that work is needed to make it work against master. But most of the changes are mechanical.

@ghost
Copy link

ghost commented Feb 9, 2023

@yogeshsajanikar Thanks for your input, we have a chat today with @lehins to sort out this branch issue and move this PR forward.

@ghost
Copy link

ghost commented Feb 10, 2023

Had a shot at rebasing this issue on master and it's not trivial (for me), as discussed with @lehins I will wait for him to merge related changes to ledger's master codebase before trying again.

@yogeshsajanikar
Copy link
Contributor Author

Can I help? I have a some free time next week.

@ghost
Copy link

ghost commented Feb 12, 2023

@yogeshsajanikar Sure, would you be available on Monday morning CET for a call?

@yogeshsajanikar
Copy link
Contributor Author

yogeshsajanikar commented Feb 13, 2023

Yes. Please feel free to schedule a meeting @abailly-iohk

@ghost
Copy link

ghost commented Feb 13, 2023

Hope you're available, just setup a meeting today at 10:30 CET

@ghost
Copy link

ghost commented Feb 14, 2023

@lehins Do you have a branch we could attempt to rebase on?

@lehins
Copy link
Collaborator

lehins commented Feb 14, 2023

@abailly-iohk The one I have is quite unstable right this moment, however I expect this to change either today or tomorrow. So, very soon I'll have a reviewable PR, which could be used as a base branch if need be.

@ghost
Copy link

ghost commented Feb 22, 2023

@lehins Any news on this front?

@lehins
Copy link
Collaborator

lehins commented Feb 22, 2023

@abailly-iohk Sorry, forgot to let you know. I did have a reviewable PR last week. As of today it has been merged, so IntersectMBO/ouroboros-network#4349 is fully compatible with ledger master. I'll be doing ledger releases to CHaPs today and merging the above PR

@ghost
Copy link

ghost commented Feb 22, 2023

No problem @lehins , so this means we can rebase this PR on master?

@lehins
Copy link
Collaborator

lehins commented Feb 22, 2023

this means we can rebase this PR on master?

Correct

@ghost
Copy link

ghost commented Feb 22, 2023

@yogeshsajanikar Are you still available to do the rebase? Otherwise, I can take care of it, no worries.

@yogeshsajanikar
Copy link
Contributor Author

yogeshsajanikar commented Feb 23, 2023 via email

@ghost
Copy link

ghost commented Feb 23, 2023

@yogeshsajanikar Tomorrow is totally fine, thanks for your help

@yogeshsajanikar
Copy link
Contributor Author

Started working on this.

@yogeshsajanikar
Copy link
Contributor Author

Continuing work today afternoon.

@ghost
Copy link

ghost commented Mar 9, 2023

@yogeshsajanikar I guess you did not have time to work on this? That's totally fine, I propose to take it over if you don't mind as I need it to implement the relevant stuff in consensus.

@JaredCorduan
Copy link
Contributor

This PR appears stale. I am going to close it for now.

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.

3 participants