1
1
/* eslint-disable @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-argument */
2
2
import { ZkProgram } from "o1js" ;
3
- import { DependencyContainer , injectable } from "tsyringe" ;
3
+ import { container , DependencyContainer , injectable } from "tsyringe" ;
4
4
import {
5
5
StringKeyOf ,
6
6
ModuleContainer ,
@@ -11,11 +11,16 @@ import {
11
11
PlainZkProgram ,
12
12
AreProofsEnabled ,
13
13
ChildContainerProvider ,
14
+ CompilableModule ,
15
+ CompileRegistry ,
14
16
} from "@proto-kit/common" ;
15
17
import {
16
18
MethodPublicOutput ,
17
19
StateServiceProvider ,
18
20
SimpleAsyncStateService ,
21
+ RuntimeMethodExecutionContext ,
22
+ RuntimeTransaction ,
23
+ NetworkState ,
19
24
} from "@proto-kit/protocol" ;
20
25
21
26
import {
@@ -227,9 +232,10 @@ export class RuntimeZkProgrammable<
227
232
return buckets ;
228
233
} ;
229
234
230
- return splitRuntimeMethods ( ) . map ( ( bucket ) => {
235
+ return splitRuntimeMethods ( ) . map ( ( bucket , index ) => {
236
+ const name = `RuntimeProgram-${ index } ` ;
231
237
const program = ZkProgram ( {
232
- name : "RuntimeProgram" ,
238
+ name,
233
239
publicOutput : MethodPublicOutput ,
234
240
methods : bucket ,
235
241
} ) ;
@@ -245,6 +251,7 @@ export class RuntimeZkProgrammable<
245
251
) ;
246
252
247
253
return {
254
+ name,
248
255
compile : program . compile . bind ( program ) ,
249
256
verify : program . verify . bind ( program ) ,
250
257
analyzeMethods : program . analyzeMethods . bind ( program ) ,
@@ -262,7 +269,7 @@ export class RuntimeZkProgrammable<
262
269
@injectable ( )
263
270
export class Runtime < Modules extends RuntimeModulesRecord >
264
271
extends ModuleContainer < Modules >
265
- implements RuntimeEnvironment
272
+ implements RuntimeEnvironment , CompilableModule
266
273
{
267
274
public static from < Modules extends RuntimeModulesRecord > (
268
275
definition : RuntimeDefinition < Modules >
@@ -375,5 +382,14 @@ export class Runtime<Modules extends RuntimeModulesRecord>
375
382
public get runtimeModuleNames ( ) {
376
383
return Object . keys ( this . definition . modules ) ;
377
384
}
385
+
386
+ public async compile ( registry : CompileRegistry ) {
387
+ const context = container . resolve ( RuntimeMethodExecutionContext ) ;
388
+ context . setup ( {
389
+ transaction : RuntimeTransaction . dummyTransaction ( ) ,
390
+ networkState : NetworkState . empty ( ) ,
391
+ } ) ;
392
+ return await this . zkProgrammable . compile ( registry ) ;
393
+ }
378
394
}
379
395
/* eslint-enable @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-argument */
0 commit comments