2FA with Zero-Knowledge proofs

Overview

zkAuth ๐Ÿ—๏ธ ๐Ÿ”—

Zero-Knowledge protected onchain two-factor Authentication

This project provides 2FA for EVM blockchains, compatible with the broadly adapted timed-one-time-password (TOTP) algorithm. We remove the trusted validator, creating a zero-trust authentication circuit and solve the challenge of on-chain visibility by verification via zero-knowledge proofs.

The Challenge Statement ๐Ÿ“œ

The introduction of 2FA has been a big win for cyber security. It's quick and persistent adaptation by the wide public (non-technical audience) is due to its user-friendly interface (GoogleAuthenticator) and standardized algorithm (rfc6238). Yet, this technology is vulnerable and leaves plenty of room for security improvement. We identified the following attack-vectors:

  • The trusted validator: The issuing party is trusted with validating the authentication request. There is no protection against insider attacks or technical faults on the validators side.
  • The secret used to generate and validate the TOTP is stored in a centralized database, vulnerable to data breaches, which web2 companies are falling victim to with steadily increasing frequency.
  • Recovery of mentioned secret is commonly possible through verification of personal data, which is vulnerable to social-engineering attacks.
  • The un-hashed, un-encrypted secret is required to authenticate a provided TOTP. Due to the transparency of EVM blockchains, this requirement makes the current 2FA solution unsuitable for onchain authentication and thus incompatible with web3.

The Solution: zkAuth ๐Ÿ”

We present zkAuth, a zero-knowledge and zero-trust based onchain 2FA inspired by ERC4337. For the sake of mass-adaptation, which we the web3 community strive for, our solution builds on the established TOTP standard, instead of providing an optimized solution which with high probability will get rejected by the public.

TLDR:

  • Compatible with established TOTP apps (e.g. GoogleAuthenticator).
  • The critical TOTP generator secret is only displayed to the user.
  • Mentioned secret is generated randomly and does not get stored.
  • Authentication is validated on-chain, thus cannot be corrupted and is transparent.
  • Authentication can be invoked by smart-contracts by cross-calling the zkAuth contracts.
  • The zkAuth contracts can be base-class to paymasters of 2nd generation wallets such as ERC4337.
  • The generator secret can be recovered through social recovery (zk-protected&onchain-validated).

Zero-trust setup

Current TOTP 2FA solutions are based on a shared secret which generates a different password for every moment in time. The trusted validator uses the secret to verify the user.

Our approach removes the trusted validator. The secret is randomly generated on the frontend and displayed in form of a QR-code to the user only once. Before discarding the secret, passwords for 2**8 timestamps into the future are generated and hashed together with the corresponding time-step. A merkle tree is build on top of those hashed. Once the user authenticates, which proves that he scanned and hopefully securely saved the secret, a authenticator contract containing the merkle-tree's root gets deployed to the blockchain.

We chose the layer 2 solution OPTIMISM as our home-chain due to it's scalability, block-time of ~1sec, zero-gas fees and its seriousness.

Neither the merkle-tree nor the hashes which form the leaves of the tree, can be used to infer the secret, nor can an attacker back-propagate the corresponding generation-time of an password-hash.

To further make this solution invulnerable to brute-force attacks, we encrypt the tree with a key signed with the users public key, meaning this key can only by generated by this specific address.

The full merkle tree is necessary to parse the data needed for onchain authentication with the deployed merkle-tree root. Earlier implementations od this approach have stored the tree in the browsers local-storage. Needless to say that this solution is sub-optimal for multiple reasons. We choose for decentralized storage an provide the user the option to store and retrieve the tree from IPFS, specifically web3storage, or CERAMIC, a protocol for decentralized data composability.

Authentication can be invoked by any smart-contract, wallet or even token when used as modifier. The calldata is put on hold until the user authenticates. Authentication requests emit an event which get's indexed by theGraph, a decentralized blockchain indexing protocol. We use these events to inform the user about open authentications and the staged call-data.

The authentication step requires the user to access her/his TOTP generator and the corresponding merkle-tree. Once a TOTP is provided, it get's hashed together with the current time-step and compared to the leaves of the merkle-tree. If a matching hash is found, the same plus the additional branch-hashes necessary for verification are send to the blockchain. With the initially provided root, it can be verified that the merkle-tree has not been modified. This method is commonly used to prove the integrity of downloaded files and in internet protocols such as TSL to protect against man-in-the middle attacks.

Social recovery

Web3 is known for the fatal consequences of losing access to the personal private-key. Inspired by a talk of Vitalik we took a step further and implemented social recovery.

The user-specific authentication contract let's the user assign other wallets as trustees for recovery.

In the case that the user's wallet gets unaccessible or compromised, a recovery process can be initiated.

