Skip to content

Commit 11b7460

Browse files
committed
Merge branch 'feature/zkprogram-qol' into feature/conditional-recursive-proving
2 parents 1a903d0 + e59b340 commit 11b7460

File tree

11 files changed

+43
-111
lines changed

11 files changed

+43
-111
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
3131
- Method for optional types to assert none https://github.com/o1-labs/o1js/pull/1922
3232
- Increased maximum supported amount of methods in a `SmartContract` or `ZkProgram` to 30. https://github.com/o1-labs/o1js/pull/1918
3333
- Expose low-level conversion methods `Proof.{_proofToBase64,_proofFromBase64}` https://github.com/o1-labs/o1js/pull/1928
34+
- Expore `maxProofsVerified()` and a `Proof` class directly on ZkPrograms https://github.com/o1-labs/o1js/pull/1933
35+
36+
### Changed
37+
38+
- Changed an internal type to improve IntelliSense on ZkProgram methods https://github.com/o1-labs/o1js/pull/1933
3439

3540
### Fixed
3641

run-minimal-mina-tests.sh

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/examples/zkprogram/mututal-recursion.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,13 @@ const add = ZkProgram({
4747
},
4848
});
4949

50-
const AddProof = ZkProgram.Proof(add);
51-
5250
const multiply = ZkProgram({
5351
name: 'multiply',
5452
publicInput: Undefined,
5553
publicOutput: Field,
5654
methods: {
5755
performMultiplication: {
58-
privateInputs: [Field, AddProof],
56+
privateInputs: [Field, add.Proof],
5957
async method(field: Field, addProof: Proof<Undefined, Field>) {
6058
addProof.verify();
6159
const multiplicationResult = addProof.publicOutput.mul(field);

src/examples/zkprogram/program-with-input.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ MyProgram.publicOutputType satisfies Provable<void>;
3535
MyProgram.privateInputTypes;
3636
MyProgram.auxiliaryOutputTypes;
3737

38-
let MyProof = ZkProgram.Proof(MyProgram);
39-
4038
console.log('program digest', await MyProgram.digest());
4139

4240
console.log('compiling MyProgram...');
@@ -45,7 +43,7 @@ console.log('verification key', verificationKey.data.slice(0, 10) + '..');
4543

4644
console.log('proving base case...');
4745
let { proof } = await MyProgram.baseCase(Field(0));
48-
proof = await testJsonRoundtrip(MyProof, proof);
46+
proof = await testJsonRoundtrip(MyProgram.Proof, proof);
4947

5048
// type sanity check
5149
proof satisfies Proof<Field, void>;
@@ -60,7 +58,7 @@ console.log('ok (alternative)?', ok);
6058

6159
console.log('proving step 1...');
6260
let { proof: proof1 } = await MyProgram.inductiveCase(Field(1), proof);
63-
proof1 = await testJsonRoundtrip(MyProof, proof1);
61+
proof1 = await testJsonRoundtrip(MyProgram.Proof, proof1);
6462

6563
console.log('verify...');
6664
ok = await verify(proof1, verificationKey);
@@ -72,7 +70,7 @@ console.log('ok (alternative)?', ok);
7270

7371
console.log('proving step 2...');
7472
let { proof: proof2 } = await MyProgram.inductiveCase(Field(2), proof1);
75-
proof2 = await testJsonRoundtrip(MyProof, proof2);
73+
proof2 = await testJsonRoundtrip(MyProgram.Proof, proof2);
7674

7775
console.log('verify...');
7876
ok = await verify(proof2.toJSON(), verificationKey);

src/lib/mina/actions/offchain-state-rollup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ function OffchainStateRollup({
239239
},
240240
});
241241

242-
let RollupProof = ZkProgram.Proof(offchainStateRollup);
242+
let RollupProof = offchainStateRollup.Proof;
243243

244244
let isCompiled = false;
245245

src/lib/proof-system/proof-system.unit-test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const EmptyProgram = ZkProgram({
2626
methods: { run: { privateInputs: [], async method(_) {} } },
2727
});
2828

29-
class EmptyProof extends ZkProgram.Proof(EmptyProgram) {}
29+
class EmptyProof extends EmptyProgram.Proof {}
3030

3131
// unit-test zkprogram creation helpers:
3232
// -) sortMethodArguments

src/lib/proof-system/zkprogram.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ function ZkProgram<
225225
}
226226
): {
227227
name: string;
228+
maxProofsVerified(): Promise<0 | 1 | 2>;
229+
228230
compile: (options?: {
229231
cache?: Cache;
230232
forceRecompile?: boolean;
@@ -244,13 +246,20 @@ function ZkProgram<
244246
ReturnType<typeof analyzeMethod>
245247
>;
246248
}>;
249+
247250
publicInputType: ProvableOrUndefined<Get<Config, 'publicInput'>>;
248251
publicOutputType: ProvableOrVoid<Get<Config, 'publicOutput'>>;
249252
privateInputTypes: PrivateInputs;
250253
auxiliaryOutputTypes: AuxiliaryOutputs;
251254
rawMethods: {
252255
[I in keyof Config['methods']]: Methods[I]['method'];
253256
};
257+
258+
Proof: typeof Proof<
259+
InferProvableOrUndefined<Get<Config, 'publicInput'>>,
260+
InferProvableOrVoid<Get<Config, 'publicOutput'>>
261+
>;
262+
254263
proofsEnabled: boolean;
255264
setProofsEnabled(proofsEnabled: boolean): void;
256265
} & {
@@ -523,10 +532,13 @@ function ZkProgram<
523532
const program = Object.assign(
524533
selfTag,
525534
{
535+
maxProofsVerified: getMaxProofsVerified,
536+
526537
compile,
527538
verify,
528539
digest,
529540
analyzeMethods,
541+
530542
publicInputType: publicInputType as ProvableOrUndefined<
531543
Get<Config, 'publicInput'>
532544
>,
@@ -542,6 +554,9 @@ function ZkProgram<
542554
rawMethods: Object.fromEntries(
543555
methodKeys.map((key) => [key, methods[key].method])
544556
) as any,
557+
558+
Proof: SelfProof,
559+
545560
proofsEnabled: doProving,
546561
setProofsEnabled(proofsEnabled: boolean) {
547562
doProving = proofsEnabled;
@@ -1128,7 +1143,7 @@ type Infer<T> = T extends Subclass<typeof ProofBase>
11281143

11291144
type TupleToInstances<T> = {
11301145
[I in keyof T]: Infer<T[I]>;
1131-
} & any[];
1146+
};
11321147

11331148
type PrivateInput = ProvableType | Subclass<typeof ProofBase>;
11341149

src/lib/provable/test/custom-gates-recursion.unit-test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ let emptyProgram = ZkProgram({
2929
name: 'empty',
3030
methods: { run: { privateInputs: [], async method() {} } },
3131
});
32-
class EmptyProof extends ZkProgram.Proof(emptyProgram) {}
32+
class EmptyProof extends emptyProgram.Proof {}
3333

3434
let program = ZkProgram({
3535
name: 'ecdsa',

src/tests/fake-proof.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const FakeProgram = ZkProgram({
4242
},
4343
});
4444

45-
class RealProof extends ZkProgram.Proof(RealProgram) {}
45+
class RealProof extends RealProgram.Proof {}
4646
class Nested extends Struct({ inner: RealProof }) {}
4747

4848
const RecursiveProgram = ZkProgram({

src/tests/inductive-proofs-small.ts

Lines changed: 0 additions & 81 deletions
This file was deleted.

0 commit comments

Comments
 (0)