Skip to content

Commit

Permalink
feat(halo2): pack clientId and public input to proof
Browse files Browse the repository at this point in the history
  • Loading branch information
hunshenshi committed Aug 5, 2024
1 parent bbb6c76 commit c1edb82
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 25 deletions.
3 changes: 1 addition & 2 deletions halo2-wasm-node-server/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ COPY halo2-wasm-node-server server/
WORKDIR /halo2-wasm-server/server

RUN npm install
RUN npm install -g clinic

CMD [ "/bin/bash", "start.sh" ]
CMD [ "node", "src/server.js" ]
9 changes: 2 additions & 7 deletions halo2-wasm-node-server/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,8 @@ function execute(call, callback) {
wasm.initWasmInstance();

const result = wasm.prove(projectID, taskID, clientID, sequencerSignature, JSON.stringify(datas));
// convert result to bytes
let resultBytes = new Uint8Array(result.length);
for (var i = 0; i < result.length; i++) {
resultBytes[i] = result.charCodeAt(i);
}

callback(null, { result: resultBytes });
callback(null, { result: result });
}

let server;
Expand Down Expand Up @@ -123,5 +118,5 @@ module.exports = {
};

if (require.main === module) {
startGrpcServer('0.0.0.0:4001');
startGrpcServer('0.0.0.0:4002');
}
30 changes: 14 additions & 16 deletions halo2-wasm-node-server/src/wasm_instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,20 @@ function getInt32Memory0() {
}
return cachedInt32Memory0;
}

function getArrayU8FromWasm0(ptr, len) {
ptr = ptr >>> 0;
return getUint8Memory0().subarray(ptr / 1, ptr / 1 + len);
}
/**
* @param {bigint} project_id
* @param {bigint} task_id
* @param {string} client_id
* @param {string} sequencer_sign
* @param {string} input
* @returns {string}
* @returns {Uint8Array}
*/
module.exports.prove = function(project_id, task_id, client_id, sequencer_sign, input) {
let deferred4_0;
let deferred4_1;
try {
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
const ptr0 = passStringToWasm0(client_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
Expand All @@ -136,12 +139,11 @@ module.exports.prove = function(project_id, task_id, client_id, sequencer_sign,
wasm.prove(retptr, project_id, task_id, ptr0, len0, ptr1, len1, ptr2, len2);
var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
deferred4_0 = r0;
deferred4_1 = r1;
return getStringFromWasm0(r0, r1);
var v4 = getArrayU8FromWasm0(r0, r1).slice();
wasm.__wbindgen_free(r0, r1 * 1, 1);
return v4;
} finally {
wasm.__wbindgen_add_to_stack_pointer(16);
wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
}
};

Expand All @@ -153,10 +155,6 @@ function handleError(f, args) {
}
}

module.exports.__wbg_log_d95057db93b45721 = function(arg0, arg1) {
console.log(getStringFromWasm0(arg0, arg1));
};

module.exports.__wbg_crypto_58f13aa23ffcb166 = function(arg0) {
const ret = getObject(arg0).crypto;
return addHeapObject(ret);
Expand Down Expand Up @@ -192,11 +190,6 @@ module.exports.__wbindgen_object_drop_ref = function(arg0) {
takeObject(arg0);
};

module.exports.__wbg_msCrypto_abcb1295e768d1f2 = function(arg0) {
const ret = getObject(arg0).msCrypto;
return addHeapObject(ret);
};

module.exports.__wbg_require_2784e593a4674877 = function() { return handleError(function () {
const ret = module.require;
return addHeapObject(ret);
Expand All @@ -212,6 +205,11 @@ module.exports.__wbindgen_string_new = function(arg0, arg1) {
return addHeapObject(ret);
};

module.exports.__wbg_msCrypto_abcb1295e768d1f2 = function(arg0) {
const ret = getObject(arg0).msCrypto;
return addHeapObject(ret);
};

module.exports.__wbg_randomFillSync_a0d98aa11c81fe89 = function() { return handleError(function (arg0, arg1) {
getObject(arg0).randomFillSync(takeObject(arg1));
}, arguments) };
Expand Down

0 comments on commit c1edb82

Please sign in to comment.