Skip to content

Commit f6cd8c2

Browse files
committed
Merge branch 'develop' into fix/atomic-block-production
# Conflicts: # packages/sequencer/test/integration/BlockProduction.test.ts # packages/sequencer/test/settlement/Settlement.ts
2 parents 13c3b69 + 676d651 commit f6cd8c2

File tree

129 files changed

+6884
-19911
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

129 files changed

+6884
-19911
lines changed

.github/workflows/pull-request-develop.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ jobs:
9191

9292
- name: "Test"
9393
run: npm run test:ci
94+
env:
95+
IN_CI: true
9496

9597
integration:
9698
runs-on: ubuntu-latest

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v18.14.2
1+
v22.9.0

package-lock.json

Lines changed: 1822 additions & 18419 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/api/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"@proto-kit/module": "*",
3535
"@proto-kit/protocol": "*",
3636
"@proto-kit/sequencer": "*",
37-
"o1js": "^1.1.0",
37+
"o1js": "^1.6.0",
3838
"tsyringe": "^4.7.0"
3939
},
4040
"devDependencies": {

packages/api/src/graphql/modules/BatchStorageResolver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class ComputedBlockModel {
2121
blockHashes.map(
2222
(blockHash) => blocks.find((block) => block?.hash === blockHash)!
2323
),
24-
proof.proof === MOCK_PROOF ? "mock-proof" : JSON.stringify(proof)
24+
proof.proof === MOCK_PROOF ? MOCK_PROOF : JSON.stringify(proof)
2525
);
2626
}
2727

