Skip to main content

Utility Functions

Overview

The SDK exports several utility functions for initialization and verification operations.

Functions

initThreadPool

Initialize the thread pool for parallel WASM operations. This should be called before performing CPU-intensive operations like proof generation.

initThreadPool(num_threads)Promise<void>
ParamTypeDescription
num_threadsnumberNumber of threads to use in the thread pool
returnPromise<void>Promise that resolves when initialization is complete

Example

import { initThreadPool } from '@provablehq/sdk';

// Initialize with available CPU cores
await initThreadPool(navigator.hardwareConcurrency);

verifyFunctionExecution

Verify an execution. Executions with multiple transitions must have the program source code and verifying keys of imported functions supplied from outside to correctly verify. Note: this does not verify that the state root of the execution is included in the Aleo Network ledger.

verifyFunctionExecution(execution, verifying_key, program, function_id, imports, import_verifying_keys, block_height) ► boolean
ParamTypeDescription
executionExecutionThe function execution to verify
verifying_keyVerifyingKeyThe verifying key for the function
programProgramThe program that the function execution belongs to
function_idstringThe name of the function that was executed
importsObjectThe imports for the program in the form of { "program_id.aleo": "source code", ... }
import_verifying_keysObjectThe verifying keys for the imports in the form of { "program_id.aleo": [["function", "verifying_key"], ...], ... }
block_heightnumberThe block height at which the execution occurred
returnbooleanTrue if the execution is valid, false otherwise

Example

import { verifyFunctionExecution, Execution, VerifyingKey, Program } from '@provablehq/sdk';

const execution = Execution.fromString(executionJson);
const verifyingKey = VerifyingKey.fromString(vkString);
const program = Program.fromString(programSource);

const isValid = verifyFunctionExecution(
execution,
verifyingKey,
program,
"transfer_public",
{}, // imports
{}, // import_verifying_keys
1000000 // block_height
);

console.log("Execution valid:", isValid);

getOrInitConsensusVersionTestHeights

Get or initialize consensus version test heights. This is primarily used for testing network consensus version transitions.

getOrInitConsensusVersionTestHeights()Object
ParamType
returnObject