WOTS+ parameters
The exact one-time signature scheme the program verifies, its hash inputs byte by byte, and what it costs.
Lean Key uses WOTS+ (Winternitz one-time signatures) with a tweakable hash in the style of SPHINCS+. The specification is written once, in Lean (program/Twokey/Spec/Wots.lean). The on-chain verifier (program/Twokey/Program.lean) and the TypeScript signer (packages/core/src/wots.ts) implement it, and both are tested against test vectors that Lean computes from the specification (make vectors, program/release/vectors.json).
Parameters
| Parameter | Value | Meaning |
|---|---|---|
| Hash | SHA-256 | On chain through the sol_sha256 syscall; in Lean, lean-svm's FIPS 180-4 implementation checked against NIST vectors. |
| n | 24 bytes | Length of every chain value (the first 24 bytes of a SHA-256 digest). |
| w | 256 | One digit per byte: digits run 0 to 255. |
| Message digits | 24 | The first 24 bytes of the message digest. |
| Checksum digits | 2 | Σ (255 − m_i) over the 24 message digits, at most 6,120, written as two base-256 digits, high byte first. |
| Chains | 26 | 24 + 2. |
| Steps per chain | 255 | A chain runs from its secret (step 0) to its end (after step 254). |
| Signature | 624 bytes | 26 chain values of 24 bytes. |
| Public key hash | 32 bytes | SHA-256 of the 26 chain ends with a prefix; this is what the vault stores. |
| Seed | 32 bytes | Random; backed up as 24 words. |
Domain tags
Every hash input starts with an ASCII tag (program/Twokey/Spec/Bytes.lean):
| Tag | Bytes | Hex |
|---|---|---|
TWOKEY/v1/F | 11 | 54574f4b45592f76312f46 |
TWOKEY/v1/SK | 12 | 54574f4b45592f76312f534b |
TWOKEY/v1/PK | 12 | 54574f4b45592f76312f504b |
TWOKEY/v1/MSG | 13 | 54574f4b45592f76312f4d5347 |
TWOKEY/v1/INTENT | 16 | 54574f4b45592f76312f494e54454e54 |
All integers are little-endian. k is the key index as 8 bytes, i the chain number as 1 byte (0 to 25), j the step as 1 byte (0 to 254).
The functions
Tweakable hash F
F(i, j, x) = SHA-256( "TWOKEY/v1/F" ‖ program_id ‖ vault ‖ k ‖ i ‖ j ‖ x )[0..24]
The input is 109 bytes:
| Offset | Size | Field |
|---|---|---|
| 0 | 11 | TWOKEY/v1/F |
| 11 | 32 | program id |
| 43 | 32 | vault address |
| 75 | 8 | key index k, u64 LE |
| 83 | 1 | chain i |
| 84 | 1 | step j |
| 85 | 24 | chain value x |
Each hash is bound to the program, the vault, the key index, the chain and the step, so a hash computed for one position is useless at any other (protection against multi-target attacks).
Test vector (program/release/vectors.json, f_example): localnet program id, vault bytes 00 01 … 1f, k = 0, i = 3, j = 7, x = 24 bytes of 0x11 gives 99aaa723bac2cb1fbe574aba2cdb73af26f6d64d00b40c68.
Chain secrets
sk[k][i] = SHA-256( "TWOKEY/v1/SK" ‖ seed ‖ vault ‖ k ‖ i )[0..24]
The input is 12 + 32 + 32 + 8 + 1 = 85 bytes. The vault address is part of it, so one seed can serve many vaults without any vault's chain values being related to another's.
Chains and the public key
Walking chain i for n steps from step s applies F with step numbers s, s+1, …, s+n−1. The end of chain i is the secret walked all 255 steps (steps 0 to 254). The one-time public key of index k is the 26 ends, and the vault stores its hash:
pk_hash[k] = SHA-256( "TWOKEY/v1/PK" ‖ vault ‖ k ‖ end_0 ‖ end_1 ‖ … ‖ end_25 )
The input is 12 + 32 + 8 + 624 = 676 bytes. Computing one public key costs 26 × 255 = 6,630 F-hashes. The client computes key k+1's hash for every withdrawal, because the intent must name it.
Message digits
digest = SHA-256( "TWOKEY/v1/MSG" ‖ intent ) (input 13 + 193 = 206 bytes)
m_0..23 = digest[0..24] (one digit per byte)
checksum = Σ (255 − m_i) (0 to 6,120)
d = m_0 … m_23, checksum / 256, checksum mod 256
Signing and verifying
- Signature element i is chain i walked d_i steps from its secret (steps 0 to d_i − 1). Elements are concatenated in chain order, 24 bytes each.
- Verification walks element i from step d_i to the end (255 − d_i steps), hashes the 26 ends with the PK prefix and compares the result with the
pk_hashstored in the vault. The program does exactly this inverifyWots, then requires equality, elseBadSignature(6005).
A signature reveals step d_i of every chain. Without the checksum, a signature of one message would let anyone sign any message with larger digits by hashing forward. The checksum goes down when message digits go up, which rules that out: for any two intents with different digits, the second is strictly lower than the first on some chain (theorem wots_no_domination). That is also why a key must sign only one intent: two signatures with different digits reveal the minimum of both on each chain.
What the proofs say about the scheme
| Theorem | Statement |
|---|---|
wots_complete | An honest signature of any intent verifies under the public key it was made with. |
verifySteps_eq | The verifier computes Σ (255 − d_i) hashes, which always equals 255 × (⌊checksum / 256⌋ + 2). |
verifySteps_bounds | That number is between 510 and 6,375. |
wots_no_domination | If two intents have different digits, the second has a digit strictly below the first's on some chain. |
None of these assume anything about SHA-256. That nobody can forge a signature without the seed is the hash assumption, which the proofs do not and cannot establish. See Trust boundaries.
Cost
The verifier's work depends only on the checksum's high byte: 255 × (⌊checksum / 256⌋ + 2) chain steps, plus the message digest and the final public-key hash. packages/core estimates about 158 compute units per chain step (one sol_sha256 of 109 bytes and the loop around it), measured in LiteSVM, and sets the transaction's compute-unit limit from the intent: min(1,400,000, ⌈(fixed + steps × 158) × 1.05⌉ + 2,000), with a fixed part of 3,400 (SOL withdrawal, close vault), 7,000 (token withdrawal) or 6,500 (close token account).
Measured in LiteSVM 1.6.3 (Agave 4.x, sBPF v3), program/release/program.json:
| Case | Chain steps | Compute units |
|---|---|---|
WithdrawSol, 13 runs | 3,060 to 4,080 | 486,660 to 647,820 (average 542,446) |
WithdrawSol, worst of 4,000 random intents | 4,845 | 768,690 |
WithdrawSol, extrapolated to 6,375 steps | 6,375 | 1,010,392 (an extrapolation from the worst measured run, not a measurement) |
WithdrawToken, SPL Token | 3,570 | 568,645 |
WithdrawToken, Token-2022 | 3,315 | 530,284 |
CloseTokenAccount, SPL Token | 2,550 | 407,339 |
CloseTokenAccount, Token-2022 | 3,570 | 569,960 |
CloseVault | 3,315 | 526,949 |
| Refused for a bad signature | 566,934 |
The verifier runs the full computation before comparing, so a wrong signature costs as much as a right one. The LiteSVM test "worst-case verification fits the compute limit" sends the worst of 4,000 intents with the limit set to 1,400,000.
Sizes
| Item | Bytes |
|---|---|
| Intent | 193 |
| WOTS+ signature | 624 |
WithdrawSol instruction data | 665 |
WithdrawToken instruction data | 666 |
CloseTokenAccount / CloseVault instruction data | 657 |
Whole transaction, WithdrawSol (as measured) | 942 |
Whole transaction, WithdrawToken (as measured) | 1,042 |
Test vectors
program/release/vectors.json holds, from the Lean specification: the tags, little-endian encodings, SHA-256 of "" and "abc", f_example, keys 0 to 2 of a test seed (two chain secrets, two chain ends and pk_hash each), and five complete intents (SOL withdrawal, token withdrawal, close token account, close vault, and a SOL withdrawal of 2^64 − 1 lamports) with their encoding, digits, checksum, step count and signature. packages/core must reproduce every byte (bun test), and the compiled program must accept the Lean signature and reject it for another amount or with one byte changed (program/tests/vectors.test.ts).