Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zemse/halo2-utils
some basic utils for halo2
https://github.com/zemse/halo2-utils
halo2 zk
Last synced: about 1 month ago
JSON representation
some basic utils for halo2
- Host: GitHub
- URL: https://github.com/zemse/halo2-utils
- Owner: zemse
- Created: 2024-01-30T07:23:04.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2024-02-19T11:01:56.000Z (11 months ago)
- Last Synced: 2024-10-29T03:04:57.522Z (3 months ago)
- Topics: halo2, zk
- Language: Rust
- Homepage:
- Size: 112 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-halo2 - halo2-utils
README
# halo2 utils
some basic utils to slightly improve dx with vanila [pse/halo2](https://github.com/privacy-scaling-explorations/halo2).
## estimate k
```rust
let circuit = FactorisationCircuit {
a: Fr::from(2),
b: Fr::from(3),
_marker: std::marker::PhantomData,
};halo2_utils::estimate_k(&circuit)
```## print assignments
```rust
let circuit = FactorisationCircuit {
a: Fr::from(2),
b: Fr::from(3),
_marker: std::marker::PhantomData,
};halo2_utils::assignments::print_all(4, &circuit);
``````
cargo run --example print_assignment╭────────────────┬──────────────┬─────────────┬──────────────────╮
│ unnamed advice │ advice colm │ my selector │ unnamed instance │
├────────────────┼──────────────┼─────────────┼──────────────────┤
│ Unassigned │ 2 │ 1 │ 6 │
│ Unassigned │ 3 │ 0 │ 0 │
│ Unassigned │ 6 │ 0 │ 0 │
│ Unassigned │ Unassigned │ 0 │ 0 │
│ Unassigned │ Unassigned │ 0 │ 0 │
│ Unassigned │ Unassigned │ 0 │ 0 │
│ Unassigned │ Unassigned │ 0 │ 0 │
│ Unassigned │ Unassigned │ 0 │ 0 │
│ Unassigned │ Unassigned │ 0 │ 0 │
│ Unassigned │ Unassigned │ 0 │ 0 │
│ Poisoned(10) │ Poisoned(10) │ 0 │ 0 │
╰────────────────┴──────────────┴─────────────┴──────────────────╯
```## print info
```rust
let circuit = FactorisationCircuit::::default();
halo2_utils::info::print(4, &circuit);
``````
cargo run --example print_infoadvice columns: 2
fixed columns: 1
instance columns: 1
selectors columns: 1
gates: 1
lookups: 0
```## compare halo2 circuits
Compare 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.
```rust
let circuit1 = ...;
let circuit2 = ...;halo2_utils::compare::compare_all(&super_circuit, &my_circuit, Some(k));
```## infer instance
Sometimes 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.
Hence this util infers the values of the instances from the private witnesses using copy constraints and gives you a `Vec>` that you can pass and make MockProver happy temporarily. Note this is only for debugging purposes.
```rust
let circuit = FactorisationCircuit {
a: Fr::from(2),
b: Fr::from(3),
_marker: std::marker::PhantomData,
};
halo2_utils::infer_instance(&circuit, None)
// [
// [
// 0x0000000000000000000000000000000000000000000000000000000000000006,
// ],
// ]```
## generate layout diagrams
abstracts some dependencies and auto estimates value of k.
```rust
use halo2_utils::LayoutPrinter;fn main() {
let circuit = MyCircuit::::default();
LayoutPrinter::from(&circuit).print();
}
```![example layout](./FactorisationCircuit-layout.png)
## real prover
abstracts r/w kzg params from local files, generating instances, value of k.
```rust
use halo2_utils::RealProver;fn main() {
// implements halo2_proofs::plonk::Circuit and halo2_utils::CircuitExt
let circuit = FactorizationCircuit {
a: Fr::from(3),
b: Fr::from(7),
_marker: PhantomData,
};// generate proofs
let mut prover = RealProver::from(circuit);
let (proof, public_inputs) = prover.run(/* write_to_file: */ true).unwrap();// verify proofs
let verifier = prover.verifier();
let success = verifier.run(proof, public_inputs);// yul verifier
let code = verifier.generate_yul(/* write_to_file: */ true).unwrap();
}
```