Skip to main content
Version: 2.4.0

ZkProgram

function ZkProgram<Config, _>(config: Config & {
methods: { [I in string | number | symbol]: InferMethodType<Config>[I] };
name: string;
overrideWrapDomain: 0 | 2 | 1;
}): {
analyzeMethods: () => Promise<{ [I in keyof Config["methods"]]: MethodAnalysis }>;
auxiliaryOutputTypes: InferAuxiliaryOutputs<Config>;
compile: (options?: {
cache: Cache;
forceRecompile: boolean;
proofsEnabled: boolean;
withRuntimeTables: boolean;
}) => Promise<{
verificationKey: {
data: string;
hash: Field;
};
}>;
digest: () => Promise<string>;
name: string;
privateInputTypes: InferPrivateInput<Config>;
Proof: typeof Proof;
proofsEnabled: boolean;
publicInputType: ProvableOrUndefined<Get<Config, "publicInput">>;
publicOutputType: ProvableOrVoid<Get<Config, "publicOutput">>;
rawMethods: { [I in keyof Config["methods"]]: InferMethodType<Config>[I]["method"] };
verify: (proof: Proof<InferProvableOrUndefined<Get<Config, "publicInput">>, InferProvableOrVoid<Get<Config, "publicOutput">>>) => Promise<boolean>;
maxProofsVerified: Promise<0 | 1 | 2>;
setProofsEnabled: void;
} & { [I in keyof Config["methods"]]: Prover<InferProvableOrUndefined<Get<Config, "publicInput">>, ProvableOrUndefined<Get<Config, "publicInput">>, InferProvableOrVoid<Get<Config, "publicOutput">>, InferPrivateInput<Config>[I], InferProvableOrUndefined<InferAuxiliaryOutputs<Config>[I]>> }

Defined in: lib/proof-system/zkprogram.ts:224

Wraps config + provable code into a program capable of producing Proofs.

Type Parameters

Config extends ConfigBaseType

_ extends unknown = unknown

Parameters

config

Config & { methods: { [I in string | number | symbol]: InferMethodType<Config>[I] }; name: string; overrideWrapDomain: 0 | 2 | 1; }

The configuration of the program, describing the type of the public input and public output, as well as defining the methods which can be executed provably.

Returns

{ analyzeMethods: () => Promise<{ [I in keyof Config["methods"]]: MethodAnalysis }>; auxiliaryOutputTypes: InferAuxiliaryOutputs<Config>; compile: (options?: { cache: Cache; forceRecompile: boolean; proofsEnabled: boolean; withRuntimeTables: boolean; }) => Promise<{ verificationKey: { data: string; hash: Field; }; }>; digest: () => Promise<string>; name: string; privateInputTypes: InferPrivateInput<Config>; Proof: typeof Proof; proofsEnabled: boolean; publicInputType: ProvableOrUndefined<Get<Config, "publicInput">>; publicOutputType: ProvableOrVoid<Get<Config, "publicOutput">>; rawMethods: { [I in keyof Config["methods"]]: InferMethodType<Config>[I]["method"] }; verify: (proof: Proof<InferProvableOrUndefined<Get<Config, "publicInput">>, InferProvableOrVoid<Get<Config, "publicOutput">>>) => Promise<boolean>; maxProofsVerified: Promise<0 | 1 | 2>; setProofsEnabled: void; } & { [I in keyof Config["methods"]]: Prover<InferProvableOrUndefined<Get<Config, "publicInput">>, ProvableOrUndefined<Get<Config, "publicInput">>, InferProvableOrVoid<Get<Config, "publicOutput">>, InferPrivateInput<Config>[I], InferProvableOrUndefined<InferAuxiliaryOutputs<Config>[I]>> }

an object that can be used to compile, prove, and verify the program.

Example

const ExampleProgram = ZkProgram({
name: 'ExampleProgram',
publicOutput: Int64,
methods: {
// Prove that I know 2 numbers less than 100 each, whose product is greater than 1000
provableMultiply: {
privateInputs: [Int64, Int64],
method: async (n1: Int64, n2: Int64) => {
n1.assertLessThan(100);
n2.assertLessThan(100);
const publicOutput = n1.mul(n2);
publicOutput.assertGreaterThan(1000);
return { publicOutput: n1.mul(n2) }
}
}
}
});