This project demonstrates privacy-preserving token accounting (Zether) on BabyJub with Circom proofs.
- The implementation is based on this paper: https://eprint.iacr.org/2019/191.pdf (page 13)
- Solidity contracts:
contracts/BasicZether.sol,contracts/BabyJub.sol,contracts/Verifier/Verifier.sol - Circom circuits and proving artifacts:
circom/ - TypeScript client helpers:
client/ - Hardhat tests:
test/
- Install dependencies
npm install- Compile contracts
npx hardhat compile- Run tests
npx hardhat testOptional: start a local node
npx hardhat node- Node.js 18+
- npm (or pnpm/yarn)
- For circuit work:
circomandsnarkjs(seecircom/README)
- Epoch-based accounting: pending changes are applied when the next epoch starts (
epochLengthblocks). - ZK transfers/burns: Circom proofs attest to valid balance updates without revealing amounts.
- Access control: accounts can be locked to an EOA; unlocking removes the restriction.
Key parameters
DECIMALS: on-chain precision (e.g., 4)MAX: total supply cap2^32 - 1
Pre-built artifacts for transfer/burn are included under circom/. To rebuild or modify circuits, follow the circom/README and accompanying Makefile:
# inside ./circom
make compile name=circom-file-name
make power power=power name=circom-file-name
make solidity name=circom-file-name
make witness name=circom-file-name # requires inputs/<name>_input.json
make proof name=circom-file-name
make verifyIf you regenerate the solidity verifier, ensure contracts/Verifier/Verifier.sol reflects the latest output.
contracts/— Solidity sourcescircom/— circuits, proving/verifying keys, wasm, Makefileclient/— helper utilities for proofs and contract callstest/— Hardhat tests for fund/transfer/burn/lock-unlock and epochs
# Compile contracts
npx hardhat compile
# Run tests with gas report / coverage (if configured)
npx hardhat test
# Start local node
npx hardhat node- After funding, balances move from
pending→accat the next epoch. - Transfers debit the sender immediately; the receiver is credited after the next epoch.
- Burns schedule balance reduction that applies after the next epoch.
- Locking restricts who can initiate actions for a Zether public key; unlocking removes it.
- Reinstall deps if TypeScript types are missing:
rm -rf node_modules package-lock.json && npm install- If circuit files change, rebuild artifacts in
circom/, then recompile contracts. - Ensure Node.js 18+ and recent
hardhat.