- The zkdai components are based on the latest spec.
- Learn about the ingredients behind ZkDai from ZkDai — Private DAI transactions on Ethereum using Zk-SNARKs.
- The optimistic nature of the contracts is inspired from Optimistic Contracts.
- To mint a zkdai note worth x Dai,
dai.approve
the zkdai contract to movex
tokens. - Generate a zkSnark (using zokrates) with appropriate params. See mintNoteZokcmd.js.
- Send a transaction calling
zkdai.mint
with the proof and send along the required stake. The contract will transferx
Dai tokens from user to itself and save the hash of the proof on-chain. The hash will be saved on-chain instead of the entire proof to save gas. The note is not yet committed. - Before the challenge period ends, a watchful verifier can challenge the proof if the verifier notices that an invalid zkSnark was submitted. This would entail reading the submitted proof from the transaction above and sending it to
zkdai.challenge
. The challenged proof will then be verified. If the the challenge passes, the submitter's stake would be slashed and transferred to the the challenger; if the challenge fails, the zkdai note will be committed and the stake will be returned to the proof submitter. - Alternatively, if the proof remained unchallenged during the challenge period, the submitter can commit the note by calling
zkdai.commit
. - Similarly, to spend a zkdai note, the user would need to generate and submit the zkSnark proof to
zkdai.spend
. See spendNoteZokcmd.js. The challenge and commit phases will follow the same mechanism as above. - At any point, the user can choose to liquidate a zkdai note. The user submits the zkSnark. The contract verifies the proof, marks the note as
Spent
and transfers the equivalent amount of Dai to the specified recepient.
ganache-cli
npm test
Run container
git clone git@github.com:Zokrates/ZoKrates.git
cd ZoKrates
docker build -t zokrates .
docker run --name zokrates -ti zokrates /bin/bash
Setup circuit and export solidity verifier
docker cp circuits/createNote.code zokrates:/home/zokrates/
(in container)
./zokrates compile -i createNote.code
./zokrates setup
./zokrates export-verifier
docker cp zokrates:/home/zokrates/verifier.sol contracts/verifiers/MintNoteVerifier.sol
Generate witness and proof
node scripts/mintNoteZokcmd.js
(in container)
Paste the command printed above in zokrates container (computes witness)
./zokrates generate-proof
docker cp zokrates:/home/zokrates/proof.json test/mintNoteProof.json