Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

leanSPHINCS smart accounts

Three ERC-4337 smart accounts modeled on eth-infinitism's SimpleAccount (develop branch, EntryPoint v0.9). In all three, the ECDSA owner is replaced by a leanSPHINCS public key: a post-quantum, stateless, hash-based signature scheme over Keccak-256.

Variant Contract What it adds
1. Single key LeanSphincsSimpleAccount + factory SimpleAccount with a leanSPHINCS owner key
2. Dual key LeanSphincsDualKeyAccount + factory Variant 1 plus an optional ECDSA key. Either key has full control, and the owner can disable the ECDSA key at any time
3. Frame-ready LeanSphincsFrameAccount + factory Variant 1, and also a sender of EIP-8141 frame transactions. No upgrade is needed when 8141 ships or when leanSPHINCS is enshrined

Not audited. The verifier is hand-written EVM assembly, so treat this as a prototype.

The scheme: pinned to EIP-8141

EIP-8141 (lightclient/EIPs at 040e94a488a536414436b5a574ccca9355f088ce) enshrines leanSPHINCS as LEANSPHINCS_VERIFIER. It defines the scheme as the Cryptography/Sphincs module of ethereum/EthLib at commit f0e41b61ed6349f7ae35e8a4528c7da847bf27a8. All three accounts use exactly that scheme, so the key and the signature bytes that sign a UserOperation today are the same ones a frame transaction carries later.

Public key 32 bytes, PK.seed (16) ‖ PK.root (16)
Signature 7,740 bytes
Hash Keccak-256 truncated to 16 bytes, FIPS 205 32-byte addresses
Structure FORS (24 trees of height 10), then a 3-layer hypertree (heights 8, 8, 10) with WOTS+C (w = 4, 64 chains, target sum 128)
Rated use 2^30 signatures per key (EIP-8141, "leanSPHINCS Signature Limit")

Verifier (src/LeanSphincsVerifier.sol):

  • I transcribed it from the Lean definitions. It is not derived from nconsigny/SPHINCS-: that repository's verifiers implement an earlier EthLib draft and fail the f0e41b61 vectors.
  • The core is LeanSphincsVerification._leanSphincsVerify. Two contracts expose it:
    • LeanSphincsProofVerifier is the one the accounts use. Its input is key ‖ msg ‖ signature with no selector, and the call succeeds iff the signature is valid. That is exactly the contract-verifier interface of an EIP-8141 PROOF frame. It uses no state, context or call opcodes, so it runs in the PROOF frame's pure context; a test scans its bytecode for this.
    • LeanSphincsVerifier offers verify(bytes32 pk, bytes32 msg, bytes sig) → bool as a convenience view for other callers.

Reference signer (signers/leansphincs-ethlib/leansphincs.py):

  • A Python port of EthLib f0e41b61 (keygen, sign, verify). The tests call it over vm.ffi.
  • It passes all 35 of EthLib's own vectors (python3 test_vectors.py; the vectors are copied from EthLib at that commit).
  • It is for tests only: it takes the seed on the command line.

Variant 1: LeanSphincsSimpleAccount

It keeps SimpleAccount's structure: BaseAccount, execute/executeBatch, EntryPoint deposit helpers, token callbacks, a UUPS proxy per account, and a SenderCreator-gated CREATE2 factory.

What changes:

  • Owner = leanSPHINCS public key (one storage slot). userOp.signature is the raw 7,740-byte signature over userOpHash.
  • Verification: _validateSignature staticcalls the shared LeanSphincsProofVerifier with pk ‖ userOpHash ‖ sig.
    • A wrong-length or invalid signature returns SIG_VALIDATION_FAILED; it never reverts.
    • The constructor refuses a verifier address with no code, since a call to an empty address would "succeed".
  • No owner EOA:
    • execute/executeBatch are EntryPoint-only.
    • Owner-only functions (withdrawDepositTo, upgrades, rotateOwnerKey) require msg.sender == address(this), which means a validated UserOperation calling back into the account.
  • rotateOwnerKey(bytes32) is new. A key has a signature budget, so moving to a fresh key without redeploying is useful.

Variant 2: LeanSphincsDualKeyAccount

It extends variant 1 with address ecdsaOwner (storage slot 1). A LeanSphincsSimpleAccount can therefore be upgraded in place to it; a test covers this.

  • Choosing the key per UserOperation: a 65-byte signature is ECDSA (r ‖ s ‖ v, checked with ECDSA.tryRecover, so malformed input fails instead of reverting). Anything else goes to leanSPHINCS.
  • ECDSA is optional at creation. createAccount(pk, ecdsaOwner, salt) takes address(0) for none, and the address commits to both keys.
  • Either key has full access. As in SimpleAccount, the ECDSA key can also act directly as an EOA (execute, executeBatch, and the owner-only functions).
  • disableEcdsaOwner() can be called by the owner at any time: either key, through a UserOperation or directly.
    • Disabling is permanent.
    • A UserOperation the ECDSA key already signed fails validation once the key is disabled.

Security note. "Either key gives complete access" includes the ECDSA key replacing the leanSPHINCS key or upgrading the account. Until the ECDSA key is disabled, the account is only as strong as ECDSA. Disabling it is what makes the account post-quantum.

Variant 3: LeanSphincsFrameAccount (EIP-8141 forward compatible)

It is variant 1, unchanged on the ERC-4337 path, plus the pieces a frame-transaction sender needs. The account and its address are the same on both paths.

  • VERIFY frame: the frame calls the account from ENTRY_POINT (0xaa) with empty data, which lands in receive(). The account DELEGATECALLs a tiny Yul helper, src/frame/LeanSphincsFrameVerify.yul. Solidity cannot emit TXPARAM, FRAMEPARAM, HASCLAIM or APPROVE; this is the same pattern as the EIP's CanonicalPaymasterPay.yul. The helper:
    1. Walks the leading PROOF frames and looks for a claim (verifier, storedPublicKey, TXPARAM(0x08)) from a verifier the account trusts:
      • the enshrined LEANSPHINCS_VERIFIER. Its address is still TBD in the spec, so the helper recognizes it by range: the EIP-1352 precompile range, outside the RIP range 0x100–0x1ff. The spec puts protocol verifiers there, and nothing else in that range can make a claim hold: a PROOF frame to an empty account or to a precompile halts.
      • proofVerifier, the same LeanSphincsProofVerifier the 4337 path uses. Frame transactions therefore work from day one of 8141, before leanSPHINCS is enshrined.
    2. Calls APPROVE with the scope the frame's flags allow: self_verify 0x3, only_verify 0x2, or 0x1 to pay for another sender.
  • SENDER frames act as the account. They can call any target, or the account itself: execute/executeBatch and the owner-only functions accept msg.sender == address(this).
  • Deploy frame: the factory also accepts ENTRY_POINT as caller. On that path it skips the "already deployed" EXTCODESIZE check, because the mempool rules let a deploy frame touch only tx.sender.
  • Key rule: a key whose top 96 bits are zero is refused. The secp256k1 and P-256 protocol verifiers take a left-padded address as key, so this rule means their claims can never match. A random key hits it with probability 2^-96.

What a frame transaction looks like (EIP Example 4):

[PROOF  → LEANSPHINCS_VERIFIER, data = pk ‖ 0 ‖ signature(7740)]   (msg 0 = canonical sig hash)
[DEFAULT → factory.createAccount(pk, salt)]                            (first transaction only)
[VERIFY → sender, flags 3, empty data]
[SENDER → anything]

How it is tested without an 8141 client. test/frame/emulate.py derives an emulator build of the helper:

  • It replaces only the four primitive functions with calls to test/frame/FrameEmulator.sol. Everything else is byte for byte, and the script fails if the primitives section changes.
  • FrameTxSim executes frame lists the way the spec's Behavior section does:
    • PROOF frames are verified first. A contract verifier is called; the enshrined verifier is evaluated natively.
    • DEFAULT and VERIFY frames are called from 0xaa, and SENDER frames from the sender.
    • APPROVE rules are enforced, and the transaction is invalid without a payer.
  • The canonical signature hash (an RLP of the elided transaction) is replaced by a stand-in hash. The account only sees it through TXPARAM(0x08).
  • Separately, tests check that the real helper contains TXPARAM/FRAMEPARAM/HASCLAIM/ APPROVE and no state or call opcodes, and that it halts outside a frame transaction.

Statelessness

leanSPHINCS is stateless: the signer keeps no counter or used-leaf index. Signing is deterministic (R = PRF_msg(SK.prf, PK.seed, M)), so one key can sign from several devices or a restored backup with no coordination. There is no catastrophic "reused one-time key" failure as with XMSS/LMS. On chain, the accounts keep no signature state at all, just the 32-byte key.

The limit is statistical. Each distinct message reuses one of the key's few-time FORS instances, and security degrades slowly past 2^30 signatures per key. Nothing on chain counts. A wallet that signs a lot should rotate (rotateOwnerKey) well before that.

Gas

Every number below comes from these scripts:

  • script/gas-report.sh: real transactions on anvil, so receipt gasUsed includes intrinsic gas and the calldata floor. validateUserOp is the account's call, from a callTracer trace. Hardfork Bpo1, so the EIP-7623 calldata floor applies.
  • script/verify-frame-gas.sh: a VERIFY-frame trace.
  • script/frame-tx-gas.py: the EIP-8141 gas formulas.

Verification alone

execution gas
LeanSphincsProofVerifier (used by all three accounts and PROOF frames) 98,624
LeanSphincsVerifier.verify() (ABI view helper) 111,188
EIP-8141 enshrined LEANSPHINCS_VERIFIER (spec constant) 13,200

ERC-4337, one UserOperation per handleOps (anvil receipts)

Account deploy + transfer transfer validateUserOp calldata
V1 single-key 480,504 339,190 123,664 8,452 B
V2 dual-key, leanSPHINCS signature 504,895 339,340 123,892 8,452 B
V2 dual-key, ECDSA signature 280,593 93,847 23,348 804 B
V3 frame-ready (4337 path) 480,708 339,340 123,692 8,452 B
ECDSA SimpleAccount (baseline) 256,321 93,392 23,100 804 B

