ZK Email: Decentralized Email Login + Account Recovery + 2FA

ETHCC 7 · 9 Jul 2024 · 25:11

Aayush Gupta and colleagues present ZK Email, which wraps the DKIM signature on an email in a zero-knowledge proof so that replying to an email can authorize an on-chain action without revealing the address. Live demos show an email acting as a second signer on a Safe multisig, and account recovery with email guardians through ERC-7579 modules and an optional time lock. The team also sketches email-based OAuth login with scoped ephemeral keys. In the Q&A they say the proof costs about 300,000 gas before aggregation, and explain how DKIM key rotation is handled.

Speakers

Topics

From ETHCC 7, hosted by Ethereum France.

Transcript

So today in Web3, one of the major problems is that wallets are not very intuitive. It's hard for non-crypto users to use Web3 products. But if you could have emails transact on behalf of you in those wallets without compromising on cryptography cryptography and security, then perhaps you would have a more user-friendly way for users to interact with Web3N wallets. I'm Ayush.

And thanks to the rest of the team, including Sora, Aditya, Wateru, Shabum, Cressandra, and Isha, who made this whole demo possible. It wouldn't have been possible without them. Well, the idea is that you can have programmably provenant data from within your inbox. That is, we can verify emails directly from the Web2 services mail server instead of having to trust an intermediary. Second, we can extract arbitrary information via ZK Regex, allowing us to program it. And finally, we can these proofs are portable.

We can prove them on any chain or any service and move it around as we wish. But how exactly does ZK email work? Well the idea is that emails are signed according to the DKIM protocol. That is, it's an RSA signature of the SHA 256 hash of all the data in the email, including the FROM to subject and hash of the body. Now every single email sent or received since 2017 has this cryptographic signature on it. And so what we did is we wrap this inside a ZK proof and we verified the RSA signature and the SHA256 and then we run regex inside that ZK proof as well to ensure that only the data you want to reveal is revealed. So in today's presentation we'll be discussing first how we can use the ZK email primitive to build ZK email powered smart contracts.

Then we'll talk about how we could use this for instance to have email signers on multi-sigs. Then we'll discuss a sketch flow for how you might have OAuth login, for instance approving an ephemeral key via your email in a very easy to use interface. And finally, we'll go over account recovery, using your email as a guardian for your smart wallet. But first, how exactly do email based smart contracts work? Well the idea is that if a user replies to an email, then the person who receives the reply can make a ZK proof of that email being sent by the email owner. And so the idea is that we can authorize transactions just by replying to an email.

For instance, here you have an account creation email. The code we've put in the subject for ease of visibility, but you can also have it in the body. As soon as the user responds to this, this email can automatically get proved by the recipient and relayed on-chain. You can even try it for yourself if you go to emailwallet.org. You'll notice that this account code is a long hex string, and this is what allows us to have both privacy and decentralization. We never commit the email address directly on-chain. The ZK proof itself calculates the email address was valid and then only publishes the hash of that email address and that account code.

That means that the email address is private on-chain and nobody knows who is your guardian or who is using the email address on-chain, but no other email address can ever authorize that contract. Second, we prove that the user's email contains the account code, meaning that we know the data is available to the user. This means the user cannot lose access to that data. This allows for relayer decentralization, because this means that the recipient of that email who's proving it on-chain can be anybody, including any number of decentralized relayers or even yourself, giving the system full fault tolerance and censorship resistance. Now, how would you use this primitive to build something like email multi-sig signers?

Well, to begin, why even have emails on multi-sigs? Well, DAOs with many signers often want faster and easier mobile confirmation flows. Perhaps your primary wallet is an EOA, but the dozens of signers that might be approving that would be more intuitive if they used emails instead. This is especially for people who don't already already own all wallets or who aren't already familiar with wallet infrastructure, for instance, non-technical members of your team, friends or family members. And finally, you can imagine this leads to an intuitive two-factor authentication flow for your own large transactions. You can have a rule like every transaction over a thousand dollars requires a confirmation from my email address before it gets sent.

And so now that we've understood how we can use ZK email to prove emails, how we can use that to authorize smart contracts, and how we can use that to control multi-sigs, we now understand that there's perhaps a world in which users signing on multi-sigs don't need to get their own wallet app and back up their seed phrase, and they can instead use these emails. And so we have a live demo up, which you can try by scanning emailwallet.org or setting up a safe on safe.global. We'll go through the whole flow here for you as well, live so that you understand how it works. So what I've done is prior, I've gone to emailwallet.org and I've signed up with my email.

