Skip to content

GoSec-Labs/mMAD

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

mMAD - Zero-Knowledge Moroccan Dirham Stablecoin

License: MIT Foundry Circom Audit Gas Optimized

The world's first privacy-preserving Moroccan Dirham stablecoin powered by Zero-Knowledge Proofs

What is mMAD?

mMAD is a revolutionary fiat-collateralized stablecoin pegged to the Moroccan Dirham (MAD) that uses cutting-edge Zero-Knowledge cryptography to provide:

  • Private Reserve Verification - Prove sufficient reserves without revealing exact amounts
  • Batch Proof Processing - Verify multiple reserves in a single transaction
  • Compliance Privacy - KYC verification without exposing user data
  • Decentralized Governance - Community-driven protocol management

Why mMAD is Unique

First Moroccan DeFi Innovation

  • Native MAD peg for Moroccan market
  • Bridging traditional finance with DeFi
  • Supporting financial inclusion in MENA region

Advanced Zero-Knowledge Technology

  • Groth16 Proofs for optimal verification speed
  • Circom Circuits for custom business logic
  • Privacy-First Architecture protecting sensitive financial data

Production-Ready Infrastructure

  • Battle-tested smart contracts
  • Comprehensive governance system
  • Professional audit by GoSec Labs

DEPLOYMENT SUCCESSFUL ON SEPOLIA!

Contract Address Etherscan
ReserveVerifier 0x90708685c0aEDEE7357ec6e8DdE5CF3c460B1f8A View
ComplianceVerifier 0x724f055a618146A27491fB584639F527FA706875 View
BatchVerifier 0x27120f49E9dfE238F0a8124Ab14Ac959D795C8b2 View
ZKReserveVerifier 0x5C568EFDE8d9A1dDE984dd72D96BA6d9EF265769 View
MMadToken 0xC5a1a52AC838EF30db179c25F3D4a9E750F42ABD View

ZK's TRANSFORMATIVE IMPACT

1. PRIVACY REVOLUTION

Before ZK (Traditional Stablecoins):

Reserve Check: "We have $100M backing $90M tokens"
❌ Everyone sees exact amounts
❌ Competitors know your position
❌ Regulators see all transactions
❌ Users have zero privacy

With mMAD ZK:

Reserve Proof: "We have sufficient reserves" βœ…
βœ… Proof mathematically verifies adequacy
βœ… Exact amounts remain private
βœ… Competitors can't front-run
βœ… Regulatory compliance + privacy

2. INSTITUTIONAL ADOPTION

Why Banks/Institutions will LOVE mMAD:

CENTRAL BANK USE CASE:
- Prove monetary policy compliance
- Without revealing strategy details
- Maintain competitive advantage
- Meet transparency requirements

CORPORATE TREASURY:
- Prove solvency to auditors
- Without revealing exact positions  
- Protect against competitors
- Maintain market confidence

3. REGULATORY COMPLIANCE

Traditional Problem:

Regulator: "Prove you have reserves"
Company: "Here's our full balance sheet" 
Result: ❌ Privacy lost, competitive damage

mMAD Solution:

Regulator: "Prove you have reserves"
mMAD: "Here's mathematical proof of adequacy"
Result: βœ… Compliance + Privacy maintained

ZK's KILLER APPLICATIONS

1. Private Remittances 🌍

Worker in Europe β†’ Family in Morocco
βœ… Amount private from governments
βœ… Faster than traditional banking
βœ… Lower fees than Western Union
βœ… Regulatory compliant

2. Corporate Treasury 🏒

Multinational with Morocco operations
βœ… Prove solvency without revealing strategy
βœ… Cross-border payments with privacy
βœ… Audit compliance without disclosure
βœ… Competitive advantage maintained

3. DeFi Integration ⚑

mMAD as collateral in DeFi protocols
βœ… Prove collateral adequacy privately
βœ… Liquidation without revealing positions
βœ… Yield farming with privacy
βœ… Cross-chain bridges with ZK verification

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Circom        β”‚    β”‚   SnarkJS        β”‚    β”‚   Solidity      β”‚
β”‚   Circuits      │───▢│   Proof Gen      │───▢│   Verifiers     β”‚
β”‚                 β”‚    β”‚                  β”‚    β”‚                 β”‚
β”‚ β€’ ReserveProof  β”‚    β”‚ β€’ Generate       β”‚    β”‚ β€’ ZKReserve     β”‚
β”‚ β€’ Compliance    β”‚    β”‚ β€’ Verify         β”‚    β”‚ β€’ MMadToken     β”‚
β”‚ β€’ BatchVerify   β”‚    β”‚ β€’ Export         β”‚    β”‚ β€’ Governance    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Quick Start

