Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
5,455 changes: 4,620 additions & 835 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"build": "tsc -p tsconfig.json",
"dev": "tsc -p tsconfig.json --watch",
"lint": "eslint ./src ./test",
"test:file": "node --experimental-vm-modules --experimental-wasm-modules --experimental-wasm-threads ../../node_modules/jest/bin/jest.js",
"test:file": "node --experimental-vm-modules ../../node_modules/jest/bin/jest.js",
"test": "npm run test:file -- ./test/**",
"test:watch": "npm run test:file -- ./test/** --watch"
},
Expand All @@ -34,7 +34,7 @@
"@proto-kit/module": "*",
"@proto-kit/protocol": "*",
"@proto-kit/sequencer": "*",
"o1js": "^1.6.0",
"o1js": "^2.0.0",
"tsyringe": "^4.7.0"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"build": "tsc -p tsconfig.json",
"dev": "tsc -p tsconfig.json --watch",
"lint": "eslint ./src ./test",
"test:file": "node --experimental-vm-modules --experimental-wasm-modules --experimental-wasm-threads ../../node_modules/jest/bin/jest.js",
"test:file": "node --experimental-vm-modules ../../node_modules/jest/bin/jest.js",
"test": "npm run test:file -- ./test/**",
"test:watch": "npm run test:file -- ./test/** --watch"
},
Expand All @@ -23,7 +23,7 @@
"typescript-memoize": "^1.1.1"
},
"peerDependencies": {
"o1js": "^1.6.0",
"o1js": "^2.0.0",
"tsyringe": "^4.7.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/compiling/AtomicCompileHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
AreProofsEnabled,
CompileArtifact,
MOCK_VERIFICATION_KEY,
} from "../zkProgrammable/ZkProgrammable";
} from "../zkProgrammable/Helper";
import { isSubtypeOfName } from "../utils";
import { TypedClass } from "../types";
import { log } from "../log";
Expand Down
5 changes: 1 addition & 4 deletions packages/common/src/compiling/CompileRegistry.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { inject, injectable, singleton } from "tsyringe";

import {
AreProofsEnabled,
CompileArtifact,
} from "../zkProgrammable/ZkProgrammable";
import { AreProofsEnabled, CompileArtifact } from "../zkProgrammable/Helper";

import {
ArtifactRecord,
Expand Down
4 changes: 2 additions & 2 deletions packages/common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ export * from "./config/ConfigurableModule";
export * from "./config/ChildContainerProvider";
export * from "./config/ChildContainerCreatable";
export * from "./types";
export * from "./zkProgrammable/ZkProgrammable";
export * from "./zkProgrammable/WithZkProgram";
export * from "./zkProgrammable/Helper";
export * from "./zkProgrammable/ProvableMethodExecutionContext";
export * from "./zkProgrammable/provableMethod";
export * from "./utils";
export * from "./dependencyFactory/DependencyFactory";
export * from "./dependencyFactory/injectOptional";
Expand Down
23 changes: 23 additions & 0 deletions packages/common/src/zkProgrammable/Helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Field } from "o1js";

export interface AreProofsEnabled {
areProofsEnabled: boolean;
setProofsEnabled: (areProofsEnabled: boolean) => void;
}
export interface CompileArtifact {
verificationKey: {
data: string;
hash: Field;
};
}

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

export const MOCK_PROOF = "mock-proof";

export const MOCK_VERIFICATION_KEY = {
data: "mock-verification-key",
hash: Field(0),
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Proof } from "o1js";
import { singleton } from "tsyringe";
import uniqueId from "lodash/uniqueId";

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

const errors = {
moduleOrMethodNameNotSet: () => new Error("Module or method name not set"),
Expand All @@ -20,7 +20,10 @@ export class ProvableMethodExecutionResult {

public args?: ArgumentTypes;

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

public async prove<
ProofType extends Proof<unknown, unknown>,
Expand All @@ -35,7 +38,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 +61,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
78 changes: 78 additions & 0 deletions packages/common/src/zkProgrammable/WithZkProgram.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import {
DynamicProof,
FlexibleProvablePure,
Proof,
Provable,
ZkProgram,
} from "o1js";

import { CompileRegistry } from "../compiling/CompileRegistry";

import { Compile, CompileArtifact } from "./Helper";

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 Verify<PublicInput, PublicOutput> {
(proof: Proof<PublicInput, PublicOutput>): Promise<boolean>;
}

export interface PlainZkProgram<PublicInput = undefined, PublicOutput = void> {
name: string;
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;
setProofsEnabled(proofsEnabled: boolean): void;
}

export interface ZkProgramFactory<PublicInput, PublicOutput> {
zkProgramFactory(): PlainZkProgram<PublicInput, PublicOutput>[];
compile(registry: CompileRegistry): Promise<Record<string, CompileArtifact>>;
// appChain: AreProofsEnabled | undefined;
}

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

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

export function toProver(
methodName: string,
areProofsEnabled: boolean,
...args: ArgumentTypes
) {
return async function prover(this: ZkProgramFactory<any, any>) {
const zkProgram = this.zkProgramFactory().find((prog) =>
Object.keys(prog.methods).includes(methodName)
);

if (zkProgram === undefined) {
throw new Error("Correct ZkProgram not found");
}

const programProvableMethod = zkProgram.methods[methodName];
return await Reflect.apply(programProvableMethod, this, args);
};
}
151 changes: 0 additions & 151 deletions packages/common/src/zkProgrammable/ZkProgrammable.ts

This file was deleted.

Loading