Cryptography
Outside of the Midnight Ledger, which contains its own specialized cryptographic circuits, the Midnight node relies on several foundational cryptographic algorithms for securing core functions such as consensus, state transition integrity, and network communication.
The primary hash function used is Blake2 256, which provides strong cryptographic guarantees and is employed for general-purpose hashing — including block hashes and within various state transition functions. It strikes a balance between performance and security, making it suitable for runtime-critical operations.
For signature verification, Midnight uses three distinct schemes depending on the role:
-
sr25519, based on the Schnorrkel and Ristretto x25519 construction, is used for signing block authorship messages in the AURA consensus mechanism. It supports efficient key derivation, signature aggregation, and strong security properties.
-
ECDSA is used specifically for signing consensus-related messages associated with Partnerchains. This ensures interoperability with external systems that adopt ECDSA as a standard.
-
Ed25519 is employed in two areas of the Midnight node:
- for signing finality-related messages in the GRANDPA protocol, offering a fast and secure mechanism for verifying validator communications during finalization.
- for signing messages sent as part of the underlying libp2p protocols implemented in Polkadot SDK
Additionally, the Midnight node uses twoxhash as a non-cryptographic hash function for generating storage keys. While not suitable for cryptographic applications, twoxhash is optimized for speed and low collision rates, making it appropriate for internal key-value storage structures. More details on its use are described in the Storage section.