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

Upgrade cardano-base dependency #4699

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

tdammers
Copy link

Description

Upgrade dependency on cardano-base in order to be compatible with upcoming versions of ouroboros-consensus.
In current versions of cardano-base, KES sign keys are stored in mlocked memory, and all operations involving them must now happen in IO or ST. In order to facilitate existing pure code that isn't security-critical (e.g., generating mock data for testing purposes), the previous pure KES API is now provided as UnsoundPureKES, which we use here.

Checklist

  • Commit sequence broadly makes sense and commits have useful messages
  • New tests are added if needed and existing tests are updated
  • All visible changes are prepended to the latest section of a CHANGELOG.md for the affected packages.
    New section is never added with the code changes. (See RELEASING.md)
  • When applicable, versions are updated in .cabal and CHANGELOG.md files according to the
    versioning process.
  • The version bounds in .cabal files for all affected packages are updated.
    If you change the bounds in a cabal file, that package itself must have a version increase. (See RELEASING.md)
  • Code is formatted with fourmolu (use scripts/fourmolize.sh)
  • Cabal files are formatted (use scripts/cabal-format.sh)
  • hie.yaml has been updated (use scripts/gen-hie.sh)
  • Self-reviewed the diff

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.

@tdammers Please get rid of any changes related to serialization.
I wish you would have asked me before you went on wasting a lot of time on introducing all those changes.

We need to get rid of all KES related serialization form ledger, since ledger codebase does not depend on KES at all. So, please revert all of the additions with respect to KES and get rid of any serialization functionality for KES that was provided before

eras/shelley/impl/src/Cardano/Ledger/Shelley/API/Types.hs Outdated Show resolved Hide resolved
libs/cardano-ledger-binary/cardano-ledger-binary.cabal Outdated Show resolved Hide resolved
libs/cardano-ledger-binary/cardano-ledger-binary.cabal Outdated Show resolved Hide resolved
libs/cardano-ledger-binary/cardano-ledger-binary.cabal Outdated Show resolved Hide resolved
libs/cardano-ledger-binary/cardano-ledger-binary.cabal Outdated Show resolved Hide resolved
libs/cardano-ledger-binary/cardano-ledger-binary.cabal Outdated Show resolved Hide resolved
Comment on lines 100 to 123
withSK :: KESAlgorithm v
=> PinnedSizedBytes (SeedSizeKES v) -> (SignKeyKES v -> IO b) -> IO b
withSK seedPSB action =
bracket
(fmap MLockedSeed . mlsbFromByteString . psbToByteString $ seedPSB)
mlockedSeedFinalize
$ \seed ->
bracket
(genKeyKES seed)
forgetSignKeyKES
action

mkVerKeyKES :: KESAlgorithm v
=> PinnedSizedBytes (SeedSizeKES v)
-> IO (VerKeyKES v)
mkVerKeyKES seedPSB =
withSK seedPSB deriveVerKeyKES

mkSigKES :: (KESAlgorithm v, ContextKES v ~ (), Signable v BS.ByteString)
=> (PinnedSizedBytes (SeedSizeKES v), [Word8])
-> IO (SigKES v)
mkSigKES (seedPSB, msg) =
withSK seedPSB $ \sk -> (signKES () 0 (BS.pack msg) sk)

Copy link
Collaborator

Choose a reason for hiding this comment

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

All KES tests can be removed. Again. We don't need them, if we do not provide those serialization instances

Copy link
Author

@tdammers tdammers Oct 22, 2024

Choose a reason for hiding this comment

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

I believe we do need ser/deser on verification keys, because that is used to ser/deser OCerts. And in order to generate a verification key for testing, we need to derive it from a signing key, so we need these helpers here.

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 you missed my point. We need to remove all this new KES keys serialization related functionality from cardano-ledger-binary, because ledger does not rely on it. The fact that OCert contains KES does not interfere with that point, because the cardano-protocol-tpraos is really a consensus package. We hope to move it some day into the consensus repo. We can continue using the serialization mechanism provided by cardano-crypto-class and cardano-binary in those places where KES serialization is needed.

In places like OCert we can rely on serialization provided by unsound serialization, it just doesn't need to come from cardano-ledger-binary. All you need is fromPlainDecoder to lift the regular Decoder from cborg to the Decoder provided by the cardano-ledger-library package.

KES.encodeVerKeyKES (ocertVkHot ocert)
<> Plain.toCBOR (ocertN ocert)
<> Plain.toCBOR (ocertKESPeriod ocert)

The only reason why serialization for KES was provided by cardano-ledegr-binary was for completeness. In other words we do not need to provide unsound support, since it will be removed at some point later.

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.

2 participants