From 6102f78ec5d370417544ee25a9eab31bc241db9b Mon Sep 17 00:00:00 2001 From: Joss Date: Fri, 10 Mar 2023 17:08:48 +0000 Subject: [PATCH 1/5] feat(abi) Support json inputs --- crates/noirc_abi/Cargo.toml | 2 - crates/noirc_abi/src/errors.rs | 10 +- crates/noirc_abi/src/input_parser/json.rs | 166 ++++++++++++++++++++++ crates/noirc_abi/src/input_parser/mod.rs | 27 ++++ 4 files changed, 201 insertions(+), 4 deletions(-) create mode 100644 crates/noirc_abi/src/input_parser/json.rs diff --git a/crates/noirc_abi/Cargo.toml b/crates/noirc_abi/Cargo.toml index 3d12afc8293..12d6193f011 100644 --- a/crates/noirc_abi/Cargo.toml +++ b/crates/noirc_abi/Cargo.toml @@ -12,6 +12,4 @@ iter-extended.workspace = true toml.workspace = true serde.workspace = true thiserror.workspace = true - -[dev-dependencies] serde_json = "1.0" diff --git a/crates/noirc_abi/src/errors.rs b/crates/noirc_abi/src/errors.rs index 4dc8a4bdc41..d39a4118aed 100644 --- a/crates/noirc_abi/src/errors.rs +++ b/crates/noirc_abi/src/errors.rs @@ -4,7 +4,7 @@ use thiserror::Error; #[derive(Debug, Error)] pub enum InputParserError { - #[error("input.toml file is badly formed, could not parse, {0}")] + #[error("input file is badly formed, could not parse, {0}")] ParseTomlMap(String), #[error("Expected witness values to be integers, provided value causes `{0}` error")] ParseStr(String), @@ -12,7 +12,7 @@ pub enum InputParserError { ParseHexStr(String), #[error("duplicate variable name {0}")] DuplicateVariableName(String), - #[error("cannot parse a string toml type into {0:?}")] + #[error("cannot parse a string into type {0:?}")] AbiTypeMismatch(AbiType), #[error("Expected argument `{0}`, but none was found")] MissingArgument(String), @@ -30,6 +30,12 @@ impl From for InputParserError { } } +impl From for InputParserError { + fn from(err: serde_json::Error) -> Self { + Self::ParseTomlMap(err.to_string()) + } +} + #[derive(Debug, Error)] pub enum AbiError { #[error("{0}")] diff --git a/crates/noirc_abi/src/input_parser/json.rs b/crates/noirc_abi/src/input_parser/json.rs new file mode 100644 index 00000000000..4543b67e0e2 --- /dev/null +++ b/crates/noirc_abi/src/input_parser/json.rs @@ -0,0 +1,166 @@ +use super::{parse_str_to_field, InputValue}; +use crate::{errors::InputParserError, Abi, AbiType, MAIN_RETURN_NAME}; +use acvm::FieldElement; +use iter_extended::{btree_map, try_btree_map, try_vecmap, vecmap}; +use serde::{Deserialize, Serialize}; +use std::collections::BTreeMap; + +pub(crate) fn parse_json( + input_string: &str, + abi: &Abi, +) -> Result, InputParserError> { + // Parse input.json into a BTreeMap. + let data: BTreeMap = serde_json::from_str(input_string)?; + + // The json map is stored in an ordered BTreeMap. As the keys are strings the map is in alphanumerical order. + // When parsing the json map we recursively go through each field to enable struct inputs. + // To match this map with the correct abi type we reorganize our abi by parameter name in a BTreeMap, while the struct fields + // in the abi are already stored in a BTreeMap. + let abi_map = abi.to_btree_map(); + + // Convert arguments to field elements. + let mut parsed_inputs = try_btree_map(abi_map, |(arg_name, abi_type)| { + // Check that json contains a value for each argument in the ABI. + let value = data + .get(&arg_name) + .ok_or_else(|| InputParserError::MissingArgument(arg_name.clone()))?; + InputValue::try_from_json(value.clone(), &abi_type, &arg_name) + .map(|input_value| (arg_name, input_value)) + })?; + + // If the json file also includes a return value then we parse it as well. + // This isn't required as the prover calculates the return value itself. + if let (Some(return_type), Some(json_return_value)) = + (&abi.return_type, data.get(MAIN_RETURN_NAME)) + { + let return_value = + InputValue::try_from_json(json_return_value.clone(), return_type, MAIN_RETURN_NAME)?; + parsed_inputs.insert(MAIN_RETURN_NAME.to_owned(), return_value); + } + + Ok(parsed_inputs) +} + +pub(crate) fn serialize_to_json( + w_map: &BTreeMap, +) -> Result { + let to_map: BTreeMap<_, _> = + w_map.iter().map(|(key, value)| (key, JsonTypes::from(value.clone()))).collect(); + + let json_string = serde_json::to_string(&to_map)?; + + Ok(json_string) +} + +#[derive(Debug, Deserialize, Serialize, Clone)] +#[serde(untagged)] +enum JsonTypes { + // This is most likely going to be a hex string + // But it is possible to support UTF-8 + String(String), + // Just a regular integer, that can fit in 128 bits + Integer(u64), + // Simple boolean flag + Bool(bool), + // Array of regular integers + ArrayNum(Vec), + // Array of hexadecimal integers + ArrayString(Vec), + // Array of booleans + ArrayBool(Vec), + // Struct of JsonTypes + Table(BTreeMap), +} + +impl From for JsonTypes { + fn from(value: InputValue) -> Self { + match value { + InputValue::Field(f) => { + let f_str = format!("0x{}", f.to_hex()); + JsonTypes::String(f_str) + } + InputValue::Vec(v) => { + let array = v.iter().map(|i| format!("0x{}", i.to_hex())).collect(); + JsonTypes::ArrayString(array) + } + InputValue::String(s) => JsonTypes::String(s), + InputValue::Struct(map) => { + let map_with_json_types = + btree_map(map, |(key, value)| (key, JsonTypes::from(value))); + JsonTypes::Table(map_with_json_types) + } + } + } +} + +impl InputValue { + fn try_from_json( + value: JsonTypes, + param_type: &AbiType, + arg_name: &str, + ) -> Result { + let input_value = match value { + JsonTypes::String(string) => match param_type { + AbiType::String { .. } => InputValue::String(string), + AbiType::Field | AbiType::Integer { .. } | AbiType::Boolean => { + InputValue::Field(parse_str_to_field(&string)?) + } + + AbiType::Array { .. } | AbiType::Struct { .. } => { + return Err(InputParserError::AbiTypeMismatch(param_type.clone())) + } + }, + JsonTypes::Integer(integer) => { + let new_value = FieldElement::from(i128::from(integer)); + + InputValue::Field(new_value) + } + JsonTypes::Bool(boolean) => { + let new_value = if boolean { FieldElement::one() } else { FieldElement::zero() }; + + InputValue::Field(new_value) + } + JsonTypes::ArrayNum(arr_num) => { + let array_elements = + vecmap(arr_num, |elem_num| FieldElement::from(i128::from(elem_num))); + + InputValue::Vec(array_elements) + } + JsonTypes::ArrayString(arr_str) => { + let array_elements = try_vecmap(arr_str, |elem_str| parse_str_to_field(&elem_str))?; + + InputValue::Vec(array_elements) + } + JsonTypes::ArrayBool(arr_bool) => { + let array_elements = vecmap(arr_bool, |elem_bool| { + if elem_bool { + FieldElement::one() + } else { + FieldElement::zero() + } + }); + + InputValue::Vec(array_elements) + } + + JsonTypes::Table(table) => match param_type { + AbiType::Struct { fields } => { + let native_table = try_btree_map(fields, |(field_name, abi_type)| { + // Check that json contains a value for each field of the struct. + let field_id = format!("{arg_name}.{field_name}"); + let value = table + .get(field_name) + .ok_or_else(|| InputParserError::MissingArgument(field_id.clone()))?; + InputValue::try_from_json(value.clone(), abi_type, &field_id) + .map(|input_value| (field_name.to_string(), input_value)) + })?; + + InputValue::Struct(native_table) + } + _ => return Err(InputParserError::AbiTypeMismatch(param_type.clone())), + }, + }; + + Ok(input_value) + } +} diff --git a/crates/noirc_abi/src/input_parser/mod.rs b/crates/noirc_abi/src/input_parser/mod.rs index cf9e0909f57..a5c7ac25dde 100644 --- a/crates/noirc_abi/src/input_parser/mod.rs +++ b/crates/noirc_abi/src/input_parser/mod.rs @@ -1,3 +1,4 @@ +mod json; mod toml; use std::{collections::BTreeMap, path::Path}; @@ -74,12 +75,14 @@ pub trait InitialWitnessParser { /// The different formats that are supported when parsing /// the initial witness values pub enum Format { + Json, Toml, } impl Format { pub fn ext(&self) -> &'static str { match self { + Format::Json => "json", Format::Toml => "toml", } } @@ -92,6 +95,7 @@ impl Format { abi: &Abi, ) -> Result, InputParserError> { match self { + Format::Json => json::parse_json(input_string, abi), Format::Toml => toml::parse_toml(input_string, abi), } } @@ -101,7 +105,30 @@ impl Format { w_map: &BTreeMap, ) -> Result { match self { + Format::Json => json::serialize_to_json(w_map), Format::Toml => toml::serialize_to_toml(w_map), } } } + +pub(self) fn parse_str_to_field(value: &str) -> Result { + if value.starts_with("0x") { + FieldElement::from_hex(value).ok_or_else(|| InputParserError::ParseHexStr(value.to_owned())) + } else { + value + .parse::() + .map_err(|err_msg| InputParserError::ParseStr(err_msg.to_string())) + .map(FieldElement::from) + } +} + +#[cfg(test)] +mod test { + use super::parse_str_to_field; + + #[test] + fn parse_empty_str_fails() { + // Check that this fails appropriately rather than being treated as 0, etc. + assert!(parse_str_to_field("").is_err()); + } +} From b0bd0d02a2e9d23ee0107e333a909a1dd8f96965 Mon Sep 17 00:00:00 2001 From: Joss Date: Tue, 28 Mar 2023 17:19:13 +0100 Subject: [PATCH 2/5] feat(wasm): copy various methods from noir_util_wasm --- crates/wasm/Cargo.toml | 3 + crates/wasm/src/js_sys_util.rs | 15 ++++ crates/wasm/src/lib.rs | 135 ++++++++++++++++++++++++++++++++- 3 files changed, 151 insertions(+), 2 deletions(-) create mode 100644 crates/wasm/src/js_sys_util.rs diff --git a/crates/wasm/Cargo.toml b/crates/wasm/Cargo.toml index bbcabe12e0a..aae9f8c8014 100644 --- a/crates/wasm/Cargo.toml +++ b/crates/wasm/Cargo.toml @@ -13,6 +13,7 @@ crate-type = ["cdylib"] [dependencies] acvm.workspace = true +noirc_abi.workspace = true noirc_driver.workspace = true noirc_frontend.workspace = true wasm-bindgen.workspace = true @@ -21,6 +22,8 @@ log = "0.4.17" wasm-logger = "0.2.0" console_error_panic_hook = "0.1.7" gloo-utils = { version = "0.1", features = ["serde"] } +serde_json = "1.0" +js-sys = { version = "0.3.61" } [build-dependencies] build-data = "0.1.3" diff --git a/crates/wasm/src/js_sys_util.rs b/crates/wasm/src/js_sys_util.rs new file mode 100644 index 00000000000..766e3e53a3d --- /dev/null +++ b/crates/wasm/src/js_sys_util.rs @@ -0,0 +1,15 @@ +use std::collections::BTreeMap; + +use acvm::{acir::native_types::Witness, FieldElement}; + +pub(crate) fn witness_map_to_js_map(witness_map: BTreeMap) -> js_sys::Map { + let js_map = js_sys::Map::new(); + for (witness, field_value) in witness_map.iter() { + let js_idx = js_sys::Number::from(witness.0); + let mut hex_str = "0x".to_owned(); + hex_str.push_str(&field_value.to_hex()); + let js_hex_str = js_sys::JsString::from(hex_str); + js_map.set(&js_idx, &js_hex_str); + } + js_map +} diff --git a/crates/wasm/src/lib.rs b/crates/wasm/src/lib.rs index 61212dbaacd..d12aaa2babd 100644 --- a/crates/wasm/src/lib.rs +++ b/crates/wasm/src/lib.rs @@ -1,15 +1,21 @@ #![forbid(unsafe_code)] #![warn(unused_crate_dependencies, unused_extern_crates)] #![warn(unreachable_pub)] -use acvm::acir::circuit::Circuit; +use acvm::{ + acir::{circuit::Circuit, native_types::Witness}, + FieldElement, +}; use gloo_utils::format::JsValueSerdeExt; use log::{debug, Level}; +use noirc_abi::{input_parser, Abi, MAIN_RETURN_NAME}; use noirc_driver::{CompileOptions, Driver}; use noirc_frontend::graph::{CrateName, CrateType}; use serde::{Deserialize, Serialize}; -use std::{path::PathBuf, str::FromStr}; +use std::{collections::BTreeMap, path::PathBuf, str::FromStr}; use wasm_bindgen::prelude::*; +mod js_sys_util; + #[derive(Serialize, Deserialize)] pub struct BuildInfo { git_hash: &'static str, @@ -191,3 +197,128 @@ pub fn build_info() -> JsValue { console_error_panic_hook::set_once(); ::from_serde(&BUILD_INFO).unwrap() } + +// Below is all copied from noir_wasm_util branch + +fn js_map_to_witness_map(js_map: js_sys::Map) -> BTreeMap { + let mut witness_skeleton: BTreeMap = BTreeMap::new(); + for key_result in js_map.keys() { + let key = key_result.expect("bad key"); + let idx; + unsafe { + idx = key.as_f64().expect("not a number").to_int_unchecked::(); + } + let hex_str = js_map.get(&key).as_string().expect("not a string"); + let field_element = FieldElement::from_hex(&hex_str).expect("bad hex str"); + witness_skeleton.insert(Witness(idx), field_element); + } + witness_skeleton +} + +fn witness_map_to_js_map(witness_map: BTreeMap) -> js_sys::Map { + let js_map = js_sys::Map::new(); + for (witness, field_value) in witness_map.iter() { + let js_idx = js_sys::Number::from(witness.0); + let mut hex_str = "0x".to_owned(); + hex_str.push_str(&field_value.to_hex()); + let js_hex_str = js_sys::JsString::from(hex_str); + js_map.set(&js_idx, &js_hex_str); + } + js_map +} + +fn read_circuit(circuit: js_sys::Uint8Array) -> Circuit { + let circuit: Vec = circuit.to_vec(); + match Circuit::read(&*circuit) { + Ok(circuit) => circuit, + Err(err) => panic!("Circuit read err: {}", err), + } +} + +#[wasm_bindgen] +pub fn arrange_initial_witness(abi_json_str: String, inputs_json_str: String) -> js_sys::Map { + console_error_panic_hook::set_once(); + + let abi = match serde_json::from_str::(&abi_json_str) { + Ok(abi) => abi, + Err(err) => panic!("Failed to read ABI: {}", err), + }; + let parser = input_parser::Format::Json; + let input_map = match parser.parse(&inputs_json_str, &abi) { + Ok(input_map) => input_map, + Err(err) => panic!("Failed to parse input: {}", err), + }; + let initial_witness = match abi.encode(&input_map, None) { + Ok(initial_witness) => initial_witness, + Err(err) => panic!("Failed to arrange initial witness: {}", err), + }; + js_sys_util::witness_map_to_js_map(initial_witness) +} + +#[wasm_bindgen] +pub fn arrange_public_witness(abi_json_str: String, inputs_json_str: String) -> js_sys::Map { + console_error_panic_hook::set_once(); + + let abi = match serde_json::from_str::(&abi_json_str) { + Ok(abi) => abi, + Err(err) => panic!("Failed to read ABI: {}", err), + }; + let public_abi = abi.public_abi(); + let parser = input_parser::Format::Json; + let mut input_map = match parser.parse(&inputs_json_str, &public_abi) { + Ok(input_map) => input_map, + Err(err) => panic!("Failed to parse input: {}", err), + }; + let return_value = input_map.remove(MAIN_RETURN_NAME); + let public_witness = match public_abi.encode(&input_map, return_value) { + Ok(public_witness) => public_witness, + Err(err) => panic!("Failed to arrange initial witness: {}", err), + }; + js_sys_util::witness_map_to_js_map(public_witness) +} + +#[wasm_bindgen] +pub fn select_return_value(abi_json_str: String, intermediate_witness: js_sys::Map) -> String { + console_error_panic_hook::set_once(); + + let intermediate_witness = js_map_to_witness_map(intermediate_witness); + let abi = match serde_json::from_str::(&abi_json_str) { + Ok(abi) => abi, + Err(err) => panic!("Failed to read ABI: {}", err), + }; + let parser = input_parser::Format::Json; + let return_value = match abi.decode(&intermediate_witness) { + // `None` indicates that the circuit has no return value -> return a serialised "null" + Ok((_inputs_map, None)) => return "null".to_owned(), + Ok((_inputs_map, Some(return_value))) => return_value, + Err(err) => panic!("Failed to decode intermediate witness: {}", err), + }; + let input_map = BTreeMap::from([(MAIN_RETURN_NAME.to_owned(), return_value)]); + match parser.serialize(&input_map) { + Ok(json_str) => json_str, + Err(err) => panic!("Failed to serialise return value: {}", err), + } +} + +#[wasm_bindgen] +pub fn select_public_witness( + circuit: js_sys::Uint8Array, + intermediate_witness: js_sys::Map, +) -> js_sys::Map { + console_error_panic_hook::set_once(); + + let circuit = read_circuit(circuit); + let intermediate_witness = js_map_to_witness_map(intermediate_witness); + let public_witness = circuit + .public_inputs + .indices() + .iter() + .map(|idx| { + let witness = Witness(*idx); + let field_element = + *intermediate_witness.get(&witness).expect("witness element not found"); + (witness, field_element) + }) + .collect::>(); + witness_map_to_js_map(public_witness) +} From 46589626b5009eee44ad3f28f453ba82da3bb7b0 Mon Sep 17 00:00:00 2001 From: Joe Andrews Date: Tue, 28 Mar 2023 22:18:40 +0000 Subject: [PATCH 3/5] update lock file --- Cargo.lock | 361 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 215 insertions(+), 146 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c04345b45c9..0ffb5176aa3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -50,7 +50,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "081a09b71facabddd411bfb8459c0f4d9350c39707680da6c04debb3db9de503" dependencies = [ "ark-bn254 0.4.0", - "ark-ff 0.4.1", + "ark-ff 0.4.2", "cfg-if 1.0.0", "hex", "num-bigint", @@ -167,12 +167,46 @@ dependencies = [ "libc", ] +[[package]] +name = "anstream" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "342258dd14006105c2b75ab1bd7543a03bdf0cfc94383303ac212a04939dff6f" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-wincon", + "concolor-override", + "concolor-query", + "is-terminal", + "utf8parse", +] + [[package]] name = "anstyle" version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23ea9e81bd02e310c216d080f6223c179012256e5151c41db88d12c88a1684d2" +[[package]] +name = "anstyle-parse" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7d1bb534e9efed14f3e5f44e7dd1a4f709384023a4165199a4241e18dff0116" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-wincon" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3127af6145b149f3287bb9a0d10ad9c5692dba8c53ad48285e5bec4063834fa" +dependencies = [ + "anstyle", + "windows-sys 0.45.0", +] + [[package]] name = "arena" version = "0.3.2" @@ -208,8 +242,8 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a22f4561524cd949590d78d7d4c5df8f592430d221f7f3c9497bbafd8972120f" dependencies = [ - "ark-ec 0.4.1", - "ark-ff 0.4.1", + "ark-ec 0.4.2", + "ark-ff 0.4.2", "ark-std 0.4.0", ] @@ -229,13 +263,13 @@ dependencies = [ [[package]] name = "ark-ec" -version = "0.4.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c60370a92f8e1a5f053cad73a862e1b99bc642333cd676fa11c0c39f80f4ac2" +checksum = "defd9a439d56ac24968cca0571f598a61bc8c55f71d50a89cda591cb750670ba" dependencies = [ - "ark-ff 0.4.1", - "ark-poly 0.4.1", - "ark-serialize 0.4.1", + "ark-ff 0.4.2", + "ark-poly 0.4.2", + "ark-serialize 0.4.2", "ark-std 0.4.0", "derivative", "hashbrown 0.13.2", @@ -264,13 +298,13 @@ dependencies = [ [[package]] name = "ark-ff" -version = "0.4.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c2d42532524bee1da5a4f6f733eb4907301baa480829557adcff5dfaeee1d9a" +checksum = "ec847af850f44ad29048935519032c33da8aa03340876d351dfab5660d2966ba" dependencies = [ - "ark-ff-asm 0.4.1", - "ark-ff-macros 0.4.1", - "ark-serialize 0.4.1", + "ark-ff-asm 0.4.2", + "ark-ff-macros 0.4.2", + "ark-serialize 0.4.2", "ark-std 0.4.0", "derivative", "digest 0.10.6", @@ -289,17 +323,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "db02d390bf6643fb404d3d22d31aee1c4bc4459600aef9113833d17e786c6e44" dependencies = [ "quote", - "syn", + "syn 1.0.109", ] [[package]] name = "ark-ff-asm" -version = "0.4.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d6873aaba7959593d89babed381d33e2329453368f1bf3c67e07686a1c1056f" +checksum = "3ed4aa4fe255d0bc6d79373f7e31d2ea147bcf486cba1be5ba7ea85abdb92348" dependencies = [ "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -311,20 +345,20 @@ dependencies = [ "num-bigint", "num-traits", "quote", - "syn", + "syn 1.0.109", ] [[package]] name = "ark-ff-macros" -version = "0.4.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3c2e7d0f2d67cc7fc925355c74d36e7eda19073639be4a0a233d4611b8c959d" +checksum = "7abe79b0e4288889c4574159ab790824d0033b9fdcb2a112a3182fac2e514565" dependencies = [ "num-bigint", "num-traits", "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -359,12 +393,12 @@ dependencies = [ [[package]] name = "ark-poly" -version = "0.4.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f6ec811462cabe265cfe1b102fcfe3df79d7d2929c2425673648ee9abfd0272" +checksum = "d320bfc44ee185d899ccbadfa8bc31aab923ce1558716e1997a1e74057fe86bf" dependencies = [ - "ark-ff 0.4.1", - "ark-serialize 0.4.1", + "ark-ff 0.4.2", + "ark-serialize 0.4.2", "ark-std 0.4.0", "derivative", "hashbrown 0.13.2", @@ -410,11 +444,11 @@ dependencies = [ [[package]] name = "ark-serialize" -version = "0.4.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7e735959bc173ea4baf13327b19c22d452b8e9e8e8f7b7fc34e6bf0e316c33e" +checksum = "adb7b85a02b83d2f22f89bd5cac66c9c89474240cb6207cb1efc16d098e822a5" dependencies = [ - "ark-serialize-derive 0.4.1", + "ark-serialize-derive 0.4.2", "ark-std 0.4.0", "digest 0.10.6", "num-bigint", @@ -428,18 +462,18 @@ checksum = "8dd4e5f0bf8285d5ed538d27fab7411f3e297908fd93c62195de8bee3f199e82" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] name = "ark-serialize-derive" -version = "0.4.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd34f0920d995d2c932f38861c416f70de89a6de9875876b012557079603e6cc" +checksum = "ae3281bc6d0fd7e549af32b52511e1302185bd688fd3359fa36423346ff682ea" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -695,7 +729,7 @@ checksum = "e31225543cb46f81a7e224762764f4a6a0f097b1db0b175f69e8065efaa42de5" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -789,30 +823,38 @@ dependencies = [ [[package]] name = "clap" -version = "4.1.8" +version = "4.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3d7ae14b20b94cb02149ed21a86c423859cbe18dc7ed69845cace50e52b40a5" +checksum = "6efb5f0a41b5ef5b50c5da28c07609c20091df0c1fc33d418fa2a7e693c2b624" dependencies = [ - "bitflags", + "clap_builder", "clap_derive", - "clap_lex 0.3.2", - "is-terminal", "once_cell", +] + +[[package]] +name = "clap_builder" +version = "4.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "671fcaa5debda4b9a84aa7fde49c907c8986c0e6ab927e04217c9cb74e7c8bc9" +dependencies = [ + "anstream", + "anstyle", + "bitflags", + "clap_lex 0.4.1", "strsim", - "termcolor", ] [[package]] name = "clap_derive" -version = "4.1.8" +version = "4.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44bec8e5c9d09e439c4335b1af0abaab56dcf3b94999a936e1bb47b9134288f0" +checksum = "3f9644cd56d6b87dbe899ef8b053e331c0637664e9e21a33dfcdc36093f5c5c4" dependencies = [ "heck", - "proc-macro-error", "proc-macro2", "quote", - "syn", + "syn 2.0.11", ] [[package]] @@ -826,18 +868,15 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.3.2" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "350b9cf31731f9957399229e9b2adc51eeabdfbe9d71d9a0552275fd12710d09" -dependencies = [ - "os_str_bytes", -] +checksum = "8a2dd5a6fe8c6e3502f568a6353e5273bbb15193ad9a89e457b9970798efbea1" [[package]] name = "cmake" -version = "0.1.49" +version = "0.1.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db34956e100b30725f2eb215f90d4871051239535632f84fea3bc92722c66b7c" +checksum = "a31c789563b815f77f4250caee12365734369f942439b7defd71e18a48197130" dependencies = [ "cc", ] @@ -912,6 +951,21 @@ dependencies = [ "sled", ] +[[package]] +name = "concolor-override" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a855d4a1978dc52fb0536a04d384c2c0c1aa273597f08b77c8c4d3b2eec6037f" + +[[package]] +name = "concolor-query" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88d11d52c3d7ca2e6d0040212be9e4dbbcd78b6447f535b6b561f449427944cf" +dependencies = [ + "windows-sys 0.45.0", +] + [[package]] name = "console" version = "0.15.5" @@ -982,9 +1036,9 @@ dependencies = [ [[package]] name = "cpufeatures" -version = "0.2.5" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28d997bd5e24a5928dd43e46dc529867e207907fe0b239c3477d924f7f2ca320" +checksum = "280a9f2d8b3a38871a3c8a46fb80db65e5e5ed97da80c4d08bf27fb63e35e181" dependencies = [ "libc", ] @@ -1132,9 +1186,9 @@ dependencies = [ [[package]] name = "cxx" -version = "1.0.92" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a140f260e6f3f79013b8bfc65e7ce630c9ab4388c6a89c71e07226f49487b72" +checksum = "f61f1b6389c3fe1c316bf8a4dccc90a38208354b330925bce1f74a6c4756eb93" dependencies = [ "cc", "cxxbridge-flags", @@ -1144,9 +1198,9 @@ dependencies = [ [[package]] name = "cxx-build" -version = "1.0.92" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da6383f459341ea689374bf0a42979739dc421874f112ff26f829b8040b8e613" +checksum = "12cee708e8962df2aeb38f594aae5d827c022b6460ac71a7a3e2c3c2aae5a07b" dependencies = [ "cc", "codespan-reporting 0.11.1", @@ -1154,24 +1208,24 @@ dependencies = [ "proc-macro2", "quote", "scratch", - "syn", + "syn 2.0.11", ] [[package]] name = "cxxbridge-flags" -version = "1.0.92" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90201c1a650e95ccff1c8c0bb5a343213bdd317c6e600a93075bca2eff54ec97" +checksum = "7944172ae7e4068c533afbb984114a56c46e9ccddda550499caa222902c7f7bb" [[package]] name = "cxxbridge-macro" -version = "1.0.92" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b75aed41bb2e6367cae39e6326ef817a851db13c13e4f3263714ca3cfb8de56" +checksum = "2345488264226bf682893e25de0769f3360aac9957980ec49361b083ddaa5bc5" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.11", ] [[package]] @@ -1194,7 +1248,7 @@ dependencies = [ "ident_case", "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -1205,7 +1259,7 @@ checksum = "a4aab4dbc9f7611d8b55048a3a16d2d010c2c8334e46304b40ac1cc14bf3b48e" dependencies = [ "darling_core", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -1225,7 +1279,7 @@ checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -1368,7 +1422,7 @@ checksum = "c134c37760b27a871ba422106eedbb8247da973a09e82558bf26d619c882b159" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -1389,7 +1443,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -1585,7 +1639,7 @@ checksum = "3eb14ed937631bd8b8b8977f2c198443447a8355b6e3ca599f38c975e5a963b6" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -1638,9 +1692,9 @@ dependencies = [ [[package]] name = "generic-array" -version = "0.14.6" +version = "0.14.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", @@ -1899,16 +1953,16 @@ dependencies = [ [[package]] name = "iana-time-zone" -version = "0.1.53" +version = "0.1.54" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64c122667b287044802d6ce17ee2ddf13207ed924c712de9a66a5814d5b64765" +checksum = "0c17cc76786e99f8d2f055c11159e7f0091c42474dcc3189fbab96072e873e6d" dependencies = [ "android_system_properties", "core-foundation-sys", "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "winapi", + "windows", ] [[package]] @@ -1962,9 +2016,9 @@ checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" [[package]] name = "indexmap" -version = "1.9.2" +version = "1.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" dependencies = [ "autocfg", "hashbrown 0.12.3", @@ -1994,25 +2048,26 @@ dependencies = [ [[package]] name = "io-lifetimes" -version = "1.0.6" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfa919a82ea574332e2de6e74b4c36e74d41982b335080fa59d4ef31be20fdf3" +checksum = "09270fd4fa1111bc614ed2246c7ef56239a3063d5be0d1ec3b589c505d400aeb" dependencies = [ + "hermit-abi 0.3.1", "libc", "windows-sys 0.45.0", ] [[package]] name = "ipnet" -version = "2.7.1" +version = "2.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30e22bd8629359895450b59ea7a776c850561b96a3b1d31321c1949d9e6c9146" +checksum = "12b6ee2129af8d4fb011108c73d99a1b83a85977f23b82460c0ae2e25bb4b57f" [[package]] name = "is-terminal" -version = "0.4.4" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21b6b32576413a8e69b90e952e4a026476040d81017b80445deda5f2d3921857" +checksum = "8687c819457e979cc940d09cb16e42a1bf70aa6b60a549de6d3a62a0ee90c69e" dependencies = [ "hermit-abi 0.3.1", "io-lifetimes", @@ -2146,7 +2201,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0fbfc88337168279f2e9ae06e157cfed4efd3316e14dc96ed074d4f2e6c5952" dependencies = [ "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -2202,9 +2257,9 @@ dependencies = [ [[package]] name = "mime" -version = "0.3.16" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" [[package]] name = "minimal-lexical" @@ -2250,7 +2305,7 @@ dependencies = [ "barretenberg_wasm", "build-data", "cfg-if 1.0.0", - "clap 4.1.8", + "clap 4.2.0", "color-eyre", "const_format", "dirs 4.0.0", @@ -2279,10 +2334,13 @@ dependencies = [ "build-data", "console_error_panic_hook", "gloo-utils", + "js-sys", "log", + "noirc_abi", "noirc_driver", "noirc_frontend", "serde", + "serde_json", "wasm-bindgen", "wasm-logger", ] @@ -2304,7 +2362,7 @@ name = "noirc_driver" version = "0.3.2" dependencies = [ "acvm 0.6.0", - "clap 4.1.8", + "clap 4.2.0", "fm", "iter-extended", "noirc_abi", @@ -2466,9 +2524,9 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "os_str_bytes" -version = "6.4.1" +version = "6.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee" +checksum = "ceedf44fb00f2d1984b0bc98102627ce622e083e49a5bacdb3e514fa4238e267" [[package]] name = "owo-colors" @@ -2607,7 +2665,7 @@ dependencies = [ "proc-macro-error-attr", "proc-macro2", "quote", - "syn", + "syn 1.0.109", "version_check", ] @@ -2624,9 +2682,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.52" +version = "1.0.54" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d0e1ae9e836cc3beddd63db0df682593d7e2d3d891ae8c9083d2113e1744224" +checksum = "e472a104799c74b514a57226160104aa483546de37e839ec50e3c2e41dd87534" dependencies = [ "unicode-ident", ] @@ -2657,7 +2715,7 @@ checksum = "16b845dbfca988fa33db069c0e230574d15a3088f147a87b64c7589eb662c9ac" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -2803,9 +2861,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.7.1" +version = "1.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733" +checksum = "8b1f693b24f6ac912f4893ef08244d70b6067480d2f1a46e950c9691e6749d1d" dependencies = [ "aho-corasick", "memchr", @@ -2820,9 +2878,9 @@ checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" [[package]] name = "regex-syntax" -version = "0.6.28" +version = "0.6.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" +checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" [[package]] name = "region" @@ -2856,9 +2914,9 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.11.14" +version = "0.11.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21eed90ec8570952d53b772ecf8f206aa1ec9a3d76b2521c56c42973f2d91ee9" +checksum = "27b71749df584b7f4cac2c426c127a7c785a5106cc98f7a8feb044115f0fa254" dependencies = [ "base64", "bytes", @@ -2930,7 +2988,7 @@ checksum = "ff26ed6c7c4dfc2aa9480b86a60e3c7233543a270a680e10758a507c5a4ce476" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -2957,9 +3015,9 @@ dependencies = [ [[package]] name = "rust-embed" -version = "6.6.0" +version = "6.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb133b9a38b5543fad3807fb2028ea47c5f2b566f4f5e28a11902f1a358348b6" +checksum = "1b68543d5527e158213414a92832d2aab11a84d2571a5eb021ebe22c43aab066" dependencies = [ "rust-embed-impl", "rust-embed-utils", @@ -2975,7 +3033,7 @@ dependencies = [ "proc-macro2", "quote", "rust-embed-utils", - "syn", + "syn 1.0.109", "walkdir", ] @@ -2991,9 +3049,9 @@ dependencies = [ [[package]] name = "rustc-demangle" -version = "0.1.21" +version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342" +checksum = "d4a36c42d1873f9a77c53bde094f9664d9891bc604a45b4798fd2c389ed12e5b" [[package]] name = "rustc-hash" @@ -3021,9 +3079,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.36.9" +version = "0.36.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd5c6ff11fecd55b40746d1995a02f2eb375bf8c00d192d521ee09f42bef37bc" +checksum = "db4165c9963ab29e422d6c26fbc1d37f15bace6b2810221f9d925023480fcf0e" dependencies = [ "bitflags", "errno", @@ -3182,9 +3240,9 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.155" +version = "1.0.159" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71f2b4817415c6d4210bfe1c7bfcf4801b2d904cb4d0e1a8fdb651013c9e86b8" +checksum = "3c04e8343c3daeec41f58990b9d77068df31209f2af111e059e9fe9646693065" dependencies = [ "serde_derive", ] @@ -3200,20 +3258,20 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.155" +version = "1.0.159" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d071a94a3fac4aff69d023a7f411e33f40f3483f8c5190b1953822b6b76d7630" +checksum = "4c614d17805b093df4b147b51339e7e44bf05ef59fba1e45d83500bcfb4d8585" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.11", ] [[package]] name = "serde_json" -version = "1.0.94" +version = "1.0.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c533a59c9d8a93a09c6ab31f0fd5e5f4dd1b8fc9434804029839884765d04ea" +checksum = "d721eca97ac802aa7777b701877c8004d950fc142651367300d21c1cc0194744" dependencies = [ "itoa", "ryu", @@ -3393,7 +3451,7 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn", + "syn 1.0.109", ] [[package]] @@ -3414,15 +3472,14 @@ dependencies = [ ] [[package]] -name = "synstructure" -version = "0.12.6" +name = "syn" +version = "2.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f" +checksum = "21e3787bb71465627110e7d87ed4faaa36c1f61042ee67badb9e2ef173accc40" dependencies = [ "proc-macro2", "quote", - "syn", - "unicode-xid", + "unicode-ident", ] [[package]] @@ -3477,22 +3534,22 @@ checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" [[package]] name = "thiserror" -version = "1.0.39" +version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5ab016db510546d856297882807df8da66a16fb8c4101cb8b30054b0d5b2d9c" +checksum = "978c9a314bd8dc99be594bc3c175faaa9794be04a5a5e153caba6915336cebac" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.39" +version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5420d42e90af0c38c3290abcca25b9b3bdf379fc9f55c528f53a269d9c9a267e" +checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.11", ] [[package]] @@ -3533,14 +3590,13 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.26.0" +version = "1.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03201d01c3c27a29c8a5cee5b55a93ddae1ccf6f08f65365c2c918f8c1b76f64" +checksum = "d0de47a4eecbe11f498978a9b29d792f0d2692d1dd003650c24c76510e3bc001" dependencies = [ "autocfg", "bytes", "libc", - "memchr", "mio", "num_cpus 1.15.0", "pin-project-lite", @@ -3596,9 +3652,9 @@ dependencies = [ [[package]] name = "toml_edit" -version = "0.19.6" +version = "0.19.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08de71aa0d6e348f070457f85af8bd566e2bc452156a423ddf22861b3a953fae" +checksum = "239410c8609e8125456927e6707163a3b1fdb40561e4b803bc041f466ccfdc13" dependencies = [ "indexmap", "serde", @@ -3634,7 +3690,7 @@ checksum = "4017f8f45139870ca7e672686113917c71c7a6e02d4924eda67186083c03081a" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -3688,9 +3744,9 @@ checksum = "9e79c4d996edb816c91e4308506774452e55e95c3c9de07b6729e17e15a5ef81" [[package]] name = "unicode-bidi" -version = "0.3.11" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524b68aca1d05e03fdf03fcdce2c6c94b6daf6d16861ddaa7e4f2b6638a9052c" +checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" [[package]] name = "unicode-ident" @@ -3736,6 +3792,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + [[package]] name = "valuable" version = "0.1.0" @@ -3759,12 +3821,11 @@ dependencies = [ [[package]] name = "walkdir" -version = "2.3.2" +version = "2.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56" +checksum = "36df944cda56c7d8d8b7496af378e6b16de9284591917d307c9b4d313c44e698" dependencies = [ "same-file", - "winapi", "winapi-util", ] @@ -3813,7 +3874,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn", + "syn 1.0.109", "wasm-bindgen-shared", ] @@ -3847,7 +3908,7 @@ checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -3965,7 +4026,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -4207,6 +4268,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdacb41e6a96a052c6cb63a144f24900236121c6f63f4f8219fef5977ecb0c25" +dependencies = [ + "windows-targets", +] + [[package]] name = "windows-sys" version = "0.33.0" @@ -4333,9 +4403,9 @@ checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" [[package]] name = "winnow" -version = "0.3.5" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee7b2c67f962bf5042bfd8b6a916178df33a26eec343ae064cb8e069f638fa6f" +checksum = "ae8970b36c66498d8ff1d66685dc86b91b29db0c7739899012f63a63814b4b28" dependencies = [ "memchr", ] @@ -4357,21 +4427,20 @@ checksum = "85e60b0d1b5f99db2556934e21937020776a5d31520bf169e851ac44e6420214" [[package]] name = "zeroize" -version = "1.5.7" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c394b5bd0c6f669e7275d9c20aa90ae064cb22e75a1cad54e1b34088034b149f" +checksum = "2a0956f1ba7c7909bfb66c2e9e4124ab6f6482560f6628b5aaeba39207c9aad9" dependencies = [ "zeroize_derive", ] [[package]] name = "zeroize_derive" -version = "1.3.3" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44bf07cb3e50ea2003396695d58bf46bc9887a1f362260446fad6bc4e79bd36c" +checksum = "25588073e5216b50bca71d61cb8595cdb9745e87032a58c199730def2862c934" dependencies = [ "proc-macro2", "quote", - "syn", - "synstructure", + "syn 2.0.11", ] From de69bebceb58ffd5039cab12af75202e6924d372 Mon Sep 17 00:00:00 2001 From: Kevaundray Wedderburn Date: Wed, 29 Mar 2023 09:07:41 +0100 Subject: [PATCH 4/5] remove unsafe and use bigInt to u32 conversion method --- crates/wasm/src/lib.rs | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/crates/wasm/src/lib.rs b/crates/wasm/src/lib.rs index d12aaa2babd..8bd5a1837bb 100644 --- a/crates/wasm/src/lib.rs +++ b/crates/wasm/src/lib.rs @@ -6,6 +6,7 @@ use acvm::{ FieldElement, }; use gloo_utils::format::JsValueSerdeExt; +use js_sys::BigInt; use log::{debug, Level}; use noirc_abi::{input_parser, Abi, MAIN_RETURN_NAME}; use noirc_driver::{CompileOptions, Driver}; @@ -204,10 +205,7 @@ fn js_map_to_witness_map(js_map: js_sys::Map) -> BTreeMap let mut witness_skeleton: BTreeMap = BTreeMap::new(); for key_result in js_map.keys() { let key = key_result.expect("bad key"); - let idx; - unsafe { - idx = key.as_f64().expect("not a number").to_int_unchecked::(); - } + let idx = js_value_to_u32(&key); let hex_str = js_map.get(&key).as_string().expect("not a string"); let field_element = FieldElement::from_hex(&hex_str).expect("bad hex str"); witness_skeleton.insert(Witness(idx), field_element); @@ -235,6 +233,26 @@ fn read_circuit(circuit: js_sys::Uint8Array) -> Circuit { } } +fn js_value_to_u32(val: &JsValue) -> u32 { + if let Ok(val_int) = BigInt::new(&val) { + // Seems like the only way in javascript to get the number of bits + let num_bits = val_int.to_string(2).unwrap().length(); + + if num_bits > 32 { + panic!("value can not be greater than a 32 bit number, number of bits is {}", num_bits); + } + + // The following lines of code will convert a BigInt into a u32 + // To do this, we convert it to a Javascript string in base10, then to a utf8 encoded rust string + // then we parse the rust string as a u32 + let val_as_string = val_int.to_string(10).unwrap().as_string().unwrap(); + + let value_u32: u32 = val_as_string.parse().unwrap(); + return value_u32; + } + panic!("expected a big integer") +} + #[wasm_bindgen] pub fn arrange_initial_witness(abi_json_str: String, inputs_json_str: String) -> js_sys::Map { console_error_panic_hook::set_once(); From 7451e6c2468f6d92a05915304ad94b7edebe1733 Mon Sep 17 00:00:00 2001 From: Kevaundray Wedderburn Date: Wed, 29 Mar 2023 09:30:13 +0100 Subject: [PATCH 5/5] remove extra & --- crates/wasm/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/wasm/src/lib.rs b/crates/wasm/src/lib.rs index 8bd5a1837bb..fb1579e2394 100644 --- a/crates/wasm/src/lib.rs +++ b/crates/wasm/src/lib.rs @@ -234,7 +234,7 @@ fn read_circuit(circuit: js_sys::Uint8Array) -> Circuit { } fn js_value_to_u32(val: &JsValue) -> u32 { - if let Ok(val_int) = BigInt::new(&val) { + if let Ok(val_int) = BigInt::new(val) { // Seems like the only way in javascript to get the number of bits let num_bits = val_int.to_string(2).unwrap().length();