Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@ 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")
var vk = plonk_wasm.caml_pasta_fp_plonk_verifier_index_create(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);
};

Expand Down
4 changes: 3 additions & 1 deletion src/lib/crypto/kimchi_bindings/js/dune
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
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
native/native-overrides/verifier-index.js))
(instrumentation
(backend bisect_ppx))
(preprocess
Expand Down
14 changes: 14 additions & 0 deletions src/lib/crypto/kimchi_bindings/js/native/header-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> = {};
type NapiFlatVector<T> = {};
type WasmVecVecFq = {};
type WasmVecVecFp = {};
type Self = {};

// Header section end
Original file line number Diff line number Diff line change
@@ -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);
};
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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,
Expand All @@ -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")
Expand Down
51 changes: 39 additions & 12 deletions src/lib/crypto/kimchi_bindings/js/native/native-overrides/srs.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -169,15 +189,19 @@ 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);
};

// 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);
Expand Down Expand Up @@ -212,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);
};
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 11 additions & 10 deletions src/lib/crypto/kimchi_bindings/js/node_js/node_backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -61,8 +59,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",
Expand All @@ -84,16 +82,19 @@ 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] = native[override]
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, x11, x12);
}
})
wasm.native = true;
} catch (e) {
Expand All @@ -104,4 +105,4 @@ var plonk_wasm = (function() {
}
}
return wasm
})()
})()