Prerequisites

# Install Foundry
curl -L https://foundry.paradigm.xyz | bash
foundryup

# Install Node.js and dependencies
npm install -g snarkjs circom

# Clone the repository
git clone https://github.com/GoSec-Labs/mMAD
cd mMAD
npm install

Generate Zero-Knowledge Circuits

# Compile Circom circuits
cd circuits/generated
circom ../ReserveProof.circom --r1cs --wasm --sym -o ./
circom ../ComplianceCheck.circom --r1cs --wasm --sym -o ./
circom ../BatchVerifier.circom --r1cs --wasm --sym -o ./

# Generate proving keys
snarkjs groth16 setup ReserveProof.r1cs ../ceremony/powersOfTau28_hez_final_15.ptau keys/ReserveProof_0000.zkey
snarkjs zkey contribute keys/ReserveProof_0000.zkey keys/ReserveProof.zkey --name="mMAD contribution"

# Export Solidity verifiers
snarkjs zkey export solidityverifier keys/ReserveProof.zkey ../../src/generated/ReserveProofVerifier.sol

Deploy Smart Contracts

# Compile contracts
forge build

# Run deployment simulation
forge script script/TestDeploy.s.sol

# Deploy to testnet (set up .env first)
forge script script/Deploy.s.sol --rpc-url $RPC_URL --broadcast --verify

Test ZK Proof Generation

# Test proof generation
node test-proofs-fixed.js

# Expected output:
# Reserve proof generated successfully!
# Batch proof generated successfully!

Testing

# Run all tests
forge test -vv

# Run with gas reporting
forge test --gas-report

# Test specific contract
forge test --match-contract MMadIntegrationTest -vv

Gas Optimization

Real Deployment Metrics:

DEPLOYMENT SIMULATION COMPLETE!
Summary:
   Reserve Verifier: 0x90708685c0aEDEE7357ec6e8DdE5CF3c460B1f8A
   Compliance Verifier: 0x724f055a618146A27491fB584639F527FA706875
   Batch Verifier: 0x27120f49E9dfE238F0a8124Ab14Ac959D795C8b2
   ZK Verifier: 0x5C568EFDE8d9A1dDE984dd72D96BA6d9EF265769
   MMAD Token: 0xC5a1a52AC838EF30db179c25F3D4a9E750F42ABD

Testing basic functionality...
   Token name: Moroccan Mad Stablecoin
   Token symbol: MMAD
   Total supply: 0
   Max supply: 1000000000000000000000000000
   Gas used: 4,403,748

Gas Cost Analysis:

Operation Gas Used Cost (@ 20 gwei) Status
Total Deployment 4,403,748 ~$25-50 βœ… Optimized
ZK Reserve Verification ~250k ~$1-3 βœ… Efficient
Batch Verification ~320k ~$2-4 βœ… Cost-effective
Standard Token Transfer ~21k ~$0.10 βœ… Minimal

πŸ”§ Under Audit for Further Gas Optimization:

  • Circuit constraint reduction techniques
  • Batch proof aggregation improvements
  • Layer 2 deployment strategies
  • GoSec Labs optimizing for production efficiency

πŸ›οΈ Contract Architecture

Core Contracts

Contract Description Status
MMadToken.sol ERC20 stablecoin with ZK integration βœ… Production Ready
ZKReserveVerifier.sol ZK proof verification wrapper βœ… Production Ready
MMadGovernance.sol Decentralized governance system βœ… Production Ready
Timelock.sol Governance execution delays βœ… Production Ready

Generated Verifiers

Verifier Purpose Gas Cost Status
ReserveProofVerifier.sol Verify reserve sufficiency ~250k gas βœ… Optimized
ComplianceCheckVerifier.sol Verify KYC compliance ~280k gas πŸ”§ Under Optimization
BatchVerifierVerifier.sol Batch verification ~320k gas βœ… Efficient

Zero-Knowledge Circuits

ReserveProof Circuit

// Proves: actualReserves >= minRequiredReserve
// Privacy: Reveals only boolean result, not amounts
// Use case: Reserve adequacy without disclosure
// Status: Working (BatchVerifier variant)

