Skip to content

Commit 37749a6

Browse files
committed
fixed template file
1 parent 3143b39 commit 37749a6

File tree

1 file changed

+35
-7
lines changed

1 file changed

+35
-7
lines changed
Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
1-
import {Account, initThreadPool, ProgramManager, AleoKeyProvider, OfflineKeyProvider, CREDITS_PROGRAM_KEYS} from "@provablehq/sdk";
1+
import {Account, initThreadPool, ProgramManager, AleoKeyProvider, AleoKeyProviderParams} from "@provablehq/sdk";
22

33
await initThreadPool();
44

5+
const programName = "hello_hello.aleo"
56

7+
const hello_hello_program =`
8+
program ${programName};
69
7-
async function localProgramExecution() {
10+
function hello:
11+
input r0 as u32.public;
12+
input r1 as u32.private;
13+
add r0 r1 into r2;
14+
output r2 as u32.private;`
15+
16+
async function localProgramExecution(program, programName, aleoFunction, inputs) {
817
const programManager = new ProgramManager();
918

1019
// Create a temporary account for the execution of the program
@@ -13,19 +22,38 @@ async function localProgramExecution() {
1322

1423
// Create a key provider in order to re-use the same key for each execution
1524
const keyProvider = new AleoKeyProvider();
16-
const offlineKeyProvider = new OfflineKeyProvider();
1725
keyProvider.useCache(true);
1826
programManager.setKeyProvider(keyProvider);
1927

20-
const [transferPublicProver, transferPublicVerifier] =await keyProvider.fetchCreditsKeys(CREDITS_PROGRAM_KEYS.transfer_public);
21-
console.log(transferPublicVerifier.toString());
28+
// Pre-synthesize the program keys and then cache them in memory using key provider
29+
const keyPair = await programManager.synthesizeKeys(hello_hello_program, aleoFunction, inputs);
30+
programManager.keyProvider.cacheKeys(`${programName}:${aleoFunction}`, keyPair);
2231

2332
// Specify parameters for the key provider to use search for program keys. In particular specify the cache key
2433
// that was used to cache the keys in the previous step.
25-
34+
const keyProviderParams = new AleoKeyProviderParams({cacheKey: `${programName}:${aleoFunction}`});
35+
36+
// Execute once using the key provider params defined above. This will use the cached proving keys and make
37+
// execution significantly faster.
38+
let executionResponse = await programManager.run(
39+
program,
40+
aleoFunction,
41+
inputs,
42+
true,
43+
undefined,
44+
keyProviderParams,
45+
);
46+
console.log("hello_hello/hello executed - result:", executionResponse.getOutputs());
47+
48+
// Verify the execution using the verifying key that was generated earlier.
49+
if (programManager.verifyExecution(executionResponse, 9_000_000)) {
50+
console.log("hello_hello/hello execution verified!");
51+
} else {
52+
throw("Execution failed verification!");
53+
}
2654
}
2755

2856
const start = Date.now();
2957
console.log("Starting execute!");
30-
await localProgramExecution();
58+
await localProgramExecution(hello_hello_program, programName, "hello", ["5u32", "5u32"]);
3159
console.log("Execute finished!", Date.now() - start);

0 commit comments

Comments
 (0)