@proto-kit/common 0.1.1-develop.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +201 -0
- package/dist/compiling/AtomicCompileHelper.d.ts +13 -0
- package/dist/compiling/AtomicCompileHelper.d.ts.map +1 -0
- package/dist/compiling/AtomicCompileHelper.js +40 -0
- package/dist/compiling/AtomicCompileHelper.js.map +1 -0
- package/dist/compiling/CompilableModule.d.ts +6 -0
- package/dist/compiling/CompilableModule.d.ts.map +1 -0
- package/dist/compiling/CompilableModule.js +2 -0
- package/dist/compiling/CompilableModule.js.map +1 -0
- package/dist/compiling/CompileRegistry.d.ts +26 -0
- package/dist/compiling/CompileRegistry.d.ts.map +1 -0
- package/dist/compiling/CompileRegistry.js +68 -0
- package/dist/compiling/CompileRegistry.js.map +1 -0
- package/dist/compiling/services/ChildVerificationKeyService.d.ts +10 -0
- package/dist/compiling/services/ChildVerificationKeyService.d.ts.map +1 -0
- package/dist/compiling/services/ChildVerificationKeyService.js +27 -0
- package/dist/compiling/services/ChildVerificationKeyService.js.map +1 -0
- package/dist/config/ChildContainerCreatable.d.ts +5 -0
- package/dist/config/ChildContainerCreatable.d.ts.map +1 -0
- package/dist/config/ChildContainerCreatable.js +2 -0
- package/dist/config/ChildContainerCreatable.js.map +1 -0
- package/dist/config/ChildContainerProvider.d.ts +5 -0
- package/dist/config/ChildContainerProvider.d.ts.map +1 -0
- package/dist/config/ChildContainerProvider.js +2 -0
- package/dist/config/ChildContainerProvider.js.map +1 -0
- package/dist/config/ConfigurableModule.d.ts +25 -0
- package/dist/config/ConfigurableModule.d.ts.map +1 -0
- package/dist/config/ConfigurableModule.js +24 -0
- package/dist/config/ConfigurableModule.js.map +1 -0
- package/dist/config/ModuleContainer.d.ts +162 -0
- package/dist/config/ModuleContainer.d.ts.map +1 -0
- package/dist/config/ModuleContainer.js +289 -0
- package/dist/config/ModuleContainer.js.map +1 -0
- package/dist/config/injectAlias.d.ts +18 -0
- package/dist/config/injectAlias.d.ts.map +1 -0
- package/dist/config/injectAlias.js +47 -0
- package/dist/config/injectAlias.js.map +1 -0
- package/dist/dependencyFactory/DependencyFactory.d.ts +29 -0
- package/dist/dependencyFactory/DependencyFactory.d.ts.map +1 -0
- package/dist/dependencyFactory/DependencyFactory.js +2 -0
- package/dist/dependencyFactory/DependencyFactory.js.map +1 -0
- package/dist/dependencyFactory/injectOptional.d.ts +16 -0
- package/dist/dependencyFactory/injectOptional.d.ts.map +1 -0
- package/dist/dependencyFactory/injectOptional.js +40 -0
- package/dist/dependencyFactory/injectOptional.js.map +1 -0
- package/dist/dummyVerificationKey.d.ts +3 -0
- package/dist/dummyVerificationKey.d.ts.map +1 -0
- package/dist/dummyVerificationKey.js +8 -0
- package/dist/dummyVerificationKey.js.map +1 -0
- package/dist/events/EventEmitter.d.ts +19 -0
- package/dist/events/EventEmitter.d.ts.map +1 -0
- package/dist/events/EventEmitter.js +35 -0
- package/dist/events/EventEmitter.js.map +1 -0
- package/dist/events/EventEmitterProxy.d.ts +18 -0
- package/dist/events/EventEmitterProxy.d.ts.map +1 -0
- package/dist/events/EventEmitterProxy.js +35 -0
- package/dist/events/EventEmitterProxy.js.map +1 -0
- package/dist/events/EventEmittingComponent.d.ts +9 -0
- package/dist/events/EventEmittingComponent.d.ts.map +1 -0
- package/dist/events/EventEmittingComponent.js +2 -0
- package/dist/events/EventEmittingComponent.js.map +1 -0
- package/dist/events/ReplayingSingleUseEventEmitter.d.ts +17 -0
- package/dist/events/ReplayingSingleUseEventEmitter.d.ts.map +1 -0
- package/dist/events/ReplayingSingleUseEventEmitter.js +34 -0
- package/dist/events/ReplayingSingleUseEventEmitter.js.map +1 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/log.d.ts +37 -0
- package/dist/log.d.ts.map +1 -0
- package/dist/log.js +114 -0
- package/dist/log.js.map +1 -0
- package/dist/trees/InMemoryMerkleTreeStorage.d.ts +11 -0
- package/dist/trees/InMemoryMerkleTreeStorage.d.ts.map +1 -0
- package/dist/trees/InMemoryMerkleTreeStorage.js +13 -0
- package/dist/trees/InMemoryMerkleTreeStorage.js.map +1 -0
- package/dist/trees/MerkleTreeStore.d.ts +5 -0
- package/dist/trees/MerkleTreeStore.d.ts.map +1 -0
- package/dist/trees/MerkleTreeStore.js +2 -0
- package/dist/trees/MerkleTreeStore.js.map +1 -0
- package/dist/trees/MockAsyncMerkleStore.d.ts +9 -0
- package/dist/trees/MockAsyncMerkleStore.d.ts.map +1 -0
- package/dist/trees/MockAsyncMerkleStore.js +20 -0
- package/dist/trees/MockAsyncMerkleStore.js.map +1 -0
- package/dist/trees/RollupMerkleTree.d.ts +147 -0
- package/dist/trees/RollupMerkleTree.d.ts.map +1 -0
- package/dist/trees/RollupMerkleTree.js +218 -0
- package/dist/trees/RollupMerkleTree.js.map +1 -0
- package/dist/trees/VirtualMerkleTreeStore.d.ts +13 -0
- package/dist/trees/VirtualMerkleTreeStore.d.ts.map +1 -0
- package/dist/trees/VirtualMerkleTreeStore.js +18 -0
- package/dist/trees/VirtualMerkleTreeStore.js.map +1 -0
- package/dist/types.d.ts +27 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +12 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +48 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +113 -0
- package/dist/utils.js.map +1 -0
- package/dist/zkProgrammable/ProvableMethodExecutionContext.d.ts +54 -0
- package/dist/zkProgrammable/ProvableMethodExecutionContext.d.ts.map +1 -0
- package/dist/zkProgrammable/ProvableMethodExecutionContext.js +97 -0
- package/dist/zkProgrammable/ProvableMethodExecutionContext.js.map +1 -0
- package/dist/zkProgrammable/ZkProgrammable.d.ts +40 -0
- package/dist/zkProgrammable/ZkProgrammable.d.ts.map +1 -0
- package/dist/zkProgrammable/ZkProgrammable.js +79 -0
- package/dist/zkProgrammable/ZkProgrammable.js.map +1 -0
- package/dist/zkProgrammable/provableMethod.d.ts +19 -0
- package/dist/zkProgrammable/provableMethod.d.ts.map +1 -0
- package/dist/zkProgrammable/provableMethod.js +71 -0
- package/dist/zkProgrammable/provableMethod.js.map +1 -0
- package/jest.config.cjs +12 -0
- package/package.json +34 -0
- package/src/compiling/AtomicCompileHelper.ts +62 -0
- package/src/compiling/CompilableModule.ts +6 -0
- package/src/compiling/CompileRegistry.ts +78 -0
- package/src/compiling/services/ChildVerificationKeyService.ts +26 -0
- package/src/config/ChildContainerCreatable.ts +5 -0
- package/src/config/ChildContainerProvider.ts +5 -0
- package/src/config/ConfigurableModule.ts +57 -0
- package/src/config/ModuleContainer.ts +487 -0
- package/src/config/injectAlias.ts +70 -0
- package/src/dependencyFactory/DependencyFactory.ts +57 -0
- package/src/dependencyFactory/injectOptional.ts +41 -0
- package/src/dummyVerificationKey.ts +10 -0
- package/src/events/EventEmitter.ts +61 -0
- package/src/events/EventEmitterProxy.ts +83 -0
- package/src/events/EventEmittingComponent.ts +11 -0
- package/src/events/ReplayingSingleUseEventEmitter.ts +42 -0
- package/src/index.ts +25 -0
- package/src/log.ts +143 -0
- package/src/trees/InMemoryMerkleTreeStorage.ts +17 -0
- package/src/trees/MerkleTreeStore.ts +5 -0
- package/src/trees/MockAsyncMerkleStore.ts +30 -0
- package/src/trees/RollupMerkleTree.ts +356 -0
- package/src/trees/VirtualMerkleTreeStore.ts +20 -0
- package/src/types.ts +58 -0
- package/src/utils.ts +200 -0
- package/src/zkProgrammable/ProvableMethodExecutionContext.ts +122 -0
- package/src/zkProgrammable/ZkProgrammable.ts +151 -0
- package/src/zkProgrammable/provableMethod.ts +124 -0
- package/test/config/ContainerEvents.test.ts +67 -0
- package/test/config/ModuleContainer.test.ts +215 -0
- package/test/config/injectAlias.test.ts +28 -0
- package/test/trees/MerkleTree.test.ts +106 -0
- package/test/tsconfig.json +7 -0
- package/test/zkProgrammable/ZkProgrammable.test.ts +304 -0
- package/tsconfig.json +8 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { beforeEach } from "@jest/globals";
|
|
2
|
+
import { Field } from "o1js";
|
|
3
|
+
|
|
4
|
+
import { createMerkleTree, InMemoryMerkleTreeStorage, log } from "../../src";
|
|
5
|
+
|
|
6
|
+
describe.each([4, 16, 256])("cachedMerkleTree - %s", (height) => {
|
|
7
|
+
class RollupMerkleTree extends createMerkleTree(height) {}
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
9
|
+
class RollupMerkleTreeWitness extends RollupMerkleTree.WITNESS {}
|
|
10
|
+
|
|
11
|
+
let store: InMemoryMerkleTreeStorage;
|
|
12
|
+
let tree: RollupMerkleTree;
|
|
13
|
+
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
log.setLevel("INFO");
|
|
16
|
+
|
|
17
|
+
store = new InMemoryMerkleTreeStorage();
|
|
18
|
+
tree = new RollupMerkleTree(store);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("should have the same root when empty", () => {
|
|
22
|
+
expect.assertions(1);
|
|
23
|
+
|
|
24
|
+
expect(tree.getRoot().toBigInt()).toStrictEqual(
|
|
25
|
+
RollupMerkleTree.EMPTY_ROOT
|
|
26
|
+
);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("should have a different root when not empty", () => {
|
|
30
|
+
expect.assertions(1);
|
|
31
|
+
|
|
32
|
+
tree.setLeaf(1n, Field(1));
|
|
33
|
+
|
|
34
|
+
expect(tree.getRoot().toBigInt()).not.toStrictEqual(
|
|
35
|
+
RollupMerkleTree.EMPTY_ROOT
|
|
36
|
+
);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("should have the same root after adding and removing item", () => {
|
|
40
|
+
expect.assertions(1);
|
|
41
|
+
|
|
42
|
+
tree.setLeaf(1n, Field(1));
|
|
43
|
+
|
|
44
|
+
const root = tree.getRoot();
|
|
45
|
+
|
|
46
|
+
tree.setLeaf(5n, Field(5));
|
|
47
|
+
tree.setLeaf(5n, Field(0));
|
|
48
|
+
|
|
49
|
+
expect(tree.getRoot().toBigInt()).toStrictEqual(root.toBigInt());
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("should provide correct witnesses", () => {
|
|
53
|
+
expect.assertions(1);
|
|
54
|
+
|
|
55
|
+
tree.setLeaf(1n, Field(1));
|
|
56
|
+
tree.setLeaf(5n, Field(5));
|
|
57
|
+
|
|
58
|
+
const witness = tree.getWitness(5n);
|
|
59
|
+
|
|
60
|
+
expect(witness.calculateRoot(Field(5)).toBigInt()).toStrictEqual(
|
|
61
|
+
tree.getRoot().toBigInt()
|
|
62
|
+
);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("should have invalid witnesses with wrong values", () => {
|
|
66
|
+
expect.assertions(1);
|
|
67
|
+
|
|
68
|
+
tree.setLeaf(1n, Field(1));
|
|
69
|
+
tree.setLeaf(5n, Field(5));
|
|
70
|
+
|
|
71
|
+
const witness = tree.getWitness(5n);
|
|
72
|
+
|
|
73
|
+
expect(witness.calculateRoot(Field(6)).toBigInt()).not.toStrictEqual(
|
|
74
|
+
tree.getRoot().toBigInt()
|
|
75
|
+
);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("should have valid witnesses with changed value on the same leafs", () => {
|
|
79
|
+
expect.assertions(1);
|
|
80
|
+
|
|
81
|
+
tree.setLeaf(1n, Field(1));
|
|
82
|
+
tree.setLeaf(5n, Field(5));
|
|
83
|
+
|
|
84
|
+
const witness = tree.getWitness(5n);
|
|
85
|
+
|
|
86
|
+
tree.setLeaf(5n, Field(10));
|
|
87
|
+
|
|
88
|
+
expect(witness.calculateRoot(Field(10)).toBigInt()).toStrictEqual(
|
|
89
|
+
tree.getRoot().toBigInt()
|
|
90
|
+
);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("should throw for invalid index", () => {
|
|
94
|
+
expect.assertions(2);
|
|
95
|
+
|
|
96
|
+
const index = 2n ** BigInt(height) + 1n;
|
|
97
|
+
|
|
98
|
+
expect(() => {
|
|
99
|
+
tree.setLeaf(index, Field(1));
|
|
100
|
+
}).toThrow("Index greater than maximum leaf number");
|
|
101
|
+
|
|
102
|
+
expect(() => {
|
|
103
|
+
tree.getNode(0, index);
|
|
104
|
+
}).toThrow("Index greater than maximum leaf number");
|
|
105
|
+
});
|
|
106
|
+
});
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
import "reflect-metadata";
|
|
2
|
+
import { jest } from "@jest/globals";
|
|
3
|
+
import { container } from "tsyringe";
|
|
4
|
+
import { Field, Struct, Proof, ZkProgram } from "o1js";
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
MOCK_PROOF,
|
|
8
|
+
provableMethod,
|
|
9
|
+
AreProofsEnabled,
|
|
10
|
+
CompileArtifact,
|
|
11
|
+
MOCK_VERIFICATION_KEY,
|
|
12
|
+
ZkProgrammable,
|
|
13
|
+
ProvableMethodExecutionContext,
|
|
14
|
+
} from "../../src";
|
|
15
|
+
|
|
16
|
+
const appChainMock: AreProofsEnabled = {
|
|
17
|
+
areProofsEnabled: false,
|
|
18
|
+
|
|
19
|
+
setProofsEnabled(areProofsEnabled: boolean) {
|
|
20
|
+
this.areProofsEnabled = areProofsEnabled;
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
class TestPublicInput extends Struct({
|
|
25
|
+
foo: Field,
|
|
26
|
+
}) {}
|
|
27
|
+
|
|
28
|
+
class TestPublicOutput extends Struct({
|
|
29
|
+
bar: Field,
|
|
30
|
+
}) {}
|
|
31
|
+
|
|
32
|
+
const failErrorMessage = "test failure";
|
|
33
|
+
|
|
34
|
+
type Balance = Field;
|
|
35
|
+
|
|
36
|
+
class TestProgrammable extends ZkProgrammable<
|
|
37
|
+
TestPublicInput,
|
|
38
|
+
TestPublicOutput
|
|
39
|
+
> {
|
|
40
|
+
public areProofsEnabled: AreProofsEnabled = appChainMock;
|
|
41
|
+
|
|
42
|
+
@provableMethod()
|
|
43
|
+
public async foo(publicInput: TestPublicInput, bar: Balance) {
|
|
44
|
+
// expose the private input as public output again for testing purposes
|
|
45
|
+
return new TestPublicOutput({
|
|
46
|
+
bar,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
@provableMethod()
|
|
51
|
+
public async fail(publicInput: TestPublicInput) {
|
|
52
|
+
publicInput.foo.assertEquals(1, failErrorMessage);
|
|
53
|
+
|
|
54
|
+
return new TestPublicOutput({
|
|
55
|
+
bar: Field(0),
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
public zkProgramFactory() {
|
|
60
|
+
const program = ZkProgram({
|
|
61
|
+
name: "testprogram",
|
|
62
|
+
publicInput: TestPublicInput,
|
|
63
|
+
publicOutput: TestPublicOutput,
|
|
64
|
+
|
|
65
|
+
methods: {
|
|
66
|
+
foo: {
|
|
67
|
+
privateInputs: [Field],
|
|
68
|
+
method: this.foo.bind(this),
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
fail: {
|
|
72
|
+
privateInputs: [],
|
|
73
|
+
method: this.fail.bind(this),
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
const SelfProof = ZkProgram.Proof(program);
|
|
79
|
+
|
|
80
|
+
const methods = {
|
|
81
|
+
foo: program.foo.bind(program),
|
|
82
|
+
fail: program.fail.bind(program),
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
return [
|
|
86
|
+
{
|
|
87
|
+
name: program.name,
|
|
88
|
+
compile: program.compile.bind(program),
|
|
89
|
+
verify: program.verify.bind(program),
|
|
90
|
+
analyzeMethods: program.analyzeMethods.bind(program),
|
|
91
|
+
Proof: SelfProof,
|
|
92
|
+
methods,
|
|
93
|
+
},
|
|
94
|
+
];
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
class OtherTestProgrammable extends ZkProgrammable<undefined, void> {
|
|
99
|
+
public areProofsEnabled: AreProofsEnabled = appChainMock;
|
|
100
|
+
|
|
101
|
+
public constructor(public testProgrammable: TestProgrammable) {
|
|
102
|
+
super();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
proofType = this.testProgrammable.zkProgram[0].Proof;
|
|
106
|
+
|
|
107
|
+
@provableMethod()
|
|
108
|
+
public async bar(testProgrammableProof: InstanceType<typeof this.proofType>) {
|
|
109
|
+
testProgrammableProof.verify();
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
public zkProgramFactory() {
|
|
113
|
+
const program = ZkProgram({
|
|
114
|
+
name: "testprogram2",
|
|
115
|
+
methods: {
|
|
116
|
+
bar: {
|
|
117
|
+
privateInputs: [this.testProgrammable.zkProgram[0].Proof],
|
|
118
|
+
method: this.bar.bind(this),
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
const methods = {
|
|
124
|
+
bar: program.bar.bind(program),
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const SelfProof = ZkProgram.Proof(program);
|
|
128
|
+
|
|
129
|
+
return [
|
|
130
|
+
{
|
|
131
|
+
name: program.name,
|
|
132
|
+
compile: program.compile.bind(program),
|
|
133
|
+
verify: program.verify.bind(program),
|
|
134
|
+
analyzeMethods: program.analyzeMethods.bind(program),
|
|
135
|
+
Proof: SelfProof,
|
|
136
|
+
methods,
|
|
137
|
+
},
|
|
138
|
+
];
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const testWithProofs = false;
|
|
143
|
+
|
|
144
|
+
describe("zkProgrammable", () => {
|
|
145
|
+
let testProgrammable: TestProgrammable;
|
|
146
|
+
let artifact: CompileArtifact;
|
|
147
|
+
let zkProgramFactorySpy: ReturnType<typeof jest.spyOn>;
|
|
148
|
+
|
|
149
|
+
const testCases: [
|
|
150
|
+
boolean,
|
|
151
|
+
{
|
|
152
|
+
verificationKey: CompileArtifact["verificationKey"];
|
|
153
|
+
shouldVerifyMockProofs: boolean;
|
|
154
|
+
},
|
|
155
|
+
][] = [
|
|
156
|
+
[
|
|
157
|
+
false,
|
|
158
|
+
{
|
|
159
|
+
verificationKey: MOCK_VERIFICATION_KEY,
|
|
160
|
+
shouldVerifyMockProofs: true,
|
|
161
|
+
},
|
|
162
|
+
],
|
|
163
|
+
];
|
|
164
|
+
|
|
165
|
+
// We want to disable testing with proofs enabled for the CI and other stuff,
|
|
166
|
+
// as it is quite expensive. But we should find a better pattern than this
|
|
167
|
+
if (testWithProofs) {
|
|
168
|
+
// TODO Migrate to new o1js compile artifact format
|
|
169
|
+
// testCases.push([
|
|
170
|
+
// true,
|
|
171
|
+
// {
|
|
172
|
+
// verificationKey:
|
|
173
|
+
// eslint-disable-next-line max-len
|
|
174
|
+
// "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",
|
|
175
|
+
//
|
|
176
|
+
// shouldVerifyMockProofs: false,
|
|
177
|
+
// },
|
|
178
|
+
// ]);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
describe.each(testCases)(
|
|
182
|
+
"areProofsEnabled",
|
|
183
|
+
(areProofsEnabled, { verificationKey, shouldVerifyMockProofs }) => {
|
|
184
|
+
beforeAll(async () => {
|
|
185
|
+
testProgrammable = new TestProgrammable();
|
|
186
|
+
testProgrammable.areProofsEnabled.setProofsEnabled(areProofsEnabled);
|
|
187
|
+
zkProgramFactorySpy = jest.spyOn(testProgrammable, "zkProgramFactory");
|
|
188
|
+
artifact = await testProgrammable.zkProgram[0].compile();
|
|
189
|
+
}, 500_000);
|
|
190
|
+
|
|
191
|
+
describe("zkProgramFactory", () => {
|
|
192
|
+
it("should create and cache a ZkProgram", () => {
|
|
193
|
+
expect.assertions(1);
|
|
194
|
+
|
|
195
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
196
|
+
const programs = {
|
|
197
|
+
1: testProgrammable.zkProgram,
|
|
198
|
+
2: testProgrammable.zkProgram,
|
|
199
|
+
3: testProgrammable.zkProgram,
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
expect(zkProgramFactorySpy).toHaveBeenCalledTimes(1);
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it("compile should return the correct verification key", () => {
|
|
207
|
+
expect.assertions(1);
|
|
208
|
+
|
|
209
|
+
expect(artifact.verificationKey).toBe(verificationKey);
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it("if proofs are disabled, it should successfully verify mock proofs", async () => {
|
|
213
|
+
expect.assertions(1);
|
|
214
|
+
|
|
215
|
+
const proof = new testProgrammable.zkProgram[0].Proof({
|
|
216
|
+
proof: MOCK_PROOF,
|
|
217
|
+
|
|
218
|
+
publicInput: new TestPublicInput({
|
|
219
|
+
foo: Field(0),
|
|
220
|
+
}),
|
|
221
|
+
|
|
222
|
+
publicOutput: new TestPublicOutput({
|
|
223
|
+
bar: Field(0),
|
|
224
|
+
}),
|
|
225
|
+
|
|
226
|
+
maxProofsVerified: 0,
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
const verified = await testProgrammable.zkProgram[0].verify(proof);
|
|
230
|
+
|
|
231
|
+
expect(verified).toBe(shouldVerifyMockProofs);
|
|
232
|
+
|
|
233
|
+
// Check if toJSON works on mockproofs
|
|
234
|
+
// const json = proof.toJSON();
|
|
235
|
+
// expect(json).toBeDefined();
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
describe("provableMethod", () => {
|
|
239
|
+
const executionContext =
|
|
240
|
+
container.resolve<ProvableMethodExecutionContext>(
|
|
241
|
+
ProvableMethodExecutionContext
|
|
242
|
+
);
|
|
243
|
+
|
|
244
|
+
let otherTestProgrammable: OtherTestProgrammable;
|
|
245
|
+
|
|
246
|
+
const testPublicInput = new TestPublicInput({
|
|
247
|
+
foo: Field(0),
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
describe("zkProgram interoperability", () => {
|
|
251
|
+
beforeAll(async () => {
|
|
252
|
+
otherTestProgrammable = new OtherTestProgrammable(testProgrammable);
|
|
253
|
+
await otherTestProgrammable.zkProgram[0].compile();
|
|
254
|
+
}, 500_000);
|
|
255
|
+
|
|
256
|
+
it("should successfully pass proof of one zkProgram as input to another zkProgram", async () => {
|
|
257
|
+
expect.assertions(3);
|
|
258
|
+
|
|
259
|
+
// execute foo
|
|
260
|
+
await testProgrammable.foo(testPublicInput, Field(0));
|
|
261
|
+
|
|
262
|
+
// prove foo
|
|
263
|
+
const testProof = await executionContext
|
|
264
|
+
.current()
|
|
265
|
+
.result.prove<Proof<TestPublicInput, TestPublicOutput>>();
|
|
266
|
+
const testProofVerified =
|
|
267
|
+
await testProgrammable.zkProgram[0].verify(testProof);
|
|
268
|
+
|
|
269
|
+
// execute bar
|
|
270
|
+
await otherTestProgrammable.bar(testProof);
|
|
271
|
+
|
|
272
|
+
// proof bar
|
|
273
|
+
const otherTestProof = await executionContext
|
|
274
|
+
.current()
|
|
275
|
+
.result.prove<Proof<undefined, void>>();
|
|
276
|
+
const otherTestProofVerified =
|
|
277
|
+
await otherTestProgrammable.zkProgram[0].verify(otherTestProof);
|
|
278
|
+
|
|
279
|
+
expect(testProof.publicOutput.bar.toString()).toBe(
|
|
280
|
+
testPublicInput.foo.toString()
|
|
281
|
+
);
|
|
282
|
+
|
|
283
|
+
expect(testProofVerified).toBe(true);
|
|
284
|
+
expect(otherTestProofVerified).toBe(true);
|
|
285
|
+
}, 500_000);
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
describe("failed method execution", () => {
|
|
289
|
+
it("if the method fails, it should fail to execute and prove", async () => {
|
|
290
|
+
expect.assertions(2);
|
|
291
|
+
|
|
292
|
+
await expect(
|
|
293
|
+
testProgrammable.fail(testPublicInput)
|
|
294
|
+
).rejects.toThrow(failErrorMessage);
|
|
295
|
+
|
|
296
|
+
await expect(async () => {
|
|
297
|
+
await executionContext.current().result.prove();
|
|
298
|
+
}).rejects.toThrow(failErrorMessage);
|
|
299
|
+
});
|
|
300
|
+
});
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
);
|
|
304
|
+
});
|