-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathStateTransitionTask.ts
More file actions
84 lines (73 loc) · 2.5 KB
/
StateTransitionTask.ts
File metadata and controls
84 lines (73 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import { inject, injectable, Lifecycle, scoped } from "tsyringe";
import {
AppliedStateTransitionBatchState,
MandatoryProtocolModulesRecord,
MerkleWitnessBatch,
Protocol,
ProtocolModulesRecord,
StateTransitionProof,
StateTransitionProvable,
StateTransitionProvableBatch,
StateTransitionProverPublicInput,
} from "@proto-kit/protocol";
import {
ProvableMethodExecutionContext,
CompileRegistry,
LinkedMerkleTreeWitness,
implement,
} from "@proto-kit/common";
import { Task, TaskSerializer } from "../../../worker/flow/Task";
import { ProofTaskSerializer } from "../../../helpers/utils";
import { TaskWorkerModule } from "../../../worker/worker/TaskWorkerModule";
import { StateTransitionParametersSerializer } from "./serializers/StateTransitionParametersSerializer";
export interface StateTransitionProofParameters {
publicInput: StateTransitionProverPublicInput;
batch: StateTransitionProvableBatch;
batchState: AppliedStateTransitionBatchState;
merkleWitnesses: LinkedMerkleTreeWitness[];
}
@injectable()
@scoped(Lifecycle.ContainerScoped)
@implement("Task")
export class StateTransitionTask
extends TaskWorkerModule
implements Task<StateTransitionProofParameters, StateTransitionProof>
{
protected readonly stateTransitionProver: StateTransitionProvable;
public name = "stateTransitionProof";
public constructor(
@inject("Protocol")
private readonly protocol: Protocol<
MandatoryProtocolModulesRecord & ProtocolModulesRecord
>,
private readonly executionContext: ProvableMethodExecutionContext,
private readonly compileRegistry: CompileRegistry
) {
super();
this.stateTransitionProver = this.protocol.stateTransitionProver;
}
public inputSerializer(): TaskSerializer<StateTransitionProofParameters> {
return new StateTransitionParametersSerializer();
}
public resultSerializer(): TaskSerializer<StateTransitionProof> {
return new ProofTaskSerializer(
this.stateTransitionProver.zkProgrammable.zkProgram[0].Proof
);
}
public async compute(
input: StateTransitionProofParameters
): Promise<StateTransitionProof> {
await this.stateTransitionProver.proveBatch(
input.publicInput,
input.batch,
new MerkleWitnessBatch({ witnesses: input.merkleWitnesses.slice() }),
input.batchState
);
return await this.executionContext
.current()
.result.prove<StateTransitionProof>();
}
public async prepare(): Promise<void> {
await this.stateTransitionProver.compile(this.compileRegistry);
}
}