- Overview
- System Architecture
- TOTP Authentication
- Social Recovery
- Smart Contracts
- Zero-Knowledge Circuits
- Security Considerations
- Implementation Guide
The ZK Authentication System is a blockchain-based two-factor authentication solution that combines Time-based One-Time Passwords (TOTP) with zero-knowledge proofs to provide secure, trustless authentication and account recovery capabilities.
- Zero-knowledge TOTP verification
- Smart contract-based authentication
- Trustless social recovery system
- Compatible with standard TOTP apps (e.g., Google Authenticator)
- Decentralized storage integration (IPFS/Ceramic)
graph TB
subgraph Client
A[User Interface] --> B[TOTP Generator]
B --> C[ZK Proof Generator]
A --> D[Local Storage]
end
subgraph Blockchain
E[Authentication Contract]
F[Social Recovery Contract]
G[Verifier Contracts]
end
subgraph Storage
H[IPFS/Ceramic]
end
C --> E
D --> H
E --> G
F --> G
H --> A
-
Secret Generation
- Random secret generated on client-side
- Displayed as QR code for TOTP app scanning
- Never stored on-chain or in centralized storage
-
Merkle Tree Generation
graph TD A[Generate TOTP Secret] --> B[Generate 256 Time-Steps] B --> C[Hash Time+TOTP Pairs] C --> D[Build Merkle Tree] D --> E[Store Root On-Chain] D --> F[Store Tree in IPFS/Ceramic]
-
Authentication Flow
- User initiates transaction
- Gets current TOTP from authenticator app
- Frontend generates ZK proof using:
- Current TOTP
- Current timestamp
- Merkle path
- Smart contract verifies proof
- Transaction executes upon successful verification
template MerkleTreeInclusionVerification(n) {
signal input time;
signal input otp;
signal input pathElements[n];
signal input pathIndex[n];
signal output root;
// ... (circuit implementation details)
}
-
Trustee Configuration
- Owner designates trusted addresses
- Sets recovery threshold
- Assigns password hashes for each trustee
-
Recovery Flow
sequenceDiagram
participant Trustee
participant Contract
participant Owner
Trustee->>Contract: Initiate Recovery
Note over Contract: Verify Trustee ZK Proof
Contract->>Contract: Start Recovery Round
loop Voting
Trustee->>Contract: Submit Vote + ZK Proof
end
Note over Contract: Check Threshold
Contract->>Owner: Transfer Ownership
-
Initialization
- Trustee initiates with new owner proposal
- ZK proof validates trustee's identity
-
Voting
- Other trustees submit votes
- Each vote requires ZK proof
- Threshold tracking
-
Execution
- Transfer ownership once threshold met
- Clear recovery state
contract OtpValidator {
bytes32 constant ROOT_SLOT = 0xeb7c...;
bytes32 constant VERIFIER_SLOT = 0x9be...;
bytes32 constant LAST_VALIDATED_TIMESTAMP_SLOT = 0xcda...;
function verifyOTP(
uint256[2] memory a,
uint256[2][2] memory b,
uint256[2] memory c,
uint256[2] memory input
) public returns (bool);
}
Key features:
- Owner management
- Trustee management
- Recovery round tracking
- Vote counting
- Proof verification
- Transaction execution
template HashLeaves() {
signal input leftLeaf;
signal input rightLeaf;
signal output out;
// ... implementation
}
template MerkleTreeInclusionVerification(n) {
// ... implementation
}
template Main() {
signal input pass;
signal input addr;
signal input hash;
signal output out;
// ... implementation
}
- One-time secret display
- No secret storage
- Time-based validity
- Proof uniqueness verification
- Threshold-based execution
- ZK proof requirement for all participants
- Password hash protection
- Prevention of replay attacks
- Assembly optimization
- Slot-based storage
- Reentrancy protection
- Access control
- Generate TOTP secret
- Create and store Merkle tree
- Deploy authentication contract
- Configure trustees
- Get current TOTP
- Generate ZK proof
- Submit transaction with proof
- Handle verification result
- Trustee initiates recovery
- Collect required votes
- Submit proofs
- Execute ownership transfer
- IPFS/Ceramic configuration
- Merkle tree storage
- Recovery data management
- Client-side caching