diff --git a/crypto/bindings/srs.ts b/crypto/bindings/srs.ts index 05cb2bd7..073381a1 100644 --- a/crypto/bindings/srs.ts +++ b/crypto/bindings/srs.ts @@ -77,7 +77,8 @@ function srsPerField(f: 'fp' | 'fq', wasm: Wasm, conversion: RustConversion) { let setSrs = wasm[`caml_${f}_srs_set`]; let maybeLagrangeCommitment = wasm[`caml_${f}_srs_maybe_lagrange_commitment`]; - let lagrangeCommitment = wasm[`caml_${f}_srs_lagrange_commitment`]; + let lagrangeCommitment = (srs: WasmFpSrs, domain_size: number, i: number) => + wasm[`caml_${f}_srs_lagrange_commitment`](srs, domain_size, i); let setLagrangeBasis = wasm[`caml_${f}_srs_set_lagrange_basis`]; let getLagrangeBasis = (srs: WasmSrs, n: number) => wasm[`caml_${f}_srs_get_lagrange_basis`](srs, n); @@ -158,14 +159,16 @@ function srsPerField(f: 'fp' | 'fq', wasm: Wasm, conversion: RustConversion) { if (didRead !== true) { // not in cache - let wasmComms = getLagrangeBasis(srs, domainSize); - if (cache.canWrite) { + // TODO: this code path will throw on the web since `caml_${f}_srs_get_lagrange_basis` is not properly implemented + // using a writable cache in the browser seems to be fairly uncommon though, so it's at least an 80/20 solution + let wasmComms = getLagrangeBasis(srs, domainSize); let mlComms = conversion[f].polyCommsFromRust(wasmComms); let comms = polyCommsToJSON(mlComms); let bytes = new TextEncoder().encode(JSON.stringify(comms)); - writeCache(cache, header, bytes); + } else { + lagrangeCommitment(srs, domainSize, i); } } diff --git a/crypto/elliptic-curve.ts b/crypto/elliptic-curve.ts index 001a464e..4e823e9d 100644 --- a/crypto/elliptic-curve.ts +++ b/crypto/elliptic-curve.ts @@ -402,7 +402,7 @@ function projectiveOnCurve( a: bigint ) { // substitution x -> x/z^2 and y -> y/z^3 gives - // the equation y^2 = x^3 + a*z^4 + b*z^6 + // the equation y^2 = x^3 + a*x*z^4 + b*z^6 // (note: we allow a restricted set of x,y for z==0; this seems fine) let x3 = mod(mod(x * x, p) * x, p); let y2 = mod(y * y, p); diff --git a/js/web/web-backend.js b/js/web/web-backend.js index ad1be16a..e742bec2 100644 --- a/js/web/web-backend.js +++ b/js/web/web-backend.js @@ -135,6 +135,8 @@ function overrideBindings(plonk_wasm, worker) { let spec = workerSpec(plonk_wasm); for (let key in spec) { plonk_wasm[key] = (...args) => { + if (spec[key].disabled) + throw Error(`Wasm method '${key}' is disabled on the web.`); let u32_ptr = wasm.create_zero_u32_ptr(); worker.postMessage({ type: 'run', diff --git a/js/web/worker-spec.js b/js/web/worker-spec.js index 9e00a6b4..af659f6a 100644 --- a/js/web/worker-spec.js +++ b/js/web/worker-spec.js @@ -105,11 +105,20 @@ function workerSpec(wasm) { res: wasm.WasmFqSrs, }, caml_fp_srs_get_lagrange_basis: { + disabled: true, args: [wasm.WasmFpSrs, undefined /* number */], + // TODO: returning a UintXArray does not work: + // the worker wrapper excepts the return value to be a number + // that can be stored in a single u32. + // A UintXArray is coerced into a 0 pointer, which doesn't trigger `wait_until_non_zero()`, + // which means the main worker just keeps spinning waiting for a response. + // A proper solution would be to wrap the return value in a pointer! res: undefined /* UintXArray */, }, caml_fq_srs_get_lagrange_basis: { + disabled: true, args: [wasm.WasmFqSrs, undefined /* number */], + // TODO: returning a UintXArray does not work, see above res: undefined /* UintXArray */, }, caml_fp_srs_b_poly_commitment: {