That is, I've put in my email and I've replied to an email allowing me to create my account. It's now created this smart contract address, 0xC E A E, that is only controlled by my email, and no other EOA or contract can control that address. I can also have other functionality like sending money or viewing my assets from this wallet. Now you'll notice that in this Nose safe, I've added this exact address as a signer. And this corresponds to the email address that we're using today. And so all I need to do is from the primary EOA that owns this address, I can simply choose any wallet, and I can start trigger a transaction to send ETH.

Once I start this transaction, the original EOA will sign it. And now you'll notice that one out of two signers have signed. The only way for the other signer to sign is if you confirm via email. So if you go to your inbox, you'll notice almost immediately I've received an email asking me to approve this transfer this transaction. Again, the details are in the subject for visibility, but you could also put this in a very nice embedded flow inside the body, which shows exactly what the transaction is doing. All I need to do is reply.

And once that is picked up by the relayer and sent on chain, then the safe will approve that transaction. While that happens, we can understand what exactly is happening behind the scenes. Every time a Nose safe adds a signer or removes a signer, any number of email wallet relayers are picking that up. If they realize that they have the account code for that email address, they can then send emails to that address. So now, every time they see a transaction that's pending on Nose Safe, they detect that. And subsequently, they can send a user the email to confirm that. And once the user replies, the email wallet sends that to approver, which currently is running on the email wallet relayer, and then once the proof gets generated, it can send it on chain and pass it to the Nose safe.

Now currently, the user has to sign up through email wallet.org, but you can imagine in the future this is natively integrated into Nose Safe. So for instance, this is one of the things that we're currently working on, in which in the Nose Safe interface, you can insert a normal EOA address, an ENS address, or directly an email address. And then you don't have to do any of the signup flow of worrying what the actual address corresponding to that email address is. Now if we go back to this wallet, we'll notice that that second proof has been relayed on chain and the signature has already been approved from that second wallet. All I need to do now is execute the transaction from the original EOA or any one of the EOAs that are signers on the account.

So we can execute this transaction. Sweet. And this transaction will get sent on chain. Now, other than using emails as signers, you'd imagine the most intuitive use for emails is as a login service. That is, you can log in with your email address and request access to specific scopes in a very user intuitive manner. So how might this work? Well, first of all, why do applications even want email based login instead of the current wallet login? Well, first it allows you to reach a completely different set of users than what crypto has already been reaching.

Second, dApps can have ephemeral keys living in the browser so that transactions are seamless. You don't have to sign and confirm with an email every single time, you just do it once, and then it can happen in the background for the rest of the session. If you lose that device or that browser, because it's an ephemeral key, it doesn't matter, you can always just generate another one that allows you to sign for that account. And finally, by defining scopes, you can avoid unilateral control over user funds. We've talked to a number of dApps who don't like having access to wallets with, say, millions of dollars of user funds, because that means the front-end developer has a lot of control, and if they get hacked, that's a liability. And so often they're looking to, for instance, only approve 10 USDC at a time for a week or something.

And so being able to specify these scopes in a user intuitive way is extremely useful. And so what we've done is we've created a very simple SDK in which in a user's front end, they simply import our OAuth core and they call the sign-in function on the email address that the user has inputted, the ephemeral key that was generated in local storage in the browser, and the scopes that they want. In this case, 10 die for a week. Subsequently, the user will simply get an email, confirm it, and then that ephemeral key will transact on behalf of that user's email wallet. This is very interesting because alone, this one line integration is already easier to integrate than Google OAuth, and it gives you full cryptographic security of that user's email.

Only that user can ever transact with that ephemeral key because it's local, and only they can ever authorize new ephemeral keys. You can also have the scope shown up front to the user. So in the email in which the user actually approves that scope, there's a view much like your average OAuth scope view that shows, oh, these are the precise scopes that we're requesting. And finally, it's decentralized. Unlike having to trust Google's OAT service or a different OAuth server or somebody to hold your keys and MPC, you can simply run your own relayer and completely move off of any centralized dependence as long as the email, the user still keeps their email on their email server. We're currently looking for beta testers for this SDK, and we'll be in person to help support people during the hackathon this weekend if they want to build an application with this.

