Skip to content

lambdaclass/ethrex_l2_hub

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

86 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ethrex L2 Hub

Overview

A full-stack demonstration of Ethrex L2, showcasing a Layer 2 rollup solution with bridge capabilities and account abstraction features. This React-based frontend allows users to:

  • Bridge assets between L1 and L2 (deposit, withdraw, claim)
  • Use Account Abstraction to mint and transfer tokens with passkey authentication (fingerprint/biometrics)
  • Interact with Ethrex Rollup without complex wallet management

Prerequisites

Before starting, ensure you have the following installed:

  • Node.js v21+ (Download)
  • npm (comes with Node.js)
  • Solc - v0.8.29
  • Rex - Utility tool for debugging and interacting with Ethereum. Install here

Setup and Deployment

Follow these steps to get the entire system running.

Phase 1: Ethrex Setup

  1. Clone ethrex
git clone https://github.com/lambdaclass/ethrex.git && cd ethrex
  1. Checkout the branch required for this project
git checkout test_sponsor
  1. Build ethrex
export COMPILE_CONTRACTS=true && cargo build --bin ethrex --release --manifest-path Cargo.toml --features l2,l2-sql
  1. Start L1 and L2

This command will:

  • Start the L1 on port 8545
  • Deploy L1 contracts (Bridge, OnChainProposer, Verifier)
  • Start the L2 on port 1729

If you want to use the account abstraction feature, you need to create a txt file with the addresses of the contract you want to sponsor. You

target/release/ethrex l2 --dev --no-monitor --sponsorable-addresses <YOUR_SPONSORABLE_ADDRESSES_FILE>

Wait for the chains to fully initialize. You should see logs indicating both L1 (port 8545) and L2 (port 1729) are running. The deployment will also fund test accounts with ETH.

  1. Initialize the Prover

In a new terminal window, run:

./ethrex l2 prover --backend exec --proof-coordinators tcp://127.0.0.1:3900

Keep this terminal running. The prover must stay active for the L2 to function properly. Without it, withdrawals cannot be finalized.

Phase 2: Deploy the Hub App

  1. Configure environment variables

In another terminal window, in the root of the project, run:

cp app/.env.example app/.env
  1. Deploy smart contracts

Important

Running the following command requires a rex version that supports compiling contracts and outputting JSON ABI files. To install this version run the following commands:

git clone https://github.com/lambdaclass/rex.git
cd rex
git checkout add_abi_json_flag
make cli

This deploys two contracts to the L2:

  • Delegation: Enables account abstraction with passkey authentication
  • TestToken: ERC-20 token for testing transfers
make deploy

After deployment, you'll see output with contract addresses. Copy these addresses:

Deployed Delegation to: 0x...
Deployed TestToken to: 0x...
  1. Update environment variables

Edit app/.env and update the following variables with the addresses from step 7:

VITE_DELEGATION_CONTRACT_ADDRESS=0x... # Address from Delegation deployment
VITE_TEST_TOKEN_CONTRACT_ADDRESS=0x... # Address from TestToken deployment
  1. Run the frontend

The app should now be running at http://localhost:5173

make run-front

Features

L1 ↔ L2 Bridge

Transfer assets between the L1 and L2 chains:

  • Deposit: Move ETH from L1 to L2 for faster and cheaper transactions
  • Withdraw: Initiate a withdrawal from L2 back to L1
  • Claim: Finalize and claim your withdrawal on L1 (after proof generation)

The bridge ensures secure asset transfers by locking funds on one chain and minting/releasing them on the other.

Account Abstraction with Passkeys

Experience transactions using biometric authentication:

  • Mint Tokens: Create tokens on L2 using your device's fingerprint or Face ID
  • Transfer Tokens: Send tokens to other addresses without traditional wallet signatures
  • Passkey Authentication: Uses WebAuthn (device biometrics) instead of private keys

This feature leverages:

  • EIP-7702: Account delegation for enabling smart contract functionality on EOAs
  • RIP-7212: secp256r1 curve precompile for efficient passkey signature verification

Usage

Connecting Your Wallet

  1. Open the app in your browser (http://localhost:5173)
  2. Click Connect Wallet
  3. Approve the connection in MetaMask or your preferred Web3 wallet

Using the Bridge

To Deposit (L1 → L2):

Note

You will need to have some ETH in your L1 wallet to be able to deposit. You can use the rich account to transfer ETH to your wallet. rex send 0xb9d9ede845d349369eef96ef8e853b2cda387d88 --value 100000000000000000000 --private-key 0x941e103320615d394a55708be13e45994c7d93b932b064dbcb2b511fe3254e2e --rpc-url http://localhost:8545 This will transfer 100 ETH to your wallet.

  1. Navigate to the /bridge/deposit page
  2. Enter the amount of ETH to transfer
  3. Confirm the transaction in your wallet
  4. Wait for the transaction to be processed on both L1 and L2

To Withdraw (L2 → L1):

  1. Navigate to the /bridge/withdraw page
  2. Enter the amount to withdraw
  3. Submit the withdrawal request
  4. Wait for the L2 block to be proven (Search for a)

To Claim Withdrawal:

  1. After your withdrawal is proven, you will be able to claim it by clicking on the "Claim Withdrawal" button
  2. Your funds will be released on L1

Using Account Abstraction

Note

You will need to add the Delegation address to a file in ethrex/crates/l2/sponsorable.txt. This allows the Delegation contract to sponsor transactions for you.

  1. Navigate to the /passkey_demo page
  2. Create Account: Click to create a new account with passkey authentication
    • You'll be prompted to use your device's biometric authentication
  3. Mint Tokens: Enter an amount and mint tokens using your passkey
  4. Transfer Tokens: Enter a recipient address and amount to transfer
    • No gas fees required! Transactions are sponsored by the Delegation contract

Debugging with Rex

Rex is a CLI tool that helps you debug and interact with your L1 and L2 chains. Here are some useful commands:

# Check the transaction receipt for error details
rex receipt <DEPLOYMENT_TX_HASH> <RPC_URL>

# Check the code of a contract
rex code <CONTRACT_ADDRESS> <RPC_URL>

# Verify L2 is producing blocks
rex block-number <L2_RPC_URL>

# Check balance
rex balance <YOUR_ADDRESS> <RPC_URL>

Contributing

Feel free to submit pull requests or open issues for bug fixes and feature suggestions.

References and acknowledgements

The following links, repos, companies and projects have been important in the development of this repo, we have learned a lot from them and want to thank and acknowledge them.

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages