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-
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.
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
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 |
β 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 β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
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
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
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
β β β
Offer ZK Proof Atomic
Created Verified Swap
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 |
Order book with hidden limit prices
Multi-asset atomic swaps
Privacy pools for liquidity aggregation
Cross-chain confidential bridges
Browser SDK with WebGPU proving
Low Gas Costs: ZK proof verification is expensive; Mantle L2 makes it affordable
EVM Native: Zero modifications needed for deployment
Growing Ecosystem: Privacy is the missing piece in Mantle DeFi
Institutional Alignment: Mantle's treasury focus aligns with our compliance features
<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>---</p><p>## 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>---</p><p>## 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>
<p>N/A</p>