And you can see the exact integration at our docs. Cool. Thanks, Ayosh. So we're really excited to share with you guys a feature that we've been working on recently, which is email account recovery. So you can use email guardians to recover your smart account. So we see this as a killer feature for ZK email. You can completely forget complicated recovery setups with seed phrases, and now anyone with it with access to an email, whether that be yourself or your non-tech savvy friends and family, can help recover your own or even their own account. Importantly, the email is never revealed on chain, so guardian privacy is preserved.

And to make this work, we're using a really cool ERC called ERC7579. And this is a standard for modular smart accounts that allows developers to add additional functionality to smart accounts for other use of so-called modules. So shout out to the Rhinestone team for helping us make this integration. And we're really excited to be part of this really quickly expanding ecosystem. So our contracts provide out of the box recovery for all existing safe accounts and any 7579 account, whether it be existing, present, or future. And the integration is really simple.

The ERC makes it really easy to install a module, and everything is 4337 compatible, so you can make a really simple integration into your front end via permissionless JS. And importantly, as I just said, the ZK email infrastructure is decentralized. So as long as the smart contracts receive a valid proof from any relayer, the authentic email can be authenticated on chain. So an important thing to highlight is that transaction origination can only start from the sending of a user's email. So the user is in complete control.

So we have a generic recovery module, and this sort of works by binding, it works, it binds the email to the on-chain action based on a recovery hash, which binds to the call data, which works for a generic recovery module. But this isn't the best UX, so we allow developers to write custom recovery subject handlers where you can define your own email subject that is specific to your implementation, and you just have to write some simple validation logic, and then you can deploy that via our handy factory functions. So now we'll go over how it works high level before diving into the demo.

So there's a few steps to sort of like from the from top to bottom. Step number one is you need to install the recovery module. So this is where you add all the necessary configuration, such as your guardians, your threshold, your recovery time lock. The recovery time lock we'll come back to in a few steps time. But you can add like one guardian, you can add multiple guardians, you can set different weights for different guardians. And once you've done that, we have this next step. And this is really important for the robustness of the security of the recovery setup. So we want guardians to explicitly confirm that they are in control of this email address.

So we don't want there to be any typos, and we want them to want high certainty that they're in control of the email address. And so the way we look at this is recovery is probably the most important transaction you'll ever make. So we really want to reduce the chance of there being broken recovery setups down the line. So we have this additional step where the guardian confirms they want to be a guardian for an account. So you set up recovery, some time has passed, and you've lost your device. If it's a pass key, maybe you've lost your phone. Maybe if it's an EOA, you've lost your private key.

And now you need to recover your account. So the next step is to process recovery. So this is where you'll go to your R recovery UI or via your wallet provider's UI, and you'll recover your account, which will call the relayer API, and all of your guardians will get an email. Once they're happy with this recovery request, maybe they've communicated to you off-chain, they'll reply, and then the ZKP will be generated and it'll be verified on-chain. Once the threshold has been reached, you can recover your account. And we split out the final steps to take advantage of the recovery time lock, which is an optional security feature.

So the recovery time lock protects against malicious recovery attempts. So if your guardians act maliciously, or if somehow uh emails are leaked and someone hacks into your email, then the time lock, say of two days, would give the account owner time to react to a malicious recovery attempt and cancel it. So that was the basic flow, and now we'll show you what this looks like. So I'm just going to swap over to the recovery safe. And so this safe we set up earlier and we installed the module.

So we're ready to go to our recovery UI and configure recovery. Cool. So I'm going to grab my email address from here and I'm going to add myself as a guardian. So this is where I'm setting recovery. We're just surfacing a few configuration details here. I'm just going to set the time lock to one second, but you can set it to zero, you can set it to two days. That's completely configurable. First, I should probably connect my wallet. So I'm going to use wallet connect to do that. The wallet connect connection makes it really easy to use your safe with an external DAP.

So I'm just going to paste that in there and then we'll connect it. Cool. So we're ready to configure recovery and request the guardian. So we go back to our safe, we execute that transaction because we're happy with adding this configuration. And then after we've confirmed this transaction, we can go to our email account, and we should have a request to add the guardian to the recovery setup. Nice.

So we can see that just there. You can see the account code that I mentioned earlier, which provides availability to users. And I'm happy with this email, so I'm just going to reply and write confirm. So under the hood, the ZKP will be being generated, and we'll just walk this, walk over this in a diagram. So we've already done number, we've already done step number one, which is we set up recovery via the front end. We've already done step number two, which is where the relayer emails the guardian to confirm acceptance. Step number three and four is what's happening right now in the live demo, and this is where we've replied to the relayer, the ZKP is being generated, and it's being verified on chain.

