ZkDai — Private DAI transactions on Ethereum using Zk-SNARKs

ZkDai Implementation

Note = (pk, v)

Spending a ZkDai note

  1. Ownership of the secret key (sk) that corresponds to the public key (pk) that a note belongs to.
  2. Value of the note
C(sk, v) = h
where h = Hash(Note) and is publicly known
sk, v are private inputs
N1 = (receiverPk, v’) and
N2 = (pk, v — v’)
C(oldNote, newNote1, newNote2, sk, v, receiverPk, v’, change)
where oldNote, newNote1, newNote2 are public inputs.
C(oldNote, newNote1, newNote2, sk, v, receiverPk, v’, change) {
pk = computePublicKeyfromSecret(sk)
oldNote == sha256(pk, v)
v == v’ + change
newNote1 == sha256(receiverPk, v’)
newNote2 == sha256(pk, change)
return 1

Implementing the zkSNARK on Ethereum

git clone https://github.com/JacobEberhardt/ZoKrates
cd ZoKrates
docker build -t zokrates .
docker run — name zokrates -ti zokrates /bin/bash
  • The keyword field is the basic type we use, which is an element of a given prime field. A field value can only hold 254 bits due to the size of the underlying prime field we are using.
  • The keyword private signals that we do not want to reveal this input, but still prove that we know its value.
  • sha256packed — A function that takes 4 field elements as inputs, unpacks each of them to 128 bits (big endian), concatenates them and applies sha256. It then returns two field elements, each representing 128 bits of the result. sha256packed is a SHA256 implementation that is optimized for the use in the ZoKrates DSL.
./zokrates compile -i zk-circuit.codeCompiling zk-circuit.code...
Compiled code written to ‘out’
Number of constraints: 165257
‘0x3644B986B3F5Ba3cb8D5627A22465942f8E06d09’, // sender
‘0xb’, // value of the secret note
‘0x9e8f633D0C46ED7170EF3B30E291c64a91a49C7E’, // receiver
‘0x9’ // value to be sent
./zokrates compute-witness -a 232310020822901034104762510965330293111 290107346578087637545360782727286918188 910473606 239207701314920212136923811659422657801 0 11 210219292964116369102883671286459321076 227322991366389551999749449849806758625 2660197181 16319012648326391858874240100255177854 0 9 42022122505097917127364068979301637648 120910671520054972343429929459551033400 0 2




Building @HubbleExchange

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

“Dialogue with the most popular Game-Fi projects on OEC” AMA Recap

Oddz Collaborates With Konomi

Is Gonzaga an NFT?

COSS.IO June 20th, 2018 updates

New listing on KickEX exchange: Binance Coin (BNB)

How ACH works: A developer perspective — Part 2

The Hashrate Gap between BCH and BSV is Widening, and A Large Number of TRON-Based DApps Enter the…

Elven Gets Into Partnership With Doracakeswap

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


Building @HubbleExchange

More from Medium

SpaceShard x StarkWare

MINA Protocol — Beginners guide to Ouroboros Samasika Consensus protocol #1

News with VIA #9✌️

Building for a Permissionless future