Skip to content

Commit

Permalink
Update metadata and lib
Browse files Browse the repository at this point in the history
  • Loading branch information
ytham committed Dec 14, 2023
1 parent d9e935d commit cc394d3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 33 deletions.
38 changes: 21 additions & 17 deletions halo2-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ pub struct CircuitConfig {
num_instance: usize,
num_lookup_bits: usize,
num_virtual_instance: usize,
max_user_subqueries: usize,
max_user_outputs: usize,
}

#[wasm_bindgen]
Expand Down Expand Up @@ -110,6 +112,22 @@ impl Default for Halo2Wasm {
}
}

impl Halo2Wasm {
pub fn get_circuit_metadata(&self, circuit_params: &BaseCircuitParams) -> AxiomV2CircuitMetadata {
AxiomV2CircuitMetadata {
version: 0,
num_instance: vec![circuit_params.num_instance_columns as u32],
num_challenge: vec![0],
is_aggregation: false,
num_advice_per_phase: circuit_params.num_advice_per_phase.clone().iter().map(|x| *x as u16).collect(),
num_lookup_advice_per_phase: circuit_params.num_lookup_advice_per_phase.clone().iter().map(|x| *x as u8).collect(),
num_fixed: circuit_params.num_fixed.clone() as u8,
max_outputs: 1,
..Default::default()
}
}
}

#[wasm_bindgen]
impl Halo2Wasm {
#[wasm_bindgen(constructor)]
Expand Down Expand Up @@ -231,24 +249,10 @@ impl Halo2Wasm {
}
}

pub fn get_circuit_metadata(&mut self, circuit_params: &BaseCircuitParams) -> AxiomV2CircuitMetadata {
AxiomV2CircuitMetadata {
version: 0,
num_instance: vec![circuit_params.num_instance_columns as u32],
num_challenge: vec![0],
is_aggregation: false,
num_advice_per_phase: circuit_params.num_advice_per_phase.clone().iter().map(|x| *x as u16).collect(),
num_lookup_advice_per_phase: circuit_params.num_lookup_advice_per_phase.clone().iter().map(|x| *x as u8).collect(),
num_fixed: circuit_params.num_fixed.clone() as u8,
max_outputs: 1,
..Default::default()
}
}

#[wasm_bindgen(js_name = getEncodedCircuitMetadata)]
pub fn get_encoded_circuit_metadata(&mut self) -> Vec<u8> {
let circuit_metadata = self.get_circuit_metadata(self.circuit_params.unwrap().as_ref());
circuit_metadata.encode().unwrap().to_vec()
let circuit_metadata = AxiomV2CircuitMetadata::from_circuit_params(&self.circuit_params.clone().unwrap()); //self.get_circuit_metadata(&self.circuit_params.clone().unwrap());
circuit_metadata.encode().unwrap().0.to_vec()
}

#[wasm_bindgen(js_name = getVk)]
Expand All @@ -264,7 +268,7 @@ impl Halo2Wasm {
#[wasm_bindgen(js_name = getOnchainVk)]
pub fn get_onchain_vk(&self) -> Vec<u8> {
let vk = self.vk.as_ref().unwrap();
let circuit_metadata = self.get_circuit_metadata(self.circuit_params.unwrap().as_ref());
let circuit_metadata = self.get_circuit_metadata(&self.circuit_params.clone().unwrap());
let preprocessed = vk
.fixed_commitments()
.iter()
Expand Down
31 changes: 15 additions & 16 deletions halo2-wasm/src/metadata.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
use anyhow::bail;
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
use ethers_core::types::H256;
use halo2_base::gates::circuit::BaseCircuitParams;
use serde::{Deserialize, Serialize};
use wasm_bindgen::{
convert::IntoWasmAbi,
describe::WasmDescribe,
};

/// All configuration parameters of an Axiom Client Circuit that are
/// hard-coded into the Verify Compute Circuit (which is an Aggregation Circuit with Universality::Full).
Expand Down Expand Up @@ -105,19 +102,21 @@ impl AxiomV2CircuitMetadata {
encoded.resize(32, 0);
Ok(H256::from_slice(&encoded))
}
}

impl IntoWasmAbi for AxiomV2CircuitMetadata {
type Abi = [u8; 32];

fn into_abi(self) -> Self::Abi {
self.encode().unwrap().into()
}
}

impl WasmDescribe for AxiomV2CircuitMetadata {
fn describe() {

pub fn from_circuit_params(
circuit_params: &BaseCircuitParams
) -> Self {
Self {
version: 0,
num_instance: vec![circuit_params.num_instance_columns as u32],
num_challenge: vec![0],
is_aggregation: false,
num_advice_per_phase: circuit_params.num_advice_per_phase.clone().iter().map(|x| *x as u16).collect(),
num_lookup_advice_per_phase: circuit_params.num_lookup_advice_per_phase.clone().iter().map(|x| *x as u8).collect(),
num_fixed: circuit_params.num_fixed.clone() as u8,
max_outputs: 1,
..Default::default()
}
}
}

Expand Down

0 comments on commit cc394d3

Please sign in to comment.