You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -118,9 +124,16 @@ function createProgramState() {
118
124
};
119
125
}
120
126
127
+
/**
128
+
* 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.
129
+
*
130
+
* @param proof Either a `Proof` instance or a serialized JSON proof
131
+
* @param verificationKey Either a base64 serialized verification key or a `VerificationKey` instance which will be base64 serialized for use in the bindings.
132
+
* @returns A promise that resolves to a boolean indicating whether the proof is valid.
* Serializable representation of a Pickles proof, useful for caching compiled proofs.
173
+
*/
158
174
typeJsonProof={
175
+
/** Array of string, where each string is a `Field` in the publicInput of this proof */
159
176
publicInput: string[];
177
+
/** Array of string, where each string is a `Field` in the publicOutput of this proof */
160
178
publicOutput: string[];
161
179
maxProofsVerified: 0|1|2;
162
-
proof: string;
180
+
proof: Base64ProofString;
163
181
};
164
182
typeCompiledTag=unknown;
165
183
@@ -183,6 +201,33 @@ let SideloadedTag = {
183
201
},
184
202
};
185
203
204
+
/**
205
+
* Wraps config + provable code into a program capable of producing {@link Proof}s.
206
+
*
207
+
* @example
208
+
* ```ts
209
+
* const ExampleProgram = ZkProgram({
210
+
* name: 'ExampleProgram',
211
+
* publicOutput: Int64,
212
+
* methods: {
213
+
* // Prove that I know 2 numbers less than 100 each, whose product is greater than 1000
214
+
* provableMultiply: {
215
+
* privateInputs: [Int64, Int64],
216
+
* method: async (n1: Int64, n2: Int64) => {
217
+
* n1.assertLessThan(100);
218
+
* n2.assertLessThan(100);
219
+
* const publicOutput = n1.mul(n2);
220
+
* publicOutput.assertGreaterThan(1000);
221
+
* return { publicOutput: n1.mul(n2) }
222
+
* }
223
+
* }
224
+
* }
225
+
* });
226
+
* ```
227
+
*
228
+
* @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.
229
+
* @returns an object that can be used to compile, prove, and verify the program.
230
+
*/
186
231
functionZkProgram<
187
232
Configextends{
188
233
publicInput?: ProvableType;
@@ -591,6 +636,33 @@ type ZkProgram<
591
636
}
592
637
>=ReturnType<typeofZkProgram<Config,Methods>>;
593
638
639
+
/**
640
+
* A class representing the type of Proof produced by the {@link ZkProgram} in which it is used.
641
+
*
642
+
* @example
643
+
* ```ts
644
+
* const ExampleProgram = ZkProgram({
645
+
* name: 'ExampleProgram',
646
+
* publicOutput: Field,
647
+
* methods: {
648
+
* baseCase: {
649
+
* privateInputs: [],
650
+
* method: async () => {
651
+
* return { publicOutput: Field(0) }
652
+
* }
653
+
* },
654
+
* add: {
655
+
* privateInputs: [SelfProof, Field],
656
+
* // `previous` is the type of proof produced by ExampleProgram
Copy file name to clipboardExpand all lines: src/snarky.d.ts
+26-5Lines changed: 26 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -48,10 +48,22 @@ export {
48
48
MlPublicKeyVar,
49
49
MlFeatureFlags,
50
50
areBindingsInitialized,
51
+
Base64ProofString,
52
+
Base64VerificationKeyString,
51
53
};
52
54
53
55
declareletareBindingsInitialized: boolean;
54
56
57
+
/**
58
+
* A string representation of a Pickles proof in base64 encoding, used for communication between OCaml and TypeScript and for JSON serialization.
59
+
*/
60
+
typeBase64ProofString=string;
61
+
62
+
/**
63
+
* A string representation of a constraint system's verification key in base64 encoding, used for communication between OCaml and TypeScript and for JSON serialization.
0 commit comments