Skip to main content

DynamicProof

Defined in: lib/proof-system/proof.ts:222

The DynamicProof class enables circuits to verify proofs using in-ciruit verfication keys. This is opposed to the baked-in verification keys of the Proof class.

In order to use this, a subclass of DynamicProof that specifies the public input and output types along with the maxProofsVerified number has to be created.

export class SideloadedProgramProof extends DynamicProof<MyStruct, Field> {
static publicInputType = MyStruct;
static publicOutputType = Field;
static maxProofsVerified = 0 as const;
}

The maxProofsVerified constant is a product of the child circuit and indicates the maximum number that that circuit verifies itself. If you are unsure about what that is for you, you should use 2.

Any DynamicProof subclass can be used as private input to ZkPrograms or SmartContracts along with a VerificationKey input.

proof.verify(verificationKey)

NOTE: In the case of DynamicProofs, the circuit makes no assertions about the verificationKey used on its own. This is the responsibility of the application developer and should always implement appropriate checks. This pattern differs a lot from the usage of normal Proof, where the verification key is baked into the compiled circuit.

See

src/examples/zkprogram/dynamic-keys-merkletree.ts for an example of how this can be done using merkle trees

Assertions generally only happen using the vk hash that is part of the VerificationKey struct along with the raw vk data as auxiliary data. When using verify() on a DynamicProof, Pickles makes sure that the verification key data matches the hash. Therefore all manual assertions have to be made on the vk's hash and it can be assumed that the vk's data is checked to match the hash if it is used with verify().

Extends

Type Parameters

Input

Output

Constructors

new DynamicProof()

new DynamicProof<Input, Output>(__namedParameters: {
maxProofsVerified: 0 | 1 | 2;
proof: unknown;
publicInput: Input;
publicOutput: Output;
}): DynamicProof<Input, Output>

Defined in: lib/proof-system/proof.ts:71

Parameters

__namedParameters
maxProofsVerified

0 | 1 | 2

proof

unknown

publicInput

Input

publicOutput

Output

Returns

DynamicProof<Input, Output>

Inherited from

ProofBase.constructor

Properties

maxProofsVerified

maxProofsVerified: 0 | 1 | 2;

Defined in: lib/proof-system/proof.ts:37

Inherited from

ProofBase.maxProofsVerified


proof

proof: unknown;

Defined in: lib/proof-system/proof.ts:36

Inherited from

ProofBase.proof


publicInput

publicInput: Input;

Defined in: lib/proof-system/proof.ts:34

Inherited from

ProofBase.publicInput


publicOutput

publicOutput: Output;

Defined in: lib/proof-system/proof.ts:35

Inherited from

ProofBase.publicOutput


shouldVerify

shouldVerify: Bool;

Defined in: lib/proof-system/proof.ts:38

Inherited from

ProofBase.shouldVerify


usedVerificationKey?

optional usedVerificationKey: VerificationKey;

Defined in: lib/proof-system/proof.ts:254


featureFlags

static featureFlags: FeatureFlags = FeatureFlags.allNone;

Defined in: lib/proof-system/proof.ts:241

As the name indicates, feature flags are features of the proof system.

If we want to side load proofs and verification keys, we first have to tell Pickles what shape of proofs it should expect.

For example, if we want to side load proofs that use foreign field arithmetic custom gates, we have to make Pickles aware of that by defining these custom gates.

Note: Only proofs that use the exact same composition of custom gates which were expected by Pickles can be verified using side loading. If you want to verify any proof, no matter what custom gates it uses, you can use FeatureFlags.allMaybe. Please note that this might incur a significant overhead.

You can also toggle specific feature flags manually by specifying them here. Alternatively, you can use FeatureFlags.fromZkProgram to compute the set of feature flags that are compatible with a given program.


maxProofsVerified

static maxProofsVerified: 0 | 1 | 2;

Defined in: lib/proof-system/proof.ts:223


publicInputType

static publicInputType: FlexibleProvable<any>;

Defined in: lib/proof-system/proof.ts:26

Inherited from

ProofBase.publicInputType


publicOutputType

static publicOutputType: FlexibleProvable<any>;

Defined in: lib/proof-system/proof.ts:27

Inherited from

ProofBase.publicOutputType

Accessors

provable

Get Signature

get static provable(): ProvableProof<DynamicProof<any, any>, any, any>

Defined in: lib/proof-system/proof.ts:320

Returns

ProvableProof<DynamicProof<any, any>, any, any>

Overrides

ProofBase.provable

Methods

declare()

