9

I've asked that question on some places, got a few answers but I'm still missing the bigger piece. I'd like to experiment with zk-snarks. In particular, I'd like to be able to do something similar to this tutorial, i.e., write a program to prove some computation based on a pair of public and secret values, such as:

function senderFunction(x, w) {
  return (
    w.senderBalanceBefore > w.value &&
    sha256(w.value) == x.hashValue &&
    sha256(w.senderBalanceBefore) == x.hashSenderBalanceBefore &&
    sha256(w.senderBalanceBefore - w.value) == x.hashSenderBalanceAfter
  )
}
var proof = zksnarkprove(
    confTxSenderPk,
    senderFunction,
    [hashSenderBalanceBefore, hashSenderBalanceAfter, hashValue],
    [senderBalanceBefore, senderBalanceAfter, hashValue]);

And then be able to verify the correctness of this computation without knowing w from inside an Ethereum contract, for example:

zksnarkverify(
    confTxSenderVk, 
    [hashSenderBalanceBefore, hashSenderBalanceAfter, hashValue],
    zkProofSender)

Is there anything already implemented that allows me to experiment with this usage?

5

Please find the zksnarks solidity code:

https://gist.github.com/chriseth/f9be9d9391efc5beb9704255a8e2989d

The transaction can be seen on Etherscan and was made on the testnet.

4
+50

My answer is a fairly dumb one, as I've only had a look around in the code, and I haven't looked into zk-SNARKs properly yet, so apologies in advance if it's no help.

The cpp-ethereum implementation contains the libdevcrypto library, which itself contains LibSnark.cpp. This seems to be built into a separate project with its own cmake file, and there's a set of associated unit test files. There doesn't seem to be anything in any of the other clients (including Parity).

The test file I linked to contains this comment, which would imply something is working at least...

// This verifies a full zkSNARK proof. Let's see if this hocus-pocus actually works...

  • 1
    It's in the development pipeline, and will likely be there through 2017. – Todd Baur Jul 15 '17 at 8:29
  • @Richard please can you advise, how to use in my smart contact? Do I need any extra setup for this? – Parwej Jul 4 '18 at 17:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.