{"id":13815949,"url":"https://github.com/zemse/halo2-utils","last_synced_at":"2025-04-03T13:26:55.353Z","repository":{"id":219904217,"uuid":"750203008","full_name":"zemse/halo2-utils","owner":"zemse","description":"some basic utils for halo2","archived":false,"fork":false,"pushed_at":"2024-02-19T11:01:56.000Z","size":115,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-09T02:29:26.760Z","etag":null,"topics":["halo2","zk"],"latest_commit_sha":null,"homepage":"","language":"Rust","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/zemse.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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-01-30T07:23:04.000Z","updated_at":"2024-06-29T08:36:45.000Z","dependencies_parsed_at":"2024-02-19T12:27:36.834Z","dependency_job_id":"dcdfb24f-7ace-4e32-82d9-08d79020f5db","html_url":"https://github.com/zemse/halo2-utils","commit_stats":null,"previous_names":["zemse/halo2-utils"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zemse%2Fhalo2-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zemse%2Fhalo2-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zemse%2Fhalo2-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zemse%2Fhalo2-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zemse","download_url":"https://codeload.github.com/zemse/halo2-utils/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247008511,"owners_count":20868393,"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":["halo2","zk"],"created_at":"2024-08-04T05:00:24.804Z","updated_at":"2025-04-03T13:26:55.321Z","avatar_url":"https://github.com/zemse.png","language":"Rust","funding_links":[],"categories":["Gadgets"],"sub_categories":[],"readme":"# halo2 utils\n\nsome basic utils to slightly improve dx with vanila [pse/halo2](https://github.com/privacy-scaling-explorations/halo2).\n\n## estimate k\n\n```rust\nlet circuit = FactorisationCircuit {\n    a: Fr::from(2),\n    b: Fr::from(3),\n    _marker: std::marker::PhantomData,\n};\n\nhalo2_utils::estimate_k(\u0026circuit)\n```\n\n## print assignments\n\n```rust\nlet circuit = FactorisationCircuit {\n    a: Fr::from(2),\n    b: Fr::from(3),\n    _marker: std::marker::PhantomData,\n};\n\nhalo2_utils::assignments::print_all(4, \u0026circuit);\n```\n\n```\ncargo run --example print_assignment\n\n╭────────────────┬──────────────┬─────────────┬──────────────────╮\n│ unnamed advice │ advice colm  │ my selector │ unnamed instance │\n├────────────────┼──────────────┼─────────────┼──────────────────┤\n│ Unassigned     │ 2            │ 1           │ 6                │\n│ Unassigned     │ 3            │ 0           │ 0                │\n│ Unassigned     │ 6            │ 0           │ 0                │\n│ Unassigned     │ Unassigned   │ 0           │ 0                │\n│ Unassigned     │ Unassigned   │ 0           │ 0                │\n│ Unassigned     │ Unassigned   │ 0           │ 0                │\n│ Unassigned     │ Unassigned   │ 0           │ 0                │\n│ Unassigned     │ Unassigned   │ 0           │ 0                │\n│ Unassigned     │ Unassigned   │ 0           │ 0                │\n│ Unassigned     │ Unassigned   │ 0           │ 0                │\n│ Poisoned(10)   │ Poisoned(10) │ 0           │ 0                │\n╰────────────────┴──────────────┴─────────────┴──────────────────╯\n```\n\n## print info\n\n\n```rust\nlet circuit = FactorisationCircuit::\u003cFr\u003e::default();\nhalo2_utils::info::print(4, \u0026circuit);\n```\n\n```\ncargo run --example print_info\n\nadvice columns: 2\nfixed columns: 1\ninstance columns: 1\nselectors columns: 1\ngates: 1\nlookups: 0\n```\n\n## compare halo2 circuits\n\nCompare all the columns and rows in a huge plonkish table and see what is not matching. This can be helpful to debug in very specific cases where you have two similar circuits and want to make sure second circuit performs assignments exactly as the first circuit.\n\n```rust\nlet circuit1 = ...;\nlet circuit2 = ...;\n\nhalo2_utils::compare::compare_all(\u0026super_circuit, \u0026my_circuit, Some(k));\n```\n\n## infer instance\n\nSometimes we are facing this error `Equality constraint not satisfied by cell (Column('Instance', 0 `. This error is due to incorrect instances passed in the MockProver which do not satisfy the copy constraints.\n\nHence this util infers the values of the instances from the private witnesses using copy constraints and gives you a `Vec\u003cVec\u003cF\u003e\u003e` that you can pass and make MockProver happy temporarily. Note this is only for debugging purposes.\n\n```rust\n let circuit = FactorisationCircuit {\n    a: Fr::from(2),\n    b: Fr::from(3),\n    _marker: std::marker::PhantomData,\n};\nhalo2_utils::infer_instance(\u0026circuit, None)\n// [\n//     [\n//         0x0000000000000000000000000000000000000000000000000000000000000006,\n//     ],\n// ]\n\n```\n\n\n## generate layout diagrams\n\nabstracts some dependencies and auto estimates value of k.\n\n```rust\nuse halo2_utils::LayoutPrinter;\n\nfn main() {\n    let circuit = MyCircuit::\u003cFr\u003e::default();\n    LayoutPrinter::from(\u0026circuit).print();\n}\n```\n\n![example layout](./FactorisationCircuit-layout.png)\n\n## real prover\n\nabstracts r/w kzg params from local files, generating instances, value of k.\n\n```rust\nuse halo2_utils::RealProver;\n\nfn main() {\n    // implements halo2_proofs::plonk::Circuit and halo2_utils::CircuitExt\n    let circuit = FactorizationCircuit {\n        a: Fr::from(3),\n        b: Fr::from(7),\n        _marker: PhantomData,\n    };\n\n    // generate proofs\n    let mut prover = RealProver::from(circuit);\n    let (proof, public_inputs) = prover.run(/* write_to_file: */ true).unwrap();\n\n    // verify proofs\n    let verifier = prover.verifier();\n    let success = verifier.run(proof, public_inputs);\n\n    // yul verifier\n    let code = verifier.generate_yul(/* write_to_file: */ true).unwrap();\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzemse%2Fhalo2-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzemse%2Fhalo2-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzemse%2Fhalo2-utils/lists"}