From 94df4c79e7bdecc7b49a1f84b280927af8f09f6a Mon Sep 17 00:00:00 2001 From: Martin Minkov Date: Tue, 9 Jan 2024 11:19:21 -0800 Subject: [PATCH] chore(kimchi_bindings): use kimchi_bindings from o1js-bindings commit 21cf464 --- .../kimchi_bindings/js/bindings-bigint256.js | 50 - .../kimchi_bindings/js/bindings-curve.js | 118 - .../kimchi_bindings/js/bindings-field.js | 253 -- .../kimchi_bindings/js/bindings-vector.js | 45 - src/lib/crypto/kimchi_bindings/js/bindings.js | 2576 +++++++++++++++-- src/lib/crypto/kimchi_bindings/js/dune | 14 +- .../kimchi_bindings/js/node_js/build.sh | 4 +- .../js/test/bindings_js_test.ml | 87 +- .../crypto/kimchi_bindings/js/web/build.sh | 4 +- src/lib/crypto/kimchi_bindings/js/web/dune | 1 - .../kimchi_bindings/js/web/web_backend.js | 2 +- .../crypto/kimchi_bindings/wasm/Cargo.lock | 575 ++-- .../crypto/kimchi_bindings/wasm/Cargo.toml | 7 +- .../kimchi_bindings/wasm/rust-toolchain.toml | 6 +- .../kimchi_bindings/wasm/src/oracles.rs | 11 +- .../wasm/src/pasta_fp_plonk_index.rs | 128 +- .../wasm/src/pasta_fq_plonk_index.rs | 124 +- .../kimchi_bindings/wasm/src/plonk_proof.rs | 79 +- .../wasm/src/plonk_verifier_index.rs | 263 +- .../crypto/kimchi_bindings/wasm/src/srs.rs | 200 +- .../wasm/src/wasm_ocaml_serde/de.rs | 3 +- .../wasm/src/wasm_ocaml_serde/ser.rs | 5 - .../kimchi_bindings/wasm/src/wasm_vector.rs | 54 +- 23 files changed, 2782 insertions(+), 1827 deletions(-) delete mode 100644 src/lib/crypto/kimchi_bindings/js/bindings-bigint256.js delete mode 100644 src/lib/crypto/kimchi_bindings/js/bindings-curve.js delete mode 100644 src/lib/crypto/kimchi_bindings/js/bindings-field.js delete mode 100644 src/lib/crypto/kimchi_bindings/js/bindings-vector.js diff --git a/src/lib/crypto/kimchi_bindings/js/bindings-bigint256.js b/src/lib/crypto/kimchi_bindings/js/bindings-bigint256.js deleted file mode 100644 index 50fa2a000483..000000000000 --- a/src/lib/crypto/kimchi_bindings/js/bindings-bigint256.js +++ /dev/null @@ -1,50 +0,0 @@ -/* global tsBindings -*/ - -// Provides: caml_bigint_256_of_numeral -// Requires: tsBindings -var caml_bigint_256_of_numeral = tsBindings.caml_bigint_256_of_numeral; - -// Provides: caml_bigint_256_of_decimal_string -// Requires: tsBindings -var caml_bigint_256_of_decimal_string = tsBindings.caml_bigint_256_of_decimal_string; - -// Provides: caml_bigint_256_num_limbs -// Requires: tsBindings -var caml_bigint_256_num_limbs = tsBindings.caml_bigint_256_num_limbs; - -// Provides: caml_bigint_256_bytes_per_limb -// Requires: tsBindings -var caml_bigint_256_bytes_per_limb = tsBindings.caml_bigint_256_bytes_per_limb; - -// Provides: caml_bigint_256_div -// Requires: tsBindings -var caml_bigint_256_div = tsBindings.caml_bigint_256_div; - -// Provides: caml_bigint_256_compare -// Requires: tsBindings -var caml_bigint_256_compare = tsBindings.caml_bigint_256_compare; - -// Provides: caml_bigint_256_print -// Requires: tsBindings -var caml_bigint_256_print = tsBindings.caml_bigint_256_print; - -// Provides: caml_bigint_256_to_string -// Requires: tsBindings -var caml_bigint_256_to_string = tsBindings.caml_bigint_256_to_string; - -// Provides: caml_bigint_256_test_bit -// Requires: tsBindings -var caml_bigint_256_test_bit = tsBindings.caml_bigint_256_test_bit; - -// Provides: caml_bigint_256_to_bytes -// Requires: tsBindings -var caml_bigint_256_to_bytes = tsBindings.caml_bigint_256_to_bytes; - -// Provides: caml_bigint_256_of_bytes -// Requires: tsBindings -var caml_bigint_256_of_bytes = tsBindings.caml_bigint_256_of_bytes; - -// Provides: caml_bigint_256_deep_copy -// Requires: tsBindings -var caml_bigint_256_deep_copy = tsBindings.caml_bigint_256_deep_copy diff --git a/src/lib/crypto/kimchi_bindings/js/bindings-curve.js b/src/lib/crypto/kimchi_bindings/js/bindings-curve.js deleted file mode 100644 index 18d67a0b28d7..000000000000 --- a/src/lib/crypto/kimchi_bindings/js/bindings-curve.js +++ /dev/null @@ -1,118 +0,0 @@ -/* global tsBindings -*/ - -// pallas - -// Provides: caml_pallas_one -// Requires: tsBindings -var caml_pallas_one = tsBindings.caml_pallas_one; - -// Provides: caml_pallas_add -// Requires: tsBindings -var caml_pallas_add = tsBindings.caml_pallas_add; - -// Provides: caml_pallas_sub -// Requires: tsBindings -var caml_pallas_sub = tsBindings.caml_pallas_sub; - -// Provides: caml_pallas_negate -// Requires: tsBindings -var caml_pallas_negate = tsBindings.caml_pallas_negate; - -// Provides: caml_pallas_double -// Requires: tsBindings -var caml_pallas_double = tsBindings.caml_pallas_double; - -// Provides: caml_pallas_scale -// Requires: tsBindings -var caml_pallas_scale = tsBindings.caml_pallas_scale; - -// Provides: caml_pallas_random -// Requires: tsBindings -var caml_pallas_random = tsBindings.caml_pallas_random; - -// Provides: caml_pallas_rng -// Requires: tsBindings -var caml_pallas_rng = tsBindings.caml_pallas_rng; - -// Provides: caml_pallas_endo_base -// Requires: tsBindings -var caml_pallas_endo_base = tsBindings.caml_pallas_endo_base; - -// Provides: caml_pallas_endo_scalar -// Requires: tsBindings -var caml_pallas_endo_scalar = tsBindings.caml_pallas_endo_scalar; - -// Provides: caml_pallas_to_affine -// Requires: tsBindings -var caml_pallas_to_affine = tsBindings.caml_pallas_to_affine; - -// Provides: caml_pallas_of_affine -// Requires: tsBindings -var caml_pallas_of_affine = tsBindings.caml_pallas_of_affine; - -// Provides: caml_pallas_of_affine_coordinates -// Requires: tsBindings -var caml_pallas_of_affine_coordinates = tsBindings.caml_pallas_of_affine_coordinates; - -// Provides: caml_pallas_affine_deep_copy -// Requires: tsBindings -var caml_pallas_affine_deep_copy = tsBindings.caml_pallas_affine_deep_copy; - -// vesta - -// Provides: caml_vesta_one -// Requires: tsBindings -var caml_vesta_one = tsBindings.caml_vesta_one; - -// Provides: caml_vesta_add -// Requires: tsBindings -var caml_vesta_add = tsBindings.caml_vesta_add; - -// Provides: caml_vesta_sub -// Requires: tsBindings -var caml_vesta_sub = tsBindings.caml_vesta_sub; - -// Provides: caml_vesta_negate -// Requires: tsBindings -var caml_vesta_negate = tsBindings.caml_vesta_negate; - -// Provides: caml_vesta_double -// Requires: tsBindings -var caml_vesta_double = tsBindings.caml_vesta_double; - -// Provides: caml_vesta_scale -// Requires: tsBindings -var caml_vesta_scale = tsBindings.caml_vesta_scale; - -// Provides: caml_vesta_random -// Requires: tsBindings -var caml_vesta_random = tsBindings.caml_vesta_random; - -// Provides: caml_vesta_rng -// Requires: tsBindings -var caml_vesta_rng = tsBindings.caml_vesta_rng; - -// Provides: caml_vesta_endo_base -// Requires: tsBindings -var caml_vesta_endo_base = tsBindings.caml_vesta_endo_base; - -// Provides: caml_vesta_endo_scalar -// Requires: tsBindings -var caml_vesta_endo_scalar = tsBindings.caml_vesta_endo_scalar; - -// Provides: caml_vesta_to_affine -// Requires: tsBindings -var caml_vesta_to_affine = tsBindings.caml_vesta_to_affine; - -// Provides: caml_vesta_of_affine -// Requires: tsBindings -var caml_vesta_of_affine = tsBindings.caml_vesta_of_affine; - -// Provides: caml_vesta_of_affine_coordinates -// Requires: tsBindings -var caml_vesta_of_affine_coordinates = tsBindings.caml_vesta_of_affine_coordinates; - -// Provides: caml_vesta_affine_deep_copy -// Requires: tsBindings -var caml_vesta_affine_deep_copy = tsBindings.caml_vesta_affine_deep_copy; diff --git a/src/lib/crypto/kimchi_bindings/js/bindings-field.js b/src/lib/crypto/kimchi_bindings/js/bindings-field.js deleted file mode 100644 index 4b93a52cecd9..000000000000 --- a/src/lib/crypto/kimchi_bindings/js/bindings-field.js +++ /dev/null @@ -1,253 +0,0 @@ -/* global tsBindings -*/ - -// Provides: caml_pasta_fp_copy -// Requires: tsBindings -var caml_pasta_fp_copy = tsBindings.caml_pasta_fp_copy; - -// Provides: caml_pasta_fp_size_in_bits -// Requires: tsBindings -var caml_pasta_fp_size_in_bits = tsBindings.caml_pasta_fp_size_in_bits; - -// Provides: caml_pasta_fp_size -// Requires: tsBindings -var caml_pasta_fp_size = tsBindings.caml_pasta_fp_size; - -// Provides: caml_pasta_fp_add -// Requires: tsBindings -var caml_pasta_fp_add = tsBindings.caml_pasta_fp_add; - -// Provides: caml_pasta_fp_sub -// Requires: tsBindings -var caml_pasta_fp_sub = tsBindings.caml_pasta_fp_sub; - -// Provides: caml_pasta_fp_negate -// Requires: tsBindings -var caml_pasta_fp_negate = tsBindings.caml_pasta_fp_negate; - -// Provides: caml_pasta_fp_mul -// Requires: tsBindings -var caml_pasta_fp_mul = tsBindings.caml_pasta_fp_mul; - -// Provides: caml_pasta_fp_div -// Requires: tsBindings -var caml_pasta_fp_div = tsBindings.caml_pasta_fp_div; - -// Provides: caml_pasta_fp_inv -// Requires: tsBindings -var caml_pasta_fp_inv = tsBindings.caml_pasta_fp_inv; - -// Provides: caml_pasta_fp_square -// Requires: tsBindings -var caml_pasta_fp_square = tsBindings.caml_pasta_fp_square - -// Provides: caml_pasta_fp_is_square -// Requires: tsBindings -var caml_pasta_fp_is_square = tsBindings.caml_pasta_fp_is_square; - -// Provides: caml_pasta_fp_sqrt -// Requires: tsBindings -var caml_pasta_fp_sqrt = tsBindings.caml_pasta_fp_sqrt; - -// Provides: caml_pasta_fp_of_int -// Requires: tsBindings -var caml_pasta_fp_of_int = tsBindings.caml_pasta_fp_of_int - -// Provides: caml_pasta_fp_to_string -// Requires: tsBindings -var caml_pasta_fp_to_string = tsBindings.caml_pasta_fp_to_string; - -// Provides: caml_pasta_fp_of_string -// Requires: tsBindings -var caml_pasta_fp_of_string = tsBindings.caml_pasta_fp_of_string; - -// Provides: caml_pasta_fp_print -// Requires: tsBindings -var caml_pasta_fp_print = tsBindings.caml_pasta_fp_print; - -// Provides: caml_pasta_fp_mut_add -// Requires: tsBindings -var caml_pasta_fp_mut_add = tsBindings.caml_pasta_fp_mut_add; - -// Provides: caml_pasta_fp_mut_sub -// Requires: tsBindings -var caml_pasta_fp_mut_sub = tsBindings.caml_pasta_fp_mut_sub; - -// Provides: caml_pasta_fp_mut_mul -// Requires: tsBindings -var caml_pasta_fp_mut_mul = tsBindings.caml_pasta_fp_mut_mul; - -// Provides: caml_pasta_fp_mut_square -// Requires: tsBindings -var caml_pasta_fp_mut_square = tsBindings.caml_pasta_fp_mut_square; - -// Provides: caml_pasta_fp_compare -// Requires: tsBindings -var caml_pasta_fp_compare = tsBindings.caml_pasta_fp_compare; - -// Provides: caml_pasta_fp_equal -// Requires: tsBindings -var caml_pasta_fp_equal = tsBindings.caml_pasta_fp_equal; - -// Provides: caml_pasta_fp_random -// Requires: tsBindings -var caml_pasta_fp_random = tsBindings.caml_pasta_fp_random; - -// Provides: caml_pasta_fp_rng -// Requires: tsBindings -var caml_pasta_fp_rng = tsBindings.caml_pasta_fp_rng; - -// Provides: caml_pasta_fp_to_bigint -// Requires: tsBindings -var caml_pasta_fp_to_bigint = tsBindings.caml_pasta_fp_to_bigint; - -// Provides: caml_pasta_fp_of_bigint -// Requires: tsBindings -var caml_pasta_fp_of_bigint = tsBindings.caml_pasta_fp_of_bigint; - -// Provides: caml_pasta_fp_two_adic_root_of_unity -// Requires: tsBindings -var caml_pasta_fp_two_adic_root_of_unity = tsBindings.caml_pasta_fp_two_adic_root_of_unity; - -// Provides: caml_pasta_fp_domain_generator -// Requires: tsBindings -var caml_pasta_fp_domain_generator = tsBindings.caml_pasta_fp_domain_generator; - -// Provides: caml_pasta_fp_to_bytes -// Requires: tsBindings -var caml_pasta_fp_to_bytes = tsBindings.caml_pasta_fp_to_bytes; - -// Provides: caml_pasta_fp_of_bytes -// Requires: tsBindings -var caml_pasta_fp_of_bytes = tsBindings.caml_pasta_fp_of_bytes; - -// Provides: caml_pasta_fp_deep_copy -// Requires: tsBindings -var caml_pasta_fp_deep_copy = tsBindings.caml_pasta_fp_deep_copy; - - - - -// Provides: caml_pasta_fq_copy -// Requires: tsBindings -var caml_pasta_fq_copy = tsBindings.caml_pasta_fq_copy; - -// Provides: caml_pasta_fq_size_in_bits -// Requires: tsBindings -var caml_pasta_fq_size_in_bits = tsBindings.caml_pasta_fq_size_in_bits; - -// Provides: caml_pasta_fq_size -// Requires: tsBindings -var caml_pasta_fq_size = tsBindings.caml_pasta_fq_size; - -// Provides: caml_pasta_fq_add -// Requires: tsBindings -var caml_pasta_fq_add = tsBindings.caml_pasta_fq_add; - -// Provides: caml_pasta_fq_sub -// Requires: tsBindings -var caml_pasta_fq_sub = tsBindings.caml_pasta_fq_sub; - -// Provides: caml_pasta_fq_negate -// Requires: tsBindings -var caml_pasta_fq_negate = tsBindings.caml_pasta_fq_negate; - -// Provides: caml_pasta_fq_mul -// Requires: tsBindings -var caml_pasta_fq_mul = tsBindings.caml_pasta_fq_mul; - -// Provides: caml_pasta_fq_div -// Requires: tsBindings -var caml_pasta_fq_div = tsBindings.caml_pasta_fq_div; - -// Provides: caml_pasta_fq_inv -// Requires: tsBindings -var caml_pasta_fq_inv = tsBindings.caml_pasta_fq_inv; - -// Provides: caml_pasta_fq_square -// Requires: tsBindings -var caml_pasta_fq_square = tsBindings.caml_pasta_fq_square - -// Provides: caml_pasta_fq_is_square -// Requires: tsBindings -var caml_pasta_fq_is_square = tsBindings.caml_pasta_fq_is_square; - -// Provides: caml_pasta_fq_sqrt -// Requires: tsBindings -var caml_pasta_fq_sqrt = tsBindings.caml_pasta_fq_sqrt; - -// Provides: caml_pasta_fq_of_int -// Requires: tsBindings -var caml_pasta_fq_of_int = tsBindings.caml_pasta_fq_of_int; - -// Provides: caml_pasta_fq_to_string -// Requires: tsBindings -var caml_pasta_fq_to_string = tsBindings.caml_pasta_fq_to_string; - -// Provides: caml_pasta_fq_of_string -// Requires: tsBindings -var caml_pasta_fq_of_string = tsBindings.caml_pasta_fq_of_string; - -// Provides: caml_pasta_fq_print -// Requires: tsBindings -var caml_pasta_fq_print = tsBindings.caml_pasta_fq_print; - -// Provides: caml_pasta_fq_mut_add -// Requires: tsBindings -var caml_pasta_fq_mut_add = tsBindings.caml_pasta_fq_mut_add; - -// Provides: caml_pasta_fq_mut_sub -// Requires: tsBindings -var caml_pasta_fq_mut_sub = tsBindings.caml_pasta_fq_mut_sub; - -// Provides: caml_pasta_fq_mut_mul -// Requires: tsBindings -var caml_pasta_fq_mut_mul = tsBindings.caml_pasta_fq_mut_mul; - -// Provides: caml_pasta_fq_mut_square -// Requires: tsBindings -var caml_pasta_fq_mut_square = tsBindings.caml_pasta_fq_mut_square; - -// Provides: caml_pasta_fq_compare -// Requires: tsBindings -var caml_pasta_fq_compare = tsBindings.caml_pasta_fq_compare; - -// Provides: caml_pasta_fq_equal -// Requires: tsBindings -var caml_pasta_fq_equal = tsBindings.caml_pasta_fq_equal; - -// Provides: caml_pasta_fq_random -// Requires: tsBindings -var caml_pasta_fq_random = tsBindings.caml_pasta_fq_random; - -// Provides: caml_pasta_fq_rng -// Requires: tsBindings -var caml_pasta_fq_rng = tsBindings.caml_pasta_fq_rng; - -// Provides: caml_pasta_fq_to_bigint -// Requires: tsBindings -var caml_pasta_fq_to_bigint = tsBindings.caml_pasta_fq_to_bigint; - -// Provides: caml_pasta_fq_of_bigint -// Requires: tsBindings -var caml_pasta_fq_of_bigint = tsBindings.caml_pasta_fq_of_bigint; - -// Provides: caml_pasta_fq_two_adic_root_of_unity -// Requires: tsBindings -var caml_pasta_fq_two_adic_root_of_unity = tsBindings.caml_pasta_fq_two_adic_root_of_unity; - -// Provides: caml_pasta_fq_domain_generator -// Requires: tsBindings -var caml_pasta_fq_domain_generator = tsBindings.caml_pasta_fq_domain_generator; - -// Provides: caml_pasta_fq_to_bytes -// Requires: tsBindings -var caml_pasta_fq_to_bytes = tsBindings.caml_pasta_fq_to_bytes; - -// Provides: caml_pasta_fq_of_bytes -// Requires: tsBindings -var caml_pasta_fq_of_bytes = tsBindings.caml_pasta_fq_of_bytes; - -// Provides: caml_pasta_fq_deep_copy -// Requires: tsBindings -var caml_pasta_fq_deep_copy = tsBindings.caml_pasta_fq_deep_copy; diff --git a/src/lib/crypto/kimchi_bindings/js/bindings-vector.js b/src/lib/crypto/kimchi_bindings/js/bindings-vector.js deleted file mode 100644 index 9ff2441bc337..000000000000 --- a/src/lib/crypto/kimchi_bindings/js/bindings-vector.js +++ /dev/null @@ -1,45 +0,0 @@ -/* global tsBindings */ - -// fp - -// Provides: caml_fp_vector_create -// Requires: tsBindings -var caml_fp_vector_create = tsBindings.caml_fp_vector_create; - -// Provides: caml_fp_vector_length -// Requires: tsBindings -var caml_fp_vector_length = tsBindings.caml_fp_vector_length; - -// Provides: caml_fp_vector_emplace_back -// Requires: tsBindings -var caml_fp_vector_emplace_back = tsBindings.caml_fp_vector_emplace_back; - -// Provides: caml_fp_vector_get -// Requires: tsBindings -var caml_fp_vector_get = tsBindings.caml_fp_vector_get; - -// Provides: caml_fp_vector_set -// Requires: tsBindings -var caml_fp_vector_set = tsBindings.caml_fp_vector_set; - -// fq - -// Provides: caml_fq_vector_create -// Requires: tsBindings -var caml_fq_vector_create = tsBindings.caml_fq_vector_create; - -// Provides: caml_fq_vector_length -// Requires: tsBindings -var caml_fq_vector_length = tsBindings.caml_fq_vector_length; - -// Provides: caml_fq_vector_emplace_back -// Requires: tsBindings -var caml_fq_vector_emplace_back = tsBindings.caml_fq_vector_emplace_back; - -// Provides: caml_fq_vector_get -// Requires: tsBindings -var caml_fq_vector_get = tsBindings.caml_fq_vector_get; - -// Provides: caml_fq_vector_set -// Requires: tsBindings -var caml_fq_vector_set = tsBindings.caml_fq_vector_set; diff --git a/src/lib/crypto/kimchi_bindings/js/bindings.js b/src/lib/crypto/kimchi_bindings/js/bindings.js index 329072330437..989d7c92551e 100644 --- a/src/lib/crypto/kimchi_bindings/js/bindings.js +++ b/src/lib/crypto/kimchi_bindings/js/bindings.js @@ -1,25 +1,9 @@ -/* global plonk_wasm, caml_jsstring_of_string, caml_string_of_jsstring, +/* global joo_global_object, plonk_wasm, caml_js_to_bool, caml_jsstring_of_string, + caml_string_of_jsstring caml_create_bytes, caml_bytes_unsafe_set, caml_bytes_unsafe_get, caml_ml_bytes_length, UInt64, caml_int64_of_int32 */ -// Provides: tsBindings -var tsBindings = globalThis.__snarkyTsBindings; - -// Provides: tsRustConversion -// Requires: tsBindings, plonk_wasm -var tsRustConversion = tsBindings.rustConversion(plonk_wasm); - -// Provides: tsSrs -// Requires: tsBindings, plonk_wasm -var tsSrs = tsBindings.srs(plonk_wasm); - -// Provides: getTsBindings -// Requires: tsBindings -function getTsBindings() { - return tsBindings; -} - // Provides: caml_bytes_of_uint8array // Requires: caml_create_bytes, caml_bytes_unsafe_set var caml_bytes_of_uint8array = function (uint8array) { @@ -36,7 +20,7 @@ var caml_bytes_of_uint8array = function (uint8array) { // Requires: caml_ml_bytes_length, caml_bytes_unsafe_get var caml_bytes_to_uint8array = function (ocaml_bytes) { var length = caml_ml_bytes_length(ocaml_bytes); - var bytes = new globalThis.Uint8Array(length); + var bytes = new joo_global_object.Uint8Array(length); for (var i = 0; i < length; i++) { // No need to convert here: OCaml Char.t is just an int under the hood. bytes[i] = caml_bytes_unsafe_get(ocaml_bytes, i); @@ -44,6 +28,81 @@ var caml_bytes_to_uint8array = function (ocaml_bytes) { return bytes; }; +// Provides: caml_bigint_256_of_numeral +// Requires: plonk_wasm, caml_jsstring_of_string +var caml_bigint_256_of_numeral = function (s, len, base) { + return plonk_wasm.caml_bigint_256_of_numeral( + caml_jsstring_of_string(s), + len, + base + ); +}; + +// Provides: caml_bigint_256_of_decimal_string +// Requires: plonk_wasm, caml_jsstring_of_string +var caml_bigint_256_of_decimal_string = function (s) { + return plonk_wasm.caml_bigint_256_of_decimal_string( + caml_jsstring_of_string(s) + ); +}; + +// Provides: caml_bigint_256_num_limbs +// Requires: plonk_wasm +var caml_bigint_256_num_limbs = plonk_wasm.caml_bigint_256_num_limbs; + +// Provides: caml_bigint_256_bytes_per_limb +// Requires: plonk_wasm +var caml_bigint_256_bytes_per_limb = plonk_wasm.caml_bigint_256_bytes_per_limb; + +// Provides: caml_bigint_256_div +// Requires: plonk_wasm +var caml_bigint_256_div = plonk_wasm.caml_bigint_256_div; + +// Provides: caml_bigint_256_compare +// Requires: plonk_wasm +var caml_bigint_256_compare = plonk_wasm.caml_bigint_256_compare; + +// Provides: caml_bigint_256_print +// Requires: plonk_wasm +var caml_bigint_256_print = plonk_wasm.caml_bigint_256_print; + +// Provides: caml_bigint_256_to_string +// Requires: plonk_wasm, caml_string_of_jsstring +var caml_bigint_256_to_string = function (x) { + return caml_string_of_jsstring(plonk_wasm.caml_bigint_256_to_string(x)); +}; + +// Provides: caml_bigint_256_test_bit +// Requires: plonk_wasm, caml_js_to_bool +var caml_bigint_256_test_bit = function (x, i) { + return caml_js_to_bool(plonk_wasm.caml_bigint_256_test_bit(x, i)); +}; + +// Provides: caml_bigint_256_to_bytes +// Requires: plonk_wasm, caml_bytes_of_uint8array +var caml_bigint_256_to_bytes = function (x) { + return caml_bytes_of_uint8array(plonk_wasm.caml_bigint_256_to_bytes(x)); +}; + +// Provides: caml_bigint_256_of_bytes +// Requires: plonk_wasm, caml_bytes_to_uint8array +var caml_bigint_256_of_bytes = function (ocaml_bytes) { + return plonk_wasm.caml_bigint_256_of_bytes( + caml_bytes_to_uint8array(ocaml_bytes) + ); +}; + +// Provides: caml_bigint_256_deep_copy +// Requires: plonk_wasm +var caml_bigint_256_deep_copy = plonk_wasm.caml_bigint_256_deep_copy; + +// Provides: caml_pasta_fp_copy +var caml_pasta_fp_copy = function (x, y) { + for (var i = 0, l = x.length; i < l; i++) { + x[i] = y[i]; + } +}; + // Provides: caml_option_of_maybe_undefined var caml_option_of_maybe_undefined = function (x) { if (x === undefined) { @@ -63,12 +122,446 @@ var caml_option_to_maybe_undefined = function (x) { } }; +// Provides: caml_pasta_fp_size_in_bits +// Requires: plonk_wasm +var caml_pasta_fp_size_in_bits = plonk_wasm.caml_pasta_fp_size_in_bits; + +// Provides: caml_pasta_fp_size +// Requires: plonk_wasm +var caml_pasta_fp_size = plonk_wasm.caml_pasta_fp_size; + +// Provides: caml_pasta_fp_add +// Requires: plonk_wasm +var caml_pasta_fp_add = plonk_wasm.caml_pasta_fp_add; + +// Provides: caml_pasta_fp_sub +// Requires: plonk_wasm +var caml_pasta_fp_sub = plonk_wasm.caml_pasta_fp_sub; + +// Provides: caml_pasta_fp_negate +// Requires: plonk_wasm +var caml_pasta_fp_negate = plonk_wasm.caml_pasta_fp_negate; + +// Provides: caml_pasta_fp_mul +// Requires: plonk_wasm +var caml_pasta_fp_mul = plonk_wasm.caml_pasta_fp_mul; + +// Provides: caml_pasta_fp_div +// Requires: plonk_wasm +var caml_pasta_fp_div = plonk_wasm.caml_pasta_fp_div; + +// Provides: caml_pasta_fp_inv +// Requires: plonk_wasm, caml_option_of_maybe_undefined +var caml_pasta_fp_inv = function (x) { + return caml_option_of_maybe_undefined(plonk_wasm.caml_pasta_fp_inv(x)); +}; + +// Provides: caml_pasta_fp_square +// Requires: plonk_wasm +var caml_pasta_fp_square = plonk_wasm.caml_pasta_fp_square; + +// Provides: caml_pasta_fp_is_square +// Requires: plonk_wasm, caml_js_to_bool +var caml_pasta_fp_is_square = function (x) { + return caml_js_to_bool(plonk_wasm.caml_pasta_fp_is_square(x)); +}; + +// Provides: caml_pasta_fp_sqrt +// Requires: plonk_wasm, caml_option_of_maybe_undefined +var caml_pasta_fp_sqrt = function (x) { + return caml_option_of_maybe_undefined(plonk_wasm.caml_pasta_fp_sqrt(x)); +}; + +// Provides: caml_pasta_fp_of_int +// Requires: plonk_wasm +var caml_pasta_fp_of_int = plonk_wasm.caml_pasta_fp_of_int; + +// Provides: caml_pasta_fp_to_string +// Requires: plonk_wasm, caml_string_of_jsstring +var caml_pasta_fp_to_string = function (x) { + return caml_string_of_jsstring(plonk_wasm.caml_pasta_fp_to_string(x)); +}; + +// Provides: caml_pasta_fp_of_string +// Requires: plonk_wasm, caml_jsstring_of_string +var caml_pasta_fp_of_string = function (x) { + return plonk_wasm.caml_pasta_fp_of_string(caml_jsstring_of_string(x)); +}; + +// Provides: caml_pasta_fp_print +// Requires: plonk_wasm +var caml_pasta_fp_print = plonk_wasm.caml_pasta_fp_print; + +// Provides: caml_pasta_fp_mut_add +// Requires: caml_pasta_fp_copy, caml_pasta_fp_add +var caml_pasta_fp_mut_add = function (x, y) { + caml_pasta_fp_copy(x, caml_pasta_fp_add(x, y)); +}; + +// Provides: caml_pasta_fp_mut_sub +// Requires: caml_pasta_fp_copy, caml_pasta_fp_sub +var caml_pasta_fp_mut_sub = function (x, y) { + caml_pasta_fp_copy(x, caml_pasta_fp_sub(x, y)); +}; + +// Provides: caml_pasta_fp_mut_mul +// Requires: caml_pasta_fp_copy, caml_pasta_fp_mul +var caml_pasta_fp_mut_mul = function (x, y) { + caml_pasta_fp_copy(x, caml_pasta_fp_mul(x, y)); +}; + +// Provides: caml_pasta_fp_mut_square +// Requires: caml_pasta_fp_copy, caml_pasta_fp_square +var caml_pasta_fp_mut_square = function (x) { + caml_pasta_fp_copy(x, caml_pasta_fp_square(x)); +}; + +// Provides: caml_pasta_fp_compare +// Requires: plonk_wasm +var caml_pasta_fp_compare = plonk_wasm.caml_pasta_fp_compare; + +// Provides: caml_pasta_fp_equal +// Requires: plonk_wasm +var caml_pasta_fp_equal = plonk_wasm.caml_pasta_fp_equal; + +// Provides: caml_pasta_fp_random +// Requires: plonk_wasm +var caml_pasta_fp_random = plonk_wasm.caml_pasta_fp_random; + +// Provides: caml_pasta_fp_rng +// Requires: plonk_wasm +var caml_pasta_fp_rng = plonk_wasm.caml_pasta_fp_rng; + +// Provides: caml_pasta_fp_to_bigint +// Requires: plonk_wasm +var caml_pasta_fp_to_bigint = plonk_wasm.caml_pasta_fp_to_bigint; + +// Provides: caml_pasta_fp_of_bigint +// Requires: plonk_wasm +var caml_pasta_fp_of_bigint = plonk_wasm.caml_pasta_fp_of_bigint; + +// Provides: caml_pasta_fp_two_adic_root_of_unity +// Requires: plonk_wasm +var caml_pasta_fp_two_adic_root_of_unity = + plonk_wasm.caml_pasta_fp_two_adic_root_of_unity; + +// Provides: caml_pasta_fp_domain_generator +// Requires: plonk_wasm +var caml_pasta_fp_domain_generator = plonk_wasm.caml_pasta_fp_domain_generator; + +// Provides: caml_pasta_fp_to_bytes +// Requires: plonk_wasm, caml_bytes_of_uint8array +var caml_pasta_fp_to_bytes = function (x) { + var res = plonk_wasm.caml_pasta_fp_to_bytes(x); + return caml_bytes_of_uint8array(plonk_wasm.caml_pasta_fp_to_bytes(x)); +}; + +// Provides: caml_pasta_fp_of_bytes +// Requires: plonk_wasm, caml_bytes_to_uint8array +var caml_pasta_fp_of_bytes = function (ocaml_bytes) { + return plonk_wasm.caml_pasta_fp_of_bytes( + caml_bytes_to_uint8array(ocaml_bytes) + ); +}; + +// Provides: caml_pasta_fp_deep_copy +// Requires: plonk_wasm +var caml_pasta_fp_deep_copy = plonk_wasm.caml_pasta_fp_deep_copy; + +// Provides: caml_pasta_fq_copy +var caml_pasta_fq_copy = function (x, y) { + for (var i = 0, l = x.length; i < l; i++) { + x[i] = y[i]; + } +}; + +// Provides: caml_pasta_fq_size_in_bits +// Requires: plonk_wasm +var caml_pasta_fq_size_in_bits = plonk_wasm.caml_pasta_fq_size_in_bits; + +// Provides: caml_pasta_fq_size +// Requires: plonk_wasm +var caml_pasta_fq_size = plonk_wasm.caml_pasta_fq_size; + +// Provides: caml_pasta_fq_add +// Requires: plonk_wasm +var caml_pasta_fq_add = plonk_wasm.caml_pasta_fq_add; + +// Provides: caml_pasta_fq_sub +// Requires: plonk_wasm +var caml_pasta_fq_sub = plonk_wasm.caml_pasta_fq_sub; + +// Provides: caml_pasta_fq_negate +// Requires: plonk_wasm +var caml_pasta_fq_negate = plonk_wasm.caml_pasta_fq_negate; + +// Provides: caml_pasta_fq_mul +// Requires: plonk_wasm +var caml_pasta_fq_mul = plonk_wasm.caml_pasta_fq_mul; + +// Provides: caml_pasta_fq_div +// Requires: plonk_wasm +var caml_pasta_fq_div = plonk_wasm.caml_pasta_fq_div; + +// Provides: caml_pasta_fq_inv +// Requires: plonk_wasm, caml_option_of_maybe_undefined +var caml_pasta_fq_inv = function (x) { + return caml_option_of_maybe_undefined(plonk_wasm.caml_pasta_fq_inv(x)); +}; + +// Provides: caml_pasta_fq_square +// Requires: plonk_wasm +var caml_pasta_fq_square = plonk_wasm.caml_pasta_fq_square; + +// Provides: caml_pasta_fq_is_square +// Requires: plonk_wasm, caml_js_to_bool +var caml_pasta_fq_is_square = function (x) { + return caml_js_to_bool(plonk_wasm.caml_pasta_fq_is_square(x)); +}; + +// Provides: caml_pasta_fq_sqrt +// Requires: plonk_wasm, caml_option_of_maybe_undefined +var caml_pasta_fq_sqrt = function (x) { + return caml_option_of_maybe_undefined(plonk_wasm.caml_pasta_fq_sqrt(x)); +}; + +// Provides: caml_pasta_fq_of_int +// Requires: plonk_wasm +var caml_pasta_fq_of_int = plonk_wasm.caml_pasta_fq_of_int; + +// Provides: caml_pasta_fq_to_string +// Requires: plonk_wasm, caml_string_of_jsstring +var caml_pasta_fq_to_string = function (x) { + return caml_string_of_jsstring(plonk_wasm.caml_pasta_fq_to_string(x)); +}; + +// Provides: caml_pasta_fq_of_string +// Requires: plonk_wasm, caml_jsstring_of_string +var caml_pasta_fq_of_string = function (x) { + return plonk_wasm.caml_pasta_fq_of_string(caml_jsstring_of_string(x)); +}; + +// Provides: caml_pasta_fq_print +// Requires: plonk_wasm +var caml_pasta_fq_print = plonk_wasm.caml_pasta_fq_print; + +// Provides: caml_pasta_fq_mut_add +// Requires: caml_pasta_fq_copy, caml_pasta_fq_add +var caml_pasta_fq_mut_add = function (x, y) { + caml_pasta_fq_copy(x, caml_pasta_fq_add(x, y)); +}; + +// Provides: caml_pasta_fq_mut_sub +// Requires: caml_pasta_fq_copy, caml_pasta_fq_sub +var caml_pasta_fq_mut_sub = function (x, y) { + caml_pasta_fq_copy(x, caml_pasta_fq_sub(x, y)); +}; + +// Provides: caml_pasta_fq_mut_mul +// Requires: caml_pasta_fq_copy, caml_pasta_fq_mul +var caml_pasta_fq_mut_mul = function (x, y) { + caml_pasta_fq_copy(x, caml_pasta_fq_mul(x, y)); +}; + +// Provides: caml_pasta_fq_mut_square +// Requires: caml_pasta_fq_copy, caml_pasta_fq_square +var caml_pasta_fq_mut_square = function (x) { + caml_pasta_fq_copy(x, caml_pasta_fq_square(x)); +}; + +// Provides: caml_pasta_fq_compare +// Requires: plonk_wasm +var caml_pasta_fq_compare = plonk_wasm.caml_pasta_fq_compare; + +// Provides: caml_pasta_fq_equal +// Requires: plonk_wasm +var caml_pasta_fq_equal = plonk_wasm.caml_pasta_fq_equal; + +// Provides: caml_pasta_fq_random +// Requires: plonk_wasm +var caml_pasta_fq_random = plonk_wasm.caml_pasta_fq_random; + +// Provides: caml_pasta_fq_rng +// Requires: plonk_wasm +var caml_pasta_fq_rng = plonk_wasm.caml_pasta_fq_rng; + +// Provides: caml_pasta_fq_to_bigint +// Requires: plonk_wasm +var caml_pasta_fq_to_bigint = plonk_wasm.caml_pasta_fq_to_bigint; + +// Provides: caml_pasta_fq_of_bigint +// Requires: plonk_wasm +var caml_pasta_fq_of_bigint = plonk_wasm.caml_pasta_fq_of_bigint; + +// Provides: caml_pasta_fq_two_adic_root_of_unity +// Requires: plonk_wasm +var caml_pasta_fq_two_adic_root_of_unity = + plonk_wasm.caml_pasta_fq_two_adic_root_of_unity; + +// Provides: caml_pasta_fq_domain_generator +// Requires: plonk_wasm +var caml_pasta_fq_domain_generator = plonk_wasm.caml_pasta_fq_domain_generator; + +// Provides: caml_pasta_fq_to_bytes +// Requires: plonk_wasm, caml_bytes_of_uint8array +var caml_pasta_fq_to_bytes = function (x) { + var res = plonk_wasm.caml_pasta_fq_to_bytes(x); + return caml_bytes_of_uint8array(plonk_wasm.caml_pasta_fq_to_bytes(x)); +}; + +// Provides: caml_pasta_fq_of_bytes +// Requires: plonk_wasm, caml_bytes_to_uint8array +var caml_pasta_fq_of_bytes = function (ocaml_bytes) { + return plonk_wasm.caml_pasta_fq_of_bytes( + caml_bytes_to_uint8array(ocaml_bytes) + ); +}; + +// Provides: caml_pasta_fq_deep_copy +// Requires: plonk_wasm +var caml_pasta_fq_deep_copy = plonk_wasm.caml_pasta_fq_deep_copy; + +// Provides: caml_u8array_vector_to_rust_flat_vector +var caml_u8array_vector_to_rust_flat_vector = function (v) { + var i = 1; // The first entry is the OCaml tag for arrays + var len = v.length - i; + if (len === 0) { + return new joo_global_object.Uint8Array(0); + } + var inner_len = v[i].length; + var res = new joo_global_object.Uint8Array(len * inner_len); + for (var pos = 0; i <= len; i++) { + for (var j = 0; j < inner_len; j++, pos++) { + res[pos] = v[i][j]; + } + } + return res; +}; + +// Provides: caml_u8array_vector_of_rust_flat_vector +var caml_u8array_vector_of_rust_flat_vector = function (v, inner_len) { + var len = v.length; + var output_len = len / inner_len; + var res = new Array(output_len + 1); + res[0] = 0; // OCaml tag before array contents, so that we can use this with arrays or vectors + for (var i = 1, pos = 0; i <= output_len; i++) { + var inner_res = new joo_global_object.Uint8Array(inner_len); + for (var j = 0; j < inner_len; j++, pos++) { + inner_res[j] = v[pos]; + } + res[i] = inner_res; + } + return res; +}; + +// Provides: js_class_vector_to_rust_vector +var js_class_vector_to_rust_vector = function (v) { + var len = v.length; + var res = new joo_global_object.Uint32Array(len); + for (var i = 0; i < len; i++) { + // Beware: caller may need to do finalizer things to avoid these + // pointers disappearing out from under us. + res[i] = v[i].ptr; + } + return res; +}; + +// Provides: js_class_vector_of_rust_vector +var js_class_vector_of_rust_vector = function (v, klass) { + // return v.map(klass.__wrap) + var len = v.length; + var res = new Array(len); + for (var i = 0; i < len; i++) { + // Beware: the caller may need to add finalizers to these. + res[i] = klass.__wrap(v[i]); + } + return res; +}; + +// Provides: caml_fp_vector_create +var caml_fp_vector_create = function () { + return [0]; // OCaml tag for arrays, so that we can use the same utility fns on both +}; + +// Provides: caml_fp_vector_length +var caml_fp_vector_length = function (v) { + return v.length - 1; +}; + +// Provides: caml_fp_vector_emplace_back +var caml_fp_vector_emplace_back = function (v, x) { + v.push(x); +}; + +// Provides: caml_fp_vector_get +var caml_fp_vector_get = function (v, i) { + var value = v[i + 1]; + if (value === undefined) { + throw Error( + 'caml_fp_vector_get: Index out of bounds, got ' + i + '/' + (v.length - 1) + ); + } + return new joo_global_object.Uint8Array(value); +}; + +// Provides: caml_fp_vector_to_rust +// Requires: caml_u8array_vector_to_rust_flat_vector +var caml_fp_vector_to_rust = function (v) { + return caml_u8array_vector_to_rust_flat_vector(v); +}; + +// Provides: caml_fp_vector_of_rust +// Requires: caml_u8array_vector_of_rust_flat_vector +var caml_fp_vector_of_rust = function (v) { + // TODO: Hardcoding this is a little brittle + return caml_u8array_vector_of_rust_flat_vector(v, 32); +}; + +// Provides: caml_fq_vector_create +var caml_fq_vector_create = function () { + return [0]; // OCaml tag for arrays, so that we can use the same utility fns on both +}; + +// Provides: caml_fq_vector_length +var caml_fq_vector_length = function (v) { + return v.length - 1; +}; + +// Provides: caml_fq_vector_emplace_back +var caml_fq_vector_emplace_back = function (v, x) { + v.push(x); +}; + +// Provides: caml_fq_vector_get +var caml_fq_vector_get = function (v, i) { + var value = v[i + 1]; + if (value === undefined) { + throw Error( + 'caml_fq_vector_get: Index out of bounds, got ' + i + '/' + (v.length - 1) + ); + } + return new joo_global_object.Uint8Array(value); +}; + +// Provides: caml_fq_vector_to_rust +// Requires: caml_u8array_vector_to_rust_flat_vector +var caml_fq_vector_to_rust = function (v) { + return caml_u8array_vector_to_rust_flat_vector(v); +}; + +// Provides: caml_fq_vector_of_rust +// Requires: caml_u8array_vector_of_rust_flat_vector +var caml_fq_vector_of_rust = function (v) { + // TODO: Hardcoding this is a little brittle + return caml_u8array_vector_of_rust_flat_vector(v, 32); +}; + // Provides: free_finalization_registry -var free_finalization_registry = new globalThis.FinalizationRegistry(function ( - instance_representative -) { - instance_representative.free(); -}); +var free_finalization_registry = new joo_global_object.FinalizationRegistry( + function (instance_representative) { + instance_representative.free(); + } +); // Provides: free_on_finalize // Requires: free_finalization_registry @@ -84,16 +577,366 @@ var free_on_finalize = function (x) { // directly, but unfortunately the destructor name is some mangled internal // string generated by wasm_bindgen. For now, this is the best, // least-brittle way to free once the original class instance gets collected. - var instance_representative = x.constructor.__wrap(x.__wbg_ptr); + var instance_representative = x.constructor.__wrap(x.ptr); free_finalization_registry.register(x, instance_representative, x); return x; }; -// srs - +// Provides: rust_affine_to_caml_affine +var rust_affine_to_caml_affine = function (pt) { + var infinity = pt.infinity; + if (infinity) { + pt.free(); + return 0; + } else { + var x = pt.x; + var y = pt.y; + pt.free(); + return [0, [0, x, y]]; + } +}; + +// Provides: rust_affine_of_caml_affine +var rust_affine_of_caml_affine = function (pt, klass) { + var res = new klass(); + if (pt === 0) { + res.infinity = true; + } else { + // Layout is [0, [0, x, y]] + // First 0 is the tag (it's the 0th constructor that takes arguments) + // Second 0 is the block marker for the anonymous tuple arguments + res.x = pt[1][1]; + res.y = pt[1][2]; + } + return res; +}; + +// Provides: caml_pallas_one +// Requires: plonk_wasm, free_on_finalize +var caml_pallas_one = function () { + var res = plonk_wasm.caml_pallas_one(); + free_on_finalize(res); + return res; +}; + +// Provides: caml_pallas_add +// Requires: plonk_wasm, free_on_finalize +var caml_pallas_add = function (x, y) { + var res = plonk_wasm.caml_pallas_add(x, y); + free_on_finalize(res); + return res; +}; + +// Provides: caml_pallas_sub +// Requires: plonk_wasm, free_on_finalize +var caml_pallas_sub = function (x, y) { + var res = plonk_wasm.caml_pallas_sub(x, y); + free_on_finalize(res); + return res; +}; + +// Provides: caml_pallas_negate +// Requires: plonk_wasm, free_on_finalize +var caml_pallas_negate = function (x) { + var res = plonk_wasm.caml_pallas_negate(x); + free_on_finalize(res); + return res; +}; + +// Provides: caml_pallas_double +// Requires: plonk_wasm, free_on_finalize +var caml_pallas_double = function (x) { + var res = plonk_wasm.caml_pallas_double(x); + free_on_finalize(res); + return res; +}; + +// Provides: caml_pallas_scale +// Requires: plonk_wasm, free_on_finalize +var caml_pallas_scale = function (x, y) { + var res = plonk_wasm.caml_pallas_scale(x, y); + free_on_finalize(res); + return res; +}; + +// Provides: caml_pallas_random +// Requires: plonk_wasm, free_on_finalize +var caml_pallas_random = function () { + var res = plonk_wasm.caml_pallas_random(); + free_on_finalize(res); + return res; +}; + +// Provides: caml_pallas_rng +// Requires: plonk_wasm, free_on_finalize +var caml_pallas_rng = function (i) { + var res = plonk_wasm.caml_pallas_rng(i); + free_on_finalize(res); + return res; +}; + +// Provides: caml_pallas_to_affine +// Requires: plonk_wasm, rust_affine_to_caml_affine +var caml_pallas_to_affine = function (pt) { + var res = plonk_wasm.caml_pallas_to_affine(pt); + return rust_affine_to_caml_affine(res); +}; + +// Provides: caml_pallas_of_affine +// Requires: plonk_wasm, rust_affine_of_caml_affine, free_on_finalize +var caml_pallas_of_affine = function (pt) { + var res = plonk_wasm.caml_pallas_of_affine( + rust_affine_of_caml_affine(pt, plonk_wasm.caml_pallas_affine_one) + ); + free_on_finalize(res); + return res; +}; + +// Provides: caml_pallas_of_affine_coordinates +// Requires: plonk_wasm, free_on_finalize +var caml_pallas_of_affine_coordinates = function (x, y) { + var res = plonk_wasm.caml_pallas_of_affine_coordinates(x, y); + free_on_finalize(res); + return res; +}; + +// Provides: caml_pallas_endo_base +// Requires: plonk_wasm +var caml_pallas_endo_base = plonk_wasm.caml_pallas_endo_base; + +// Provides: caml_pallas_endo_scalar +// Requires: plonk_wasm +var caml_pallas_endo_scalar = plonk_wasm.caml_pallas_endo_scalar; + +// Provides: caml_pallas_affine_deep_copy +// Requires: plonk_wasm, rust_affine_of_caml_affine, rust_affine_to_caml_affine +var caml_pallas_affine_deep_copy = function (pt) { + return rust_affine_to_caml_affine( + plonk_wasm.caml_pallas_affine_deep_copy( + rust_affine_of_caml_affine(pt, plonk_wasm.caml_pallas_affine_one) + ) + ); +}; + +// Provides: caml_vesta_one +// Requires: plonk_wasm, free_on_finalize +var caml_vesta_one = function () { + var res = plonk_wasm.caml_vesta_one(); + free_on_finalize(res); + return res; +}; + +// Provides: caml_vesta_add +// Requires: plonk_wasm, free_on_finalize +var caml_vesta_add = function (x, y) { + var res = plonk_wasm.caml_vesta_add(x, y); + free_on_finalize(res); + return res; +}; + +// Provides: caml_vesta_sub +// Requires: plonk_wasm, free_on_finalize +var caml_vesta_sub = function (x, y) { + var res = plonk_wasm.caml_vesta_sub(x, y); + free_on_finalize(res); + return res; +}; + +// Provides: caml_vesta_negate +// Requires: plonk_wasm, free_on_finalize +var caml_vesta_negate = function (x) { + var res = plonk_wasm.caml_vesta_negate(x); + free_on_finalize(res); + return res; +}; + +// Provides: caml_vesta_double +// Requires: plonk_wasm, free_on_finalize +var caml_vesta_double = function (x) { + var res = plonk_wasm.caml_vesta_double(x); + free_on_finalize(res); + return res; +}; + +// Provides: caml_vesta_scale +// Requires: plonk_wasm, free_on_finalize +var caml_vesta_scale = function (x, y) { + var res = plonk_wasm.caml_vesta_scale(x, y); + free_on_finalize(res); + return res; +}; + +// Provides: caml_vesta_random +// Requires: plonk_wasm, free_on_finalize +var caml_vesta_random = function () { + var res = plonk_wasm.caml_vesta_random(); + free_on_finalize(res); + return res; +}; + +// Provides: caml_vesta_rng +// Requires: plonk_wasm, free_on_finalize +var caml_vesta_rng = function (i) { + var res = plonk_wasm.caml_vesta_rng(i); + free_on_finalize(res); + return res; +}; + +// Provides: caml_vesta_to_affine +// Requires: plonk_wasm, rust_affine_to_caml_affine +var caml_vesta_to_affine = function (pt) { + var res = plonk_wasm.caml_vesta_to_affine(pt); + return rust_affine_to_caml_affine(res); +}; + +// Provides: caml_vesta_of_affine +// Requires: plonk_wasm, rust_affine_of_caml_affine, free_on_finalize +var caml_vesta_of_affine = function (pt) { + var res = plonk_wasm.caml_vesta_of_affine( + rust_affine_of_caml_affine(pt, plonk_wasm.caml_vesta_affine_one) + ); + free_on_finalize(res); + return res; +}; + +// Provides: caml_vesta_of_affine_coordinates +// Requires: plonk_wasm, free_on_finalize +var caml_vesta_of_affine_coordinates = function (x, y) { + var res = plonk_wasm.caml_vesta_of_affine_coordinates(x, y); + free_on_finalize(res); + return res; +}; + +// Provides: caml_vesta_endo_base +// Requires: plonk_wasm +var caml_vesta_endo_base = plonk_wasm.caml_vesta_endo_base; + +// Provides: caml_vesta_endo_scalar +// Requires: plonk_wasm +var caml_vesta_endo_scalar = plonk_wasm.caml_vesta_endo_scalar; + +// Provides: caml_vesta_affine_deep_copy +// Requires: plonk_wasm, rust_affine_of_caml_affine, rust_affine_to_caml_affine +var caml_vesta_affine_deep_copy = function (pt) { + return rust_affine_to_caml_affine( + plonk_wasm.caml_vesta_affine_deep_copy( + rust_affine_of_caml_affine(pt, plonk_wasm.caml_vesta_affine_one) + ) + ); +}; + +// Provides: caml_array_of_rust_vector +// Requires: js_class_vector_of_rust_vector +var caml_array_of_rust_vector = function (v, klass, convert, should_free) { + v = js_class_vector_of_rust_vector(v, klass); + var len = v.length; + var res = new Array(len + 1); + res[0] = 0; // OCaml tag before array contents + for (var i = 0; i < len; i++) { + var rust_val = v[i]; + res[i + 1] = convert(rust_val); + if (should_free) { + rust_val.free(); + } + } + return res; +}; + +// Provides: caml_array_to_rust_vector +// Requires: js_class_vector_to_rust_vector, free_finalization_registry +var caml_array_to_rust_vector = function (v, convert, mk_new) { + v = v.slice(1); // Copy, dropping OCaml tag + for (var i = 0, l = v.length; i < l; i++) { + var class_val = convert(v[i], mk_new); + v[i] = class_val; + // Don't free when GC runs; rust will free on its end. + free_finalization_registry.unregister(class_val); + } + return js_class_vector_to_rust_vector(v); +}; + +// Provides: caml_poly_comm_of_rust_poly_comm +// Requires: rust_affine_to_caml_affine, caml_array_of_rust_vector +var caml_poly_comm_of_rust_poly_comm = function ( + poly_comm, + klass, + should_free +) { + var rust_shifted = poly_comm.shifted; + var rust_unshifted = poly_comm.unshifted; + var caml_shifted; + if (rust_shifted === undefined) { + caml_shifted = 0; + } else { + caml_shifted = [0, rust_affine_to_caml_affine(rust_shifted)]; + } + var caml_unshifted = caml_array_of_rust_vector( + rust_unshifted, + klass, + rust_affine_to_caml_affine, + should_free + ); + return [0, caml_unshifted, caml_shifted]; +}; + +// Provides: caml_poly_comm_to_rust_poly_comm +// Requires: rust_affine_of_caml_affine, caml_array_to_rust_vector +var caml_poly_comm_to_rust_poly_comm = function ( + poly_comm, + poly_comm_class, + mk_affine +) { + var caml_unshifted = poly_comm[1]; + var caml_shifted = poly_comm[2]; + var rust_shifted = undefined; + if (caml_shifted !== 0) { + rust_shifted = rust_affine_of_caml_affine(caml_shifted[1], mk_affine); + } + var rust_unshifted = caml_array_to_rust_vector( + caml_unshifted, + rust_affine_of_caml_affine, + mk_affine + ); + return new poly_comm_class(rust_unshifted, rust_shifted); +}; + +// Provides: caml_vesta_poly_comm_of_rust +// Requires: plonk_wasm, caml_poly_comm_of_rust_poly_comm +var caml_vesta_poly_comm_of_rust = function (x) { + return caml_poly_comm_of_rust_poly_comm(x, plonk_wasm.WasmGVesta, false); +}; + +// Provides: caml_vesta_poly_comm_to_rust +// Requires: plonk_wasm, caml_poly_comm_to_rust_poly_comm +var caml_vesta_poly_comm_to_rust = function (x) { + return caml_poly_comm_to_rust_poly_comm( + x, + plonk_wasm.WasmFpPolyComm, + plonk_wasm.caml_vesta_affine_one + ); +}; + +// Provides: caml_pallas_poly_comm_of_rust +// Requires: plonk_wasm, caml_poly_comm_of_rust_poly_comm +var caml_pallas_poly_comm_of_rust = function (x) { + return caml_poly_comm_of_rust_poly_comm(x, plonk_wasm.WasmGPallas, false); +}; + +// Provides: caml_pallas_poly_comm_to_rust +// Requires: plonk_wasm, caml_poly_comm_to_rust_poly_comm +var caml_pallas_poly_comm_to_rust = function (x) { + return caml_poly_comm_to_rust_poly_comm( + x, + plonk_wasm.WasmFqPolyComm, + plonk_wasm.caml_pallas_affine_one + ); +}; + // Provides: caml_fp_srs_create -// Requires: tsSrs -var caml_fp_srs_create = tsSrs.fp.create; +// Requires: plonk_wasm, free_on_finalize +var caml_fp_srs_create = function (i) { + return free_on_finalize(plonk_wasm.caml_fp_srs_create(i)); +}; // Provides: caml_fp_srs_write // Requires: plonk_wasm, caml_jsstring_of_string @@ -123,35 +966,42 @@ var caml_fp_srs_read = function (offset, path) { }; // Provides: caml_fp_srs_lagrange_commitment -// Requires: tsSrs -var caml_fp_srs_lagrange_commitment = tsSrs.fp.lagrangeCommitment; +// Requires: plonk_wasm, caml_vesta_poly_comm_of_rust +var caml_fp_srs_lagrange_commitment = function (t, domain_size, i) { + var res = plonk_wasm.caml_fp_srs_lagrange_commitment(t, domain_size, i); + return caml_vesta_poly_comm_of_rust(res); +}; // Provides: caml_fp_srs_commit_evaluations -// Requires: plonk_wasm, tsRustConversion +// Requires: plonk_wasm, caml_vesta_poly_comm_of_rust, caml_fp_vector_to_rust var caml_fp_srs_commit_evaluations = function (t, domain_size, fps) { var res = plonk_wasm.caml_fp_srs_commit_evaluations( t, domain_size, - tsRustConversion.fp.vectorToRust(fps) + caml_fp_vector_to_rust(fps) ); - return tsRustConversion.fp.polyCommFromRust(res); + return caml_vesta_poly_comm_of_rust(res); }; // Provides: caml_fp_srs_b_poly_commitment -// Requires: plonk_wasm, tsRustConversion +// Requires: plonk_wasm, caml_vesta_poly_comm_of_rust, caml_u8array_vector_to_rust_flat_vector var caml_fp_srs_b_poly_commitment = function (srs, chals) { var res = plonk_wasm.caml_fp_srs_b_poly_commitment( srs, - tsRustConversion.fieldsToRustFlat(chals) + caml_u8array_vector_to_rust_flat_vector(chals) ); - return tsRustConversion.fp.polyCommFromRust(res); + return caml_vesta_poly_comm_of_rust(res); }; // Provides: caml_fp_srs_batch_accumulator_check -// Requires: plonk_wasm, tsRustConversion +// Requires: plonk_wasm, rust_affine_of_caml_affine, caml_array_to_rust_vector, caml_fp_vector_to_rust var caml_fp_srs_batch_accumulator_check = function (srs, comms, chals) { - var rust_comms = tsRustConversion.fp.pointsToRust(comms); - var rust_chals = tsRustConversion.fp.vectorToRust(chals); + var rust_comms = caml_array_to_rust_vector( + comms, + rust_affine_of_caml_affine, + plonk_wasm.caml_vesta_affine_one + ); + var rust_chals = caml_fp_vector_to_rust(chals); var ok = plonk_wasm.caml_fp_srs_batch_accumulator_check( srs, rust_comms, @@ -161,30 +1011,33 @@ var caml_fp_srs_batch_accumulator_check = function (srs, comms, chals) { }; // Provides: caml_fp_srs_batch_accumulator_generate -// Requires: plonk_wasm, tsRustConversion -var caml_fp_srs_batch_accumulator_generate = function (srs, n_comms, chals) { - var rust_chals = tsRustConversion.fp.vectorToRust(chals); +// Requires: plonk_wasm, rust_affine_to_caml_affine, caml_array_of_rust_vector, caml_fp_vector_to_rust +var caml_fp_srs_batch_accumulator_generate = function (srs, comms, chals) { + var rust_chals = caml_fp_vector_to_rust(chals); var rust_comms = plonk_wasm.caml_fp_srs_batch_accumulator_generate( srs, - n_comms, + comms, rust_chals ); - return tsRustConversion.fp.pointsFromRust(rust_comms); + return caml_array_of_rust_vector( + rust_comms, + plonk_wasm.WasmGVesta, + rust_affine_to_caml_affine, + false + ); }; // Provides: caml_fp_srs_h -// Requires: plonk_wasm, tsRustConversion +// Requires: plonk_wasm, rust_affine_to_caml_affine var caml_fp_srs_h = function (t) { - return tsRustConversion.fp.pointFromRust(plonk_wasm.caml_fp_srs_h(t)); + return rust_affine_to_caml_affine(plonk_wasm.caml_fp_srs_h(t)); }; -// Provides: caml_fp_srs_add_lagrange_basis -// Requires: tsSrs -var caml_fp_srs_add_lagrange_basis = tsSrs.fp.addLagrangeBasis; - // Provides: caml_fq_srs_create -// Requires: tsSrs -var caml_fq_srs_create = tsSrs.fq.create; +// Requires: plonk_wasm, free_on_finalize +var caml_fq_srs_create = function (i) { + return free_on_finalize(plonk_wasm.caml_fq_srs_create(i)); +}; // Provides: caml_fq_srs_write // Requires: plonk_wasm, caml_jsstring_of_string @@ -214,35 +1067,42 @@ var caml_fq_srs_read = function (offset, path) { }; // Provides: caml_fq_srs_lagrange_commitment -// Requires: tsSrs -var caml_fq_srs_lagrange_commitment = tsSrs.fq.lagrangeCommitment; +// Requires: plonk_wasm, caml_pallas_poly_comm_of_rust +var caml_fq_srs_lagrange_commitment = function (t, domain_size, i) { + var res = plonk_wasm.caml_fq_srs_lagrange_commitment(t, domain_size, i); + return caml_pallas_poly_comm_of_rust(res); +}; // Provides: caml_fq_srs_commit_evaluations -// Requires: plonk_wasm, tsRustConversion +// Requires: plonk_wasm, caml_pallas_poly_comm_of_rust, caml_fq_vector_to_rust var caml_fq_srs_commit_evaluations = function (t, domain_size, fqs) { var res = plonk_wasm.caml_fq_srs_commit_evaluations( t, domain_size, - tsRustConversion.fq.vectorToRust(fqs) + caml_fq_vector_to_rust(fqs) ); - return tsRustConversion.fq.polyCommFromRust(res); + return caml_pallas_poly_comm_of_rust(res); }; // Provides: caml_fq_srs_b_poly_commitment -// Requires: plonk_wasm, tsRustConversion +// Requires: plonk_wasm, caml_pallas_poly_comm_of_rust, caml_u8array_vector_to_rust_flat_vector var caml_fq_srs_b_poly_commitment = function (srs, chals) { var res = plonk_wasm.caml_fq_srs_b_poly_commitment( srs, - tsRustConversion.fieldsToRustFlat(chals) + caml_u8array_vector_to_rust_flat_vector(chals) ); - return tsRustConversion.fq.polyCommFromRust(res); + return caml_pallas_poly_comm_of_rust(res); }; // Provides: caml_fq_srs_batch_accumulator_check -// Requires: plonk_wasm, tsRustConversion +// Requires: plonk_wasm, rust_affine_of_caml_affine, caml_array_to_rust_vector, caml_fq_vector_to_rust var caml_fq_srs_batch_accumulator_check = function (srs, comms, chals) { - var rust_comms = tsRustConversion.fq.pointsToRust(comms); - var rust_chals = tsRustConversion.fq.vectorToRust(chals); + var rust_comms = caml_array_to_rust_vector( + comms, + rust_affine_of_caml_affine, + plonk_wasm.caml_pallas_affine_one + ); + var rust_chals = caml_fq_vector_to_rust(chals); var ok = plonk_wasm.caml_fq_srs_batch_accumulator_check( srs, rust_comms, @@ -252,28 +1112,112 @@ var caml_fq_srs_batch_accumulator_check = function (srs, comms, chals) { }; // Provides: caml_fq_srs_batch_accumulator_generate -// Requires: plonk_wasm, tsRustConversion +// Requires: plonk_wasm, rust_affine_to_caml_affine, caml_array_of_rust_vector, caml_fq_vector_to_rust var caml_fq_srs_batch_accumulator_generate = function (srs, comms, chals) { - var rust_chals = tsRustConversion.fq.vectorToRust(chals); + var rust_chals = caml_fq_vector_to_rust(chals); var rust_comms = plonk_wasm.caml_fq_srs_batch_accumulator_generate( srs, comms, rust_chals ); - return tsRustConversion.fq.pointsFromRust(rust_comms); + return caml_array_of_rust_vector( + rust_comms, + plonk_wasm.WasmGPallas, + rust_affine_to_caml_affine, + false + ); }; // Provides: caml_fq_srs_h -// Requires: plonk_wasm, tsRustConversion +// Requires: plonk_wasm, rust_affine_to_caml_affine var caml_fq_srs_h = function (t) { - return tsRustConversion.fq.pointFromRust(plonk_wasm.caml_fq_srs_h(t)); + return rust_affine_to_caml_affine(plonk_wasm.caml_fq_srs_h(t)); }; // Provides: caml_fq_srs_add_lagrange_basis -// Requires: tsSrs -var caml_fq_srs_add_lagrange_basis = tsSrs.fq.addLagrangeBasis; +// Requires: plonk_wasm +function caml_fq_srs_add_lagrange_basis(srs, log2_size) { + return plonk_wasm.caml_fq_srs_add_lagrange_basis(srs, log2_size); +} + +// Provides: caml_plonk_wire_of_rust +var caml_plonk_wire_of_rust = function (wire) { + var res = [0, wire.row, wire.col]; + wire.free(); + return res; +}; + +// Provides: caml_plonk_wire_to_rust +// Requires: plonk_wasm +var caml_plonk_wire_to_rust = function (wire) { + return plonk_wasm.Wire.create(wire[1], wire[2]); +}; + +// Provides: caml_plonk_wires_of_rust +// Requires: caml_plonk_wire_of_rust +var caml_plonk_wires_of_rust = function (wires) { + var res = [ + 0, + caml_plonk_wire_of_rust(wires[0]), + caml_plonk_wire_of_rust(wires[1]), + caml_plonk_wire_of_rust(wires[2]), + caml_plonk_wire_of_rust(wires[3]), + caml_plonk_wire_of_rust(wires[4]), + caml_plonk_wire_of_rust(wires[5]), + caml_plonk_wire_of_rust(wires[6]), + ]; + wires.free(); + return res; +}; + +// Provides: caml_plonk_wires_to_rust +// Requires: plonk_wasm, caml_plonk_wire_to_rust +var caml_plonk_wires_to_rust = function (wires) { + return new plonk_wasm.WasmGateWires( + caml_plonk_wire_to_rust(wires[1]), + caml_plonk_wire_to_rust(wires[2]), + caml_plonk_wire_to_rust(wires[3]), + caml_plonk_wire_to_rust(wires[4]), + caml_plonk_wire_to_rust(wires[5]), + caml_plonk_wire_to_rust(wires[6]), + caml_plonk_wire_to_rust(wires[7]) + ); +}; + +// Provides: caml_plonk_gate_of_rust +// Requires: caml_plonk_wires_of_rust, caml_u8array_vector_of_rust_flat_vector +var caml_plonk_gate_of_rust = function (gate) { + // TODO: Hardcoding 32 here is a little brittle + var res = [ + 0, + gate.typ, + caml_plonk_wires_of_rust(gate.wires), + caml_u8array_vector_of_rust_flat_vector(gate.c, 32), + ]; + gate.free(); + return res; +}; + +// Provides: caml_fp_plonk_gate_to_rust +// Requires: plonk_wasm, caml_plonk_wires_to_rust, caml_u8array_vector_to_rust_flat_vector +var caml_fp_plonk_gate_to_rust = function (gate) { + return new plonk_wasm.WasmFpGate( + gate[1], + caml_plonk_wires_to_rust(gate[2]), + caml_u8array_vector_to_rust_flat_vector(gate[3]) + ); +}; -// gate vector +// Provides: caml_fq_plonk_gate_to_rust +// Requires: plonk_wasm, caml_plonk_wires_to_rust, caml_u8array_vector_to_rust_flat_vector +var caml_fq_plonk_gate_to_rust = function (gate) { + // TODO: Hardcoding 32 here is a little brittle + return new plonk_wasm.WasmFqGate( + gate[1], + caml_plonk_wires_to_rust(gate[2]), + caml_u8array_vector_to_rust_flat_vector(gate[3]) + ); +}; // Provides: caml_pasta_fp_plonk_gate_vector_create // Requires: plonk_wasm, free_on_finalize @@ -282,18 +1226,18 @@ var caml_pasta_fp_plonk_gate_vector_create = function () { }; // Provides: caml_pasta_fp_plonk_gate_vector_add -// Requires: plonk_wasm, tsRustConversion +// Requires: plonk_wasm, caml_fp_plonk_gate_to_rust var caml_pasta_fp_plonk_gate_vector_add = function (v, x) { return plonk_wasm.caml_pasta_fp_plonk_gate_vector_add( v, - tsRustConversion.fp.gateToRust(x) + caml_fp_plonk_gate_to_rust(x) ); }; // Provides: caml_pasta_fp_plonk_gate_vector_get -// Requires: plonk_wasm, tsRustConversion +// Requires: plonk_wasm, caml_plonk_gate_of_rust var caml_pasta_fp_plonk_gate_vector_get = function (v, i) { - return tsRustConversion.fp.gateFromRust( + return caml_plonk_gate_of_rust( plonk_wasm.caml_pasta_fp_plonk_gate_vector_get(v, i) ); }; @@ -305,12 +1249,12 @@ var caml_pasta_fp_plonk_gate_vector_len = function (v) { }; // Provides: caml_pasta_fp_plonk_gate_vector_wrap -// Requires: plonk_wasm, tsRustConversion +// Requires: plonk_wasm, caml_plonk_wire_to_rust var caml_pasta_fp_plonk_gate_vector_wrap = function (v, x, y) { return plonk_wasm.caml_pasta_fp_plonk_gate_vector_wrap( v, - tsRustConversion.wireToRust(x), - tsRustConversion.wireToRust(y) + caml_plonk_wire_to_rust(x), + caml_plonk_wire_to_rust(y) ); }; @@ -341,8 +1285,6 @@ var caml_pasta_fp_plonk_circuit_serialize = function ( ); }; -// prover index - // Provides: caml_pasta_fq_plonk_gate_vector_create // Requires: plonk_wasm, free_on_finalize var caml_pasta_fq_plonk_gate_vector_create = function () { @@ -350,18 +1292,18 @@ var caml_pasta_fq_plonk_gate_vector_create = function () { }; // Provides: caml_pasta_fq_plonk_gate_vector_add -// Requires: plonk_wasm, tsRustConversion +// Requires: plonk_wasm, caml_fq_plonk_gate_to_rust var caml_pasta_fq_plonk_gate_vector_add = function (v, x) { return plonk_wasm.caml_pasta_fq_plonk_gate_vector_add( v, - tsRustConversion.fq.gateToRust(x) + caml_fq_plonk_gate_to_rust(x) ); }; // Provides: caml_pasta_fq_plonk_gate_vector_get -// Requires: plonk_wasm, tsRustConversion +// Requires: plonk_wasm, caml_plonk_gate_of_rust var caml_pasta_fq_plonk_gate_vector_get = function (v, i) { - return tsRustConversion.fq.gateFromRust( + return caml_plonk_gate_of_rust( plonk_wasm.caml_pasta_fq_plonk_gate_vector_get(v, i) ); }; @@ -373,12 +1315,12 @@ var caml_pasta_fq_plonk_gate_vector_len = function (v) { }; // Provides: caml_pasta_fq_plonk_gate_vector_wrap -// Requires: plonk_wasm, tsRustConversion +// Requires: plonk_wasm, caml_plonk_wire_to_rust var caml_pasta_fq_plonk_gate_vector_wrap = function (v, x, y) { return plonk_wasm.caml_pasta_fq_plonk_gate_vector_wrap( v, - tsRustConversion.wireToRust(x), - tsRustConversion.wireToRust(y) + caml_plonk_wire_to_rust(x), + caml_plonk_wire_to_rust(y) ); }; @@ -410,52 +1352,22 @@ var caml_pasta_fq_plonk_circuit_serialize = function ( }; // Provides: caml_pasta_fp_plonk_index_create -// Requires: plonk_wasm, free_on_finalize, tsRustConversion +// Requires: plonk_wasm, free_on_finalize var caml_pasta_fp_plonk_index_create = function ( gates, public_inputs, - caml_lookup_tables, - caml_runtime_table_cfgs, prev_challenges, urs ) { - var wasm_lookup_tables = - tsRustConversion.fp.lookupTablesToRust(caml_lookup_tables); - var wasm_runtime_table_cfgs = tsRustConversion.fp.runtimeTableCfgsToRust( - caml_runtime_table_cfgs - ); - var t = plonk_wasm.caml_pasta_fp_plonk_index_create( gates, public_inputs, - wasm_lookup_tables, - wasm_runtime_table_cfgs, prev_challenges, urs ); return free_on_finalize(t); }; -// Provides: caml_pasta_fp_plonk_index_create_bytecode -// Requires: caml_pasta_fp_plonk_index_create -var caml_pasta_fp_plonk_index_create_bytecode = function ( - gates, - public_inputs, - caml_lookup_tables, - caml_runtime_table_cfgs, - prev_challenges, - urs -) { - return caml_pasta_fp_plonk_index_create( - gates, - public_inputs, - caml_lookup_tables, - caml_runtime_table_cfgs, - prev_challenges, - urs - ); -}; - // Provides: caml_pasta_fp_plonk_index_max_degree // Requires: plonk_wasm var caml_pasta_fp_plonk_index_max_degree = @@ -512,53 +1424,23 @@ var caml_pasta_fp_plonk_index_write = function (append, t, path) { }; // Provides: caml_pasta_fq_plonk_index_create -// Requires: plonk_wasm, free_on_finalize, tsRustConversion +// Requires: plonk_wasm, free_on_finalize var caml_pasta_fq_plonk_index_create = function ( gates, public_inputs, - caml_lookup_tables, - caml_runtime_table_cfgs, prev_challenges, urs ) { - var wasm_lookup_tables = - tsRustConversion.fq.lookupTablesToRust(caml_lookup_tables); - var wasm_runtime_table_cfgs = tsRustConversion.fq.runtimeTableCfgsToRust( - caml_runtime_table_cfgs - ); - return free_on_finalize( plonk_wasm.caml_pasta_fq_plonk_index_create( gates, public_inputs, - wasm_lookup_tables, - wasm_runtime_table_cfgs, prev_challenges, urs ) ); }; -// Provides: caml_pasta_fq_plonk_index_create_bytecode -// Requires: caml_pasta_fq_plonk_index_create -var caml_pasta_fq_plonk_index_create_bytecode = function ( - gates, - public_inputs, - caml_lookup_tables, - caml_runtime_table_cfgs, - prev_challenges, - urs -) { - return caml_pasta_fq_plonk_index_create( - gates, - public_inputs, - caml_lookup_tables, - caml_runtime_table_cfgs, - prev_challenges, - urs - ); -}; - // Provides: caml_pasta_fq_plonk_index_max_degree // Requires: plonk_wasm var caml_pasta_fq_plonk_index_max_degree = @@ -614,44 +1496,628 @@ var caml_pasta_fq_plonk_index_write = function (append, t, path) { ); }; -// verifier index +// Provides: caml_plonk_domain_of_rust +var caml_plonk_domain_of_rust = function (x) { + var log_size_of_group = x.log_size_of_group; + var group_gen = x.group_gen; + x.free(); + return [0, log_size_of_group, group_gen]; +}; + +// Provides: caml_plonk_domain_to_rust +// Requires: free_on_finalize +var caml_plonk_domain_to_rust = function (x, klass) { + // TODO: Check if this gets finalized + return new klass(x[1], x[2]); +}; + +// Provides: caml_plonk_verification_evals_of_rust +// Requires: caml_poly_comm_of_rust_poly_comm, js_class_vector_of_rust_vector, plonk_wasm +var caml_plonk_verification_evals_of_rust = function (x, affine_klass) { + var convert = function (poly_comm) { + return caml_poly_comm_of_rust_poly_comm(poly_comm, affine_klass, false); + }; + + // var convertArray = function(comms) { + // var n = comms.length; + // var res = new Array(n-1); + // for (var i = 1; i < n; i++) { + // res[i-1] = convert(comms[i]); + // } + // return js_class_vector_to_rust_vector(res); + // }; + + // should be inverse of the above ^ + // TODO: make work for both Wasm..PolyComm types + var convertArray = function (comms) { + comms = js_class_vector_of_rust_vector(comms, plonk_wasm.WasmFqPolyComm); + // comms = js_class_vector_of_rust_vector(comms, plonk_wasm.WasmFpPolyComm); + return [0].concat(comms.map(convert)); + }; + + var sigma_comm = convertArray(x.sigma_comm); + var coefficients_comm = convertArray(x.coefficients_comm); + var generic_comm = convert(x.generic_comm); + var psm_comm = convert(x.psm_comm); + var complete_add_comm = convert(x.complete_add_comm); + var mul_comm = convert(x.mul_comm); + var emul_comm = convert(x.emul_comm); + var endomul_scalar_comm = convert(x.endomul_scalar_comm); + + x.free(); + return [ + 0, + sigma_comm, + coefficients_comm, + generic_comm, + psm_comm, + complete_add_comm, + mul_comm, + emul_comm, + endomul_scalar_comm, + 0, + ]; +}; + +// Provides: caml_plonk_verification_evals_to_rust +// Requires: caml_poly_comm_to_rust_poly_comm, js_class_vector_to_rust_vector +var caml_plonk_verification_evals_to_rust = function ( + x, + klass, + poly_comm_to_rust +) { + var convertArray = function (comms) { + var n = comms.length; + var res = new Array(n - 1); + for (var i = 1; i < n; i++) { + res[i - 1] = poly_comm_to_rust(comms[i]); + } + return js_class_vector_to_rust_vector(res); + }; + + var sigma_comm = convertArray(x[1]); + var coefficients_comm = convertArray(x[2]); + var generic_comm = poly_comm_to_rust(x[3]); + var psm_comm = poly_comm_to_rust(x[4]); + var complete_add_comm = poly_comm_to_rust(x[5]); + var mul_comm = poly_comm_to_rust(x[6]); + var emul_comm = poly_comm_to_rust(x[7]); + var endomul_scalar_comm = poly_comm_to_rust(x[8]); + + return new klass( + sigma_comm, + coefficients_comm, + generic_comm, + psm_comm, + complete_add_comm, + mul_comm, + emul_comm, + endomul_scalar_comm + ); +}; + +// Provides: caml_plonk_verification_shifts_of_rust +var caml_plonk_verification_shifts_of_rust = function (x) { + var res = [0, x.s0, x.s1, x.s2, x.s3, x.s4, x.s5, x.s6]; + x.free(); + return res; +}; + +// Provides: caml_plonk_verification_shifts_to_rust +var caml_plonk_verification_shifts_to_rust = function (x, klass) { + return new klass(x[1], x[2], x[3], x[4], x[5], x[6], x[7]); +}; + +// Provides: column_of_rust +function column_of_rust(col) { + // type nonrec column = Witness of int | Z | LookupSorted of int | LookupAggreg | LookupTable | LookupKindIndex of int | Index of gate_type | Coefficient of int + var tag = col.tag; + var gate_type = col.gate_type; + var i = col.i; + col.free(); + return ( + { + 0: [tag, i], + 2: [tag, i], + 5: [tag, i], + 6: [tag, gate_type], + 7: [tag, i], + }[tag] || tag + ); +} + +// Provides: variable_of_rust +// Requires: column_of_rust +function variable_of_rust(variable) { + // col * row + var col = variable.col; + var row = variable.row; // 0, 1 + variable.free(); + return [0, column_of_rust(col), row]; +} + +// Provides: polish_token_of_rust +// Requires: variable_of_rust +function polish_token_of_rust(token) { + var tag = token.tag; + var i0 = token.i0; + var i1 = token.i1; + var f = token.f; + var v = variable_of_rust(token.v); + token.free(); + return ( + { + 5: [5, i0, i1], + 6: [6, f], + 7: [7, v], + 9: [9, i0], + 14: [14, i0], + 16: [16, i0], + }[tag] || tag + ); +} + +// Provides: index_term_of_rust +// Requires: column_of_rust, js_class_vector_of_rust_vector, polish_token_of_rust +function index_term_of_rust(term, token_class) { + // pub column: WasmColumn, + // pub coefficient: WasmVector, + var column = column_of_rust(term.column); + var coefficient = js_class_vector_of_rust_vector( + term.coefficient, + token_class + ); + coefficient = coefficient.map(polish_token_of_rust); + coefficient = [0].concat(coefficient); + term.free(); + return [0, column, coefficient]; +} + +// Provides: wrap +function wrap(ptr, klass) { + var obj = Object.create(klass.prototype); + obj.ptr = ptr; + return obj; +} + +// Provides: linearization_of_rust +// Requires: plonk_wasm, js_class_vector_of_rust_vector, polish_token_of_rust, wrap, index_term_of_rust +function linearization_of_rust(linearization, affine_class) { + var F = affine_class === plonk_wasm.WasmGVesta ? 'Fq' : 'Fp'; + var WasmPolishToken = plonk_wasm['Wasm' + F + 'PolishToken']; + var WasmIndexTerm = plonk_wasm['Wasm' + F + 'IndexTerm']; + + var constant_term = js_class_vector_of_rust_vector( + linearization.constant_term, + WasmPolishToken + ); + constant_term = constant_term.map(polish_token_of_rust); + constant_term = [0].concat(constant_term); + + var index_terms = Array.from(linearization.index_terms).map(function (ptr) { + var wasmIndexTerm = wrap(ptr, WasmIndexTerm); + return index_term_of_rust(wasmIndexTerm, WasmPolishToken); + }); + index_terms = [0].concat(index_terms); + + linearization.free(); + return [0, constant_term, index_terms]; +} + +// Provides: None +var None = 0; + +// Provides: caml_is_none +// Requires: None +var caml_is_none = function (v) { + return v === None; +}; + +// Provides: caml_map_of_rust_vector +// Requires: js_class_vector_of_rust_vector +var caml_map_of_rust_vector = function (v, klass, converter_to_rust) { + var a = js_class_vector_of_rust_vector(v, klass); + var res = [0]; + for (var i = 0; i < a.length; ++i) { + res.push(converter_to_rust(a[i])); + } + return res; +}; // Provides: caml_opt_of_rust +// Requires: None var caml_opt_of_rust = function (value, value_of_rust) { if (value === undefined) { - return 0; + return None; } else { return [0, value_of_rust(value)]; } }; +// Provides: caml_bool_of_rust +var caml_bool_of_rust = function (bool) { + return bool; +}; + +// Provides: caml_lookup_patterns_of_rust +// Requires: plonk_wasm, caml_bool_of_rust +var caml_lookup_patterns_of_rust = function (wasm_lookup_patterns) { + return [ + 0, + caml_bool_of_rust(wasm_lookup_patterns.xor), + caml_bool_of_rust(wasm_lookup_patterns.lookup), + caml_bool_of_rust(wasm_lookup_patterns.range_check), + caml_bool_of_rust(wasm_lookup_patterns.foreign_field_mul), + ]; +}; + +// Provides: caml_lookup_features_of_rust +// Requires: plonk_wasm, caml_lookup_patterns_of_rust, caml_bool_of_rust +var caml_lookup_features_of_rust = function (wasm_lookup_features) { + var caml_lookup_patterns = caml_lookup_patterns_of_rust( + wasm_lookup_features.patterns + ); + var caml_joint_lookup_used = caml_bool_of_rust( + wasm_lookup_features.joint_lookup_used + ); + var caml_uses_runtime_tables = caml_bool_of_rust( + wasm_lookup_features.uses_runtime_tables + ); + + return [ + 0, + caml_lookup_patterns, + caml_joint_lookup_used, + caml_uses_runtime_tables, + ]; +}; + +// Provides: caml_lookup_info_of_rust +// Requires: plonk_wasm, caml_lookup_features_of_rust +var caml_lookup_info_of_rust = function (wasm_lookup_info) { + var caml_max_per_row = wasm_lookup_info.max_per_row; + var caml_max_joint_size = wasm_lookup_info.max_joint_size; + var caml_lookup_features = caml_lookup_features_of_rust( + wasm_lookup_info.features + ); + + return [0, caml_max_per_row, caml_max_joint_size, caml_lookup_features]; +}; + +// Provides: caml_lookup_selectors_of_rust +// Requires: plonk_wasm, caml_opt_of_rust +var caml_lookup_selectors_of_rust = function ( + wasm_lookup_selectors, + poly_comm_of_rust +) { + var xor = caml_opt_of_rust(wasm_lookup_selectors.xor, poly_comm_of_rust); + var lookup = caml_opt_of_rust( + wasm_lookup_selectors.lookup, + poly_comm_of_rust + ); + var range_check = caml_opt_of_rust( + wasm_lookup_selectors.range_check, + poly_comm_of_rust + ); + var ffmul = caml_opt_of_rust(wasm_lookup_selectors.ffmul, poly_comm_of_rust); + + return [0, xor, lookup, range_check, ffmul]; +}; + +// Provides: caml_lookup_verifier_index_of_rust +// Requires: plonk_wasm, caml_map_of_rust_vector, caml_bool_of_rust, caml_lookup_selectors_of_rust, caml_opt_of_rust, caml_lookup_info_of_rust +var caml_lookup_verifier_index_of_rust = function ( + wasm_lookup_index, + poly_comm_class, + poly_comm_of_rust +) { + var caml_joint_lookup_used = caml_bool_of_rust( + wasm_lookup_index.join_lookup_used + ); + + // lookup table + var caml_lookup_table = caml_map_of_rust_vector( + wasm_lookup_index.lookup_table, + poly_comm_class, + poly_comm_of_rust + ); + + var caml_lookup_selectors = caml_lookup_selectors_of_rust( + wasm_lookup_index.lookup_selectors, + poly_comm_of_rust + ); + + var caml_table_ids = caml_opt_of_rust( + wasm_lookup_index.table_ids, + poly_comm_of_rust + ); + + var caml_lookup_info = caml_lookup_info_of_rust( + wasm_lookup_index.lookup_info + ); + + var caml_runtime_tables_selector = caml_opt_of_rust( + wasm_lookup_index.runtime_tables_selector, + poly_comm_of_rust + ); + + return [ + 0, + caml_joint_lookup_used, + caml_lookup_table, + caml_lookup_selectors, + caml_table_ids, + caml_lookup_info, + caml_runtime_tables_selector, + ]; +}; + +// Provides: caml_plonk_verifier_index_of_rust +// Requires: linearization_of_rust, caml_plonk_domain_of_rust, caml_plonk_verification_evals_of_rust, caml_plonk_verification_shifts_of_rust, free_on_finalize, None, caml_opt_of_rust, caml_lookup_verifier_index_of_rust +var caml_plonk_verifier_index_of_rust = function (x, affine_class) { + var domain = caml_plonk_domain_of_rust(x.domain); + var max_poly_size = x.max_poly_size; + var public_ = x.public_; + var prev_challenges = x.prev_challenges; + var srs = free_on_finalize(x.srs); + var evals = caml_plonk_verification_evals_of_rust(x.evals, affine_class); + var shifts = caml_plonk_verification_shifts_of_rust(x.shifts); + // TODO: Handle linearization correctly! + // var linearization = linearization_of_rust(x.linearization, affine_class); + + var caml_lookup_index = caml_opt_of_rust( + x.lookup_index, + caml_lookup_verifier_index_of_rust + ); + x.free(); + return [ + 0, + domain, + max_poly_size, + public_, + prev_challenges, + srs, + evals, + shifts, + caml_lookup_index, + ]; +}; +// Provides: caml_plonk_verifier_index_to_rust +// Requires: caml_plonk_domain_to_rust, caml_plonk_verification_evals_to_rust, caml_plonk_verification_shifts_to_rust, free_finalization_registry, caml_plonk_lookup_verifier_index_to_rust, caml_opt_to_rust, caml_poly_comm_to_rust_poly_comm +var caml_plonk_verifier_index_to_rust = function ( + x, + klass, + domain_class, + verification_evals_class, + poly_comm_class, + mk_affine, + verification_shifts_class, + lookup_verifier_index_class, + lookup_selectors_class +) { + // Defining how to translate polynomial commitments from OCaml back to Rust + var poly_comm_to_rust = function (poly_comm) { + return caml_poly_comm_to_rust_poly_comm( + poly_comm, + poly_comm_class, + mk_affine + ); + }; + var domain = caml_plonk_domain_to_rust(x[1], domain_class); + var max_poly_size = x[2]; + var public_ = x[3]; + var prev_challenges = x[4]; + var srs = x[5]; + var evals = caml_plonk_verification_evals_to_rust( + x[6], + verification_evals_class, + poly_comm_to_rust + ); + var shifts = caml_plonk_verification_shifts_to_rust( + x[7], + verification_shifts_class + ); + + ////////////////////////////////////////////////////////////////////////////// + // The lookup_index_to_rust function is defined only in order to be able to // + // use the generic caml_opt_to_rust function. // + // // + // We could as well inline it but I preferred not having to think about // + // internal representation of values yet again. // + ////////////////////////////////////////////////////////////////////////////// + var lookup_index_to_rust = function (lidx) { + return caml_plonk_lookup_verifier_index_to_rust( + lidx, + lookup_verifier_index_class, + poly_comm_to_rust, + lookup_selectors_class, + mk_affine + ); + }; + + var wasm_lookup_index = caml_opt_to_rust(x[8], lookup_index_to_rust); + + return new klass( + domain, + max_poly_size, + public_, + prev_challenges, + srs, + evals, + shifts, + wasm_lookup_index + ); +}; + // Provides: caml_opt_to_rust +// Requires: caml_is_none, None var caml_opt_to_rust = function (caml_optional_value, to_rust) { // to_rust expects the parameters of the variant. A `Some vx` is represented // as [0, vx] - if (caml_optional_value === 0) { + if (caml_is_none(caml_optional_value)) { return undefined; } else { return to_rust(caml_optional_value[1]); } }; +// Provides: caml_lookup_selectors_to_rust +// Requires: plonk_wasm, caml_opt_to_rust +var caml_lookup_selectors_to_rust = function ( + wasm_lookup_selectors, + klass, + poly_comm_to_rust +) { + var xor = caml_opt_to_rust(wasm_lookup_selectors[1], poly_comm_to_rust); + var lookup = caml_opt_to_rust(wasm_lookup_selectors[2], poly_comm_to_rust); + var range_check = caml_opt_to_rust( + wasm_lookup_selectors[3], + poly_comm_to_rust + ); + var ffmul = caml_opt_to_rust(wasm_lookup_selectors[4], poly_comm_to_rust); + + return new klass(xor, lookup, range_check, ffmul); +}; + +// Provides: caml_lookup_table_to_rust +// Requires: plonk_wasm, caml_array_to_rust_vector, rust_affine_of_caml_affine +var caml_lookup_table_to_rust = function (wasm_lookup_table, mk_affine) { + return caml_array_to_rust_vector( + wasm_lookup_table, + rust_affine_of_caml_affine, + mk_affine + ); +}; + +// Provides: caml_lookup_patterns_to_rust +// Requires: plonk_wasm +var caml_lookup_patterns_to_rust = function (wasm_lookup_patterns, klass) { + var xor = wasm_lookup_patterns[1]; + var lookup = wasm_lookup_patterns[2]; + var range_check = wasm_lookup_patterns[3]; + var foreign_field_mul = wasm_lookup_patterns[4]; + + return new plonk_wasm.LookupPatterns( + xor, + lookup, + range_check, + foreign_field_mul + ); +}; + +// Provides: caml_lookup_features_to_rust +// Requires: plonk_wasm, caml_lookup_patterns_to_rust +var caml_lookup_features_to_rust = function (wasm_lookup_features) { + var patterns = caml_lookup_patterns_to_rust(wasm_lookup_features[1]); + var joint_lookup_used = wasm_lookup_features[2]; + var uses_runtime_tables = wasm_lookup_features[3]; + + return new plonk_wasm.LookupFeatures( + patterns, + joint_lookup_used, + uses_runtime_tables + ); +}; + +// Provides: caml_lookup_info_to_rust +// Requires: plonk_wasm, caml_lookup_features_to_rust +var caml_lookup_info_to_rust = function (wasm_lookup_info) { + var max_per_row = wasm_lookup_info[1]; + var max_poly_size = wasm_lookup_info[2]; + var features = caml_lookup_features_to_rust(wasm_lookup_info[3]); + + return new plonk_wasm.LookupInfo(max_per_row, max_poly_size, features); +}; + +// Provides: caml_plonk_lookup_verifier_index_to_rust +// Requires: plonk_wasm, caml_lookup_table_to_rust, caml_lookup_selectors_to_rust, caml_lookup_info_to_rust, caml_opt_to_rust +var caml_plonk_lookup_verifier_index_to_rust = function ( + caml_lookup_verifier_index, + klass, + poly_comm_to_rust, + lookup_selectors_class, + mk_affine +) { + // joint_lookup_used + var joint_lookup_used = caml_lookup_verifier_index[1]; + + // lookup_table + var lookup_table = caml_lookup_table_to_rust( + caml_lookup_verifier_index[2], + mk_affine + ); + + // lookup_selectors + var lookup_selectors = caml_lookup_selectors_to_rust( + caml_lookup_verifier_index[3], + lookup_selectors_class, + poly_comm_to_rust + ); + + // table_ids + var table_ids = caml_opt_to_rust( + caml_lookup_verifier_index[4], + poly_comm_to_rust + ); + + // lookup_info + var lookup_info = caml_lookup_info_to_rust(caml_lookup_verifier_index[5]); + + // runtime_tables_selector + var runtime_tables_selector = caml_opt_to_rust( + caml_lookup_verifier_index[6], + poly_comm_to_rust + ); + + return new klass( + joint_lookup_used, + lookup_table, + lookup_selectors, + table_ids, + lookup_info, + runtime_tables_selector + ); +}; + +// Provides: caml_pasta_fp_plonk_verifier_index_of_rust +// Requires: plonk_wasm, caml_plonk_verifier_index_of_rust +var caml_pasta_fp_plonk_verifier_index_of_rust = function (x) { + return caml_plonk_verifier_index_of_rust(x, plonk_wasm.WasmGVesta); +}; + +// Provides: caml_pasta_fp_plonk_verifier_index_to_rust +// Requires: plonk_wasm, caml_plonk_verifier_index_to_rust +var caml_pasta_fp_plonk_verifier_index_to_rust = function (x) { + return caml_plonk_verifier_index_to_rust( + x, + plonk_wasm.WasmFpPlonkVerifierIndex, + plonk_wasm.WasmFpDomain, + plonk_wasm.WasmFpPlonkVerificationEvals, + plonk_wasm.WasmFpPolyComm, + plonk_wasm.caml_vesta_affine_one, + plonk_wasm.WasmFpShifts, + plonk_wasm.WasmFpLookupVerifierIndex, + plonk_wasm.WasmFpLookupSelectors + ); +}; + // Provides: caml_pasta_fp_plonk_verifier_index_create -// Requires: plonk_wasm, tsRustConversion +// Requires: plonk_wasm, caml_pasta_fp_plonk_verifier_index_of_rust var caml_pasta_fp_plonk_verifier_index_create = function (x) { var vk = plonk_wasm.caml_pasta_fp_plonk_verifier_index_create(x); - return tsRustConversion.fp.verifierIndexFromRust(vk); + var vk_caml = caml_pasta_fp_plonk_verifier_index_of_rust(vk); + return vk_caml; }; // Provides: caml_pasta_fp_plonk_verifier_index_read -// Requires: plonk_wasm, caml_jsstring_of_string, tsRustConversion +// Requires: plonk_wasm, caml_jsstring_of_string, caml_pasta_fp_plonk_verifier_index_of_rust var caml_pasta_fp_plonk_verifier_index_read = function (offset, urs, path) { if (offset === 0) { offset = undefined; } else { offset = offset[1]; } - return tsRustConversion.fp.verifierIndexFromRust( + return caml_pasta_fp_plonk_verifier_index_of_rust( plonk_wasm.caml_pasta_fp_plonk_verifier_index_read( offset, urs, @@ -661,7 +2127,7 @@ var caml_pasta_fp_plonk_verifier_index_read = function (offset, urs, path) { }; // Provides: caml_pasta_fp_plonk_verifier_index_write -// Requires: plonk_wasm, caml_jsstring_of_string, tsRustConversion +// Requires: plonk_wasm, caml_jsstring_of_string, caml_pasta_fp_plonk_verifier_index_to_rust var caml_pasta_fp_plonk_verifier_index_write = function (append, t, path) { if (append === 0) { append = undefined; @@ -670,53 +2136,76 @@ var caml_pasta_fp_plonk_verifier_index_write = function (append, t, path) { } return plonk_wasm.caml_pasta_fp_plonk_verifier_index_write( append, - tsRustConversion.fp.verifierIndexToRust(t), + caml_pasta_fp_plonk_verifier_index_to_rust(t), caml_jsstring_of_string(path) ); }; // Provides: caml_pasta_fp_plonk_verifier_index_shifts -// Requires: plonk_wasm, tsRustConversion +// Requires: plonk_wasm, caml_plonk_verification_shifts_of_rust var caml_pasta_fp_plonk_verifier_index_shifts = function (log2_size) { - return tsRustConversion.fp.shiftsFromRust( + return caml_plonk_verification_shifts_of_rust( plonk_wasm.caml_pasta_fp_plonk_verifier_index_shifts(log2_size) ); }; // Provides: caml_pasta_fp_plonk_verifier_index_dummy -// Requires: plonk_wasm, tsRustConversion +// Requires: plonk_wasm, caml_pasta_fp_plonk_verifier_index_of_rust var caml_pasta_fp_plonk_verifier_index_dummy = function () { var res = plonk_wasm.caml_pasta_fp_plonk_verifier_index_dummy(); - return tsRustConversion.fp.verifierIndexFromRust(res); + return caml_pasta_fp_plonk_verifier_index_of_rust(res); + // return caml_pasta_fp_plonk_verifier_index_of_rust(plonk_wasm.caml_pasta_fp_plonk_verifier_index_dummy()); }; // Provides: caml_pasta_fp_plonk_verifier_index_deep_copy -// Requires: plonk_wasm, tsRustConversion +// Requires: plonk_wasm, caml_pasta_fp_plonk_verifier_index_of_rust, caml_pasta_fp_plonk_verifier_index_to_rust var caml_pasta_fp_plonk_verifier_index_deep_copy = function (x) { - return tsRustConversion.fp.verifierIndexFromRust( + return caml_pasta_fp_plonk_verifier_index_of_rust( plonk_wasm.caml_pasta_fp_plonk_verifier_index_deep_copy( - tsRustConversion.fp.verifierIndexToRust(x) + caml_pasta_fp_plonk_verifier_index_to_rust(x) ) ); }; +// Provides: caml_pasta_fq_plonk_verifier_index_of_rust +// Requires: plonk_wasm, caml_plonk_verifier_index_of_rust +var caml_pasta_fq_plonk_verifier_index_of_rust = function (x) { + return caml_plonk_verifier_index_of_rust(x, plonk_wasm.WasmGPallas); +}; + +// Provides: caml_pasta_fq_plonk_verifier_index_to_rust +// Requires: plonk_wasm, caml_plonk_verifier_index_to_rust +var caml_pasta_fq_plonk_verifier_index_to_rust = function (x) { + return caml_plonk_verifier_index_to_rust( + x, + plonk_wasm.WasmFqPlonkVerifierIndex, + plonk_wasm.WasmFqDomain, + plonk_wasm.WasmFqPlonkVerificationEvals, + plonk_wasm.WasmFqPolyComm, + plonk_wasm.caml_pallas_affine_one, + plonk_wasm.WasmFqShifts, + plonk_wasm.WasmFqLookupVerifierIndex, + plonk_wasm.WasmFqLookupSelectors + ); +}; + // Provides: caml_pasta_fq_plonk_verifier_index_create -// Requires: plonk_wasm, tsRustConversion +// Requires: plonk_wasm, caml_pasta_fq_plonk_verifier_index_of_rust var caml_pasta_fq_plonk_verifier_index_create = function (x) { - return tsRustConversion.fq.verifierIndexFromRust( + return caml_pasta_fq_plonk_verifier_index_of_rust( plonk_wasm.caml_pasta_fq_plonk_verifier_index_create(x) ); }; // Provides: caml_pasta_fq_plonk_verifier_index_read -// Requires: plonk_wasm, caml_jsstring_of_string, tsRustConversion +// Requires: plonk_wasm, caml_jsstring_of_string, caml_pasta_fq_plonk_verifier_index_of_rust var caml_pasta_fq_plonk_verifier_index_read = function (offset, urs, path) { if (offset === 0) { offset = undefined; } else { offset = offset[1]; } - return tsRustConversion.fq.verifierIndexFromRust( + return caml_pasta_fq_plonk_verifier_index_of_rust( plonk_wasm.caml_pasta_fq_plonk_verifier_index_read( offset, urs, @@ -726,7 +2215,7 @@ var caml_pasta_fq_plonk_verifier_index_read = function (offset, urs, path) { }; // Provides: caml_pasta_fq_plonk_verifier_index_write -// Requires: plonk_wasm, caml_jsstring_of_string, tsRustConversion +// Requires: plonk_wasm, caml_jsstring_of_string, caml_pasta_fq_plonk_verifier_index_to_rust var caml_pasta_fq_plonk_verifier_index_write = function (append, t, path) { if (append === 0) { append = undefined; @@ -735,238 +2224,771 @@ var caml_pasta_fq_plonk_verifier_index_write = function (append, t, path) { } return plonk_wasm.caml_pasta_fq_plonk_verifier_index_write( append, - tsRustConversion.fq.verifierIndexToRust(t), + caml_pasta_fq_plonk_verifier_index_to_rust(t), caml_jsstring_of_string(path) ); }; // Provides: caml_pasta_fq_plonk_verifier_index_shifts -// Requires: plonk_wasm, tsRustConversion +// Requires: plonk_wasm, caml_plonk_verification_shifts_of_rust var caml_pasta_fq_plonk_verifier_index_shifts = function (log2_size) { - return tsRustConversion.fq.shiftsFromRust( + return caml_plonk_verification_shifts_of_rust( plonk_wasm.caml_pasta_fq_plonk_verifier_index_shifts(log2_size) ); }; // Provides: caml_pasta_fq_plonk_verifier_index_dummy -// Requires: plonk_wasm, tsRustConversion +// Requires: plonk_wasm, caml_pasta_fq_plonk_verifier_index_of_rust var caml_pasta_fq_plonk_verifier_index_dummy = function () { - return tsRustConversion.fq.verifierIndexFromRust( + return caml_pasta_fq_plonk_verifier_index_of_rust( plonk_wasm.caml_pasta_fq_plonk_verifier_index_dummy() ); }; // Provides: caml_pasta_fq_plonk_verifier_index_deep_copy -// Requires: plonk_wasm, tsRustConversion, tsRustConversion +// Requires: plonk_wasm, caml_pasta_fq_plonk_verifier_index_of_rust, caml_pasta_fq_plonk_verifier_index_to_rust var caml_pasta_fq_plonk_verifier_index_deep_copy = function (x) { - return tsRustConversion.fq.verifierIndexFromRust( + return caml_pasta_fq_plonk_verifier_index_of_rust( plonk_wasm.caml_pasta_fq_plonk_verifier_index_deep_copy( - tsRustConversion.fq.verifierIndexToRust(x) + caml_pasta_fq_plonk_verifier_index_to_rust(x) ) ); }; -// proof +// Provides: COLUMNS +var COLUMNS = 15; +// Provides: PERMUTS_MINUS_1 +var PERMUTS_MINUS_1 = 6; + +// Provides: caml_pasta_fp_proof_evaluations_to_rust +// Requires: plonk_wasm, caml_fp_vector_to_rust, PERMUTS_MINUS_1, COLUMNS +var caml_pasta_fp_proof_evaluations_to_rust = function (x) { + return x; +}; + +// Provides: caml_pasta_fp_proof_evaluations_of_rust +// Requires: plonk_wasm, caml_fp_vector_of_rust, COLUMNS, PERMUTS_MINUS_1 +var caml_pasta_fp_proof_evaluations_of_rust = function (x) { + return x; +}; + +// Provides: caml_pasta_fp_opening_proof_to_rust +// Requires: plonk_wasm, caml_array_to_rust_vector, rust_affine_of_caml_affine +var caml_pasta_fp_opening_proof_to_rust = function (x) { + var convert_affines = function (affines) { + return caml_array_to_rust_vector( + affines, + rust_affine_of_caml_affine, + plonk_wasm.caml_vesta_affine_one + ); + }; + var lr = x[1]; + var delta = rust_affine_of_caml_affine( + x[2], + plonk_wasm.caml_vesta_affine_one + ); + var z1 = x[3]; + var z2 = x[4]; + var sg = rust_affine_of_caml_affine(x[5], plonk_wasm.caml_vesta_affine_one); + var len = lr.length; + // We pass l and r as separate vectors over the FFI + var l_ocaml = new Array(len); + var r_ocaml = new Array(len); + for (var i = 1; i < len; i++) { + l_ocaml[i] = lr[i][1]; + r_ocaml[i] = lr[i][2]; + } + var l = convert_affines(l_ocaml); + var r = convert_affines(r_ocaml); + return new plonk_wasm.WasmFpOpeningProof(l, r, delta, z1, z2, sg); +}; + +// Provides: caml_pasta_fp_opening_proof_of_rust +// Requires: plonk_wasm, caml_array_of_rust_vector, rust_affine_to_caml_affine +var caml_pasta_fp_opening_proof_of_rust = function (x) { + var convert_affines = function (affines) { + return caml_array_of_rust_vector( + affines, + plonk_wasm.WasmGVesta, + rust_affine_to_caml_affine, + false + ); + }; + var l = convert_affines(x.lr_0); + var r = convert_affines(x.lr_1); + var delta = rust_affine_to_caml_affine(x.delta); + var z1 = x.z1; + var z2 = x.z2; + var sg = rust_affine_to_caml_affine(x.sg); + x.free(); + var len = l.length; + if (len !== r.length) { + throw new Error("l and r lengths don't match"); + } + var lr = new Array(len); + lr[0] = 0; + for (var i = 1; i < len; i++) { + var tuple = new Array(3); + tuple[0] = 0; + tuple[1] = l[i]; + tuple[2] = r[i]; + lr[i] = tuple; + } + return [0, lr, delta, z1, z2, sg]; +}; + +// Provides: caml_fp_lookup_commitments_to_rust +// Requires: plonk_wasm, caml_vesta_poly_comm_to_rust, js_class_vector_to_rust_vector, caml_opt_to_rust +var caml_fp_lookup_commitments_to_rust = function (caml_lc) { + var convertArray = function (v) { + var n = v.length - 1; + var res = new Array(n); + for (var i = 0; i < n; ++i) { + res[i] = caml_vesta_poly_comm_to_rust(v[i + 1]); + } + return js_class_vector_to_rust_vector(res); + }; + + var wasm_sorted = convertArray(caml_lc[1]); + var wasm_aggreg = caml_vesta_poly_comm_to_rust(caml_lc[2]); + var wasm_runtime; + if (caml_lc[3] === 0) { + wasm_runtime = undefined; + } else { + wasm_runtime = caml_vesta_poly_comm_to_rust(caml_lc[3][1]); + } + return plonk_wasm.WasmFpLookupCommitments( + wasm_sorted, + wasm_aggreg, + wasm_runtime + ); +}; + +// Provides: caml_pasta_fp_commitments_to_rust +// Requires: plonk_wasm, caml_vesta_poly_comm_to_rust, js_class_vector_to_rust_vector, caml_fp_lookup_commitments_to_rust, caml_opt_to_rust +var caml_pasta_fp_commitments_to_rust = function (x) { + var convertArray = function (v) { + var n = v.length - 1; + var res = new Array(n); + for (var i = 0; i < n; ++i) { + res[i] = caml_vesta_poly_comm_to_rust(v[i + 1]); + } + // TODO need to do finalizer things? + return js_class_vector_to_rust_vector(res); + }; + + var w_comm = convertArray(x[1]); + var z_comm = caml_vesta_poly_comm_to_rust(x[2]); + var t_comm = caml_vesta_poly_comm_to_rust(x[3]); + var lookup = caml_opt_to_rust(x[4], caml_fp_lookup_commitments_to_rust); + return new plonk_wasm.WasmFpProverCommitments(w_comm, z_comm, t_comm, lookup); +}; + +// Provides: caml_fp_lookup_commitments_of_rust +// Requires: caml_vesta_poly_comm_of_rust, js_class_vector_of_rust_vector, plonk_wasm +var caml_fp_lookup_commitments_of_rust = function (wasm_lc) { + var convertArray = function (v) { + var a = js_class_vector_of_rust_vector(v, plonk_wasm.WasmFpPolyComm); + var res = [0]; + for (var i = 0; i < a.length; ++i) { + res.push(caml_vesta_poly_comm_of_rust(a[i])); + } + return res; + }; + + var sorted = convertArray(wasm_lc.sorted); + var aggreg = caml_vesta_poly_comm_of_rust(wasm_lc.aggreg); + var wasm_lc_runtime = wasm_lc.runtime; + var caml_runtime; + if (wasm_lc_runtime === undefined) { + caml_runtime = 0; + } else { + caml_runtime = [0, caml_vesta_poly_comm_of_rust(wasm_lc_runtime)]; + } + wasm_lc.free(); + return [0, sorted, aggreg, caml_runtime]; +}; + +// Provides: caml_pasta_fp_commitments_of_rust +// Requires: caml_vesta_poly_comm_of_rust, js_class_vector_of_rust_vector, plonk_wasm, caml_fp_lookup_commitments_of_rust, caml_opt_of_rust +var caml_pasta_fp_commitments_of_rust = function (x) { + var convertArray = function (v) { + var a = js_class_vector_of_rust_vector(v, plonk_wasm.WasmFpPolyComm); + var res = [0]; + for (var i = 0; i < a.length; ++i) { + // TODO Check this. Could be off by 1 + res.push(caml_vesta_poly_comm_of_rust(a[i])); + } + return res; + }; + + var w_comm = convertArray(x.w_comm); + var z_comm = caml_vesta_poly_comm_of_rust(x.z_comm); + var t_comm = caml_vesta_poly_comm_of_rust(x.t_comm); + var caml_lookup = caml_opt_of_rust( + x.lookup, + caml_fp_lookup_commitments_of_rust + ); + x.free(); + return [0, w_comm, z_comm, t_comm, caml_lookup]; +}; + +// Provides: caml_pasta_fp_proof_to_rust +// Requires: plonk_wasm, caml_pasta_fp_commitments_to_rust, caml_pasta_fp_opening_proof_to_rust, caml_pasta_fp_proof_evaluations_to_rust, caml_fp_vector_to_rust, caml_vesta_poly_comm_to_rust, js_class_vector_to_rust_vector +var caml_pasta_fp_proof_to_rust = function (x) { + var commitments = caml_pasta_fp_commitments_to_rust(x[1]); + var proof = caml_pasta_fp_opening_proof_to_rust(x[2]); + var evals = caml_pasta_fp_proof_evaluations_to_rust(x[3]); + var ft_eval1 = x[4]; + var public_ = caml_fp_vector_to_rust(x[5]); + var prev_challenges = x[6]; + var chals_len = prev_challenges.length; + var prev_challenges_scalars = new plonk_wasm.WasmVecVecFp(chals_len - 1); + var prev_challenges_comms = new Array(chals_len - 1); + for (var i = 1; i < chals_len; i++) { + prev_challenges_scalars.push(caml_fp_vector_to_rust(prev_challenges[i][1])); + prev_challenges_comms[i - 1] = caml_vesta_poly_comm_to_rust( + prev_challenges[i][2] + ); + } + prev_challenges_comms = js_class_vector_to_rust_vector(prev_challenges_comms); + return new plonk_wasm.WasmFpProverProof( + commitments, + proof, + evals, + ft_eval1, + public_, + prev_challenges_scalars, + prev_challenges_comms + ); +}; + +// Provides: caml_pasta_fp_proof_of_rust +// Requires: plonk_wasm, caml_pasta_fp_commitments_of_rust, caml_pasta_fp_opening_proof_of_rust, caml_pasta_fp_proof_evaluations_of_rust, caml_fp_vector_of_rust, js_class_vector_of_rust_vector, caml_vesta_poly_comm_of_rust +var caml_pasta_fp_proof_of_rust = function (x) { + var messages = caml_pasta_fp_commitments_of_rust(x.commitments); + var proof = caml_pasta_fp_opening_proof_of_rust(x.proof); + var evals = caml_pasta_fp_proof_evaluations_of_rust(x.evals); + var ft_eval1 = x.ft_eval1; + var public_ = caml_fp_vector_of_rust(x.public_); + var prev_challenges_scalars = x.prev_challenges_scalars; + var prev_challenges_comms = js_class_vector_of_rust_vector( + x.prev_challenges_comms, + plonk_wasm.WasmFpPolyComm + ); + var chals_len = prev_challenges_comms.length; + var prev_challenges = new Array(chals_len); + prev_challenges[0] = 0; + for (var i = 1; i < chals_len; i++) { + var res = new Array(3); + res[0] = 0; + res[1] = caml_fp_vector_of_rust(prev_challenges_scalars.get(i - 1)); + // TODO Check this. Could be off by 1 + res[2] = caml_vesta_poly_comm_of_rust(prev_challenges_comms[i]); + prev_challenges[i] = res; + } + return [0, messages, proof, evals, ft_eval1, public_, prev_challenges]; +}; // Provides: caml_pasta_fp_plonk_proof_create -// Requires: plonk_wasm, tsRustConversion +// Requires: plonk_wasm, caml_fp_vector_to_rust, caml_array_to_rust_vector, rust_affine_of_caml_affine, caml_pasta_fp_proof_of_rust var caml_pasta_fp_plonk_proof_create = function ( index, witness_cols, - caml_runtime_tables, prev_challenges, prev_sgs ) { var w = new plonk_wasm.WasmVecVecFp(witness_cols.length - 1); for (var i = 1; i < witness_cols.length; i++) { - w.push(tsRustConversion.fp.vectorToRust(witness_cols[i])); + w.push(caml_fp_vector_to_rust(witness_cols[i])); } witness_cols = w; - prev_challenges = tsRustConversion.fp.vectorToRust(prev_challenges); - var wasm_runtime_tables = - tsRustConversion.fp.runtimeTablesToRust(caml_runtime_tables); - prev_sgs = tsRustConversion.fp.pointsToRust(prev_sgs); - var proof = plonk_wasm.caml_pasta_fp_plonk_proof_create( + prev_challenges = caml_fp_vector_to_rust(prev_challenges); + prev_sgs = caml_array_to_rust_vector( + prev_sgs, + rust_affine_of_caml_affine, + plonk_wasm.caml_vesta_affine_one + ); + var res = plonk_wasm.caml_pasta_fp_plonk_proof_create( index, witness_cols, - wasm_runtime_tables, prev_challenges, prev_sgs ); - return tsRustConversion.fp.proofFromRust(proof); + var proof = caml_pasta_fp_proof_of_rust(res); + return proof; }; // Provides: caml_pasta_fp_plonk_proof_verify -// Requires: plonk_wasm, tsRustConversion +// Requires: plonk_wasm, caml_array_to_rust_vector, caml_vesta_poly_comm_to_rust, caml_pasta_fp_plonk_verifier_index_to_rust, caml_pasta_fp_proof_to_rust var caml_pasta_fp_plonk_proof_verify = function (index, proof) { - index = tsRustConversion.fp.verifierIndexToRust(index); - proof = tsRustConversion.fp.proofToRust(proof); + index = caml_pasta_fp_plonk_verifier_index_to_rust(index); + proof = caml_pasta_fp_proof_to_rust(proof); return plonk_wasm.caml_pasta_fp_plonk_proof_verify(index, proof); }; // Provides: caml_pasta_fp_plonk_proof_batch_verify -// Requires: plonk_wasm, tsRustConversion +// Requires: plonk_wasm, caml_array_to_rust_vector, caml_vesta_poly_comm_to_rust, caml_pasta_fp_plonk_verifier_index_to_rust, caml_pasta_fp_proof_to_rust var caml_pasta_fp_plonk_proof_batch_verify = function (indexes, proofs) { - indexes = tsRustConversion.mapMlArrayToRustVector( + indexes = caml_array_to_rust_vector( indexes, - tsRustConversion.fp.verifierIndexToRust - ); - proofs = tsRustConversion.mapMlArrayToRustVector( - proofs, - tsRustConversion.fp.proofToRust + caml_pasta_fp_plonk_verifier_index_to_rust ); + proofs = caml_array_to_rust_vector(proofs, caml_pasta_fp_proof_to_rust); return plonk_wasm.caml_pasta_fp_plonk_proof_batch_verify(indexes, proofs); }; // Provides: caml_pasta_fp_plonk_proof_dummy -// Requires: plonk_wasm, tsRustConversion +// Requires: plonk_wasm, caml_pasta_fp_proof_of_rust var caml_pasta_fp_plonk_proof_dummy = function () { - return tsRustConversion.fp.proofFromRust( + return caml_pasta_fp_proof_of_rust( plonk_wasm.caml_pasta_fp_plonk_proof_dummy() ); }; // Provides: caml_pasta_fp_plonk_proof_deep_copy -// Requires: plonk_wasm, tsRustConversion +// Requires: plonk_wasm, caml_pasta_fp_proof_to_rust, caml_pasta_fp_proof_of_rust var caml_pasta_fp_plonk_proof_deep_copy = function (proof) { - return tsRustConversion.fp.proofFromRust( + return caml_pasta_fp_proof_of_rust( plonk_wasm.caml_pasta_fp_plonk_proof_deep_copy( - tsRustConversion.fp.proofToRust(proof) + caml_pasta_fp_proof_to_rust(proof) ) ); }; +// Provides: caml_pasta_fq_proof_evaluations_to_rust +// Requires: plonk_wasm, caml_fq_vector_to_rust, PERMUTS_MINUS_1, COLUMNS +var caml_pasta_fq_proof_evaluations_to_rust = function (x) { + return x; +}; + +// Provides: caml_pasta_fq_proof_evaluations_of_rust +// Requires: plonk_wasm, caml_fq_vector_of_rust, COLUMNS, PERMUTS_MINUS_1 +var caml_pasta_fq_proof_evaluations_of_rust = function (x) { + return x; +}; + +// Provides: caml_pasta_fq_opening_proof_to_rust +// Requires: plonk_wasm, caml_array_to_rust_vector, rust_affine_of_caml_affine +var caml_pasta_fq_opening_proof_to_rust = function (x) { + var convert_affines = function (affines) { + return caml_array_to_rust_vector( + affines, + rust_affine_of_caml_affine, + plonk_wasm.caml_pallas_affine_one + ); + }; + var lr = x[1]; + var delta = rust_affine_of_caml_affine( + x[2], + plonk_wasm.caml_pallas_affine_one + ); + var z1 = x[3]; + var z2 = x[4]; + var sg = rust_affine_of_caml_affine(x[5], plonk_wasm.caml_pallas_affine_one); + var len = lr.length; + // We pass l and r as separate vectors over the FFI + var l_ocaml = new Array(len); + var r_ocaml = new Array(len); + for (var i = 1; i < len; i++) { + l_ocaml[i] = lr[i][1]; + r_ocaml[i] = lr[i][2]; + } + var l = convert_affines(l_ocaml); + var r = convert_affines(r_ocaml); + return new plonk_wasm.WasmFqOpeningProof(l, r, delta, z1, z2, sg); +}; + +// Provides: caml_pasta_fq_opening_proof_of_rust +// Requires: plonk_wasm, caml_array_of_rust_vector, rust_affine_to_caml_affine +var caml_pasta_fq_opening_proof_of_rust = function (x) { + var convert_affines = function (affines) { + return caml_array_of_rust_vector( + affines, + plonk_wasm.WasmGPallas, + rust_affine_to_caml_affine, + false + ); + }; + var l = convert_affines(x.lr_0); + var r = convert_affines(x.lr_1); + var delta = rust_affine_to_caml_affine(x.delta); + var z1 = x.z1; + var z2 = x.z2; + var sg = rust_affine_to_caml_affine(x.sg); + x.free(); + var len = l.length; + if (len !== r.length) { + throw new Error("l and r lengths don't match"); + } + var lr = new Array(len); + lr[0] = 0; + for (var i = 1; i < len; i++) { + var tuple = new Array(3); + tuple[0] = 0; + tuple[1] = l[i]; + tuple[2] = r[i]; + lr[i] = tuple; + } + return [0, lr, delta, z1, z2, sg]; +}; + +// Provides: caml_fq_lookup_commitments_to_rust +// Requires: plonk_wasm, caml_pallas_poly_comm_to_rust, js_class_vector_to_rust_vector, caml_opt_to_rust +var caml_fq_lookup_commitments_to_rust = function (caml_lc) { + var convertArray = function (v) { + var n = v.length - 1; + var res = new Array(n); + for (var i = 0; i < n; ++i) { + res[i] = caml_pallas_poly_comm_to_rust(v[i + 1]); + } + return js_class_vector_to_rust_vector(res); + }; + + var wasm_sorted = convertArray(caml_lc[1]); + var wasm_aggreg = caml_pallas_poly_comm_to_rust(caml_lc[2]); + var wasm_runtime = caml_opt_to_rust( + caml_lc[3], + caml_pallas_poly_comm_to_rust + ); + return plonk_wasm.WasmFqLookupCommitments( + wasm_sorted, + wasm_aggreg, + wasm_runtime + ); +}; + +// Provides: caml_pasta_fq_commitments_to_rust +// Requires: plonk_wasm, caml_pallas_poly_comm_to_rust, js_class_vector_to_rust_vector, caml_fq_lookup_commitments_to_rust, caml_opt_to_rust +var caml_pasta_fq_commitments_to_rust = function (x) { + var convertArray = function (v) { + var n = v.length - 1; + var res = new Array(n); + for (var i = 0; i < n; ++i) { + res[i] = caml_pallas_poly_comm_to_rust(v[i + 1]); + } + return js_class_vector_to_rust_vector(res); + }; + + var w_comm = convertArray(x[1]); + var z_comm = caml_pallas_poly_comm_to_rust(x[2]); + var t_comm = caml_pallas_poly_comm_to_rust(x[3]); + var lookup = caml_opt_to_rust(x[4], caml_fq_lookup_commitments_to_rust); + return new plonk_wasm.WasmFqProverCommitments(w_comm, z_comm, t_comm, lookup); +}; + +// Provides: caml_fq_lookup_commitments_of_rust +// Requires: caml_pallas_poly_comm_of_rust, js_class_vector_of_rust_vector, plonk_wasm +var caml_fq_lookup_commitments_of_rust = function (wasm_lc) { + var convertArray = function (v) { + var a = js_class_vector_of_rust_vector(v, plonk_wasm.WasmFqPolyComm); + var res = [0]; + for (var i = 0; i < a.length; ++i) { + res.push(caml_pallas_poly_comm_of_rust(a[i])); + } + return res; + }; + + var sorted = convertArray(wasm_lc.sorted); + var aggreg = caml_pallas_poly_comm_of_rust(wasm_lc.aggreg); + var wasm_lc_runtime = wasm_lc.runtime; + var caml_runtime; + if (wasm_lc_runtime === undefined) { + caml_runtime = 0; + } else { + caml_runtime = [0, caml_pallas_poly_comm_of_rust(wasm_lc_runtime)]; + } + wasm_lc.free(); + return [0, sorted, aggreg, caml_runtime]; +}; + +// Provides: caml_pasta_fq_commitments_of_rust +// Requires: caml_pallas_poly_comm_of_rust, js_class_vector_of_rust_vector, plonk_wasm, caml_fq_lookup_commitments_of_rust, caml_opt_of_rust +var caml_pasta_fq_commitments_of_rust = function (x) { + var convertArray = function (v) { + var a = js_class_vector_of_rust_vector(v, plonk_wasm.WasmFqPolyComm); + var res = [0]; + for (var i = 0; i < a.length; ++i) { + // TODO Check this. Could be off by 1 + res.push(caml_pallas_poly_comm_of_rust(a[i])); + } + return res; + }; + + var w_comm = convertArray(x.w_comm); + var z_comm = caml_pallas_poly_comm_of_rust(x.z_comm); + var t_comm = caml_pallas_poly_comm_of_rust(x.t_comm); + var caml_lookup = caml_opt_of_rust( + x.lookup, + caml_fq_lookup_commitments_of_rust + ); + x.free(); + return [0, w_comm, z_comm, t_comm, caml_lookup]; +}; + +// Provides: caml_pasta_fq_proof_to_rust +// Requires: plonk_wasm, caml_pasta_fq_commitments_to_rust, caml_pasta_fq_opening_proof_to_rust, caml_pasta_fq_proof_evaluations_to_rust, caml_fq_vector_to_rust, caml_pallas_poly_comm_to_rust, js_class_vector_to_rust_vector +var caml_pasta_fq_proof_to_rust = function (x) { + var messages = caml_pasta_fq_commitments_to_rust(x[1]); + var proof = caml_pasta_fq_opening_proof_to_rust(x[2]); + var evals = caml_pasta_fq_proof_evaluations_to_rust(x[3]); + var ft_eval1 = x[4]; + var public_ = caml_fq_vector_to_rust(x[5]); + var prev_challenges = x[6]; + var chals_len = prev_challenges.length; + var prev_challenges_scalars = new plonk_wasm.WasmVecVecFq(chals_len - 1); + var prev_challenges_comms = new Array(chals_len - 1); + for (var i = 1; i < chals_len; i++) { + prev_challenges_scalars.push(caml_fq_vector_to_rust(prev_challenges[i][1])); + prev_challenges_comms[i - 1] = caml_pallas_poly_comm_to_rust( + prev_challenges[i][2] + ); + } + prev_challenges_comms = js_class_vector_to_rust_vector(prev_challenges_comms); + return new plonk_wasm.WasmFqProverProof( + messages, + proof, + evals, + ft_eval1, + public_, + prev_challenges_scalars, + prev_challenges_comms + ); +}; + +// Provides: caml_pasta_fq_proof_of_rust +// Requires: plonk_wasm, caml_pasta_fq_commitments_of_rust, caml_pasta_fq_opening_proof_of_rust, caml_pasta_fq_proof_evaluations_of_rust, caml_fq_vector_of_rust, js_class_vector_of_rust_vector, caml_pallas_poly_comm_of_rust +var caml_pasta_fq_proof_of_rust = function (x) { + var messages = caml_pasta_fq_commitments_of_rust(x.commitments); + var proof = caml_pasta_fq_opening_proof_of_rust(x.proof); + var evals = caml_pasta_fq_proof_evaluations_of_rust(x.evals); + var evals1 = caml_pasta_fq_proof_evaluations_of_rust(x.evals1); + var ft_eval1 = x.ft_eval1; + var public_ = caml_fq_vector_of_rust(x.public_); + var prev_challenges_scalars = x.prev_challenges_scalars; + var prev_challenges_comms = js_class_vector_of_rust_vector( + x.prev_challenges_comms, + plonk_wasm.WasmFqPolyComm + ); + var chals_len = prev_challenges_comms.length; + var prev_challenges = new Array(chals_len); + prev_challenges[0] = 0; + for (var i = 1; i < chals_len; i++) { + var res = new Array(3); + res[0] = 0; + res[1] = caml_fq_vector_of_rust(prev_challenges_scalars.get(i - 1)); + res[2] = caml_pallas_poly_comm_of_rust(prev_challenges_comms[i]); + prev_challenges[i] = res; + } + return [0, messages, proof, evals, ft_eval1, public_, prev_challenges]; +}; + // Provides: caml_pasta_fq_plonk_proof_create -// Requires: plonk_wasm, tsRustConversion +// Requires: plonk_wasm, caml_fq_vector_to_rust, caml_array_to_rust_vector, rust_affine_of_caml_affine, caml_pasta_fq_proof_of_rust var caml_pasta_fq_plonk_proof_create = function ( index, witness_cols, - caml_runtime_tables, prev_challenges, prev_sgs ) { var w = new plonk_wasm.WasmVecVecFq(witness_cols.length - 1); for (var i = 1; i < witness_cols.length; i++) { - w.push(tsRustConversion.fq.vectorToRust(witness_cols[i])); + w.push(caml_fq_vector_to_rust(witness_cols[i])); } witness_cols = w; - prev_challenges = tsRustConversion.fq.vectorToRust(prev_challenges); - var wasm_runtime_tables = - tsRustConversion.fq.runtimeTablesToRust(caml_runtime_tables); - prev_sgs = tsRustConversion.fq.pointsToRust(prev_sgs); - var proof = plonk_wasm.caml_pasta_fq_plonk_proof_create( + prev_challenges = caml_fq_vector_to_rust(prev_challenges); + prev_sgs = caml_array_to_rust_vector( + prev_sgs, + rust_affine_of_caml_affine, + plonk_wasm.caml_pallas_affine_one + ); + var res = plonk_wasm.caml_pasta_fq_plonk_proof_create( index, witness_cols, - wasm_runtime_tables, prev_challenges, prev_sgs ); - return tsRustConversion.fq.proofFromRust(proof); + var proof = caml_pasta_fq_proof_of_rust(res); + return proof; }; // Provides: caml_pasta_fq_plonk_proof_verify -// Requires: plonk_wasm, tsRustConversion +// Requires: plonk_wasm, caml_array_to_rust_vector, caml_pallas_poly_comm_to_rust, caml_pasta_fq_plonk_verifier_index_to_rust, caml_pasta_fq_proof_to_rust var caml_pasta_fq_plonk_proof_verify = function (index, proof) { - index = tsRustConversion.fq.verifierIndexToRust(index); - proof = tsRustConversion.fq.proofToRust(proof); + index = caml_pasta_fq_plonk_verifier_index_to_rust(index); + proof = caml_pasta_fq_proof_to_rust(proof); return plonk_wasm.caml_pasta_fq_plonk_proof_verify(index, proof); }; // Provides: caml_pasta_fq_plonk_proof_batch_verify -// Requires: plonk_wasm, tsRustConversion +// Requires: plonk_wasm, caml_array_to_rust_vector, caml_pallas_poly_comm_to_rust, caml_pasta_fq_plonk_verifier_index_to_rust, caml_pasta_fq_proof_to_rust var caml_pasta_fq_plonk_proof_batch_verify = function (indexes, proofs) { - indexes = tsRustConversion.mapMlArrayToRustVector( + indexes = caml_array_to_rust_vector( indexes, - tsRustConversion.fq.verifierIndexToRust - ); - proofs = tsRustConversion.mapMlArrayToRustVector( - proofs, - tsRustConversion.fq.proofToRust + caml_pasta_fq_plonk_verifier_index_to_rust ); + proofs = caml_array_to_rust_vector(proofs, caml_pasta_fq_proof_to_rust); return plonk_wasm.caml_pasta_fq_plonk_proof_batch_verify(indexes, proofs); }; // Provides: caml_pasta_fq_plonk_proof_dummy -// Requires: plonk_wasm, tsRustConversion +// Requires: plonk_wasm, caml_pasta_fq_proof_of_rust var caml_pasta_fq_plonk_proof_dummy = function () { - return tsRustConversion.fq.proofFromRust( + return caml_pasta_fq_proof_of_rust( plonk_wasm.caml_pasta_fq_plonk_proof_dummy() ); }; // Provides: caml_pasta_fq_plonk_proof_deep_copy -// Requires: plonk_wasm, tsRustConversion +// Requires: plonk_wasm, caml_pasta_fq_proof_to_rust, caml_pasta_fq_proof_of_rust var caml_pasta_fq_plonk_proof_deep_copy = function (proof) { - return tsRustConversion.fq.proofFromRust( + return caml_pasta_fq_proof_of_rust( plonk_wasm.caml_pasta_fq_plonk_proof_deep_copy( - tsRustConversion.fq.proofToRust(proof) + caml_pasta_fq_proof_to_rust(proof) ) ); }; -// oracles +// Provides: caml_random_oracles_of_rust +// Requires: caml_u8array_vector_of_rust_flat_vector, caml_option_of_maybe_undefined +var caml_random_oracles_of_rust = function (x) { + var joint_combiner_chal = x.joint_combiner_chal; + var joint_combiner = x.joint_combiner; + var joint_combiner_ocaml = undefined; + if (joint_combiner_chal !== undefined && joint_combiner !== undefined) { + joint_combiner_ocaml = [0, [0, joint_combiner_chal], joint_combiner]; + } + return [ + 0, + caml_option_of_maybe_undefined(joint_combiner_ocaml), + x.beta, + x.gamma, + [0, x.alpha_chal], + x.alpha, + x.zeta, + x.v, + x.u, + [0, x.zeta_chal], + [0, x.v_chal], + [0, x.u_chal], + ]; +}; + +// Provides: caml_random_oracles_to_rust +// Requires: caml_u8array_vector_to_rust_flat_vector, caml_option_to_maybe_undefined +var caml_random_oracles_to_rust = function (x, roKlass) { + // var caml_vector = [0, x[1], x[2], x[3][1], x[4], x[5], x[6], x[7], x[8][1], x[9][1], x[10][1]]; + var joint_combiner_ocaml = caml_option_to_maybe_undefined(x[1]); + var joint_combiner_chal = undefined; + var joint_combiner = undefined; + if (joint_combiner_ocaml !== undefined) { + joint_combiner_chal = joint_combiner_ocaml[1][1]; + joint_combiner = joint_combiner_ocaml[2]; + } + return new roKlass( + joint_combiner_chal, + joint_combiner, + x[2], + x[3], + x[4][1], + x[5], + x[6], + x[7], + x[8], + x[9][1], + x[10][1], + x[11][1] + ); +}; + +// Provides: caml_oracles_of_rust +// Requires: caml_u8array_vector_of_rust_flat_vector, caml_random_oracles_of_rust +var caml_oracles_of_rust = function (x) { + return [ + 0, + caml_random_oracles_of_rust(x.o), + [0, x.p_eval0, x.p_eval1], + caml_u8array_vector_of_rust_flat_vector( + x.opening_prechallenges, + 32 /* TODO: Don't hardcode */ + ), + x.digest_before_evaluations, + ]; +}; + +// Provides: caml_oracles_to_rust +// Requires: caml_u8array_vector_to_rust_flat_vector, caml_random_oracles_to_rust +var caml_oracles_to_rust = function (x, klass, roKlass) { + return new klass( + caml_random_oracles_to_rust(x[1], roKlass), + x[2][1], + x[2][2], + caml_u8array_vector_to_rust_flat_vector(x[3]), + x[4] + ); +}; // Provides: fp_oracles_create -// Requires: plonk_wasm, tsRustConversion +// Requires: plonk_wasm, caml_oracles_of_rust, caml_array_to_rust_vector, caml_vesta_poly_comm_to_rust, caml_pasta_fp_plonk_verifier_index_to_rust, caml_pasta_fp_proof_to_rust var fp_oracles_create = function (lgr_comm, verifier_index, proof) { - return tsRustConversion.fp.oraclesFromRust( + return caml_oracles_of_rust( plonk_wasm.fp_oracles_create( - tsRustConversion.fp.polyCommsToRust(lgr_comm), - tsRustConversion.fp.verifierIndexToRust(verifier_index), - tsRustConversion.fp.proofToRust(proof) + caml_array_to_rust_vector(lgr_comm, caml_vesta_poly_comm_to_rust), + caml_pasta_fp_plonk_verifier_index_to_rust(verifier_index), + caml_pasta_fp_proof_to_rust(proof) ) ); }; -// Provides: fp_oracles_create_no_public -// Requires: fp_oracles_create -var fp_oracles_create_no_public = function (lgr_comm, verifier_index, proof) { - return fp_oracles_create(lgr_comm, verifier_index, [0, 0, proof]); -}; - // Provides: fp_oracles_dummy -// Requires: plonk_wasm, tsRustConversion +// Requires: plonk_wasm, caml_oracles_of_rust var fp_oracles_dummy = function () { - return tsRustConversion.fp.oraclesFromRust(plonk_wasm.fp_oracles_dummy()); + return caml_oracles_of_rust(plonk_wasm.fp_oracles_dummy()); }; // Provides: fp_oracles_deep_copy -// Requires: plonk_wasm, tsRustConversion +// Requires: plonk_wasm, caml_oracles_of_rust, caml_oracles_to_rust var fp_oracles_deep_copy = function (x) { - return tsRustConversion.fp.oraclesFromRust( - plonk_wasm.fp_oracles_deep_copy(tsRustConversion.fp.oraclesToRust(x)) + return caml_oracles_of_rust( + plonk_wasm.fp_oracles_deep_copy( + caml_oracles_to_rust( + x, + plonk_wasm.WasmFpOracles, + plonk_wasm.WasmFpRandomOracles + ) + ) ); }; // Provides: fq_oracles_create -// Requires: plonk_wasm, tsRustConversion +// Requires: plonk_wasm, caml_oracles_of_rust, caml_array_to_rust_vector, caml_pallas_poly_comm_to_rust, caml_pasta_fq_plonk_verifier_index_to_rust, caml_pasta_fq_proof_to_rust var fq_oracles_create = function (lgr_comm, verifier_index, proof) { - return tsRustConversion.fq.oraclesFromRust( + return caml_oracles_of_rust( plonk_wasm.fq_oracles_create( - tsRustConversion.fq.polyCommsToRust(lgr_comm), - tsRustConversion.fq.verifierIndexToRust(verifier_index), - tsRustConversion.fq.proofToRust(proof) + caml_array_to_rust_vector(lgr_comm, caml_pallas_poly_comm_to_rust), + caml_pasta_fq_plonk_verifier_index_to_rust(verifier_index), + caml_pasta_fq_proof_to_rust(proof) ) ); }; -// Provides: fq_oracles_create_no_public -// Requires: fq_oracles_create -var fq_oracles_create_no_public = function (lgr_comm, verifier_index, proof) { - return fq_oracles_create(lgr_comm, verifier_index, [0, 0, proof]); -}; - // Provides: fq_oracles_dummy -// Requires: plonk_wasm, tsRustConversion +// Requires: plonk_wasm, caml_oracles_of_rust var fq_oracles_dummy = function () { - return tsRustConversion.fq.oraclesFromRust(plonk_wasm.fq_oracles_dummy()); + return caml_oracles_of_rust(plonk_wasm.fq_oracles_dummy()); }; // Provides: fq_oracles_deep_copy -// Requires: plonk_wasm, tsRustConversion +// Requires: plonk_wasm, caml_oracles_of_rust, caml_oracles_to_rust var fq_oracles_deep_copy = function (x) { - return tsRustConversion.fq.oraclesFromRust( - plonk_wasm.fq_oracles_deep_copy(tsRustConversion.fq.oraclesToRust(x)) + return caml_oracles_of_rust( + plonk_wasm.fq_oracles_deep_copy( + caml_oracles_to_rust( + x, + plonk_wasm.WasmFqOracles, + plonk_wasm.WasmFqRandomOracles + ) + ) ); }; @@ -981,41 +3003,32 @@ function caml_pasta_fq_poseidon_params_create() { } // Provides: caml_pasta_fp_poseidon_block_cipher -// Requires: plonk_wasm, tsRustConversion, tsRustConversion +// Requires: plonk_wasm, caml_fp_vector_to_rust, caml_fp_vector_of_rust function caml_pasta_fp_poseidon_block_cipher(_fake_params, fp_vector) { // 1. get permuted field vector from rust var wasm_flat_vector = plonk_wasm.caml_pasta_fp_poseidon_block_cipher( - tsRustConversion.fp.vectorToRust(fp_vector) + caml_fp_vector_to_rust(fp_vector) ); - var new_fp_vector = tsRustConversion.fp.vectorFromRust(wasm_flat_vector); + var new_fp_vector = caml_fp_vector_of_rust(wasm_flat_vector); // 2. write back modified field vector to original one new_fp_vector.forEach(function (a, i) { fp_vector[i] = a; }); } - // Provides: caml_pasta_fq_poseidon_block_cipher -// Requires: plonk_wasm, tsRustConversion, tsRustConversion +// Requires: plonk_wasm, caml_fq_vector_to_rust, caml_fq_vector_of_rust function caml_pasta_fq_poseidon_block_cipher(_fake_params, fq_vector) { // 1. get permuted field vector from rust var wasm_flat_vector = plonk_wasm.caml_pasta_fq_poseidon_block_cipher( - tsRustConversion.fq.vectorToRust(fq_vector) + caml_fq_vector_to_rust(fq_vector) ); - var new_fq_vector = tsRustConversion.fq.vectorFromRust(wasm_flat_vector); + var new_fq_vector = caml_fq_vector_of_rust(wasm_flat_vector); // 2. write back modified field vector to original one new_fq_vector.forEach(function (a, i) { fq_vector[i] = a; }); } -// Provides: caml_pasta_fp_plonk_proof_example_with_lookup -function caml_pasta_fp_plonk_proof_example_with_lookup() { - // This is only used in the pickles unit tests - throw new Error( - 'Unimplemented caml_pasta_fp_plonk_proof_example_with_lookup' - ); -} - // Provides: prover_to_json // Requires: plonk_wasm var prover_to_json = plonk_wasm.prover_to_json; @@ -1066,3 +3079,10 @@ function caml_pasta_fp_plonk_proof_example_with_rot() { function caml_pasta_fp_plonk_proof_example_with_xor() { throw new Error('Unimplemented caml_pasta_fp_plonk_proof_example_with_xor'); } + +// Provides: caml_pasta_fp_plonk_proof_example_with_lookup +function caml_pasta_fp_plonk_proof_example_with_lookup() { + throw new Error( + 'Unimplemented caml_pasta_fp_plonk_proof_example_with_lookup' + ); +} diff --git a/src/lib/crypto/kimchi_bindings/js/dune b/src/lib/crypto/kimchi_bindings/js/dune index f8746ce705dd..68b86f3fa2f6 100644 --- a/src/lib/crypto/kimchi_bindings/js/dune +++ b/src/lib/crypto/kimchi_bindings/js/dune @@ -1,14 +1,6 @@ (library (name bindings_js) (public_name bindings_js) - (js_of_ocaml - (javascript_files - bindings.js - bindings-bigint256.js - bindings-field.js - bindings-curve.js - bindings-vector.js)) - (instrumentation - (backend bisect_ppx)) - (preprocess - (pps ppx_version))) + (js_of_ocaml (javascript_files bindings.js)) + (instrumentation (backend bisect_ppx)) + (preprocess (pps ppx_version))) diff --git a/src/lib/crypto/kimchi_bindings/js/node_js/build.sh b/src/lib/crypto/kimchi_bindings/js/node_js/build.sh index 41a7c57bc5cf..5e230e410208 100755 --- a/src/lib/crypto/kimchi_bindings/js/node_js/build.sh +++ b/src/lib/crypto/kimchi_bindings/js/node_js/build.sh @@ -2,9 +2,9 @@ set -euo pipefail if [[ -z "${PLONK_WASM_NODEJS-}" ]]; then - export RUSTFLAGS="-C target-feature=+atomics,+bulk-memory,+mutable-globals -C link-arg=--no-check-features -C link-arg=--max-memory=4294967296" # The version should stay in line with the one in kimchi_bindings/wasm/rust-toolchain.toml - rustup run nightly-2023-09-01 wasm-pack build --target nodejs --out-dir ../js/node_js ../../wasm -- -Z build-std=panic_abort,std --features nodejs + export RUSTFLAGS="-C target-feature=+atomics,+bulk-memory,+mutable-globals -C link-arg=--no-check-features -C link-arg=--max-memory=4294967296" + rustup run nightly-2022-09-12 wasm-pack build --target nodejs --out-dir ../js/node_js ../../wasm -- -Z build-std=panic_abort,std --features nodejs else cp "$PLONK_WASM_NODEJS"/* -R . fi diff --git a/src/lib/crypto/kimchi_bindings/js/test/bindings_js_test.ml b/src/lib/crypto/kimchi_bindings/js/test/bindings_js_test.ml index f7d9cc49dfd0..2296d95f0fd9 100644 --- a/src/lib/crypto/kimchi_bindings/js/test/bindings_js_test.ml +++ b/src/lib/crypto/kimchi_bindings/js/test/bindings_js_test.ml @@ -643,7 +643,7 @@ let _ = |> Backend.Keypair.create ~prev_challenges:0 ) in let x = Backend.Field.of_int 2 in - let (pi : Backend.Proof.with_public_evals) = + let (pi : Backend.Proof.t) = time "generate witness conv" (fun () -> Impl.generate_witness_conv ~input_typ:Typ.field ~return_typ:Typ.unit main @@ -920,16 +920,8 @@ let _ = vec in let urs = Pasta_fp_urs.create 16 in - (* TODO(dw) write tests with lookup tables *) - let lookup_tables = [||] in - (* TODO(dw) write tests with runtime tables *) - let runtime_table_cfg = [||] in - let index0 = - create gate_vector 0 lookup_tables runtime_table_cfg 0 urs - in - let index2 = - create gate_vector 2 lookup_tables runtime_table_cfg 0 urs - in + let index0 = create gate_vector 0 0 urs in + let index2 = create gate_vector 2 0 urs in assert (max_degree index0 = 16) ; assert (max_degree index2 = 16) ; assert (public_inputs index0 = 0) ; @@ -975,16 +967,8 @@ let _ = vec in let urs = Pasta_fq_urs.create 16 in - (* TODO(dw) write tests with lookup tables *) - let lookup_tables = [||] in - (* TODO(dw) write tests with runtime tables *) - let runtime_table_cfg = [||] in - let index0 = - create gate_vector 0 lookup_tables runtime_table_cfg 0 urs - in - let index2 = - create gate_vector 2 lookup_tables runtime_table_cfg 0 urs - in + let index0 = create gate_vector 0 0 urs in + let index2 = create gate_vector 2 0 urs in assert (max_degree index0 = 16) ; assert (max_degree index2 = 16) ; assert (public_inputs index0 = 0) ; @@ -1008,28 +992,10 @@ let verification_evals_to_list ; mul_comm : 'PolyComm ; emul_comm : 'PolyComm ; endomul_scalar_comm : 'PolyComm - ; xor_comm : 'PolyComm option - ; range_check0_comm : 'PolyComm option - ; range_check1_comm : 'PolyComm option - ; foreign_field_add_comm : 'PolyComm option - ; foreign_field_mul_comm : 'PolyComm option - ; rot_comm : 'PolyComm option } = - let non_opt_comms = - generic_comm :: psm_comm :: complete_add_comm :: mul_comm :: emul_comm - :: endomul_scalar_comm - :: (Array.append sigma_comm coefficients_comm |> Array.to_list) - in - let opt_comms = - [ xor_comm - ; range_check0_comm - ; range_check1_comm - ; foreign_field_add_comm - ; foreign_field_mul_comm - ; rot_comm - ] - in - List.map Option.some non_opt_comms @ opt_comms + generic_comm :: psm_comm :: complete_add_comm :: mul_comm :: emul_comm + :: endomul_scalar_comm + :: (Array.append sigma_comm coefficients_comm |> Array.to_list) let eq_verifier_index ~field_equal ~other_field_equal { VerifierIndex.domain = { log_size_of_group = i1_1; group_gen = f1 } @@ -1052,14 +1018,7 @@ let eq_verifier_index ~field_equal ~other_field_equal } = i1_1 = i2_1 && field_equal f1 f2 && i1_2 = i2_2 && List.for_all2 - (fun x y -> - match (x, y) with - | Some x, Some y -> - eq_poly_comm ~field_equal:other_field_equal x y - | None, None -> - true - | _, _ -> - false ) + (eq_poly_comm ~field_equal:other_field_equal) (verification_evals_to_list evals1) (verification_evals_to_list evals2) && eq_verification_shifts ~field_equal shifts1 shifts2 @@ -1100,18 +1059,8 @@ let _ = ~other_field_equal:Pasta_fq.equal in let urs = Pasta_fp_urs.create 16 in - (* TODO(dw) write tests with lookup tables *) - let lookup_tables = [||] in - (* TODO(dw) write tests with runtime tables *) - let runtime_table_cfg = [||] in - let index0 = - Pasta_fp_index.create gate_vector 0 lookup_tables runtime_table_cfg 0 - urs - in - let index2 = - Pasta_fp_index.create gate_vector 2 lookup_tables runtime_table_cfg 0 - urs - in + let index0 = Pasta_fp_index.create gate_vector 0 0 urs in + let index2 = Pasta_fp_index.create gate_vector 2 0 urs in let vindex0_0 = create index0 in let vindex0_1 = create index0 in assert (eq vindex0_0 vindex0_1) ; @@ -1160,18 +1109,8 @@ let _ = ~other_field_equal:Pasta_fp.equal in let urs = Pasta_fq_urs.create 16 in - (* TODO(dw) write tests with lookup tables *) - let lookup_tables = [||] in - (* TODO(dw) write tests with runtime tables *) - let runtime_table_cfg = [||] in - let index0 = - Pasta_fq_index.create gate_vector 0 lookup_tables runtime_table_cfg 0 - urs - in - let index2 = - Pasta_fq_index.create gate_vector 2 lookup_tables runtime_table_cfg 0 - urs - in + let index0 = Pasta_fq_index.create gate_vector 0 0 urs in + let index2 = Pasta_fq_index.create gate_vector 2 0 urs in let vindex0_0 = create index0 in let vindex0_1 = create index0 in assert (eq vindex0_0 vindex0_1) ; diff --git a/src/lib/crypto/kimchi_bindings/js/web/build.sh b/src/lib/crypto/kimchi_bindings/js/web/build.sh index f99564ef81d4..c63fadb4ccb8 100755 --- a/src/lib/crypto/kimchi_bindings/js/web/build.sh +++ b/src/lib/crypto/kimchi_bindings/js/web/build.sh @@ -2,9 +2,9 @@ set -euo pipefail if [[ -z "${PLONK_WASM_WEB-}" ]]; then - export RUSTFLAGS="-C target-feature=+atomics,+bulk-memory,+mutable-globals -C link-arg=--no-check-features -C link-arg=--max-memory=4294967296" # The version should stay in line with the one in kimchi_bindings/wasm/rust-toolchain.toml - rustup run nightly-2023-09-01 wasm-pack build --target web --out-dir ../js/web ../../wasm -- -Z build-std=panic_abort,std + export RUSTFLAGS="-C target-feature=+atomics,+bulk-memory,+mutable-globals -C link-arg=--no-check-features -C link-arg=--max-memory=4294967296" + rustup run nightly-2022-09-12 wasm-pack build --target web --out-dir ../js/web ../../wasm -- -Z build-std=panic_abort,std else cp "$PLONK_WASM_WEB"/* -R . fi diff --git a/src/lib/crypto/kimchi_bindings/js/web/dune b/src/lib/crypto/kimchi_bindings/js/web/dune index bcc52fe55d0d..4c9ebc21ce6f 100644 --- a/src/lib/crypto/kimchi_bindings/js/web/dune +++ b/src/lib/crypto/kimchi_bindings/js/web/dune @@ -1,6 +1,5 @@ (library (name web_backend) - (public_name bindings_js.web_backend) (js_of_ocaml (flags (:include flags.sexp)) diff --git a/src/lib/crypto/kimchi_bindings/js/web/web_backend.js b/src/lib/crypto/kimchi_bindings/js/web/web_backend.js index 53db813af7f7..57c4928ec20a 100644 --- a/src/lib/crypto/kimchi_bindings/js/web/web_backend.js +++ b/src/lib/crypto/kimchi_bindings/js/web/web_backend.js @@ -1,2 +1,2 @@ // Provides: plonk_wasm -var plonk_wasm = globalThis.plonk_wasm; +var plonk_wasm = joo_global_object.plonk_wasm; diff --git a/src/lib/crypto/kimchi_bindings/wasm/Cargo.lock b/src/lib/crypto/kimchi_bindings/wasm/Cargo.lock index 4d70407e2e3c..204b924271ac 100644 --- a/src/lib/crypto/kimchi_bindings/wasm/Cargo.lock +++ b/src/lib/crypto/kimchi_bindings/wasm/Cargo.lock @@ -24,12 +24,6 @@ dependencies = [ "num-traits", ] -[[package]] -name = "android-tzdata" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" - [[package]] name = "android_system_properties" version = "0.1.5" @@ -89,7 +83,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "db02d390bf6643fb404d3d22d31aee1c4bc4459600aef9113833d17e786c6e44" dependencies = [ "quote", - "syn 1.0.109", + "syn", ] [[package]] @@ -101,7 +95,7 @@ dependencies = [ "num-bigint", "num-traits", "quote", - "syn 1.0.109", + "syn", ] [[package]] @@ -137,7 +131,7 @@ checksum = "8dd4e5f0bf8285d5ed538d27fab7411f3e297908fd93c62195de8bee3f199e82" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn", ] [[package]] @@ -185,23 +179,23 @@ version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "46502ad458c9a52b69d4d4d32775c788b7a1b85e8bc9d482d92250fc0e3f8efe" dependencies = [ - "digest 0.10.7", + "digest 0.10.6", ] [[package]] name = "block-buffer" -version = "0.10.4" +version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +checksum = "69cce20737498f97b993470a6e536b8523f0af7892a4f928cceb1ac5e52ebe7e" dependencies = [ "generic-array", ] [[package]] name = "bumpalo" -version = "3.14.0" +version = "3.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" +checksum = "0d261e256854913907f67ed06efbc3338dfe6179796deefc1ff763fc1aee5535" [[package]] name = "byteorder" @@ -211,12 +205,9 @@ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" [[package]] name = "cc" -version = "1.0.83" +version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" -dependencies = [ - "libc", -] +checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" [[package]] name = "cfg-if" @@ -226,15 +217,25 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.31" +version = "0.4.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f2c685bad3eb3d45a01354cedb7d5faa66194d1d58ba6e267a8de788f79db38" +checksum = "16b0a3d9ed01224b22057780a37bb8c5dbfe1be8ba48678e7bf57ec4b385411f" dependencies = [ - "android-tzdata", "iana-time-zone", + "num-integer", "num-traits", "serde", - "windows-targets", + "winapi", +] + +[[package]] +name = "codespan-reporting" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e" +dependencies = [ + "termcolor", + "unicode-width", ] [[package]] @@ -249,24 +250,34 @@ dependencies = [ [[package]] name = "core-foundation-sys" -version = "0.8.4" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" +checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" [[package]] name = "cpufeatures" -version = "0.2.9" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a17b76ff3a4162b0b27f354a0c87015ddad39d35f9c0c36607a3bdd175dde1f1" +checksum = "28d997bd5e24a5928dd43e46dc529867e207907fe0b239c3477d924f7f2ca320" dependencies = [ "libc", ] +[[package]] +name = "crossbeam-channel" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2dd04ddaf88237dc3b8d8f9a3c1004b506b54b3313403944054d23c0870c521" +dependencies = [ + "cfg-if", + "crossbeam-utils", +] + [[package]] name = "crossbeam-deque" -version = "0.8.3" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce6fd6f855243022dcecf8702fef0c297d4338e226845fe067f6341ad9fa0cef" +checksum = "715e8152b692bba2d374b53d4875445368fdf21a94751410af607a5ac677d1fc" dependencies = [ "cfg-if", "crossbeam-epoch", @@ -275,9 +286,9 @@ dependencies = [ [[package]] name = "crossbeam-epoch" -version = "0.9.15" +version = "0.9.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae211234986c545741a7dc064309f67ee1e5ad243d0e48335adc0484d960bcc7" +checksum = "01a9af1f4c2ef74bb8aa1f7e19706bc72d03598c8a570bb5de72243c7a9d9d5a" dependencies = [ "autocfg", "cfg-if", @@ -288,9 +299,9 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.16" +version = "0.8.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294" +checksum = "4fb766fa798726286dbbb842f174001dab8abc7b627a1dd86e0b7222a95d929f" dependencies = [ "cfg-if", ] @@ -305,6 +316,50 @@ dependencies = [ "typenum", ] +[[package]] +name = "cxx" +version = "1.0.91" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86d3488e7665a7a483b57e25bdd90d0aeb2bc7608c8d0346acf2ad3f1caf1d62" +dependencies = [ + "cc", + "cxxbridge-flags", + "cxxbridge-macro", + "link-cplusplus", +] + +[[package]] +name = "cxx-build" +version = "1.0.91" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48fcaf066a053a41a81dfb14d57d99738b767febb8b735c3016e469fac5da690" +dependencies = [ + "cc", + "codespan-reporting", + "once_cell", + "proc-macro2", + "quote", + "scratch", + "syn", +] + +[[package]] +name = "cxxbridge-flags" +version = "1.0.91" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2ef98b8b717a829ca5603af80e1f9e2e48013ab227b68ef37872ef84ee479bf" + +[[package]] +name = "cxxbridge-macro" +version = "1.0.91" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "086c685979a698443656e5cf7856c95c642295a38599f12fb1ff76fb28d19892" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "darling" version = "0.13.4" @@ -317,12 +372,12 @@ dependencies = [ [[package]] name = "darling" -version = "0.20.3" +version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0209d94da627ab5605dcccf08bb18afa5009cfbef48d8a8b7d7bdbc79be25c5e" +checksum = "c0808e1bd8671fb44a113a14e13497557533369847788fa2ae912b6ebfce9fa8" dependencies = [ - "darling_core 0.20.3", - "darling_macro 0.20.3", + "darling_core 0.14.3", + "darling_macro 0.14.3", ] [[package]] @@ -336,21 +391,21 @@ dependencies = [ "proc-macro2", "quote", "strsim", - "syn 1.0.109", + "syn", ] [[package]] name = "darling_core" -version = "0.20.3" +version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "177e3443818124b357d8e76f53be906d60937f0d3a90773a664fa63fa253e621" +checksum = "001d80444f28e193f30c2f293455da62dcf9a6b29918a4253152ae2b1de592cb" dependencies = [ "fnv", "ident_case", "proc-macro2", "quote", "strsim", - "syn 2.0.20", + "syn", ] [[package]] @@ -361,27 +416,18 @@ checksum = "9c972679f83bdf9c42bd905396b6c3588a843a17f0f16dfcfa3e2c5d57441835" dependencies = [ "darling_core 0.13.4", "quote", - "syn 1.0.109", + "syn", ] [[package]] name = "darling_macro" -version = "0.20.3" +version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "836a9bbc7ad63342d6d6e7b815ccab164bc77a2d95d84bc3117a8c0d5c98e2d5" +checksum = "b36230598a2d5de7ec1c6f51f72d8a99a9208daff41de2084d06e3fd3ea56685" dependencies = [ - "darling_core 0.20.3", + "darling_core 0.14.3", "quote", - "syn 2.0.20", -] - -[[package]] -name = "deranged" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2696e8a945f658fd14dc3b87242e6b80cd0f36ff04ea560fa39082368847946" -dependencies = [ - "serde", + "syn", ] [[package]] @@ -392,7 +438,7 @@ checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn", ] [[package]] @@ -406,9 +452,9 @@ dependencies = [ [[package]] name = "digest" -version = "0.10.7" +version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +checksum = "8168378f4e5023e7218c89c891c0fd8ecdb5e5e4f18cb78f38cf245dd021e76f" dependencies = [ "block-buffer", "crypto-common", @@ -423,9 +469,9 @@ checksum = "d102f1a462fdcdddce88d6d46c06c074a2d2749b262230333726b06c52bb7585" [[package]] name = "either" -version = "1.9.0" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" +checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" [[package]] name = "fnv" @@ -435,9 +481,9 @@ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] name = "generic-array" -version = "0.14.7" +version = "0.14.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9" dependencies = [ "typenum", "version_check", @@ -445,9 +491,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.10" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" +checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" dependencies = [ "cfg-if", "js-sys", @@ -488,40 +534,41 @@ checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] name = "hermit-abi" -version = "0.3.3" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" +checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" +dependencies = [ + "libc", +] [[package]] name = "hex" version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" -dependencies = [ - "serde", -] [[package]] name = "iana-time-zone" -version = "0.1.57" +version = "0.1.53" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fad5b825842d2b38bd206f3e81d6957625fd7f0a361e345c30e01a0ae2dd613" +checksum = "64c122667b287044802d6ce17ee2ddf13207ed924c712de9a66a5814d5b64765" dependencies = [ "android_system_properties", "core-foundation-sys", "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "windows", + "winapi", ] [[package]] name = "iana-time-zone-haiku" -version = "0.1.2" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +checksum = "0703ae284fc167426161c2e3f1da3ea71d94b21bedbcc9494e92b28e334e3dca" dependencies = [ - "cc", + "cxx", + "cxx-build", ] [[package]] @@ -532,19 +579,15 @@ checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" [[package]] name = "indexmap" -version = "1.9.3" +version = "1.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" +checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" dependencies = [ "autocfg", "hashbrown 0.12.3", "serde", ] -[[package]] -name = "internal-tracing" -version = "0.1.0" - [[package]] name = "itertools" version = "0.10.5" @@ -556,15 +599,15 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.9" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" +checksum = "fad582f4b9e86b6caa621cabeb0963332d92eea04729ab12892c2533951e6440" [[package]] name = "js-sys" -version = "0.3.62" +version = "0.3.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68c16e1bfd491478ab155fd8b4896b86f9ede344949b641e61501e07c2b8b4d5" +checksum = "445dde2150c55e483f3d8416706b97ec8e8237c307e5b7b4b8dd15e6af2a0730" dependencies = [ "wasm-bindgen", ] @@ -581,7 +624,6 @@ dependencies = [ "disjoint-set", "groupmap", "hex", - "internal-tracing", "itertools", "mina-curves", "mina-poseidon", @@ -607,43 +649,48 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.148" +version = "0.2.139" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cdc71e17332e86d2e1d38c1f99edcb6288ee11b815fb1a4b049eaa2114d369b" +checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" [[package]] name = "libm" -version = "0.2.7" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7012b1bbb0719e1097c47611d3898568c546d597c2e74d66f6087edd5233ff4" +checksum = "348108ab3fba42ec82ff6e9564fc4ca0247bdccdc68dd8af9764bbc79c3c8ffb" [[package]] -name = "log" -version = "0.4.20" +name = "link-cplusplus" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" +checksum = "ecd207c9c713c34f95a097a5b029ac2ce6010530c7b49d7fea24d977dede04f5" +dependencies = [ + "cc", +] [[package]] -name = "matrixmultiply" -version = "0.3.8" +name = "log" +version = "0.4.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7574c1cf36da4798ab73da5b215bbf444f50718207754cb522201d78d1cd0ff2" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" dependencies = [ - "autocfg", - "rawpointer", + "cfg-if", ] [[package]] -name = "memchr" -version = "2.6.4" +name = "matrixmultiply" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" +checksum = "add85d4dd35074e6fedc608f8c8f513a3548619a9024b751949ef0e8e45a4d84" +dependencies = [ + "rawpointer", +] [[package]] name = "memoffset" -version = "0.9.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a634b1c61a95585bd15607c6ab0c4e5b226e695ff2800ba0cdccddf208c406c" +checksum = "5de893c32cde5f383baa4c04c5d6dbdd735cfd4a794b0debdb2bb1b421da5ff4" dependencies = [ "autocfg", ] @@ -679,7 +726,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "adb12d4e967ec485a5f71c6311fe28158e9d6f4bc4a447b474184d0f91a8fa32" dependencies = [ "matrixmultiply", - "num-complex 0.4.4", + "num-complex 0.4.3", "num-integer", "num-traits", "rawpointer", @@ -687,9 +734,9 @@ dependencies = [ [[package]] name = "num-bigint" -version = "0.4.4" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "608e7659b5c3d7cba262d894801b9ec9d00de989e8a82bd4bef91d08da45cdc0" +checksum = "f93ab6289c7b344a8a9f60f88d80aa20032336fe78da341afc91c8a2341fc75f" dependencies = [ "autocfg", "num-integer", @@ -710,9 +757,9 @@ dependencies = [ [[package]] name = "num-complex" -version = "0.4.4" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ba157ca0885411de85d6ca030ba7e2a83a28636056c7c699b07c8b6f7383214" +checksum = "02e0d21255c828d6f128a1e41534206671e8c3ea0c62f32291e808dc82cff17d" dependencies = [ "num-traits", ] @@ -725,7 +772,7 @@ checksum = "876a53fff98e03a936a674b29568b0e605f06b29372c2489ff4de23f1949743d" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn", ] [[package]] @@ -740,9 +787,9 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.16" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f30b0abd723be7e2ffca1272140fac1a2f084c77ec3e123c192b66af1ee9e6c2" +checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" dependencies = [ "autocfg", "libm", @@ -750,9 +797,9 @@ dependencies = [ [[package]] name = "num_cpus" -version = "1.16.0" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" dependencies = [ "hermit-abi", "libc", @@ -782,23 +829,22 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.18.0" +version = "1.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" +checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" [[package]] name = "paste" -version = "1.0.14" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" +checksum = "d01a5bd0424d00070b0098dd17ebca6f961a959dead1dbcbbbc1d1cd8d3deeba" [[package]] name = "pest" -version = "2.7.4" +version = "2.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c022f1e7b65d6a24c0dbbd5fb344c66881bc01f3e5ae74a1c8100f2f985d98a4" +checksum = "028accff104c4e513bad663bbcd2ad7cfd5304144404c31ed0a77ac103d00660" dependencies = [ - "memchr", "thiserror", "ucd-trie", ] @@ -826,14 +872,13 @@ dependencies = [ "once_cell", "paste", "poly-commitment", - "proc-macro2", "rand", "rayon", "rmp-serde", "serde", "serde-wasm-bindgen", "serde_json", - "serde_with 2.3.3", + "serde_with 2.2.0", "spmc", "sprs", "wasm-bindgen", @@ -859,7 +904,6 @@ dependencies = [ "rand", "rand_core", "rayon", - "rmp-serde", "serde", "serde_with 1.14.0", "thiserror", @@ -873,18 +917,18 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "proc-macro2" -version = "1.0.60" +version = "1.0.51" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dec2b086b7a862cf4de201096214fa870344cf922b2b30c167badb3af3195406" +checksum = "5d727cae5b39d21da60fa540906919ad737832fe0b1c165da3a34d6548c849d6" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.28" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b9ab9c7eadfd8df19006f1cf1a4aed13540ed5cbc047010ece5826e10825488" +checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" dependencies = [ "proc-macro2", ] @@ -927,9 +971,9 @@ checksum = "60a357793950651c4ed0f3f52338f53b2f809f32d83a07f72909fa13e4c6c1e3" [[package]] name = "rayon" -version = "1.8.0" +version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c27db03db7734835b3f53954b534c91069375ce6ccaa2e065441e07d9b6cdb1" +checksum = "6db3a213adf02b3bcfd2d3846bb41cb22857d131789e01df434fb7e7bc0759b7" dependencies = [ "either", "rayon-core", @@ -937,19 +981,21 @@ dependencies = [ [[package]] name = "rayon-core" -version = "1.12.0" +version = "1.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ce3fb6ad83f861aac485e76e1985cd109d9a3713802152be56c3b1f0e0658ed" +checksum = "356a0625f1954f730c0201cdab48611198dc6ce21f4acff55089b5a78e6e835b" dependencies = [ + "crossbeam-channel", "crossbeam-deque", "crossbeam-utils", + "num_cpus", ] [[package]] name = "rmp" -version = "0.8.12" +version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9860a6cc38ed1da53456442089b4dfa35e7cedaa326df63017af88385e6b20" +checksum = "44519172358fd6d58656c86ab8e7fbc9e1490c3e8f14d35ed78ca0dd07403c9f" dependencies = [ "byteorder", "num-traits", @@ -958,9 +1004,9 @@ dependencies = [ [[package]] name = "rmp-serde" -version = "1.1.2" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bffea85eea980d8a74453e5d02a8d93028f3c34725de143085a844ebe953258a" +checksum = "c5b13be192e0220b8afb7222aa5813cb62cc269ebb5cac346ca6487681d2913e" dependencies = [ "byteorder", "rmp", @@ -978,15 +1024,15 @@ dependencies = [ [[package]] name = "rustversion" -version = "1.0.14" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" +checksum = "5583e89e108996506031660fe09baa5011b9dd0341b89029313006d1fb508d70" [[package]] name = "ryu" -version = "1.0.15" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" +checksum = "7b4b9743ed687d4b4bcedf9ff5eaa7398495ae14e61cba0a295704edbc7decde" [[package]] name = "scoped-tls" @@ -996,9 +1042,15 @@ checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" [[package]] name = "scopeguard" -version = "1.2.0" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + +[[package]] +name = "scratch" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddccb15bcce173023b3fedd9436f882a0739b8dfb45e4f6b6002bee5929f61b2" [[package]] name = "semver" @@ -1020,9 +1072,9 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.164" +version = "1.0.152" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e8c8cf938e98f769bc164923b06dce91cea1751522f46f8466461af04c9027d" +checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb" dependencies = [ "serde_derive", ] @@ -1040,20 +1092,20 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.164" +version = "1.0.152" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9735b638ccc51c28bf6914d90a2e9725b377144fc612c49a611fddd1b631d68" +checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.20", + "syn", ] [[package]] name = "serde_json" -version = "1.0.99" +version = "1.0.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46266871c240a00b8f503b877622fe33430b3c7d963bdc0f2adc511e54a1eae3" +checksum = "cad406b69c91885b5107daf2c29572f6c8cdb3c66826821e286c533490c0bc76" dependencies = [ "itoa", "ryu", @@ -1072,9 +1124,9 @@ dependencies = [ [[package]] name = "serde_with" -version = "2.3.3" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07ff71d2c147a7b57362cead5e22f772cd52f6ab31cfcd9edcd7f6aeb2a0afbe" +checksum = "30d904179146de381af4c93d3af6ca4984b3152db687dacb9c3c35e86f39809c" dependencies = [ "base64", "chrono", @@ -1082,7 +1134,7 @@ dependencies = [ "indexmap", "serde", "serde_json", - "serde_with_macros 2.3.3", + "serde_with_macros 2.2.0", "time", ] @@ -1095,37 +1147,37 @@ dependencies = [ "darling 0.13.4", "proc-macro2", "quote", - "syn 1.0.109", + "syn", ] [[package]] name = "serde_with_macros" -version = "2.3.3" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "881b6f881b17d13214e5d494c939ebab463d01264ce1811e9d4ac3a882e7695f" +checksum = "a1966009f3c05f095697c537312f5415d1e3ed31ce0a56942bac4c771c5c335e" dependencies = [ - "darling 0.20.3", + "darling 0.14.3", "proc-macro2", "quote", - "syn 2.0.20", + "syn", ] [[package]] name = "sha2" -version = "0.10.8" +version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0" dependencies = [ "cfg-if", "cpufeatures", - "digest 0.10.7", + "digest 0.10.6", ] [[package]] name = "smallvec" -version = "1.11.1" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a" +checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" [[package]] name = "spmc" @@ -1135,13 +1187,13 @@ checksum = "02a8428da277a8e3a15271d79943e80ccc2ef254e78813a166a08d65e4c3ece5" [[package]] name = "sprs" -version = "0.11.1" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88bab60b0a18fb9b3e0c26e92796b3c3a278bf5fa4880f5ad5cc3bdfb843d0b1" +checksum = "6ea71e48b3eab4c4b153e8e35dcaeac132720809ef68359097b8cb54a18edd70" dependencies = [ "alga", "ndarray", - "num-complex 0.4.4", + "num-complex 0.4.3", "num-traits", "num_cpus", "rayon", @@ -1170,20 +1222,20 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 1.0.109", + "syn", ] [[package]] name = "subtle" -version = "2.5.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" +checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" [[package]] name = "syn" -version = "1.0.109" +version = "1.0.107" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" dependencies = [ "proc-macro2", "quote", @@ -1191,43 +1243,52 @@ dependencies = [ ] [[package]] -name = "syn" -version = "2.0.20" +name = "synstructure" +version = "0.12.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcb8d4cebc40aa517dfb69618fa647a346562e67228e2236ae0042ee6ac14775" +checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f" dependencies = [ "proc-macro2", "quote", - "unicode-ident", + "syn", + "unicode-xid", +] + +[[package]] +name = "termcolor" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6" +dependencies = [ + "winapi-util", ] [[package]] name = "thiserror" -version = "1.0.40" +version = "1.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "978c9a314bd8dc99be594bc3c175faaa9794be04a5a5e153caba6915336cebac" +checksum = "6a9cd18aa97d5c45c6603caea1da6628790b37f7a34b6ca89522331c5180fed0" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.40" +version = "1.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" +checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.20", + "syn", ] [[package]] name = "time" -version = "0.3.26" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a79d09ac6b08c1ab3906a2f7cc2e81a0e27c7ae89c63812df75e52bef0751e07" +checksum = "53250a3b3fed8ff8fd988587d8925d26a83ac3845d9e03b220b37f34c2b8d6c2" dependencies = [ - "deranged", "itoa", "serde", "time-core", @@ -1236,15 +1297,15 @@ dependencies = [ [[package]] name = "time-core" -version = "0.1.1" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7300fbefb4dadc1af235a9cef3737cea692a9d97e1b9cbcd4ebdae6f8868e6fb" +checksum = "2e153e1f1acaef8acc537e68b44906d2db6436e2b35ac2c6b42640fff91f00fd" [[package]] name = "time-macros" -version = "0.2.12" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75c65469ed6b3a4809d987a41eb1dc918e9bc1d92211cbad7ae82931846f7451" +checksum = "a460aeb8de6dcb0f381e1ee05f1cd56fcf5a5f6eb8187ff3d8f0b11078d38b7c" dependencies = [ "time-core", ] @@ -1260,21 +1321,33 @@ dependencies = [ [[package]] name = "typenum" -version = "1.17.0" +version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" +checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" [[package]] name = "ucd-trie" -version = "0.1.6" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9" +checksum = "9e79c4d996edb816c91e4308506774452e55e95c3c9de07b6729e17e15a5ef81" [[package]] name = "unicode-ident" -version = "1.0.12" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" + +[[package]] +name = "unicode-width" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" + +[[package]] +name = "unicode-xid" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" [[package]] name = "version_check" @@ -1290,9 +1363,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.85" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b6cb788c4e39112fbe1822277ef6fb3c55cd86b95cb3d3c4c1c9597e4ac74b4" +checksum = "31f8dcbc21f30d9b8f2ea926ecb58f6b91192c17e9d33594b3df58b2007ca53b" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -1300,24 +1373,24 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.85" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35e522ed4105a9d626d885b35d62501b30d9666283a5c8be12c14a8bdafe7822" +checksum = "95ce90fd5bcc06af55a641a86428ee4229e44e07033963a2290a8e241607ccb9" dependencies = [ "bumpalo", "log", "once_cell", "proc-macro2", "quote", - "syn 2.0.20", + "syn", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-futures" -version = "0.4.35" +version = "0.4.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "083abe15c5d88556b77bdf7aef403625be9e327ad37c62c4e4129af740168163" +checksum = "f219e0d211ba40266969f6dbdd90636da12f75bee4fc9d6c23d1260dadb51454" dependencies = [ "cfg-if", "js-sys", @@ -1327,9 +1400,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.85" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "358a79a0cb89d21db8120cbfb91392335913e4890665b1a7981d9e956903b434" +checksum = "4c21f77c0bedc37fd5dc21f897894a5ca01e7bb159884559461862ae90c0b4c5" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -1337,28 +1410,28 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.85" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4783ce29f09b9d93134d41297aded3a712b7b979e9c6f28c32cb88c973a94869" +checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.20", + "syn", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.85" +version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a901d592cafaa4d711bc324edfaff879ac700b19c3dfd60058d2b445be2691eb" +checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d" [[package]] name = "wasm-bindgen-test" -version = "0.3.35" +version = "0.3.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b27e15b4a3030b9944370ba1d8cec6f21f66a1ad4fd14725c5685600460713ec" +checksum = "6db36fc0f9fb209e88fb3642590ae0205bb5a56216dabd963ba15879fe53a30b" dependencies = [ "console_error_panic_hook", "js-sys", @@ -1370,9 +1443,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-test-macro" -version = "0.3.35" +version = "0.3.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dbaa9b9a574eac00c4f3a9c4941ac051f07632ecd0484a8588abd95af6b99d2" +checksum = "0734759ae6b3b1717d661fe4f016efcfb9828f5edb4520c18eaee05af3b43be9" dependencies = [ "proc-macro2", "quote", @@ -1380,96 +1453,62 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.62" +version = "0.3.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16b5f940c7edfdc6d12126d98c9ef4d1b3d470011c47c76a6581df47ad9ba721" +checksum = "e33b99f4b23ba3eec1a53ac264e35a755f00e966e0065077d6027c0f575b0b97" dependencies = [ "js-sys", "wasm-bindgen", ] [[package]] -name = "windows" -version = "0.48.0" +name = "winapi" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" dependencies = [ - "windows-targets", + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", ] [[package]] -name = "windows-targets" -version = "0.48.5" +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", -] +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" +name = "winapi-util" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi", +] [[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "zeroize" -version = "1.6.0" +version = "1.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a0956f1ba7c7909bfb66c2e9e4124ab6f6482560f6628b5aaeba39207c9aad9" +checksum = "c394b5bd0c6f669e7275d9c20aa90ae064cb22e75a1cad54e1b34088034b149f" dependencies = [ "zeroize_derive", ] [[package]] name = "zeroize_derive" -version = "1.4.2" +version = "1.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" +checksum = "44bf07cb3e50ea2003396695d58bf46bc9887a1f362260446fad6bc4e79bd36c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.20", + "syn", + "synstructure", ] diff --git a/src/lib/crypto/kimchi_bindings/wasm/Cargo.toml b/src/lib/crypto/kimchi_bindings/wasm/Cargo.toml index 65cde6600607..42a91c704800 100644 --- a/src/lib/crypto/kimchi_bindings/wasm/Cargo.toml +++ b/src/lib/crypto/kimchi_bindings/wasm/Cargo.toml @@ -14,9 +14,7 @@ crate-type = ["cdylib"] ################################# Dependencies ################################ [dependencies] -# Strictly enforcing 0.2.84. It seems that 0.2.87 generates unwanted behavior. -# See https://github.com/MinaProtocol/mina/issues/14253 -wasm-bindgen = { version = "=0.2.85" } +wasm-bindgen = { version = "0.2.78" } console_error_panic_hook = { version = "0.1.6" } web-sys = { version = "0.3.35", features = ["Window", "Document", "HtmlElement", "Text", "Node", "Element" ] } @@ -52,9 +50,6 @@ serde_json = "1.0" serde_with = "2.0.1" serde-wasm-bindgen = "0.4" js-sys = "0.3" -# Version for proc-macro2 needs to be 1.0.60+ to be compatible with newer rust versions -# https://github.com/rust-lang/rust/issues/113152 -proc-macro2 = { version = "=1.0.60", features=["default", "proc-macro"] } [dev-dependencies] wasm-bindgen-test = "0.3.0" diff --git a/src/lib/crypto/kimchi_bindings/wasm/rust-toolchain.toml b/src/lib/crypto/kimchi_bindings/wasm/rust-toolchain.toml index b04d9639e65d..1f6f0ea957be 100644 --- a/src/lib/crypto/kimchi_bindings/wasm/rust-toolchain.toml +++ b/src/lib/crypto/kimchi_bindings/wasm/rust-toolchain.toml @@ -1,6 +1,2 @@ -# A nightly is necessary to enable the use of #![feature] [toolchain] -# This should stay in line with the versions in -# - kimchi_bindings/js/node_js/build.sh -# - kimchi_bindings/js/web/build.sh -channel = "nightly-2023-09-01" # roughly matches 1.72 +channel = "nightly-2023-02-05" diff --git a/src/lib/crypto/kimchi_bindings/wasm/src/oracles.rs b/src/lib/crypto/kimchi_bindings/wasm/src/oracles.rs index 96a17baa4329..e333e8ce0561 100644 --- a/src/lib/crypto/kimchi_bindings/wasm/src/oracles.rs +++ b/src/lib/crypto/kimchi_bindings/wasm/src/oracles.rs @@ -9,8 +9,6 @@ use mina_poseidon::{ }; use paste::paste; use poly_commitment::commitment::{shift_scalar, PolyComm}; -use poly_commitment::evaluation_proof::OpeningProof; -use poly_commitment::SRS; use wasm_bindgen::prelude::*; // use wasm_bindgen::convert::{IntoWasmAbi, FromWasmAbi}; use crate::wasm_vector::WasmVector; @@ -180,7 +178,7 @@ macro_rules! impl_oracles { ) -> Result<[], JsError> { // conversions let result = crate::rayon::run_in_pool(|| { - let index: DlogVerifierIndex<$G, OpeningProof<$G>> = index.into(); + let index: DlogVerifierIndex<$G> = index.into(); let lgr_comm: Vec> = lgr_comm .into_iter() @@ -209,13 +207,10 @@ macro_rules! impl_oracles { .commitment }; - let (proof, public_input): (ProverProof<$G, OpeningProof<$G>>, Vec<$F>) = proof.into(); + let (proof, public_input): (ProverProof<$G>, Vec<$F>) = proof.into(); let oracles_result = - proof.oracles::< - DefaultFqSponge<$curve_params, PlonkSpongeConstantsKimchi>, - DefaultFrSponge<$F, PlonkSpongeConstantsKimchi> - >(&index, &p_comm, Some(&public_input)); + proof.oracles::, DefaultFrSponge<$F, PlonkSpongeConstantsKimchi>>(&index, &p_comm,&public_input); let oracles_result = match oracles_result { Err(e) => { return Err(format!("oracles_create: {}", e)); diff --git a/src/lib/crypto/kimchi_bindings/wasm/src/pasta_fp_plonk_index.rs b/src/lib/crypto/kimchi_bindings/wasm/src/pasta_fp_plonk_index.rs index 2d1f9432448c..5b48d79c4943 100644 --- a/src/lib/crypto/kimchi_bindings/wasm/src/pasta_fp_plonk_index.rs +++ b/src/lib/crypto/kimchi_bindings/wasm/src/pasta_fp_plonk_index.rs @@ -1,15 +1,9 @@ use ark_poly::EvaluationDomain; -use kimchi::circuits::lookup::runtime_tables::RuntimeTableCfg; -use crate::arkworks::WasmPastaFp; use crate::gate_vector::fp::WasmGateVector; use crate::srs::fp::WasmFpSrs as WasmSrs; -use crate::wasm_flat_vector::WasmFlatVector; -use crate::wasm_vector::{fp::*, WasmVector}; -use kimchi::circuits::lookup::tables::LookupTable; use kimchi::circuits::{constraints::ConstraintSystem, gate::CircuitGate}; use kimchi::linearization::expr_linearization; -use kimchi::poly_commitment::evaluation_proof::OpeningProof; use kimchi::prover_index::ProverIndex; use mina_curves::pasta::{Fp, Pallas as GAffineOther, Vesta as GAffine, VestaParameters}; use mina_poseidon::{constants::PlonkSpongeConstantsKimchi, sponge::DefaultFqSponge}; @@ -26,81 +20,16 @@ use wasm_bindgen::prelude::*; /// Boxed so that we don't store large proving indexes in the OCaml heap. #[wasm_bindgen] -pub struct WasmPastaFpPlonkIndex( - #[wasm_bindgen(skip)] pub Box>>, -); - -// This should mimic LookupTable structure -#[wasm_bindgen] -pub struct WasmPastaFpLookupTable { - #[wasm_bindgen(skip)] - pub id: i32, - #[wasm_bindgen(skip)] - pub data: WasmVecVecFp, -} - -// Converter from WasmPastaFpLookupTable to LookupTable, used by the binding -// below. -impl From for LookupTable { - fn from(wasm_lt: WasmPastaFpLookupTable) -> LookupTable { - LookupTable { - id: wasm_lt.id.into(), - data: wasm_lt.data.0, - } - } -} - -// JS constructor for js/bindings.js -#[wasm_bindgen] -impl WasmPastaFpLookupTable { - #[wasm_bindgen(constructor)] - pub fn new(id: i32, data: WasmVecVecFp) -> WasmPastaFpLookupTable { - WasmPastaFpLookupTable { id, data } - } -} - -// Runtime table config - -#[wasm_bindgen] -pub struct WasmPastaFpRuntimeTableCfg { - #[wasm_bindgen(skip)] - pub id: i32, - #[wasm_bindgen(skip)] - pub first_column: WasmFlatVector, -} - -// JS constructor for js/bindings.js -#[wasm_bindgen] -impl WasmPastaFpRuntimeTableCfg { - #[wasm_bindgen(constructor)] - pub fn new(id: i32, first_column: WasmFlatVector) -> Self { - Self { id, first_column } - } -} - -impl From for RuntimeTableCfg { - fn from(wasm_rt_table_cfg: WasmPastaFpRuntimeTableCfg) -> Self { - Self { - id: wasm_rt_table_cfg.id, - first_column: wasm_rt_table_cfg - .first_column - .into_iter() - .map(Into::into) - .collect(), - } - } -} +pub struct WasmPastaFpPlonkIndex(#[wasm_bindgen(skip)] pub Box>); +// // CamlPastaFpPlonkIndex methods // -// Change js/web/worker-spec.js accordingly #[wasm_bindgen] pub fn caml_pasta_fp_plonk_index_create( gates: &WasmGateVector, public_: i32, - lookup_tables: WasmVector, - runtime_table_cfgs: WasmVector, prev_challenges: i32, srs: &WasmSrs, ) -> Result { @@ -117,22 +46,10 @@ pub fn caml_pasta_fp_plonk_index_create( }) .collect(); - let rust_runtime_table_cfgs: Vec> = - runtime_table_cfgs.into_iter().map(Into::into).collect(); - - let rust_lookup_tables: Vec> = - lookup_tables.into_iter().map(Into::into).collect(); - // create constraint system let cs = match ConstraintSystem::::create(gates) .public(public_ as usize) .prev_challenges(prev_challenges as usize) - .lookup(rust_lookup_tables) - .runtime(if rust_runtime_table_cfgs.is_empty() { - None - } else { - Some(rust_runtime_table_cfgs) - }) .build() { Err(_) => { @@ -151,8 +68,7 @@ pub fn caml_pasta_fp_plonk_index_create( ptr.add_lagrange_basis(cs.domain.d1); } - let mut index = - ProverIndex::>::create(cs, endo_q, srs.0.clone()); + let mut index = ProverIndex::::create(cs, endo_q, srs.0.clone()); // Compute and cache the verifier index digest index.compute_verifier_index_digest::>(); Ok(index) @@ -190,36 +106,6 @@ pub fn caml_pasta_fp_plonk_index_domain_d8_size(index: &WasmPastaFpPlonkIndex) - index.0.cs.domain.d8.size() as i32 } -#[wasm_bindgen] -pub fn caml_pasta_fp_plonk_index_decode( - bytes: &[u8], - srs: &WasmSrs, -) -> Result { - let mut deserializer = rmp_serde::Deserializer::new(bytes); - let mut index = - ProverIndex::>::deserialize(&mut deserializer) - .map_err(|e| JsError::new(&format!("caml_pasta_fp_plonk_index_decode: {}", e)))?; - - index.srs = srs.0.clone(); - let (linearization, powers_of_alpha) = - expr_linearization(Some(&index.cs.feature_flags), true, 3); - index.linearization = linearization; - index.powers_of_alpha = powers_of_alpha; - - Ok(WasmPastaFpPlonkIndex(Box::new(index))) -} - -#[wasm_bindgen] -pub fn caml_pasta_fp_plonk_index_encode(index: &WasmPastaFpPlonkIndex) -> Result, JsError> { - let mut buffer = Vec::new(); - let mut serializer = rmp_serde::Serializer::new(&mut buffer); - index - .0 - .serialize(&mut serializer) - .map_err(|e| JsError::new(&format!("caml_pasta_fp_plonk_index_encode: {}", e)))?; - Ok(buffer) -} - #[wasm_bindgen] pub fn caml_pasta_fp_plonk_index_read( offset: Option, @@ -240,12 +126,10 @@ pub fn caml_pasta_fp_plonk_index_read( } // deserialize the index - let mut t = ProverIndex::>::deserialize( - &mut rmp_serde::Deserializer::new(r), - ) - .map_err(|err| JsValue::from_str(&format!("caml_pasta_fp_plonk_index_read: {err}")))?; + let mut t = ProverIndex::::deserialize(&mut rmp_serde::Deserializer::new(r)) + .map_err(|err| JsValue::from_str(&format!("caml_pasta_fp_plonk_index_read: {err}")))?; t.srs = srs.0.clone(); - let (linearization, powers_of_alpha) = expr_linearization(Some(&t.cs.feature_flags), true, 3); + let (linearization, powers_of_alpha) = expr_linearization(Some(&t.cs.feature_flags), true); t.linearization = linearization; t.powers_of_alpha = powers_of_alpha; diff --git a/src/lib/crypto/kimchi_bindings/wasm/src/pasta_fq_plonk_index.rs b/src/lib/crypto/kimchi_bindings/wasm/src/pasta_fq_plonk_index.rs index 911dbcf9b08b..be56f0bd88d2 100644 --- a/src/lib/crypto/kimchi_bindings/wasm/src/pasta_fq_plonk_index.rs +++ b/src/lib/crypto/kimchi_bindings/wasm/src/pasta_fq_plonk_index.rs @@ -1,15 +1,9 @@ use ark_poly::EvaluationDomain; -use kimchi::circuits::lookup::runtime_tables::RuntimeTableCfg; -use crate::arkworks::WasmPastaFq; use crate::gate_vector::fq::WasmGateVector; use crate::srs::fq::WasmFqSrs as WasmSrs; -use crate::wasm_flat_vector::WasmFlatVector; -use crate::wasm_vector::{fq::*, WasmVector}; -use kimchi::circuits::lookup::tables::LookupTable; use kimchi::circuits::{constraints::ConstraintSystem, gate::CircuitGate}; use kimchi::linearization::expr_linearization; -use kimchi::poly_commitment::evaluation_proof::OpeningProof; use kimchi::prover_index::ProverIndex; use mina_curves::pasta::{Fq, Pallas as GAffine, PallasParameters, Vesta as GAffineOther}; use mina_poseidon::{constants::PlonkSpongeConstantsKimchi, sponge::DefaultFqSponge}; @@ -26,79 +20,16 @@ use wasm_bindgen::prelude::*; /// Boxed so that we don't store large proving indexes in the OCaml heap. #[wasm_bindgen] -pub struct WasmPastaFqPlonkIndex( - #[wasm_bindgen(skip)] pub Box>>, -); - -#[wasm_bindgen] -pub struct WasmPastaFqLookupTable { - #[wasm_bindgen(skip)] - pub id: i32, - #[wasm_bindgen(skip)] - pub data: WasmVecVecFq, -} - -impl From for LookupTable { - fn from(wasm_lt: WasmPastaFqLookupTable) -> LookupTable { - LookupTable { - id: wasm_lt.id.into(), - data: wasm_lt.data.0, - } - } -} - -// JS constructor for js/bindings.js -#[wasm_bindgen] -impl WasmPastaFqLookupTable { - #[wasm_bindgen(constructor)] - pub fn new(id: i32, data: WasmVecVecFq) -> WasmPastaFqLookupTable { - WasmPastaFqLookupTable { id, data } - } -} - -// Runtime table config - -#[wasm_bindgen] -pub struct WasmPastaFqRuntimeTableCfg { - #[wasm_bindgen(skip)] - pub id: i32, - #[wasm_bindgen(skip)] - pub first_column: WasmFlatVector, -} - -impl From for RuntimeTableCfg { - fn from(wasm_rt_cfg: WasmPastaFqRuntimeTableCfg) -> Self { - Self { - id: wasm_rt_cfg.id, - first_column: wasm_rt_cfg - .first_column - .into_iter() - .map(Into::into) - .collect(), - } - } -} - -// JS constructor for js/bindings.js -#[wasm_bindgen] -impl WasmPastaFqRuntimeTableCfg { - #[wasm_bindgen(constructor)] - pub fn new(id: i32, first_column: WasmFlatVector) -> Self { - Self { id, first_column } - } -} +pub struct WasmPastaFqPlonkIndex(#[wasm_bindgen(skip)] pub Box>); // // CamlPastaFqPlonkIndex methods // -// Change js/web/worker-spec.js accordingly #[wasm_bindgen] pub fn caml_pasta_fq_plonk_index_create( gates: &WasmGateVector, public_: i32, - lookup_tables: WasmVector, - runtime_table_cfgs: WasmVector, prev_challenges: i32, srs: &WasmSrs, ) -> Result { @@ -115,22 +46,10 @@ pub fn caml_pasta_fq_plonk_index_create( }) .collect(); - let rust_runtime_table_cfgs: Vec> = - runtime_table_cfgs.into_iter().map(Into::into).collect(); - - let rust_lookup_tables: Vec> = - lookup_tables.into_iter().map(Into::into).collect(); - // create constraint system let cs = match ConstraintSystem::::create(gates) .public(public_ as usize) .prev_challenges(prev_challenges as usize) - .lookup(rust_lookup_tables) - .runtime(if rust_runtime_table_cfgs.is_empty() { - None - } else { - Some(rust_runtime_table_cfgs) - }) .build() { Err(_) => { @@ -149,8 +68,7 @@ pub fn caml_pasta_fq_plonk_index_create( ptr.add_lagrange_basis(cs.domain.d1); } - let mut index = - ProverIndex::>::create(cs, endo_q, srs.0.clone()); + let mut index = ProverIndex::::create(cs, endo_q, srs.0.clone()); // Compute and cache the verifier index digest index.compute_verifier_index_digest::>(); @@ -189,36 +107,6 @@ pub fn caml_pasta_fq_plonk_index_domain_d8_size(index: &WasmPastaFqPlonkIndex) - index.0.cs.domain.d8.size() as i32 } -#[wasm_bindgen] -pub fn caml_pasta_fq_plonk_index_decode( - bytes: &[u8], - srs: &WasmSrs, -) -> Result { - let mut deserializer = rmp_serde::Deserializer::new(bytes); - let mut index = - ProverIndex::>::deserialize(&mut deserializer) - .map_err(|e| JsError::new(&format!("caml_pasta_fq_plonk_index_decode: {}", e)))?; - - index.srs = srs.0.clone(); - let (linearization, powers_of_alpha) = - expr_linearization(Some(&index.cs.feature_flags), true, 3); - index.linearization = linearization; - index.powers_of_alpha = powers_of_alpha; - - Ok(WasmPastaFqPlonkIndex(Box::new(index))) -} - -#[wasm_bindgen] -pub fn caml_pasta_fq_plonk_index_encode(index: &WasmPastaFqPlonkIndex) -> Result, JsError> { - let mut buffer = Vec::new(); - let mut serializer = rmp_serde::Serializer::new(&mut buffer); - index - .0 - .serialize(&mut serializer) - .map_err(|e| JsError::new(&format!("caml_pasta_fq_plonk_index_encode: {}", e)))?; - Ok(buffer) -} - #[wasm_bindgen] pub fn caml_pasta_fq_plonk_index_read( offset: Option, @@ -239,12 +127,10 @@ pub fn caml_pasta_fq_plonk_index_read( } // deserialize the index - let mut t = ProverIndex::>::deserialize( - &mut rmp_serde::Deserializer::new(r), - ) - .map_err(|err| JsValue::from_str(&format!("caml_pasta_fq_plonk_index_read: {err}")))?; + let mut t = ProverIndex::::deserialize(&mut rmp_serde::Deserializer::new(r)) + .map_err(|err| JsValue::from_str(&format!("caml_pasta_fq_plonk_index_read: {err}")))?; t.srs = srs.0.clone(); - let (linearization, powers_of_alpha) = expr_linearization(Some(&t.cs.feature_flags), true, 3); + let (linearization, powers_of_alpha) = expr_linearization(Some(&t.cs.feature_flags), true); t.linearization = linearization; t.powers_of_alpha = powers_of_alpha; diff --git a/src/lib/crypto/kimchi_bindings/wasm/src/plonk_proof.rs b/src/lib/crypto/kimchi_bindings/wasm/src/plonk_proof.rs index d035816288d4..8ce1f8869d07 100644 --- a/src/lib/crypto/kimchi_bindings/wasm/src/plonk_proof.rs +++ b/src/lib/crypto/kimchi_bindings/wasm/src/plonk_proof.rs @@ -1,15 +1,12 @@ // use kimchi::circuits::expr::{Linearization, PolishToken, Variable, Column}; // use kimchi::circuits::gate::{GateType, CurrOrNext}; use crate::wasm_flat_vector::WasmFlatVector; -use crate::wasm_vector::fp::WasmVecVecFp; -use crate::wasm_vector::fq::WasmVecVecFq; use crate::wasm_vector::WasmVector; use paste::paste; use std::convert::TryInto; use wasm_bindgen::prelude::*; // use std::sync::Arc; // use poly_commitment::srs::SRS; -use kimchi::circuits::lookup::runtime_tables::RuntimeTable; // use kimchi::index::{expr_linearization, VerifierIndex as DlogVerifierIndex}; // use ark_poly::{EvaluationDomain, Radix2EvaluationDomain as Domain}; use ark_ec::AffineCurve; @@ -58,9 +55,35 @@ macro_rules! impl_proof { $WasmVerifierIndex: ty, $field_name: ident ) => { + paste! { + #[wasm_bindgen] + pub struct [](Vec>); type WasmVecVecF = []; + #[wasm_bindgen] + impl [] { + #[wasm_bindgen(constructor)] + pub fn create(n: i32) -> Self { + [](Vec::with_capacity(n as usize)) + } + + #[wasm_bindgen] + pub fn push(&mut self, x: WasmFlatVector<$WasmF>) { + self.0.push(x.into_iter().map(Into::into).collect()) + } + + #[wasm_bindgen] + pub fn get(&self, i: i32) -> WasmFlatVector<$WasmF> { + self.0[i as usize].clone().into_iter().map(Into::into).collect() + } + + #[wasm_bindgen] + pub fn set(&mut self, i: i32, x: WasmFlatVector<$WasmF>) { + self.0[i as usize] = x.into_iter().map(Into::into).collect() + } + } + #[derive(Clone)] pub struct []( ProofEvaluations>> @@ -228,7 +251,7 @@ macro_rules! impl_proof { #[wasm_bindgen(skip)] pub t_comm: $WasmPolyComm, #[wasm_bindgen(skip)] - pub lookup: Option, + pub lookup: Option } type WasmProverCommitments = []; @@ -287,7 +310,7 @@ macro_rules! impl_proof { w_comm: x.w_comm.iter().map(Into::into).collect(), z_comm: x.z_comm.clone().into(), t_comm: x.t_comm.clone().into(), - lookup: x.lookup.clone().map(Into::into) + lookup: x.lookup.clone().map(Into::into), } } } @@ -461,8 +484,8 @@ macro_rules! impl_proof { } type WasmProverProof = []; - impl From<(&ProverProof<$G, OpeningProof<$G>>, &Vec<$F>)> for WasmProverProof { - fn from((x, public): (&ProverProof<$G, OpeningProof<$G>>, &Vec<$F>)) -> Self { + impl From<(&ProverProof<$G>, &Vec<$F>)> for WasmProverProof { + fn from((x, public): (&ProverProof<$G>, &Vec<$F>)) -> Self { let (scalars, comms) = x.prev_challenges .iter() @@ -482,8 +505,8 @@ macro_rules! impl_proof { } } - impl From<(ProverProof<$G, OpeningProof<$G>>, Vec<$F>)> for WasmProverProof { - fn from((x, public): (ProverProof<$G, OpeningProof<$G>>, Vec<$F>)) -> Self { + impl From<(ProverProof<$G>, Vec<$F>)> for WasmProverProof { + fn from((x, public): (ProverProof<$G>, Vec<$F>)) -> Self { let ProverProof {ft_eval1, commitments, proof, evals , prev_challenges} = x; let (scalars, comms) = prev_challenges @@ -502,7 +525,7 @@ macro_rules! impl_proof { } } - impl From<&WasmProverProof> for (ProverProof<$G, OpeningProof<$G>>, Vec<$F>) { + impl From<&WasmProverProof> for (ProverProof<$G>, Vec<$F>) { fn from(x: &WasmProverProof) -> Self { let proof = ProverProof { commitments: x.commitments.clone().into(), @@ -526,7 +549,7 @@ macro_rules! impl_proof { } } - impl From for (ProverProof<$G, OpeningProof<$G>>, Vec<$F>) { + impl From for (ProverProof<$G>, Vec<$F>) { fn from(x: WasmProverProof) -> Self { let proof =ProverProof { commitments: x.commitments.into(), @@ -630,35 +653,10 @@ macro_rules! impl_proof { } } - #[wasm_bindgen] - pub struct [] { - id: i32, - data: WasmFlatVector<$WasmF> - } - type WasmRuntimeTable = []; - - #[wasm_bindgen] - impl [] { - #[wasm_bindgen(constructor)] - pub fn new(id: i32, data: WasmFlatVector<$WasmF>) -> WasmRuntimeTable { - WasmRuntimeTable {id, data} - } - } - - impl From<[]> for RuntimeTable<$F> { - fn from(wasm_rt: WasmRuntimeTable) -> RuntimeTable<$F> { - RuntimeTable { - id: wasm_rt.id.into(), - data: wasm_rt.data.into_iter().map(Into::into).collect() - } - } - } - #[wasm_bindgen] pub fn [<$name:snake _create>]( index: &$WasmIndex, witness: WasmVecVecF, - wasm_runtime_tables: WasmVector, prev_challenges: WasmFlatVector<$WasmF>, prev_sgs: WasmVector<$WasmG>, ) -> Result { @@ -694,13 +692,11 @@ macro_rules! impl_proof { } }; - let rust_runtime_tables: Vec> = wasm_runtime_tables.into_iter().map(Into::into).collect(); - let witness: [Vec<_>; COLUMNS] = witness.0 .try_into() .expect("the witness should be a column of 15 vectors"); - let index: &ProverIndex<$G, OpeningProof<$G>> = &index.0.as_ref(); + let index: &ProverIndex<$G> = &index.0.as_ref(); let public_input = witness[0][0..index.cs.public].to_vec(); @@ -709,7 +705,7 @@ macro_rules! impl_proof { let maybe_proof = ProverProof::create_recursive::< DefaultFqSponge<_, PlonkSpongeConstantsKimchi>, DefaultFrSponge<_, PlonkSpongeConstantsKimchi>, - >(&group_map, witness, &rust_runtime_tables, index, prev, None); + >(&group_map, witness, &[], index, prev, None); (maybe_proof, public_input) }); @@ -732,7 +728,6 @@ macro_rules! impl_proof { $G, DefaultFqSponge<_, PlonkSpongeConstantsKimchi>, DefaultFrSponge<_, PlonkSpongeConstantsKimchi>, - OpeningProof<$G> >( &group_map, &[Context { verifier_index, proof, public_input }] @@ -774,7 +769,6 @@ macro_rules! impl_proof { $G, DefaultFqSponge<_, PlonkSpongeConstantsKimchi>, DefaultFrSponge<_, PlonkSpongeConstantsKimchi>, - OpeningProof<$G> >(&group_map, &ts) .is_ok() }) @@ -834,7 +828,6 @@ macro_rules! impl_proof { lookup_gate_lookup_selector: None, range_check_lookup_selector: None, foreign_field_mul_lookup_selector: None, - public: None, }; let dlogproof = ProverProof { diff --git a/src/lib/crypto/kimchi_bindings/wasm/src/plonk_verifier_index.rs b/src/lib/crypto/kimchi_bindings/wasm/src/plonk_verifier_index.rs index 7bdf8d2a4010..9ae817de6218 100644 --- a/src/lib/crypto/kimchi_bindings/wasm/src/plonk_verifier_index.rs +++ b/src/lib/crypto/kimchi_bindings/wasm/src/plonk_verifier_index.rs @@ -7,15 +7,15 @@ use kimchi::circuits::{ constraints::FeatureFlags, lookup::index::LookupSelectors, lookup::lookups::{LookupFeatures, LookupInfo, LookupPatterns}, - polynomials::permutation::{permutation_vanishing_polynomial, zk_w, Shifts}, + polynomials::permutation::Shifts, + polynomials::permutation::{zk_polynomial, zk_w3}, wires::{COLUMNS, PERMUTS}, }; use kimchi::linearization::expr_linearization; -use kimchi::poly_commitment::evaluation_proof::OpeningProof; use kimchi::verifier_index::{LookupVerifierIndex, VerifierIndex as DlogVerifierIndex}; use paste::paste; -use poly_commitment::commitment::PolyComm; use poly_commitment::srs::SRS; +use poly_commitment::commitment::PolyComm; use std::path::Path; use std::sync::Arc; use wasm_bindgen::prelude::*; @@ -71,26 +71,11 @@ macro_rules! impl_verification_key { pub emul_comm: $WasmPolyComm, #[wasm_bindgen(skip)] pub endomul_scalar_comm: $WasmPolyComm, - #[wasm_bindgen(skip)] - pub xor_comm: Option<$WasmPolyComm>, - #[wasm_bindgen(skip)] - pub range_check0_comm: Option<$WasmPolyComm>, - #[wasm_bindgen(skip)] - pub range_check1_comm: Option<$WasmPolyComm>, - #[wasm_bindgen(skip)] - pub foreign_field_add_comm: Option<$WasmPolyComm>, - #[wasm_bindgen(skip)] - pub foreign_field_mul_comm: Option<$WasmPolyComm>, - #[wasm_bindgen(skip)] - pub rot_comm: Option<$WasmPolyComm> } - type WasmPlonkVerificationEvals = []; - #[wasm_bindgen] impl [] { - #[allow(clippy::too_many_arguments)] #[wasm_bindgen(constructor)] pub fn new( sigma_comm: WasmVector<$WasmPolyComm>, @@ -101,12 +86,6 @@ macro_rules! impl_verification_key { mul_comm: &$WasmPolyComm, emul_comm: &$WasmPolyComm, endomul_scalar_comm: &$WasmPolyComm, - xor_comm: Option<$WasmPolyComm>, - range_check0_comm: Option<$WasmPolyComm>, - range_check1_comm: Option<$WasmPolyComm>, - foreign_field_add_comm: Option<$WasmPolyComm>, - foreign_field_mul_comm: Option<$WasmPolyComm>, - rot_comm: Option<$WasmPolyComm>, ) -> Self { WasmPlonkVerificationEvals { sigma_comm: sigma_comm.clone(), @@ -117,12 +96,6 @@ macro_rules! impl_verification_key { mul_comm: mul_comm.clone(), emul_comm: emul_comm.clone(), endomul_scalar_comm: endomul_scalar_comm.clone(), - xor_comm: xor_comm.clone(), - range_check0_comm: range_check0_comm.clone(), - range_check1_comm: range_check1_comm.clone(), - foreign_field_mul_comm: foreign_field_mul_comm.clone(), - foreign_field_add_comm: foreign_field_add_comm.clone(), - rot_comm: rot_comm.clone(), } } @@ -205,67 +178,6 @@ macro_rules! impl_verification_key { pub fn set_endomul_scalar_comm(&mut self, x: $WasmPolyComm) { self.endomul_scalar_comm = x; } - - #[wasm_bindgen(getter)] - pub fn xor_comm(&self) -> Option<$WasmPolyComm> { - self.xor_comm.clone() - } - - #[wasm_bindgen(setter)] - pub fn set_xor_comm(&mut self, x: Option<$WasmPolyComm>) { - self.xor_comm = x; - } - - #[wasm_bindgen(getter)] - pub fn rot_comm(&self) -> Option<$WasmPolyComm> { - self.rot_comm.clone() - } - - #[wasm_bindgen(setter)] - pub fn set_rot_comm(&mut self, x: Option<$WasmPolyComm>) { - self.rot_comm = x; - } - - #[wasm_bindgen(getter)] - pub fn range_check0_comm(&self) -> Option<$WasmPolyComm> { - self.range_check0_comm.clone() - } - - #[wasm_bindgen(setter)] - pub fn set_range_check0_comm(&mut self, x: Option<$WasmPolyComm>) { - self.range_check0_comm = x; - } - - #[wasm_bindgen(getter)] - pub fn range_check1_comm(&self) -> Option<$WasmPolyComm> { - self.range_check1_comm.clone() - } - - #[wasm_bindgen(setter)] - pub fn set_range_check1_comm(&mut self, x: Option<$WasmPolyComm>) { - self.range_check1_comm = x; - } - - #[wasm_bindgen(getter)] - pub fn foreign_field_add_comm(&self) -> Option<$WasmPolyComm> { - self.foreign_field_add_comm.clone() - } - - #[wasm_bindgen(setter)] - pub fn set_foreign_field_add_comm(&mut self, x: Option<$WasmPolyComm>) { - self.foreign_field_add_comm = x; - } - - #[wasm_bindgen(getter)] - pub fn foreign_field_mul_comm(&self) -> Option<$WasmPolyComm> { - self.foreign_field_mul_comm.clone() - } - - #[wasm_bindgen(setter)] - pub fn set_foreign_field_mul_comm(&mut self, x: Option<$WasmPolyComm>) { - self.foreign_field_mul_comm = x; - } - } #[derive(Clone, Copy)] @@ -498,7 +410,7 @@ macro_rules! impl_verification_key { lookup_table: WasmVector<$WasmPolyComm>, lookup_selectors: WasmLookupSelectors, table_ids: Option<$WasmPolyComm>, - lookup_info: &LookupInfo, + lookup_info: LookupInfo, runtime_tables_selector: Option<$WasmPolyComm> ) -> WasmLookupVerifierIndex { WasmLookupVerifierIndex { @@ -506,7 +418,7 @@ macro_rules! impl_verification_key { lookup_table, lookup_selectors, table_ids, - lookup_info: lookup_info.clone(), + lookup_info, runtime_tables_selector } } @@ -541,16 +453,6 @@ macro_rules! impl_verification_key { self.table_ids = x } - #[wasm_bindgen(getter)] - pub fn lookup_info(&self) -> LookupInfo { - self.lookup_info.clone() - } - - #[wasm_bindgen(setter)] - pub fn set_lookup_info(&mut self, x: LookupInfo) { - self.lookup_info = x - } - #[wasm_bindgen(getter)] pub fn runtime_tables_selector(&self) -> Option<$WasmPolyComm> { self.runtime_tables_selector.clone() @@ -637,7 +539,7 @@ macro_rules! impl_verification_key { pub fn to_wasm<'a>( srs: &Arc>, - vi: DlogVerifierIndex<$G, OpeningProof<$G>>, + vi: DlogVerifierIndex<$G>, ) -> WasmPlonkVerifierIndex { WasmPlonkVerifierIndex { domain: WasmDomain { @@ -657,12 +559,6 @@ macro_rules! impl_verification_key { mul_comm: vi.mul_comm.into(), emul_comm: vi.emul_comm.into(), endomul_scalar_comm: vi.endomul_scalar_comm.into(), - xor_comm: vi.xor_comm.map(|v| v.into()), - range_check0_comm: vi.range_check0_comm.map(|v| v.into()), - range_check1_comm: vi.range_check1_comm.map(|v| v.into()), - foreign_field_add_comm: vi.foreign_field_add_comm.map(|v| v.into()), - foreign_field_mul_comm: vi.foreign_field_mul_comm.map(|v| v.into()), - rot_comm: vi.rot_comm.map(|v| v.into()) }, shifts: WasmShifts { @@ -713,54 +609,15 @@ macro_rules! impl_verification_key { } } */ - fn compute_feature_flags(index: &WasmPlonkVerifierIndex) -> FeatureFlags { - let xor = index.evals.xor_comm.is_some(); - let range_check0 = index.evals.range_check0_comm.is_some(); - let range_check1 = index.evals.range_check1_comm.is_some(); - let foreign_field_add = index.evals.foreign_field_add_comm.is_some(); - let foreign_field_mul = index.evals.foreign_field_mul_comm.is_some(); - let rot = index.evals.rot_comm.is_some(); - - let lookup = index - .lookup_index.as_ref() - .map_or(false, |li| li.lookup_info.features.patterns.lookup); - - // TODO - let runtime_tables = false; - - let patterns = LookupPatterns { - xor, - lookup, - range_check: range_check0 || range_check1 || rot, - foreign_field_mul: foreign_field_mul, - }; - - FeatureFlags { - range_check0, - range_check1, - foreign_field_add, - foreign_field_mul, - xor, - rot, - lookup_features: LookupFeatures { - patterns, - joint_lookup_used: patterns.joint_lookups_used(), - uses_runtime_tables: runtime_tables, - }, - } - } - pub fn of_wasm( - index: WasmPlonkVerifierIndex, - ) -> (DlogVerifierIndex>, Arc>) { - let max_poly_size = index.max_poly_size; - let public_ = index.public_; - let prev_challenges = index.prev_challenges; - let log_size_of_group = index.domain.log_size_of_group; - let srs = &index.srs; - let evals = &index.evals; - let shifts = &index.shifts; - + max_poly_size: i32, + public_: i32, + prev_challenges: i32, + log_size_of_group: i32, + srs: &$WasmSrs, + evals: &WasmPlonkVerificationEvals, + shifts: &WasmShifts, + ) -> (DlogVerifierIndex, Arc>) { /* let urs_copy = Rc::clone(&*urs); let urs_copy_outer = Rc::clone(&*urs); @@ -772,8 +629,27 @@ macro_rules! impl_verification_key { let (endo_q, _endo_r) = poly_commitment::srs::endos::<$GOther>(); let domain = Domain::<$F>::new(1 << log_size_of_group).unwrap(); - let feature_flags = compute_feature_flags(&index); - let (linearization, powers_of_alpha) = expr_linearization(Some(&feature_flags), true, 3); + let feature_flags = + FeatureFlags { + range_check0: false, + range_check1: false, + foreign_field_add: false, + foreign_field_mul: false, + rot: false, + xor: false, + lookup_features: + LookupFeatures { + patterns: LookupPatterns { + xor: false, + lookup: false, + range_check: false, + foreign_field_mul: false, }, + joint_lookup_used:false, + uses_runtime_tables: false, + }, + }; + + let (linearization, powers_of_alpha) = expr_linearization(Some(&feature_flags), true); let index = DlogVerifierIndex { @@ -790,25 +666,26 @@ macro_rules! impl_verification_key { emul_comm: (&evals.emul_comm).into(), endomul_scalar_comm: (&evals.endomul_scalar_comm).into(), - xor_comm: (&evals.xor_comm).as_ref().map(Into::into), - range_check0_comm: (&evals.range_check0_comm).as_ref().map(Into::into), - range_check1_comm: (&evals.range_check1_comm).as_ref().map(Into::into), - foreign_field_add_comm: (&evals.foreign_field_add_comm).as_ref().map(Into::into), - foreign_field_mul_comm: (&evals.foreign_field_mul_comm).as_ref().map(Into::into), - rot_comm: (&evals.rot_comm).as_ref().map(Into::into), + // TODO + range_check0_comm: None, + range_check1_comm: None, + foreign_field_add_comm: None, + foreign_field_mul_comm: None, + rot_comm: None, + xor_comm: None, w: { let res = once_cell::sync::OnceCell::new(); - res.set(zk_w(domain, 3)).unwrap(); + res.set(zk_w3(domain)).unwrap(); res }, endo: endo_q, max_poly_size: max_poly_size as usize, public: public_ as usize, prev_challenges: prev_challenges as usize, - permutation_vanishing_polynomial_m: { + zkpm: { let res = once_cell::sync::OnceCell::new(); - res.set(permutation_vanishing_polynomial(domain, 3)).unwrap(); + res.set(zk_polynomial(domain)).unwrap(); res }, shift: [ @@ -821,21 +698,30 @@ macro_rules! impl_verification_key { shifts.s6.into() ], srs: { - Arc::clone(&srs.0) + let res = once_cell::sync::OnceCell::new(); + res.set(srs.0.clone()).unwrap(); + res }, - - zk_rows: 3, - linearization, powers_of_alpha, - lookup_index: index.lookup_index.map(Into::into), + // TODO + lookup_index: None, }; (index, srs.0.clone()) } - impl From for DlogVerifierIndex<$G, OpeningProof<$G>> { + impl From for DlogVerifierIndex<$G> { fn from(index: WasmPlonkVerifierIndex) -> Self { - of_wasm(index).0 + of_wasm( + index.max_poly_size, + index.public_, + index.prev_challenges, + index.domain.log_size_of_group, + &index.srs, + &index.evals, + &index.shifts, + ) + .0 } } @@ -843,11 +729,11 @@ macro_rules! impl_verification_key { offset: Option, srs: &$WasmSrs, path: String, - ) -> Result>, JsValue> { + ) -> Result, JsValue> { let path = Path::new(&path); let (endo_q, _endo_r) = poly_commitment::srs::endos::(); - DlogVerifierIndex::<$G, OpeningProof<$G>>::from_file( - srs.0.clone(), + DlogVerifierIndex::<$G>::from_file( + Some(srs.0.clone()), path, offset.map(|x| x as u64), endo_q, @@ -870,7 +756,7 @@ macro_rules! impl_verification_key { index: WasmPlonkVerifierIndex, path: String, ) -> Result<(), JsValue> { - let index: DlogVerifierIndex<$G, OpeningProof<$G>> = index.into(); + let index: DlogVerifierIndex<$G> = index.into(); let path = Path::new(&path); index.to_file(path, append).map_err(|e| { println!("{}", e); @@ -902,7 +788,7 @@ macro_rules! impl_verification_key { pub fn [<$name:snake _serialize>]( index: WasmPlonkVerifierIndex, ) -> String { - let index: DlogVerifierIndex<$G, OpeningProof<$G>> = index.into(); + let index: DlogVerifierIndex<$G> = index.into(); serde_json::to_string(&index).unwrap() } @@ -910,12 +796,9 @@ macro_rules! impl_verification_key { pub fn [<$name:snake _deserialize>]( srs: &$WasmSrs, index: String, - ) -> Result { - let vi: Result>, serde_json::Error> = serde_json::from_str(&index); - match vi { - Ok(vi) => Ok(to_wasm(srs, vi)), - Err(e) => Err(JsError::new(&(e.to_string()))), - } + ) -> WasmPlonkVerifierIndex { + let vi: DlogVerifierIndex<$G> = serde_json::from_str(&index).unwrap(); + return to_wasm(srs, vi.into()) } #[wasm_bindgen] @@ -978,12 +861,6 @@ macro_rules! impl_verification_key { mul_comm: comm(), emul_comm: comm(), endomul_scalar_comm: comm(), - xor_comm: None, - range_check0_comm: None, - range_check1_comm: None, - foreign_field_add_comm: None, - foreign_field_mul_comm: None, - rot_comm: None, }, shifts: WasmShifts { @@ -995,7 +872,7 @@ macro_rules! impl_verification_key { s5: $F::one().into(), s6: $F::one().into(), }, - lookup_index: None + lookup_index: None, } } diff --git a/src/lib/crypto/kimchi_bindings/wasm/src/srs.rs b/src/lib/crypto/kimchi_bindings/wasm/src/srs.rs index 4e7699bc7654..44707dd4ed20 100644 --- a/src/lib/crypto/kimchi_bindings/wasm/src/srs.rs +++ b/src/lib/crypto/kimchi_bindings/wasm/src/srs.rs @@ -3,7 +3,6 @@ use crate::wasm_vector::WasmVector; use ark_poly::UVPolynomial; use ark_poly::{univariate::DensePolynomial, EvaluationDomain, Evaluations}; use paste::paste; -use poly_commitment::SRS as ISRS; use poly_commitment::{commitment::b_poly_coefficients, srs::SRS}; use serde::{Deserialize, Serialize}; use std::ops::Deref; @@ -22,6 +21,7 @@ macro_rules! impl_srs { $G: ty, $WasmPolyComm: ty, $field_name: ident) => { + paste! { #[wasm_bindgen] #[derive(Clone)] @@ -75,12 +75,10 @@ macro_rules! impl_srs { srs: &[], log2_size: i32, ) { - crate::rayon::run_in_pool(|| { - let ptr: &mut poly_commitment::srs::SRS<$G> = - unsafe { &mut *(std::sync::Arc::as_ptr(&srs) as *mut _) }; - let domain = EvaluationDomain::<$F>::new(1 << (log2_size as usize)).expect("invalid domain size"); - ptr.add_lagrange_basis(domain); - }); + let ptr: &mut poly_commitment::srs::SRS<$G> = + unsafe { &mut *(std::sync::Arc::as_ptr(&srs) as *mut _) }; + let domain = EvaluationDomain::<$F>::new(1 << (log2_size as usize)).expect("invalid domain size"); + ptr.add_lagrange_basis(domain); } #[wasm_bindgen] @@ -159,7 +157,7 @@ macro_rules! impl_srs { let evals = evals.into_iter().map(Into::into).collect(); let p = Evaluations::<$F>::from_vec_and_domain(evals, x_domain).interpolate(); - Ok(srs.commit_non_hiding(&p, 1, None).into()) + Ok(srs.commit_non_hiding(&p, None).into()) } #[wasm_bindgen] @@ -171,7 +169,7 @@ macro_rules! impl_srs { let chals: Vec<$F> = chals.into_iter().map(Into::into).collect(); let coeffs = b_poly_coefficients(&chals); let p = DensePolynomial::<$F>::from_coefficients_vec(coeffs); - srs.commit_non_hiding(&p, 1, None) + srs.commit_non_hiding(&p, None) }); Ok(result.into()) } @@ -215,171 +213,35 @@ macro_rules! impl_srs { // pub mod fp { - use std::collections::HashMap; - use super::*; - use crate::arkworks::{WasmGVesta as WasmG, WasmPastaFp}; + use crate::arkworks::{WasmGVesta, WasmPastaFp}; use crate::poly_comm::vesta::WasmFpPolyComm as WasmPolyComm; - use mina_curves::pasta::{Fp, Vesta as G}; - use poly_commitment::PolyComm; - - impl_srs!(caml_fp_srs, WasmPastaFp, WasmG, Fp, G, WasmPolyComm, Fp); - - #[wasm_bindgen] - pub fn caml_fp_srs_create_parallel(depth: i32) -> WasmFpSrs { - crate::rayon::run_in_pool(|| Arc::new(SRS::::create_parallel(depth as usize)).into()) - } - - // return the cloned srs in a form that we can store on the js side - #[wasm_bindgen] - pub fn caml_fp_srs_get(srs: &WasmFpSrs) -> WasmVector { - // return a vector which consists of h, then all the gs - let mut h_and_gs: Vec = vec![srs.0.h.clone().into()]; - h_and_gs.extend(srs.0.g.iter().map(|x: &G| WasmG::from(x.clone()))); - h_and_gs.into() - } - - // set the srs from a vector of h and gs - #[wasm_bindgen] - pub fn caml_fp_srs_set(h_and_gs: WasmVector) -> WasmFpSrs { - // return a vector which consists of h, then all the gs - let mut h_and_gs: Vec = h_and_gs.into_iter().map(|x| x.into()).collect(); - let h = h_and_gs.remove(0); - let g = h_and_gs; - let srs = SRS:: { - h, - g, - lagrange_bases: HashMap::new(), - }; - Arc::new(srs).into() - } - - // maybe get lagrange commitment - #[wasm_bindgen] - pub fn caml_fp_srs_maybe_lagrange_commitment( - srs: &WasmFpSrs, - domain_size: i32, - i: i32, - ) -> Option { - let bases = srs.0.lagrange_bases.get(&(domain_size as usize)); - bases.map(|bases| bases[i as usize].clone().into()) - } - - // set entire lagrange basis from input - #[wasm_bindgen] - pub fn caml_fp_srs_set_lagrange_basis( - srs: &WasmFpSrs, - domain_size: i32, - input_bases: WasmVector, - ) { - let bases: Vec> = input_bases.into_iter().map(Into::into).collect(); - - // add to srs - let ptr: &mut poly_commitment::srs::SRS = - unsafe { &mut *(std::sync::Arc::as_ptr(&srs) as *mut _) }; - ptr.lagrange_bases.insert(domain_size as usize, bases); - } - - // compute & add lagrange basis internally, return the entire basis - #[wasm_bindgen] - pub fn caml_fp_srs_get_lagrange_basis( - srs: &WasmFpSrs, - domain_size: i32, - ) -> WasmVector { - // compute lagrange basis - crate::rayon::run_in_pool(|| { - let ptr: &mut poly_commitment::srs::SRS = - unsafe { &mut *(std::sync::Arc::as_ptr(&srs) as *mut _) }; - let domain = - EvaluationDomain::::new(domain_size as usize).expect("invalid domain size"); - ptr.add_lagrange_basis(domain); - }); - let bases = &srs.0.lagrange_bases[&(domain_size as usize)]; - bases.into_iter().map(Into::into).collect() - } + use mina_curves::pasta::{Fp, Vesta}; + + impl_srs!( + caml_fp_srs, + WasmPastaFp, + WasmGVesta, + Fp, + Vesta, + WasmPolyComm, + Fp + ); } pub mod fq { - use std::collections::HashMap; - use super::*; - use crate::arkworks::{WasmGPallas as WasmG, WasmPastaFq}; + use crate::arkworks::{WasmGPallas, WasmPastaFq}; use crate::poly_comm::pallas::WasmFqPolyComm as WasmPolyComm; - use mina_curves::pasta::{Fq, Pallas as G}; - use poly_commitment::PolyComm; - - impl_srs!(caml_fq_srs, WasmPastaFq, WasmG, Fq, G, WasmPolyComm, Fq); - - #[wasm_bindgen] - pub fn caml_fq_srs_create_parallel(depth: i32) -> WasmFqSrs { - crate::rayon::run_in_pool(|| Arc::new(SRS::::create_parallel(depth as usize)).into()) - } - - // return the cloned srs in a form that we can store on the js side - #[wasm_bindgen] - pub fn caml_fq_srs_get(srs: &WasmFqSrs) -> WasmVector { - // return a vector which consists of h, then all the gs - let mut h_and_gs: Vec = vec![srs.0.h.clone().into()]; - h_and_gs.extend(srs.0.g.iter().map(|x: &G| WasmG::from(x.clone()))); - h_and_gs.into() - } - - // set the srs from a vector of h and gs - #[wasm_bindgen] - pub fn caml_fq_srs_set(h_and_gs: WasmVector) -> WasmFqSrs { - // return a vector which consists of h, then all the gs - let mut h_and_gs: Vec = h_and_gs.into_iter().map(|x| x.into()).collect(); - let h = h_and_gs.remove(0); - let g = h_and_gs; - let srs = SRS:: { - h, - g, - lagrange_bases: HashMap::new(), - }; - Arc::new(srs).into() - } - - // maybe get lagrange commitment - #[wasm_bindgen] - pub fn caml_fq_srs_maybe_lagrange_commitment( - srs: &WasmFqSrs, - domain_size: i32, - i: i32, - ) -> Option { - let bases = srs.0.lagrange_bases.get(&(domain_size as usize)); - bases.map(|bases| bases[i as usize].clone().into()) - } - - // set entire lagrange basis from input - #[wasm_bindgen] - pub fn caml_fq_srs_set_lagrange_basis( - srs: &WasmFqSrs, - domain_size: i32, - input_bases: WasmVector, - ) { - let bases: Vec> = input_bases.into_iter().map(Into::into).collect(); - - // add to srs - let ptr: &mut poly_commitment::srs::SRS = - unsafe { &mut *(std::sync::Arc::as_ptr(&srs) as *mut _) }; - ptr.lagrange_bases.insert(domain_size as usize, bases); - } - - // compute & add lagrange basis internally, return the entire basis - #[wasm_bindgen] - pub fn caml_fq_srs_get_lagrange_basis( - srs: &WasmFqSrs, - domain_size: i32, - ) -> WasmVector { - // compute lagrange basis - crate::rayon::run_in_pool(|| { - let ptr: &mut poly_commitment::srs::SRS = - unsafe { &mut *(std::sync::Arc::as_ptr(&srs) as *mut _) }; - let domain = - EvaluationDomain::::new(domain_size as usize).expect("invalid domain size"); - ptr.add_lagrange_basis(domain); - }); - let bases = &srs.0.lagrange_bases[&(domain_size as usize)]; - bases.into_iter().map(Into::into).collect() - } + use mina_curves::pasta::{Fq, Pallas as GAffine}; + + impl_srs!( + caml_fq_srs, + WasmPastaFq, + WasmGPallas, + Fq, + GAffine, + WasmPolyComm, + Fq + ); } diff --git a/src/lib/crypto/kimchi_bindings/wasm/src/wasm_ocaml_serde/de.rs b/src/lib/crypto/kimchi_bindings/wasm/src/wasm_ocaml_serde/de.rs index d990e856a138..395837171129 100644 --- a/src/lib/crypto/kimchi_bindings/wasm/src/wasm_ocaml_serde/de.rs +++ b/src/lib/crypto/kimchi_bindings/wasm/src/wasm_ocaml_serde/de.rs @@ -273,9 +273,8 @@ impl<'de> de::Deserializer<'de> for Deserializer { } } - #[inline] fn is_human_readable(&self) -> bool { - false + true } } diff --git a/src/lib/crypto/kimchi_bindings/wasm/src/wasm_ocaml_serde/ser.rs b/src/lib/crypto/kimchi_bindings/wasm/src/wasm_ocaml_serde/ser.rs index ab4a4f9e95ec..5dbe8b9e9ddb 100644 --- a/src/lib/crypto/kimchi_bindings/wasm/src/wasm_ocaml_serde/ser.rs +++ b/src/lib/crypto/kimchi_bindings/wasm/src/wasm_ocaml_serde/ser.rs @@ -142,11 +142,6 @@ impl<'s> ser::Serializer for &'s Serializer { type SerializeStruct = ArraySerializer<'s>; type SerializeStructVariant = ErrorSerializer; - #[inline] - fn is_human_readable(&self) -> bool { - false - } - fn serialize_bool(self, v: bool) -> Result { if v { self.0.serialize_u32(1) diff --git a/src/lib/crypto/kimchi_bindings/wasm/src/wasm_vector.rs b/src/lib/crypto/kimchi_bindings/wasm/src/wasm_vector.rs index 2ee0f6ef27a9..f93a12476948 100644 --- a/src/lib/crypto/kimchi_bindings/wasm/src/wasm_vector.rs +++ b/src/lib/crypto/kimchi_bindings/wasm/src/wasm_vector.rs @@ -1,9 +1,7 @@ -use crate::wasm_flat_vector::WasmFlatVector; -use paste::paste; +use wasm_bindgen::convert::{FromWasmAbi, IntoWasmAbi, OptionFromWasmAbi, OptionIntoWasmAbi}; + use std::convert::From; use std::ops::Deref; -use wasm_bindgen::convert::{FromWasmAbi, IntoWasmAbi, OptionFromWasmAbi, OptionIntoWasmAbi}; -use wasm_bindgen::prelude::*; #[derive(Clone, Debug)] pub struct WasmVector(Vec); @@ -116,51 +114,3 @@ impl> OptionIntoWasmAbi for WasmVector { as OptionIntoWasmAbi>::none() } } - -macro_rules! impl_vec_vec_fp { - ( $F:ty, $WasmF:ty ) => { - paste! { - #[wasm_bindgen] - pub struct [](#[wasm_bindgen(skip)] pub Vec>); - - #[wasm_bindgen] - impl [] { - #[wasm_bindgen(constructor)] - pub fn create(n: i32) -> Self { - [](Vec::with_capacity(n as usize)) - } - - #[wasm_bindgen] - pub fn push(&mut self, x: WasmFlatVector<$WasmF>) { - self.0.push(x.into_iter().map(Into::into).collect()) - } - - #[wasm_bindgen] - pub fn get(&self, i: i32) -> WasmFlatVector<$WasmF> { - self.0[i as usize].clone().into_iter().map(Into::into).collect() - } - - #[wasm_bindgen] - pub fn set(&mut self, i: i32, x: WasmFlatVector<$WasmF>) { - self.0[i as usize] = x.into_iter().map(Into::into).collect() - } - } - } - }; -} - -pub mod fp { - use super::*; - use crate::arkworks::WasmPastaFp; - use mina_curves::pasta::Fp; - - impl_vec_vec_fp!(Fp, WasmPastaFp); -} - -pub mod fq { - use super::*; - use crate::arkworks::WasmPastaFq; - use mina_curves::pasta::Fq; - - impl_vec_vec_fp!(Fq, WasmPastaFq); -}