-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
64 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Factors | ||
|
||
The hello world app of ZK: prove you know a factorization of `n` without revealing the factors. | ||
|
||
## Setup | ||
- You must have nix and some recent version of node. | ||
- You should have a local ethereum node with an unlocked default account and the web3 api running on the default port `8545`. E.g. use hardhat or [cliquebait](https://github.com/f-o-a-m/cliquebait) | ||
|
||
## Contents | ||
|
||
|
||
### The factors zk program | ||
A ZK program written in a Haskell DSL that expresses a factorization of a public input `n` into a product of secret inputs `a` and `b`. You can produce a circom compatible `r1cs` file for this program by running | ||
|
||
``` | ||
> cabal run factors | ||
``` | ||
|
||
### A factors program constraint solver | ||
A constraint solver applied to the `factors` program. You can produce a circom compatible WASM binary for this solver by running | ||
|
||
``` | ||
> cd factors-solver | ||
> ./build-wasm | ||
``` | ||
|
||
### A Groth16 Solidity Verifying contract | ||
Assuming you have run the above, you should see a `circuit.r1cs` file in the `trusted-setup` directory. To produce a final proving key and solidity verifier: | ||
|
||
``` | ||
> npx snarkjs groth16 setup trusted-setup/circuit.r1cs trusted-setup/pot14_final.ptau trusted-setup/circuit_final.zkey | ||
> npx snarkjs zkey export solidityverifier trusted-setup/circuit_final.zkey contracts/Groth16Verifier.sol | ||
``` | ||
|
||
You can verify your proving key: | ||
|
||
``` | ||
> npx snarkjs zkey verify trusted-setup/circuit.r1cs trusted-setup/pot14_final.ptau trusted-setup/circuit_final.zkey | ||
``` | ||
|
||
You can comple the contracts, build the purescript ffi, and deploy this smart contract via | ||
|
||
``` | ||
> npm run chanterelle-build | ||
> npm run chanterelle-deploy | ||
``` | ||
|
||
### A frontend application | ||
Assuming you have done the previous steps, copy the proving key to the `www` folder | ||
|
||
``` | ||
> cp trusted-setup/circuit_final.zkey www | ||
``` | ||
|
||
You should see the `circuit.wasm` solver binary is already there. Assuming you have deployed the verifying contract, you can start the frontend: | ||
|
||
``` | ||
export VERIFIER_ADDRESS=$(jq -r '.networks."420123".address' build/contracts/Groth16Verifier.json) && npm run parcel | ||
``` | ||
|
||
NOTE: I used cliquebaite to write this readme, which has networkId/chainId `420123`. If you have a different chainId, you will need to subsitute it in the above command or just find the address in the artifact manually. | ||
|
||
You should see a form load to test the application |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file was deleted.
Oops, something went wrong.