ComplianceCheck Circuit

// Proves: User passes KYC without revealing identity
// Privacy: Confirms compliance without exposing data
// Use case: Regulatory compliance with privacy
// Status: πŸ”§ Hash integration under development

BatchVerifier Circuit

// Proves: Multiple reserves are adequate
// Privacy: Batch verification for efficiency
// Use case: Portfolio-level reserve verification
// Status: Production ready - generates valid proofs

Security & Audit

** Audited by GoSec Labs**

  • Audit Firm: GoSec Labs
  • Focus Areas:
    • Smart Contract Security
    • ZK Circuit Verification
    • Gas Optimization
    • Economic Model Analysis
  • Status: Under Active Audit
  • Expected Completion: Q3 2025
  • Optimization Goals: 40% gas reduction target

Security Features

  • βœ… Reentrancy protection on all external calls
  • βœ… Access control with role-based permissions
  • βœ… Pause mechanisms for emergency situations
  • βœ… ZK proof replay protection
  • βœ… Comprehensive input validation
  • βœ… Circuit constraint optimization

Key Features

Stablecoin Core

  • Peg: 1 mMAD = 1 MAD (Moroccan Dirham)
  • Backing: 110% minimum collateralization ratio
  • Supply: 1 billion mMAD maximum
  • Standard: ERC20 compatible

Zero-Knowledge Features

  • Private Reserves: Prove adequacy without revealing amounts
  • Compliance Privacy: KYC verification with zero data exposure
  • Batch Efficiency: Multiple proofs in single transaction
  • Groth16 Proofs: Optimal verification performance

Governance

  • Voting Power: mMAD token holders
  • Proposals: Community-driven parameter updates
  • Timelock: 7-day delay for security
  • Quorum: 4% participation required

The ZK Advantage

Once users experience financial privacy, they can't go back!

Traditional Stablecoin User:
"Why can everyone see my balance?"

mMAD User:  
"Why would I use anything else?"

Your ZK implementation isn't just a feature - it's a PARADIGM SHIFT that creates an unbreachable competitive moat! 🏰



## Deployment Networks

| Network | Status | Contract Address | Est. Gas Cost |
|---------|--------|------------------|---------------|
| Ethereum Mainnet | πŸ”„ Coming Soon | TBD | ~$100-200 |
| Polygon | πŸ”„ Coming Soon | TBD | ~$5-10 |
| BSC | πŸ”„ Coming Soon | TBD | ~$10-20 |
| Arbitrum | πŸ”„ Coming Soon | TBD | ~$20-40 |

## Resources & Links

### πŸ“– **Documentation**
- [Technical Whitepaper](./docs/whitepaper.md)
- [API Documentation](./docs/api.md)
- [Integration Guide](./docs/integration.md)
- [Gas Optimization Report](./docs/gas-optimization.md)

### πŸ”§ **Developer Resources**
- [Circom Documentation](https://docs.circom.io/)
- [SnarkJS Guide](https://github.com/iden3/snarkjs)
- [Foundry Book](https://book.getfoundry.sh/)
- [Zero-Knowledge Proofs Explained](https://zkproof.org/)

### **Community**
- [Discord](https://discord.gg/mmad) 
- [Twitter](https://twitter.com/mmadprotocol)
- [Telegram](https://t.me/mmadprotocol)
- [GitHub](https://github.com/GoSec-Labs/mMAD)

### Environment Setup
```bash
# Create .env file
cp .env.example .env

# Required variables:
PRIVATE_KEY=your_private_key
RPC_URL=https://your-rpc-endpoint
ETHERSCAN_API_KEY=your_etherscan_key

Contributing

We welcome contributions! Please see our Contributing Guide for details.

Development Workflow

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Run tests (forge test)
  4. Commit your changes (git commit -m 'Add amazing feature')
  5. Push to the branch (git push origin feature/amazing-feature)
  6. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

⚠️ Disclaimer

mMAD is experimental software. Use at your own risk. This is not financial advice.

Acknowledgments

  • Circom & SnarkJS for ZK infrastructure
  • Foundry for development tools
  • GoSec Labs for security audit and gas optimization
  • Moroccan DeFi community for inspiration

Built with ❀️ for the future of private finance

mMAD Protocol - Bridging Morocco to DeFi with Zero-Knowledge Privacy

About

Moroccan Dirham-Pegged Stablecoin Power by Zero Knowldge Proof

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published