Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix halo2-wasm template struct name #62

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions halo2-wasm/src/halo2lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@ pub struct Halo2LibWasm {
#[wasm_bindgen]
impl Halo2LibWasm {
#[wasm_bindgen(constructor)]
pub fn new(circuit: &Halo2Wasm) -> Self {
pub fn new(halo2_wasm: &Halo2Wasm) -> Self {
let gate = GateChip::new();
let lookup_bits = circuit.circuit_params.clone().unwrap().lookup_bits.unwrap();
let lookup_bits = halo2_wasm.circuit_params.clone().unwrap().lookup_bits.unwrap();
let range = RangeChip::new(
lookup_bits,
circuit.circuit.borrow().lookup_manager().clone(),
halo2_wasm.circuit.borrow().lookup_manager().clone(),
);
Halo2LibWasm {
gate,
range,
builder: Rc::clone(&circuit.circuit),
builder: Rc::clone(&halo2_wasm.circuit),
}
}

Expand Down Expand Up @@ -470,16 +470,16 @@ impl Halo2LibWasm {
self.to_js_assigned_value(constant)
}

pub fn make_public(&mut self, circuit: &mut Halo2Wasm, a: usize, col: usize) {
pub fn make_public(&mut self, halo2_wasm: &mut Halo2Wasm, a: usize, col: usize) {
let a = self.get_assigned_value(a);
let public = circuit.public.get_mut(col).unwrap();
let public = halo2_wasm.public.get_mut(col).unwrap();
public.push(a);
}

pub fn log(&mut self, circuit: &Halo2Wasm, a: usize) {
pub fn log(&mut self, halo2_wasm: &Halo2Wasm, a: usize) {
let val = self.value(a);
unsafe {
circuit.log(val);
halo2_wasm.log(val);
}
}

Expand Down
36 changes: 18 additions & 18 deletions halo2-wasm/src/halo2lib/ecc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ type FqPoint = ProperCrtUint<Fr>;
pub struct Bn254FqPoint(ProperCrtUint<Fr>);
#[wasm_bindgen]
impl Bn254FqPoint {
fn to_hi_lo(&self, lib_wasm: &Halo2LibWasm) -> [AssignedValue<Fr>; 2] {
convert_3limbs88bits_to_hi_lo(lib_wasm, self.0.limbs())
fn to_hi_lo(&self, halo2_lib_wasm: &Halo2LibWasm) -> [AssignedValue<Fr>; 2] {
convert_3limbs88bits_to_hi_lo(halo2_lib_wasm, self.0.limbs())
}
pub fn to_circuit_value_256(&self, lib_wasm: &Halo2LibWasm) -> JsCircuitValue256 {
let [hi, lo] = self.to_hi_lo(lib_wasm);
let [hi, lo] = [hi, lo].map(|x| lib_wasm.to_js_assigned_value(x));
pub fn to_circuit_value_256(&self, halo2_lib_wasm: &Halo2LibWasm) -> JsCircuitValue256 {
let [hi, lo] = self.to_hi_lo(halo2_lib_wasm);
let [hi, lo] = [hi, lo].map(|x| halo2_lib_wasm.to_js_assigned_value(x));
JsCircuitValue256 { hi, lo }
}
}
Expand Down Expand Up @@ -96,12 +96,12 @@ impl Bn254G2AffinePoint {
pub struct Secp256k1FpPoint(ProperCrtUint<Fr>);
#[wasm_bindgen]
impl Secp256k1FpPoint {
fn to_hi_lo(&self, lib_wasm: &Halo2LibWasm) -> [AssignedValue<Fr>; 2] {
convert_3limbs88bits_to_hi_lo(lib_wasm, self.0.limbs())
fn to_hi_lo(&self, halo2_lib_wasm: &Halo2LibWasm) -> [AssignedValue<Fr>; 2] {
convert_3limbs88bits_to_hi_lo(halo2_lib_wasm, self.0.limbs())
}
pub fn to_circuit_value_256(&self, lib_wasm: &Halo2LibWasm) -> JsCircuitValue256 {
let [hi, lo] = self.to_hi_lo(lib_wasm);
let [hi, lo] = [hi, lo].map(|x| lib_wasm.to_js_assigned_value(x));
pub fn to_circuit_value_256(&self, halo2_lib_wasm: &Halo2LibWasm) -> JsCircuitValue256 {
let [hi, lo] = self.to_hi_lo(halo2_lib_wasm);
let [hi, lo] = [hi, lo].map(|x| halo2_lib_wasm.to_js_assigned_value(x));
JsCircuitValue256 { hi, lo }
}
}
Expand All @@ -114,12 +114,12 @@ impl Secp256k1FpPoint {
pub struct Secp256k1FqPoint(ProperCrtUint<Fr>);
#[wasm_bindgen]
impl Secp256k1FqPoint {
fn to_hi_lo(&self, lib_wasm: &Halo2LibWasm) -> [AssignedValue<Fr>; 2] {
convert_3limbs88bits_to_hi_lo(lib_wasm, self.0.limbs())
fn to_hi_lo(&self, halo2_lib_wasm: &Halo2LibWasm) -> [AssignedValue<Fr>; 2] {
convert_3limbs88bits_to_hi_lo(halo2_lib_wasm, self.0.limbs())
}
pub fn to_circuit_value_256(&self, lib_wasm: &Halo2LibWasm) -> JsCircuitValue256 {
let [hi, lo] = self.to_hi_lo(lib_wasm);
let [hi, lo] = [hi, lo].map(|x| lib_wasm.to_js_assigned_value(x));
pub fn to_circuit_value_256(&self, halo2_lib_wasm: &Halo2LibWasm) -> JsCircuitValue256 {
let [hi, lo] = self.to_hi_lo(halo2_lib_wasm);
let [hi, lo] = [hi, lo].map(|x| halo2_lib_wasm.to_js_assigned_value(x));
JsCircuitValue256 { hi, lo }
}
}
Expand Down Expand Up @@ -519,14 +519,14 @@ fn constrain_limbs_equality<F: BigPrimeField>(
}

fn convert_3limbs88bits_to_hi_lo(
lib_wasm: &Halo2LibWasm,
halo2_lib_wasm: &Halo2LibWasm,
limbs: &[AssignedValue<Fr>],
) -> [AssignedValue<Fr>; 2] {
assert_eq!(limbs.len(), 3);
let lo_bits = 128 - 88;
let hi_bits = 88 - lo_bits;
let mut builder = lib_wasm.builder.borrow_mut();
let range = &lib_wasm.range;
let mut builder = halo2_lib_wasm.builder.borrow_mut();
let range = &halo2_lib_wasm.range;
let gate = &range.gate;
let ctx = builder.main(0);
let (limb1_hi, limb1_lo) = range.div_mod(ctx, limbs[1], BigUint::one() << lo_bits, 88);
Expand Down
6 changes: 3 additions & 3 deletions halo2-wasm/template/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ pub struct MyCircuit {
#[wasm_bindgen]
impl MyCircuit {
#[wasm_bindgen(constructor)]
pub fn new(circuit: &Halo2Wasm) -> Self {
pub fn new(halo2_wasm: &Halo2Wasm) -> Self {
let gate = GateChip::new();
Halo2WasmTemplate {
MyCircuit {
gate,
builder: Arc::clone(&circuit.circuit),
builder: Arc::clone(&halo2_wasm.circuit),
}
}

Expand Down