{"id":16517853,"url":"https://github.com/erhant/circomkit-examples","last_synced_at":"2025-05-06T14:31:06.830Z","repository":{"id":174804653,"uuid":"650669195","full_name":"erhant/circomkit-examples","owner":"erhant","description":"Circom circuits such as SHA256, float-add and Fibonacci, developed with Circomkit.","archived":false,"fork":false,"pushed_at":"2024-01-27T18:37:23.000Z","size":174,"stargazers_count":7,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-12T16:33:55.541Z","etag":null,"topics":["circom","circuit","example","toolkit","zero-knowledge"],"latest_commit_sha":null,"homepage":"https://github.com/erhant/circomkit","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/erhant.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-06-07T14:53:10.000Z","updated_at":"2024-10-04T18:14:48.000Z","dependencies_parsed_at":"2024-01-27T19:39:02.538Z","dependency_job_id":"610cfce8-ce05-4228-a4b9-09db955149da","html_url":"https://github.com/erhant/circomkit-examples","commit_stats":null,"previous_names":["erhant/circomkit-examples"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erhant%2Fcircomkit-examples","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erhant%2Fcircomkit-examples/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erhant%2Fcircomkit-examples/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erhant%2Fcircomkit-examples/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/erhant","download_url":"https://codeload.github.com/erhant/circomkit-examples/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224509497,"owners_count":17323077,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["circom","circuit","example","toolkit","zero-knowledge"],"created_at":"2024-10-11T16:34:00.142Z","updated_at":"2024-11-13T19:07:08.516Z","avatar_url":"https://github.com/erhant.png","language":"TypeScript","readme":"# Circomkit Examples\n\nIn this repository, we are using [Circomkit](https://github.com/erhant/circomkit) to test some example circuits using Mocha. The circuits and the statements that they prove are as follows:\n\n- **Multiplier**: \"I know `n` factors that make up some number\".\n- **Fibonacci**: \"I know the `n`'th Fibonacci number\".\n- **SHA256**: \"I know the `n`-byte preimage of some SHA256 digest\".\n- **Sudoku**: \"I know the solution to some `(n^2)x(n^2)` Sudoku puzzle\".\n- **Floating-Point Addition**: \"I know two floating-point numbers that make up some number with `e` exponent and `m` mantissa bits.\" (adapted from [Berkeley ZKP MOOC 2023 - Lab](https://github.com/rdi-berkeley/zkp-mooc-lab)).\n\n## CLI Usage\n\nTo use Circomkit CLI with a circuit, let's say for Sudoku 9x9, we follow the steps below:\n\n1. We write a circuit config in `circuits.json` with the desired parameters. In this case, we are working with the 9x9 Sudoku solution circuit, and the board size is calculated by the square of our template parameter so we should give 3. Furthermore, `puzzle` is a public input so we should specify that too.\n\n```json\n{\n  \"sudoku_9x9\": {\n    \"file\": \"sudoku\",\n    \"template\": \"Sudoku\",\n    \"pubs\": [\"puzzle\"],\n    \"params\": [3]\n  }\n}\n```\n\n2. Compile the circuit with Circomkit, providing the same circuit name as in `circuits.json`:\n\n```sh\nnpx circomkit compile sudoku_9x9\n\n# print circuit info if you want to\nnpx circomkit info sudoku_9x9\n```\n\n3. Commence circuit-specific setup. Normally, this requires us to download a Phase-1 PTAU file and provide it's path; however, Circomkit can determine the required PTAU and download it automatically when using `bn128` curve, thanks to [Perpetual Powers of Tau](https://github.com/privacy-scaling-explorations/perpetualpowersoftau). In this case, `sudoku_9x9` circuit has 4617 constraints, so Circomkit will download `powersOfTau28_hez_final_13.ptau` (see [here](https://github.com/iden3/snarkjs#7-prepare-phase-2)).\n\n```sh\nnpx circomkit setup sudoku_9x9\n\n# alternative: provide the PTAU yourself\nnpx circomkit setup sudoku_9x9 \u003cpath-to-ptau\u003e\n```\n\n4. Prepare your input file under `./inputs/sudoku_9x9/default.json`.\n\n```json\n{\n  \"solution\": [\n    [1, 9, 4, 8, 6, 5, 2, 3, 7],\n    [7, 3, 5, 4, 1, 2, 9, 6, 8],\n    [8, 6, 2, 3, 9, 7, 1, 4, 5],\n    [9, 2, 1, 7, 4, 8, 3, 5, 6],\n    [6, 7, 8, 5, 3, 1, 4, 2, 9],\n    [4, 5, 3, 9, 2, 6, 8, 7, 1],\n    [3, 8, 9, 6, 5, 4, 7, 1, 2],\n    [2, 4, 6, 1, 7, 9, 5, 8, 3],\n    [5, 1, 7, 2, 8, 3, 6, 9, 4]\n  ],\n  \"puzzle\": [\n    [0, 0, 0, 8, 6, 0, 2, 3, 0],\n    [7, 0, 5, 0, 0, 0, 9, 0, 8],\n    [0, 6, 0, 3, 0, 7, 0, 4, 0],\n    [0, 2, 0, 7, 0, 8, 0, 5, 0],\n    [0, 7, 8, 5, 0, 0, 0, 0, 0],\n    [4, 0, 0, 9, 0, 6, 0, 7, 0],\n    [3, 0, 9, 0, 5, 0, 7, 0, 2],\n    [0, 4, 0, 1, 0, 9, 0, 8, 0],\n    [5, 0, 7, 0, 8, 0, 0, 9, 4]\n  ]\n}\n```\n\n5. We are ready to create a proof!\n\n```sh\nnpx circomkit prove sudoku_9x9 default\n```\n\n6. We can then verify our proof. You can try and modify the public input at `./build/sudoku_9x9/default/public.json` and see if the proof verifies or not!\n\n```sh\nnpx circomkit verify sudoku_9x9 default\n```\n\n## In-Code Usage\n\nIf you would like to use Circomkit within the code itself, rather than the CLI, you can see the example at `src/index.ts`. You can `yarn start` to see it in action.\n\n```ts\n// create circomkit\nconst circomkit = new Circomkit({\n  protocol: \"groth16\",\n});\n\n// artifacts output at `build/multiplier_3` directory\nawait circomkit.compile(\"multiplier_3\", {\n  file: \"multiplier\",\n  template: \"Multiplier\",\n  params: [3],\n});\n\n// proof \u0026 public signals at `build/multiplier_3/my_input` directory\nawait circomkit.prove(\"multiplier_3\", \"my_input\", { in: [3, 5, 7] });\n\n// verify with proof \u0026 public signals at `build/multiplier_3/my_input`\nconst ok = await circomkit.verify(\"multiplier_3\", \"my_input\");\nif (ok) {\n  circomkit.log(\"Proof verified!\", \"success\");\n} else {\n  circomkit.log(\"Verification failed.\", \"error\");\n}\n```\n\n## Configuration\n\nCircomkit checks for `circomkit.json` to override it's default configurations. We could for example change the target version, prime field and the proof system by setting `circomkit.json` to be:\n\n```json\n{\n  \"version\": \"2.1.2\",\n  \"protocol\": \"plonk\",\n  \"prime\": \"bls12381\"\n}\n```\n\n## Testing\n\nYou can use the following commands to test the circuits:\n\n```sh\n# test everything\nyarn test\n\n# test a specific circuit\nyarn test -g \u003ccircuit-name\u003e\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferhant%2Fcircomkit-examples","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ferhant%2Fcircomkit-examples","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferhant%2Fcircomkit-examples/lists"}