How to read this:

  • A leanSPHINCS transfer costs about 3.6× an ECDSA one.
    • It is bound by the calldata floor: 8.45 KB × 40 gas ≈ 338K.
    • The roughly 100K of verification is effectively free under that floor: execution, about 270K, stays below it.
    • So shrinking calldata is what would lower the cost, not optimizing the verifier.
  • validateUserOp breaks down as 98.6K of verification plus about 25K: a cold call to the verifier, the calldata copy, the account's SLOAD, and the prefund that every account pays.
  • Variant 2's extra code adds about 230 gas to validateUserOp.
  • An ECDSA-signed operation on variant 2 costs within 0.5% of plain SimpleAccount.
  • Deploying costs about 141K over a transfer, compared with 163K for ECDSA SimpleAccount. The first UserOperation's floor-bound calldata absorbs part of the proxy deployment. V2 deploys cost 24K more because they store the ECDSA owner: both V2 rows create the account with an ECDSA key.

EIP-8141 frame transaction (variant 3; estimates from the spec's formulas)

The VERIFY frame, account side, is about 10.6K. The trace measures 15,740; the emulator's own share is removed to get 10.6K. That share is its code (1,583), its 7 calls (3,200), and about 350 of the helper's calldata setup for those calls.

For a plain ETH transfer [proof, self_verify, user_op]:

enshrined verifier contract verifier (before enshrinement)
intrinsic (proof data priced as non-zero: 124,480) 143,905 143,905
frame execution (proof + verify + transfer) 26,500 114,524
standard total 170,405 258,429
calldata floor (EIP-7976: 64 gas/byte) 518,881 518,881
gas_used 518,881 518,881
validation prefix vs MAX_VERIFY_GAS (100,000) 23,900, public mempool OK 111,924, over: private mempool / direct to builder

How to read this:

  • Frame transactions are floor-bound too.
  • Under the same EIP-7976 pricing, a 4337 handleOps with one leanSPHINCS UserOperation would cost 561,928. So frames are about 8% cheaper, and they skip the bundler.
  • Before enshrinement, the contract-verifier path is valid but exceeds the public-mempool verification cap.

Open design choices

  1. Trusting the enshrined verifier by address range (variant 3). This is what makes the account work with no upgrade once LEANSPHINCS_VERIFIER gets an address.
    • The cost: the account also trusts any future protocol verifier another EIP adds, as long as it takes a 32-byte key.
    • Such a verifier could only hurt the account if it accepted a proof for a key equal to this account's leanSPHINCS public key without its secret key.
    • The alternative is an owner-settable verifier slot. That is safer against unknown future verifiers, but it needs one transaction once the address is assigned.
  2. The pre-enshrinement contract verifier (variant 3) is pinned in the implementation (immutable) and trusted forever. Removing it later means an upgrade.
  3. ECDSA key semantics (variant 2).
    • Disabling is permanent and cannot be undone without an upgrade. A "re-enable" or "replace ECDSA key" function would be easy to add.
    • The ECDSA key keeps full powers until disabled, including rotating the PQ key.
    • A stricter variant would let ECDSA execute but not rotate or upgrade.
  4. Key choice by signature length (variant 2): 65 bytes means ECDSA, anything else means leanSPHINCS. This is simple and unambiguous, but it rules out other ECDSA encodings (64-byte EIP-2098).
  5. One shared verifier contract. It is immutable per implementation, and changing it requires a UUPS upgrade.
  6. rotateOwnerKey is an addition over SimpleAccount. Key rotation is otherwise only possible by upgrading.
  7. Calldata dominates gas.
    • Options outside this repository: signature aggregation (EIP-8141 "Aggregation"), a compressed signature format, or L2 calldata pricing.
    • The verifier could also get faster. The ABI path is about 12K slower than the fixed-layout path for optimizer reasons. But as shown above, that does not change the receipt cost.

Layout and commands

src/LeanSphincsVerifier.sol            verifier core + LeanSphincsProofVerifier + LeanSphincsVerifier
src/LeanSphincsSimpleAccount.sol       variant 1   (+ Factory)
src/LeanSphincsDualKeyAccount.sol      variant 2   (+ Factory)
src/LeanSphincsFrameAccount.sol        variant 3   (+ Factory)
src/frame/LeanSphincsFrameVerify.yul   VERIFY-frame helper (real EIP-8141 opcodes)
signers/leansphincs-ethlib/            Python reference signer, EthLib vectors, fixture generator
test/                                  Forge tests (41); test/frame/ holds the 8141 emulator
script/                                gas-report.sh, verify-frame-gas.sh, frame-tx-gas.py

Requirements: Foundry with solc 0.8.33, plus Python 3 with pycryptodome.

git submodule update --init
forge test                           # 41 tests; signing goes through the Python signer (cached under cache/)
python3 signers/leansphincs-ethlib/test_vectors.py
python3 test/frame/emulate.py        # after any change to the Yul helper
./script/gas-report.sh && ./script/verify-frame-gas.sh && python3 script/frame-tx-gas.py

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages