Skip to content

Commit 17adf4b

Browse files
authored
Merge pull request #1933 from o1-labs/feature/zkprogram-qol
ZkPrograms QoL improvements
2 parents 1122d05 + fe77072 commit 17adf4b

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
@@ -30,6 +30,11 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
3030
- Method for optional types to assert none https://github.com/o1-labs/o1js/pull/1922
3131
- Increased maximum supported amount of methods in a `SmartContract` or `ZkProgram` to 30. https://github.com/o1-labs/o1js/pull/1918
3232
- Expose low-level conversion methods `Proof.{_proofToBase64,_proofFromBase64}` https://github.com/o1-labs/o1js/pull/1928
33+
- Expore `maxProofsVerified()` and a `Proof` class directly on ZkPrograms https://github.com/o1-labs/o1js/pull/1933
34+
35+
### Changed
36+
37+
- Changed an internal type to improve IntelliSense on ZkProgram methods https://github.com/o1-labs/o1js/pull/1933
3338

3439
### Fixed
3540

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
@@ -224,6 +224,8 @@ function ZkProgram<
224224
}
225225
): {
226226
name: string;
227+
maxProofsVerified(): Promise<0 | 1 | 2>;
228+
227229
compile: (options?: {
228230
cache?: Cache;
229231
forceRecompile?: boolean;
@@ -243,13 +245,20 @@ function ZkProgram<
243245
ReturnType<typeof analyzeMethod>
244246
>;
245247
}>;
248+
246249
publicInputType: ProvableOrUndefined<Get<Config, 'publicInput'>>;
247250
publicOutputType: ProvableOrVoid<Get<Config, 'publicOutput'>>;
248251
privateInputTypes: PrivateInputs;
249252
auxiliaryOutputTypes: AuxiliaryOutputs;
250253
rawMethods: {
251254
[I in keyof Config['methods']]: Methods[I]['method'];
252255
};
256+
257+
Proof: typeof Proof<
258+
InferProvableOrUndefined<Get<Config, 'publicInput'>>,
259+
InferProvableOrVoid<Get<Config, 'publicOutput'>>
260+
>;
261+
253262
proofsEnabled: boolean;
254263
setProofsEnabled(proofsEnabled: boolean): void;
255264
} & {
@@ -522,10 +531,13 @@ function ZkProgram<
522531
const program = Object.assign(
523532
selfTag,
524533
{
534+
maxProofsVerified: getMaxProofsVerified,
535+
525536
compile,
526537
verify,
527538
digest,
528539
analyzeMethods,
540+
529541
publicInputType: publicInputType as ProvableOrUndefined<
530542
Get<Config, 'publicInput'>
531543
>,
@@ -541,6 +553,9 @@ function ZkProgram<
541553
rawMethods: Object.fromEntries(
542554
methodKeys.map((key) => [key, methods[key].method])
543555
) as any,
556+
557+
Proof: SelfProof,
558+
544559
proofsEnabled: doProving,
545560
setProofsEnabled(proofsEnabled: boolean) {
546561
doProving = proofsEnabled;
@@ -1127,7 +1142,7 @@ type Infer<T> = T extends Subclass<typeof ProofBase>
11271142

11281143
type TupleToInstances<T> = {
11291144
[I in keyof T]: Infer<T[I]>;
1130-
} & any[];
1145+
};
11311146

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

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)