Skip to content

Refactor (de)serialization of crypto entities #668

Closed
@jpraynaud

Description

@jpraynaud

Issue

We need to handle the (de)serialization operations more implicitly allowing:

  • Avoid handling manually serialize/deserialize operations
  • Store non encoded objects in the entities
  • Support multiple serialization format (with auto detection)

To do

Step 1: PoC on ProtocolVerificationKey type with JsonHex

  • Replace HexEncodedProtocolVerificationKey by ProtocolVerificationKey
  • Handle smoothly (de)serialize when embedded in other types (e.g. CertificateMetada that has a list of SignerWithStake)

Step 2: Apply to all other types

  • Implement a generic ProtocolKey<T> wrapper type of STM types
  • Avoid hard coding JsonHex encoded cumbersome values in test by centralizing these values in fake_data module (except for golden tests)
  • Update all the crypto entities that use a HexEncoded prefix in type. Here is the list:
    • pub type HexEncodedSingleSignature = HexEncodedKey;
    • pub type HexEncodedMultiSignature = HexEncodedKey;
    • pub type HexEncodedAgregateVerificationKey = HexEncodedKey;
    • pub type HexEncodedVerificationKey = HexEncodedKey;
    • pub type HexEncodedVerificationKeySignature = HexEncodedKey;
    • pub type HexEncodedOpCert = HexEncodedKey;
    • pub type HexEncodedGenesisSecretKey = HexEncodedKey;
    • pub type HexEncodedGenesisVerificationKey = HexEncodedKey;
    • pub type HexEncodedGenesisSignature = HexEncodedKey;
    • pub type HexEncodedDigest = HexEncodedKey;
    • pub type HexEncodedEraMarkersSecretKey = HexEncodedKey;
    • pub type HexEncodedEraMarkersVerificationKey = HexEncodedKey;
    • pub type HexEncodedEraMarkersSignature = HexEncodedKey;

Update methodology

  1. Move the type alias from mithril-common::crypto_helper::types::alias to the mithril-common::crypto_helper::types::wrappers module
  2. Change the type definition to a ProtocolKey<T> where T is the concrete stm types that was behind the hex encoded key
  3. Try to compile the workspace to see where the compilation fails
  4. Update the failing code, most likely by replacing a lot of to_string with try_into calls, be wary that using try_into return an error that you should handle.
  5. If the code that fails to compile relate to the aggregator database don't forget to add a golden test (for example see the test_golden_master in the database::provider::open_message module).

Later / to design

Step 3: PoC on ProtocolVerificationKey type with JSONHex/CborHex?

  • Implement traits SerializeJsonHex/DeserializeJsonHex with blanket implementation that handles the (de)serialization in json hex
  • Implement traits SerializeCborHex/DeserializeCborHex with blanket implementation that handles the (de)serialization in cbor hex
  • Implement traits SerializeEntity: SerializeJsonHex+SerializeCborHex/DeserializeEntity: DeserializeJsonHex+DeserializeCborHex (that handles auto-detection of type when deserializing?)
  • Do we need to add an extra information in messages/entities with the encoding type or do we auto-detect encoding?

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions