Git Product home page Git Product logo

optimistic-zkdai's Introduction

optimistic-zkdai

Lifecycle of a zkdai note

  • To mint a zkdai note worth x Dai, dai.approve the zkdai contract to move x 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 transfer x 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.

Tests

ganache-cli
npm test

Development

zokrates

Run container

git clone [email protected]: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

optimistic-zkdai's People

Contributors

atvanguard avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.