Front End Guide

Overview

The frontend application provides a user interface for:

  • Shielded Deposits: Move tokens into the private pool

  • Private Transfers: Send tokens privately between shielded addresses

  • Withdrawals: Exit the shielded pool back to public addresses

  • Treasury Rates: Real-time yield data from DeFi protocols

Note: All private transactions use Pedersen commitments for amount hiding, stealth addresses for recipient hiding, and SP1 zkVM proofs for validity.

Getting Started

Prerequisites

  • Node.js 18+

  • pnpm (recommended) or npm

Installation

pnpm install

Setting Up Mantle Sepolia Testnet

Before running the app, you need to add the Mantle Sepolia Testnet to your wallet:

Option 1: Automatic (via Chainlist)

  1. Search for "Mantle Sepolia"

  2. Click "Add to Wallet" and approve the request

Option 2: Manual Configuration

Add the network manually in your wallet (e.g., MetaMask) with these settings:

Field
Value

Network Name

Mantle Sepolia Testnet

RPC URL

https://rpc.sepolia.mantle.xyz

Chain ID

5003

Currency Symbol

MNT

Block Explorer URL

https://explorer.sepolia.mantle.xyz

Getting Mock Tokens (mUSDT)

To test deposits, you'll need some mock USDT tokens on Mantle Sepolia. Follow these steps to mint mUSDT:

  1. Navigate to the mUSDT contract on MantleScan: Mock USDT Contractarrow-up-right

  2. Click "Connect to Web3" to connect your wallet

  3. Find the mint function and enter:

    • to: Your wallet address

    • amount: The amount to mint (in wei). For example, 10000000000000000000000 for 10,000 mUSDT

  4. Click "Write" and confirm the transaction in your wallet

Once the transaction is confirmed, the mUSDT tokens will appear in your wallet and can be used for testing deposits.

Development

Open your browser at http://localhost:3000 and click Launch Now to access the shielded DEX.

Build

Architecture

Wallet SDK (/src/wallet-sdk/)

The wallet SDK provides all cryptographic and blockchain interactions:

Module
Purpose

wallet.ts

Main PrivacyWallet class combining all functionality

commitment.ts

Pedersen commitment generation and verification

keyDerivation.ts

View/spend key derivation from wallet signatures

stealthAddress.ts

Stealth address generation for private receiving

merkleTree.ts

Client-side Merkle tree for tracking commitments

contractService.ts

Smart contract interaction wrapper

Key Generation Flow

When a user connects their wallet, the following happens:

  1. SP1 Environment Init: Initialize privacy context for ZK operations

  2. Sign Message: User signs a message to derive privacy keys

  3. Key Derivation: Extract view and spend keys from signature using keccak256

  4. Stealth Address: Compute receiving address from public keys

  5. Chain Sync: Fetch existing notes from contract events

User Flows

Deposit Flow

  1. Input: User selects token and amount

  2. Approve: ERC20 approval for the Gelap contract

  3. Deposit: Generate commitment, call contract

  4. Success: Note stored locally, balance updated

Withdrawal Flow

  1. Select Notes: Choose UTXOs to spend

  2. Amount: Enter withdrawal amount

  3. Confirm: Generate ZK proof (via prover service)

  4. Success: Public funds received

Smart Contract Integration

Contract Address (Mantle Sepolia)

Key Functions

Events to Track

Event
Description

AccountUpdated(bytes32 commitment, bytes encryptedMemo)

New note created

TransactionExecuted(...)

Private transaction completed

WithdrawExecuted(address receiver, ...)

Withdrawal completed

Hooks

usePrivacyWallet

Main hook for privacy wallet state:

useTreasuryRates

Fetch live yield rates from DeFiLlama:

useContractEvents

Subscribe to contract events:

Environment Variables

Create a .env.local file in the project root:

Getting WalletConnect Project ID

  1. Sign up or log in

  2. Click "Create Project"

  3. Enter project name (e.g., "Gelap Privacy")

  4. Select "App" as project type

  5. Copy the Project ID from the dashboard

  6. Paste it in your .env.local file

Prover Service Integration

Withdrawals and private transfers require ZK proofs from the SP1 prover service.

Expected API Endpoints

Request Body

Response

Merkle Tree Specification

The client-side Merkle tree must match the on-chain implementation:

Property
Value

Hash Function

keccak256

Tree Depth

32 levels

Node Index

(level << 32) | index

Zero Hash[0]

keccak256(abi.encodePacked(uint256(0)))

Commitment Format

Pedersen commitments are used for amount hiding:

Where:

  • H = Secondary generator point on secp256k1

  • G = Standard generator point

  • blinding = Random 32-byte scalar

Local Storage

The wallet persists state to localStorage:

Testing

Manual Testing Checklist

Build Verification

Troubleshooting

RPC Errors (503)

If you see "no backends available":

  • Check you're on the correct network (Mantle Sepolia for testnet)

  • Contract may not be deployed on mainnet yet

Signature Rejected

If wallet generation fails:

  • User rejected the signature request

  • Click "Retry Generation" button

Prover Unavailable

Withdrawals require a running prover service:

  • Set NEXT_PUBLIC_PROVER_API_URL in .env.local

  • Mock proofs are used in development

Last updated