Bonsai Measurements ↗ Code ↗

Bonsai

Bonsai is a 160-bit secure SPHINCS variant whose parameters are chosen jointly for blockchain use: safe over a multi-decade horizon, while keeping signatures small, signing practical on hardware wallets, and verification cheap enough to prove in a SNARK.

Read the proposalGitHub ↗

Motivation

Configurations offered by the NIST standard are impractical: the 128-bit sets use hashes that are too short, and the 192-bit sets are too slow on the device or too large.

A unique cost for blockchain settings is that we have to support key generation and signing on constrained devices, namely hardware wallets. These can become prohibitively slow. Meanwhile NIST parameterizes for safety with signature counts far beyond what any blockchain wallet has ever used, so we can afford far lower signature counts. leanSPHINCS is Ethereum's latest take optimizing towards this, with an eye towards optimizing recursive proof costs.

Instead we propose trade-offs targeting a higher security margin and easier wallet UX, at the cost of slightly higher bandwidth and verifier costs.

Security rests on two separate numbers:

Why 160 bits?

Today, based on the published data around Bitcoin's mining, it is estimated that a yearly expenditure of $10 billion produces about 295.6 SHA-2 invocations, split between $8 billion of electricity cost and $2 billion of replenishment ASIC manufacturing.

In parallel, there are numerous reasons to believe that the cost of electricity and the cost of ASIC manufacturing will fall substantially over the coming decades. If you budget an aggressive hundred-thousand-fold improvement over the coming decades, and an attacker budget of $1 trillion in today's dollars per year, this leaves you with an attacker capability of about 2118.9 SHA-2 invocations per year. If you look at a long-term adversary in terms of the percentage of the Sun's energy it can harness, you require more extraordinary buffers. These considerations leave 128-bit security feeling unsatisfactory once a cryptanalytic buffer is considered.

SPHINCS security assumptions
  • Second-preimage security of a truncated hash
  • Distinct-function multi-target second-preimage resistance (DM-SPR)
  • Interleaved target subset resilience (ITSR)

Better-than-brute-force attacks on second-preimage security tend to inherit security from the hash function's full length, as observed with classical hash functions. Any common hash has a very high security margin here, as preimage resistance is far stronger than the collision resistance that bounds the untruncated hash length.

DM-SPR depends upon there being no collisions in the internal chaining state of a hash function, so we must consider the hash function's internal state size. A collision of the internal chaining state is rated at most len(chaining_state_bits) / 2. We have seen notable reductions in collision security before, with SHA-0 having a 41-bit reduction and SHA-1 a 19-bit reduction. This suggests that to have a suitable margin, the internal state must be greater than 256 bits, which with standard hash functions suggests a jump to a 512-bit internal state (SHA-512, SHA-3). This gives a very large cryptanalytic buffer against future improvements, near 100 bits of security margin. The common design pattern within SPHINCS is to only use the larger state size hash where collisions matter, and SHA-256 for the WOTS+C chains and FORS leaves.

ITSR captures the security problem SPHINCS faces as a user produces more signatures. Every signature a public key makes creates more preimage targets that an adversary can aim at to forge a signature. Higher security margins for ITSR increase the protection offered to users who go far beyond the signature limits, and to users who land in an unlucky 99th percentile.

These collectively lead to our suggestion of 160-bit security as the target for Bonsai.

One strong feature of SPHINCS is that its design is intended to protect against multi-user attacks, up to cryptanalytic improvements in hash function attacks.

Hash function choice: SHA-2 and SHA-512

Where security rests on DM-SPR, in the Merkle tree nodes and the hashes that compress a FORS or one-time public key, we use SHA-512 truncated to 20 bytes. Its 512-bit internal state keeps a chaining-state collision far out of reach. Everywhere else we use SHA-256, also truncated to 20 bytes: the one-time chain steps, the FORS leaves and the digit hash. Their input fits in one compression after the public seed's precomputed block, so a collision in SHA-256's 256-bit state gives an attacker nothing. SLH-DSA makes the same split at its 192- and 256-bit levels. The message digest and key derivation also use SHA-512.

Why we suggest SHA-2:

  • It is one of the NIST-standardized options for SLH-DSA (FIPS 205) and already used in Zcash.
  • The faster options are ineligible where it matters. BLAKE3 and hand-optimized BLAKE2s sign slightly faster on the Ledger, but their 256-bit internal state caps DM-SPR at 128 bits, so they could only stand in for SHA-256 in the chains and leaves, and both are outside FIPS 205.
  • BLAKE2b has a 512-bit internal state, but its rated collision resistance covers only the hash as a whole; nothing establishes that its internal state resists collisions any better. It also signs more slowly on the Ledger.
  • SHAKE256 does give that guarantee for its internal state, but it is far slower on the Ledger.
  • SHA-2 is believed faster than Keccak (SHA-3) inside zero-knowledge proofs, which matters for proving signatures in a SNARK.
All options considered
Ledger signing time, relative to SHA-2Two experiments, each against SHA-2 in the same run.

How a signature is built

A FORS forest signs the message. A stack of one-time-key trees, the hypertree, links that forest to the public key.

  1. Pick a position. The message hash, bound to the public key, picks a position and one leaf in each FORS tree.
  2. Sign with FORS. Reveal those leaves and the hashes that rebuild each tree's root.
  3. Climb the hypertree. Each layer signs the root of the layer below.
  4. Reach the public key. The top tree's root is the public key. It is built at key setup: whole on a server, a slice of it on a Ledger.

Point at a part to see its role and its share of the signature.

Breaking down the signature

Two changes to SLH-DSA

Fixed digit sum (WOTS+C)

Problem
The one-time signature in each hypertree layer turns the root below it into digits from 0 to 7 and reveals, for each digit d, a secret hashed d times; anyone can hash once more to turn d into d + 1 and sign a different root, which SLH-DSA prevents with 3 extra checksum digits.
How
Trade-off
Origin
This is WOTS+C, a standard optimization of SPHINCS+ from SPHINCS+C (Hülsing, Kudinov, Ronen and Yogev), presented at NIST's fourth PQC standardization conference. leanSPHINCS uses it as its one-time signature too. It is noted in NIST's process but not part of the NIST standard, FIPS 205.

A whole one-time signatureOne bar per digit; its height is how many times that secret was hashed.

BUFF digest

Problem
Unforgeability says no one can sign a new message under your key. It does not say a signature verifies for only one message and one key, properties that protocols tend to assume. They are known as BUFF properties, for Beyond UnForgeability Features.
How
Every signature carries a 48-byte hash of the message and the public key, and the verifier recomputes it. The signature then binds exactly one message to exactly one key.
Trade-off
48 bytes on every signature.

Two profiles

Hash-based signatures have a lifetime: every signature reveals a little of the key's secrets, so past a certain number of signatures a key's security slowly degrades. Set the lifetime too short and active users are at risk. Set it too long and every signature grows, a cost that every user and every node carries.

Pruning trades part of a key's lifetime for speed on the device, which suits regular users, who sign rarely. So one layout serves two profiles: a regular wallet for everyday users, on a hardware device, pruned for a modest lifetime, and a custody wallet for exchanges, miners and funds, on a server, unpruned for a long one. Their signatures have the same size, and the same verifier can handle both.

How both profiles were measured

How pruning works

Regular covers every unlabelled Zcash key

Security as a key signs moreDots are real keys, on the curve of the profile that covers them. Press one for details.

Labelled keys are attributed to a known organization, such as an exchange, mining pool or fund. Unlabelled keys are not, so the most used of them stands for the busiest ordinary wallet.

All keys measured

Past a profile's lifetime

Choosing the layout

We search the layout options by setting the following constraints:

Among the layouts that pass, bytes and verifier work are weighed at 2:1: a signature 10% smaller is worth 20% more verifier hashing, since every node relays and checks every signature. The table's last column is that cost against the pick: the change in bytes plus half the change in verifier hashes.

The layouts no other layout beatsA layout stays when no other is at least as good on bytes, verifier work, regular lifetime and signing time, and better on one.

Running the search…

How layouts were screened

Ledger time adds 0.66 s per signature, 0.56 ms per FORS leaf, 42.2 ms per lower-layer one-time key, 1.14 ms per randomizer try and an assumed 0.1 ms per counter try, then anchors the result to the 19.68 s 90th percentile measured on an earlier four-layer layout. The 90th percentile takes 2.3 times the mean for randomizer tries and 1.67 to 1.94 times for counter tries. Counter odds are exact, for 54 chains or for 53 with a zero top digest bit, and a one-time key costs 53/54 as much with 53 chains.

On x86-64 a one-time key costs 196 µs on one core without SHA-NI (62 µs with it), and key setup runs 3.9 times faster on 4 vCPUs, all measured.

A regular wallet may also prune up to 2 bits of each lower layer; that changes nothing it or the verifier does, so the search moves top bits down only until custody key setup is within 5 s. FORS security uses the FORS reuse model, averaged over signing randomness. Verifier work counts hash blocks, a SHA-512 block weighing 1.7 SHA-256 blocks.

Alternatives

leanSPHINCS is built for Ethereum, where signatures are aggregated into one proof and never sent to the chain on their own. Zcash relays every signature, so signature size matters more.

Even at our 160-bit width, it is larger and slower to set upAgainst the regular profile, the one that runs on the same device.

SPHINCS-G