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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

### Added

- Added CircuitAnalysisModule for easy analysis of protocol circuits [#379](https://github.com/proto-kit/framework/pull/379)
- Separated settlement and bridging functionally, so now settlement can be used without bridging [#376](https://github.com/proto-kit/framework/pull/376)
- Added nightly releases via pkg.pr.new [#384](https://github.com/proto-kit/framework/pull/384)
- Introduced Changelog [#378](https://github.com/proto-kit/framework/pull/378)
2 changes: 2 additions & 0 deletions packages/common/src/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ function logProvable(
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
if (process.env?.IN_CI ?? false) {
loglevel.setLevel("ERROR");
} else {
loglevel.setLevel("INFO");
}

const timeMap: Record<string, number> = {};
Expand Down
75 changes: 75 additions & 0 deletions packages/sequencer/src/helpers/CircuitAnalysisModule.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { inject, injectable } from "tsyringe";
import { RuntimeEnvironment } from "@proto-kit/module";
import { log, mapSequential, PlainZkProgram } from "@proto-kit/common";
import {
MandatoryProtocolModulesRecord,
Protocol,
ProtocolModulesRecord,
SettlementContractModule,
SettlementModulesRecord,
} from "@proto-kit/protocol";

@injectable()
export class CircuitAnalysisModule {
public constructor(
@inject("Protocol")
private readonly protocol: Protocol<
ProtocolModulesRecord & MandatoryProtocolModulesRecord
>,
@inject("Runtime")
private readonly runtime: RuntimeEnvironment
) {}

public async printSummary() {
const summary = await this.analyseMethods();
log.info(summary);
}

public async analyseMethods() {
const zkProgrammables = [
this.runtime,
this.protocol.stateTransitionProver,
this.protocol.transactionProver,
this.protocol.blockProver,
];

const zkProgrammablePromises = await mapSequential(
zkProgrammables,
(withZkProgrammable) =>
mapSequential(
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
withZkProgrammable.zkProgrammable.zkProgramFactory() as PlainZkProgram<
unknown,
unknown
>[],
async (program) => {
const result = await program.analyzeMethods();
return [program.name, result] as const;
}
)
);

const settlementModule = this.protocol.dependencyContainer.resolve<
SettlementContractModule<SettlementModulesRecord>
>("SettlementContractModule");

const contractPromises = await mapSequential(
Object.entries(settlementModule.getContractClasses()),
async ([key, clas]) => {
const result = await clas.analyzeMethods();
return [key, result] as const;
}
);

const allResults = [...zkProgrammablePromises.flat(), ...contractPromises];

const summary = allResults.map(([program, result]) => {
const methods = Object.entries(result).map(
([methodName, constraints]) => [methodName, constraints.rows] as const
);
return [program, Object.fromEntries(methods)] as const;
});

return Object.fromEntries(summary);
}
}
1 change: 1 addition & 0 deletions packages/sequencer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export * from "./helpers/query/NetworkStateQuery";
export * from "./helpers/query/NetworkStateTransportModule";
export * from "./helpers/query/BlockExplorerQuery";
export * from "./helpers/query/BlockExplorerTransportModule";
export * from "./helpers/CircuitAnalysisModule";
export * from "./state/prefilled/PreFilledStateService";
export * from "./state/async/AsyncMerkleTreeStore";
export * from "./state/async/AsyncStateService";
Expand Down
7 changes: 7 additions & 0 deletions packages/sequencer/test/settlement/Settlement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import {
VanillaTaskWorkerModules,
Sequencer,
InMemoryMinaSigner,
CircuitAnalysisModule,
} from "../../src";
import { BlockProofSerializer } from "../../src/protocol/production/tasks/serializers/BlockProofSerializer";
import { testingSequencerModules } from "../TestingSequencer";
Expand Down Expand Up @@ -313,6 +314,12 @@ export const settlementTestFn = (
let user0Nonce = 0;
let acc0L2Nonce = 0;

it.skip("Print constraint summary", async () => {
await appChain.protocol.dependencyContainer
.resolve(CircuitAnalysisModule)
.printSummary();
});

it("should throw error", async () => {
const additionalAddresses =
tokenConfig === undefined
Expand Down
Loading