Skip to content

Commit

Permalink
Update nodejs create-aleo-app example to include execution verification
Browse files Browse the repository at this point in the history
  • Loading branch information
iamalwaysuncomfortable committed Oct 26, 2023
1 parent b43a2d3 commit 362472c
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions create-aleo-app/template-node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ async function localProgramExecution(program, aleoFunction, inputs) {

// Create a key provider in order to re-use the same key for each execution
const keyProvider = new AleoKeyProvider();
keyProvider.useCache(true);
programManager.setKeyProvider(keyProvider);

// Pre-synthesize the program keys and then cache them in memory using key provider
Expand All @@ -33,30 +34,24 @@ async function localProgramExecution(program, aleoFunction, inputs) {
// Execute once using the key provider params defined above. This will use the cached proving keys and make
// execution significantly faster.
let executionResponse = await programManager.executeOffline(
hello_hello_program,
"hello",
["5u32", "5u32"],
false,
undefined,
keyProviderParams,
);
console.log(executionResponse.getOutputs())

// Execute a second time to ensure the cached keys are still being used - however, this time prove the execution.
executionResponse = await programManager.executeOffline(
hello_hello_program,
"hello",
["5u32", "5u32"],
true,
undefined,
keyProviderParams,
);
console.log("hello_hello/hello executed - result:", executionResponse.getOutputs());

// Verify the execution using the verifying key that was generated earlier.
programManager.verifyExecution(executionResponse);
if (programManager.verifyExecution(executionResponse)) {
console.log("hello_hello/hello execution verified!");
} else {
throw("Execution failed verification!");
}
}

const start = Date.now();
console.log("Starting execute!");
const result = await localProgramExecution();
console.log(result);
await localProgramExecution();
console.log("Execute finished!", Date.now() - start);

0 comments on commit 362472c

Please sign in to comment.