hackquest logo

ZEX-Swap

ZexERC is a privacy-preserving decentralized exchange protocol that enables confidential token swaps using zero-knowledge proofs and homomorphic encryption. Built as an extension of the Encrypted ERC-

Videos

Description

Project Description

ZexERC is a privacy-preserving decentralized exchange protocol that enables confidential token swaps using zero-knowledge proofs and homomorphic encryption. Built as an extension of the Encrypted ERC-20 (eERC) standard, ZexERC allows users to trade tokens peer-to-peer while keeping transaction amounts completely hidden from blockchain observers.

The Problem

In current DeFi ecosystems, all transaction data is publicly visible on-chain. This creates several critical issues:

  • Front-running attacks: MEV bots can see pending large trades and exploit them

  • Privacy leaks: Anyone can track wallet balances and trading patterns

  • Institutional hesitation: Large traders avoid DeFi due to information exposure

  • Targeted attacks: Visible whale wallets become targets for hackers

Our Solution

ZexERC introduces a novel Confidential Allowance Model for peer-to-peer trading that keeps all amounts encrypted while still allowing trustless, on-chain verification through ZK proofs.

Key Features:

Feature

Description

πŸ”’ Hidden Balances

All token balances are encrypted using ElGamal encryption on the BabyJubJub curve

πŸ” Confidential Approvals

Approve spending without revealing the amount to anyone except the spender

πŸ”„ Private Swaps

Execute token swaps where only the participants know the traded amounts

βœ… ZK Verification

All operations are validated by Groth16 zk-SNARK proofs

πŸ“‹ Compliance Ready

Optional auditor integration for regulatory requirements

⛓️ Fully On-Chain

No relayers, mixers, or off-chain components needed

How It Works

β”‚ ZexERC Swap Protocol β”‚

β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€

β”‚ 1. INITIATE: Alice creates offer (rate public, amounts hidden)β”‚

β”‚ 2. ACCEPT: Bob generates ZK proof that his amount is valid β”‚

β”‚ 3. FINALIZE: Atomic swap executes with encrypted balances β”‚

β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Technical Stack

  • Blockchain: EVM-compatible (Mantle L2)

  • Smart Contracts: Solidity 0.8.27

  • ZK Circuits: Circom 2.1.9 with Groth16 proving system

  • Cryptography: BabyJubJub curve, ElGamal encryption, Poseidon hash

  • Testing: Hardhat, Chai, 97% test coverage


Key Innovations

1. Dual Approval System

We implemented two approval mechanisms:

  • Confidential Approve (EOAβ†’EOA): Amount encrypted for spender only

  • Public Confidential Approve (EOAβ†’Contract): Amount disclosed to enable contract logic

2. PCT (Private Ciphertext Token) System

A novel approach to encrypted balance management:

  • Enables receivers to decrypt their incoming amounts

  • Maintains full privacy from blockchain observers

  • Includes auditor PCT for compliance without revealing to public

3. Three-Phase Swap Protocol

↓ ↓ ↓

Offer ZK Proof Atomic

Created Verified Swap


Metrics & Achievements

Metric

Value

Lines of Solidity

~1,500 new lines

ZK Circuits

5 new circuits

Test Coverage

97%

Gas (Private Transfer)

~947k

Gas (Swap Finalization)

~800k


Future Roadmap

  • Order book with hidden limit prices

  • Multi-asset atomic swaps

  • Privacy pools for liquidity aggregation

  • Cross-chain confidential bridges

  • Browser SDK with WebGPU proving


Why Mantle?

  1. Low Gas Costs: ZK proof verification is expensive; Mantle L2 makes it affordable

  2. EVM Native: Zero modifications needed for deployment

  3. Growing Ecosystem: Privacy is the missing piece in Mantle DeFi

  4. Institutional Alignment: Mantle's treasury focus aligns with our compliance features

Progress During Hackathon

