Skip to content
View Anoxchange's full-sized avatar

Block or report Anoxchange

Block user

Prevent this user from interacting with your repositories and sending you notifications. Learn more about blocking users.

You must be logged in to block users.

Maximum 250 characters. Please don't include any personal information such as legal names or email addresses. Markdown supported. This note will be visible to only you.
Report abuse

Contact GitHub support about this user’s behavior. Learn more about reporting abuse.

Report abuse
anoxchange/README.md

πŸ›‘οΈ P2P ZK Anoxchange

A secure, anonymous, and scalable peer-to-peer token exchange system powered by zkSNARK proofs and on-chain withdrawal rights management.


🎯 Goal

Build a privacy-preserving P2P exchange (e.g., USDT) that protects users from tracking, using zkSNARK-based zero-knowledge proofs and Merkle tree commitments.


🧱 Architecture

Component Purpose
P2PManager.sol Smart contract managing deposits, withdrawals, and P2P requests
verifier.sol Verifies zkSNARK proofs generated on the client side
Merkle Tree Commitments tree (Poseidon hash) stored on-chain
zk-Circuit Groth16 proof system verifying nullifier, secret, recipient
CLI Tools Scripts for deposit, requestWithdraw, and withdraw
note.json Stores note details: nullifier, secret, amount, commitment, root

πŸ” Privacy with zkSNARK

The Groth16 zkSNARK scheme ensures:

  • The user knows the nullifier and secret for an existing commitment
  • The note has not been used (nullifierHash unused)
  • The note belongs to the current Merkle root
  • The recipient can be chosen freely

πŸ‘‰ All without revealing the nullifier, secret, amount, or sender.


πŸ” Usage Flow

1. Deposit

  • User generates a note {nullifier, secret}
  • Creates a commitment: Poseidon(nullifier, secret)
  • Calls P2PManager.deposit(commitment, amount)
  • Commitment is added to Merkle tree and tokens deposited
  • πŸ“ Note saved in JSON, shareable via private channel

2. P2P Note Transfer

  • Send the note to a buyer via Session, QR, or messenger
  • Buyer pays in fiat, USDT, or another method

3. Request Withdraw (Optional)

requestWithdraw(commitment, recipientAddress)
  • Locks withdrawal rights for a recipient
  • Includes expiration (expiresAt) for automatic release if unpaid

4. Withdraw

  • Buyer generates Merkle proof + zkSNARK proof

  • Calls withdraw() with proof, root, nullifierHash, recipient

  • Contract:

    • Verifies proof via verifier.sol
    • Ensures note not spent before
    • Checks reservation (recipient, expiresAt) if set
    • Sends tokens to recipient
    • Marks nullifierHash as spent

βœ… Fraud Protection

Fraud Attempt Protection
Double-spending a note nullifierHash valid only once
Linking deposit to withdrawal zkSNARK hides all details
Seller attempts to withdraw note requestWithdraw() locks recipient
Buyer reserves note but doesn’t pay expiresAt auto-expires reservation

πŸ§ͺ Deployment (MVP)

Step 1. Compile zk-Circuit

cd circuits/
snarkjs groth16 setup mixer.r1cs pot12_final.ptau mixer.zkey
snarkjs zkey export verificationkey mixer.zkey verification_key.json
snarkjs zkey export solidityverifier mixer.zkey verifier.sol

Step 2. Deploy Contracts

forge script script/Deploy.s.sol --rpc-url http://localhost:8545 --broadcast

Step 3. Generate Note

ts-node cli/deposit.ts

Step 4. Request Withdraw (Optional)

ts-node cli/requestWithdraw.ts note.json recipient_address

Step 5. Withdraw Funds

ts-node cli/withdraw.ts note.json

πŸ“¦ Project Structure

p2p-mixer/
β”œβ”€β”€ contracts/
β”‚   β”œβ”€β”€ P2PManager.sol
β”‚   └── verifier.sol
β”œβ”€β”€ circuits/
β”‚   └── mixer.circom
β”œβ”€β”€ cli/
β”‚   β”œβ”€β”€ deposit.ts
β”‚   β”œβ”€β”€ requestWithdraw.ts
β”‚   └── withdraw.ts
β”œβ”€β”€ notes/
β”‚   └── note_<timestamp>.json
β”œβ”€β”€ test/
β”‚   └── P2P.t.sol
└── README.md

πŸ”œ Upcoming Features

Feature Status
🧾 Note encryption (PGP/QR) ⏳
βŒ› Time-lock (cheque system) πŸ”œ
βš–οΈ Fee via nominal amount πŸ”œ
πŸ“± React GUI + QR support πŸ”œ
πŸ”„ Batch transfers πŸ”œ
🧩 NFT-based ownership proofs πŸ”œ

πŸ’‘ Contributions and ideas are welcome!

Popular repositories Loading

  1. anoxchange anoxchange Public

    Solidity

  2. axelar-configs axelar-configs Public

    Forked from axelarnetwork/axelar-configs

    No description

    TypeScript

  3. assets assets Public

    Forked from trustwallet/assets

    A comprehensive, up-to-date collection of information about several thousands (!) of crypto tokens.

    Go

  4. ecdsa-leakage-attack ecdsa-leakage-attack Public

    Forked from JinghuiWW/ecdsa-leakage-attack

    Attacking ECDSA with nonce leakage using lattice-based algorithms

    Python