Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/remove-zkProgrammable #249

Draft
wants to merge 30 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
1525417
Update O1js to version 2
ejMina226 Dec 19, 2024
50fbc48
Remove zkProgrammable
ejMina226 Dec 19, 2024
1d40067
Add in lock file
ejMina226 Dec 19, 2024
5d5383a
Add back in ProvableMethodExecutionContext
ejMina226 Dec 20, 2024
3c42e6e
Add in files
ejMina226 Dec 20, 2024
7587a47
Update BlockProvable
ejMina226 Jan 2, 2025
47776d9
Update provable Method
ejMina226 Jan 2, 2025
be3b55d
Move files
ejMina226 Jan 3, 2025
22ef6bf
Update STProver
ejMina226 Jan 3, 2025
72c66db
Update ZkProgram due to o1js changes
ejMina226 Jan 3, 2025
1f5df9e
Change WithZkProgram to interface
ejMina226 Jan 3, 2025
e48acde
Update with ZkProgram and STProver
ejMina226 Jan 3, 2025
78326ca
Update names to remove programmable
ejMina226 Jan 3, 2025
895b38b
Update types
ejMina226 Jan 3, 2025
9e2441d
Add in types
ejMina226 Jan 6, 2025
f332066
Fix type
ejMina226 Jan 6, 2025
d16e338
Update runtime
ejMina226 Jan 6, 2025
a62af86
Rename programmable to factory
ejMina226 Jan 6, 2025
e00f91a
Fix o1js type change
ejMina226 Jan 6, 2025
b89f299
Add toProver
ejMina226 Jan 6, 2025
802c29d
Change types for o1js
ejMina226 Jan 6, 2025
0ab96ab
Fix other types.
ejMina226 Jan 6, 2025
a0ecbeb
Don't need mock proof in utils
ejMina226 Jan 7, 2025
26d56cb
Get BP serialiser working
ejMina226 Jan 7, 2025
a80821f
Change zkProgrammable to zkProgram
ejMina226 Jan 7, 2025
10e3341
Fix o1js types
ejMina226 Jan 7, 2025
c29566c
Fix o1js types
ejMina226 Jan 7, 2025
8da0793
Fix import
ejMina226 Jan 7, 2025
c3e6488
Fix tests
ejMina226 Jan 7, 2025
f7df3c5
Fix linting
ejMina226 Jan 7, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4,703 changes: 2,554 additions & 2,149 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"@proto-kit/module": "*",
"@proto-kit/protocol": "*",
"@proto-kit/sequencer": "*",
"o1js": "^1.1.0",
"o1js": "^2.0.0",
"tsyringe": "^4.7.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"typescript-memoize": "^1.1.1"
},
"peerDependencies": {
"o1js": "^1.1.0",
"o1js": "^2.0.0",
"tsyringe": "^4.7.0"
},
"devDependencies": {
Expand Down
5 changes: 2 additions & 3 deletions packages/common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ export * from "./config/ConfigurableModule";
export * from "./config/ChildContainerProvider";
export * from "./config/ChildContainerCreatable";
export * from "./types";
export * from "./zkProgrammable/ZkProgrammable";
export * from "./zkProgrammable/ProvableMethodExecutionContext";
export * from "./zkProgrammable/provableMethod";
export * from "./utils";
export * from "./dependencyFactory/DependencyFactory";
export * from "./dependencyFactory/injectOptional";
Expand All @@ -17,3 +14,5 @@ export * from "./trees/InMemoryMerkleTreeStorage";
export * from "./trees/RollupMerkleTree";
export * from "./events/EventEmitterProxy";
export * from "./trees/MockAsyncMerkleStore";
export * from "./zkProgram/ProvableMethodExecutionContext";
export * from "./zkProgram/WithZkProgram";
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import type { Proof } from "o1js";
import { Proof } from "o1js";
import { singleton } from "tsyringe";
import uniqueId from "lodash/uniqueId";

import type { ArgumentTypes } from "./provableMethod";
import { ArgumentTypes } from "./WithZkProgram";

const errors = {
appChainNotSet: (name: string) =>
new Error(`Appchain was not injected for: ${name}`),

moduleOrMethodNameNotSet: () => new Error("Module or method name not set"),

proverNotSet: (moduleName: string, methodName: string) =>
Expand All @@ -20,7 +23,10 @@ export class ProvableMethodExecutionResult {

public args?: ArgumentTypes;

public prover?: () => Promise<Proof<unknown, unknown>>;
public prover?: () => Promise<{
proof: Proof<any, any>;
auxiliaryOutput: undefined;
}>;

public async prove<
ProofType extends Proof<unknown, unknown>,
Expand All @@ -35,7 +41,7 @@ export class ProvableMethodExecutionResult {

// turn the prover result into the desired proof type
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
return (await this.prover()) as ProofType;
return (await this.prover()).proof as ProofType;
}
}

Expand All @@ -58,10 +64,15 @@ export class ProvableMethodExecutionContext {
* Adds a method prover to the current execution context,
* which can be collected and ran asynchronously at a later point in time.
*
* @param prove - Prover function to be ran later,
* when the method execution needs to be proven
* @param prover
*/
public setProver(prover: () => Promise<Proof<unknown, unknown>>) {
public setProver(
prover: () => Promise<{
proof: Proof<any, any>;
auxiliaryOutput: undefined;
}>
) {
this.result.prover = prover;
}

Expand Down
95 changes: 95 additions & 0 deletions packages/common/src/zkProgram/WithZkProgram.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import {
DynamicProof,
Field,
FlexibleProvablePure,
Proof,
Provable,
ZkProgram,
} from "o1js";

export type O1JSPrimitive = object | string | boolean | number;
export type ArgumentTypes = (
| O1JSPrimitive
| Proof<unknown, unknown>
| DynamicProof<unknown, unknown>
)[];
export type DecoratedMethod = (...args: ArgumentTypes) => Promise<unknown>;

export interface CompileArtifact {
verificationKey: {
data: string;
hash: Field;
};
}

export interface AreProofsEnabled {
areProofsEnabled: boolean;
setProofsEnabled: (areProofsEnabled: boolean) => void;
}

export interface Verify<PublicInput, PublicOutput> {
(proof: Proof<PublicInput, PublicOutput>): Promise<boolean>;
}

export interface Compile {
(): Promise<CompileArtifact>;
}

export interface PlainZkProgram<PublicInput = undefined, PublicOutput = void> {
compile: Compile;
verify: Verify<PublicInput, PublicOutput>;
Proof: ReturnType<
typeof ZkProgram.Proof<
FlexibleProvablePure<PublicInput>,
FlexibleProvablePure<PublicOutput>
>
>;
methods: Record<
string,
(...args: any) => Promise<{
proof: Proof<PublicInput, PublicOutput>;
auxiliaryOutput: undefined;
}>
>;
analyzeMethods: () => Promise<
Record<string, Awaited<ReturnType<typeof Provable.constraintSystem>>>
>;
proofsEnabled: boolean;
}

export interface ZkProgramFactory<PublicInput, PublicOutput> {
zkProgramFactory(): PlainZkProgram<PublicInput, PublicOutput>[];
}

export interface WithZkProgram<PublicInput = undefined, PublicOutput = void> {
readonly zkProgramFactory: ZkProgramFactory<PublicInput, PublicOutput>;

readonly zkProgram: PlainZkProgram<PublicInput, PublicOutput>[];
}

export const MOCK_PROOF = "mock-proof";

export const MOCK_VERIFICATION_KEY = {
data: "mock-verification-key",
hash: Field(0),
};

export function toProver(
methodName: string,
simulatedMethod: DecoratedMethod,
isFirstParameterPublicInput: boolean,
areProofsEnabled: boolean,
...args: ArgumentTypes
) {
return async function prover(this: ZkProgramFactory<any, any>) {
for (const prog of this.zkProgramFactory()) {
if (Object.keys(prog.methods).includes(methodName)) {
prog.proofsEnabled = areProofsEnabled;
const programProvableMethod = prog.methods[methodName];
// eslint-disable-next-line no-await-in-loop
return await Reflect.apply(programProvableMethod, this, args);
}
}
throw Error("No zkProgram found with given method.");
};
}
131 changes: 0 additions & 131 deletions packages/common/src/zkProgrammable/ZkProgrammable.ts

This file was deleted.

Loading
Loading