Variable Length Hashing
| MPS | 0053 |
|---|---|
| Status | Draft |
| Category | Libraries and Tooling |
| Authors | Karmel Elshinnawi (Karmoola) |
| Created | 28-NOV-2026 |
Abstract
Compact’s keccak256 and secp256k1 signature functions only accept fixed-length input: they always hash the entire argument, and its size is set at compile time. Contracts therefore cant hash or verify signatures over variable-length messages. A message padded to a fixed size produces a different digest from the one the signer hashed, so the signature check fails. This blocks contracts that verify Ethereum-style signed messages of varying length, such as oracle price updates.
Vision
Compact supports variable-length input for keccak256 and secp256k1. A contract passes a fixed-size buffer and the message length, and the function hashes or verifies only the message bytes. The result matches what an off-chain signer produced.
Problem
Oracles, bridges and other services that sign variable-length messages off-chain cannot be verified on Midnight
keccak256and the secp256k1 operations take fixed-length input only. There is no way to hash part of a buffer.- Circuits require fixed-size inputs, so variable-length messages must be padded. The padding is hashed with the message, so the digest no longer matches the signed digest.
- Workarounds, such as verifying a signed Merkle root instead of the message, require the signer to change its protocol. External protocols built on variable-length messages will not do this.
Use Cases
- Oracle price updates: An oracle signs variable-length price updates (secp256k1 signature over a keccak256 digest). A contract copies a 240-byte update into a 512-byte buffer, hashes the first 240 bytes, and verifies the signature against the oracle’s public key before accepting the price. Today verification fails because the padding is hashed.
- Cross-chain messages: A contract verifies Ethereum-signed messages, such as attestations, intents or bridge messages, whose length depends on their content.
Goals
- Hash variable-length input with keccak256: hash only the first
lengthbytes of a fixed-size buffer, wherelengthis a runtime value andlength ≤ N. - Verify secp256k1 signatures and recover signers over variable-length messages.
- Output matches standard Ethereum keccak256 and secp256k1 over the same message.
- Proving cost is acceptable for use in every transaction
References
Acknowledgements
Copyright
This MPS is licensed under CC-BY-4.0.