Skip to content

Commit

Permalink
Create verification function
Browse files Browse the repository at this point in the history
  • Loading branch information
iamalwaysuncomfortable committed Oct 25, 2023
1 parent f627b7c commit 7a82095
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions create-aleo-app/template-react-zkml/src/workers/worker.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import {
Account,
Execution,
ProgramManager,
PrivateKey,
initThreadPool,
AleoKeyProvider,
AleoNetworkClient,
Program,
NetworkRecordProvider, AleoKeyProviderParams,
NetworkRecordProvider, AleoKeyProviderParams, verifyFunctionExecution
} from "@aleohq/sdk";
import { expose, proxy } from "comlink";
import {sample_inputs} from "../variables.js";
Expand Down Expand Up @@ -55,21 +56,31 @@ async function localProgramExecution(program_source, aleoFunction, inputs) {
if (cacheFunctionKeys) {
console.log("Caching keys");
const keys = executionResponse.getKeys(program.id(), aleoFunction);
programManager.keyProvider.cacheKeys(keySearchParams.cacheKey, [keys.provingKey(), keys.verifyingKey()]);
const verifyingKey = keys.verifyingKey();

programManager.keyProvider.cacheKeys(keySearchParams.cacheKey, [keys.provingKey(), verifyingKey]);
console.log(`Cached keys for ${keySearchParams.cacheKey}`);
}

console.log("Getting outputs");
const outputs = executionResponse.getOutputs(); // proof: executionResponse.
console.log("outputs", outputs);
return outputs;
return [outputs, executionResponse.getExecution().toString()];
}

async function getPrivateKey() {
const key = new PrivateKey();
return proxy(key);
}

async function verifyExecution(execution_string, program, aleoFunction) {
const execution = Execution.fromString(execution_string);
const keySearchParams = new AleoKeyProviderParams({cacheKey: `${program.id()}/${aleoFunction}`});

const [provingKey, verifyingKey] = programManager.keyProvider.functionKeys(keySearchParams);
return verifyFunctionExecution(execution, verifyingKey, program, aleoFunction);
}

async function deployProgram(program) {
const keyProvider = new AleoKeyProvider();
keyProvider.useCache(true);
Expand Down Expand Up @@ -106,5 +117,5 @@ async function deployProgram(program) {
return tx_id;
}

const workerMethods = { deployProgram, getPrivateKey, localProgramExecution, synthesizeKeys };
const workerMethods = { deployProgram, getPrivateKey, localProgramExecution, synthesizeKeys, verifyExecution};
expose(workerMethods);

0 comments on commit 7a82095

Please sign in to comment.