Alt EVM
Post-quantum signatures in Solidity
A Winternitz one-time signature verifier that stays sound against a quantum computer.
Overview
Quire requires a WOTS co-signature on large payment batches. Security rests on keccak256 preimage resistance, not discrete logs. The verifier walks each of 67 hash chains to its end, hashes the ends into a leaf, then climbs a Merkle tree of one-time keys to the registered root.
The code
contracts/src/libraries/LibWots.solView on GitHub ↗
/// Winternitz one-time signature (WOTS, w = 16) verification with keccak256, plus a Merkle tree of
/// one-time public keys. Hash-based, so it stays sound against an adversary with a quantum computer.
function chain(bytes32 x, bytes32 pubSeed, uint32 leafIndex, uint8 chainIdx, uint8 start)
internal pure returns (bytes32 out)
{
out = x;
assembly {
let p := mload(0x40) // scratch beyond the free pointer
mstore(p, pubSeed)
for { let step := start } lt(step, 15) { step := add(step, 1) } {
mstore(add(p, 32), shl(224, leafIndex))
mstore8(add(p, 36), chainIdx)
mstore8(add(p, 37), step)
mstore(add(p, 38), out)
out := keccak256(p, 70)
}
}
}
function digits(bytes32 digest) internal pure returns (uint8[67] memory d) {
uint256 h = uint256(digest);
uint256 csum;
for (uint256 i; i < 64; i++) {
uint8 v = uint8((h >> (252 - 4 * i)) & 15);
d[i] = v;
csum += 15 - v;
}
d[64] = uint8((csum >> 8) & 15);
d[65] = uint8((csum >> 4) & 15);
d[66] = uint8(csum & 15);
}
How it works
- w = 16: 64 message chains plus 3 checksum chains, each of length 15
- WOTS+-style tweakable hashing (seed, leaf, chain, step) to defeat multi-target attacks
- Inline assembly reuses one scratch buffer so the 70-byte chain hash costs no allocations
- computeRoot never reverts on bad input: a forged signature just produces a different root