Generate and Verify Proof (#5)

* deleted rust code but before adding submodule

* added submodule for steve/frontend branch; updated lib.rs bindings

* formatted documents

* updated submodule and tests

* changes before splitting to multiple files

* resolved circular reference and formatted files

* fixed uuid and untied constraint builder functions from Constraint type

* minor

* fmt

* initial commit'

* added disable_q_enable, updated expose, and created new json standards

* minor

* minor typo

* generate proof from halo2 using python; pragma first and last step are bugging out in fibo

* formatting things

* updated submodule
This commit is contained in:
Steve Wang
2023-07-25 10:59:40 +08:00
committed by GitHub
parent 236304a118
commit 0c191b1bcf
5 changed files with 42 additions and 7 deletions

1
.gitmodules vendored
View File

@@ -1,3 +1,4 @@
[submodule "src/chiquito"]
path = src/chiquito
url = https://github.com/privacy-scaling-explorations/chiquito

View File

@@ -65,11 +65,13 @@ class CircuitContext:
self: CircuitContext, step_type_context: StepTypeContext
) -> None:
self.circuit.first_step = step_type_context.step_type.id
print(f"first step id: {step_type_context.step_type.id}")
def pragma_last_step(
self: CircuitContext, step_type_context: StepTypeContext
) -> None:
self.circuit.last_step = step_type_context.step_type.id
print(f"last step id: {step_type_context.step_type.id}")
def pragma_num_steps(self: CircuitContext, num_steps: int) -> None:
self.circuit.num_steps = num_steps

View File

@@ -7,6 +7,8 @@ import rust_chiquito # rust bindings
from dsl import CircuitContext, StepTypeContext, StepTypeSetupContext
from chiquito_ast import StepType, First, Last, Step
from cb import eq
from chiquito_ast import StepType, First, Last, Step
from cb import eq
from query import Queriable
from wit_gen import TraceContext, StepInstance, TraceGenerator
@@ -28,11 +30,12 @@ class Fibonacci(CircuitContext):
self.pragma_first_step(self.fibo_step)
self.pragma_last_step(self.fibo_last_step)
self.pragma_disable_q_enable()
self.pragma_num_steps(11)
# self.pragma_disable_q_enable()
self.expose(self.b, First())
self.expose(self.a, Last())
self.expose(self.a, Step(1))
# self.expose(self.b, First())
# self.expose(self.a, Last())
# self.expose(self.a, Step(1))
def trace(self: Fibonacci):
def trace_def(ctx: TraceContext, _: Any): # Any instead of TraceArgs
@@ -135,3 +138,7 @@ print(
"Call rust bindings, parse json to Chiquito TraceWitness, and print using Debug trait:"
)
rust_chiquito.convert_and_print_trace_witness(trace_witness_json)
print("Parse json to Chiquito Halo2, and obtain UUID:")
ast_uuid: int = rust_chiquito.ast_to_halo2(circuit_json)
print("Verify ciruit with ast uuid and trace witness json:")
rust_chiquito.verify_proof(trace_witness_json, ast_uuid)

View File

@@ -1,6 +1,13 @@
use chiquito::{ast::Circuit, wit_gen::TraceWitness};
use chiquito::{
ast::Circuit,
frontend::pychiquito::{chiquito_ast_to_halo2, chiquito_verify_proof},
wit_gen::TraceWitness,
};
use halo2_proofs::halo2curves::bn256::Fr;
use pyo3::{prelude::*, types::PyString};
use pyo3::{
prelude::*,
types::{PyLong, PyString},
};
#[pyfunction]
fn convert_and_print_ast(json: &PyString) {
@@ -18,9 +25,27 @@ fn convert_and_print_trace_witness(json: &PyString) {
println!("{:?}", trace_witness);
}
#[pyfunction]
fn ast_to_halo2(json: &PyString) -> u128 {
let uuid = chiquito_ast_to_halo2(json.to_str().expect("PyString convertion failed."));
println!("{:?}", uuid);
uuid
}
#[pyfunction]
fn verify_proof(witness_json: &PyString, ast_uuid: &PyLong) {
chiquito_verify_proof(
witness_json.to_str().expect("PyString convertion failed."),
ast_uuid.extract().expect("PyLong convertion failed."),
);
}
#[pymodule]
fn rust_chiquito(_py: Python, m: &PyModule) -> PyResult<()> {
m.add_function(wrap_pyfunction!(convert_and_print_ast, m)?)?;
m.add_function(wrap_pyfunction!(convert_and_print_trace_witness, m)?)?;
m.add_function(wrap_pyfunction!(ast_to_halo2, m)?)?;
m.add_function(wrap_pyfunction!(verify_proof, m)?)?;
Ok(())
}