Onchain Logic and State
The Midnight node follows the standard Polkadot SDK model for defining and executing on-chain logic. All core logic (except native pre-compiles) is compiled into WebAssembly (WASM), which forms the node’s runtime—the state transition function executed consistently across all participating nodes.
This runtime is composed of modular components known as FRAME pallets. Each pallet encapsulates a specific domain of logic and can include storage definitions (maps, multi-key maps, lists, values), events, dispatchable functions (transactions), offchain workers, hooks, host-exposed functions, and RPC methods. This modular design allows for a flexible and extensible on-chain execution environment, similar in spirit to a smart contract framework but compiled ahead of time and governed at the chain level.
Midnight’s runtime integrates both upstream pallets from Polkadot SDK and components developed by Cardano Partner-Chains. Examples include:
pallet-aura: Handles block production using the AURA protocol.pallet-grandpa: Manages finality through the GRANDPA protocol.pallet-partnerchains-sessionandpallet_session_validator_management: Coordinate session rotation and validator management in the partnerchain context.
The core pallet powering Midnight’s privacy-preserving transaction logic is pallet-midnight. Maintained internally, this pallet encapsulates the state machine for the Midnight Ledger.
The pallet-midnight is responsible for processing specialized transactions originating from the Midnight Ledger, including ZSwap asset transfers and contract operations. Rather than relying on traditional signature-based dispatch, this pallet processes cryptographic proofs embedded in each transaction. It leverages native libraries to verify these proofs and execute the corresponding state transitions.
Once executed, the new state is committed on-chain. Like all Polkadot SDK chains, Midnight uses a Patricia-Merkle trie, backed by a key-value database, to store the canonical ledger state. A commitment to the full Midnight Ledger state is also stored, ensuring a tamper-proof, verifiable snapshot of the system after each block.