Skip to content
Lean Key
Reference

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

ParameterValueMeaning
HashSHA-256On chain through the sol_sha256 syscall; in Lean, lean-svm's FIPS 180-4 implementation checked against NIST vectors.
n24 bytesLength of every chain value (the first 24 bytes of a SHA-256 digest).
w256One digit per byte: digits run 0 to 255.
Message digits24The first 24 bytes of the message digest.
Checksum digits2Σ (255 − m_i) over the 24 message digits, at most 6,120, written as two base-256 digits, high byte first.
Chains2624 + 2.
Steps per chain255A chain runs from its secret (step 0) to its end (after step 254).
Signature624 bytes26 chain values of 24 bytes.
Public key hash32 bytesSHA-256 of the 26 chain ends with a prefix; this is what the vault stores.
Seed32 bytesRandom; backed up as 24 words.

Domain tags

Every hash input starts with an ASCII tag (program/Twokey/Spec/Bytes.lean):

TagBytesHex
TWOKEY/v1/F1154574f4b45592f76312f46
TWOKEY/v1/SK1254574f4b45592f76312f534b
TWOKEY/v1/PK1254574f4b45592f76312f504b
TWOKEY/v1/MSG1354574f4b45592f76312f4d5347
TWOKEY/v1/INTENT1654574f4b45592f76312f494e54454e54

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:

OffsetSizeField
011TWOKEY/v1/F
1132program id
4332vault address
758key index k, u64 LE
831chain i
841step j
8524chain 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_hash stored in the vault. The program does exactly this in verifyWots, then requires equality, else BadSignature (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

TheoremStatement
wots_completeAn honest signature of any intent verifies under the public key it was made with.
verifySteps_eqThe verifier computes Σ (255 − d_i) hashes, which always equals 255 × (⌊checksum / 256⌋ + 2).
verifySteps_boundsThat number is between 510 and 6,375.
wots_no_dominationIf 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:

CaseChain stepsCompute units
WithdrawSol, 13 runs3,060 to 4,080486,660 to 647,820 (average 542,446)
WithdrawSol, worst of 4,000 random intents4,845768,690
WithdrawSol, extrapolated to 6,375 steps6,3751,010,392 (an extrapolation from the worst measured run, not a measurement)
WithdrawToken, SPL Token3,570568,645
WithdrawToken, Token-20223,315530,284
CloseTokenAccount, SPL Token2,550407,339
CloseTokenAccount, Token-20223,570569,960
CloseVault3,315526,949
Refused for a bad signature566,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

ItemBytes
Intent193
WOTS+ signature624
WithdrawSol instruction data665
WithdrawToken instruction data666
CloseTokenAccount / CloseVault instruction data657
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).

Connect a wallet

Your wallet signs as the owner (Key A). Lean Key adds the post-quantum key (Key B).

Wallets

Any wallet that supports the Solana Wallet Standard appears under Installed. Lean Key never asks for your seed phrase on this site.