Skip to content

Commit 51f7126

Browse files
Update offline function verification method
1 parent 20543b6 commit 51f7126

File tree

7 files changed

+136
-37
lines changed

7 files changed

+136
-37
lines changed

sdk/src/browser.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { ExecutionJSON, FeeExecutionJSON } from "./models/execution/executionJSO
1010
import { ExecutionObject, FeeExecutionObject } from "./models/execution/executionObject";
1111
import { FinalizeJSON } from "./models/finalizeJSON";
1212
import { FunctionObject } from "./models/functionObject";
13+
import { ImportedVerifyingKeys, ImportedPrograms } from "./models/imports";
1314
import { InputJSON } from "./models/input/inputJSON";
1415
import { InputObject } from "./models/input/inputObject";
1516
import { OutputJSON } from "./models/output/outputJSON";
@@ -128,6 +129,8 @@ export {
128129
FunctionKeyPair,
129130
FunctionKeyProvider,
130131
Header,
132+
ImportedPrograms,
133+
ImportedVerifyingKeys,
131134
InputJSON,
132135
InputObject,
133136
KeySearchParams,

sdk/src/models/imports.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
interface ImportedVerifyingKeys {
2+
[key: string]: Array<[string, string]>;
3+
}
4+
5+
interface ImportedPrograms {
6+
[key: string]: string; // This allows for arbitrary keys with any type values
7+
}
8+
9+
export { ImportedVerifyingKeys, ImportedPrograms }

sdk/src/program-manager.ts

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Account } from "./account";
2-
import { AleoNetworkClient, AleoNetworkClientOptions, ProgramImports } from "./network-client";
3-
2+
import { AleoNetworkClient, ProgramImports } from "./network-client";
3+
import { ImportedPrograms, ImportedVerifyingKeys } from "./models/imports";
44
import { RecordProvider, RecordSearchParams } from "./record-provider";
55

66
import {
@@ -1952,12 +1952,34 @@ class ProgramManager {
19521952
}
19531953

19541954
/**
1955-
* Verify a proof of execution from an offline execution
1955+
* Verify a proof from an offline execution. This is useful when it is desired to do offchain proving and verification.
19561956
*
1957-
* @param {executionResponse} executionResponse
1957+
* @param {executionResponse} executionResponse The response from an offline function execution (via the `programManager.run` method)
1958+
* @param {ImportedPrograms} imports The imported programs used in the execution. Specified as { "programName": "programSourceCode", ... }
1959+
* @param {ImportedVerifyingKeys} importedVerifyingKeys The verifying keys in the execution. Specified as { "programName": [["functionName", "verifyingKey"], ...], ... }
19581960
* @returns {boolean} True if the proof is valid, false otherwise
1961+
*
1962+
* @example
1963+
* /// Import the mainnet version of the sdk used to build executions.
1964+
* import { Account, ProgramManager } from "@provablehq/sdk/mainnet.js";
1965+
*
1966+
* /// Create the source for two programs.
1967+
* const program = "import add_it_up.aleo; \n\n program mul_add.aleo;\n\nfunction mul_and_add:\n input r0 as u32.public;\n input r1 as u32.private;\n mul r0 r1 into r2;\n call add_it_up.aleo/add r1 r2 into r3; output r3 as u32.private;\n";
1968+
* const program_import = "program add_it_up.aleo;\n\nfunction add:\n input r0 as u32.public;\n input r1 as u32.private;\n add r0 r1 into r2;\n output r2 as u32.private;\n";
1969+
* const programManager = new ProgramManager(undefined, undefined, undefined);
1970+
*
1971+
* /// Create a temporary account for the execution of the program
1972+
* const account = Account.fromCipherText(process.env.ciphertext, process.env.password);
1973+
* programManager.setAccount(account);
1974+
*
1975+
* /// Get the response and ensure that the program executed correctly
1976+
* const executionResponse = await programManager.run(program, "hello", ["5u32", "5u32"]);
1977+
*
1978+
* /// Verify the execution.
1979+
* const isValid = programManager.verifyExecution(executionResponse);
1980+
* assert(isValid);
19591981
*/
1960-
verifyExecution(executionResponse: ExecutionResponse): boolean {
1982+
verifyExecution(executionResponse: ExecutionResponse, imports?: ImportedPrograms, importedVerifyingKeys?: ImportedVerifyingKeys): boolean {
19611983
try {
19621984
const execution = <FunctionExecution>(
19631985
executionResponse.getExecution()
@@ -1970,6 +1992,8 @@ class ProgramManager {
19701992
verifyingKey,
19711993
program,
19721994
function_id,
1995+
imports,
1996+
importedVerifyingKeys,
19731997
);
19741998
} catch (e) {
19751999
console.warn(

wasm/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"The Provable Team"
77
],
88
"license": "GPL-3.0",
9-
"type": "module",
9+
1010
"main": "./dist/testnet/index.js",
1111
"browser": "./dist/testnet/index.js",
1212
"types": "./dist/testnet/index.d.ts",

0 commit comments

Comments
 (0)