Skip to content
Merged
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
8,666 changes: 6,378 additions & 2,288 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"ts-jest": "^29.0.5",
"typedoc": "^0.26.11",
"typedoc-plugin-frontmatter": "1.0.0",
"typedoc-plugin-inline-sources": "^1.2.0",
"typedoc-plugin-inline-sources": "1.2.0",
"typedoc-plugin-markdown": "4.2.10",
"typescript": "5.1",
"istanbul-merge": "^2.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"@proto-kit/module": "*",
"@proto-kit/protocol": "*",
"@proto-kit/sequencer": "*",
"o1js": "^1.6.0",
"o1js": "^2.10.0",
"tsyringe": "^4.10.0"
},
"devDependencies": {
Expand Down
6 changes: 3 additions & 3 deletions packages/api/src/metrics/OpenTelemetryServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ export class OpenTelemetryServer extends SequencerModule<OpenTelemetryServerConf
);

const metricReader =
metrics?.enabled ?? true
(metrics?.enabled ?? true)
? new PrometheusExporter(metrics?.prometheus)
: undefined;

const instrumentations =
metrics?.enabled ?? true
(metrics?.enabled ?? true)
? [
new RuntimeNodeInstrumentation({
monitoringPrecision: metrics?.nodeScrapeInterval ?? 5000,
Expand All @@ -74,7 +74,7 @@ export class OpenTelemetryServer extends SequencerModule<OpenTelemetryServerConf
: [];

const traceExporter =
tracing?.enabled ?? true
(tracing?.enabled ?? true)
? new OTLPTraceExporter(tracing?.otlp)
: undefined;

Expand Down
2 changes: 1 addition & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"ts-mixer": "^6.0.3"
},
"peerDependencies": {
"o1js": "^1.6.0",
"o1js": "^2.10.0",
"tsyringe": "^4.10.0"
},
"devDependencies": {
Expand Down
15 changes: 12 additions & 3 deletions packages/common/src/zkProgrammable/ZkProgrammable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ export interface Compile {
(): Promise<CompileArtifact>;
}

export interface PlainZkProgram<PublicInput = undefined, PublicOutput = void> {
export interface PlainZkProgram<
PublicInput = undefined,
PublicOutput = undefined,
> {
name: string;
compile: Compile;
verify: Verify<PublicInput, PublicOutput>;
Expand All @@ -45,11 +48,17 @@ export interface PlainZkProgram<PublicInput = undefined, PublicOutput = void> {
>;
methods: Record<
string,
| ((...args: any) => Promise<Proof<PublicInput, PublicOutput>>)
| ((...args: any) => Promise<{
proof: Proof<PublicInput, PublicOutput>;
auxiliaryOutput: any;
}>)
| ((
publicInput: PublicInput,
...args: any
) => Promise<Proof<PublicInput, PublicOutput>>)
) => Promise<{
proof: Proof<PublicInput, PublicOutput>;
auxiliaryOutput: any;
}>)
>;
analyzeMethods: () => Promise<
Record<string, Awaited<ReturnType<typeof Provable.constraintSystem>>>
Expand Down
18 changes: 15 additions & 3 deletions packages/common/src/zkProgrammable/provableMethod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ export function toProver(

if (areProofsEnabled) {
const programProvableMethod = zkProgram.methods[methodName];
return await Reflect.apply(programProvableMethod, this, args);
const result = await Reflect.apply(programProvableMethod, this, args);
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
return result.proof as Proof<any, any>;
}

// create a mock proof by simulating method> execution in JS
Expand All @@ -49,8 +51,18 @@ export function toProver(

// TODO: provide undefined if public input is not used
publicInput: isFirstParameterPublicInput ? args[0] : undefined,
publicOutput,

// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
publicOutput: (() => {
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
if (!publicOutput || typeof publicOutput !== "object") {
return undefined;
}
if ("publicOutput" in publicOutput) {
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
return (publicOutput as any).publicOutput;
}
return publicOutput;
})(),
/**
* We set this to the max possible number, to avoid having
* to manually count in-circuit proof verifications
Expand Down
18 changes: 11 additions & 7 deletions packages/common/test/zkProgrammable/ZkProgrammable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,22 @@ class TestProgrammable extends ZkProgrammable<
@provableMethod()
public async foo(publicInput: TestPublicInput, bar: Balance) {
// expose the private input as public output again for testing purposes
return new TestPublicOutput({
bar,
});
return {
publicOutput: new TestPublicOutput({
bar,
}),
};
}

@provableMethod()
public async fail(publicInput: TestPublicInput) {
publicInput.foo.assertEquals(1, failErrorMessage);

return new TestPublicOutput({
bar: Field(0),
});
return {
publicOutput: new TestPublicOutput({
bar: Field(0),
}),
};
}

public zkProgramFactory() {
Expand Down Expand Up @@ -272,7 +276,7 @@ describe("zkProgrammable", () => {
// proof bar
const otherTestProof = await executionContext
.current()
.result.prove<Proof<undefined, void>>();
.result.prove<Proof<undefined, undefined>>();
const otherTestProofVerified =
await otherTestProgrammable.zkProgram[0].verify(otherTestProof);

Expand Down
2 changes: 1 addition & 1 deletion packages/deployment/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@proto-kit/sdk": "*",
"@proto-kit/sequencer": "*",
"bullmq": "^3.15.8",
"o1js": "^1.6.0",
"o1js": "^2.10.0",
"tsyringe": "^4.10.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/indexer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"@proto-kit/sdk": "*",
"@proto-kit/sequencer": "*",
"koa": "^2.14.2",
"o1js": "^1.1.0",
"o1js": "^2.10.0",
"tsyringe": "^4.10.0",
"type-graphql": "2.0.0-rc.2",
"typegraphql-prisma": "0.28"
Expand Down
2 changes: 1 addition & 1 deletion packages/library/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@proto-kit/module": "*",
"@proto-kit/protocol": "*",
"@proto-kit/sequencer": "*",
"o1js": "^1.6.0",
"o1js": "^2.10.0",
"tsyringe": "^4.10.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/module/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"peerDependencies": {
"@proto-kit/common": "*",
"@proto-kit/protocol": "*",
"o1js": "^1.6.0",
"o1js": "^2.10.0",
"tsyringe": "^4.10.0"
},
"gitHead": "397881ed5d8f98f5005bcd7be7f5a12b3bc6f956"
Expand Down
10 changes: 6 additions & 4 deletions packages/module/src/method/MethodParameterEncoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
Provable,
DynamicProof,
FlexibleProvablePure,
FlexibleProvable,
} from "o1js";
import {
ArgumentTypes,
Expand All @@ -29,7 +30,7 @@ const errors = {
};

type ArgumentType =
| FlexibleProvablePure<any>
| FlexibleProvable<any>
| typeof Proof<unknown, unknown>
| typeof DynamicProof<unknown, unknown>;

Expand Down Expand Up @@ -122,7 +123,7 @@ export class MethodParameterEncoder {
);
}
// as any, since we shouldn't be using this workaround in the first place
return (type as FlexibleProvablePure<unknown>).sizeInFields();
return (type as FlexibleProvable<unknown>).sizeInFields();
}

public constructor(private readonly types: ArgTypeArray) {}
Expand Down Expand Up @@ -178,8 +179,9 @@ export class MethodParameterEncoder {
}
}

return (type as FlexibleProvablePure<unknown>).fromFields(
structFields
return (type as FlexibleProvable<unknown>).fromFields(
structFields,
[]
) as any;
})
);
Expand Down
15 changes: 14 additions & 1 deletion packages/module/src/runtime/Runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,23 @@ export class RuntimeZkProgrammable<

return splitRuntimeMethods().map((bucket, index) => {
const name = `RuntimeProgram-${index}`;
const wrappedBucket = Object.fromEntries(
Object.entries(bucket).map(([methodName, methodDef]) => [
methodName,
{
privateInputs: methodDef.privateInputs,
method: async (...args: any[]) => {
const publicOutput = await methodDef.method(...args);
return { publicOutput };
},
},
])
);

const program = ZkProgram({
name,
publicOutput: MethodPublicOutput,
methods: bucket,
methods: wrappedBucket,
});

const SelfProof = ZkProgram.Proof(program);
Expand Down
8 changes: 5 additions & 3 deletions packages/module/test/method/MethodParameterEncoder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ const TestProgram = ZkProgram({
privateInputs: [],
method: async (input: PublicKey) => {
return {
a: Field(input.x),
b: Bool(input.isOdd),
publicOutput: {
a: Field(input.x),
b: Bool(input.isOdd),
},
};
},
},
Expand Down Expand Up @@ -117,5 +119,5 @@ describe("MethodParameterEncoder", () => {
expect(decoded1.publicOutput.b.equals(output.b).toBoolean()).toStrictEqual(
true
);
}, 30000);
}, 60_000);
});
6 changes: 4 additions & 2 deletions packages/module/test/method/runtimeMethod-fail.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ const TestProgram = ZkProgram({
privateInputs: [],
method: async (input: PublicKey) => {
return {
a: Field(input.x),
b: Bool(input.isOdd),
publicOutput: {
a: Field(input.x),
b: Bool(input.isOdd),
},
};
},
},
Expand Down
2 changes: 1 addition & 1 deletion packages/persistance/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"@proto-kit/module": "*",
"@proto-kit/protocol": "*",
"@proto-kit/sequencer": "*",
"o1js": "^1.6.0",
"o1js": "^2.10.0",
"tsyringe": "^4.10.0"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe("prisma integration", () => {
[block, batch] = await appChain.sequencer
.resolve("BlockTrigger")
.produceBlockAndBatch();
}, 30000);
}, 60_000);

afterAll(async () => {
await teardown();
Expand Down Expand Up @@ -201,7 +201,7 @@ describe("prisma integration", () => {
expectDefined(block2);
expectDefined(batch2);
expect(block2.transactions).toHaveLength(1);
}, 30000);
}, 60_000);

it("should retrieve correct balance for account 2", async () => {
const balance = await appChain.query.runtime.Balances.balances.get(
Expand Down
2 changes: 1 addition & 1 deletion packages/processor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"@proto-kit/protocol": "*",
"@proto-kit/sdk": "*",
"@proto-kit/sequencer": "*",
"o1js": "^1.1.0",
"o1js": "^2.10.0",
"tsyringe": "^4.10.0",
"type-graphql": "2.0.0-rc.2",
"typegraphql-prisma": "^0.28"
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
"peerDependencies": {
"@proto-kit/common": "*",
"o1js": "^1.6.0",
"o1js": "^2.10.0",
"ts-pattern": "^4.3.0",
"tsyringe": "^4.10.0"
},
Expand Down
Loading