Relayer Infrastructure
An overview of the relayer infrastructure for Email Wallet, and how to set it up.
Last updated
An overview of the relayer infrastructure for Email Wallet, and how to set it up.
Last updated
The Relayer, a crucial system component, bridges email communication and blockchain transactions, ensuring secure information processing.
Below is a diagram of the Relayer infrastructure and its component interactions.
To build the Relayer, you need to understand its three main components:
SMTP Server: The entry point for emails, which the Relayer monitors for incoming messages that trigger blockchain transactions.
Relayer: The core service that listens for emails from the SMTP server, communicates with the Prover to verify proofs, and then writes the validated transactions to the blockchain.
Prover: A separate service that the Relayer relies on to verify and create zk proofs of the data extracted from emails.
Database (DB): A PostgreSQL database to store account information, facilitating checks on whether an account already exists within the system.
Before building the Relayer, ensure that you have the following prerequisites installed:
Node.js and npm
Python 3
Docker
Rust and Cargo (with build-essential
or equivalent for your operating system)
For Ubuntu users, you can install build-essential
by running:
For macOS users, you can install the necessary tools by installing Xcode Command Line Tools:
☞ Running locally
To run the prover locally, follow these steps:
Prepare the Environment: Ensure your system has Node.js, npm, and Python 3 installed. The prover relies on specific npm packages and Python modules to function correctly.
Install Global npm Packages: Install snarkjs globally using npm.
Install Python Requirements: Navigate to the prover directory and install the required Python packages listed in requirements.txt.
Run the curl commands and script in the prover/local_setup.sh
file.
Start the prover
☞ Using Modal
The prover leverages Modal, a cost-effective, serverless computing platform activated as needed, for generating zk proofs. Visit site here: https://modal.com
Set Up Modal Tokens: Follow the instructions in /Relayer.Dockerfile
to set up your Modal tokens.
Start the Prover Service: Run the following command to start the Prover service using Modal:
Database Setup Steps:
Start PostgreSQL Database:
Set Environment Variable: In .env
:
Note: The system triggers on emails with accountKey
in the subject, for new account setups. Reply-email functionality for account transport will be deprecated.
Create a .env
file in packages/relayer
by taking a copy from .env.example
.
Update the .env
file
For local development
Production(x86 compatibility):
Running the Relayer
Start the Docker Container: Launch the Relayer service in a Docker container with the following command:
Update Contract ABIs: Ensure the contract ABIs are up to date in packages/relayer/abi/
directory.
Register the relayer on chain by running:
This step registers the relayer's details on the blockchain, preparing it for operation.
Start the relayer:
You can test by sending an email to your relayer account with a subject like Send 1 ETH to another@email.com
. Relayer will deploy wallet for you for the first time and you will need to fund it externally as the wallet have no balance.
For local development
For x86 compatibility(e.g. For production)
Create .env
in the execution directory with reference to env_example
.
The Relayer's incentive is transaction fees collected from the sender. Specifically, the Relayer operator can set a fee per gas in wei to the ENV file. However, that value must be less maxFeePerGas
parameter defined in our contract, which is 2 gwei now.
When the Relayer posts the email-triggered transaction along with the ZK proof of email, our contract calculates the total amount of fee in wei as follows:
If the transaction does not pass the validation function validateEmailOp
, the fee is zero.
The contract measures the consumed gas when executing the transaction.
The gas to refund ERC20 tokens, 55000 gas, is added to 2.
If the transaction specifies a recipient's email address, 450000 and 500000 gas are added to 3 for ERC20 tokens transfer and the other use cases, respectively.
The total amount of fee in wei is the multiplication between the fee per gas set by the relayer and the total gas in 4.
Note that our contract catches any errors during the execution of the transaction in Step 2 instead of making the transaction fail because the Relayer cannot always simulate if the execution returns errors in general cases before posting it on-chain. Therefore, the Relayer can always collect the fee as long as the transaction passes the validation in Step 1. This design refers to the bundler's fee mechanism in ERC-4337.