packages/common/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"typescript-memoize": "^1.1.1"
2424
},
2525
"peerDependencies": {
26-
"o1js": "^1.1.0",
26+
"o1js": "^1.6.0",
2727
"tsyringe": "^4.7.0"
2828
},
2929
"devDependencies": {
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import {
2+
AreProofsEnabled,
3+
CompileArtifact,
4+
MOCK_VERIFICATION_KEY,
5+
} from "../zkProgrammable/ZkProgrammable";
6+
import { isSubtypeOfName } from "../utils";
7+
import { TypedClass } from "../types";
8+
import { log } from "../log";
9+
10+
export type ArtifactRecord = Record<string, CompileArtifact>;
11+
12+
export type CompileTarget = {
13+
name: string;
14+
compile: () => Promise<CompileArtifact>;
15+
};
16+
17+
export class AtomicCompileHelper {
18+
public constructor(private readonly areProofsEnabled: AreProofsEnabled) {}
19+
20+
private compilationPromises: {
21+
[key: string]: Promise<CompileArtifact>;
22+
} = {};
23+
24+
public async compileContract(
25+
contract: CompileTarget,
26+
overrideProofsEnabled?: boolean
27+
): Promise<CompileArtifact> {
28+
let newPromise = false;
29+
const { name } = contract;
30+
if (this.compilationPromises[name] === undefined) {
31+
const proofsEnabled =
32+
overrideProofsEnabled ?? this.areProofsEnabled.areProofsEnabled;
33+
34+
// We only care about proofs enabled here if it's a contract, because
35+
// in all other cases, ZkProgrammable already handles this switch, and we
36+
// want to preserve the artifact layout (which might be more than one
37+
// entry for ZkProgrammables)
38+
if (
39+
proofsEnabled ||
40+
!isSubtypeOfName(
41+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
42+
contract as unknown as TypedClass<any>,
43+
"SmartContract"
44+
)
45+
) {
46+
log.time(`Compiling ${name}`);
47+
this.compilationPromises[name] = contract.compile();
48+
newPromise = true;
49+
} else {
50+
log.trace(`Compiling ${name} - mock`);
51+
this.compilationPromises[name] = Promise.resolve({
52+
verificationKey: MOCK_VERIFICATION_KEY,
53+
});
54+
}
55+
}
56+
const result = await this.compilationPromises[name];
57+
if (newPromise) {
58+
log.timeEnd.info(`Compiling ${name}`);
59+
}
60+
return result;
61+
}
62+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import type { CompileRegistry } from "./CompileRegistry";
2+
import type { ArtifactRecord } from "./AtomicCompileHelper";
3+
4+
export interface CompilableModule {
5+
compile(registry: CompileRegistry): Promise<ArtifactRecord | void>;
6+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import { inject, injectable, singleton } from "tsyringe";
2+
3+
import {
4+
AreProofsEnabled,
5+
CompileArtifact,
6+
} from "../zkProgrammable/ZkProgrammable";
7+
8+
import {
9+
ArtifactRecord,
10+
AtomicCompileHelper,
11+
CompileTarget,
12+
} from "./AtomicCompileHelper";
13+
14+
/**
15+
* The CompileRegistry compiles "compilable modules"
16+
* (i.e. zkprograms, contracts or contractmodules)
17+
* while making sure they don't get compiled twice in the same process in parallel.
18+
*/
19+
@injectable()
20+
@singleton()
21+
export class CompileRegistry {
22+
public constructor(
23+
@inject("AreProofsEnabled")
24+
private readonly areProofsEnabled: AreProofsEnabled
25+
) {
26+
this.compiler = new AtomicCompileHelper(this.areProofsEnabled);
27+
}
28+
29+
private compiler: AtomicCompileHelper;
30+
31+
private artifacts: ArtifactRecord = {};
32+
33+
private inForceProverBlock = false;
34+
35+
/**
36+
* This function forces compilation even if the artifact itself is in the registry.
37+
* Basically the statement is: The artifact along is not enough, we need to
38+
* actually have the prover compiled.
39+
* This is true for non-sideloaded circuit dependencies.
40+
*/
41+
public async forceProverExists(
42+
f: (registry: CompileRegistry) => Promise<void>
43+
) {
44+
this.inForceProverBlock = true;
45+
await f(this);
46+
this.inForceProverBlock = false;
47+
}
48+
49+
public async compile(target: CompileTarget) {
50+
if (this.artifacts[target.name] === undefined || this.inForceProverBlock) {
51+
const artifact = await this.compiler.compileContract(target);
52+
this.artifacts[target.name] = artifact;
53+
return artifact;
54+
}
55+
return this.artifacts[target.name];
56+
}
57+
58+
public getArtifact(name: string): CompileArtifact | undefined {
59+
if (this.artifacts[name] === undefined) {
60+
throw new Error(
61+
`Artifact for ${name} not available, did you compile it via the CompileRegistry?`
62+
);
63+
}
64+
65+
return this.artifacts[name];
66+
}
67+
68+
public addArtifactsRaw(artifacts: ArtifactRecord) {
69+
this.artifacts = {
70+
...this.artifacts,
71+
...artifacts,
72+
};
73+
}
74+
75+
public getAllArtifacts() {
76+
return this.artifacts;
77+
}
78+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { injectable, Lifecycle, scoped } from "tsyringe";
2+
3+
import { CompileRegistry } from "../CompileRegistry";
4+
5+
@injectable()
6+
@scoped(Lifecycle.ContainerScoped)
7+
export class ChildVerificationKeyService {
8+
private compileRegistry?: CompileRegistry;
9+
10+
public setCompileRegistry(registry: CompileRegistry) {
11+
this.compileRegistry = registry;
12+
}
13+
14+
public getVerificationKey(name: string) {
15+
if (this.compileRegistry === undefined) {
16+
throw new Error("CompileRegistry hasn't been set yet");
17+
}
18+
const artifact = this.compileRegistry.getArtifact(name);
19+
if (artifact === undefined) {
20+
throw new Error(
21+
`Verification Key for child program ${name} not found in registry`
22+
);
23+
}
24+
return artifact.verificationKey;
25+
}
26+
}

0 commit comments

Comments
 (0)