diff --git a/Cargo.toml b/Cargo.toml index c15cf949..44a9e6ef 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "chiquito" -version = "0.1.2023101100" +version = "0.1.2023101700" edition = "2021" license = "MIT OR Apache-2.0" authors = ["Leo Lara "] diff --git a/examples/fibonacci.py b/examples/fibonacci.py index 8771191e..4ffa7b31 100644 --- a/examples/fibonacci.py +++ b/examples/fibonacci.py @@ -79,6 +79,8 @@ def trace(self, n): fibo = Fibonacci() fibo_witness = fibo.gen_witness(7) -fibo.halo2_mock_prover(fibo_witness) +fibo.halo2_mock_prover( + fibo_witness, k=7 +) # 2^k specifies the number of PLONKish table rows in Halo2 another_fibo_witness = fibo.gen_witness(4) -fibo.halo2_mock_prover(another_fibo_witness) +fibo.halo2_mock_prover(another_fibo_witness, k=7) diff --git a/examples/mimc7.py b/examples/mimc7.py index a23e78c1..ce3a1ca5 100644 --- a/examples/mimc7.py +++ b/examples/mimc7.py @@ -167,4 +167,4 @@ def mapping(self, x_in_value, k_value): mimc7_super_witness = mimc7.gen_witness(F(1), F(2)) # for key, value in mimc7_super_witness.items(): # print(f"{key}: {str(value)}") -mimc7.halo2_mock_prover(mimc7_super_witness) +mimc7.halo2_mock_prover(mimc7_super_witness, k = 10) diff --git a/src/frontend/python/chiquito/dsl.py b/src/frontend/python/chiquito/dsl.py index 52abfc62..60b45686 100644 --- a/src/frontend/python/chiquito/dsl.py +++ b/src/frontend/python/chiquito/dsl.py @@ -70,7 +70,9 @@ def gen_witness(self: SuperCircuit, *args: Any) -> Dict[int, TraceWitness]: ) # so that we can generate different witness mapping in the next gen_witness() call return super_witness - def halo2_mock_prover(self: SuperCircuit, super_witness: Dict[int, TraceWitness]): + def halo2_mock_prover( + self: SuperCircuit, super_witness: Dict[int, TraceWitness], k: int = 16 + ): for rust_id, witness in super_witness.items(): if rust_id not in self.ast.sub_circuits: raise ValueError( @@ -79,7 +81,7 @@ def halo2_mock_prover(self: SuperCircuit, super_witness: Dict[int, TraceWitness] witness_json: str = witness.get_witness_json() super_witness[rust_id] = witness_json rust_chiquito.super_circuit_halo2_mock_prover( - list(self.ast.sub_circuits.keys()), super_witness + list(self.ast.sub_circuits.keys()), super_witness, k ) @@ -211,12 +213,12 @@ def gen_witness(self: Circuit, *args) -> TraceWitness: def get_ast_json(self: Circuit) -> str: return json.dumps(self.ast, cls=CustomEncoder, indent=4) - def halo2_mock_prover(self: Circuit, witness: TraceWitness): + def halo2_mock_prover(self: Circuit, witness: TraceWitness, k: int = 16): if self.rust_id == 0: ast_json: str = self.get_ast_json() self.rust_id: int = rust_chiquito.ast_to_halo2(ast_json) witness_json: str = witness.get_witness_json() - rust_chiquito.halo2_mock_prover(witness_json, self.rust_id) + rust_chiquito.halo2_mock_prover(witness_json, self.rust_id, k) def __str__(self: Circuit) -> str: return self.ast.__str__() diff --git a/src/frontend/python/mod.rs b/src/frontend/python/mod.rs index 489d7cc9..dcc80985 100644 --- a/src/frontend/python/mod.rs +++ b/src/frontend/python/mod.rs @@ -83,6 +83,7 @@ fn add_assignment_generator_to_rust_id( pub fn chiquito_super_circuit_halo2_mock_prover( rust_ids: Vec, super_witness: HashMap, + k: usize, ) { let mut super_circuit_ctx = SuperCircuitContext::::default(); @@ -114,7 +115,7 @@ pub fn chiquito_super_circuit_halo2_mock_prover( let circuit = ChiquitoHalo2SuperCircuit::new(compiled, super_assignments); - let prover = MockProver::::run(10, &circuit, circuit.instance()).unwrap(); + let prover = MockProver::::run(k as u32, &circuit, circuit.instance()).unwrap(); let result = prover.verify_par(); @@ -138,7 +139,7 @@ fn rust_id_to_halo2(uuid: UUID) -> CircuitMapStore { /// Runs `MockProver` for a single circuit given JSON of `TraceWitness` and `rust_id` of the /// circuit. -pub fn chiquito_halo2_mock_prover(witness_json: &str, rust_id: UUID) { +pub fn chiquito_halo2_mock_prover(witness_json: &str, rust_id: UUID, k: usize) { let trace_witness: TraceWitness = serde_json::from_str(witness_json).expect("Json deserialization to TraceWitness failed."); let (_, compiled, assignment_generator) = rust_id_to_halo2(rust_id); @@ -147,7 +148,7 @@ pub fn chiquito_halo2_mock_prover(witness_json: &str, rust_id: UUID) { assignment_generator.map(|g| g.generate_with_witness(trace_witness)), ); - let prover = MockProver::::run(7, &circuit, circuit.instance()).unwrap(); + let prover = MockProver::::run(k as u32, &circuit, circuit.instance()).unwrap(); let result = prover.verify_par(); @@ -1827,15 +1828,16 @@ fn ast_to_halo2(json: &PyString) -> u128 { } #[pyfunction] -fn halo2_mock_prover(witness_json: &PyString, rust_id: &PyLong) { +fn halo2_mock_prover(witness_json: &PyString, rust_id: &PyLong, k: &PyLong) { chiquito_halo2_mock_prover( witness_json.to_str().expect("PyString convertion failed."), rust_id.extract().expect("PyLong convertion failed."), + k.extract().expect("PyLong convertion failed."), ); } #[pyfunction] -fn super_circuit_halo2_mock_prover(rust_ids: &PyList, super_witness: &PyDict) { +fn super_circuit_halo2_mock_prover(rust_ids: &PyList, super_witness: &PyDict, k: &PyLong) { let uuids = rust_ids .iter() .map(|rust_id| { @@ -1864,7 +1866,11 @@ fn super_circuit_halo2_mock_prover(rust_ids: &PyList, super_witness: &PyDict) { }) .collect::>(); - chiquito_super_circuit_halo2_mock_prover(uuids, super_witness) + chiquito_super_circuit_halo2_mock_prover( + uuids, + super_witness, + k.extract().expect("PyLong convertion failed."), + ) } #[pymodule]