In a first step the user agrees off-chain (e.g. by phone-call) on trustee-specific and one personal passphrase. For each passphrases, a SNARK proof is generated and committed to the blockchain.

Each trustee has then the option to consent to the recovery-process by submitting s SNARK proof of his passphrase.

Once a predefined threshold (at least majority) of consents is reached, the user is able to recover his authentication contract by in a last step, providing the SNARK proofs of his personal passphrase.

Live Demo

zkauthLogo

Comments
  • Ceramic patch

    Ceramic patch

    Changes:

    • implemented an intermediate local state in useCeramic() hook. We now read the initial state from ceramic, then rely on the local state to read and update ceramic. Gonna keep that one for future projects ๐Ÿค“
    • cleaned logs.
    • fixed a dom issue.
    • ran prettier
    documentation enhancement 
    opened by 3lLobo 0
  • ipfs functions for storage

    ipfs functions for storage

    Changes:

    • upload and fetch functions for ipfs

    Discussion:

    • we need to either run this on a backend of encrypt it with a msg signed by the user
    • or use ceramic
    • also need to decide how to store it? a dictionary trees[address] = mrkltree ?
    frontend ipfs 
    opened by 3lLobo 0
  • Fetch the graph

    Fetch the graph

    Changes:

    • fetched the Auth Events from the graph
    • useTheGraph() hook for fetching
    • exampleResult.json with example data
    • committed the .lock file, feels weird!
    • If the app throws an ``MODULE_NOT_FOUNDerror, just add.js` to the import in the complaining file. Pretty sure its a typescript bug only on my machine.
    frontend graph 
    opened by 3lLobo 0
  • TotpAuth subgraph

    TotpAuth subgraph

    • Implemented the totpAuthenticator subgraph.
    • Deployed subgraph to hosted service for Optimism-goerli.
    • Endpoint: https://api.thegraph.com/subgraphs/name/3llobo/zkauthtotp
    • QGL query in Readme @danieljcss ready to be used in the frontend to fetch all data per wallet

    zkAuthZoomAnimLoop10mb

    backend graph 
    opened by 3lLobo 0
  • Feature/add zk circuits and contracts

    Feature/add zk circuits and contracts

    • Add ZK circuit for Hash Check using MiMc hash function and Merkle Tree Inclusion
    • Add smart contracts for OTP Validation and Social Recovery
    • Add test for both
    opened by rishotics 0
  • The Merge ๐ŸŒŠ

    The Merge ๐ŸŒŠ

    Plenty of changes on the backend. In short: we got the TotpAuthenticator contract working and deployed. More importantly, I git ignored the yarn.lock file, what reduced our codebase to 3% ๐Ÿ’ฅ

    Next step is going to be the subgraph to index our on-chain events.

    UPDATE:

    • upgraded tailwind.config for custom colors like snow and attributes like scrollbar-hidden
    • Had to uppercase some file names in components for the app to run
    • UI feature wish: Use color zinc instead of gray ๐Ÿ’…

    crib

    smrtCntrct backend 
    opened by 3lLobo 0
  • new encryption + more hashes ๐Ÿณ

    new encryption + more hashes ๐Ÿณ

    Changes:

    • use Metamask only to encrypt a key
    • this key is the TOTP secret -> we can update the tree without the user having to re-scan the qr
    • same key used to en/decrypt the merkle tree
    • using crypto-js and AES for en/decryption
    • rewrote and parametized the prepareMerkleTree() function.
    • totp exponent set to 16 which generates hashes for 22 days into the future.
    • generation takes approx 3 sec on my machine.
    • TODO: adjust the OtpMerkleTreeVerifier contract to accept more hashes for validation.
    frontend 
    opened by 3lLobo 0
Owner
Daniel Contreras Salinas
Daniel Contreras Salinas
The zkPass browser extension can proxy three parties TLS and generate zero-knowledge proofs

zkPass Extension zkPass a Chromium extension which can proxy three parties TLS and generate zero-knowledge proofs. Technology Dependence Multi-party c

zkPass 9 Nov 1, 2022
Solidity NFT whitelist contract example using MerkleTree.js for constructing merkle root and merkle proofs.

MerkleTree.js Solidity NFT Whitelist example Allow NFT minting only to whitelisted accounts by verifying merkle proof in Solidity contract. Merkle roo

Miguel Mota 65 Dec 29, 2022
Node.js module for verifying Plumo proofs and reading states based on it

plumo-verifier Node.js module for verifying Plumo proofs and reading states based on it. Plumo is a SNARK-based light client verifier for the Celo blo

Celo 3 Dec 15, 2022
Groth16 proofs are very popular and are used by many protocols in production.

Geometry presents: the Groth16 Malleability Challenge Preamble Groth16 proofs are very popular and are used by many protocols in production. Libraries

Geometry 39 Dec 14, 2022
Been interested, studying, and developing blockchain security with a Zero Knowledge Proof (ZKP) and create a prototype on the current issue with Philippine's upcoming election. ๐Ÿ“ฅ

Implementation of Zero Knowledge Proofs in Cryptographic Voting ?? Reference: Cryptographic Voting โ€“ A Gentle Introduction Overview ????โ€?? The main i

Karl Joseph Saycon 2 Apr 11, 2022
Privacy preserving governance mechanism using zero knowledge for proof of merkle inclusion.

Zero Knowledge Private Voting V1 Motivation On-chain governance today is fully transparent at the cost of privacy. This means that every proposal and

Blockchain Capital 18 Dec 16, 2022
Tell your crush you like them with zero-knowledge

zk-Crush zk-Crush is a way to tell your crush you like them with zero-knowledge. Disclaimer Note this project was mostly meant as a joke, it's not tru

Amir Bolous 224 Jan 2, 2023
Privacy preserving governance mechanism using zero knowledge for proof of merkle inclusion.

Zero Knowledge Private Voting V1 Motivation On-chain governance today is fully transparent at the cost of privacy. This means that every proposal and

Blockchain Capital 11 Jun 7, 2022
Zero-Knowledge OTP verification on chain

zkOTP: Zero-Knowledge OTP verification on chain Motivation Inspired by SmartOTP and Modulo's 1wallet, a zkOTP solution can manage access to a smart co

drCathieSo.eth 15 Dec 22, 2022
An Opensource Peer-to-peer Social Network with Zero-Knowledge-Proof based authentication.

HexHoot This is an attempt to create an Opensource Peer-to-peer Social Network with Zero-Knowledge-Proof based authentication. The objective is to dem

Zenin Easa Panthakkalakath 6 Dec 28, 2022
The classical game of Liar's Dice enhanced with the usage of Zero-Knowledge Proof

Liar's Dice An online multiplayer game showcasing the potential of Aleo's Zero Knowledge Proof platform. Local deployment Prerequisites Setup dnsmasq

Kryha 4 Dec 15, 2022
The classical game of Liar's Dice enhanced with the usage of Zero-Knowledge Proof

Liar's Dice An online multiplayer game showcasing the potential of Aleo's Zero Knowledge Proof platform. Local deployment Prerequisites Setup dnsmasq

Kryha 3 Oct 20, 2022
Zero Two Bot,A fully Modular Whatsapp Bot to do everything possible in WhatsApp by Team Zero Two

?? ???????? ?????? ???? ?? A Moduler WhatsApp Bot designed for both PM and Groups - To take your boring WhatsApp usage into a whole different level. T

Sam Pandey 69 Dec 25, 2022
Multiplies a number by zero. Useful for when you need to multiply a number by zero

multiply-by-zero Multiplies a number by zero. Useful for when you need to multiply a number by zero Please consider checking out the links of this pro

Dheirya Tyagi 2 Jul 3, 2022
Cheatsheet for the JavaScript knowledge you will frequently encounter in modern projects.

Modern JavaScript Cheatsheet Image Credits: Ahmad Awais โšก๏ธ If you like this content, you can ping me or follow me on Twitter ?? Introduction Motivatio

Manuel Beaudru 23.9k Jan 4, 2023
Open Source projects are a project to improve your JavaScript knowledge with JavaScript documentation, design patterns, books, playlists.

It is a project I am trying to list the repos that have received thousands of stars on Github and deemed useful by the JavaScript community. It's a gi

Cihat Salik 22 Aug 14, 2022
a tunisian platform made to share knowledge. :dizzy:

โญ tha9fni.tn a tunisian platform made to share knowledge. ?? What's tha9fni will be like? We're still tweaking the wireframes but this is How its goin

ุงู„ุชูˆุงู†ุณุฉ ุฅู„ูŠ ูŠุญุจูˆุง ุงู„ุจู€ุฑู…ุฌุฉ 18 Nov 17, 2021
A knowledge management garden for https://obsidian.md, in which to grow your ideas

?? ?? The Obsidian Garden Welcome to your Knowledge Garden The Obsidian Garden is both guide in helping you create your own knowledge system, and a kn

Tane Piper 145 Dec 27, 2022
It consists of a recreation of Twitter, to put into practice both Front-end and Back-end knowledge by implementing the MERN Stack together with other technologies to add more value to the project.

Twitter-Clone_Back-end โœจ Demo. ?? About the project. ?? Descriptions. It consists of a recreation of Twitter, to put into practice knowledge of both F

Mario Quirรณs Luna 5 Apr 12, 2022