Once that's done, so once that's done, some state will be set on our recovery module which says the guardian is accepted. We get a handy email from the relayer to say our request has been acknowledged, and within a few seconds, we should get a successful email, which we have. So back in the recovery UI, I'm going to select another address from MetaMask, and this is the signer we're going to update. So I'm going to paste this in here, and then we're going to start the recovery request.

We're going to be like, yeah, I'm happy, and we're going to reply to that email. You can see the subject here, so that's what you can customize to have uh to improve the UX for your recovery sort of implementation via a subject handler. So we're happy with this. We're just gonna confirm right there. And the same process will be happening, except this time we'll be increasing the number of approvals, and it's gonna meet the threshold, so we're gonna be able to recover our account. So under the hood, we've already seen step number one where we've started the recovery attempt, and again, we've already seen step number two, where we've got an email from the relayer and we've replied to it, and the ZKP is being generated. So very similar to the first part of the flow.

Once that's been verified on chain, it's the it gets approved. We've only got a threshold of one, so we're all good to wrap up the deno the demo and recover our account. So this is where you can call the complete recovery function. This is where you might have your time lock. We only set this to one second, so this is already ready to go. Make a note of this address here. This is 0x free free. It should be changing from 0x91 to 0x free free. So keep an eye on the screen. There we go.

So that is how you recover a safe account via ZK email. And I'm gonna hand over to Ayosh to wrap us up. Sweet. If you wanted to try that demo yourself, feel free to go to approve.email slash recovery and try it out with any knows a safe on Basipolia. I'll leave this up for a moment. We're really excited about the future of this technology. If you're a wallet and you want to support emails in your interface as guardians or as signers, please reach out. We have a telegram link here.

We're happy to support any wallet or DAO that wants to make their flows for users more intuitive. We'll be sponsoring some of the hackathons at ETH Global Brussels. And so if folks want to either integrate this into an existing wallet and get live help from the team on the ground, or you want to try even improving our core uh circuits or ideas, we also have uh both an application track and a research track where folks can try their hand at different circuit optimizations or interesting public goods. Our audits on these systems have started, and they should be completed by the end of July. We're hoping to launch a mainnet in July or August for account recovery, and based on demand for other things at similar times.

Finally, ZK email is much more than just wallet interfaces and recovery and signers. You can actually prove any email in your inbox, including making interesting identity proofs. And so we have a whole line of research around fast client-side proofs, around identity modules, around people building their own attestations from off-chain to on-chain. And if you're interested about that line of work, definitely check out prove.email in which we describe a lot of those flows and we have demos that people can try. For instance, to prove your Twitter username directly on-chain without trusting an intermediary. So thank you for coming, and I'm sure people have lots of questions on how this works, and we're happy to take any questions. What's the main net cost of verifying the ZK proof?

Yeah, so the ZK proof alone without aggregation is about 300,000 gas, and the rest of it, the rest of the operation, it like varies based on the complexity of the wallet recovery from anywhere from 50,000 to like 700,000 if it's a very inefficient chain. Post 4844, this is actually quite cheap. So this is like maybe like an average of 25 cents on like uh an L2 for recovery process. Um second, the moment we've incorporated aggregation, the cost of ZK proof drops by about a factor of 30. And so we expect this to be quite cheap and efficient on-chain when users actually start using it.

Last question, anyone. Um yeah, I had a question about the DKIM key. Um for example, Gmail uses, I guess, one key for everybody. Do you know if they rotate that key? Like, can you tell me more about what you found implementing this? Yeah, that's a great question. Um, so how do we properly rotate the DKIM key when the domain actually rotates their key? And so there's the idea is that that RSA public key is hosted on DNS, and without DNS sec on the majority of domains, uh, you have to somehow relay that public key on chain.

And so the idea is that uh users basically have control to confirm or deny any rotation request on the DKIM signature contract. So the DKM signature contract right now has like various oracles pulling from the DNS key and putting it on chain. But if somebody tries to maliciously screw you over, you can use your own override key to say, oh, I reject this key rotation, or no, I reject this consensus failure between Oracles and I want to trust that Oracle only. And so the idea is uh as long as there's uh different parties posting it on chain and you have this override key, users actually are able to control how that DKIM key rotates, and that only happens every six months to a year. Um and so it's quite infrequent.

And many users who like don't want to trust that overhead can just trust their protocol to confirm the key rotations for them. Uh thank you a lot. Sweet, thank you.

Related talks