<p># Work Completed During Hackathon</p><p>1. ZexERC Smart Contract Extension</p><p><strong>File:</strong> <code data-inline="true" spellcheck="false">contracts/ZexERC.sol</code> (~900 lines)</p><p>Extended the base <code data-inline="true" spellcheck="false">EncryptedERC</code> contract with the following functionality:</p><p>- <strong>confidentialApprove()</strong> </p><p> Approve tokens to EOAs with hidden (encrypted) amounts.</p><p>- <strong>publicConfidentialApprove()</strong> </p><p> Approve tokens to contracts with disclosed amounts.</p><p>- <strong>confidentialTransferFrom()</strong> </p><p> Spend from encrypted allowances.</p><p>- <strong>initiateOffer()</strong> </p><p> Create peer-to-peer (P2P) swap offers.</p><p>- <strong>acceptOffer()</strong> </p><p> Accept offers with zero-knowledge proof validation.</p><p>- <strong>finalizeSwap()</strong> </p><p> Execute atomic swaps with finalization proofs.</p><p>- <strong>cancelConfidentialAllowance()</strong> </p><p> Revoke approvals using a zero-knowledge proof.</p><p>---<br><br>2. Zero-Knowledge Circuits</p><p><strong>Directory:</strong> <code data-inline="true" spellcheck="false">circom/</code></p><p>Designed and implemented <strong>five new ZK circuits</strong>:</p><p>| Circuit File | Constraints | Purpose |</p><p>|-------------------------------------|-------------|----------------------------------------------|</p><p>| <code data-inline="true" spellcheck="false">confidential_approve.circom</code> | ~15k | Prove approval amount ≀ balance |</p><p>| <code data-inline="true" spellcheck="false">confidential_transfer_from.circom</code>| ~18k | Prove spend amount ≀ allowance |</p><p>| <code data-inline="true" spellcheck="false">cancel_allowance.circom</code> | ~8k | Prove ownership for allowance cancellation |</p><p>| <code data-inline="true" spellcheck="false">offer_acceptance.circom</code> | ~12k | Prove amount ≀ maximum offer amount |</p><p>| <code data-inline="true" spellcheck="false">offer_finalization.circom</code> | ~14k | Prove correct exchange rate computation |</p><p>Each circuit verifies:</p><p>- Public key ownership (proof of knowledge of private key)</p><p>- Balance or allowance sufficiency via range proofs</p><p>- Correct encryption of amounts for recipients</p><p>- Auditor PCT generation for compliance</p><p>---</p><p>3. Verifier Contracts</p><p><strong>Directory:</strong> <code data-inline="true" spellcheck="false">contracts/verifiers/</code></p><p>Auto-generated Solidity verifier contracts from the ZK circuits:</p><p>- <code data-inline="true" spellcheck="false">ConfidentialApproveCircuitGroth16Verifier.sol</code></p><p>- <code data-inline="true" spellcheck="false">ConfidentialTransferFromCircuitGroth16Verifier.sol</code></p><p>- <code data-inline="true" spellcheck="false">CancelAllowanceCircuitGroth16Verifier.sol</code></p><p>- <code data-inline="true" spellcheck="false">OfferAcceptanceCircuitGroth16Verifier.sol</code></p><p>- <code data-inline="true" spellcheck="false">OfferFinalizationCircuitGroth16Verifier.sol</code></p><p>---</p><p>4. Interface Definitions</p><p><strong>Directory:</strong> <code data-inline="true" spellcheck="false">contracts/interfaces/</code></p><p>Created clean and modular interface contracts:</p><p>- <code data-inline="true" spellcheck="false">IZexERC.sol</code> β€” Main ZexERC interface</p><p>- <code data-inline="true" spellcheck="false">IConfidentialApproveVerifier.sol</code></p><p>- <code data-inline="true" spellcheck="false">IConfidentialTransferFromVerifier.sol</code></p><p>- <code data-inline="true" spellcheck="false">IOfferAcceptanceVerifier.sol</code></p><p>- <code data-inline="true" spellcheck="false">IOfferFinalizationVerifier.sol</code></p><p>---</p><p>5. Test Suites</p><p><strong>Directory:</strong> <code data-inline="true" spellcheck="false">test/</code></p><p>Implemented comprehensive test coverage:</p><p>- *<code data-inline="true" spellcheck="false">ZexERC.ts</code>** </p><p> Unit tests for all <code data-inline="true" spellcheck="false">ZexERC</code> functions (~34 KB)</p><p>- *<code data-inline="true" spellcheck="false">ZexERC-E2E.ts</code>** </p><p> End-to-end swap lifecycle tests with real ZK proofs (~19 KB)</p><p>- *<code data-inline="true" spellcheck="false">zex-helpers.ts</code>** </p><p> Utilities for zero-knowledge proof generation and testing (~10 KB)</p><p>---<br><br>6. Deployment Scripts</p><p><strong>File:</strong> <code data-inline="true" spellcheck="false">scripts/deploy-zex.ts</code></p><p>Production-ready deployment script that:</p><p>- Deploys all base and ZEX-specific verifier contracts</p><p>- Deploys the BabyJubJub cryptographic library</p><p>- Deploys the Registrar for user key management</p><p>- Deploys <code data-inline="true" spellcheck="false">ZexERC</code> with all dependencies correctly linked</p><p></p>

Tech Stack

React
Web3
Ethers
Node
Solidity
Circom
Next
Rust

Fundraising Status

<p>N/A</p>

Team LeaderGGautam Kumar
Sector
DeFiOtherInfraNFT

Builders Also Viewed