项目的 README,来自 github.com/QuipNetwork/hashsigs-solidity。合并为一个 markdown 文件:README.md。
Verifier-oriented Solidity implementations of hash-based signature schemes: the WOTS+ one-time signature scheme and the SHRINCS hybrid stateful/stateless construction.
The production contracts in contracts/ cover on-chain
verification only. Signer-side recovery state, seed restore logic, and
wallet lifecycle management are out of scope; test-only Solidity signer
helpers live under test/helpers/ and are not
deployable.
Citation keys follow CODINGSTANDARDS.md §1.
[WOTSPLUS] (A. Hülsing,
W-OTS+: Shorter Signatures for Hash-Based Signature Schemes,
AFRICACRYPT 2013; https://eprint.iacr.org/2017/965). Keccak-256,
32-byte hashes and messages, Winternitz parameter w = 16, 67 chains
(64 message + 3 checksum). Standalone, with no SHRINCS dependency.
The public API (verify, verifyWithRandomizationElements, sign,
generateKeyPair, generateRandomizationElements, chain, and the
public constants) is stable and vector-tested; the signer-side
helpers are reference code, documented "do not use on-chain."[SHRINCS], specified in the
appendix of Hash-based Signature Schemes for Bitcoin, Cryptology
ePrint Archive 2025/2203 (https://eprint.iacr.org/2025/2203).
Compiled per profile (see Profiles):256s (default) — keccak-256, 32-byte hashes, h = 64, d = 8,
a = 14, k = 22, 64 WOTS-C chains, 2^20 stateless budget.
Reviewed and anchored to Rust-generated signature vectors.128s-q18 (experimental) — 16-byte truncated hashes, single-layer h = 18
hypertree, a = 24, k = 6, 32 WOTS-C chains, 2^18 stateless
budget. Anchored to Rust-generated signature vectors; the stateless
path is verified against them by SHRINCSSphincs128sVectors.128s-q20 (experimental) — as 128s-q18 with a 2^20 stateless budget; shares the
128s vectors except the profile-bound commitment.[SPHINCSPLUSC] (M. Kudinov,
A. Hülsing, E. Ronen, E. Yogev, SPHINCS+C: Compressing SPHINCS+ With
(Almost) No Cost, Cryptology ePrint Archive 2022/778, IEEE S&P 2023;
https://eprint.iacr.org/2022/778). SHRINCS uses it as the stateless
recovery path: a FORS-C few-time signature carried up a hypertree of
WOTS-C layers to the public root. Deployed per profile as
SPHINCSPlusC256sKeccak, SPHINCSPlusC128sQ18Keccak, and
SPHINCSPlusC128sQ20Keccak; each SHRINCS verifier delegates its
stateless path to the matching profile sibling.SHRINCS is a two-path signature design:
WOTS-C plus an unbalanced XMSS-style authentication pathFORS-C + hypertree + WOTS-C structureNormal operation uses the cheaper stateful path. A restored or degraded
signer falls back to the stateless path. The verifier only checks signatures
and rotation authorizations; it does not track signer state. The ERC-7913
verifiers here cover both paths: each SHRINCS verifier exposes the stateful
verify plus a verifyStateless that delegates to a pinned SPHINCS+C
sibling, and the standalone SPHINCS+C verifiers check the stateless recovery
path directly. Each SHRINCS verifier also exposes verifyAndAttest /
wasVerified: a successful verifyAndAttest records the verification for
the calling account in EIP-1153 transient storage, so downstream contracts
in the same transaction can query it instead of burning another one-time
leaf on a fresh signature.
Main contracts:
verify
plus verifyStateless delegating to the pinned SPHINCSPlusC sibling,
and the transient attestation surface (verifyAndAttest /
wasVerified)shrincs-hash/ remapping axisWOTS-C reconstruction and unbalanced XMSS-style path
verificationFORS-C digest extraction and root reconstructionWOTS-C and hypertree layer verificationWOTS+C chain machinery used by the hypertree and UXMSSFORS-C + hypertree +
WOTS-C to the public root)PROFILE_TAG;
each pins its SPHINCS+C sibling for the stateless pathPROFILE_TAGSHRINCSParams constant libraries (see
Profiles)verifyAndAttest / wasVerified), including the
shared transient-slot spec consumers deriveWOTS+ verifier (see
Implementations)IERC7913SignatureVerifier.verify(...) flow: stores a verifier address
plus opaque key bytes and treats the verifier as a pure signature-validity
oracleverifyStateless(...) path on the concrete verifier surfaceDeployment and tooling:
Architecture:
graph TD
subgraph "Integrator layer (example)"
EX["SHRINCSAccountVerifierExample.sol<br/>(contract — owner, policies, nonce,<br/>keyVersion, q_s budget, stateful-use tracking)"]
end
subgraph "ERC-7913 verifiers"
VF["SHRINCSVerifier.sol (abstract base)<br/>+ SHRINCS256sKeccak / 128sQ18Keccak / 128sQ20Keccak<br/>(stateful verify + verifyStateless)"]
SP["SPHINCSPlusCVerifier.sol (abstract base)<br/>+ SPHINCSPlusC256sKeccak / 128sQ18Keccak / 128sQ20Keccak<br/>(stateless recovery path)"]
end
subgraph "Verification core libraries"
FA["SHRINCS.sol<br/>stateful + stateless verify-in-place,<br/>canonical action + rotation hashes"]
SC["SPHINCSPlusC.sol<br/>stateless FORS-C + hypertree<br/>-> public root"]
end
subgraph "Crypto component libraries"
ST["UXMSS.sol<br/>compact WOTS-C digits +<br/>unbalanced-XMSS auth path<br/>(cheap normal-case path)"]
FO["FORSMinusC.sol<br/>FORS-C digest, grind checks,<br/>k−1 tree-root rebuild -> forsRoot"]
HY["Hypertree.sol<br/>d=8 XMSS layers, stateless WOTS-C,<br/>Merkle paths -> hypertreeRoot"]
WC["WOTSPlusC.sol<br/>shared WOTS+C chain machinery"]
end
subgraph "Foundation"
HS["hash/keccak/HashSuite.sol<br/>tagged scheme hashes<br/>(shrincs-hash/ suite seam)"]
HH["Hash.sol<br/>hash + bit primitives,<br/>address-word packing<br/>(never remapped)"]
PA["profiles/<profile>/SHRINCSParams.sol<br/>(profile-selected constants)"]
end
WP["WOTSPlus.sol<br/>(standalone library —<br/>no SHRINCS dependency)"]
EX --> FA
EX --> SC
EX --> PA
VF --> FA
VF -. stateless delegate .-> SP
SP --> SC
FA --> ST
FA --> SC
FA --> PA
FA --> HS
SC --> FO
SC --> HY
ST --> WC
ST --> HS
ST --> PA
FO --> HH
FO --> HS
FO --> PA
HY --> WC
HY --> HS
HY --> PA
WC --> HS
HS --> HH
HH --> PA
Tests (29 suites, 266 tests as of 2026-07-13, ci profile):
abi.decode over every
vector and fuzzed well-formed envelope, and that malformed envelopes
(wild offsets, truncation, aliasing) land in revert or false through
the full verify pathfalseSHRINCSParams profileWOTS+ testsTest vectors:
The SHRINCS public key (SHRINCS.PublicKey) contains:
statefulPublicKeypublicKeyCommitmentpkSeedhypertreeRootThe stateless side follows the SPHINCS-style PK = (PK.seed, PK.root)
abstraction ([SPHINCSPLUS §5], [FIPS205 §9.1]):
pkSeed is the global public seed used by FORS and the hypertreehypertreeRoot is the stateless public rootpublicKeyCommitment binds the full hybrid bundle together. The verifier
checks that:
publicKey.publicKeyCommitment matches the commitment recomputed fromstatefulPublicKeypkSeedhypertreeRootThis keeps the hybrid stateful/stateless public key coherent while preserving the SPHINCS-style stateless core.
SHRINCS verifies signatures in place over calldata. No production verify
path copies the envelope or calls abi.decode, and no path walks the
envelope for canonicity.
Each verifier re-tags the calldata: it reads the ABI head offsets of the
opaque signature argument and points calldata-typed structs at the
signature fields where they already sit. The signature is then verified
directly from those fields. The one copy in the system is the stateless
delegation payload, which the SHRINCS verifier builds by slicing the
re-tagged signature region and forwarding it to its SPHINCS+C sibling.
The re-tag is sound because of two mechanisms:
docs/guard-applicability-review.md) pins the field lengths that the
hash construction depends on — the public-key field split, the WOTS key
windows, and the shape and count checks that the reconstruction loops
read.Together these turn every malformed envelope into a revert or a false
return. See Revert model for the caller-visible
behavior.
The verify paths distinguish two failure classes:
0xffffffff from the ERC-7913 and ERC-1271 paths, or false
from the library entry points.Acceptance widened from the earlier canonicity-walk model: any calldata
framing whose in-place field reads reproduce a valid signature's field
values now verifies. The verifier no longer requires the byte-exact
canonical encoding. This is a superset of what abi.decode tolerates:
the re-tagged reads are bounds-checked against calldatasize (the whole
transaction calldata), not the envelope slice, so a read may extend into
adjacent calldata such as the outer ABI zero-padding. Under masked-hash
(128s) profiles the low bytes of each hash node are zero, so a
tail-truncated envelope that abi.decode would reject reads its stripped
tail back from that padding and still verifies. Acceptance never reaches
a wrong-accept: accepted reads always equal a valid signature's exact
field values. One qualification applies to the stateless delegation
path: it slices a bounded signature region before forwarding it to the
SPHINCS+C sibling, so a framing that reproduces those fields only by
reading out into adjacent calldata can revert or return false at the
sibling rather than verify there.
Malleability caveat. Because these field-value-equivalent framings all verify, an external consumer that keys, caches, or deduplicates on the raw signature bytes can see two distinct byte strings that both verify for the same message. Consumers that need a single canonical byte form must re-encode the signature themselves before keying on it. Nothing in this repository keys on raw signature bytes; the wrapper's replay protection binds the message and account state, not the signature encoding.
flowchart LR
subgraph "Stateful path (normal case)"
A1["action context<br/>(domain, nonce, keyVersion,<br/>actionType, payloadHash)"] --> A2["statefulActionMessageHash"]
A2 --> A3["validate expected<br/>public root"]
A3 --> A4["recompute compact WOTS-C<br/>pk hash from 64 chains<br/>(target-sum 480 check)"]
A4 --> A5["fold unbalanced-XMSS<br/>auth path"]
A5 --> A6{"== stateful root?"}
end
subgraph "Stateless path (fallback / rotation authorization)"
B1["action or rotation<br/>message hash"] --> B2["validate public key +<br/>public root"]
B2 --> B3["FORS-C: digest, omitted final<br/>tree leaf == 0, rebuild 21 tree<br/>roots → fors-pk root"]
B3 --> B4["forsRoot"]
B4 --> B5["8 hypertree layers:<br/>WOTS-C verify + Merkle path,<br/>root chains upward"]
B5 --> B6{"== hypertree root?"}
end
Each verifier has two forms:
ActionContextverifyStatefulUncheckedMessage,
verifyStatelessUncheckedMessage) that verifies caller-supplied message
bytes directly; the ERC-7913 verifier and the tests use itSHRINCS.verifyStateful(expectedPublicKeyCommitment, publicKey, actionContext, signature)
verifyStateful(...) computes a canonical hash from ActionContext:
domainSeparatornoncekeyVersionactionTypepayloadHashpayloadHash should be the hash of a typed action payload. This path does
not accept free-form account-operation bytes.
The canonical path rejects invalid contexts:
expectedPublicKeyCommitment == 0domainSeparator == 0actionType == 0payloadHash == 0Both forms verify:
expectedPublicKeyCommitment matches
publicKey.publicKeyCommitmentWOTS-C reconstructionSHRINCS.verifyStateless(expectedPublicKeyCommitment, publicKey, actionContext, signature)
verifyStateless(...) computes the same canonical ActionContext hash and
applies the same context rejections as the stateful path.
Both forms verify:
expectedPublicKeyCommitment matches
publicKey.publicKeyCommitmentFORS-CWOTS-CDesign note — hypertree coordinate derivation. SHRINCS derives the
hypertree tree/leaf coordinates sequentially per layer rather than following
the [FIPS205 §8.2] index recurrence. The FORS digest fixes layer 0's
coordinate; each upper layer's leaf index is the low
HYPERTREE_HEIGHT / NUM_HYPERTREE_LAYERS bits of the layer below's tree
index, and its tree index is the remaining high bits.
Hypertree.verifyHypertree derives these coordinates and the test signer
follows the same recurrence, so a signature cannot choose independent
upper-layer addresses. The coordinates are not carried in the signature:
the verifier seeds layer 0 from the FORS digest and derives every upper
layer, making the derived value the sole coordinate input (the pre-T6
carried treeIndex/leafIndex fields were removed with the vector
regeneration). This is a deliberate, documented departure from FIPS 205
(marked Deviates from [FIPS205 §8.2]: in the code); do not change either
side toward the FIPS recurrence without regenerating all vectors.
SHRINCS.rotateStatefulViaStateless(
expectedPublicKeyCommitment,
currentPublicKey,
rotationContext,
recoverySignature,
nextStatefulKey
)
This is a verifier-side authorization helper, not signer recovery logic.
It:
expectedPublicKeyCommitmentcurrentPublicKey.publicKeyCommitmentrotationContextnextStatefulKey.publicKeyCommitmentmaxSignatures == 0domainSeparatorbytes32(0) on failureSHRINCS.statelessRotate(
expectedPublicKeyCommitment,
currentPublicKey,
rotationContext,
recoverySignature,
nextKey
)
This verifies a stateless recovery signature authorizing a full next SHRINCS key bundle.
It:
expectedPublicKeyCommitmentcurrentPublicKey.publicKeyCommitmentrotationContextnextKey.publicKeyCommitmentmaxSignatures == 0domainSeparatorbytes32(0) on failureThe example wrapper exposes:
isValidSignature(bytes32 hash, bytes signature) external view returns (bytes4)
This adapter is limited to canonical account-action envelopes. It is not a generic raw SHRINCS verifier.
Supported envelope modes:
0x01 || abi.encode(publicKey, actionType, payloadHash, statefulSignature)0x02 || abi.encode(publicKey, actionType, payloadHash, statelessSignature)The adapter:
0xffffffffActionContext from wrapper-owned statedomainSeparator()noncekeyVersionhash matches the current canonical action hash for that modeImportant semantics:
nonce,
keyVersion, policy state, or key state changes0xffffffff0xffffffff; malformed envelope bytes and any execution
failure, including out-of-gas, revert. A valid signature is never
reported invalid. Callers must forward gas comfortably above the
measured figures in Gas measurements.This repository also includes a standalone ERC-7913 verifier for the raw stateful SHRINCS path.
verify(bytes key, bytes32 hash, bytes signature) → bytes4
publicKeyCommitment.abi.encode(PublicKey, StatefulSignature), the
SHRINCS stateful envelope.verify(...) calls, returns 0x024ad318 on success and
0xffffffff on verification failure or a wrong-length key. Malformed
envelope bytes revert: the verifier re-tags the calldata in place, and
offsets or lengths that fall outside the calldata bounds fail the
solc-generated access check rather than being reported as an invalid
signature.The envelope fields are:
PublicKey = (statefulPublicKey, publicKeyCommitment, pkSeed, hypertreeRoot)StatefulSignature = (randomizer, counter, chains, authPath)The ERC-7913 verifier is intentionally narrow:
VERSION_TAG constant identifying its key/envelope format
family, and each deployable subclass adds a PROFILE_TAG identifying
its compiled parameter setMinimal consumer-side examples:
IERC7913SignatureVerifier.verify(...)SHRINCSVerifier address and key bytesverifyStateless(...) on that verifier directlyThese examples are intentionally thin:
keyVersion, stateful-leaf tracking, or rotation
stateisAuthorized/isAuthorizedStateless path normalizes verifier
reverts (including out-of-gas) to false; requireAuthorized/
requireAuthorizedStateless bubble themConcrete consumer flow:
SHRINCS256sKeccakpublicKeyCommitmentIERC7913SignatureVerifier(verifier).verify(key, hash, signature)verifier and key and exposes
isAuthorized(hash, signature)SHRINCSVerifier itself is an abstract base; the deployable contracts are
the per-profile subclasses (SHRINCS256sKeccak, SHRINCS128sQ18Keccak,
SHRINCS128sQ20Keccak), each compiled under its own build profile.
At a high level, SHRINCSVerifier.verify(...):
key as the expected bundle commitmentsignature as a stateful SHRINCS envelope in place over
calldata, with no copySHRINCS library over the
32-byte hashSHRINCS.verify(...), which enforces the commitment match,
bundle shape, WOTS-C reconstruction, and the unbalanced-tree root0xffffffff on
verification failureA well-formed envelope that fails verification returns 0xffffffff.
Malformed envelope bytes revert: the re-tag reads offsets and lengths
that the solc-generated calldata access check rejects when they fall
outside the calldata bounds.
verify(...) makes no external call: it runs entirely in-contract over
calldata, so any execution failure, including out-of-gas, reverts to the
caller rather than being misreported as an invalid signature.
This path is not the same as the canonical account-wrapper flow.
The canonical wrapper binds signatures to:
domainSeparatornoncekeyVersionactionTypepayloadHashand can also enforce stateful leaf-use policy.
The ERC-7913 raw verifier does none of that. It answers only: does this stateful SHRINCS signature verify for this commitment and these exact 32 message bytes?
That makes it suitable as a low-level verifier surface, but not as a drop-in replacement for the wrapper-owned account flow unless the caller supplies the missing replay protection and policy checks externally.
Use the verifier surfaces for different purposes:
SHRINCSERC7913ConsumerExample: minimal external-app integration over the
generic ERC-7913 verify(...) interfaceSHRINCSStatelessConsumerExample: minimal external-app integration over the
verifier's explicit stateless delegation pathFor ERC-7913 blobs, callers should treat the verifier contract address as the algorithm/version identifier. Since the envelope has no in-band version tag, opaque blobs are fragile if stored or forwarded across verifier families.
Each build compiles the verifier for exactly one SHRINCS configuration. Callers do not supply selectors or arbitrary numeric tuples.
The constants live in the profile-selected
contracts/profiles/<profile>/SHRINCSParams.sol library, imported
through the shrincs-profile/ remapping so reference sites stay
profile-agnostic (see Profiles). The default 256s profile
pins these values (citation keys per
CODINGSTANDARDS.md §1):
STATELESS_SIGNATURE_LIMIT = 2^20 = 1,048,576HASH_LEN = 32 — the n security parameter [FIPS205 §11]HYPERTREE_HEIGHT = 64 — the h parameter [FIPS205 §7]NUM_HYPERTREE_LAYERS = 8 — the d parameter [FIPS205 §7]FORS_TREE_HEIGHT = 14 — the a parameter [SPHINCSPLUS §5.5]NUM_FORS_TREES = 22 — the k parameter [SPHINCSPLUS §5.5]WOTS_CHAIN_LEN = 16 — the w parameter [WOTSPLUS §3]NUM_WOTS_CHAINS = 64 — the len parameter [WOTSPLUS §3]WOTS_TARGET_SUM_STATEFUL = 480 — the WOTS-C digit-sum target,
len * (w - 1) / 2HASH_MASK = bytes32-of-ones — high-aligned truncation mask applied at
every hash-producing site; a no-op for 256s, a real truncation for the
128s profilesHASH_SUITE_KECCAK_256Important distinction:
256s-style compile-time structure
([FIPS205 §11]: h = 64, d = 8, a = 14, k = 22)STATELESS_SIGNATURE_LIMIT = 2^20 is enforced by the wrapper/account
layer as the maximum accepted number of stateless signatures under one
installed stateless key256s-style stateless primitive with a stricter
operational cap of 2^20Two verifier rules deserve explicit mention:
FORS-C verifies NUM_FORS_TREES - 1 revealed entries, not all
NUM_FORS_TREESWOTS-C uses the fixed target sum instead of an explicit checksum suffixw digits must add up to
WOTS_TARGET_SUM_STATEFULFor the stateful WOTS-C / XMSS path, the code also assumes:
STATEFUL_PUBLIC_KEY_BYTES = 68pkSeed || root || maxSignatures32 + 32 + 4 bytesWOTS_CHAINS_STATEFUL = 64WOTS-C signature carries 64 chainsWOTS_BASE_STATEFUL = 16WOTS_TARGET_SUM_STATEFUL = 480This is deliberate: the library claims no support for arbitrary future numeric tuples, even ones that are superficially shape-compatible.
Three compile-time profiles exist, selected by the shrincs-profile/
Foundry remapping in foundry.toml (each build profile also gets its own
out directory):
256s (default). The SPHINCS+-256s-style parameter set listed
above. The split into SHRINCSParams kept the 256s production build
byte-identical to the pre-split verifier (metadata-stripped deployed
bytecode compared before/after).128s-q18 and 128s-q20 (experimental). 16-byte truncated-hash profiles
(HASH_LEN = 16, high-aligned via HASH_MASK), single-layer h = 18
hypertree, a = 24, k = 6, 32 stateful WOTS chains. They differ only
in the stateless budget: 2^18 for q18, 2^20 for q20. Both compile
and pass the structural and profile-invariant test sets, and their
stateless paths are verified against Rust-generated signature vectors
by SHRINCSSphincs128sVectors. Neither limit has an approved
birthday-bound security analysis. These profiles are retained only for
tests, vectors, and research: no production Foundry profile, deployment
script, salt, or advertised address is provided.Build a non-default profile with FOUNDRY_PROFILE:
FOUNDRY_PROFILE=test-128s-q18 forge build
FOUNDRY_PROFILE=test-128s-q18 forge test
test/SHRINCSProfileInvariants.t.sol checks the active profile's
structural invariants and carries a profile-identity guard: a build whose
shrincs-profile/ remapping was shadowed (say, by a top-level
remappings.txt) fails closed. CI builds, lints, and tests all three
profiles and rejects a top-level remappings.txt.
The SHRINCS library is only responsible for signature verification and
rotation-authorization checking.
It manages none of the surrounding account or protocol state:
A real on-chain verifier or account contract needs an initialization step that stores at least:
currentSHRINCSPublicKeyand usually also:
noncekeyVersionThis is outside the SHRINCS library itself. The library only checks whether the provided signature or rotation authorization is valid for the provided inputs.
The integrating contract should pass its stored currentSHRINCSPublicKey
into the library as expectedPublicKeyCommitment. The library enforces that
the provided publicKey bundle is pinned to that expected key.
For rotation flows, the integrating contract should also supply a
rotationContext carrying at least:
domainSeparatornoncekeyVersionThe library uses that context to build the canonical rotation message hash that must be signed by the stateless recovery path.
The library is storage-free by design. A real on-chain verifier or account contract must own the account state and feed that state into the library on every call.
Reference implementation:
The example contract is intentionally small. It shows how wrapper-owned state should interact with the library for:
This is not the same integration model as the consumer examples above.
verifier, key)Use the consumer examples when the integrator already has its own message framing and only wants signature validity. Use the account wrapper when the contract itself must enforce replay scoping, key epochs, stateful-leaf policy, and recovery rotation.
The example wrapper also shows account-layer policies for handling stateful
XMSS leaf use. These are wrapper policies, not part of the SHRINCS library
itself.
StatefulPolicy.MonotonicIndex
nextStatefulLeafIndexStatefulPolicy.RecoveryRotation
enterRecoveryMode() call before stateless
recovery rotations are acceptedStatefulPolicy.LeafBitmap
The integrator chooses which policy fits the account design. In the example wrapper, policy-changing functions are owner-gated.
Policy changes are sensitive administrative actions.
Fresh-key rotation must reset stateful tracking state.
nextStatefulLeafIndexrecoveryModeRaw verifier paths are lower-level interfaces.
verifyStatefulAction(...) / verifyStatelessAction(...) style
interfacesStateless rotation is recovery-only in the example wrapper.
rotateToFreshKey(...) and rotateFullKey(...) both require
StatefulPolicy.RecoveryRotationrecoveryMode == trueRecoveryRotation disables the stateful path immediately.
StatefulPolicy.RecoveryRotation blocks stateful verification
even before enterRecoveryMode()enterRecoveryMode() only arms stateless recovery rotation; it does not
change stateful-path availabilityStateless usage accounting follows the stateless key, not only the bundle epoch.
rotateToFreshKey(...) replaces only the stateful subkeystatelessSignaturesUsed and first consumes one stateless
use for the recovery signature itselfrotateFullKey(...) replaces the full bundle including the stateless
key materialstatelessSignaturesUsed for the newly installed stateless
key after consuming the recovery signature under the old keyThe example wrapper binds its signing domain to both contract identity and chain context.
block.chainid, and
address(this)What the wrapper must handle:
currentSHRINCSPublicKeynoncekeyVersionstatelessSignaturesUsed < STATELESS_SIGNATURE_LIMITdomainSeparatorpayloadHashWhat the wrapper should not delegate to users:
expectedPublicKeyCommitmentnoncekeyVersiondomainSeparatorpayloadHash flow for normal account operationsCurrent tests cover:
maxSignatures boundary verifiesmaxSignatures is rejectedpkSeed length is rejectedWOTS-C chain count is rejectedFORS data is rejectedWOTS-C public-key hash is rejectedpkSeed length is rejectedhypertreeRoot length is rejectedFORS entries are rejectedFORS randomizers, secret leaves, auth paths, and auth nodes are
rejectedWOTS-C chain length is rejectedrotateStatefulViaStateless(...)
maxSignatures == 0domainSeparatorstatelessRotate(...)
maxSignatures == 0domainSeparatorRecoveryRotation policy revertsRecoveryRotation, stateless action verification is rejected until
the owner enters recovery modeRecoveryRotation policy and entered recovery
modeabi.decode over every vector
and fuzzed well-formed envelopefalse through the full verify pathverify(...) returns 0x024ad318 for a valid stateful raw
signature0xffffffff without reverting0xffffffffverify(...) inputs return the failure value instead of
revertingSHRINCS.decodePublicKeyCommitment(...) accepts exactly 32-byte keys and rejects
other lengths without revertingSHRINCS.statefulEnvelope(...) re-tags canonical and other
field-value-equivalent framings in place, and reverts on out-of-bounds
offsets or lengthsSPHINCSPlusC.toMessage(...) maps the ERC-7913 bytes32 hash to exactly
those 32 packed bytesverifier || key signers and reject
no-code, wrong-verifier, short-signer, and non-magic-return casesPer-profile call gas for the five paths measured by
test/SHRINCSMeasurements.t.sol: the
stateful and stateless canonical wrapper calls, the stateful and
stateless ERC-1271 checks, and the ERC-7913 verifyStateless delegation
to the pinned SPHINCSPlusC sibling. The ERC-1271 figures verify the
envelope in place over calldata; the delegation figure calls
verifyStateless directly. Each cell is the gas the measured .call()
consumed (vm.lastCallGas().gasTotalUsed), excluding setup and calldata
encoding.
| Measurement | default | 128s-q18 | 128s-q20 | 256s-sha2 |
|---|---|---|---|---|
stateful.canonical_wrapper_call_gas |
190,792 | 117,759 | 117,759 | 281,063 |
stateful.erc1271_call_gas |
167,779 | 94,746 | 94,746 | 258,050 |
stateless.canonical_wrapper_call_gas |
1,629,049 | 192,109† | 192,109† | 2,420,861 |
stateless.erc1271_call_gas |
1,606,819 | 191,906† | 191,906† | 2,398,565 |
stateless.verify_stateless_delegation_gas |
1,660,931 | 204,614 | 204,614 | 2,455,228 |
† raw SHRINCS.verifyStatelessUncheckedMessage call (wrapper context-hash derivation excluded); see README.md "Gas Measurements" for detail.
Measured 2026-07-13 at each profile's own solc/via_ir/optimizer
settings (default and 256s-sha2: optimizer runs 200; 128s-q18/q20 share
the same settings). Regenerate this table with scripts/gas-report.sh,
which runs every profile's SHRINCSMeasurements suite and re-emits it.
The default-profile stateless figures fall ~50k from earlier baselines: the T6 wire change drops the carried per-layer tree/leaf coordinates from the stateless signature (the verifier now derives them from the FORS digest), shrinking the envelope calldata and its decode. Because T6 also changes the stateful chain-hash preimage (F-08) and the profile-bound commitment, and because WOTS/FORS chain-walk lengths are data-dependent on the regenerated vectors, these figures are recorded actuals, not equality anchors.
For the stateful rows, the ERC-1271 figure falls below the canonical
wrapper call in every profile: the wrapper builds and validates the
typed ActionContext and canonical hash on-chain, whereas the ERC-1271
path verifies a precomputed hash, and the in-place re-tag verification
costs less than that context machinery.
In-process stateless keygen/signing is compute-infeasible at 128s (full
2^a FORS trees plus the fixed hypertree), so the 128s-q18/q20 stateless
rows measure a different call shape than the other profiles: instead of
the account wrapper, they call the same underlying SHRINCS library
verification through a raw-message test harness
(MeasurementRawStatelessHarness) fed by the profile's Rust-anchored
vector, since the wrapper's context-derived hash cannot match a fixed
vector signature. The delegation row still calls the
production verifyStateless entrypoint directly at every profile, since
that entrypoint already takes the hash as a parameter. A narrower
verify-only figure over the same 128s vector, excluding call overhead,
is in SHRINCSSphincs128sVectors.t.sol (stateless.128s_verify_gas,
~243k).
A default-profile-only data point,
SHRINCSVerifier.t.sol::testGasSnapshotHappyPathVerify (stateful,
adapter-direct verify without the account wrapper), measures 349,162
gas; reproduce with forge test --match-test testGasSnapshotHappyPathVerify -vv.
Reproduce the table with:
scripts/gas-report.sh
or a single profile directly:
FOUNDRY_PROFILE=test-128s-q18 forge test --match-contract SHRINCSMeasurements -vv
These figures require a clean full build per profile, which
scripts/gas-report.sh performs; running the single-profile command above
over an out/ directory a different profile already populated can read
stale harness bytecode and shift a cell (the delegation row drifts by a few
hundred gas from its 1,660,931 clean-build value this way).
The stateful entrypoints make no external call, so their execution
failures (including out-of-gas) simply revert. The stateless delegation
(verifyStateless calling its SPHINCS+C sibling) is the one remaining
external call; an out-of-gas there reverts rather than being misreported
as 0xffffffff (see the ERC-1271 and ERC-7913 sections above). Either
way, forward gas comfortably above these figures.
This project uses Foundry for Solidity build and test work. Coding rules, citation conventions, and the enforcement gates (format, lint, line cap, tests, static analysis, and fuzz/invariant properties) are defined in CODINGSTANDARDS.md §8; GitLab CI runs them all.
The repository tracks two kinds of files for LLM coding agents:
.agents/skills/: tool-neutral skills in the
Agent Skills format (<name>/SKILL.md). The
solidity-standards skill walks
CODINGSTANDARDS.md for any agent that writes or
reviews Solidity here.Every other agent file is local state and is ignored by .gitignore:
.claude/, CLAUDE.md, .codex/, .beads/, .serena/, and the
bd-generated .agents/skills/beads/. Put project instructions in
AGENTS.md. Put reusable agent workflows in .agents/skills/, never in
a tool-specific directory. Do not commit tool configuration or
task-tracking databases.
Codex, Cursor, Gemini CLI, Copilot, and most other agents read
.agents/skills/ directly. Claude Code reads only .claude/skills/, so
link the shared skill into it once. The link stays local because
.claude/ is ignored:
mkdir -p .claude/skills
ln -s ../../.agents/skills/solidity-standards .claude/skills/
Install Foundry:
curl -L https://foundry.paradigm.xyz | bash
foundryup
The default foundry.toml profile sets via_ir = true, which the SHRINCS
verifier requires to avoid stack-too-deep compilation failures:
forge build
To build a non-default profile, set FOUNDRY_PROFILE
(FOUNDRY_PROFILE=test-128s-q18 forge build); see Profiles and the
profile sections in foundry.toml.
Run the full verifier test suite:
forge test
Expected result as of 2026-07-13 on the default profile:
266 tests passed, 0 failed.
The Solidity verifier tests are intended to consume vectors generated by the Rust SHRINCS signer/keygen implementation. The Solidity code verifies those vectors; it does not generate production signing material.
The vector file expected by this repository is:
test/test_vectors/shrincs_sphincs_256s_keccak.json
From the Rust repository, generate the vector file:
cargo test --test generate_shrincs_vectors -- --ignored --nocapture
The Rust generator writes:
tests/test_vectors/shrincs_sphincs_256s_keccak.json
Copy that file into this Solidity repository:
cp /path/to/hashsigs-rs/tests/test_vectors/shrincs_sphincs_256s_keccak.json \
/path/to/hashsigs-solidity/test/test_vectors/shrincs_sphincs_256s_keccak.json
Then run the SHRINCS-only Solidity tests:
forge test --match-contract SHRINCSSphincs256sVectorsTest -vv
forge test --match-contract SHRINCSAccountVerifierExampleTest -vv
The vector JSON contains the Rust-generated public keys, messages, signatures, and negative/tampered cases. It also includes compatibility calldata fields used by the current Foundry vector decoder.
This repository also contains test-only Solidity signer helpers under
test/helpers/. These are not part of the production
verifier surface in contracts/.
test/helpers/SHRINCSTestSigner.soltest/helpers/SHRINCSStatelessVectorSigner.soltest/helpers/SHRINCSStatelessVectorSigningFacade.solsignFromSeed(...) / completeSession(...) APItest/helpers/SHRINCSAccountSigningFacade.soldomainSeparator, nonce, and
keyVersion before signing stateful actions, stateless actions, and
both rotation messagestest/helpers/SHRINCSAccountVectorExport.solabi.encodeCall(...) payloads, and
ERC-1271 envelopesUse these helpers for tests, debugging, and local vector generation only. They are not deployable wallet or signer contracts.
The account wrapper signs canonical, wrapper-owned messages, so test signing must bind:
domainSeparatornoncekeyVersionactionTypepayloadHashfor action flows, and the wrapper-owned rotation context for recovery flows.
The test-only account-aware path is:
test/helpers/SHRINCSAccountSigningFacade.solrotateToFreshKey(...) and rotateFullKey(...)test/helpers/SHRINCSAccountVectorExport.soltest/SHRINCSAccountVectorExport.t.solRun the export suite directly:
forge test --match-path test/SHRINCSAccountVectorExport.t.sol -vv
Or generate a JSON artifact from the emitted bundle bytes:
bash dev/export-account-vectors.sh
The default output artifact is:
test/test_vectors/shrincs_account_wrapper_vectors.json
To cross-check these Solidity-exported account vectors against the Rust verifier, copy that JSON into the Rust repository manually. The repositories are separate, so this handoff is intentionally not automated:
cp /path/to/hashsigs-solidity/test/test_vectors/shrincs_account_wrapper_vectors.json \
/path/to/hashsigs-rs/tests/test_vectors/shrincs_account_wrapper_vectors.json
Then run the Rust-side cross-check from hashsigs-rs:
cargo test --test solidity_account_vectors
The export tests emit four wrapper-feedable bundle categories:
testExportStatefulActionBundlestateful_vector_abi:
ABI encoding of the full exported stateful-action bundlestateful_verify_calldata:
calldata for verifyStatefulAction(...)stateful_1271_envelope:
ERC-1271 payload for canonical stateful-action validationtestExportStatelessActionBundlestateless_vector_abi:
ABI encoding of the full exported stateless-action bundlestateless_verify_calldata:
calldata for verifyStatelessAction(...)stateless_1271_envelope:
ERC-1271 payload for canonical stateless-action validationtestExportStatefulOnlyRotationBundlestateful_rotation_vector_abi:
ABI encoding of the full exported stateful-only rotation bundlestateful_rotation_calldata:
calldata for rotateToFreshKey(...)testExportFullRotationBundlefull_rotation_vector_abi:
ABI encoding of the full exported full-rotation bundlefull_rotation_calldata:
calldata for rotateFullKey(...)These exports are intended for local tooling, debugging, and cross-repo vector work. They are not a production signer interface.
The canonical SHRINCS verifiers and their SPHINCSPlusC stateless delegates
deploy through CREATE3 Foundry scripts. A CREATE3 address depends only on
the factory and the guarded salt, not on the init code, so each verifier
profile gets a distinct, chain-invariant address.
Salts are sender-scoped (CreateX's permissioned mode), so only the
canonical deployer can deploy at an advertised address — see
script/CreateXSalt.sol. DEPLOYMENTS.md is the
registry: it holds the salts, profile tags, predicted addresses, the
deploy procedure, the superseded permissionless-salt deployments, and the
historical CREATE2 (verifier) and Hardhat-Ignition (WOTS+) mechanisms
these scripts replace.
Deploy each SPHINCSPlusC delegate before its SHRINCS sibling: CREATE3
fixes the address either way, but SHRINCSVerifier.verifyStateless
reverts on empty code, and each SHRINCS deploy script asserts its sibling
is already deployed at the pinned address.
script/DeploySPHINCSPlusC256sKeccak.s.sol — 256s stateless delegate
(profile production)script/DeploySHRINCS256sKeccak.s.sol — 256s verifier (profile
production)The 128s-q18 and 128s-q20 contracts are deliberately absent from this
list. They are experimental test/vector artifacts and have no production
deployment scripts, production salts, or advertised addresses. CI enforces
this boundary with scripts/check-production-profiles.sh.
Each script asserts its FOUNDRY_PROFILE and refuses to run under the
wrong one. Example:
FOUNDRY_PROFILE=production forge script \
script/DeploySHRINCS256sKeccak.s.sol \
--rpc-url $RPC --private-key $DEPLOYER_PK --broadcast --verify
SHRINCS is testnet-only. The example wrapper
(contracts/examples/SHRINCSAccountVerifierExample.sol) is a reference
integration, not a canonical deployment; deploy it directly with
forge create when you need one.
forge-std is a git submodule at lib/forge-std.via_ir = true; the verifier relies on
it for clean builds.Copyright (C) 2024-2026 quip.network
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/.