Skip to content

Commit

Permalink
Merge pull request #327 from o1-labs/fix/compatibility-followup
Browse files Browse the repository at this point in the history
Handle whole domain commitment by pointer
  • Loading branch information
Trivo25 authored Jan 27, 2025
2 parents 36df9f0 + 888f91e commit dfe6874
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion MINA_COMMIT
Original file line number Diff line number Diff line change
@@ -1 +1 @@
The mina commit used to generate the backends for node and web is 6aba21f57bd4094c3f611d7f9124d9570d711a22
The mina commit used to generate the backends for node and web is 11e233cdc0d9fcff3361ee0b6a4b958e5e38041d
19 changes: 15 additions & 4 deletions crypto/bindings/srs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,16 @@ function srsPerField(f: 'fp' | 'fq', wasm: Wasm, conversion: RustConversion) {
let maybeLagrangeCommitment = wasm[`caml_${f}_srs_maybe_lagrange_commitment`];
let lagrangeCommitment = (srs: WasmFpSrs, domain_size: number, i: number) =>
wasm[`caml_${f}_srs_lagrange_commitment`](srs, domain_size, i);
let lagrangeCommitmentsWholeDomain = (srs: WasmSrs, domain_size: number) =>
wasm[`caml_${f}_srs_lagrange_commitments_whole_domain`](srs, domain_size);
let lagrangeCommitmentsWholeDomainPtr = (srs: WasmSrs, domain_size: number) =>
wasm[`caml_${f}_srs_lagrange_commitments_whole_domain_ptr`](
srs,
domain_size
);
let setLagrangeBasis = wasm[`caml_${f}_srs_set_lagrange_basis`];
let getLagrangeBasis = (srs: WasmSrs, n: number) =>
wasm[`caml_${f}_srs_get_lagrange_basis`](srs, n);

let getCommitmentsWholeDomainByPtr =
wasm[`caml_${f}_srs_lagrange_commitments_whole_domain_read_from_ptr`];
return {
/**
* returns existing stored SRS or falls back to creating a new one
Expand Down Expand Up @@ -187,7 +191,14 @@ function srsPerField(f: 'fp' | 'fq', wasm: Wasm, conversion: RustConversion) {
* Returns the Lagrange basis commitments for the whole domain
*/
lagrangeCommitmentsWholeDomain(srs: WasmSrs, domainSize: number) {
let wasmComms = lagrangeCommitmentsWholeDomain(srs, domainSize);
// instead of getting the entire commitment directly (which works for nodejs/servers), we get a pointer to the commitment
// and then read the commitment from the pointer
// this is because the web worker implementation currently does not support returning UintXArray's directly
// hence we return a pointer from wasm, funnel it through the web worker
// and then read the commitment from the pointer in the main thread (where UintXArray's are supported)
// see https://github.com/o1-labs/o1js-bindings/blob/09e17b45e0c2ca2b51cd9ed756106e17ca1cf36d/js/web/worker-spec.js#L110-L115
let ptr = lagrangeCommitmentsWholeDomainPtr(srs, domainSize);
let wasmComms = getCommitmentsWholeDomainByPtr(ptr);
let mlComms = conversion[f].polyCommsFromRust(wasmComms);
return mlComms;
},
Expand Down
4 changes: 2 additions & 2 deletions js/web/worker-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,11 @@ function workerSpec(wasm) {
},
caml_fp_srs_lagrange_commitments_whole_domain: {
args: [wasm.WasmFpSrs, undefined /* number */],
res: wasm.WasmFpPolyComm,
res: undefined /* number, ptr */,
},
caml_fq_srs_lagrange_commitments_whole_domain: {
args: [wasm.WasmFqSrs, undefined /* number */],
res: wasm.WasmFqPolyComm,
res: undefined /* number, ptr */,
},
};
}

0 comments on commit dfe6874

Please sign in to comment.