Skip to content

Commit

Permalink
Merge branch 'main' into brian/nix-pure-bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
Geometer1729 committed Nov 25, 2024
2 parents 1f81c1f + e172bf0 commit 97bb6cd
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
11 changes: 7 additions & 4 deletions crypto/bindings/srs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion crypto/elliptic-curve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions js/web/web-backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
9 changes: 9 additions & 0 deletions js/web/worker-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit 97bb6cd

Please sign in to comment.