Docs · Contracts
Vault validator
An ERC-7579 validator module. It checks the owner's ECDSA signature until an account is flipped, and one-time hash-based signatures afterwards.
What it is
One contract serves every account that installs it. State is kept per account: the owner, whether it has flipped, the current key index and the hash of the current one-time public key. The module is immutable, with no owner and no upgrade path.
Installing
The account calls its own installModule with module type 1. The account then calls the module:
data is abi.encode(address owner, bytes32 pqKeyHash). The owner is the ECDSA signer used before the flip. The hash is for key index 0 of this account.
Install also calls registry.commitFor, so the backup key is on record from the same transaction. That call reverts once the alarm has tripped, so installing after a trip fails.
Derive the hash with the TypeScript signer or the install tool:
import { derivePublicKeyHash, generateSeed, bytesToHex } from "@enquantum/wots";
import { encodeAbiParameters } from "viem";
const seed = generateSeed(); // back this up offline
const pqKeyHash = bytesToHex(derivePublicKeyHash(seed, account, 0));
const initData = encodeAbiParameters(
[{ type: "address" }, { type: "bytes32" }],
[owner, pqKeyHash],
);
After a flip, uninstalling removes the post-quantum check. The account's other validators then decide who controls it.
Two modes
| Before the flip | After the flip | |
|---|---|---|
| Accepted signature | 65-byte ECDSA by the owner, over the hash raw or EIP-191 prefixed | Next key hash plus a WOTS+ signature |
| Validation gas | About 18k | About 103k, 154k worst case |
| State change | None | Key index and key hash rotate |
| ERC-1271 | Valid for the owner's signature | Always invalid |
ERC-1271 is refused after the flip because a one-time signature cannot be checked from a view call without leaving the key usable a second time.
The flip
Called by the account itself, through a normal user operation. Flips the caller at any time.
The account's owner may call this at any time. Once the alarm has tripped, anyone may. Reverts with NotAuthorized otherwise.
For the keeper. Requires a tripped alarm and skips accounts that are not installed or already flipped, so one bad entry cannot block a batch.
The flip is permanent. Validation never reads the Alarm, which is why flipping is a separate transaction.
Signature format
After the flip, userOp.signature is exactly 2,176 bytes:
bytes 0 .. 31 nextPqKeyHash hash of the key for index + 1
bytes 32 .. 2175 WOTS+ signature 67 values of 32 bytes
message signed = keccak256(userOpHash ‖ nextPqKeyHash)
tweak = keccak256(account ‖ uint256 keyIndex)
The validator recomputes the public key hash from the signature and compares it with the stored one. On a match it stores nextPqKeyHash, increments the key index and returns success. Binding the next key into the signed message means it cannot be swapped in transit. A zero next hash or a wrong length fails validation.
import { signUserOp, bytesToHex } from "@enquantum/wots";
const keyIndex = await client.readContract({
address: VAULT_VALIDATOR, abi: vaultValidatorAbi,
functionName: "keyIndexOf", args: [account],
});
const { signature } = signUserOp(seed, account, keyIndex, userOpHash);
userOp.signature = bytesToHex(signature);
Signing two different hashes with the same key index reveals enough chain values for someone else to forge a third. Always read the index from the chain, and never re-sign a changed operation with an index that has already been used.
Notes for bundlers
- Validation reads and writes only this module's storage keyed by the account, the associated-storage pattern that ERC-7562 allows.
- The signature adds 2,176 bytes of calldata. On an Arbitrum Nitro chain that raises the data fee, so estimate
preVerificationGaswith the full-length signature in place. - A failed validation leaves the key index unchanged, so the same key is still valid for the same operation.
The module is tested in Foundry, including on forks of Robinhood Chain. It has not yet been installed on a real Kernel v3.1 account or sent through a production bundler, so try it with a throwaway account before protecting real funds with it.
Views
| Function | Returns |
|---|---|
accountData(address) | Owner, installed, flipped, key index and current key hash. |
isFlipped(address) | Whether the account has flipped. |
keyIndexOf(address) | The index of the key that must sign next. |
isInitialized(address) | Whether the module is installed for the account. |
isModuleType(uint256) | True for type 1, validator. |
Events and errors
event Installed(address indexed account, address indexed owner, bytes32 indexed pqKeyHash);
event Uninstalled(address indexed account);
event Flipped(address indexed account, address indexed by, uint256 blockNumber);
event KeyRotated(address indexed account, uint64 newKeyIndex, bytes32 newPqKeyHash);
| Error | When |
|---|---|
AlreadyInstalled() | Install on an account that has the module. |
NotInstalled() | Flip on an account without the module. |
ZeroAddress() | Install with a zero owner. |
ZeroHash() | Install with a zero key hash. |
NotAuthorized() | flipFor by a non-owner before the alarm trips. |
AlarmNotTripped() | flipForMany before the alarm trips. |
AlreadyFlipped() | Flip on an account that has flipped. |