From 180694955f031728e196255d73df33776232b3d1 Mon Sep 17 00:00:00 2001 From: Florian Date: Wed, 5 Nov 2025 20:30:33 +0700 Subject: [PATCH 01/30] merge native/-napi --- src/lib/crypto/kimchi_bindings/js/dune | 3 +- .../js/native/native-overrides/proof.js | 31 +++++++++++++++++++ .../native/native-overrides/prover-index.js | 4 +-- .../js/native/native-overrides/srs.js | 4 +++ .../js/node_js/node_backend.js | 2 +- 5 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 src/lib/crypto/kimchi_bindings/js/native/native-overrides/proof.js diff --git a/src/lib/crypto/kimchi_bindings/js/dune b/src/lib/crypto/kimchi_bindings/js/dune index 6af252023e0a..84584c588b4e 100644 --- a/src/lib/crypto/kimchi_bindings/js/dune +++ b/src/lib/crypto/kimchi_bindings/js/dune @@ -20,7 +20,8 @@ native/native-overrides/oracles.js native/native-overrides/prover-index.js native/native-overrides/srs.js - native/native-overrides/util.js)) + native/native-overrides/util.js + native/native-overrides/proof.js)) (instrumentation (backend bisect_ppx)) (preprocess diff --git a/src/lib/crypto/kimchi_bindings/js/native/native-overrides/proof.js b/src/lib/crypto/kimchi_bindings/js/native/native-overrides/proof.js new file mode 100644 index 000000000000..782c416d69b0 --- /dev/null +++ b/src/lib/crypto/kimchi_bindings/js/native/native-overrides/proof.js @@ -0,0 +1,31 @@ +/* global plonk_wasm, tsRustConversion + */ + + +// Provides: caml_pasta_fp_plonk_proof_create +// Requires: plonk_wasm, tsRustConversion +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])); + } + 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( + index, + witness_cols, + wasm_runtime_tables, + prev_challenges, + prev_sgs + ); + return tsRustConversion.fp.proofFromRust(proof); +}; diff --git a/src/lib/crypto/kimchi_bindings/js/native/native-overrides/prover-index.js b/src/lib/crypto/kimchi_bindings/js/native/native-overrides/prover-index.js index f87b4527ed0b..d52d91a1e379 100644 --- a/src/lib/crypto/kimchi_bindings/js/native/native-overrides/prover-index.js +++ b/src/lib/crypto/kimchi_bindings/js/native/native-overrides/prover-index.js @@ -123,7 +123,7 @@ var caml_pasta_fp_plonk_index_create = function ( ); console.time("conversion") var gate_vec = plonk_wasm.caml_pasta_fp_plonk_gate_vector_from_bytes(gates.serialize()); - var urs_ser = plonk_wasm.caml_fp_srs_from_bytes(urs.serialize()) + var urs_ser = plonk_wasm.caml_fp_srs_from_bytes_external(urs.serialize()) console.timeEnd("conversion") console.time("index_create") @@ -216,7 +216,7 @@ var caml_pasta_fq_plonk_index_create = function ( console.time("conversion") var gate_vec = plonk_wasm.caml_pasta_fq_plonk_gate_vector_from_bytes(gates.serialize()); - var urs_ser = plonk_wasm.caml_fq_srs_from_bytes(urs.serialize()) + var urs_ser = plonk_wasm.caml_fq_srs_from_bytes_external(urs.serialize()) console.timeEnd("conversion") console.time("index_create") diff --git a/src/lib/crypto/kimchi_bindings/js/native/native-overrides/srs.js b/src/lib/crypto/kimchi_bindings/js/native/native-overrides/srs.js index 20d4bfaf61a5..62ef4822826b 100644 --- a/src/lib/crypto/kimchi_bindings/js/native/native-overrides/srs.js +++ b/src/lib/crypto/kimchi_bindings/js/native/native-overrides/srs.js @@ -169,10 +169,14 @@ var caml_fq_srs_commit_evaluations = function (t, domain_size, fqs) { // Requires: plonk_wasm, tsRustConversionNative var caml_fq_srs_b_poly_commitment = function (srs, chals) { console.log("native caml_fq_srs_b_poly_commitment"); + console.log("srs", srs); + console.log("chals", chals); + console.log("conv", tsRustConversionNative.fq.vectorToRust(chals)) var res = plonk_wasm.caml_fq_srs_b_poly_commitment( srs, tsRustConversionNative.fq.vectorToRust(chals) ); + console.log("res", res); return tsRustConversionNative.fq.polyCommFromRust(res); }; diff --git a/src/lib/crypto/kimchi_bindings/js/node_js/node_backend.js b/src/lib/crypto/kimchi_bindings/js/node_js/node_backend.js index 87b70eec4773..e5500b9d811e 100644 --- a/src/lib/crypto/kimchi_bindings/js/node_js/node_backend.js +++ b/src/lib/crypto/kimchi_bindings/js/node_js/node_backend.js @@ -104,4 +104,4 @@ var plonk_wasm = (function() { } } return wasm -})() +})() \ No newline at end of file From fb3788cbd95d271aa38452c8a0614e32368019a8 Mon Sep 17 00:00:00 2001 From: Florian Date: Sun, 9 Nov 2025 13:10:48 +0700 Subject: [PATCH 02/30] Update proof-systems --- src/lib/crypto/proof-systems | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/crypto/proof-systems b/src/lib/crypto/proof-systems index 4f80d3cecc36..b42113c16e77 160000 --- a/src/lib/crypto/proof-systems +++ b/src/lib/crypto/proof-systems @@ -1 +1 @@ -Subproject commit 4f80d3cecc361686b2f48fbadded2dceb0e9a1c1 +Subproject commit b42113c16e7787d27c099bf91fdad44afffc04e8 From 637e59b8720ccc00c383658cfa8c869b8a350fb1 Mon Sep 17 00:00:00 2001 From: Florian Date: Sun, 9 Nov 2025 13:11:25 +0700 Subject: [PATCH 03/30] Update proof-systems --- src/lib/crypto/proof-systems | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/crypto/proof-systems b/src/lib/crypto/proof-systems index b42113c16e77..597d69eb46bf 160000 --- a/src/lib/crypto/proof-systems +++ b/src/lib/crypto/proof-systems @@ -1 +1 @@ -Subproject commit b42113c16e7787d27c099bf91fdad44afffc04e8 +Subproject commit 597d69eb46bf511e12c8208f8464c6c69bec5248 From 791b7f46f270eeea212d21e6827134307eac28ba Mon Sep 17 00:00:00 2001 From: Florian Date: Sun, 9 Nov 2025 13:34:46 +0700 Subject: [PATCH 04/30] Update proof-systems --- src/lib/crypto/proof-systems | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/crypto/proof-systems b/src/lib/crypto/proof-systems index 597d69eb46bf..87adbbf23335 160000 --- a/src/lib/crypto/proof-systems +++ b/src/lib/crypto/proof-systems @@ -1 +1 @@ -Subproject commit 597d69eb46bf511e12c8208f8464c6c69bec5248 +Subproject commit 87adbbf23335cde174fe232f1aab793f0a3c3821 From 924cecfa891148abe946f55295d791ba5c0f8928 Mon Sep 17 00:00:00 2001 From: Florian Date: Mon, 10 Nov 2025 18:58:39 +0700 Subject: [PATCH 05/30] fix headet ypes --- .../crypto/kimchi_bindings/js/native/header-d.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/lib/crypto/kimchi_bindings/js/native/header-d.ts b/src/lib/crypto/kimchi_bindings/js/native/header-d.ts index 4256c45ed93d..514d01400b5b 100644 --- a/src/lib/crypto/kimchi_bindings/js/native/header-d.ts +++ b/src/lib/crypto/kimchi_bindings/js/native/header-d.ts @@ -4,6 +4,20 @@ // This file gets auto-included in the generated plonk-napi types to supplement // external pointer types. +type NapiGVesta = {}; +type NapiGPallas = {}; +type NapiPastaFpPlonkIndex = {}; +type NapiPastaFqPlonkIndex = {}; +type NapiPastaFp = {}; +type NapiPastaFq = {}; +type NapiLookupInfo = {}; +type WasmPastaFqPlonkIndex = {}; type WasmPastaFpPlonkIndex = {}; +type Proof = {} +type NapiVector = {}; +type NapiFlatVector = {}; +type WasmVecVecFq = {}; +type WasmVecVecFp = {}; +type Self = {}; // Header section end \ No newline at end of file From 459c8624f8253e328f5748ce3807f3a9fb77ce0e Mon Sep 17 00:00:00 2001 From: querolita Date: Tue, 11 Nov 2025 16:23:27 +0100 Subject: [PATCH 06/30] submodule: update proof-systems --- src/lib/crypto/proof-systems | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/crypto/proof-systems b/src/lib/crypto/proof-systems index 87adbbf23335..f43f9a41bcde 160000 --- a/src/lib/crypto/proof-systems +++ b/src/lib/crypto/proof-systems @@ -1 +1 @@ -Subproject commit 87adbbf23335cde174fe232f1aab793f0a3c3821 +Subproject commit f43f9a41bcde7e8830df4ae4b4fcaff2357422aa From 940cf319ab8fdb8d8d13a8aded7c76b384f9023c Mon Sep 17 00:00:00 2001 From: querolita Date: Wed, 12 Nov 2025 15:11:35 +0100 Subject: [PATCH 07/30] jsoo: attempt proof bindings --- .../kimchi_bindings/js/bindings/proof.js | 69 ------------------- .../js/native/native-overrides/proof.js | 60 ++++++++++++++-- .../js/node_js/node_backend.js | 4 ++ 3 files changed, 57 insertions(+), 76 deletions(-) diff --git a/src/lib/crypto/kimchi_bindings/js/bindings/proof.js b/src/lib/crypto/kimchi_bindings/js/bindings/proof.js index 9a58c242c86b..c08c48a59ea0 100644 --- a/src/lib/crypto/kimchi_bindings/js/bindings/proof.js +++ b/src/lib/crypto/kimchi_bindings/js/bindings/proof.js @@ -1,41 +1,6 @@ /* global plonk_wasm, tsRustConversion */ -// Provides: caml_pasta_fp_plonk_proof_create -// Requires: plonk_wasm, tsRustConversion -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])); - } - 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( - index, - witness_cols, - wasm_runtime_tables, - prev_challenges, - prev_sgs - ); - return tsRustConversion.fp.proofFromRust(proof); -}; - -// Provides: caml_pasta_fp_plonk_proof_verify -// Requires: plonk_wasm, tsRustConversion -var caml_pasta_fp_plonk_proof_verify = function (index, proof) { - index = tsRustConversion.fp.verifierIndexToRust(index); - proof = tsRustConversion.fp.proofToRust(proof); - return plonk_wasm.caml_pasta_fp_plonk_proof_verify(index, proof); -}; // Provides: caml_pasta_fp_plonk_proof_batch_verify // Requires: plonk_wasm, tsRustConversion @@ -69,41 +34,7 @@ var caml_pasta_fp_plonk_proof_deep_copy = function (proof) { ); }; -// Provides: caml_pasta_fq_plonk_proof_create -// Requires: plonk_wasm, tsRustConversion -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])); - } - 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( - index, - witness_cols, - wasm_runtime_tables, - prev_challenges, - prev_sgs - ); - return tsRustConversion.fq.proofFromRust(proof); -}; -// Provides: caml_pasta_fq_plonk_proof_verify -// Requires: plonk_wasm, tsRustConversion -var caml_pasta_fq_plonk_proof_verify = function (index, proof) { - index = tsRustConversion.fq.verifierIndexToRust(index); - proof = tsRustConversion.fq.proofToRust(proof); - return plonk_wasm.caml_pasta_fq_plonk_proof_verify(index, proof); -}; // Provides: caml_pasta_fq_plonk_proof_batch_verify // Requires: plonk_wasm, tsRustConversion diff --git a/src/lib/crypto/kimchi_bindings/js/native/native-overrides/proof.js b/src/lib/crypto/kimchi_bindings/js/native/native-overrides/proof.js index 782c416d69b0..d399a2c250e2 100644 --- a/src/lib/crypto/kimchi_bindings/js/native/native-overrides/proof.js +++ b/src/lib/crypto/kimchi_bindings/js/native/native-overrides/proof.js @@ -1,9 +1,9 @@ -/* global plonk_wasm, tsRustConversion +/* global plonk_wasm, tsRustConversionNative */ // Provides: caml_pasta_fp_plonk_proof_create -// Requires: plonk_wasm, tsRustConversion +// Requires: plonk_wasm, tsRustConversionNative var caml_pasta_fp_plonk_proof_create = function ( index, witness_cols, @@ -13,13 +13,13 @@ var caml_pasta_fp_plonk_proof_create = function ( ) { 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(tsRustConversionNative.fp.vectorToRust(witness_cols[i])); } witness_cols = w; - prev_challenges = tsRustConversion.fp.vectorToRust(prev_challenges); + prev_challenges = tsRustConversionNative.fp.vectorToRust(prev_challenges); var wasm_runtime_tables = - tsRustConversion.fp.runtimeTablesToRust(caml_runtime_tables); - prev_sgs = tsRustConversion.fp.pointsToRust(prev_sgs); + tsRustConversionNative.fp.runtimeTablesToRust(caml_runtime_tables); + prev_sgs = tsRustConversionNative.fp.pointsToRust(prev_sgs); var proof = plonk_wasm.caml_pasta_fp_plonk_proof_create( index, witness_cols, @@ -27,5 +27,51 @@ var caml_pasta_fp_plonk_proof_create = function ( prev_challenges, prev_sgs ); - return tsRustConversion.fp.proofFromRust(proof); + return tsRustConversionNative.fp.proofFromRust(proof); +}; + +// Provides: caml_pasta_fp_plonk_proof_verify +// Requires: plonk_wasm, tsRustConversionNative +var caml_pasta_fp_plonk_proof_verify = function (index, proof) { + index = tsRustConversionNative.fp.verifierIndexToRust(index); + proof = tsRustConversionNative.fp.proofToRust(proof); + return plonk_wasm.caml_pasta_fp_plonk_proof_verify(index, proof); +}; + + + +// Provides: caml_pasta_fq_plonk_proof_create +// Requires: plonk_wasm, tsRustConversionNative +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(tsRustConversionNative.fq.vectorToRust(witness_cols[i])); + } + witness_cols = w; + prev_challenges = tsRustConversionNative.fq.vectorToRust(prev_challenges); + var wasm_runtime_tables = + tsRustConversionNative.fq.runtimeTablesToRust(caml_runtime_tables); + prev_sgs = tsRustConversionNative.fq.pointsToRust(prev_sgs); + var proof = plonk_wasm.caml_pasta_fq_plonk_proof_create( + index, + witness_cols, + wasm_runtime_tables, + prev_challenges, + prev_sgs + ); + return tsRustConversionNative.fq.proofFromRust(proof); +}; + +// Provides: caml_pasta_fq_plonk_proof_verify +// Requires: plonk_wasm, tsRustConversionNative +var caml_pasta_fq_plonk_proof_verify = function (index, proof) { + index = tsRustConversionNative.fq.verifierIndexToRust(index); + proof = tsRustConversionNative.fq.proofToRust(proof); + return plonk_wasm.caml_pasta_fq_plonk_proof_verify(index, proof); }; diff --git a/src/lib/crypto/kimchi_bindings/js/node_js/node_backend.js b/src/lib/crypto/kimchi_bindings/js/node_js/node_backend.js index 24c05ccf48a6..49ee9e31ded1 100644 --- a/src/lib/crypto/kimchi_bindings/js/node_js/node_backend.js +++ b/src/lib/crypto/kimchi_bindings/js/node_js/node_backend.js @@ -89,6 +89,10 @@ var plonk_wasm = (function() { "WasmGVesta", "WasmPastaFp", "WasmPastaFq", + "caml_pasta_fp_plonk_proof_create", + "caml_pasta_fp_plonk_proof_verify", + "caml_pasta_fq_plonk_proof_create", + "caml_pasta_fq_plonk_proof_verify", ]; overrides.forEach(function (override) { From 2686bf16763ae989f7a06171ecee1312deb4fc84 Mon Sep 17 00:00:00 2001 From: querolita Date: Thu, 13 Nov 2025 12:43:49 +0100 Subject: [PATCH 08/30] jsoo: remove proof conversions --- .../js/native/native-overrides/proof.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/lib/crypto/kimchi_bindings/js/native/native-overrides/proof.js b/src/lib/crypto/kimchi_bindings/js/native/native-overrides/proof.js index d399a2c250e2..bd7fb911acbd 100644 --- a/src/lib/crypto/kimchi_bindings/js/native/native-overrides/proof.js +++ b/src/lib/crypto/kimchi_bindings/js/native/native-overrides/proof.js @@ -20,21 +20,21 @@ var caml_pasta_fp_plonk_proof_create = function ( var wasm_runtime_tables = tsRustConversionNative.fp.runtimeTablesToRust(caml_runtime_tables); prev_sgs = tsRustConversionNative.fp.pointsToRust(prev_sgs); - var proof = plonk_wasm.caml_pasta_fp_plonk_proof_create( + // Because proof is an external object, it does not need conversion + return plonk_wasm.caml_pasta_fp_plonk_proof_create( index, witness_cols, wasm_runtime_tables, prev_challenges, prev_sgs ); - return tsRustConversionNative.fp.proofFromRust(proof); }; // Provides: caml_pasta_fp_plonk_proof_verify // Requires: plonk_wasm, tsRustConversionNative var caml_pasta_fp_plonk_proof_verify = function (index, proof) { index = tsRustConversionNative.fp.verifierIndexToRust(index); - proof = tsRustConversionNative.fp.proofToRust(proof); + // Because proof is an external object, it does not need conversion return plonk_wasm.caml_pasta_fp_plonk_proof_verify(index, proof); }; @@ -58,20 +58,20 @@ var caml_pasta_fq_plonk_proof_create = function ( var wasm_runtime_tables = tsRustConversionNative.fq.runtimeTablesToRust(caml_runtime_tables); prev_sgs = tsRustConversionNative.fq.pointsToRust(prev_sgs); - var proof = plonk_wasm.caml_pasta_fq_plonk_proof_create( + // Because proof is an external object, it does not need conversion + return plonk_wasm.caml_pasta_fq_plonk_proof_create( index, witness_cols, wasm_runtime_tables, prev_challenges, prev_sgs ); - return tsRustConversionNative.fq.proofFromRust(proof); }; // Provides: caml_pasta_fq_plonk_proof_verify // Requires: plonk_wasm, tsRustConversionNative var caml_pasta_fq_plonk_proof_verify = function (index, proof) { index = tsRustConversionNative.fq.verifierIndexToRust(index); - proof = tsRustConversionNative.fq.proofToRust(proof); + // Because proof is an external object, it does not need conversion return plonk_wasm.caml_pasta_fq_plonk_proof_verify(index, proof); }; From cc4b4116354ff9917bd80597b3971c16199fef1b Mon Sep 17 00:00:00 2001 From: querolita Date: Thu, 13 Nov 2025 12:43:58 +0100 Subject: [PATCH 09/30] Revert "jsoo: remove proof conversions" This reverts commit 2686bf16763ae989f7a06171ecee1312deb4fc84. Because we need full access to the proof structure we cannot avoid the conversions. --- .../js/native/native-overrides/proof.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/lib/crypto/kimchi_bindings/js/native/native-overrides/proof.js b/src/lib/crypto/kimchi_bindings/js/native/native-overrides/proof.js index bd7fb911acbd..d399a2c250e2 100644 --- a/src/lib/crypto/kimchi_bindings/js/native/native-overrides/proof.js +++ b/src/lib/crypto/kimchi_bindings/js/native/native-overrides/proof.js @@ -20,21 +20,21 @@ var caml_pasta_fp_plonk_proof_create = function ( var wasm_runtime_tables = tsRustConversionNative.fp.runtimeTablesToRust(caml_runtime_tables); prev_sgs = tsRustConversionNative.fp.pointsToRust(prev_sgs); - // Because proof is an external object, it does not need conversion - return plonk_wasm.caml_pasta_fp_plonk_proof_create( + var proof = plonk_wasm.caml_pasta_fp_plonk_proof_create( index, witness_cols, wasm_runtime_tables, prev_challenges, prev_sgs ); + return tsRustConversionNative.fp.proofFromRust(proof); }; // Provides: caml_pasta_fp_plonk_proof_verify // Requires: plonk_wasm, tsRustConversionNative var caml_pasta_fp_plonk_proof_verify = function (index, proof) { index = tsRustConversionNative.fp.verifierIndexToRust(index); - // Because proof is an external object, it does not need conversion + proof = tsRustConversionNative.fp.proofToRust(proof); return plonk_wasm.caml_pasta_fp_plonk_proof_verify(index, proof); }; @@ -58,20 +58,20 @@ var caml_pasta_fq_plonk_proof_create = function ( var wasm_runtime_tables = tsRustConversionNative.fq.runtimeTablesToRust(caml_runtime_tables); prev_sgs = tsRustConversionNative.fq.pointsToRust(prev_sgs); - // Because proof is an external object, it does not need conversion - return plonk_wasm.caml_pasta_fq_plonk_proof_create( + var proof = plonk_wasm.caml_pasta_fq_plonk_proof_create( index, witness_cols, wasm_runtime_tables, prev_challenges, prev_sgs ); + return tsRustConversionNative.fq.proofFromRust(proof); }; // Provides: caml_pasta_fq_plonk_proof_verify // Requires: plonk_wasm, tsRustConversionNative var caml_pasta_fq_plonk_proof_verify = function (index, proof) { index = tsRustConversionNative.fq.verifierIndexToRust(index); - // Because proof is an external object, it does not need conversion + proof = tsRustConversionNative.fq.proofToRust(proof); return plonk_wasm.caml_pasta_fq_plonk_proof_verify(index, proof); }; From 698b18b9cc53e6db034e9d4a7e44ae691dfc0594 Mon Sep 17 00:00:00 2001 From: Florian Date: Fri, 14 Nov 2025 09:22:01 +0700 Subject: [PATCH 10/30] fix tbd --- .../js/bindings/verifier-index.js | 2 +- src/lib/crypto/kimchi_bindings/js/dune | 3 +- .../native/native-overrides/prover-index.js | 2 +- .../js/native/native-overrides/srs.js | 47 ++++++++++++++----- .../native/native-overrides/verifier-index.js | 17 +++++-- .../js/node_js/node_backend.js | 9 ++-- 6 files changed, 59 insertions(+), 21 deletions(-) diff --git a/src/lib/crypto/kimchi_bindings/js/bindings/verifier-index.js b/src/lib/crypto/kimchi_bindings/js/bindings/verifier-index.js index a14f5b773f24..756c70ff3379 100644 --- a/src/lib/crypto/kimchi_bindings/js/bindings/verifier-index.js +++ b/src/lib/crypto/kimchi_bindings/js/bindings/verifier-index.js @@ -24,7 +24,7 @@ var caml_opt_to_rust = function (caml_optional_value, to_rust) { // Provides: caml_pasta_fp_plonk_verifier_index_create // Requires: plonk_wasm, tsRustConversion var caml_pasta_fp_plonk_verifier_index_create = function (x) { - console.log("caml_pasta_fp_plonk_verifier_index_create") + console.log("caml_pasta_fp_plonk_verifier_index_create", x) var vk = plonk_wasm.caml_pasta_fp_plonk_verifier_index_create(x); return tsRustConversion.fp.verifierIndexFromRust(vk); }; diff --git a/src/lib/crypto/kimchi_bindings/js/dune b/src/lib/crypto/kimchi_bindings/js/dune index 84584c588b4e..29c5460622ce 100644 --- a/src/lib/crypto/kimchi_bindings/js/dune +++ b/src/lib/crypto/kimchi_bindings/js/dune @@ -21,7 +21,8 @@ native/native-overrides/prover-index.js native/native-overrides/srs.js native/native-overrides/util.js - native/native-overrides/proof.js)) + native/native-overrides/proof.js + native/native-overrides/verifier-index.js)) (instrumentation (backend bisect_ppx)) (preprocess diff --git a/src/lib/crypto/kimchi_bindings/js/native/native-overrides/prover-index.js b/src/lib/crypto/kimchi_bindings/js/native/native-overrides/prover-index.js index d52d91a1e379..56794d71f912 100644 --- a/src/lib/crypto/kimchi_bindings/js/native/native-overrides/prover-index.js +++ b/src/lib/crypto/kimchi_bindings/js/native/native-overrides/prover-index.js @@ -198,7 +198,7 @@ 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, tsRustConversionNative var caml_pasta_fq_plonk_index_create = function ( gates, public_inputs, diff --git a/src/lib/crypto/kimchi_bindings/js/native/native-overrides/srs.js b/src/lib/crypto/kimchi_bindings/js/native/native-overrides/srs.js index 62ef4822826b..0125d21dfa8d 100644 --- a/src/lib/crypto/kimchi_bindings/js/native/native-overrides/srs.js +++ b/src/lib/crypto/kimchi_bindings/js/native/native-overrides/srs.js @@ -1,16 +1,19 @@ /* global plonk_wasm, caml_jsstring_of_string, - tsBindings, tsRustConversion + tsBindings, tsRustConversionNative */ // Provides: tsSrs // Requires: tsBindings, plonk_wasm -var tsSrs = tsBindings.srs(plonk_wasm); +var tsSrs = tsBindings.srsNative(plonk_wasm); // srs // Provides: caml_fp_srs_create // Requires: tsSrs -var caml_fp_srs_create = tsSrs.fp.create; +var caml_fp_srs_create = function (log_size) { + console.log("native caml_fp_srs_create"); + return tsSrs.fp.create(log_size); +} // Provides: caml_fp_srs_write // Requires: plonk_wasm, caml_jsstring_of_string @@ -43,17 +46,25 @@ var caml_fp_srs_read = function (offset, path) { // Provides: caml_fp_srs_lagrange_commitments_whole_domain // Requires: tsSrs -var caml_fp_srs_lagrange_commitments_whole_domain = - tsSrs.fp.lagrangeCommitmentsWholeDomain; +var caml_fp_srs_lagrange_commitments_whole_domain = function (srs, domain_size) { + console.log("native caml_fp_srs_lagrange_commitments_whole_domain"); + return tsSrs.fp.lagrangeCommitmentsWholeDomain(srs, domain_size); +} // Provides: caml_fq_srs_lagrange_commitments_whole_domain // Requires: tsSrs var caml_fq_srs_lagrange_commitments_whole_domain = - tsSrs.fq.lagrangeCommitmentsWholeDomain; + function (srs, domain_size) { + console.log("native caml_fq_srs_lagrange_commitments_whole_domain"); + return tsSrs.fq.lagrangeCommitmentsWholeDomain(srs, domain_size); + } // Provides: caml_fp_srs_lagrange_commitment // Requires: tsSrs -var caml_fp_srs_lagrange_commitment = tsSrs.fp.lagrangeCommitment; +var caml_fp_srs_lagrange_commitment = function (srs, i) { + console.log("native caml_fp_srs_lagrange_commitment"); + return tsSrs.fp.lagrangeCommitment(srs, i); +} // Provides: caml_fp_srs_commit_evaluations // Requires: plonk_wasm, tsRustConversionNative @@ -114,11 +125,17 @@ var caml_fp_srs_h = function (t) { // Provides: caml_fp_srs_add_lagrange_basis // Requires: tsSrs -var caml_fp_srs_add_lagrange_basis = tsSrs.fp.addLagrangeBasis; +var caml_fp_srs_add_lagrange_basis = function (srs, domain_size) { + console.log("native caml_fp_srs_add_lagrange_basis"); + return tsSrs.fp.addLagrangeBasis(srs, domain_size); +}; // Provides: caml_fq_srs_create // Requires: tsSrs -var caml_fq_srs_create = tsSrs.fq.create; +var caml_fq_srs_create = function (log_size) { + console.log("native caml_fq_srs_create"); + return tsSrs.fq.create(log_size); +} // Provides: caml_fq_srs_write // Requires: plonk_wasm, caml_jsstring_of_string @@ -151,7 +168,10 @@ 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; +var caml_fq_srs_lagrange_commitment = function (srs, i) { + console.log("native caml_fq_srs_lagrange_commitment"); + return tsSrs.fq.lagrangeCommitment(srs, i); +} // Provides: caml_fq_srs_commit_evaluations // Requires: plonk_wasm, tsRustConversionNative @@ -181,7 +201,7 @@ var caml_fq_srs_b_poly_commitment = function (srs, chals) { }; // Provides: caml_fq_srs_batch_accumulator_check -// Requires: plonk_wasm, tsRustConversion +// Requires: plonk_wasm, tsRustConversionNative var caml_fq_srs_batch_accumulator_check = function (srs, comms, chals) { console.log("native caml_fq_srs_batch_accumulator_check"); var rust_comms = tsRustConversionNative.fq.pointsToRust(comms); @@ -216,4 +236,7 @@ var caml_fq_srs_h = function (t) { // Provides: caml_fq_srs_add_lagrange_basis // Requires: tsSrs -var caml_fq_srs_add_lagrange_basis = tsSrs.fq.addLagrangeBasis; +var caml_fq_srs_add_lagrange_basis = function (srs, domain_size) { + console.log("native caml_fq_srs_add_lagrange_basis"); + return tsSrs.fq.addLagrangeBasis(srs, domain_size); +}; \ No newline at end of file diff --git a/src/lib/crypto/kimchi_bindings/js/native/native-overrides/verifier-index.js b/src/lib/crypto/kimchi_bindings/js/native/native-overrides/verifier-index.js index 683751701676..1a3b01f44aab 100644 --- a/src/lib/crypto/kimchi_bindings/js/native/native-overrides/verifier-index.js +++ b/src/lib/crypto/kimchi_bindings/js/native/native-overrides/verifier-index.js @@ -4,9 +4,20 @@ // Provides: caml_pasta_fq_plonk_verifier_index_shifts // Requires: plonk_wasm, tsRustConversionNative var caml_pasta_fq_plonk_verifier_index_shifts = function (log2_size) { - return tsRustConversionNative.fq.shiftsFromRust( - plonk_wasm.caml_pasta_fq_plonk_verifier_index_shifts(log2_size) - ); + console.log("log2_size", log2_size); + try { + var shifts = plonk_wasm.caml_pasta_fq_plonk_verifier_index_shifts(log2_size); + console.log("shifts", shifts); + console.log("shiftsFromRust", tsRustConversionNative.fq.shiftsFromRust( + shifts + )) + return tsRustConversionNative.fq.shiftsFromRust( + shifts + ); + } catch (e) { + console.error("Error calling caml_pasta_fq_plonk_verifier_index_shifts:", e); + throw e; + } }; // Provides: caml_pasta_fp_plonk_verifier_index_shifts diff --git a/src/lib/crypto/kimchi_bindings/js/node_js/node_backend.js b/src/lib/crypto/kimchi_bindings/js/node_js/node_backend.js index e5500b9d811e..50dfe28a314e 100644 --- a/src/lib/crypto/kimchi_bindings/js/node_js/node_backend.js +++ b/src/lib/crypto/kimchi_bindings/js/node_js/node_backend.js @@ -61,8 +61,8 @@ var plonk_wasm = (function() { "WasmFpSrs", "caml_fp_srs_create", "caml_fp_srs_create_parallel", - "caml_fq_srs_get", - "caml_fq_srs_set", + "caml_fp_srs_get", + "caml_fp_srs_set", "caml_fp_srs_write", "caml_fp_srs_read", "caml_fp_srs_add_lagrange_basis", @@ -93,7 +93,10 @@ var plonk_wasm = (function() { ]; overrides.forEach(function (override) { - wasm[override] = native[override] + wasm[override] = function(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10) { + console.log("calling native override:", override); + return native[override](x1, x2, x3, x4, x5, x6, x7, x8, x9, x10); + } }) wasm.native = true; } catch (e) { From a7e7ab7957d2cc9d26c4e0a2cc79b2d34e7d9e9b Mon Sep 17 00:00:00 2001 From: Florian Date: Fri, 14 Nov 2025 10:38:01 +0700 Subject: [PATCH 11/30] wip dont use napi types just yet --- .../kimchi_bindings/js/bindings/verifier-index.js | 7 ++++++- .../kimchi_bindings/js/node_js/node_backend.js | 14 ++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/lib/crypto/kimchi_bindings/js/bindings/verifier-index.js b/src/lib/crypto/kimchi_bindings/js/bindings/verifier-index.js index 756c70ff3379..ab662007c714 100644 --- a/src/lib/crypto/kimchi_bindings/js/bindings/verifier-index.js +++ b/src/lib/crypto/kimchi_bindings/js/bindings/verifier-index.js @@ -25,7 +25,12 @@ var caml_opt_to_rust = function (caml_optional_value, to_rust) { // Requires: plonk_wasm, tsRustConversion var caml_pasta_fp_plonk_verifier_index_create = function (x) { console.log("caml_pasta_fp_plonk_verifier_index_create", x) - var vk = plonk_wasm.caml_pasta_fp_plonk_verifier_index_create(x); + var bytes = plonk_wasm.prover_index_fp_to_bytes(x); + console.log("bytes", bytes) + var index = plonk_wasm.WasmPastaFpPlonkIndex.deserialize(bytes) + console.log("index", index) + var vk = plonk_wasm.caml_pasta_fp_plonk_verifier_index_create(index); + console.log("vk", vk) return tsRustConversion.fp.verifierIndexFromRust(vk); }; diff --git a/src/lib/crypto/kimchi_bindings/js/node_js/node_backend.js b/src/lib/crypto/kimchi_bindings/js/node_js/node_backend.js index 50dfe28a314e..24187cd36df4 100644 --- a/src/lib/crypto/kimchi_bindings/js/node_js/node_backend.js +++ b/src/lib/crypto/kimchi_bindings/js/node_js/node_backend.js @@ -20,8 +20,6 @@ var plonk_wasm = (function() { "caml_pasta_fp_plonk_proof_create", "caml_pasta_fp_plonk_verifier_index_shifts", "caml_pasta_fq_plonk_verifier_index_shifts", - "WasmFpPolyComm", - "WasmFqPolyComm", "caml_pasta_fp_plonk_gate_vector_create", "caml_pasta_fq_plonk_gate_vector_create", "caml_pasta_fp_plonk_gate_vector_add", @@ -84,18 +82,18 @@ var plonk_wasm = (function() { "caml_fq_srs_batch_accumulator_check", "caml_fq_srs_batch_accumulator_generate", "caml_fq_srs_h", - "WasmFpPolyComm", - "WasmFqPolyComm", - "WasmGPallas", - "WasmGVesta", +/* "WasmFpPolyComm", + "WasmFqPolyComm", */ +/* "WasmGPallas", + "WasmGVesta", */ "WasmPastaFp", "WasmPastaFq", ]; overrides.forEach(function (override) { - wasm[override] = function(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10) { + wasm[override] = function(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12) { console.log("calling native override:", override); - return native[override](x1, x2, x3, x4, x5, x6, x7, x8, x9, x10); + return native[override](x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12); } }) wasm.native = true; From 4c4df14fb1b5c0c9e5b3621276676d8ef0e78f02 Mon Sep 17 00:00:00 2001 From: Florian Date: Fri, 14 Nov 2025 10:38:08 +0700 Subject: [PATCH 12/30] Update proof-systems --- src/lib/crypto/proof-systems | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/crypto/proof-systems b/src/lib/crypto/proof-systems index f43f9a41bcde..f5110b8fbe6e 160000 --- a/src/lib/crypto/proof-systems +++ b/src/lib/crypto/proof-systems @@ -1 +1 @@ -Subproject commit f43f9a41bcde7e8830df4ae4b4fcaff2357422aa +Subproject commit f5110b8fbe6e25c609095eb86dc2c2b8da72909f From ef9d64fbce56e86c6a8b000813324cee3d646fbc Mon Sep 17 00:00:00 2001 From: querolita Date: Fri, 14 Nov 2025 12:37:40 +0100 Subject: [PATCH 13/30] submodule: update proof-systems --- src/lib/crypto/proof-systems | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/crypto/proof-systems b/src/lib/crypto/proof-systems index 27272e22abbe..ad8954c272b7 160000 --- a/src/lib/crypto/proof-systems +++ b/src/lib/crypto/proof-systems @@ -1 +1 @@ -Subproject commit 27272e22abbef15bdec175e5e771b87ff1b90730 +Subproject commit ad8954c272b74006588b1067230c329ac8508f1b From 2cffb7fa75d91e4dfdd0371943923b1de64ff35a Mon Sep 17 00:00:00 2001 From: Shigoto-dev19 Date: Fri, 14 Nov 2025 19:22:41 +0300 Subject: [PATCH 14/30] Kimchi bindings native overrides for napi oracles conversion --- .../kimchi_bindings/js/bindings/oracles.js | 64 ------------------- .../js/native/native-overrides/oracles.js | 63 ++++++++++++++++++ .../js/node_js/node_backend.js | 8 +++ 3 files changed, 71 insertions(+), 64 deletions(-) diff --git a/src/lib/crypto/kimchi_bindings/js/bindings/oracles.js b/src/lib/crypto/kimchi_bindings/js/bindings/oracles.js index ecd57b9f4861..bc824ee04cc4 100644 --- a/src/lib/crypto/kimchi_bindings/js/bindings/oracles.js +++ b/src/lib/crypto/kimchi_bindings/js/bindings/oracles.js @@ -1,69 +1,5 @@ /* global plonk_wasm, tsRustConversion,*/ -// Provides: fp_oracles_create -// Requires: plonk_wasm, tsRustConversion -var fp_oracles_create = function (lgr_comm, verifier_index, proof) { - return tsRustConversion.fp.oraclesFromRust( - plonk_wasm.fp_oracles_create( - tsRustConversion.fp.polyCommsToRust(lgr_comm), - tsRustConversion.fp.verifierIndexToRust(verifier_index), - tsRustConversion.fp.proofToRust(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 -var fp_oracles_dummy = function () { - return tsRustConversion.fp.oraclesFromRust(plonk_wasm.fp_oracles_dummy()); -}; - -// Provides: fp_oracles_deep_copy -// Requires: plonk_wasm, tsRustConversion -var fp_oracles_deep_copy = function (x) { - return tsRustConversion.fp.oraclesFromRust( - plonk_wasm.fp_oracles_deep_copy(tsRustConversion.fp.oraclesToRust(x)) - ); -}; - -// Provides: fq_oracles_create -// Requires: plonk_wasm, tsRustConversion -var fq_oracles_create = function (lgr_comm, verifier_index, proof) { - return tsRustConversion.fq.oraclesFromRust( - plonk_wasm.fq_oracles_create( - tsRustConversion.fq.polyCommsToRust(lgr_comm), - tsRustConversion.fq.verifierIndexToRust(verifier_index), - tsRustConversion.fq.proofToRust(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 -var fq_oracles_dummy = function () { - return tsRustConversion.fq.oraclesFromRust(plonk_wasm.fq_oracles_dummy()); -}; - -// Provides: fq_oracles_deep_copy -// Requires: plonk_wasm, tsRustConversion -var fq_oracles_deep_copy = function (x) { - return tsRustConversion.fq.oraclesFromRust( - plonk_wasm.fq_oracles_deep_copy(tsRustConversion.fq.oraclesToRust(x)) - ); -}; - // This is fake -- parameters are only needed on the Rust side, so no need to return something meaningful // Provides: caml_pasta_fp_poseidon_params_create function caml_pasta_fp_poseidon_params_create() { diff --git a/src/lib/crypto/kimchi_bindings/js/native/native-overrides/oracles.js b/src/lib/crypto/kimchi_bindings/js/native/native-overrides/oracles.js index 795c518f1ca1..3ccde404c09b 100644 --- a/src/lib/crypto/kimchi_bindings/js/native/native-overrides/oracles.js +++ b/src/lib/crypto/kimchi_bindings/js/native/native-overrides/oracles.js @@ -1,5 +1,68 @@ /* global plonk_wasm, tsRustConversionNative,*/ +// Provides: fp_oracles_create +// Requires: plonk_wasm, tsRustConversionNative +var fp_oracles_create = function (lgr_comm, verifier_index, proof) { + return tsRustConversionNative.fp.oraclesFromRust( + plonk_wasm.fp_oracles_create( + tsRustConversionNative.fp.polyCommsToRust(lgr_comm), + tsRustConversionNative.fp.verifierIndexToRust(verifier_index), + tsRustConversionNative.fp.proofToRust(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, tsRustConversionNative +var fp_oracles_dummy = function () { + return tsRustConversionNative.fp.oraclesFromRust(plonk_wasm.fp_oracles_dummy()); +}; + +// Provides: fp_oracles_deep_copy +// Requires: plonk_wasm, tsRustConversionNative +var fp_oracles_deep_copy = function (x) { + return tsRustConversionNative.fp.oraclesFromRust( + plonk_wasm.fp_oracles_deep_copy(tsRustConversionNative.fp.oraclesToRust(x)) + ); +}; + +// Provides: fq_oracles_create +// Requires: plonk_wasm, tsRustConversionNative +var fq_oracles_create = function (lgr_comm, verifier_index, proof) { + return tsRustConversionNative.fq.oraclesFromRust( + plonk_wasm.fq_oracles_create( + tsRustConversionNative.fq.polyCommsToRust(lgr_comm), + tsRustConversionNative.fq.verifierIndexToRust(verifier_index), + tsRustConversionNative.fq.proofToRust(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, tsRustConversionNative +var fq_oracles_dummy = function () { + return tsRustConversionNative.fq.oraclesFromRust(plonk_wasm.fq_oracles_dummy()); +}; + +// Provides: fq_oracles_deep_copy +// Requires: plonk_wasm, tsRustConversionNative +var fq_oracles_deep_copy = function (x) { + return tsRustConversionNative.fq.oraclesFromRust( + plonk_wasm.fq_oracles_deep_copy(tsRustConversionNative.fq.oraclesToRust(x)) + ); +}; // Provides: caml_pasta_fq_poseidon_block_cipher // Requires: plonk_wasm, tsRustConversionNative diff --git a/src/lib/crypto/kimchi_bindings/js/node_js/node_backend.js b/src/lib/crypto/kimchi_bindings/js/node_js/node_backend.js index 49ee9e31ded1..984464fea6d0 100644 --- a/src/lib/crypto/kimchi_bindings/js/node_js/node_backend.js +++ b/src/lib/crypto/kimchi_bindings/js/node_js/node_backend.js @@ -93,6 +93,14 @@ var plonk_wasm = (function() { "caml_pasta_fp_plonk_proof_verify", "caml_pasta_fq_plonk_proof_create", "caml_pasta_fq_plonk_proof_verify", + "fp_oracles_create", + "fp_oracles_create_no_public", + "fp_oracles_dummy", + "fp_oracles_deep_copy", + "fq_oracles_create", + "fq_oracles_create_no_public", + "fq_oracles_dummy", + "fq_oracles_deep_copy", ]; overrides.forEach(function (override) { From b68cc0fdb33755119af32ad4a4964fd1deb78b72 Mon Sep 17 00:00:00 2001 From: querolita Date: Fri, 14 Nov 2025 23:08:51 +0100 Subject: [PATCH 15/30] submodule: update proof systemse --- src/lib/crypto/proof-systems | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/crypto/proof-systems b/src/lib/crypto/proof-systems index ad8954c272b7..ecb68549f116 160000 --- a/src/lib/crypto/proof-systems +++ b/src/lib/crypto/proof-systems @@ -1 +1 @@ -Subproject commit ad8954c272b74006588b1067230c329ac8508f1b +Subproject commit ecb68549f116db47fd4a4a086ed0413fee13004a From 4a260766b10f0d597bde65345771729f8591b8bd Mon Sep 17 00:00:00 2001 From: querolita Date: Fri, 14 Nov 2025 23:09:21 +0100 Subject: [PATCH 16/30] backend: add overrides for proof types --- .../crypto/kimchi_bindings/js/node_js/node_backend.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/lib/crypto/kimchi_bindings/js/node_js/node_backend.js b/src/lib/crypto/kimchi_bindings/js/node_js/node_backend.js index 49ee9e31ded1..8d6a661e3af6 100644 --- a/src/lib/crypto/kimchi_bindings/js/node_js/node_backend.js +++ b/src/lib/crypto/kimchi_bindings/js/node_js/node_backend.js @@ -93,6 +93,16 @@ var plonk_wasm = (function() { "caml_pasta_fp_plonk_proof_verify", "caml_pasta_fq_plonk_proof_create", "caml_pasta_fq_plonk_proof_verify", + "WasmFpOpeningProof", + "WasmFqOpeningProof", + "WasmFpLookupCommitments", + "WasmFqLookupCommitments", + "WasmFpProverProof", + "WasmFqProverProof", + "WasmFpProofEvaluations", + "WasmFqProofEvaluations", + "WasmFpProverCommitments", + "WasmFqProverCommitments", ]; overrides.forEach(function (override) { From 05ae9bac56711ca718da300ec2ff4bc09ef5db1b Mon Sep 17 00:00:00 2001 From: querolita Date: Fri, 14 Nov 2025 23:11:50 +0100 Subject: [PATCH 17/30] jsoo: override proof batch verify --- .../kimchi_bindings/js/bindings/proof.js | 31 ------------------- .../js/native/native-overrides/proof.js | 28 ++++++++++++++++- 2 files changed, 27 insertions(+), 32 deletions(-) diff --git a/src/lib/crypto/kimchi_bindings/js/bindings/proof.js b/src/lib/crypto/kimchi_bindings/js/bindings/proof.js index c08c48a59ea0..79c4ecd43222 100644 --- a/src/lib/crypto/kimchi_bindings/js/bindings/proof.js +++ b/src/lib/crypto/kimchi_bindings/js/bindings/proof.js @@ -1,21 +1,6 @@ /* global plonk_wasm, tsRustConversion */ - -// Provides: caml_pasta_fp_plonk_proof_batch_verify -// Requires: plonk_wasm, tsRustConversion -var caml_pasta_fp_plonk_proof_batch_verify = function (indexes, proofs) { - indexes = tsRustConversion.mapMlArrayToRustVector( - indexes, - tsRustConversion.fp.verifierIndexToRust - ); - proofs = tsRustConversion.mapMlArrayToRustVector( - proofs, - tsRustConversion.fp.proofToRust - ); - return plonk_wasm.caml_pasta_fp_plonk_proof_batch_verify(indexes, proofs); -}; - // Provides: caml_pasta_fp_plonk_proof_dummy // Requires: plonk_wasm, tsRustConversion var caml_pasta_fp_plonk_proof_dummy = function () { @@ -34,22 +19,6 @@ var caml_pasta_fp_plonk_proof_deep_copy = function (proof) { ); }; - - -// Provides: caml_pasta_fq_plonk_proof_batch_verify -// Requires: plonk_wasm, tsRustConversion -var caml_pasta_fq_plonk_proof_batch_verify = function (indexes, proofs) { - indexes = tsRustConversion.mapMlArrayToRustVector( - indexes, - tsRustConversion.fq.verifierIndexToRust - ); - proofs = tsRustConversion.mapMlArrayToRustVector( - proofs, - tsRustConversion.fq.proofToRust - ); - return plonk_wasm.caml_pasta_fq_plonk_proof_batch_verify(indexes, proofs); -}; - // Provides: caml_pasta_fq_plonk_proof_dummy // Requires: plonk_wasm, tsRustConversion var caml_pasta_fq_plonk_proof_dummy = function () { diff --git a/src/lib/crypto/kimchi_bindings/js/native/native-overrides/proof.js b/src/lib/crypto/kimchi_bindings/js/native/native-overrides/proof.js index d399a2c250e2..072be55e2e6e 100644 --- a/src/lib/crypto/kimchi_bindings/js/native/native-overrides/proof.js +++ b/src/lib/crypto/kimchi_bindings/js/native/native-overrides/proof.js @@ -38,7 +38,19 @@ var caml_pasta_fp_plonk_proof_verify = function (index, proof) { return plonk_wasm.caml_pasta_fp_plonk_proof_verify(index, proof); }; - +// Provides: caml_pasta_fp_plonk_proof_batch_verify +// Requires: plonk_wasm, tsRustConversionNative +var caml_pasta_fp_plonk_proof_batch_verify = function (indexes, proofs) { + indexes = tsRustConversionNative.mapMlArrayToRustVector( + indexes, + tsRustConversionNative.fp.verifierIndexToRust + ); + proofs = tsRustConversionNative.mapMlArrayToRustVector( + proofs, + tsRustConversionNative.fp.proofToRust + ); + return plonk_wasm.caml_pasta_fp_plonk_proof_batch_verify(indexes, proofs); +}; // Provides: caml_pasta_fq_plonk_proof_create // Requires: plonk_wasm, tsRustConversionNative @@ -75,3 +87,17 @@ var caml_pasta_fq_plonk_proof_verify = function (index, proof) { proof = tsRustConversionNative.fq.proofToRust(proof); return plonk_wasm.caml_pasta_fq_plonk_proof_verify(index, proof); }; + +// Provides: caml_pasta_fq_plonk_proof_batch_verify +// Requires: plonk_wasm, tsRustConversionNative +var caml_pasta_fq_plonk_proof_batch_verify = function (indexes, proofs) { + indexes = tsRustConversionNative.mapMlArrayToRustVector( + indexes, + tsRustConversionNatsRustConversionNativetive.fq.verifierIndexToRust + ); + proofs = tsRustConversionNative.mapMlArrayToRustVector( + proofs, + tsRustConversionNative.fq.proofToRust + ); + return plonk_wasm.caml_pasta_fq_plonk_proof_batch_verify(indexes, proofs); +}; \ No newline at end of file From 277525f1f35b688e3c548b02f54d3b1939ffba34 Mon Sep 17 00:00:00 2001 From: querolita Date: Fri, 14 Nov 2025 23:12:40 +0100 Subject: [PATCH 18/30] jsoo: override proof dummy --- .../crypto/kimchi_bindings/js/bindings/proof.js | 15 +-------------- .../js/native/native-overrides/proof.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/lib/crypto/kimchi_bindings/js/bindings/proof.js b/src/lib/crypto/kimchi_bindings/js/bindings/proof.js index 79c4ecd43222..e39cd3be1863 100644 --- a/src/lib/crypto/kimchi_bindings/js/bindings/proof.js +++ b/src/lib/crypto/kimchi_bindings/js/bindings/proof.js @@ -1,13 +1,7 @@ /* global plonk_wasm, tsRustConversion */ -// Provides: caml_pasta_fp_plonk_proof_dummy -// Requires: plonk_wasm, tsRustConversion -var caml_pasta_fp_plonk_proof_dummy = function () { - return tsRustConversion.fp.proofFromRust( - plonk_wasm.caml_pasta_fp_plonk_proof_dummy() - ); -}; + // Provides: caml_pasta_fp_plonk_proof_deep_copy // Requires: plonk_wasm, tsRustConversion @@ -19,13 +13,6 @@ var caml_pasta_fp_plonk_proof_deep_copy = function (proof) { ); }; -// Provides: caml_pasta_fq_plonk_proof_dummy -// Requires: plonk_wasm, tsRustConversion -var caml_pasta_fq_plonk_proof_dummy = function () { - return tsRustConversion.fq.proofFromRust( - plonk_wasm.caml_pasta_fq_plonk_proof_dummy() - ); -}; // Provides: caml_pasta_fq_plonk_proof_deep_copy // Requires: plonk_wasm, tsRustConversion diff --git a/src/lib/crypto/kimchi_bindings/js/native/native-overrides/proof.js b/src/lib/crypto/kimchi_bindings/js/native/native-overrides/proof.js index 072be55e2e6e..1e508e8bf508 100644 --- a/src/lib/crypto/kimchi_bindings/js/native/native-overrides/proof.js +++ b/src/lib/crypto/kimchi_bindings/js/native/native-overrides/proof.js @@ -52,6 +52,14 @@ var caml_pasta_fp_plonk_proof_batch_verify = function (indexes, proofs) { return plonk_wasm.caml_pasta_fp_plonk_proof_batch_verify(indexes, proofs); }; +// Provides: caml_pasta_fp_plonk_proof_dummy +// Requires: plonk_wasm, tsRustConversionNative +var caml_pasta_fp_plonk_proof_dummy = function () { + return tsRustConversionNative.fp.proofFromRust( + plonk_wasm.caml_pasta_fp_plonk_proof_dummy() + ); +}; + // Provides: caml_pasta_fq_plonk_proof_create // Requires: plonk_wasm, tsRustConversionNative var caml_pasta_fq_plonk_proof_create = function ( @@ -100,4 +108,12 @@ var caml_pasta_fq_plonk_proof_batch_verify = function (indexes, proofs) { tsRustConversionNative.fq.proofToRust ); return plonk_wasm.caml_pasta_fq_plonk_proof_batch_verify(indexes, proofs); +}; + +// Provides: caml_pasta_fq_plonk_proof_dummy +// Requires: plonk_wasm, tsRustConversionNative +var caml_pasta_fq_plonk_proof_dummy = function () { + return tsRustConversionNative.fq.proofFromRust( + plonk_wasm.caml_pasta_fq_plonk_proof_dummy() + ); }; \ No newline at end of file From c19a049b4fe354206b40854ce4fa80b5c099e32b Mon Sep 17 00:00:00 2001 From: querolita Date: Fri, 14 Nov 2025 23:13:36 +0100 Subject: [PATCH 19/30] jsoo: override proof deep copy --- .../kimchi_bindings/js/bindings/proof.js | 26 ------------------- .../js/native/native-overrides/proof.js | 23 +++++++++++++++- 2 files changed, 22 insertions(+), 27 deletions(-) diff --git a/src/lib/crypto/kimchi_bindings/js/bindings/proof.js b/src/lib/crypto/kimchi_bindings/js/bindings/proof.js index e39cd3be1863..e69de29bb2d1 100644 --- a/src/lib/crypto/kimchi_bindings/js/bindings/proof.js +++ b/src/lib/crypto/kimchi_bindings/js/bindings/proof.js @@ -1,26 +0,0 @@ -/* global plonk_wasm, tsRustConversion - */ - - - -// Provides: caml_pasta_fp_plonk_proof_deep_copy -// Requires: plonk_wasm, tsRustConversion -var caml_pasta_fp_plonk_proof_deep_copy = function (proof) { - return tsRustConversion.fp.proofFromRust( - plonk_wasm.caml_pasta_fp_plonk_proof_deep_copy( - tsRustConversion.fp.proofToRust(proof) - ) - ); -}; - - -// Provides: caml_pasta_fq_plonk_proof_deep_copy -// Requires: plonk_wasm, tsRustConversion -var caml_pasta_fq_plonk_proof_deep_copy = function (proof) { - return tsRustConversion.fq.proofFromRust( - plonk_wasm.caml_pasta_fq_plonk_proof_deep_copy( - tsRustConversion.fq.proofToRust(proof) - ) - ); -}; - diff --git a/src/lib/crypto/kimchi_bindings/js/native/native-overrides/proof.js b/src/lib/crypto/kimchi_bindings/js/native/native-overrides/proof.js index 1e508e8bf508..3a030063c293 100644 --- a/src/lib/crypto/kimchi_bindings/js/native/native-overrides/proof.js +++ b/src/lib/crypto/kimchi_bindings/js/native/native-overrides/proof.js @@ -60,6 +60,16 @@ var caml_pasta_fp_plonk_proof_dummy = function () { ); }; +// Provides: caml_pasta_fp_plonk_proof_deep_copy +// Requires: plonk_wasm, tsRustConversionNative +var caml_pasta_fp_plonk_proof_deep_copy = function (proof) { + return tsRustConversionNative.fp.proofFromRust( + plonk_wasm.caml_pasta_fp_plonk_proof_deep_copy( + tsRustConversionNative.fp.proofToRust(proof) + ) + ); +}; + // Provides: caml_pasta_fq_plonk_proof_create // Requires: plonk_wasm, tsRustConversionNative var caml_pasta_fq_plonk_proof_create = function ( @@ -116,4 +126,15 @@ var caml_pasta_fq_plonk_proof_dummy = function () { return tsRustConversionNative.fq.proofFromRust( plonk_wasm.caml_pasta_fq_plonk_proof_dummy() ); -}; \ No newline at end of file +}; + +// Provides: caml_pasta_fq_plonk_proof_deep_copy +// Requires: plonk_wasm, tsRustConversionNative +var caml_pasta_fq_plonk_proof_deep_copy = function (proof) { + return tsRustConversionNative.fq.proofFromRust( + plonk_wasm.caml_pasta_fq_plonk_proof_deep_copy( + tsRustConversionNative.fq.proofToRust(proof) + ) + ); +}; + From 857e2a8402e67d4a3931bdd60043123890046df7 Mon Sep 17 00:00:00 2001 From: querolita Date: Mon, 17 Nov 2025 18:01:03 +0100 Subject: [PATCH 20/30] backend: don't include fq yet --- src/lib/crypto/kimchi_bindings/js/node_js/node_backend.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib/crypto/kimchi_bindings/js/node_js/node_backend.js b/src/lib/crypto/kimchi_bindings/js/node_js/node_backend.js index 96e218de9d35..4aabf7d8de3f 100644 --- a/src/lib/crypto/kimchi_bindings/js/node_js/node_backend.js +++ b/src/lib/crypto/kimchi_bindings/js/node_js/node_backend.js @@ -18,7 +18,6 @@ var plonk_wasm = (function() { "caml_pasta_fp_poseidon_block_cipher", "caml_pasta_fq_poseidon_block_cipher", "caml_pasta_fp_plonk_proof_create", - "caml_pasta_fq_plonk_proof_create", "caml_pasta_fp_plonk_verifier_index_shifts", "caml_pasta_fq_plonk_verifier_index_shifts", "caml_pasta_fp_plonk_gate_vector_create", From 6189fa7b99e90a34673ac19519cb0271816b306a Mon Sep 17 00:00:00 2001 From: querolita Date: Wed, 19 Nov 2025 00:47:16 +0100 Subject: [PATCH 21/30] backend: include missing srs functions --- .../js/native/native-overrides/srs.js | 10 +++++++++- .../kimchi_bindings/js/node_js/node_backend.js | 16 ++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/lib/crypto/kimchi_bindings/js/native/native-overrides/srs.js b/src/lib/crypto/kimchi_bindings/js/native/native-overrides/srs.js index 0125d21dfa8d..b9d7329c7946 100644 --- a/src/lib/crypto/kimchi_bindings/js/native/native-overrides/srs.js +++ b/src/lib/crypto/kimchi_bindings/js/native/native-overrides/srs.js @@ -59,6 +59,10 @@ var caml_fq_srs_lagrange_commitments_whole_domain = return tsSrs.fq.lagrangeCommitmentsWholeDomain(srs, domain_size); } +// Provides: caml_fp_srs_lagrange_commitment +// Requires: tsSrs +var caml_fp_srs_lagrange_commitment = tsSrs.fp.lagrangeCommitment; + // Provides: caml_fp_srs_lagrange_commitment // Requires: tsSrs var caml_fp_srs_lagrange_commitment = function (srs, i) { @@ -166,12 +170,16 @@ 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; + // Provides: caml_fq_srs_lagrange_commitment // Requires: tsSrs var caml_fq_srs_lagrange_commitment = function (srs, i) { console.log("native caml_fq_srs_lagrange_commitment"); return tsSrs.fq.lagrangeCommitment(srs, i); -} +}; // Provides: caml_fq_srs_commit_evaluations // Requires: plonk_wasm, tsRustConversionNative diff --git a/src/lib/crypto/kimchi_bindings/js/node_js/node_backend.js b/src/lib/crypto/kimchi_bindings/js/node_js/node_backend.js index ad7f9e847b63..159d7da16fe9 100644 --- a/src/lib/crypto/kimchi_bindings/js/node_js/node_backend.js +++ b/src/lib/crypto/kimchi_bindings/js/node_js/node_backend.js @@ -56,11 +56,22 @@ var plonk_wasm = (function() { "caml_pasta_fq_plonk_index_read", "caml_fp_srs_from_bytes", "caml_fq_srs_from_bytes", + "caml_fp_srs_to_bytes_external", + "caml_fq_srs_to_bytes_external", + "caml_fp_srs_from_bytes_external", + "caml_fq_srs_from_bytes_external", + "caml_fp_srs_to_bytes", + "caml_fq_srs_to_bytes", "WasmFpSrs", "caml_fp_srs_create", "caml_fp_srs_create_parallel", "caml_fp_srs_get", "caml_fp_srs_set", + "caml_fp_srs_lagrange_commitment", + "caml_fp_srs_maybe_lagrange_commitment", + "caml_fp_srs_lagrange_commitments_whole_domain_ptr", + "caml_fp_srs_set_lagrange_basis", + "caml_fp_srs_get_lagrange_basis", "caml_fp_srs_write", "caml_fp_srs_read", "caml_fp_srs_add_lagrange_basis", @@ -74,6 +85,11 @@ var plonk_wasm = (function() { "caml_fq_srs_create_parallel", "caml_fq_srs_get", "caml_fq_srs_set", + "caml_fq_srs_lagrange_commitment", + "caml_fq_srs_maybe_lagrange_commitment", + "caml_fq_srs_lagrange_commitments_whole_domain_ptr", + "caml_fq_srs_set_lagrange_basis", + "caml_fq_srs_get_lagrange_basis", "caml_fq_srs_write", "caml_fq_srs_read", "caml_fq_srs_add_lagrange_basis", From 464b918092f6a851c7993f3a6f4ba89f6de75b4d Mon Sep 17 00:00:00 2001 From: querolita Date: Thu, 20 Nov 2025 21:17:26 +0100 Subject: [PATCH 22/30] jsoo: remove serde workaround for wasm/napi as we are advancing in exposing all the intermediate types --- .../kimchi_bindings/js/native/header-d.ts | 18 +++++++------- .../native/native-overrides/prover-index.js | 24 ++++++++----------- .../js/node_js/node_backend.js | 9 +++---- 3 files changed, 24 insertions(+), 27 deletions(-) diff --git a/src/lib/crypto/kimchi_bindings/js/native/header-d.ts b/src/lib/crypto/kimchi_bindings/js/native/header-d.ts index 58f93d192edf..3fd3d74b1e57 100644 --- a/src/lib/crypto/kimchi_bindings/js/native/header-d.ts +++ b/src/lib/crypto/kimchi_bindings/js/native/header-d.ts @@ -4,20 +4,20 @@ // This file gets auto-included in the generated plonk-napi types to supplement // external pointer types. -type NapiGVesta = {}; -type NapiGPallas = {}; -type NapiPastaFpPlonkIndex = {}; -type NapiPastaFqPlonkIndex = {}; -type NapiPastaFp = {}; -type NapiPastaFq = {}; -type NapiLookupInfo = {}; +type WasmGVesta = {}; +type WasmGPallas = {}; +type WasmPastaFp = {}; +type WasmPastaFq = {}; +type WasmLookupInfo = {}; type WasmPastaFpPlonkIndex = {}; type WasmPastaFqPlonkIndex = {}; type Proof = {} -type NapiVector = {}; -type NapiFlatVector = {}; +type WasmVector = {}; +type WasmFlatVector = {}; type WasmVecVecFp = {}; type WasmVecVecFq = {}; +type WasmFpSrs = {}; +type WasmFqSrs = {}; type Self = {}; // Header section end \ No newline at end of file diff --git a/src/lib/crypto/kimchi_bindings/js/native/native-overrides/prover-index.js b/src/lib/crypto/kimchi_bindings/js/native/native-overrides/prover-index.js index 56794d71f912..e7d835b7930d 100644 --- a/src/lib/crypto/kimchi_bindings/js/native/native-overrides/prover-index.js +++ b/src/lib/crypto/kimchi_bindings/js/native/native-overrides/prover-index.js @@ -106,7 +106,7 @@ function caml_pasta_fq_plonk_index_domain_d8_size(prover_index) { // Provides: caml_pasta_fp_plonk_index_create -// Requires: plonk_wasm, free_on_finalize, tsRustConversionNative +// Requires: plonk_wasm, tsRustConversionNative var caml_pasta_fp_plonk_index_create = function ( gates, public_inputs, @@ -121,10 +121,10 @@ var caml_pasta_fp_plonk_index_create = function ( var wasm_runtime_table_cfgs = tsRustConversionNative.fp.runtimeTableCfgsToRust( caml_runtime_table_cfgs ); - console.time("conversion") + console.time("conversion plonk index create") var gate_vec = plonk_wasm.caml_pasta_fp_plonk_gate_vector_from_bytes(gates.serialize()); var urs_ser = plonk_wasm.caml_fp_srs_from_bytes_external(urs.serialize()) - console.timeEnd("conversion") + console.timeEnd("conversion plonk index create") console.time("index_create") var t = plonk_wasm.caml_pasta_fp_plonk_index_create( @@ -138,11 +138,7 @@ var caml_pasta_fp_plonk_index_create = function ( ); console.timeEnd("index_create"); - console.time("finalize_conversion") - var wasm_t = plonk_wasm.WasmPastaFpPlonkIndex.deserialize(plonk_wasm.prover_index_fp_to_bytes(t)) - console.timeEnd("finalize_conversion") - - return free_on_finalize(wasm_t); + return plonk_wasm.prover_index_fp_to_bytes(t); }; // Provides: caml_pasta_fp_plonk_index_create_bytecode @@ -198,7 +194,7 @@ var caml_pasta_fp_plonk_index_write = function (append, t, path) { }; // Provides: caml_pasta_fq_plonk_index_create -// Requires: plonk_wasm, free_on_finalize, tsRustConversionNative +// Requires: plonk_wasm, tsRustConversionNative var caml_pasta_fq_plonk_index_create = function ( gates, public_inputs, @@ -208,16 +204,20 @@ var caml_pasta_fq_plonk_index_create = function ( urs, lazy_mode ) { + console.log("anais: 1"); var wasm_lookup_tables = tsRustConversionNative.fq.lookupTablesToRust(caml_lookup_tables); + console.log("anais: 2"); var wasm_runtime_table_cfgs = tsRustConversionNative.fq.runtimeTableCfgsToRust( caml_runtime_table_cfgs ); + console.log("anais: 3"); console.time("conversion") var gate_vec = plonk_wasm.caml_pasta_fq_plonk_gate_vector_from_bytes(gates.serialize()); var urs_ser = plonk_wasm.caml_fq_srs_from_bytes_external(urs.serialize()) console.timeEnd("conversion") + console.log("anais: 4"); console.time("index_create") var t = plonk_wasm.caml_pasta_fq_plonk_index_create( @@ -231,11 +231,7 @@ var caml_pasta_fq_plonk_index_create = function ( ); console.timeEnd("index_create"); - console.time("finalize_conversion") - var wasm_t = plonk_wasm.WasmPastaFqPlonkIndex.deserialize(plonk_wasm.prover_index_fq_to_bytes(t)) - console.timeEnd("finalize_conversion") - - return free_on_finalize(wasm_t); + return plonk_wasm.prover_index_fq_to_bytes(t); }; // Provides: caml_pasta_fq_plonk_index_create_bytecode diff --git a/src/lib/crypto/kimchi_bindings/js/node_js/node_backend.js b/src/lib/crypto/kimchi_bindings/js/node_js/node_backend.js index 159d7da16fe9..52ce83478de8 100644 --- a/src/lib/crypto/kimchi_bindings/js/node_js/node_backend.js +++ b/src/lib/crypto/kimchi_bindings/js/node_js/node_backend.js @@ -18,6 +18,7 @@ var plonk_wasm = (function() { "caml_pasta_fp_poseidon_block_cipher", "caml_pasta_fq_poseidon_block_cipher", "caml_pasta_fp_plonk_proof_create", + "caml_pasta_fp_plonk_verifier_index_create", "caml_pasta_fp_plonk_verifier_index_shifts", "caml_pasta_fq_plonk_verifier_index_shifts", "caml_pasta_fp_plonk_gate_vector_create", @@ -98,10 +99,10 @@ var plonk_wasm = (function() { "caml_fq_srs_batch_accumulator_check", "caml_fq_srs_batch_accumulator_generate", "caml_fq_srs_h", -/* "WasmFpPolyComm", - "WasmFqPolyComm", */ -/* "WasmGPallas", - "WasmGVesta", */ + "WasmFpPolyComm", + "WasmFqPolyComm", + "WasmGPallas", + "WasmGVesta", "WasmPastaFp", "WasmPastaFq", "caml_pasta_fp_plonk_proof_create", From 6d9b2f6fe2d7f686897062637eb036f17dc41ba8 Mon Sep 17 00:00:00 2001 From: querolita Date: Thu, 20 Nov 2025 21:18:04 +0100 Subject: [PATCH 23/30] submodule: update proof-systems --- src/lib/crypto/proof-systems | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/crypto/proof-systems b/src/lib/crypto/proof-systems index 67b9a9807793..6fcc8cefaee2 160000 --- a/src/lib/crypto/proof-systems +++ b/src/lib/crypto/proof-systems @@ -1 +1 @@ -Subproject commit 67b9a98077936044f10720fadb8ef5ca8eeed249 +Subproject commit 6fcc8cefaee22e5c3a51012f024ceae50304c95e From cabebc871553da46e2504a3f1747ad65bda35ce9 Mon Sep 17 00:00:00 2001 From: querolita Date: Wed, 26 Nov 2025 17:05:36 +0100 Subject: [PATCH 24/30] jsoo: overrides for verifier index functions and types --- .../js/bindings/verifier-index.js | 133 ----------------- .../native/native-overrides/verifier-index.js | 135 ++++++++++++++++++ .../js/node_js/node_backend.js | 25 ++++ 3 files changed, 160 insertions(+), 133 deletions(-) diff --git a/src/lib/crypto/kimchi_bindings/js/bindings/verifier-index.js b/src/lib/crypto/kimchi_bindings/js/bindings/verifier-index.js index ab662007c714..08819154c87a 100644 --- a/src/lib/crypto/kimchi_bindings/js/bindings/verifier-index.js +++ b/src/lib/crypto/kimchi_bindings/js/bindings/verifier-index.js @@ -20,136 +20,3 @@ var caml_opt_to_rust = function (caml_optional_value, to_rust) { return to_rust(caml_optional_value[1]); } }; - -// Provides: caml_pasta_fp_plonk_verifier_index_create -// Requires: plonk_wasm, tsRustConversion -var caml_pasta_fp_plonk_verifier_index_create = function (x) { - console.log("caml_pasta_fp_plonk_verifier_index_create", x) - var bytes = plonk_wasm.prover_index_fp_to_bytes(x); - console.log("bytes", bytes) - var index = plonk_wasm.WasmPastaFpPlonkIndex.deserialize(bytes) - console.log("index", index) - var vk = plonk_wasm.caml_pasta_fp_plonk_verifier_index_create(index); - console.log("vk", vk) - return tsRustConversion.fp.verifierIndexFromRust(vk); -}; - -// Provides: caml_pasta_fp_plonk_verifier_index_read -// Requires: plonk_wasm, caml_jsstring_of_string, tsRustConversion -var caml_pasta_fp_plonk_verifier_index_read = function (offset, urs, path) { - console.log("caml_pasta_fp_plonk_verifier_index_read") - - if (offset === 0) { - offset = undefined; - } else { - offset = offset[1]; - } - return tsRustConversion.fp.verifierIndexFromRust( - plonk_wasm.caml_pasta_fp_plonk_verifier_index_read( - offset, - urs, - caml_jsstring_of_string(path) - ) - ); -}; - -// Provides: caml_pasta_fp_plonk_verifier_index_write -// Requires: plonk_wasm, caml_jsstring_of_string, tsRustConversion -var caml_pasta_fp_plonk_verifier_index_write = function (append, t, path) { - console.log("caml_pasta_fp_plonk_verifier_index_write") - - if (append === 0) { - append = undefined; - } else { - append = append[1]; - } - return plonk_wasm.caml_pasta_fp_plonk_verifier_index_write( - append, - tsRustConversion.fp.verifierIndexToRust(t), - caml_jsstring_of_string(path) - ); -}; - - -// Provides: caml_pasta_fp_plonk_verifier_index_dummy -// Requires: plonk_wasm, tsRustConversion -var caml_pasta_fp_plonk_verifier_index_dummy = function () { - console.log("caml_pasta_fp_plonk_verifier_index_dummy") - - var res = plonk_wasm.caml_pasta_fp_plonk_verifier_index_dummy(); - return tsRustConversion.fp.verifierIndexFromRust(res); -}; - -// Provides: caml_pasta_fp_plonk_verifier_index_deep_copy -// Requires: plonk_wasm, tsRustConversion -var caml_pasta_fp_plonk_verifier_index_deep_copy = function (x) { - console.log("caml_pasta_fp_plonk_verifier_index_deep_copy") - return tsRustConversion.fp.verifierIndexFromRust( - plonk_wasm.caml_pasta_fp_plonk_verifier_index_deep_copy( - tsRustConversion.fp.verifierIndexToRust(x) - ) - ); -}; - -// Provides: caml_pasta_fq_plonk_verifier_index_create -// Requires: plonk_wasm, tsRustConversion -var caml_pasta_fq_plonk_verifier_index_create = function (x) { - console.log("caml_pasta_fq_plonk_verifier_index_create") - return tsRustConversion.fq.verifierIndexFromRust( - 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 -var caml_pasta_fq_plonk_verifier_index_read = function (offset, urs, path) { - console.log("caml_pasta_fq_plonk_verifier_index_read") - if (offset === 0) { - offset = undefined; - } else { - offset = offset[1]; - } - return tsRustConversion.fq.verifierIndexFromRust( - plonk_wasm.caml_pasta_fq_plonk_verifier_index_read( - offset, - urs, - caml_jsstring_of_string(path) - ) - ); -}; - -// Provides: caml_pasta_fq_plonk_verifier_index_write -// Requires: plonk_wasm, caml_jsstring_of_string, tsRustConversion -var caml_pasta_fq_plonk_verifier_index_write = function (append, t, path) { - console.log("caml_pasta_fq_plonk_verifier_index_write") - if (append === 0) { - append = undefined; - } else { - append = append[1]; - } - return plonk_wasm.caml_pasta_fq_plonk_verifier_index_write( - append, - tsRustConversion.fq.verifierIndexToRust(t), - caml_jsstring_of_string(path) - ); -}; - -// Provides: caml_pasta_fq_plonk_verifier_index_dummy -// Requires: plonk_wasm, tsRustConversion -var caml_pasta_fq_plonk_verifier_index_dummy = function () { - console.log("caml_pasta_fq_plonk_verifier_index_dummy") - return tsRustConversion.fq.verifierIndexFromRust( - plonk_wasm.caml_pasta_fq_plonk_verifier_index_dummy() - ); -}; - -// Provides: caml_pasta_fq_plonk_verifier_index_deep_copy -// Requires: plonk_wasm, tsRustConversion, tsRustConversion -var caml_pasta_fq_plonk_verifier_index_deep_copy = function (x) { - console.log("caml_pasta_fq_plonk_verifier_index_deep_copy") - return tsRustConversion.fq.verifierIndexFromRust( - plonk_wasm.caml_pasta_fq_plonk_verifier_index_deep_copy( - tsRustConversion.fq.verifierIndexToRust(x) - ) - ); -}; diff --git a/src/lib/crypto/kimchi_bindings/js/native/native-overrides/verifier-index.js b/src/lib/crypto/kimchi_bindings/js/native/native-overrides/verifier-index.js index 1a3b01f44aab..998f5ebd3043 100644 --- a/src/lib/crypto/kimchi_bindings/js/native/native-overrides/verifier-index.js +++ b/src/lib/crypto/kimchi_bindings/js/native/native-overrides/verifier-index.js @@ -1,5 +1,18 @@ /* global plonk_wasm, tsRustConversionNative */ +// Provides: caml_pasta_fp_plonk_verifier_index_create +// Requires: plonk_wasm, tsRustConversionNative +var caml_pasta_fp_plonk_verifier_index_create = function (x) { + + console.log("creating caml_pasta_fp_plonk_verifier_index_create", x) + var bytes = plonk_wasm.prover_index_fp_to_bytes(x); + console.log("bytes", bytes) + var index = plonk_wasm.prover_index_fp_from_bytes(bytes); + console.log("index", index) + var vk = plonk_wasm.caml_pasta_fp_plonk_verifier_index_create(index); + console.log("vk", vk) + return tsRustConversionNative.fp.verifierIndexFromRust(vk); +}; // Provides: caml_pasta_fq_plonk_verifier_index_shifts // Requires: plonk_wasm, tsRustConversionNative @@ -20,6 +33,74 @@ var caml_pasta_fq_plonk_verifier_index_shifts = function (log2_size) { } }; +// Provides: caml_pasta_fp_plonk_verifier_index_read +// Requires: plonk_wasm, caml_jsstring_of_string, tsRustConversionNative +var caml_pasta_fp_plonk_verifier_index_read = function (offset, urs, path) { + console.log("caml_pasta_fp_plonk_verifier_index_read") + + if (offset === 0) { + offset = undefined; + } else { + offset = offset[1]; + } + return tsRustConversionNative.fp.verifierIndexFromRust( + plonk_wasm.caml_pasta_fp_plonk_verifier_index_read( + offset, + urs, + caml_jsstring_of_string(path) + ) + ); +}; + +// Provides: caml_pasta_fp_plonk_verifier_index_write +// Requires: plonk_wasm, caml_jsstring_of_string, tsRustConversionNative +var caml_pasta_fp_plonk_verifier_index_write = function (append, t, path) { + console.log("caml_pasta_fp_plonk_verifier_index_write") + + if (append === 0) { + append = undefined; + } else { + append = append[1]; + } + return plonk_wasm.caml_pasta_fp_plonk_verifier_index_write( + append, + tsRustConversionNative.fp.verifierIndexToRust(t), + caml_jsstring_of_string(path) + ); +}; + + +// Provides: caml_pasta_fp_plonk_verifier_index_dummy +// Requires: plonk_wasm, tsRustConversionNative +var caml_pasta_fp_plonk_verifier_index_dummy = function () { + console.log("caml_pasta_fp_plonk_verifier_index_dummy") + + var res = plonk_wasm.caml_pasta_fp_plonk_verifier_index_dummy(); + return tsRustConversionNative.fp.verifierIndexFromRust(res); +}; + +// Provides: caml_pasta_fp_plonk_verifier_index_deep_copy +// Requires: plonk_wasm, tsRustConversionNative +var caml_pasta_fp_plonk_verifier_index_deep_copy = function (x) { + console.log("caml_pasta_fp_plonk_verifier_index_deep_copy") + return tsRustConversionNative.fp.verifierIndexFromRust( + plonk_wasm.caml_pasta_fp_plonk_verifier_index_deep_copy( + tsRustConversionNative.fp.verifierIndexToRust(x) + ) + ); +}; + + +// Provides: caml_pasta_fq_plonk_verifier_index_create +// Requires: plonk_wasm, tsRustConversionNative +var caml_pasta_fq_plonk_verifier_index_create = function (x) { + console.log("caml_pasta_fq_plonk_verifier_index_create") + return tsRustConversionNative.fq.verifierIndexFromRust( + plonk_wasm.caml_pasta_fq_plonk_verifier_index_create(x) + ); +}; + + // Provides: caml_pasta_fp_plonk_verifier_index_shifts // Requires: plonk_wasm, tsRustConversionNative var caml_pasta_fp_plonk_verifier_index_shifts = function (log2_size) { @@ -27,3 +108,57 @@ var caml_pasta_fp_plonk_verifier_index_shifts = function (log2_size) { plonk_wasm.caml_pasta_fp_plonk_verifier_index_shifts(log2_size) ); }; + +// Provides: caml_pasta_fq_plonk_verifier_index_read +// Requires: plonk_wasm, caml_jsstring_of_string, tsRustConversionNative +var caml_pasta_fq_plonk_verifier_index_read = function (offset, urs, path) { + console.log("caml_pasta_fq_plonk_verifier_index_read") + if (offset === 0) { + offset = undefined; + } else { + offset = offset[1]; + } + return tsRustConversionNative.fq.verifierIndexFromRust( + plonk_wasm.caml_pasta_fq_plonk_verifier_index_read( + offset, + urs, + caml_jsstring_of_string(path) + ) + ); +}; + +// Provides: caml_pasta_fq_plonk_verifier_index_write +// Requires: plonk_wasm, caml_jsstring_of_string, tsRustConversionNative +var caml_pasta_fq_plonk_verifier_index_write = function (append, t, path) { + console.log("caml_pasta_fq_plonk_verifier_index_write") + if (append === 0) { + append = undefined; + } else { + append = append[1]; + } + return plonk_wasm.caml_pasta_fq_plonk_verifier_index_write( + append, + tsRustConversionNative.fq.verifierIndexToRust(t), + caml_jsstring_of_string(path) + ); +}; + +// Provides: caml_pasta_fq_plonk_verifier_index_dummy +// Requires: plonk_wasm, tsRustConversionNative +var caml_pasta_fq_plonk_verifier_index_dummy = function () { + console.log("caml_pasta_fq_plonk_verifier_index_dummy") + return tsRustConversionNative.fq.verifierIndexFromRust( + plonk_wasm.caml_pasta_fq_plonk_verifier_index_dummy() + ); +}; + +// Provides: caml_pasta_fq_plonk_verifier_index_deep_copy +// Requires: plonk_wasm, tsRustConversionNative, tsRustConversionNative +var caml_pasta_fq_plonk_verifier_index_deep_copy = function (x) { + console.log("caml_pasta_fq_plonk_verifier_index_deep_copy") + return tsRustConversionNative.fq.verifierIndexFromRust( + plonk_wasm.caml_pasta_fq_plonk_verifier_index_deep_copy( + tsRustConversionNative.fq.verifierIndexToRust(x) + ) + ); +}; diff --git a/src/lib/crypto/kimchi_bindings/js/node_js/node_backend.js b/src/lib/crypto/kimchi_bindings/js/node_js/node_backend.js index b274522dc43f..1576e7ec83a2 100644 --- a/src/lib/crypto/kimchi_bindings/js/node_js/node_backend.js +++ b/src/lib/crypto/kimchi_bindings/js/node_js/node_backend.js @@ -18,7 +18,32 @@ var plonk_wasm = (function() { "caml_pasta_fp_poseidon_block_cipher", "caml_pasta_fq_poseidon_block_cipher", "caml_pasta_fp_plonk_proof_create", + "WasmFpPlonkVerifierIndex", + "WasmFqPlonkVerifierIndex", + "WasmFpDomain", + "WasmFqDomain", + "WasmFpShifts", + "WasmFqShifts", + "WasmFpLookupSelectors", + "WasmFqLookupSelectors", + "WasmFpPlonkVerificationEvals", + "WasmFqPlonkVerificationEvals", + "WasmFpPlonkLookupVerifierIndex", + "WasmFqPlonkLookupVerifierIndex", "caml_pasta_fp_plonk_verifier_index_create", + "caml_pasta_fq_plonk_verifier_index_create", + "caml_pasta_fp_plonk_verifier_index_read", + "caml_pasta_fq_plonk_verifier_index_read", + "caml_pasta_fp_plonk_verifier_index_write", + "caml_pasta_fq_plonk_verifier_index_write", + "caml_pasta_fp_plonk_verifier_index_dummy", + "caml_pasta_fq_plonk_verifier_index_dummy", + "caml_pasta_fp_plonk_verifier_index_serialize", + "caml_pasta_fq_plonk_verifier_index_serialize", + "caml_pasta_fp_plonk_verifier_index_deserialize", + "caml_pasta_fq_plonk_verifier_index_deserialize", + "caml_pasta_fp_plonk_verifier_index_deep_copy", + "caml_pasta_fq_plonk_verifier_index_deep_copy", "caml_pasta_fp_plonk_verifier_index_shifts", "caml_pasta_fq_plonk_verifier_index_shifts", "caml_pasta_fp_plonk_gate_vector_create", From 8437493a87dcc0db0065a19b8d74d34c567b4c53 Mon Sep 17 00:00:00 2001 From: querolita Date: Wed, 26 Nov 2025 17:12:28 +0100 Subject: [PATCH 25/30] submodule: update proof-systems --- src/lib/crypto/proof-systems | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/crypto/proof-systems b/src/lib/crypto/proof-systems index 14f111cf0ce6..1ae987ef343c 160000 --- a/src/lib/crypto/proof-systems +++ b/src/lib/crypto/proof-systems @@ -1 +1 @@ -Subproject commit 14f111cf0ce6d8a3767a7a44e35edc525bea8312 +Subproject commit 1ae987ef343ce5924c74304958cf291017388b6b From 3747ee243c15037d9a00a973af729efc0bbe63a7 Mon Sep 17 00:00:00 2001 From: querolita Date: Wed, 3 Dec 2025 20:06:29 +0100 Subject: [PATCH 26/30] bindings: remove extra plonk index conversions --- .../js/native/native-overrides/verifier-index.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/lib/crypto/kimchi_bindings/js/native/native-overrides/verifier-index.js b/src/lib/crypto/kimchi_bindings/js/native/native-overrides/verifier-index.js index 998f5ebd3043..25c004b00d62 100644 --- a/src/lib/crypto/kimchi_bindings/js/native/native-overrides/verifier-index.js +++ b/src/lib/crypto/kimchi_bindings/js/native/native-overrides/verifier-index.js @@ -3,13 +3,8 @@ // Provides: caml_pasta_fp_plonk_verifier_index_create // Requires: plonk_wasm, tsRustConversionNative var caml_pasta_fp_plonk_verifier_index_create = function (x) { - - console.log("creating caml_pasta_fp_plonk_verifier_index_create", x) - var bytes = plonk_wasm.prover_index_fp_to_bytes(x); - console.log("bytes", bytes) - var index = plonk_wasm.prover_index_fp_from_bytes(bytes); - console.log("index", index) - var vk = plonk_wasm.caml_pasta_fp_plonk_verifier_index_create(index); + console.log("jsoo caml_pasta_fp_plonk_verifier_index_create x", x); + var vk = plonk_wasm.caml_pasta_fp_plonk_verifier_index_create(x); console.log("vk", vk) return tsRustConversionNative.fp.verifierIndexFromRust(vk); }; From 0fd6efb8a21576de536b3213a5d84b95d6c9162e Mon Sep 17 00:00:00 2001 From: querolita Date: Wed, 3 Dec 2025 20:07:03 +0100 Subject: [PATCH 27/30] bindings: exposing serde helpers --- .../js/native/native-overrides/proof.js | 10 +-- .../native/native-overrides/prover-index.js | 66 +++++++++++++++---- .../js/native/native-overrides/srs.js | 40 ++++++++++- .../js/node_js/node_backend.js | 10 +-- 4 files changed, 99 insertions(+), 27 deletions(-) diff --git a/src/lib/crypto/kimchi_bindings/js/native/native-overrides/proof.js b/src/lib/crypto/kimchi_bindings/js/native/native-overrides/proof.js index 6955b71376f5..6e4e84a2c691 100644 --- a/src/lib/crypto/kimchi_bindings/js/native/native-overrides/proof.js +++ b/src/lib/crypto/kimchi_bindings/js/native/native-overrides/proof.js @@ -20,14 +20,7 @@ var caml_pasta_fp_plonk_proof_create = function ( var wasm_runtime_tables = tsRustConversionNative.fp.runtimeTablesToRust(caml_runtime_tables); prev_sgs = tsRustConversionNative.fp.pointsToRust(prev_sgs); - /*w.push(tsRustConversion.fp.vectorToRust(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( index, witness_cols, @@ -36,7 +29,6 @@ var caml_pasta_fp_plonk_proof_create = function ( prev_sgs ); return tsRustConversionNative.fp.proofFromRust(proof); - /* return tsRustConversion.fp.proofFromRust(proof); */ }; // Provides: caml_pasta_fp_plonk_proof_verify diff --git a/src/lib/crypto/kimchi_bindings/js/native/native-overrides/prover-index.js b/src/lib/crypto/kimchi_bindings/js/native/native-overrides/prover-index.js index e7d835b7930d..8d4b49089fa4 100644 --- a/src/lib/crypto/kimchi_bindings/js/native/native-overrides/prover-index.js +++ b/src/lib/crypto/kimchi_bindings/js/native/native-overrides/prover-index.js @@ -4,7 +4,7 @@ // Requires: plonk_wasm function caml_pasta_fp_plonk_index_max_degree(prover_index) { var bytes = prover_index.serialize() - var index = plonk_wasm.prover_index_fp_from_bytes(bytes); + var index = plonk_wasm.prover_index_fp_deserialize(bytes); // TODO: ^ remove the round trip when napi has direct access to the object return plonk_wasm.caml_pasta_fp_plonk_index_max_degree(index); @@ -14,7 +14,7 @@ function caml_pasta_fp_plonk_index_max_degree(prover_index) { // Requires: plonk_wasm function caml_pasta_fp_plonk_index_public_inputs(prover_index) { var bytes = prover_index.serialize() - var index = plonk_wasm.prover_index_fp_from_bytes(bytes); + var index = plonk_wasm.prover_index_fp_deserialize(bytes); // TODO: ^ remove the round trip when napi has direct access to the object return plonk_wasm.caml_pasta_fp_plonk_index_public_inputs(index); @@ -24,7 +24,7 @@ function caml_pasta_fp_plonk_index_public_inputs(prover_index) { // Requires: plonk_wasm function caml_pasta_fp_plonk_index_domain_d1_size(prover_index) { var bytes = prover_index.serialize() - var index = plonk_wasm.prover_index_fp_from_bytes(bytes); + var index = plonk_wasm.prover_index_fp_deserialize(bytes); // TODO: ^ remove the round trip when napi has direct access to the object return plonk_wasm.caml_pasta_fp_plonk_index_domain_d1_size(index); @@ -34,7 +34,7 @@ function caml_pasta_fp_plonk_index_domain_d1_size(prover_index) { // Requires: plonk_wasm function caml_pasta_fp_plonk_index_domain_d4_size(prover_index) { var bytes = prover_index.serialize() - var index = plonk_wasm.prover_index_fp_from_bytes(bytes); + var index = plonk_wasm.prover_index_fp_deserialize(bytes); // TODO: ^ remove the round trip when napi has direct access to the object return plonk_wasm.caml_pasta_fp_plonk_index_domain_d4_size(index); @@ -44,7 +44,7 @@ function caml_pasta_fp_plonk_index_domain_d4_size(prover_index) { // Requires: plonk_wasm function caml_pasta_fp_plonk_index_domain_d8_size(prover_index) { var bytes = prover_index.serialize() - var index = plonk_wasm.prover_index_fp_from_bytes(bytes); + var index = plonk_wasm.prover_index_fp_deserialize(bytes); // TODO: ^ remove the round trip when napi has direct access to the object return plonk_wasm.caml_pasta_fp_plonk_index_domain_d8_size(index); @@ -58,7 +58,7 @@ function caml_pasta_fp_plonk_index_domain_d8_size(prover_index) { // Requires: plonk_wasm function caml_pasta_fq_plonk_index_max_degree(prover_index) { var bytes = prover_index.serialize() - var index = plonk_wasm.prover_index_fq_from_bytes(bytes); + var index = plonk_wasm.prover_index_fq_deserialize(bytes); // TODO: ^ remove the round trip when napi has direct access to the object return plonk_wasm.caml_pasta_fq_plonk_index_max_degree(index); @@ -68,7 +68,7 @@ function caml_pasta_fq_plonk_index_max_degree(prover_index) { // Requires: plonk_wasm function caml_pasta_fq_plonk_index_public_inputs(prover_index) { var bytes = prover_index.serialize() - var index = plonk_wasm.prover_index_fq_from_bytes(bytes); + var index = plonk_wasm.prover_index_fq_deserialize(bytes); // TODO: ^ remove the round trip when napi has direct access to the object return plonk_wasm.caml_pasta_fq_plonk_index_public_inputs(index); @@ -78,7 +78,7 @@ function caml_pasta_fq_plonk_index_public_inputs(prover_index) { // Requires: plonk_wasm function caml_pasta_fq_plonk_index_domain_d1_size(prover_index) { var bytes = prover_index.serialize() - var index = plonk_wasm.prover_index_fq_from_bytes(bytes); + var index = plonk_wasm.prover_index_fq_deserialize(bytes); // TODO: ^ remove the round trip when napi has direct access to the object return plonk_wasm.caml_pasta_fq_plonk_index_domain_d1_size(index); @@ -88,7 +88,7 @@ function caml_pasta_fq_plonk_index_domain_d1_size(prover_index) { // Requires: plonk_wasm function caml_pasta_fq_plonk_index_domain_d4_size(prover_index) { var bytes = prover_index.serialize() - var index = plonk_wasm.prover_index_fq_from_bytes(bytes); + var index = plonk_wasm.prover_index_fq_deserialize(bytes); // TODO: ^ remove the round trip when napi has direct access to the object return plonk_wasm.caml_pasta_fq_plonk_index_domain_d4_size(index); @@ -98,13 +98,33 @@ function caml_pasta_fq_plonk_index_domain_d4_size(prover_index) { // Requires: plonk_wasm function caml_pasta_fq_plonk_index_domain_d8_size(prover_index) { var bytes = prover_index.serialize() - var index = plonk_wasm.prover_index_fq_from_bytes(bytes); + var index = plonk_wasm.prover_index_fq_deserialize(bytes); // TODO: ^ remove the round trip when napi has direct access to the object return plonk_wasm.caml_pasta_fq_plonk_index_domain_d8_size(index); } +// Provides: caml_pasta_fp_plonk_index_serialize +// Requires: plonk_wasm +var caml_pasta_fp_plonk_index_serialize = function (index) { + // Workaround for napi issue where methods on External objects are not accessible + if (typeof index.serialize === 'function') { + return index.serialize(); + } + return plonk_wasm.prover_index_fp_serialize(index); +}; + +// Provides: caml_pasta_fp_plonk_index_deserialize +// Requires: plonk_wasm +var caml_pasta_fp_plonk_index_deserialize = function (index) { + // Workaround for napi issue where methods on External objects are not accessible + if (typeof index.deserialize === 'function') { + return index.deserialize(); + } + return plonk_wasm.prover_index_fp_deserialize(index); +}; + // Provides: caml_pasta_fp_plonk_index_create // Requires: plonk_wasm, tsRustConversionNative var caml_pasta_fp_plonk_index_create = function ( @@ -138,7 +158,7 @@ var caml_pasta_fp_plonk_index_create = function ( ); console.timeEnd("index_create"); - return plonk_wasm.prover_index_fp_to_bytes(t); + return t; }; // Provides: caml_pasta_fp_plonk_index_create_bytecode @@ -193,6 +213,26 @@ var caml_pasta_fp_plonk_index_write = function (append, t, path) { ); }; +// Provides: caml_pasta_fq_plonk_index_serialize +// Requires: plonk_wasm +var caml_pasta_fq_plonk_index_serialize = function (index) { + // Workaround for napi issue where methods on External objects are not accessible + if (typeof index.serialize === 'function') { + return index.serialize(); + } + return plonk_wasm.prover_index_fq_serialize(index); +}; + +// Provides: caml_pasta_fq_plonk_index_deserialize +// Requires: plonk_wasm +var caml_pasta_fq_plonk_index_deserialize = function (index) { + // Workaround for napi issue where methods on External objects are not accessible + if (typeof index.deserialize === 'function') { + return index.deserialize(); + } + return plonk_wasm.prover_index_fq_deserialize(index); +}; + // Provides: caml_pasta_fq_plonk_index_create // Requires: plonk_wasm, tsRustConversionNative var caml_pasta_fq_plonk_index_create = function ( @@ -214,7 +254,7 @@ var caml_pasta_fq_plonk_index_create = function ( console.log("anais: 3"); console.time("conversion") - var gate_vec = plonk_wasm.caml_pasta_fq_plonk_gate_vector_from_bytes(gates.serialize()); + var gate_vec = plonk_wasm.caml_pasta_fq_plonk_gate_vector_deserialize(gates.serialize()); var urs_ser = plonk_wasm.caml_fq_srs_from_bytes_external(urs.serialize()) console.timeEnd("conversion") console.log("anais: 4"); @@ -231,7 +271,7 @@ var caml_pasta_fq_plonk_index_create = function ( ); console.timeEnd("index_create"); - return plonk_wasm.prover_index_fq_to_bytes(t); + return t; }; // Provides: caml_pasta_fq_plonk_index_create_bytecode diff --git a/src/lib/crypto/kimchi_bindings/js/native/native-overrides/srs.js b/src/lib/crypto/kimchi_bindings/js/native/native-overrides/srs.js index b9d7329c7946..b0d73dd21bff 100644 --- a/src/lib/crypto/kimchi_bindings/js/native/native-overrides/srs.js +++ b/src/lib/crypto/kimchi_bindings/js/native/native-overrides/srs.js @@ -63,6 +63,20 @@ var caml_fq_srs_lagrange_commitments_whole_domain = // Requires: tsSrs var caml_fp_srs_lagrange_commitment = tsSrs.fp.lagrangeCommitment; +// Provides: caml_fp_srs_to_bytes_external +// Requires: plonk_wasm +var caml_fp_srs_to_bytes_external = function (srs) { + console.log("native caml_fp_srs_to_bytes_external"); + return plonk_wasm.caml_fp_srs_to_bytes_external(srs); +}; + +// Provides: caml_fp_srs_from_bytes_external +// Requires: plonk_wasm +var caml_fp_srs_from_bytes_external = function (bytes) { + console.log("native caml_fp_srs_from_bytes_external"); + return plonk_wasm.caml_fp_srs_from_bytes_external(bytes); +}; + // Provides: caml_fp_srs_lagrange_commitment // Requires: tsSrs var caml_fp_srs_lagrange_commitment = function (srs, i) { @@ -70,6 +84,19 @@ var caml_fp_srs_lagrange_commitment = function (srs, i) { return tsSrs.fp.lagrangeCommitment(srs, i); } +// Provides: caml_fp_srs_maybe_lagrange_commitment +// Requires: plonk_wasm, tsRustConversionNative +var caml_fp_srs_maybe_lagrange_commitment = function (srs, domain_size, i) { + console.log("native caml_fp_srs_maybe_lagrange_commitment"); + var result = plonk_wasm.caml_fp_srs_maybe_lagrange_commitment(srs, domain_size, i); + console.log("result", result); + if (result == null) return 0; // None + var polyComm = tsRustConversionNative.fp.polyCommFromRust(result); + console.log("polyComm", polyComm); + if (polyComm == undefined) return 0; // None + return [0, polyComm]; // Some(...) +}; + // Provides: caml_fp_srs_commit_evaluations // Requires: plonk_wasm, tsRustConversionNative var caml_fp_srs_commit_evaluations = function (t, domain_size, fps) { @@ -181,6 +208,17 @@ var caml_fq_srs_lagrange_commitment = function (srs, i) { return tsSrs.fq.lagrangeCommitment(srs, i); }; +// Provides: caml_fq_srs_maybe_lagrange_commitment +// Requires: plonk_wasm, tsRustConversionNative +var caml_fq_srs_maybe_lagrange_commitment = function (srs, domain_size, i) { + console.log("native caml_fq_srs_maybe_lagrange_commitment"); + var result = plonk_wasm.caml_fq_srs_maybe_lagrange_commitment(srs, domain_size, i); + if (result == null) return 0; // None + var polyComm = tsRustConversionNative.fq.polyCommFromRust(result); + if (polyComm == undefined) return 0; // None + return [0, polyComm]; // Some(...) +}; + // Provides: caml_fq_srs_commit_evaluations // Requires: plonk_wasm, tsRustConversionNative var caml_fq_srs_commit_evaluations = function (t, domain_size, fqs) { @@ -247,4 +285,4 @@ var caml_fq_srs_h = function (t) { var caml_fq_srs_add_lagrange_basis = function (srs, domain_size) { console.log("native caml_fq_srs_add_lagrange_basis"); return tsSrs.fq.addLagrangeBasis(srs, domain_size); -}; \ No newline at end of file +}; diff --git a/src/lib/crypto/kimchi_bindings/js/node_js/node_backend.js b/src/lib/crypto/kimchi_bindings/js/node_js/node_backend.js index 1576e7ec83a2..3cd882fe1b9f 100644 --- a/src/lib/crypto/kimchi_bindings/js/node_js/node_backend.js +++ b/src/lib/crypto/kimchi_bindings/js/node_js/node_backend.js @@ -11,10 +11,12 @@ var plonk_wasm = (function() { // IS SET var overrides = [ "prover_to_json", - "prover_index_fp_from_bytes", - "prover_index_fq_from_bytes", - "prover_index_fp_to_bytes", - "prover_index_fq_to_bytes", + "prover_index_fp_deserialize", + "prover_index_fq_deserialize", + "prover_index_fp_serialize", + "prover_index_fq_serialize", + "WasmPastaFpPlonkIndex", + "WasmPastaFqPlonkIndex", "caml_pasta_fp_poseidon_block_cipher", "caml_pasta_fq_poseidon_block_cipher", "caml_pasta_fp_plonk_proof_create", From 6f15cb8b8ef76a1c7c1d57d04da02836a0d6f36e Mon Sep 17 00:00:00 2001 From: querolita Date: Wed, 3 Dec 2025 20:07:14 +0100 Subject: [PATCH 28/30] submodule: update proof-systems --- src/lib/crypto/proof-systems | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/crypto/proof-systems b/src/lib/crypto/proof-systems index 1ae987ef343c..202e2d022ba6 160000 --- a/src/lib/crypto/proof-systems +++ b/src/lib/crypto/proof-systems @@ -1 +1 @@ -Subproject commit 1ae987ef343ce5924c74304958cf291017388b6b +Subproject commit 202e2d022ba63f6fb01ae8404ea5f147cc65b33e From e7dce81bba84cc7d88fca18a63175feb188277e2 Mon Sep 17 00:00:00 2001 From: Shigoto-dev19 Date: Sun, 7 Dec 2025 21:05:41 -0300 Subject: [PATCH 29/30] shigoto + anais kimchi bindings changes for the first native prover poc --- .../js/bindings/verifier-index.js | 135 +----------------- .../js/native/native-overrides/proof.js | 30 ++-- .../native/native-overrides/prover-index.js | 71 +++++++-- .../js/native/native-overrides/srs.js | 38 +++++ .../native/native-overrides/verifier-index.js | 130 +++++++++++++++++ .../js/node_js/node_backend.js | 41 +++++- 6 files changed, 282 insertions(+), 163 deletions(-) diff --git a/src/lib/crypto/kimchi_bindings/js/bindings/verifier-index.js b/src/lib/crypto/kimchi_bindings/js/bindings/verifier-index.js index ab662007c714..5a4329e4e775 100644 --- a/src/lib/crypto/kimchi_bindings/js/bindings/verifier-index.js +++ b/src/lib/crypto/kimchi_bindings/js/bindings/verifier-index.js @@ -19,137 +19,4 @@ var caml_opt_to_rust = function (caml_optional_value, to_rust) { } else { return to_rust(caml_optional_value[1]); } -}; - -// Provides: caml_pasta_fp_plonk_verifier_index_create -// Requires: plonk_wasm, tsRustConversion -var caml_pasta_fp_plonk_verifier_index_create = function (x) { - console.log("caml_pasta_fp_plonk_verifier_index_create", x) - var bytes = plonk_wasm.prover_index_fp_to_bytes(x); - console.log("bytes", bytes) - var index = plonk_wasm.WasmPastaFpPlonkIndex.deserialize(bytes) - console.log("index", index) - var vk = plonk_wasm.caml_pasta_fp_plonk_verifier_index_create(index); - console.log("vk", vk) - return tsRustConversion.fp.verifierIndexFromRust(vk); -}; - -// Provides: caml_pasta_fp_plonk_verifier_index_read -// Requires: plonk_wasm, caml_jsstring_of_string, tsRustConversion -var caml_pasta_fp_plonk_verifier_index_read = function (offset, urs, path) { - console.log("caml_pasta_fp_plonk_verifier_index_read") - - if (offset === 0) { - offset = undefined; - } else { - offset = offset[1]; - } - return tsRustConversion.fp.verifierIndexFromRust( - plonk_wasm.caml_pasta_fp_plonk_verifier_index_read( - offset, - urs, - caml_jsstring_of_string(path) - ) - ); -}; - -// Provides: caml_pasta_fp_plonk_verifier_index_write -// Requires: plonk_wasm, caml_jsstring_of_string, tsRustConversion -var caml_pasta_fp_plonk_verifier_index_write = function (append, t, path) { - console.log("caml_pasta_fp_plonk_verifier_index_write") - - if (append === 0) { - append = undefined; - } else { - append = append[1]; - } - return plonk_wasm.caml_pasta_fp_plonk_verifier_index_write( - append, - tsRustConversion.fp.verifierIndexToRust(t), - caml_jsstring_of_string(path) - ); -}; - - -// Provides: caml_pasta_fp_plonk_verifier_index_dummy -// Requires: plonk_wasm, tsRustConversion -var caml_pasta_fp_plonk_verifier_index_dummy = function () { - console.log("caml_pasta_fp_plonk_verifier_index_dummy") - - var res = plonk_wasm.caml_pasta_fp_plonk_verifier_index_dummy(); - return tsRustConversion.fp.verifierIndexFromRust(res); -}; - -// Provides: caml_pasta_fp_plonk_verifier_index_deep_copy -// Requires: plonk_wasm, tsRustConversion -var caml_pasta_fp_plonk_verifier_index_deep_copy = function (x) { - console.log("caml_pasta_fp_plonk_verifier_index_deep_copy") - return tsRustConversion.fp.verifierIndexFromRust( - plonk_wasm.caml_pasta_fp_plonk_verifier_index_deep_copy( - tsRustConversion.fp.verifierIndexToRust(x) - ) - ); -}; - -// Provides: caml_pasta_fq_plonk_verifier_index_create -// Requires: plonk_wasm, tsRustConversion -var caml_pasta_fq_plonk_verifier_index_create = function (x) { - console.log("caml_pasta_fq_plonk_verifier_index_create") - return tsRustConversion.fq.verifierIndexFromRust( - 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 -var caml_pasta_fq_plonk_verifier_index_read = function (offset, urs, path) { - console.log("caml_pasta_fq_plonk_verifier_index_read") - if (offset === 0) { - offset = undefined; - } else { - offset = offset[1]; - } - return tsRustConversion.fq.verifierIndexFromRust( - plonk_wasm.caml_pasta_fq_plonk_verifier_index_read( - offset, - urs, - caml_jsstring_of_string(path) - ) - ); -}; - -// Provides: caml_pasta_fq_plonk_verifier_index_write -// Requires: plonk_wasm, caml_jsstring_of_string, tsRustConversion -var caml_pasta_fq_plonk_verifier_index_write = function (append, t, path) { - console.log("caml_pasta_fq_plonk_verifier_index_write") - if (append === 0) { - append = undefined; - } else { - append = append[1]; - } - return plonk_wasm.caml_pasta_fq_plonk_verifier_index_write( - append, - tsRustConversion.fq.verifierIndexToRust(t), - caml_jsstring_of_string(path) - ); -}; - -// Provides: caml_pasta_fq_plonk_verifier_index_dummy -// Requires: plonk_wasm, tsRustConversion -var caml_pasta_fq_plonk_verifier_index_dummy = function () { - console.log("caml_pasta_fq_plonk_verifier_index_dummy") - return tsRustConversion.fq.verifierIndexFromRust( - plonk_wasm.caml_pasta_fq_plonk_verifier_index_dummy() - ); -}; - -// Provides: caml_pasta_fq_plonk_verifier_index_deep_copy -// Requires: plonk_wasm, tsRustConversion, tsRustConversion -var caml_pasta_fq_plonk_verifier_index_deep_copy = function (x) { - console.log("caml_pasta_fq_plonk_verifier_index_deep_copy") - return tsRustConversion.fq.verifierIndexFromRust( - plonk_wasm.caml_pasta_fq_plonk_verifier_index_deep_copy( - tsRustConversion.fq.verifierIndexToRust(x) - ) - ); -}; +}; \ No newline at end of file diff --git a/src/lib/crypto/kimchi_bindings/js/native/native-overrides/proof.js b/src/lib/crypto/kimchi_bindings/js/native/native-overrides/proof.js index 6955b71376f5..2a81aa0c3990 100644 --- a/src/lib/crypto/kimchi_bindings/js/native/native-overrides/proof.js +++ b/src/lib/crypto/kimchi_bindings/js/native/native-overrides/proof.js @@ -12,22 +12,30 @@ var caml_pasta_fp_plonk_proof_create = function ( prev_sgs ) { var w = new plonk_wasm.WasmVecVecFp(witness_cols.length - 1); + var ww = new w.WasmVecVecFp(witness_cols.length - 1) for (var i = 1; i < witness_cols.length; i++) { - w.push(tsRustConversionNative.fp.vectorToRust(witness_cols[i])); + ww.push(tsRustConversionNative.fp.vectorToRust(witness_cols[i])); } - witness_cols = w; + + witness_cols = ww; prev_challenges = tsRustConversionNative.fp.vectorToRust(prev_challenges); var wasm_runtime_tables = tsRustConversionNative.fp.runtimeTablesToRust(caml_runtime_tables); prev_sgs = tsRustConversionNative.fp.pointsToRust(prev_sgs); - /*w.push(tsRustConversion.fp.vectorToRust(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); + + /* + index: &External<$NapiIndex>, + witness: $NapiVecVec, + runtime_tables: NapiVector, + prev_challenges: NapiFlatVector<$NapiF>, + prev_sgs: NapiVector<$NapiG>, */ + + console.log('index: ', index); + console.log('witness cols: ', witness_cols) + console.log("wasm_runtime_tables: ", wasm_runtime_tables) + console.log('prev challenges: ', prev_challenges) + console.log('prev_sgs: ', prev_sgs) var proof = plonk_wasm.caml_pasta_fp_plonk_proof_create( index, witness_cols, @@ -35,8 +43,8 @@ var caml_pasta_fp_plonk_proof_create = function ( prev_challenges, prev_sgs ); + console.log('proof?') return tsRustConversionNative.fp.proofFromRust(proof); - /* return tsRustConversion.fp.proofFromRust(proof); */ }; // Provides: caml_pasta_fp_plonk_proof_verify @@ -120,7 +128,7 @@ var caml_pasta_fq_plonk_proof_verify = function (index, proof) { var caml_pasta_fq_plonk_proof_batch_verify = function (indexes, proofs) { indexes = tsRustConversionNative.mapMlArrayToRustVector( indexes, - tsRustConversionNatsRustConversionNativetive.fq.verifierIndexToRust + tsRustConversionNative.fq.verifierIndexToRust ); proofs = tsRustConversionNative.mapMlArrayToRustVector( proofs, diff --git a/src/lib/crypto/kimchi_bindings/js/native/native-overrides/prover-index.js b/src/lib/crypto/kimchi_bindings/js/native/native-overrides/prover-index.js index e7d835b7930d..cf9a90b74969 100644 --- a/src/lib/crypto/kimchi_bindings/js/native/native-overrides/prover-index.js +++ b/src/lib/crypto/kimchi_bindings/js/native/native-overrides/prover-index.js @@ -4,7 +4,7 @@ // Requires: plonk_wasm function caml_pasta_fp_plonk_index_max_degree(prover_index) { var bytes = prover_index.serialize() - var index = plonk_wasm.prover_index_fp_from_bytes(bytes); + var index = plonk_wasm.prover_index_fp_deserialize(bytes); // TODO: ^ remove the round trip when napi has direct access to the object return plonk_wasm.caml_pasta_fp_plonk_index_max_degree(index); @@ -14,7 +14,7 @@ function caml_pasta_fp_plonk_index_max_degree(prover_index) { // Requires: plonk_wasm function caml_pasta_fp_plonk_index_public_inputs(prover_index) { var bytes = prover_index.serialize() - var index = plonk_wasm.prover_index_fp_from_bytes(bytes); + var index = plonk_wasm.prover_index_fp_deserialize(bytes); // TODO: ^ remove the round trip when napi has direct access to the object return plonk_wasm.caml_pasta_fp_plonk_index_public_inputs(index); @@ -24,7 +24,7 @@ function caml_pasta_fp_plonk_index_public_inputs(prover_index) { // Requires: plonk_wasm function caml_pasta_fp_plonk_index_domain_d1_size(prover_index) { var bytes = prover_index.serialize() - var index = plonk_wasm.prover_index_fp_from_bytes(bytes); + var index = plonk_wasm.prover_index_fp_deserialize(bytes); // TODO: ^ remove the round trip when napi has direct access to the object return plonk_wasm.caml_pasta_fp_plonk_index_domain_d1_size(index); @@ -34,7 +34,7 @@ function caml_pasta_fp_plonk_index_domain_d1_size(prover_index) { // Requires: plonk_wasm function caml_pasta_fp_plonk_index_domain_d4_size(prover_index) { var bytes = prover_index.serialize() - var index = plonk_wasm.prover_index_fp_from_bytes(bytes); + var index = plonk_wasm.prover_index_fp_deserialize(bytes); // TODO: ^ remove the round trip when napi has direct access to the object return plonk_wasm.caml_pasta_fp_plonk_index_domain_d4_size(index); @@ -44,7 +44,7 @@ function caml_pasta_fp_plonk_index_domain_d4_size(prover_index) { // Requires: plonk_wasm function caml_pasta_fp_plonk_index_domain_d8_size(prover_index) { var bytes = prover_index.serialize() - var index = plonk_wasm.prover_index_fp_from_bytes(bytes); + var index = plonk_wasm.prover_index_fp_deserialize(bytes); // TODO: ^ remove the round trip when napi has direct access to the object return plonk_wasm.caml_pasta_fp_plonk_index_domain_d8_size(index); @@ -58,7 +58,7 @@ function caml_pasta_fp_plonk_index_domain_d8_size(prover_index) { // Requires: plonk_wasm function caml_pasta_fq_plonk_index_max_degree(prover_index) { var bytes = prover_index.serialize() - var index = plonk_wasm.prover_index_fq_from_bytes(bytes); + var index = plonk_wasm.prover_index_fq_deserialize(bytes); // TODO: ^ remove the round trip when napi has direct access to the object return plonk_wasm.caml_pasta_fq_plonk_index_max_degree(index); @@ -68,7 +68,7 @@ function caml_pasta_fq_plonk_index_max_degree(prover_index) { // Requires: plonk_wasm function caml_pasta_fq_plonk_index_public_inputs(prover_index) { var bytes = prover_index.serialize() - var index = plonk_wasm.prover_index_fq_from_bytes(bytes); + var index = plonk_wasm.prover_index_fq_deserialize(bytes); // TODO: ^ remove the round trip when napi has direct access to the object return plonk_wasm.caml_pasta_fq_plonk_index_public_inputs(index); @@ -78,7 +78,7 @@ function caml_pasta_fq_plonk_index_public_inputs(prover_index) { // Requires: plonk_wasm function caml_pasta_fq_plonk_index_domain_d1_size(prover_index) { var bytes = prover_index.serialize() - var index = plonk_wasm.prover_index_fq_from_bytes(bytes); + var index = plonk_wasm.prover_index_fq_deserialize(bytes); // TODO: ^ remove the round trip when napi has direct access to the object return plonk_wasm.caml_pasta_fq_plonk_index_domain_d1_size(index); @@ -88,7 +88,7 @@ function caml_pasta_fq_plonk_index_domain_d1_size(prover_index) { // Requires: plonk_wasm function caml_pasta_fq_plonk_index_domain_d4_size(prover_index) { var bytes = prover_index.serialize() - var index = plonk_wasm.prover_index_fq_from_bytes(bytes); + var index = plonk_wasm.prover_index_fq_deserialize(bytes); // TODO: ^ remove the round trip when napi has direct access to the object return plonk_wasm.caml_pasta_fq_plonk_index_domain_d4_size(index); @@ -98,13 +98,35 @@ function caml_pasta_fq_plonk_index_domain_d4_size(prover_index) { // Requires: plonk_wasm function caml_pasta_fq_plonk_index_domain_d8_size(prover_index) { var bytes = prover_index.serialize() - var index = plonk_wasm.prover_index_fq_from_bytes(bytes); + var index = plonk_wasm.prover_index_fq_deserialize(bytes); // TODO: ^ remove the round trip when napi has direct access to the object return plonk_wasm.caml_pasta_fq_plonk_index_domain_d8_size(index); } +// Provides: caml_pasta_fp_plonk_index_serialize +// Requires: plonk_wasm +var caml_pasta_fp_plonk_index_serialize = function (index) { + // Workaround for napi issue where methods on External objects are not accessible + if (typeof index.serialize === 'function') { + return index.serialize(); + } + return plonk_wasm.prover_index_fp_serialize(index); +}; + +// Provides: caml_pasta_fp_plonk_index_deserialize +// Requires: plonk_wasm +var caml_pasta_fp_plonk_index_deserialize = function (index) { + // Workaround for napi issue where methods on External objects are not accessible + if (typeof index.deserialize === 'function') { + return index.deserialize(); + } + // const deserialized = plonk_wasm.prover_index_fp_deserialize(index); + // console.log('deserialized index: ', dese) + return plonk_wasm.prover_index_fp_deserialize(index); +}; + // Provides: caml_pasta_fp_plonk_index_create // Requires: plonk_wasm, tsRustConversionNative var caml_pasta_fp_plonk_index_create = function ( @@ -116,6 +138,7 @@ var caml_pasta_fp_plonk_index_create = function ( urs, lazy_mode ) { + console.log('passing through wasm lookup tables') var wasm_lookup_tables = tsRustConversionNative.fp.lookupTablesToRust(caml_lookup_tables); var wasm_runtime_table_cfgs = tsRustConversionNative.fp.runtimeTableCfgsToRust( @@ -138,7 +161,7 @@ var caml_pasta_fp_plonk_index_create = function ( ); console.timeEnd("index_create"); - return plonk_wasm.prover_index_fp_to_bytes(t); + return t; }; // Provides: caml_pasta_fp_plonk_index_create_bytecode @@ -193,6 +216,26 @@ var caml_pasta_fp_plonk_index_write = function (append, t, path) { ); }; +// Provides: caml_pasta_fq_plonk_index_serialize +// Requires: plonk_wasm +var caml_pasta_fq_plonk_index_serialize = function (index) { + // Workaround for napi issue where methods on External objects are not accessible + if (typeof index.serialize === 'function') { + return index.serialize(); + } + return plonk_wasm.prover_index_fq_serialize(index); +}; + +// Provides: caml_pasta_fq_plonk_index_deserialize +// Requires: plonk_wasm +var caml_pasta_fq_plonk_index_deserialize = function (index) { + // Workaround for napi issue where methods on External objects are not accessible + if (typeof index.deserialize === 'function') { + return index.deserialize(); + } + return plonk_wasm.prover_index_fq_deserialize(index); +}; + // Provides: caml_pasta_fq_plonk_index_create // Requires: plonk_wasm, tsRustConversionNative var caml_pasta_fq_plonk_index_create = function ( @@ -214,7 +257,7 @@ var caml_pasta_fq_plonk_index_create = function ( console.log("anais: 3"); console.time("conversion") - var gate_vec = plonk_wasm.caml_pasta_fq_plonk_gate_vector_from_bytes(gates.serialize()); + var gate_vec = plonk_wasm.caml_pasta_fq_plonk_gate_vector_deserialize(gates.serialize()); var urs_ser = plonk_wasm.caml_fq_srs_from_bytes_external(urs.serialize()) console.timeEnd("conversion") console.log("anais: 4"); @@ -231,7 +274,7 @@ var caml_pasta_fq_plonk_index_create = function ( ); console.timeEnd("index_create"); - return plonk_wasm.prover_index_fq_to_bytes(t); + return t; }; // Provides: caml_pasta_fq_plonk_index_create_bytecode @@ -284,4 +327,4 @@ var caml_pasta_fq_plonk_index_write = function (append, t, path) { t, caml_jsstring_of_string(path) ); -}; +}; \ No newline at end of file diff --git a/src/lib/crypto/kimchi_bindings/js/native/native-overrides/srs.js b/src/lib/crypto/kimchi_bindings/js/native/native-overrides/srs.js index b9d7329c7946..c401b58468f0 100644 --- a/src/lib/crypto/kimchi_bindings/js/native/native-overrides/srs.js +++ b/src/lib/crypto/kimchi_bindings/js/native/native-overrides/srs.js @@ -63,6 +63,20 @@ var caml_fq_srs_lagrange_commitments_whole_domain = // Requires: tsSrs var caml_fp_srs_lagrange_commitment = tsSrs.fp.lagrangeCommitment; +// Provides: caml_fp_srs_to_bytes_external +// Requires: plonk_wasm +var caml_fp_srs_to_bytes_external = function (srs) { + console.log("native caml_fp_srs_to_bytes_external"); + return plonk_wasm.caml_fp_srs_to_bytes_external(srs); +}; + +// Provides: caml_fp_srs_from_bytes_external +// Requires: plonk_wasm +var caml_fp_srs_from_bytes_external = function (bytes) { + console.log("native caml_fp_srs_from_bytes_external"); + return plonk_wasm.caml_fp_srs_from_bytes_external(bytes); +}; + // Provides: caml_fp_srs_lagrange_commitment // Requires: tsSrs var caml_fp_srs_lagrange_commitment = function (srs, i) { @@ -70,6 +84,19 @@ var caml_fp_srs_lagrange_commitment = function (srs, i) { return tsSrs.fp.lagrangeCommitment(srs, i); } +// Provides: caml_fp_srs_maybe_lagrange_commitment +// Requires: plonk_wasm, tsRustConversionNative +var caml_fp_srs_maybe_lagrange_commitment = function (srs, domain_size, i) { + console.log("native caml_fp_srs_maybe_lagrange_commitment"); + var result = plonk_wasm.caml_fp_srs_maybe_lagrange_commitment(srs, domain_size, i); + console.log("result", result); + if (result == null) return 0; // None + var polyComm = tsRustConversionNative.fp.polyCommFromRust(result); + console.log("polyComm", polyComm); + if (polyComm == undefined) return 0; // None + return [0, polyComm]; // Some(...) +}; + // Provides: caml_fp_srs_commit_evaluations // Requires: plonk_wasm, tsRustConversionNative var caml_fp_srs_commit_evaluations = function (t, domain_size, fps) { @@ -181,6 +208,17 @@ var caml_fq_srs_lagrange_commitment = function (srs, i) { return tsSrs.fq.lagrangeCommitment(srs, i); }; +// Provides: caml_fq_srs_maybe_lagrange_commitment +// Requires: plonk_wasm, tsRustConversionNative +var caml_fq_srs_maybe_lagrange_commitment = function (srs, domain_size, i) { + console.log("native caml_fq_srs_maybe_lagrange_commitment"); + var result = plonk_wasm.caml_fq_srs_maybe_lagrange_commitment(srs, domain_size, i); + if (result == null) return 0; // None + var polyComm = tsRustConversionNative.fq.polyCommFromRust(result); + if (polyComm == undefined) return 0; // None + return [0, polyComm]; // Some(...) +}; + // Provides: caml_fq_srs_commit_evaluations // Requires: plonk_wasm, tsRustConversionNative var caml_fq_srs_commit_evaluations = function (t, domain_size, fqs) { diff --git a/src/lib/crypto/kimchi_bindings/js/native/native-overrides/verifier-index.js b/src/lib/crypto/kimchi_bindings/js/native/native-overrides/verifier-index.js index 1a3b01f44aab..776b88a7ad59 100644 --- a/src/lib/crypto/kimchi_bindings/js/native/native-overrides/verifier-index.js +++ b/src/lib/crypto/kimchi_bindings/js/native/native-overrides/verifier-index.js @@ -1,5 +1,13 @@ /* global plonk_wasm, tsRustConversionNative */ +// Provides: caml_pasta_fp_plonk_verifier_index_create +// Requires: plonk_wasm, tsRustConversionNative +var caml_pasta_fp_plonk_verifier_index_create = function (x) { + console.log("jsoo caml_pasta_fp_plonk_verifier_index_create x", x); + var vk = plonk_wasm.caml_pasta_fp_plonk_verifier_index_create(x); + console.log("vk", vk) + return tsRustConversionNative.fp.verifierIndexFromRust(vk); +}; // Provides: caml_pasta_fq_plonk_verifier_index_shifts // Requires: plonk_wasm, tsRustConversionNative @@ -20,6 +28,74 @@ var caml_pasta_fq_plonk_verifier_index_shifts = function (log2_size) { } }; +// Provides: caml_pasta_fp_plonk_verifier_index_read +// Requires: plonk_wasm, caml_jsstring_of_string, tsRustConversionNative +var caml_pasta_fp_plonk_verifier_index_read = function (offset, urs, path) { + console.log("caml_pasta_fp_plonk_verifier_index_read") + + if (offset === 0) { + offset = undefined; + } else { + offset = offset[1]; + } + return tsRustConversionNative.fp.verifierIndexFromRust( + plonk_wasm.caml_pasta_fp_plonk_verifier_index_read( + offset, + urs, + caml_jsstring_of_string(path) + ) + ); +}; + +// Provides: caml_pasta_fp_plonk_verifier_index_write +// Requires: plonk_wasm, caml_jsstring_of_string, tsRustConversionNative +var caml_pasta_fp_plonk_verifier_index_write = function (append, t, path) { + console.log("caml_pasta_fp_plonk_verifier_index_write") + + if (append === 0) { + append = undefined; + } else { + append = append[1]; + } + return plonk_wasm.caml_pasta_fp_plonk_verifier_index_write( + append, + tsRustConversionNative.fp.verifierIndexToRust(t), + caml_jsstring_of_string(path) + ); +}; + + +// Provides: caml_pasta_fp_plonk_verifier_index_dummy +// Requires: plonk_wasm, tsRustConversionNative +var caml_pasta_fp_plonk_verifier_index_dummy = function () { + console.log("caml_pasta_fp_plonk_verifier_index_dummy") + + var res = plonk_wasm.caml_pasta_fp_plonk_verifier_index_dummy(); + return tsRustConversionNative.fp.verifierIndexFromRust(res); +}; + +// Provides: caml_pasta_fp_plonk_verifier_index_deep_copy +// Requires: plonk_wasm, tsRustConversionNative +var caml_pasta_fp_plonk_verifier_index_deep_copy = function (x) { + console.log("caml_pasta_fp_plonk_verifier_index_deep_copy") + return tsRustConversionNative.fp.verifierIndexFromRust( + plonk_wasm.caml_pasta_fp_plonk_verifier_index_deep_copy( + tsRustConversionNative.fp.verifierIndexToRust(x) + ) + ); +}; + + +// Provides: caml_pasta_fq_plonk_verifier_index_create +// Requires: plonk_wasm, tsRustConversionNative +var caml_pasta_fq_plonk_verifier_index_create = function (x) { + console.log("caml_pasta_fq_plonk_verifier_index_create") + return tsRustConversionNative.fq.verifierIndexFromRust( + plonk_wasm.caml_pasta_fq_plonk_verifier_index_create(x) + ); +}; + + // Provides: caml_pasta_fp_plonk_verifier_index_shifts // Requires: plonk_wasm, tsRustConversionNative var caml_pasta_fp_plonk_verifier_index_shifts = function (log2_size) { @@ -27,3 +103,57 @@ var caml_pasta_fp_plonk_verifier_index_shifts = function (log2_size) { plonk_wasm.caml_pasta_fp_plonk_verifier_index_shifts(log2_size) ); }; + +// Provides: caml_pasta_fq_plonk_verifier_index_read +// Requires: plonk_wasm, caml_jsstring_of_string, tsRustConversionNative +var caml_pasta_fq_plonk_verifier_index_read = function (offset, urs, path) { + console.log("caml_pasta_fq_plonk_verifier_index_read") + if (offset === 0) { + offset = undefined; + } else { + offset = offset[1]; + } + return tsRustConversionNative.fq.verifierIndexFromRust( + plonk_wasm.caml_pasta_fq_plonk_verifier_index_read( + offset, + urs, + caml_jsstring_of_string(path) + ) + ); +}; + +// Provides: caml_pasta_fq_plonk_verifier_index_write +// Requires: plonk_wasm, caml_jsstring_of_string, tsRustConversionNative +var caml_pasta_fq_plonk_verifier_index_write = function (append, t, path) { + console.log("caml_pasta_fq_plonk_verifier_index_write") + if (append === 0) { + append = undefined; + } else { + append = append[1]; + } + return plonk_wasm.caml_pasta_fq_plonk_verifier_index_write( + append, + tsRustConversionNative.fq.verifierIndexToRust(t), + caml_jsstring_of_string(path) + ); +}; + +// Provides: caml_pasta_fq_plonk_verifier_index_dummy +// Requires: plonk_wasm, tsRustConversionNative +var caml_pasta_fq_plonk_verifier_index_dummy = function () { + console.log("caml_pasta_fq_plonk_verifier_index_dummy") + return tsRustConversionNative.fq.verifierIndexFromRust( + plonk_wasm.caml_pasta_fq_plonk_verifier_index_dummy() + ); +}; + +// Provides: caml_pasta_fq_plonk_verifier_index_deep_copy +// Requires: plonk_wasm, tsRustConversionNative, tsRustConversionNative +var caml_pasta_fq_plonk_verifier_index_deep_copy = function (x) { + console.log("caml_pasta_fq_plonk_verifier_index_deep_copy") + return tsRustConversionNative.fq.verifierIndexFromRust( + plonk_wasm.caml_pasta_fq_plonk_verifier_index_deep_copy( + tsRustConversionNative.fq.verifierIndexToRust(x) + ) + ); +}; \ No newline at end of file diff --git a/src/lib/crypto/kimchi_bindings/js/node_js/node_backend.js b/src/lib/crypto/kimchi_bindings/js/node_js/node_backend.js index b274522dc43f..1be6af9878cf 100644 --- a/src/lib/crypto/kimchi_bindings/js/node_js/node_backend.js +++ b/src/lib/crypto/kimchi_bindings/js/node_js/node_backend.js @@ -11,14 +11,43 @@ var plonk_wasm = (function() { // IS SET var overrides = [ "prover_to_json", - "prover_index_fp_from_bytes", - "prover_index_fq_from_bytes", - "prover_index_fp_to_bytes", - "prover_index_fq_to_bytes", + "prover_index_fp_deserialize", + "prover_index_fq_deserialize", + "prover_index_fp_serialize", + "prover_index_fq_serialize", + "WasmPastaFpPlonkIndex", + "WasmPastaFqPlonkIndex", "caml_pasta_fp_poseidon_block_cipher", "caml_pasta_fq_poseidon_block_cipher", "caml_pasta_fp_plonk_proof_create", + "WasmFpPlonkVerifierIndex", + "WasmFqPlonkVerifierIndex", + "WasmFpDomain", + "WasmFqDomain", + "WasmFpShifts", + "WasmFqShifts", + "WasmFpLookupSelectors", + "WasmFqLookupSelectors", + "WasmFpLookupVerifierIndex", + "WasmFqLookupVerifierIndex", + "WasmFpPlonkVerificationEvals", + "WasmFqPlonkVerificationEvals", + "WasmFpPlonkLookupVerifierIndex", + "WasmFqPlonkLookupVerifierIndex", "caml_pasta_fp_plonk_verifier_index_create", + "caml_pasta_fq_plonk_verifier_index_create", + "caml_pasta_fp_plonk_verifier_index_read", + "caml_pasta_fq_plonk_verifier_index_read", + "caml_pasta_fp_plonk_verifier_index_write", + "caml_pasta_fq_plonk_verifier_index_write", + "caml_pasta_fp_plonk_verifier_index_dummy", + "caml_pasta_fq_plonk_verifier_index_dummy", + "caml_pasta_fp_plonk_verifier_index_serialize", + "caml_pasta_fq_plonk_verifier_index_serialize", + "caml_pasta_fp_plonk_verifier_index_deserialize", + "caml_pasta_fq_plonk_verifier_index_deserialize", + "caml_pasta_fp_plonk_verifier_index_deep_copy", + "caml_pasta_fq_plonk_verifier_index_deep_copy", "caml_pasta_fp_plonk_verifier_index_shifts", "caml_pasta_fq_plonk_verifier_index_shifts", "caml_pasta_fp_plonk_gate_vector_create", @@ -127,6 +156,10 @@ var plonk_wasm = (function() { "WasmFqProofEvaluations", "WasmFpProverCommitments", "WasmFqProverCommitments", + "WasmVecVecFp", + "WasmVecVecFq", + "WasmFpRuntimeTable", + "WasmFqRuntimeTable", ]; overrides.forEach(function (override) { From ebfe5d874f09b5562d40e9eed6c647310cf9d2f1 Mon Sep 17 00:00:00 2001 From: querolita Date: Mon, 8 Dec 2025 18:53:31 +0100 Subject: [PATCH 30/30] submodule: update proof-systems --- src/lib/crypto/proof-systems | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/crypto/proof-systems b/src/lib/crypto/proof-systems index 75bd4383f435..1d1d52480279 160000 --- a/src/lib/crypto/proof-systems +++ b/src/lib/crypto/proof-systems @@ -1 +1 @@ -Subproject commit 75bd4383f435437ae0d462ac0f05afc98a71a159 +Subproject commit 1d1d5248027972bffc553a146877423e2a02854d