Skip to content

Commit c6de276

Browse files
authored
Merge pull request #1905 from o1-labs/querolita/chunking-mvp-bug
API chunking support
2 parents 7dfaaa3 + f00ef24 commit c6de276

File tree

6 files changed

+57
-3
lines changed

6 files changed

+57
-3
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
1717

1818
## [Unreleased](https://github.com/o1-labs/o1js/compare/4e23a60...HEAD)
1919

20+
### Added
21+
22+
- [PR! 1905](https://github.com/o1-labs/o1js/pull/1905) API support for circuit chunking
23+
- still requires memory optimizations to be fully functional, and
24+
- proof-systems version still needs to be updated to include [this commit](https://github.com/o1-labs/proof-systems/pull/3222/commits/8c37c293f8159eed3676964ba47fc5dc0ae6ea1e)
25+
- that fixed the zero knowledge rows mismatch across Kimchi WASM bindings
26+
2027
## [2.5.0](https://github.com/o1-labs/o1js/compare/6ff7f8470a...4e23a60)
2128

2229
### Fixed

src/bindings/ocaml/lib/pickles_bindings.ml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,8 @@ let pickles_compile (choices : pickles_rule_js array)
617617
< publicInputSize : int Js.prop
618618
; publicOutputSize : int Js.prop
619619
; storable : Cache.js_storable Js.optdef_prop
620-
; overrideWrapDomain : int Js.optdef_prop >
620+
; overrideWrapDomain : int Js.optdef_prop
621+
; numChunks : int Js.optdef_prop >
621622
Js.t ) =
622623
(* translate number of branches and recursively verified proofs from JS *)
623624
let branches = Array.length choices in
@@ -636,6 +637,9 @@ let pickles_compile (choices : pickles_rule_js array)
636637
Js.Optdef.to_option config##.overrideWrapDomain
637638
|> Option.map ~f:Pickles_base.Proofs_verified.of_int_exn
638639
in
640+
let num_chunks =
641+
Js.Optdef.get config##.numChunks (fun () -> 1)
642+
in
639643
let (Choices choices) =
640644
Choices.of_js ~public_input_size ~public_output_size choices
641645
in
@@ -658,7 +662,7 @@ let pickles_compile (choices : pickles_rule_js array)
658662
, public_input_typ public_output_size ) )
659663
~auxiliary_typ:Typ.unit
660664
~max_proofs_verified:(module Max_proofs_verified)
661-
~name ~choices ()
665+
~name ~num_chunks ~choices ()
662666
in
663667

664668
(* translate returned prover and verify functions to JS *)

src/bindings/ocaml/lib/pickles_bindings.mli

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ val pickles :
6565
-> < publicInputSize : int Js.prop
6666
; publicOutputSize : int Js.prop
6767
; storable : Cache.js_storable Js.optdef_prop
68-
; overrideWrapDomain : int Js.optdef_prop >
68+
; overrideWrapDomain : int Js.optdef_prop
69+
; numChunks : int Js.optdef_prop >
6970
Js.t
7071
-> < getVerificationKey :
7172
( unit
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { Field, Cache, Gadgets, ZkProgram } from 'o1js';
2+
3+
let MyProgram = ZkProgram({
4+
chunks: 1,
5+
overrideWrapDomain: 0,
6+
name: 'example-with-chunking',
7+
publicOutput: Field,
8+
9+
methods: {
10+
baseCase: {
11+
privateInputs: [Field],
12+
async method(input: Field) {
13+
for (let i = 0; i < 1 << 16; i++) {
14+
Gadgets.rangeCheck64(Field(input).add(Field(i)));
15+
}
16+
// The above generates 2^16+2^15 rows which needs to be split into 2 chunks
17+
return {
18+
publicOutput: Field(0),
19+
};
20+
},
21+
},
22+
},
23+
});
24+
25+
console.log(await MyProgram.analyzeMethods());
26+
27+
console.log('compiling MyProgram...');
28+
await MyProgram.compile({ cache: Cache.None });
29+
30+
console.log('proving base case...');
31+
let { proof } = await MyProgram.baseCase(Field(0));
32+
33+
console.log('verify...');
34+
let ok = await MyProgram.verify(proof);
35+
console.log('ok?', ok);

src/lib/proof-system/zkprogram.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ function ZkProgram<
233233
[I in keyof Config['methods']]: InferMethodType<Config>[I];
234234
};
235235
overrideWrapDomain?: 0 | 1 | 2;
236+
numChunks?: number;
236237
}
237238
): {
238239
name: string;
@@ -243,6 +244,7 @@ function ZkProgram<
243244
forceRecompile?: boolean;
244245
proofsEnabled?: boolean;
245246
withRuntimeTables?: boolean;
247+
numChunks?: number;
246248
}) => Promise<{
247249
verificationKey: { data: string; hash: Field };
248250
}>;
@@ -386,6 +388,7 @@ function ZkProgram<
386388
cache,
387389
forceRecompile,
388390
overrideWrapDomain: config.overrideWrapDomain,
391+
numChunks: config.numChunks,
389392
state: programState,
390393
withRuntimeTables,
391394
});
@@ -690,6 +693,7 @@ async function compileProgram({
690693
cache,
691694
forceRecompile,
692695
overrideWrapDomain,
696+
numChunks,
693697
state,
694698
withRuntimeTables,
695699
}: {
@@ -703,6 +707,7 @@ async function compileProgram({
703707
cache: Cache;
704708
forceRecompile: boolean;
705709
overrideWrapDomain?: 0 | 1 | 2;
710+
numChunks?: number;
706711
state?: ReturnType<typeof createProgramState>;
707712
withRuntimeTables?: boolean;
708713
}) {
@@ -760,6 +765,7 @@ If you are using a SmartContract, make sure you are using the @method decorator.
760765
publicOutputSize: publicOutputType.sizeInFields(),
761766
storable: picklesCache,
762767
overrideWrapDomain,
768+
numChunks: numChunks ?? 1,
763769
});
764770
let { getVerificationKey, provers, verify, tag } = result;
765771
CompiledTag.store(proofSystemTag, tag);

src/snarky.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,7 @@ declare const Pickles: {
702702
publicOutputSize: number;
703703
storable?: Pickles.Cache;
704704
overrideWrapDomain?: 0 | 1 | 2;
705+
numChunks?: number;
705706
}
706707
) => {
707708
provers: MlArray<Pickles.Prover>;

0 commit comments

Comments
 (0)