declare(): boolean

Defined in: lib/proof-system/proof.ts:54

To verify a recursive proof inside a ZkProgram method, it has to be "declared" as part of the method. This is done by calling declare() on the proof.

Note: declare() is a low-level method that most users will not have to call directly. For proofs that are inputs to the ZkProgram, it is done automatically.

You can think of declaring a proof as a similar step as witnessing a variable, which introduces that variable to the circuit. Declaring a proof will tell Pickles to add the additional constraints for recursive proof verification.

Similar to Provable.witness(), declare() is a no-op when run outside ZkProgram compilation or proving. It returns false in that case, and true if the proof was actually declared.

Returns

boolean

Inherited from

ProofBase.declare


publicFields()

publicFields(): {
input: Field[];
output: Field[];
}

Defined in: lib/proof-system/proof.ts:111

Returns

{
input: Field[];
output: Field[];
}
input
input: Field[];
output
output: Field[];

Inherited from

ProofBase.publicFields


toJSON()

toJSON(): JsonProof

Defined in: lib/proof-system/proof.ts:61

Returns

JsonProof

Inherited from

ProofBase.toJSON


verify()

verify(vk: VerificationKey): void

Defined in: lib/proof-system/proof.ts:260

Verifies this DynamicProof using a given verification key

Parameters

vk

VerificationKey

The verification key this proof will be verified against

Returns

void


verifyIf()

verifyIf(vk: VerificationKey, condition: Bool): void

Defined in: lib/proof-system/proof.ts:264

Parameters

vk

VerificationKey

condition

Bool

Returns

void


_proofFromBase64()

static _proofFromBase64(proofString: string, maxProofsVerified: 0 | 1 | 2): unknown

Defined in: lib/proof-system/proof.ts:115

Parameters

proofString

string

maxProofsVerified

0 | 1 | 2

Returns

unknown

Inherited from

ProofBase._proofFromBase64


_proofToBase64()

static _proofToBase64(proof: unknown, maxProofsVerified: 0 | 1 | 2): string

Defined in: lib/proof-system/proof.ts:119

Parameters

proof

unknown

maxProofsVerified

0 | 1 | 2

Returns

string

Inherited from

ProofBase._proofToBase64


dummy()

static dummy<S>(
this: S,
publicInput: InferProvable<S["publicInputType"]>,
publicOutput: InferProvable<S["publicOutputType"]>,
maxProofsVerified: 0 | 1 | 2,
domainLog2: number): Promise<InstanceType<S>>

Defined in: lib/proof-system/proof.ts:286

Type Parameters

S extends Subclass<typeof DynamicProof>

Parameters

this

S

publicInput

InferProvable<S["publicInputType"]>

publicOutput

InferProvable<S["publicOutputType"]>

maxProofsVerified

0 | 1 | 2

domainLog2

number = 14

Returns

Promise<InstanceType<S>>


fromJSON()

static fromJSON<S>(this: S, __namedParameters: JsonProof): Promise<DynamicProof<InferProvable<S["publicInputType"]>, InferProvable<S["publicOutputType"]>>>

Defined in: lib/proof-system/proof.ts:269

Type Parameters

S extends Subclass<typeof DynamicProof>

Parameters

this

S

__namedParameters

JsonProof

Returns

Promise<DynamicProof<InferProvable<S["publicInputType"]>, InferProvable<S["publicOutputType"]>>>


fromProof()

static fromProof<S>(this: S, proof: Proof<InferProvable<S["publicInputType"]>, InferProvable<S["publicOutputType"]>>): InstanceType<S>

Defined in: lib/proof-system/proof.ts:308

Converts a Proof into a DynamicProof carrying over all relevant data. This method can be used to convert a Proof computed by a ZkProgram into a DynamicProof that is accepted in a circuit that accepts DynamicProofs

Type Parameters

S extends Subclass<typeof DynamicProof>

Parameters

this

S

proof

Proof<InferProvable<S["publicInputType"]>, InferProvable<S["publicOutputType"]>>

Returns

InstanceType<S>


publicFields()

static publicFields(value: ProofBase): {
input: Field[];
output: Field[];
}

Defined in: lib/proof-system/proof.ts:103

Parameters

value

ProofBase

Returns

{
input: Field[];
output: Field[];
}
input
input: Field[];
output
output: Field[];

Inherited from

ProofBase.publicFields


tag()

static tag(): {
name: string;
}

Defined in: lib/proof-system/proof.ts:243

Returns

{
name: string;
}
name
name: string;

Overrides

ProofBase.tag