sCrypt-Inc / scryptTS-docs

https://docs.scrypt.io
12 stars 8 forks source link

Improve zkp tutorial #118

Closed xhliu closed 1 year ago

xhliu commented 1 year ago

Only generate a file, not a directory

It will be simpler to integrate, as verifier.scrypt. It should be a library, not a contract. Write another contract to test, as ZKSNARKTest in https://xiaohuiliu.medium.com/create-your-first-zero-knowledge-proof-program-on-bitcoin-ec159cc501f4 https://github.com/sCrypt-Inc/scryptTS-docs/blob/a599a5319a01118900c6d18a9d3f7d20ac622f06/docs/tutorials/zk-snark.md?plain=1#L139

Rename G16BN256

-> SNARK as before. This is a tutorial, so no need to introduce the intricacies & details.

Hardcode VerifyingKey into the library

verify() should be a static method as ZKSNARK.verify(inputs, proof) before, so no new is needed. Let's follow the previous article, unless u have reasons not to.

Remove test

from https://scrypt.io/docs/tutorials/zkp#7-run-the-scrypt-verifier. Just write a single script like deploy.ts.

Link to github

in Conclusion, so people can read the full zkp code.

Update Learn

image

https://learn.scrypt.io/en/courses/Build-a-zkSNARK-based-Battleship-Game-on-Bitcoin-64187ae0d1a6cb859d18d72a/lessons/4/chapters/1

msinkec commented 1 year ago

Regarding "Hardcode VerifyingKey into the library": It now isn't directly used by the library because of precalc of miller loop. This was previously done in a very hacky crude way by the snark libraries. But now we can do it by directly calling sCrypt functions locally. Makes things a lot easier and flexible.

Maybe instead of exposing the miller precalc directly to the user, we could wrap it in a single function, something like:

const vk: VerifyingKey = prepareVerfyingKey(VERIFYING_KEY_DATA)

which should make it simple enough.

msinkec commented 1 year ago

Only generate a file, not a directory

It will be simpler to integrate, as verifier.scrypt.

Not at all, especially since we have all the ASM optimization stuff that comes with it.