IntersectMBO / IntersectMBO/cardano-base

Improve KES interface

Open
#81 1 comment 0 reactions 0 assignees View on GitHub
consensus priority high shelley testnet
Dominant language
Haskell
Stars
105
Forks
54
Avg merge
9d 2h
Merged PRs (30d)
4

Description

The KES interface (https://github.com/input-output-hk/cardano-base/blob/master/cardano-crypto-class/src/Cardano/Crypto/KES/Class.hs) should be improved:

* It needs documentation
* The two different use cases of `Natural` in the mock implementation should be `newtype`d
* Most importantly, `updateKES` should get an argument: the KES period to evolve to.

We might after all have to skip some periods. For the mock, I can implement this as

```haskell
-- | Update key to specified period
--
-- Throws an error if the key is already /past/ the period
updateKESTo :: forall m v. (MonadRandom m, HasCallStack, KESAlgorithm v)
=> ContextKES v
-> Natural -- ^ KES period to evolve to
-> SignKeyKES v
-> m (Maybe (SignKeyKES v))
updateKESTo ctxt evolveTo = go
where
go :: SignKeyKES v -> m (Maybe (SignKeyKES v))
go key
| iterationCountKES ctxt key < evolveTo = do
mKey' <- updateKES ctxt key
case mKey' of
Nothing -> return Nothing
Just key' -> go key'
| iterationCountKES ctxt key == evolveTo =
return (Just key)
| otherwise =
error "updateKESTo: key already past period"
```

But I don't know if this is correct in the general case: does `iterationCountKES` return the period or the iteration count? If the former, this is correct generally, though we still might want to make this part of the main API; in that case, this function should also be renamed, as it's not the iteration count. If the iteration count is something separate from the rest, this function is wrong, but in that case documentation should be improved to document what this is.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.