import { Base64ProofString, Base64VerificationKeyString, Gate, Pickles } from '../../bindings.js'; import { From, InferValue } from '../../bindings/lib/provable-generic.js'; import { FieldConst } from '../provable/core/fieldvar.js'; import { ConstraintSystemSummary } from '../provable/core/provable-context.js'; import { Provable } from '../provable/provable.js'; import { InferProvableType } from '../provable/types/provable-derivers.js'; import { ProvableType, ToProvable } from '../provable/types/provable-intf.js'; import { FlexibleProvable, InferProvable, ProvablePureExtended } from '../provable/types/struct.js'; import { Field } from '../provable/wrapped.js'; import { Get, Subclass, Tuple } from '../util/types.js'; import { Cache } from './cache.js'; import { Proof, ProofBase, ProofClass, ProofValue } from './proof.js'; import { VerificationKey } from './verification-key.js'; export { Empty, JsonProof, Method, SelfProof, Undefined, Void, ZkProgram, verify }; export { CompiledTag, MethodInterface, MethodReturnType, PrivateInput, Proof, Prover, RegularProver, TupleToInstances, analyzeMethod, compileProgram, computeMaxProofsVerified, dummyBase64Proof, inCircuitVkHash, picklesRuleFromFunction, sortMethodArguments, }; type Undefined = undefined; declare const Undefined: ProvablePureExtended; type Empty = Undefined; declare const Empty: ProvablePureExtended; type Void = undefined; declare const Void: ProvablePureExtended; type MethodAnalysis = ConstraintSystemSummary & { proofs: ProofClass[]; }; declare function createProgramState(): { setNonPureOutput(value: any[]): void; getNonPureOutput(): any[]; setAuxiliaryOutput(value: unknown, methodName: string): void; getAuxiliaryOutput(methodName: string): unknown; reset(key: string): void; }; /** * Initializes Pickles bindings, serializes the input proof and verification key for use in OCaml, then calls into the Pickles verify function and returns the result. * * @note This function is meant to be called in JavaScript, not for use in a circuit. The verification key data and hash are not confirmed to match. * @param proof Either a `Proof` instance or a serialized JSON proof * @param verificationKey Either a base64 serialized verification key or a `VerificationKey` instance which will be base64 serialized for use in the bindings. * @returns A promise that resolves to a boolean indicating whether the proof is valid. */ declare function verify(proof: ProofBase | JsonProof, verificationKey: Base64VerificationKeyString | VerificationKey): Promise; /** * Serializable representation of a Pickles proof, useful for caching compiled proofs. */ type JsonProof = { /** Array of string, where each string is a `Field` in the publicInput of this proof */ publicInput: string[]; /** Array of string, where each string is a `Field` in the publicOutput of this proof */ publicOutput: string[]; maxProofsVerified: 0 | 1 | 2; proof: Base64ProofString; }; type CompiledTag = unknown; declare let CompiledTag: { get(tag: any): CompiledTag | undefined; store(tag: any, compiledTag: CompiledTag): void; }; type ConfigBaseType = { publicInput?: ProvableType; publicOutput?: ProvableType; methods: { [I in string]: { privateInputs: Tuple; auxiliaryOutput?: ProvableType; }; }; }; type InferMethodSignatures = Config['methods']; type InferPrivateInput = { [I in keyof Config['methods']]: Config['methods'][I]['privateInputs']; }; type InferAuxiliaryOutputs = { [I in keyof InferMethodSignatures]: Get[I], 'auxiliaryOutput'>; }; type InferMethodType = { [I in keyof Config['methods']]: Method>, InferProvableOrVoid>, Config['methods'][I]>; }; /** * Wraps config + provable code into a program capable of producing {@link Proof}s. * * @example * ```ts * 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) } * } * } * } * }); * ``` * * @param config 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 an object that can be used to compile, prove, and verify the program. */ declare function ZkProgram(config: Config & { name: string; methods: { [I in keyof Config['methods']]: InferMethodType[I]; }; overrideWrapDomain?: 0 | 1 | 2; numChunks?: number; }): { name: string; maxProofsVerified(): Promise<0 | 1 | 2>; compile: (options?: { cache?: Cache; forceRecompile?: boolean; proofsEnabled?: boolean; withRuntimeTables?: boolean; numChunks?: number; lazyMode?: boolean; }) => Promise<{ verificationKey: { data: string; hash: Field; }; }>; verify: (proof: Proof>, InferProvableOrVoid>>) => Promise; digest: () => Promise; /** * Analyze the constraint system created by each method in the program. * Every method is executed in a circuit, and the constraints are analyzed. * * @returns A summary of this ZkProgram, keyed by the method name, with a value of the {@link MethodAnalysis} for that method */ analyzeMethods: () => Promise<{ [I in keyof Config['methods']]: MethodAnalysis; }>; /** * Analyze the constraint system created by a single method in the program without analyzing any other methods and executing them. * * @returns A summary of this method, with a value of the {@link MethodAnalysis} for that method */ analyzeSingleMethod(methodName: K): Promise; publicInputType: ProvableOrUndefined>; publicOutputType: ProvableOrVoid>; privateInputTypes: InferPrivateInput; auxiliaryOutputTypes: InferAuxiliaryOutputs; rawMethods: { [I in keyof Config['methods']]: InferMethodType[I]['method']; }; Proof: typeof Proof>, InferProvableOrVoid>>; proofsEnabled: boolean; setProofsEnabled(proofsEnabled: boolean): void; } & { [I in keyof Config['methods']]: Prover>, ProvableOrUndefined>, InferProvableOrVoid>, InferPrivateInput[I], InferProvableOrUndefined[I]>>; }; declare namespace ZkProgram { var Proof: , PublicOutputType extends FlexibleProvable>(program: { name: string; publicInputType: PublicInputType; publicOutputType: PublicOutputType; }) => { new ({ proof, publicInput, publicOutput, maxProofsVerified, }: { proof: unknown; publicInput: InferProvable; publicOutput: InferProvable; maxProofsVerified: 0 | 2 | 1; }): Proof, InferProvable>; fromJSON>(this: S, { maxProofsVerified, proof: proofString, publicInput: publicInputJson, publicOutput: publicOutputJson, }: JsonProof): Promise, InferProvable>>; dummy(publicInput: Input, publicOutput: OutPut, maxProofsVerified: 0 | 2 | 1, domainLog2?: number): Promise>; readonly provable: { toFields: (value: Proof) => import("../provable/field.js").Field[]; toAuxiliary: (value?: Proof | undefined) => any[]; fromFields: (fields: import("../provable/field.js").Field[], aux: any[]) => Proof; sizeInFields(): number; check: (value: Proof) => void; toValue: (x: Proof) => ProofValue; fromValue: (x: Proof | ProofValue) => Proof; toCanonical?: ((x: Proof) => Proof) | undefined; }; publicInputType: FlexibleProvable; publicOutputType: FlexibleProvable; tag: () => { name: string; }; publicFields(value: ProofBase): { input: import("../provable/field.js").Field[]; output: import("../provable/field.js").Field[]; }; _proofFromBase64(proofString: string, maxProofsVerified: 0 | 2 | 1): unknown; _proofToBase64(proof: unknown, maxProofsVerified: 0 | 2 | 1): string; } & { provable: Provable, InferProvable>, ProofValue, InferValue>>; }; } type ZkProgram; auxiliaryOutput?: ProvableType; }; }; }> = ReturnType>; /** * A class representing the type of Proof produced by the {@link ZkProgram} in which it is used. * * @example * ```ts * const ExampleProgram = ZkProgram({ * name: 'ExampleProgram', * publicOutput: Field, * methods: { * baseCase: { * privateInputs: [], * method: async () => { * return { publicOutput: Field(0) } * } * }, * add: { * privateInputs: [SelfProof, Field], * // `previous` is the type of proof produced by ExampleProgram * method: async (previous: SelfProof, f: Field) => { * previous.verify(); * return { publicOutput: previous.publicOutput.add(f) } * } * } * } * }); * ``` */ declare class SelfProof extends Proof { } declare function sortMethodArguments(programName: string, methodName: string, privateInputs: unknown[], auxiliaryType: Provable | undefined, selfProof: Subclass): MethodInterface; type MethodInterface = { methodName: string; args: ProvableType[]; returnType?: Provable; auxiliaryType?: Provable; }; declare function compileProgram({ publicInputType, publicOutputType, methodIntfs, methods, gates, proofs, proofSystemTag, cache, forceRecompile, overrideWrapDomain, numChunks, state, withRuntimeTables, lazyMode, }: { publicInputType: Provable; publicOutputType: Provable; methodIntfs: MethodInterface[]; methods: ((...args: any) => unknown)[]; gates: Gate[][]; proofs: ProofClass[][]; proofSystemTag: { name: string; }; cache: Cache; forceRecompile: boolean; overrideWrapDomain?: 0 | 1 | 2; numChunks?: number; state?: ReturnType; withRuntimeTables?: boolean; lazyMode?: boolean; }): Promise<{ verificationKey: { data: string; hash: import("../provable/field.js").Field; }; provers: Pickles.Prover[]; verify: (statement: Pickles.Statement, proof: Pickles.Proof) => Promise; tag: unknown; }>; declare function analyzeMethod(publicInputType: Provable, methodIntf: MethodInterface, method: (...args: any) => unknown): Promise; declare function inCircuitVkHash(inCircuitVk: unknown): Field; declare function picklesRuleFromFunction(publicInputType: Provable, publicOutputType: Provable, func: (...args: unknown[]) => unknown, proofSystemTag: { name: string; }, { methodName, args, auxiliaryType }: MethodInterface, gates: Gate[], verifiedProofs: ProofClass[], state?: ReturnType, withRuntimeTables?: boolean): Pickles.Rule; declare function computeMaxProofsVerified(proofs: number[]): 0 | 2 | 1; declare function dummyBase64Proof(): Promise; declare function Prover(): { run(witnesses: unknown[], proverData: ProverData, callback: () => Promise): Promise; getData(): ProverData; }; type Infer = T extends Subclass ? InstanceType : T extends ProvableType ? InferProvableType : never; type TupleToInstances = { [I in keyof T]: Infer; }; type TupleFrom = { [I in keyof T]: From; }; type PrivateInput = ProvableType | Subclass; type MethodReturnType = PublicOutput extends void ? AuxiliaryOutput extends undefined ? void : { auxiliaryOutput: AuxiliaryOutput; } : AuxiliaryOutput extends undefined ? { publicOutput: PublicOutput; } : { publicOutput: PublicOutput; auxiliaryOutput: AuxiliaryOutput; }; type Method; auxiliaryOutput?: ProvableType; }> = PublicInput extends undefined ? { method(...args: TupleToInstances): Promise>>>; } : { method(publicInput: PublicInput, ...args: TupleToInstances): Promise>>>; }; type RegularProver, AuxiliaryOutput> = (publicInput: From, ...args: TupleFrom) => Promise<{ proof: Proof; auxiliaryOutput: AuxiliaryOutput; }>; type Prover, AuxiliaryOutput> = PublicInput extends undefined ? (...args: TupleFrom) => Promise<{ proof: Proof; auxiliaryOutput: AuxiliaryOutput; }> : (publicInput: From, ...args: TupleFrom) => Promise<{ proof: Proof; auxiliaryOutput: AuxiliaryOutput; }>; type ProvableOrUndefined = A extends undefined ? typeof Undefined : ToProvable; type ProvableOrVoid = A extends undefined ? typeof Void : ToProvable; type InferProvableOrUndefined = A extends undefined ? undefined : A extends ProvableType ? InferProvable : InferProvable | undefined; type InferProvableOrVoid = A extends undefined ? void : InferProvable;