Skip to content

Commit

Permalink
patch wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-camuto committed Sep 15, 2024
1 parent dcc1ecd commit 83dc4fa
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 20 deletions.
6 changes: 5 additions & 1 deletion src/circuit/ops/layouts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4186,7 +4186,11 @@ pub(crate) fn decompose<F: PrimeField + TensorType + PartialOrd + std::hash::Has
sliced_input = region.assign(&config.custom_gates.inputs[0], &sliced_input)?;
}

let mut claimed_output_slice = sliced_input.decompose(*base, *n)?;
let mut claimed_output_slice = if region.witness_gen() {
sliced_input.decompose(*base, *n)?
} else {
Tensor::from(vec![ValType::Value(Value::unknown()); *n + 1].into_iter()).into()
};

claimed_output_slice =
region.assign(&config.custom_gates.inputs[1], &claimed_output_slice)?;
Expand Down
6 changes: 0 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,6 @@ lazy_static! {

}

#[cfg(target_arch = "wasm32")]
const EZKL_DECOMP_BASE: &usize = &16384;

#[cfg(target_arch = "wasm32")]
const EZKL_DECOMP_LEN: &usize = &2;

#[cfg(target_arch = "wasm32")]
const EZKL_KEY_FORMAT: &str = "raw-bytes";

Expand Down
2 changes: 1 addition & 1 deletion src/tensor/val.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ impl<F: PrimeField + TensorType + PartialOrd + std::hash::Hash> ValTensor<F> {
let mut is_empty = true;
x.map(|_| is_empty = false);
if is_empty {
Ok::<_, TensorError>(vec![Value::<F>::unknown(); n + 1])
return Ok::<_, TensorError>(vec![Value::<F>::unknown(); n + 1]);
} else {
let mut res = vec![Value::unknown(); n + 1];
let mut int_rep = 0;
Expand Down
10 changes: 9 additions & 1 deletion src/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,15 @@ pub fn genWitness(
.map_err(|e| JsError::new(&format!("{}", e)))?;

let witness = circuit
.forward::<KZGCommitmentScheme<Bn256>>(&mut input, None, None, RegionSettings::all_false())
.forward::<KZGCommitmentScheme<Bn256>>(
&mut input,
None,
None,
RegionSettings::all_false(
circuit.settings().run_args.decomp_base,
circuit.settings().run_args.decomp_legs,
),
)
.map_err(|e| JsError::new(&format!("{}", e)))?;

serde_json::to_vec(&witness)
Expand Down
Binary file modified tests/wasm/model.compiled
Binary file not shown.
Binary file modified tests/wasm/pk.key
Binary file not shown.
2 changes: 1 addition & 1 deletion tests/wasm/proof.json

Large diffs are not rendered by default.

28 changes: 19 additions & 9 deletions tests/wasm/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"param_scale": 0,
"scale_rebase_multiplier": 10,
"lookup_range": [
-2,
0,
0
],
"logrows": 6,
Expand All @@ -24,15 +24,18 @@
"param_visibility": "Private",
"div_rebasing": false,
"rebase_frac_zero_constants": false,
"check_mode": "UNSAFE"
"check_mode": "UNSAFE",
"commitment": "KZG",
"decomp_base": 128,
"decomp_legs": 2
},
"num_rows": 16,
"num_rows": 46,
"total_assignments": 92,
"total_const_size": 3,
"total_dynamic_col_size": 0,
"num_dynamic_lookups": 0,
"num_shuffles": 0,
"total_shuffle_col_size": 0,
"total_assignments": 32,
"total_const_size": 8,
"model_instance_shapes": [
[
1,
Expand All @@ -54,12 +57,19 @@
]
]
},
"required_lookups": [
"ReLU"
"required_lookups": [],
"required_range_checks": [
[
-1,
1
],
[
0,
127
]
],
"required_range_checks": [],
"check_mode": "UNSAFE",
"version": "0.0.0",
"num_blinding_factors": null,
"timestamp": 1702474230544
"timestamp": 1726429587279
}
Binary file modified tests/wasm/vk.key
Binary file not shown.
2 changes: 1 addition & 1 deletion tests/wasm/witness.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"inputs":[["0200000000000000000000000000000000000000000000000000000000000000","0100000000000000000000000000000000000000000000000000000000000000","0100000000000000000000000000000000000000000000000000000000000000"]],"pretty_elements":{"rescaled_inputs":[["2","1","1"]],"inputs":[["0x0000000000000000000000000000000000000000000000000000000000000002","0x0000000000000000000000000000000000000000000000000000000000000001","0x0000000000000000000000000000000000000000000000000000000000000001"]],"processed_inputs":[],"processed_params":[],"processed_outputs":[],"rescaled_outputs":[["0","0","0","0"]],"outputs":[["0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000"]]},"outputs":[["0000000000000000000000000000000000000000000000000000000000000000","0000000000000000000000000000000000000000000000000000000000000000","0000000000000000000000000000000000000000000000000000000000000000","0000000000000000000000000000000000000000000000000000000000000000"]],"processed_inputs":null,"processed_params":null,"processed_outputs":null,"max_lookup_inputs":0,"min_lookup_inputs":-1,"max_range_size":0}
{"inputs":[["0200000000000000000000000000000000000000000000000000000000000000","0100000000000000000000000000000000000000000000000000000000000000","0100000000000000000000000000000000000000000000000000000000000000"]],"pretty_elements":{"rescaled_inputs":[["2","1","1"]],"inputs":[["0x0000000000000000000000000000000000000000000000000000000000000002","0x0000000000000000000000000000000000000000000000000000000000000001","0x0000000000000000000000000000000000000000000000000000000000000001"]],"processed_inputs":[],"processed_params":[],"processed_outputs":[],"rescaled_outputs":[["0","0","0","0"]],"outputs":[["0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000"]]},"outputs":[["0000000000000000000000000000000000000000000000000000000000000000","0000000000000000000000000000000000000000000000000000000000000000","0000000000000000000000000000000000000000000000000000000000000000","0000000000000000000000000000000000000000000000000000000000000000"]],"processed_inputs":null,"processed_params":null,"processed_outputs":null,"max_lookup_inputs":0,"min_lookup_inputs":0,"max_range_size":127}

0 comments on commit 83dc4fa

Please sign in to comment.