# stupidly simple pq signatures solidity Source: https://github.com/Philogy/stupidly-simple-pq-signatures-solidity Kiwi News: https://news.kiwistand.com/stories/stupidly-simple-pq-signatures-solidity?index=0x6b14498eebd7526fc6b1595217427c3d12f0a7c1f3b0ee9d8878e57a706710c56df21c7b Submitted by misha on 2026-12-05 UTC, 1 upvote, 0 comments ## Summary A minimal 12-line Solidity implementation of a Lamport-style post-quantum signature scheme is presented as relying only on hash functions, not on factoring, discrete logarithms or lattices. The repo says the scheme is structurally FORS with k = 32 and tree height 8, and that it is much simpler than SPHINCS+ and SLH-DSA. Because it is one-time, every signed message includes the next public key, and the SafeLamportSigner contract with the pqsafe CLI is described as Safe-compatible. Calling SafeLamportSigner.approve costs about 391k gas under the Prague EVM version. ## Article Stupidly Simple Post-Quantum Signing for Ethereum This repo provides a minimal, 12-line Solidity implementation of a Lamport-style post-quantum signature scheme. This scheme is post-quantum because it does not rely on the hardness of factoring or discrete logarithms (RSA, ECDSA). In fact it doesn't even rely on lattices, only hash functions. The cost of calling SafeLamportSigner.approve, which verifies a signature and rotates the public key, is ~391k gas (EVM version prague). KISS (Keep It Simple, Stupid) Unlike other hash-only signature schemes such as SPHINCS+ and its variants (e.g. SLH-DSA), the scheme is much simpler both conceptually and from an implementation perspective. Structurally it's FORS (with k = 32, tree height a = 8). The reduction in complexity is however not entirely free, to ensure the scheme robust it's used as a one-time signature scheme, meaning every private key may only be used to sign one message. Using it practically requires rotating keys with every signature. The provided SafeLamportSigner has every signed message include the next public key. Use with Safe This repo also provides src/SafeLamportSigner.sol a minimal, Safe-compatible signer. Along with pqsafe a small CLI written using only bash, forge and basic UNIX utils such as awk to manage keys and submit transactions. To use the signer deploy an instance of the contract configured with your Safe's address and starting Lamport pubkey. Then add the signer contract address as a required owner to your multisig. Use pqsafe new to generate a pubkey and pqsafe approve to approve transactions on the Lamport signer before attempting to execute them in your safe. The CLI SHOULD ensure you never sign two different messages with your private key but be cautious. Implementation The implementation of signature verification itself is only 12 lines of Solidity (18 lines, if you count the surrounding function declaration): src/Lamport.sol bytes32[CHUNKS] memory roots; for (uint256 i = 0; i < CHUNKS; ++i) { uint256 value = uint8(digest[i]); bytes32 node = keccak256(abi.encode(sig[i][0])); for (uint256 j = 0; j < DEPTH; ++j) { bytes32 sibling = sig[i][j + 1]; node = keccak256(value % 2 == 0 ? abi.encode(node, sibling) : abi.encode(sibling, node)); value = value / 2; } roots[i] = node; } return keccak256(abi.encode(roots)); (Yes that's it. No yeah really, that's the entire signature verification, no libraries.) How it Works Assumptions The scheme only relies on the assumption that the hash function you're using (keccak-256 for this implementation) is cryptographically secure, simplified it just means that you assume reversing it is hard. So if I give you hash h := keccak256(k) it's very hard to find k or in fact any string k' such that keccak256(k') = h from just h alone. End Goal The end goal is to have some logic our smart contract can execute to verify that someone with the private key intended to sign exactly the given message. Specifically the 32-byte digest (digest is just the hash of our message). Lamport Signatures In Lamport's original signature scheme this is achieved quite simply by generating 2 secrets per bit in our message. So 32 bytes x (8 bits / byte) x (2 secrets / bit) = 512 secrets. So for each bit $i$ we'll have a pair of secrets $(s_{i,0}, s_{i,1})$. Naively our public key is then just the hashes of all our secrets: $\lbrace h(s_{0,0}),\ h(s_{0,1}),\ h(s_{1,0}),\ h(s_{1,1}), \dots\ , h(s_{255,0}), h(s_{255,1}) \rbrace$. Signing a message is then as simple as revealing the secret for the bit at every position in the message we wish to sign. Say the bits start with 00110... then we'd reveal $\lbrace s_{0,0},\ s_{1, 0},\ s_{2, 1},\ s_{3, 1},\ s_{4, 0},\dots \rbrace$. Verifying the signature is as simple as rehashing those secrets and verifying the match. Our hash function tells us that this is only possible if we knew the secrets. This also reveals why the scheme is one-time, once you've revealed the secrets for a bit at every position you can't sign a second message with the same secrets without allowing someone to forge a signature for a different 3rd message by combining secrets from the two signatures. Our Scheme To make verification and storage a bit easier we make two simple extensions to Lamport signatures: The public key is the hash of concatenated hashes, this ensures we only have to keep track of one 32-byte value as our public key. This however also means the signature has to not only provide the secrets but also the opposing hashed secrets so that the public key can be reconstructed and compared. We generate 256 secrets per byte for every byte in our digest length (32), or rather 1 secret per possible byte value. We then commit to these values in a Merkle tree. This allows us to sign a full byte using 9 values, giving us an efficiency of 1.125 hashes / bit in the signature rather than 2 hashes / bit. This can be seen as a generalization of Lamport signatures where the base Lamport signature scheme uses a Merkle tree of depth 1 and we're using a Merkle tree of depth 8.