Dev.to Security 🔐 Cybersecurity 👁 0 📖 2 min read

Adding post-quantum co-signing to any existing Safe multisig without moving funds

The hardest part of post-quantum wallet adoption on Ethereum is not the cryptography. It is liquidity inertia. Billions of dollars already sit in audited Safe{Wallet} multisigs, and almost no DAO or treasury wants to mig

The hardest part of post-quantum wallet adoption on Ethereum is not the cryptography. It is liquidity inertia. Billions of dollars already sit in audited Safe{Wallet} multisigs, and almost no DAO or treasury wants to migrate funds into a brand-new standalone wallet contract.

So instead of asking teams to move funds, I built QVaultSafeGuard.sol in QVault v0.4.0: a single multi-Safe guard contract that bolts pure-Keccak WOTS+-128 + XMSS post-quantum co-signing onto any existing Safe v1.3, v1.4, or v1.5 without moving a single wei.

How it works with unmodified Safe{Wallet}

QVaultSafeGuard implements both Safe's ITransactionGuard (0xe6d7a83a) and Safe v1.5's IModuleGuard (0x58401ed8), plus ERC-165 (0x01ffc9a7).

  1. One-time attach (via Safe Transaction Builder): Your Safe executes a 2-call batch: guard.configureSafe(...) (binding the Safe's XMSS root, salt, freeze hash, and policy) followed by safe.setGuard(address(guard)).
  2. Pre-approve with a one-time PQ signature: Before executing a Safe transaction, any owner or relayer calls guard.approveSafeTx(safe, safeNonce, to, value, dataHash, operation, deadline, pqSig). Because it takes dataHash = keccak256(data), even a huge MultiSend Safe batch costs constant calldata gas.
  3. Execute normally in app.safe.global: Safe's execTransaction calls checkTransaction(...), which checks that approvedSafeTx[safe][txKey] exists for ISafe(safe).nonce() - 1 and consumes it atomically.

Three Safe-specific gotchas worth getting right

  1. Safe increments nonce++ before calling checkTransaction. Inside checkTransaction, ISafe(msg.sender).nonce() is already txNonce + 1. Subtracting 1 ensures the PQ signature binds to the exact executing nonce.
  2. Blocking ECDSA attackers from uninstalling or overwriting the guard. Once a Safe calls configureSafe, subsequent calls to configureSafe revert with AlreadyConfigured. And inside checkTransaction, any self-call (to == safe, which covers setGuard(0), enableModule, swapOwner, setFallbackHandler) and any DELEGATECALL unconditionally require a PQ approval. Even if a quantum computer breaks 100% of the Safe's ECDSA owners, the attacker cannot remove the guard, overwrite the XMSS root, or drain funds.
  3. Hash-locked emergency freeze + PQ rotation. Calling emergencyFreeze(safe, freezeSecret) locks all Safe transactions in 35,783 gas without touching XMSS leaves. Calling rotateRoot(...) with a valid PQ signature unfreezes the Safe and rotates to a fresh 1,024-leaf epoch at the same Safe address.

Measured gas (solc 0.8.28, optimizer 200 runs, depth=10, Cancun & Prague identical)

Operation Gas (Cancun & Prague / EIP-7623)
verifySafeActionView (pure WOTS+-128 + XMSS verify) 57,023
approveSafeTx (verify + bitmap burn + store pre-approval) 146,331
emergencyFreeze (instant Safe kill switch) 35,783
rotateRoot (unfreeze + fresh 1,024 leaves) 112,989

All 20 cross-language Rust + Browser WASM + Solidity checks (including a MockSafe quantum-hijack test suite trying to drain ETH, call setGuard(0), overwrite configureSafe, and call unapproved modules) run locally in ~30s:

git clone https://github.com/regitxx/qvault && cd qvault
cargo test && cargo build --release --all-targets
cd evm-verify && npm install && node verify.mjs && node verify-wasm.mjs

Try the Safe Batch Builder & Browser WASM signer

Open the Safe{Wallet} PQ Guard tab at https://qvault.reziiix.com (keys stay 100% client-side in a 185 KB Rust WebAssembly module; exports a ready-to-import Safe Transaction Builder JSON).

Caveat: v0.4.0 is newly engineered and not yet externally audited, so test on Arbitrum Sepolia / Base Sepolia before attaching to mainnet treasuries. Feedback from Safe module builders and auditors welcome.

📰 Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.