Skip to content

Commit

Permalink
added readme
Browse files Browse the repository at this point in the history
  • Loading branch information
martyall committed Apr 20, 2024
1 parent 1376c37 commit d116e71
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 1 deletion.
63 changes: 63 additions & 0 deletions README.md
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"scripts": {
"postinstall": "spago -x bootstrap.dhall build --deps-only",
"chanterelle-build": "spago -x bootstrap.dhall run -m ChanterelleMain --node-args=\"build\"",
"chanterelle-deploy": "npx spago -x spago-deploy.dhall run -m Deploy.Main",
"build": "spago build",
"parcel": "parcel www/* --no-cache",
"tidy": "purs-tidy format-in-place \"src/**/*.purs\" \"test/**/*.purs\"",
Expand Down
Binary file removed www/circuit_final.zkey
Binary file not shown.
1 change: 0 additions & 1 deletion www/input.json

This file was deleted.

0 comments on commit d116e71

Please sign in to comment.