@aztec/end-to-end 0.87.4-starknet.1 → 0.87.5
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/dest/bench/client_flows/client_flows_benchmark.d.ts +3 -5
- package/dest/bench/client_flows/client_flows_benchmark.d.ts.map +1 -1
- package/dest/bench/client_flows/client_flows_benchmark.js +14 -24
- package/dest/bench/client_flows/data_extractor.d.ts +21 -0
- package/dest/bench/client_flows/data_extractor.d.ts.map +1 -1
- package/dest/bench/client_flows/data_extractor.js +122 -5
- package/dest/bench/utils.d.ts +0 -7
- package/dest/bench/utils.d.ts.map +1 -1
- package/dest/e2e_p2p/shared.js +2 -6
- package/dest/fixtures/utils.d.ts.map +1 -1
- package/dest/fixtures/utils.js +4 -7
- package/dest/shared/capture_private_execution_steps.d.ts +7 -0
- package/dest/shared/capture_private_execution_steps.d.ts.map +1 -0
- package/dest/shared/capture_private_execution_steps.js +49 -0
- package/package.json +34 -34
- package/src/bench/client_flows/client_flows_benchmark.ts +10 -28
- package/src/bench/client_flows/data_extractor.ts +142 -8
- package/src/bench/utils.ts +1 -1
- package/src/e2e_p2p/shared.ts +2 -2
- package/src/fixtures/utils.ts +4 -7
- package/src/shared/capture_private_execution_steps.ts +68 -0
- package/dest/bench/client_flows/benchmark.d.ts +0 -59
- package/dest/bench/client_flows/benchmark.d.ts.map +0 -1
- package/dest/bench/client_flows/benchmark.js +0 -240
- package/src/bench/client_flows/benchmark.ts +0 -308
|
@@ -1,240 +0,0 @@
|
|
|
1
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
2
|
-
import { serializePrivateExecutionSteps } from '@aztec/stdlib/kernel';
|
|
3
|
-
import assert from 'node:assert';
|
|
4
|
-
import { mkdir, writeFile } from 'node:fs/promises';
|
|
5
|
-
import { join } from 'node:path';
|
|
6
|
-
const logger = createLogger('bench:profile_capture');
|
|
7
|
-
const logLevel = [
|
|
8
|
-
'silent',
|
|
9
|
-
'fatal',
|
|
10
|
-
'error',
|
|
11
|
-
'warn',
|
|
12
|
-
'info',
|
|
13
|
-
'verbose',
|
|
14
|
-
'debug',
|
|
15
|
-
'trace'
|
|
16
|
-
];
|
|
17
|
-
const GATE_TYPES = [
|
|
18
|
-
'ecc_op',
|
|
19
|
-
'busread',
|
|
20
|
-
'lookup',
|
|
21
|
-
'pub_inputs',
|
|
22
|
-
'arithmetic',
|
|
23
|
-
'delta_range',
|
|
24
|
-
'elliptic',
|
|
25
|
-
'aux',
|
|
26
|
-
'poseidon2_external',
|
|
27
|
-
'poseidon2_internal',
|
|
28
|
-
'overflow'
|
|
29
|
-
];
|
|
30
|
-
export class ProxyLogger {
|
|
31
|
-
static instance;
|
|
32
|
-
logs = [];
|
|
33
|
-
constructor(){}
|
|
34
|
-
static create() {
|
|
35
|
-
ProxyLogger.instance = new ProxyLogger();
|
|
36
|
-
}
|
|
37
|
-
static getInstance() {
|
|
38
|
-
return ProxyLogger.instance;
|
|
39
|
-
}
|
|
40
|
-
createLogger(prefix) {
|
|
41
|
-
return new Proxy(createLogger(prefix), {
|
|
42
|
-
get: (target, prop)=>{
|
|
43
|
-
if (logLevel.includes(prop)) {
|
|
44
|
-
return function(...data) {
|
|
45
|
-
const loggingFn = prop;
|
|
46
|
-
const args = [
|
|
47
|
-
loggingFn,
|
|
48
|
-
prefix,
|
|
49
|
-
...data
|
|
50
|
-
];
|
|
51
|
-
ProxyLogger.getInstance().handleLog(...args);
|
|
52
|
-
target[loggingFn].call(this, ...[
|
|
53
|
-
data[0],
|
|
54
|
-
data[1]
|
|
55
|
-
]);
|
|
56
|
-
};
|
|
57
|
-
} else {
|
|
58
|
-
return target[prop];
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
handleLog(type, prefix, message, data) {
|
|
64
|
-
this.logs.unshift({
|
|
65
|
-
type,
|
|
66
|
-
prefix,
|
|
67
|
-
message,
|
|
68
|
-
data,
|
|
69
|
-
timestamp: Date.now()
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
flushLogs() {
|
|
73
|
-
this.logs = [];
|
|
74
|
-
}
|
|
75
|
-
getLogs() {
|
|
76
|
-
return this.logs;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
function getMinimumTrace(logs) {
|
|
80
|
-
const minimumMessage = 'Minimum required block sizes for structured trace';
|
|
81
|
-
const minimumMessageIndex = logs.findIndex((log)=>log.message.includes(minimumMessage));
|
|
82
|
-
const candidateLogs = logs.slice(minimumMessageIndex - GATE_TYPES.length, minimumMessageIndex + 5);
|
|
83
|
-
const traceLogs = candidateLogs.filter((log)=>GATE_TYPES.some((type)=>log.message.includes(type))).map((log)=>log.message.split(/\t|\n/)).flat().map((log)=>log.replace(/\(mem: .*\)/, '').trim()).filter(Boolean);
|
|
84
|
-
const traceSizes = traceLogs.map((log)=>{
|
|
85
|
-
const [gateType, gateSizeStr] = log.replace(/\n.*\)$/, '').replace(/bb - /, '').split(':').map((s)=>s.trim());
|
|
86
|
-
const gateSize = parseInt(gateSizeStr);
|
|
87
|
-
assert(GATE_TYPES.includes(gateType), `Gate type ${gateType} is not recognized`);
|
|
88
|
-
return {
|
|
89
|
-
[gateType]: gateSize
|
|
90
|
-
};
|
|
91
|
-
});
|
|
92
|
-
assert(traceSizes.length === GATE_TYPES.length, 'Decoded trace sizes do not match expected amount of gate types');
|
|
93
|
-
return traceSizes.reduce((acc, curr)=>({
|
|
94
|
-
...acc,
|
|
95
|
-
...curr
|
|
96
|
-
}), {});
|
|
97
|
-
}
|
|
98
|
-
function getMaxMemory(logs) {
|
|
99
|
-
const candidateLogs = logs.slice(0, 100).filter((log)=>/\(mem: .*MiB\)/.test(log.message));
|
|
100
|
-
const usage = candidateLogs.map((log)=>{
|
|
101
|
-
const memStr = log ? log.message.slice(log.message.indexOf('(mem: ') + 6, log.message.indexOf('MiB') - 3) : '';
|
|
102
|
-
return memStr ? parseInt(memStr) : 0;
|
|
103
|
-
});
|
|
104
|
-
return Math.max(...usage);
|
|
105
|
-
}
|
|
106
|
-
export function generateBenchmark(flow, logs, timings, privateExecutionSteps, proverType, error) {
|
|
107
|
-
let maxMemory = 0;
|
|
108
|
-
let minimumTrace;
|
|
109
|
-
try {
|
|
110
|
-
minimumTrace = getMinimumTrace(logs);
|
|
111
|
-
maxMemory = getMaxMemory(logs);
|
|
112
|
-
} catch {
|
|
113
|
-
logger.warn(`Failed obtain minimum trace and max memory for ${flow}. Did you run with REAL_PROOFS=1?`);
|
|
114
|
-
}
|
|
115
|
-
const steps = privateExecutionSteps.reduce((acc, step, i)=>{
|
|
116
|
-
const previousAccGateCount = i === 0 ? 0 : acc[i - 1].accGateCount;
|
|
117
|
-
return [
|
|
118
|
-
...acc,
|
|
119
|
-
{
|
|
120
|
-
functionName: step.functionName,
|
|
121
|
-
gateCount: step.gateCount,
|
|
122
|
-
accGateCount: previousAccGateCount + step.gateCount,
|
|
123
|
-
time: step.timings.witgen,
|
|
124
|
-
oracles: Object.entries(step.timings.oracles ?? {}).reduce((acc, [oracleName, oracleData])=>{
|
|
125
|
-
const total = oracleData.times.reduce((sum, time)=>sum + time, 0);
|
|
126
|
-
const calls = oracleData.times.length;
|
|
127
|
-
acc[oracleName] = {
|
|
128
|
-
calls,
|
|
129
|
-
max: Math.max(...oracleData.times),
|
|
130
|
-
min: Math.min(...oracleData.times),
|
|
131
|
-
total,
|
|
132
|
-
avg: total / calls
|
|
133
|
-
};
|
|
134
|
-
return acc;
|
|
135
|
-
}, {})
|
|
136
|
-
}
|
|
137
|
-
];
|
|
138
|
-
}, []);
|
|
139
|
-
const totalGateCount = steps[steps.length - 1].accGateCount;
|
|
140
|
-
return {
|
|
141
|
-
name: flow,
|
|
142
|
-
timings: {
|
|
143
|
-
total: timings.total,
|
|
144
|
-
sync: timings.sync,
|
|
145
|
-
proving: timings.proving,
|
|
146
|
-
unaccounted: timings.unaccounted,
|
|
147
|
-
witgen: timings.perFunction.reduce((acc, fn)=>acc + fn.time, 0)
|
|
148
|
-
},
|
|
149
|
-
maxMemory,
|
|
150
|
-
proverType,
|
|
151
|
-
minimumTrace: minimumTrace,
|
|
152
|
-
totalGateCount: totalGateCount,
|
|
153
|
-
steps,
|
|
154
|
-
error
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
export function convertProfileToGHBenchmark(benchmark) {
|
|
158
|
-
const benches = [
|
|
159
|
-
{
|
|
160
|
-
name: `${benchmark.name}/witgen`,
|
|
161
|
-
value: benchmark.timings.witgen,
|
|
162
|
-
unit: 'ms'
|
|
163
|
-
},
|
|
164
|
-
{
|
|
165
|
-
name: `${benchmark.name}/total`,
|
|
166
|
-
value: benchmark.timings.total,
|
|
167
|
-
unit: 'ms'
|
|
168
|
-
},
|
|
169
|
-
{
|
|
170
|
-
name: `${benchmark.name}/sync`,
|
|
171
|
-
value: benchmark.timings.sync,
|
|
172
|
-
unit: 'ms'
|
|
173
|
-
},
|
|
174
|
-
{
|
|
175
|
-
name: `${benchmark.name}/unaccounted`,
|
|
176
|
-
value: benchmark.timings.unaccounted,
|
|
177
|
-
unit: 'ms'
|
|
178
|
-
},
|
|
179
|
-
{
|
|
180
|
-
name: `${benchmark.name}/total_gate_count`,
|
|
181
|
-
value: benchmark.totalGateCount,
|
|
182
|
-
unit: 'gates'
|
|
183
|
-
}
|
|
184
|
-
];
|
|
185
|
-
if (benchmark.timings.proving) {
|
|
186
|
-
benches.push({
|
|
187
|
-
name: `${benchmark.name}/proving`,
|
|
188
|
-
value: benchmark.timings.proving,
|
|
189
|
-
unit: 'ms'
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
if (benchmark.maxMemory) {
|
|
193
|
-
benches.push({
|
|
194
|
-
name: `${benchmark.name}/max_memory`,
|
|
195
|
-
value: benchmark.maxMemory,
|
|
196
|
-
unit: 'MiB'
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
return benches;
|
|
200
|
-
}
|
|
201
|
-
export async function captureProfile(label, interaction, opts, expectedSteps) {
|
|
202
|
-
// Make sure the proxy logger starts from a clean slate
|
|
203
|
-
ProxyLogger.getInstance().flushLogs();
|
|
204
|
-
const result = await interaction.profile({
|
|
205
|
-
...opts,
|
|
206
|
-
profileMode: 'full',
|
|
207
|
-
skipProofGeneration: false
|
|
208
|
-
});
|
|
209
|
-
const logs = ProxyLogger.getInstance().getLogs();
|
|
210
|
-
if (expectedSteps !== undefined && result.executionSteps.length !== expectedSteps) {
|
|
211
|
-
throw new Error(`Expected ${expectedSteps} execution steps, got ${result.executionSteps.length}`);
|
|
212
|
-
}
|
|
213
|
-
const benchmark = generateBenchmark(label, logs, result.timings, result.executionSteps, 'wasm', undefined);
|
|
214
|
-
const ivcFolder = process.env.CAPTURE_IVC_FOLDER;
|
|
215
|
-
if (ivcFolder) {
|
|
216
|
-
logger.info(`Capturing client ivc execution profile for ${label}`);
|
|
217
|
-
const resultsDirectory = join(ivcFolder, label);
|
|
218
|
-
logger.info(`Writing private execution steps to ${resultsDirectory}`);
|
|
219
|
-
await mkdir(resultsDirectory, {
|
|
220
|
-
recursive: true
|
|
221
|
-
});
|
|
222
|
-
// Write the client IVC files read by the prover.
|
|
223
|
-
const ivcInputsPath = join(resultsDirectory, 'ivc-inputs.msgpack');
|
|
224
|
-
await writeFile(ivcInputsPath, serializePrivateExecutionSteps(result.executionSteps));
|
|
225
|
-
await writeFile(join(resultsDirectory, 'logs.json'), JSON.stringify(logs, null, 2));
|
|
226
|
-
await writeFile(join(resultsDirectory, 'benchmark.json'), JSON.stringify(benchmark, null, 2));
|
|
227
|
-
logger.info(`Wrote private execution steps to ${resultsDirectory}`);
|
|
228
|
-
}
|
|
229
|
-
const benchOutput = process.env.BENCH_OUTPUT;
|
|
230
|
-
if (benchOutput) {
|
|
231
|
-
await mkdir(benchOutput, {
|
|
232
|
-
recursive: true
|
|
233
|
-
});
|
|
234
|
-
const ghBenchmark = convertProfileToGHBenchmark(benchmark);
|
|
235
|
-
const benchFile = join(benchOutput, `${label}.bench.json`);
|
|
236
|
-
await writeFile(benchFile, JSON.stringify(ghBenchmark));
|
|
237
|
-
logger.info(`Wrote benchmark to ${benchFile}`);
|
|
238
|
-
}
|
|
239
|
-
return result;
|
|
240
|
-
}
|
|
@@ -1,308 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
ContractFunctionInteraction,
|
|
3
|
-
DeployMethod,
|
|
4
|
-
DeployOptions,
|
|
5
|
-
Logger,
|
|
6
|
-
ProfileMethodOptions,
|
|
7
|
-
} from '@aztec/aztec.js';
|
|
8
|
-
import { createLogger } from '@aztec/foundation/log';
|
|
9
|
-
import { type PrivateExecutionStep, serializePrivateExecutionSteps } from '@aztec/stdlib/kernel';
|
|
10
|
-
import type { ProvingTimings, SimulationTimings } from '@aztec/stdlib/tx';
|
|
11
|
-
|
|
12
|
-
import assert from 'node:assert';
|
|
13
|
-
import { mkdir, writeFile } from 'node:fs/promises';
|
|
14
|
-
import { join } from 'node:path';
|
|
15
|
-
|
|
16
|
-
import type { GithubActionBenchmarkResult } from '../utils.js';
|
|
17
|
-
|
|
18
|
-
const logger = createLogger('bench:profile_capture');
|
|
19
|
-
|
|
20
|
-
const logLevel = ['silent', 'fatal', 'error', 'warn', 'info', 'verbose', 'debug', 'trace'] as const;
|
|
21
|
-
type LogLevel = (typeof logLevel)[number];
|
|
22
|
-
|
|
23
|
-
export type Log = {
|
|
24
|
-
type: LogLevel;
|
|
25
|
-
timestamp: number;
|
|
26
|
-
prefix: string;
|
|
27
|
-
message: string;
|
|
28
|
-
data: any;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const GATE_TYPES = [
|
|
32
|
-
'ecc_op',
|
|
33
|
-
'busread',
|
|
34
|
-
'lookup',
|
|
35
|
-
'pub_inputs',
|
|
36
|
-
'arithmetic',
|
|
37
|
-
'delta_range',
|
|
38
|
-
'elliptic',
|
|
39
|
-
'aux',
|
|
40
|
-
'poseidon2_external',
|
|
41
|
-
'poseidon2_internal',
|
|
42
|
-
'overflow',
|
|
43
|
-
] as const;
|
|
44
|
-
|
|
45
|
-
type GateType = (typeof GATE_TYPES)[number];
|
|
46
|
-
|
|
47
|
-
type StructuredTrace = {
|
|
48
|
-
[k in GateType]: number;
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
export class ProxyLogger {
|
|
52
|
-
private static instance: ProxyLogger;
|
|
53
|
-
private logs: Log[] = [];
|
|
54
|
-
|
|
55
|
-
private constructor() {}
|
|
56
|
-
|
|
57
|
-
static create() {
|
|
58
|
-
ProxyLogger.instance = new ProxyLogger();
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
static getInstance() {
|
|
62
|
-
return ProxyLogger.instance;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
createLogger(prefix: string): Logger {
|
|
66
|
-
return new Proxy(createLogger(prefix), {
|
|
67
|
-
get: (target: Logger, prop: keyof Logger) => {
|
|
68
|
-
if (logLevel.includes(prop as (typeof logLevel)[number])) {
|
|
69
|
-
return function (this: Logger, ...data: Parameters<Logger[LogLevel]>) {
|
|
70
|
-
const loggingFn = prop as LogLevel;
|
|
71
|
-
const args = [loggingFn, prefix, ...data] as Parameters<ProxyLogger['handleLog']>;
|
|
72
|
-
ProxyLogger.getInstance().handleLog(...args);
|
|
73
|
-
target[loggingFn].call(this, ...[data[0], data[1]]);
|
|
74
|
-
};
|
|
75
|
-
} else {
|
|
76
|
-
return target[prop];
|
|
77
|
-
}
|
|
78
|
-
},
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
private handleLog(type: (typeof logLevel)[number], prefix: string, message: string, data: any) {
|
|
83
|
-
this.logs.unshift({ type, prefix, message, data, timestamp: Date.now() });
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
public flushLogs() {
|
|
87
|
-
this.logs = [];
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
public getLogs() {
|
|
91
|
-
return this.logs;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export type ProverType = 'wasm' | 'native';
|
|
96
|
-
|
|
97
|
-
type OracleRecording = {
|
|
98
|
-
calls: number;
|
|
99
|
-
max: number;
|
|
100
|
-
min: number;
|
|
101
|
-
avg: number;
|
|
102
|
-
total: number;
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
type Step = Pick<PrivateExecutionStep, 'functionName' | 'gateCount'> & {
|
|
106
|
-
time: number;
|
|
107
|
-
accGateCount?: number;
|
|
108
|
-
oracles: Record<string, OracleRecording>;
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
type ClientFlowBenchmark = {
|
|
112
|
-
name: string;
|
|
113
|
-
timings: Omit<ProvingTimings & SimulationTimings, 'perFunction'> & { witgen: number };
|
|
114
|
-
maxMemory: number;
|
|
115
|
-
proverType: ProverType;
|
|
116
|
-
minimumTrace: StructuredTrace;
|
|
117
|
-
totalGateCount: number;
|
|
118
|
-
steps: Step[];
|
|
119
|
-
error: string | undefined;
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
function getMinimumTrace(logs: Log[]): StructuredTrace {
|
|
123
|
-
const minimumMessage = 'Minimum required block sizes for structured trace';
|
|
124
|
-
const minimumMessageIndex = logs.findIndex(log => log.message.includes(minimumMessage));
|
|
125
|
-
const candidateLogs = logs.slice(minimumMessageIndex - GATE_TYPES.length, minimumMessageIndex + 5);
|
|
126
|
-
|
|
127
|
-
const traceLogs = candidateLogs
|
|
128
|
-
.filter(log => GATE_TYPES.some(type => log.message.includes(type)))
|
|
129
|
-
.map(log => log.message.split(/\t|\n/))
|
|
130
|
-
.flat()
|
|
131
|
-
.map(log => log.replace(/\(mem: .*\)/, '').trim())
|
|
132
|
-
.filter(Boolean);
|
|
133
|
-
|
|
134
|
-
const traceSizes = traceLogs.map(log => {
|
|
135
|
-
const [gateType, gateSizeStr] = log
|
|
136
|
-
.replace(/\n.*\)$/, '')
|
|
137
|
-
.replace(/bb - /, '')
|
|
138
|
-
.split(':')
|
|
139
|
-
.map(s => s.trim());
|
|
140
|
-
const gateSize = parseInt(gateSizeStr);
|
|
141
|
-
assert(GATE_TYPES.includes(gateType as GateType), `Gate type ${gateType} is not recognized`);
|
|
142
|
-
return { [gateType]: gateSize };
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
assert(traceSizes.length === GATE_TYPES.length, 'Decoded trace sizes do not match expected amount of gate types');
|
|
146
|
-
return traceSizes.reduce((acc, curr) => ({ ...acc, ...curr }), {}) as StructuredTrace;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
function getMaxMemory(logs: Log[]): number {
|
|
150
|
-
const candidateLogs = logs.slice(0, 100).filter(log => /\(mem: .*MiB\)/.test(log.message));
|
|
151
|
-
const usage = candidateLogs.map(log => {
|
|
152
|
-
const memStr = log ? log.message.slice(log.message.indexOf('(mem: ') + 6, log.message.indexOf('MiB') - 3) : '';
|
|
153
|
-
return memStr ? parseInt(memStr) : 0;
|
|
154
|
-
});
|
|
155
|
-
return Math.max(...usage);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
export function generateBenchmark(
|
|
159
|
-
flow: string,
|
|
160
|
-
logs: Log[],
|
|
161
|
-
timings: ProvingTimings | SimulationTimings,
|
|
162
|
-
privateExecutionSteps: PrivateExecutionStep[],
|
|
163
|
-
proverType: ProverType,
|
|
164
|
-
error: string | undefined,
|
|
165
|
-
): ClientFlowBenchmark {
|
|
166
|
-
let maxMemory = 0;
|
|
167
|
-
let minimumTrace: StructuredTrace;
|
|
168
|
-
try {
|
|
169
|
-
minimumTrace = getMinimumTrace(logs);
|
|
170
|
-
maxMemory = getMaxMemory(logs);
|
|
171
|
-
} catch {
|
|
172
|
-
logger.warn(`Failed obtain minimum trace and max memory for ${flow}. Did you run with REAL_PROOFS=1?`);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
const steps = privateExecutionSteps.reduce<Step[]>((acc, step, i) => {
|
|
176
|
-
const previousAccGateCount = i === 0 ? 0 : acc[i - 1].accGateCount!;
|
|
177
|
-
return [
|
|
178
|
-
...acc,
|
|
179
|
-
{
|
|
180
|
-
functionName: step.functionName,
|
|
181
|
-
gateCount: step.gateCount,
|
|
182
|
-
accGateCount: previousAccGateCount + step.gateCount!,
|
|
183
|
-
time: step.timings.witgen,
|
|
184
|
-
oracles: Object.entries(step.timings.oracles ?? {}).reduce(
|
|
185
|
-
(acc, [oracleName, oracleData]) => {
|
|
186
|
-
const total = oracleData.times.reduce((sum, time) => sum + time, 0);
|
|
187
|
-
const calls = oracleData.times.length;
|
|
188
|
-
acc[oracleName] = {
|
|
189
|
-
calls,
|
|
190
|
-
max: Math.max(...oracleData.times),
|
|
191
|
-
min: Math.min(...oracleData.times),
|
|
192
|
-
total,
|
|
193
|
-
avg: total / calls,
|
|
194
|
-
};
|
|
195
|
-
return acc;
|
|
196
|
-
},
|
|
197
|
-
{} as Record<string, OracleRecording>,
|
|
198
|
-
),
|
|
199
|
-
},
|
|
200
|
-
];
|
|
201
|
-
}, []);
|
|
202
|
-
const totalGateCount = steps[steps.length - 1].accGateCount;
|
|
203
|
-
return {
|
|
204
|
-
name: flow,
|
|
205
|
-
timings: {
|
|
206
|
-
total: timings.total,
|
|
207
|
-
sync: timings.sync!,
|
|
208
|
-
proving: (timings as ProvingTimings).proving,
|
|
209
|
-
unaccounted: timings.unaccounted,
|
|
210
|
-
witgen: timings.perFunction.reduce((acc, fn) => acc + fn.time, 0),
|
|
211
|
-
},
|
|
212
|
-
maxMemory,
|
|
213
|
-
proverType,
|
|
214
|
-
minimumTrace: minimumTrace!,
|
|
215
|
-
totalGateCount: totalGateCount!,
|
|
216
|
-
steps,
|
|
217
|
-
error,
|
|
218
|
-
};
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
export function convertProfileToGHBenchmark(benchmark: ClientFlowBenchmark): GithubActionBenchmarkResult[] {
|
|
222
|
-
const benches = [
|
|
223
|
-
{
|
|
224
|
-
name: `${benchmark.name}/witgen`,
|
|
225
|
-
value: benchmark.timings.witgen,
|
|
226
|
-
unit: 'ms',
|
|
227
|
-
},
|
|
228
|
-
|
|
229
|
-
{
|
|
230
|
-
name: `${benchmark.name}/total`,
|
|
231
|
-
value: benchmark.timings.total,
|
|
232
|
-
unit: 'ms',
|
|
233
|
-
},
|
|
234
|
-
{
|
|
235
|
-
name: `${benchmark.name}/sync`,
|
|
236
|
-
value: benchmark.timings.sync!,
|
|
237
|
-
unit: 'ms',
|
|
238
|
-
},
|
|
239
|
-
{
|
|
240
|
-
name: `${benchmark.name}/unaccounted`,
|
|
241
|
-
value: benchmark.timings.unaccounted,
|
|
242
|
-
unit: 'ms',
|
|
243
|
-
},
|
|
244
|
-
|
|
245
|
-
{
|
|
246
|
-
name: `${benchmark.name}/total_gate_count`,
|
|
247
|
-
value: benchmark.totalGateCount,
|
|
248
|
-
unit: 'gates',
|
|
249
|
-
},
|
|
250
|
-
];
|
|
251
|
-
if (benchmark.timings.proving) {
|
|
252
|
-
benches.push({
|
|
253
|
-
name: `${benchmark.name}/proving`,
|
|
254
|
-
value: benchmark.timings.proving,
|
|
255
|
-
unit: 'ms',
|
|
256
|
-
});
|
|
257
|
-
}
|
|
258
|
-
if (benchmark.maxMemory) {
|
|
259
|
-
benches.push({
|
|
260
|
-
name: `${benchmark.name}/max_memory`,
|
|
261
|
-
value: benchmark.maxMemory,
|
|
262
|
-
unit: 'MiB',
|
|
263
|
-
});
|
|
264
|
-
}
|
|
265
|
-
return benches;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
export async function captureProfile(
|
|
269
|
-
label: string,
|
|
270
|
-
interaction: ContractFunctionInteraction | DeployMethod,
|
|
271
|
-
opts?: Omit<ProfileMethodOptions & DeployOptions, 'profileMode'>,
|
|
272
|
-
expectedSteps?: number,
|
|
273
|
-
) {
|
|
274
|
-
// Make sure the proxy logger starts from a clean slate
|
|
275
|
-
ProxyLogger.getInstance().flushLogs();
|
|
276
|
-
const result = await interaction.profile({ ...opts, profileMode: 'full', skipProofGeneration: false });
|
|
277
|
-
const logs = ProxyLogger.getInstance().getLogs();
|
|
278
|
-
if (expectedSteps !== undefined && result.executionSteps.length !== expectedSteps) {
|
|
279
|
-
throw new Error(`Expected ${expectedSteps} execution steps, got ${result.executionSteps.length}`);
|
|
280
|
-
}
|
|
281
|
-
const benchmark = generateBenchmark(label, logs, result.timings, result.executionSteps, 'wasm', undefined);
|
|
282
|
-
|
|
283
|
-
const ivcFolder = process.env.CAPTURE_IVC_FOLDER;
|
|
284
|
-
if (ivcFolder) {
|
|
285
|
-
logger.info(`Capturing client ivc execution profile for ${label}`);
|
|
286
|
-
|
|
287
|
-
const resultsDirectory = join(ivcFolder, label);
|
|
288
|
-
logger.info(`Writing private execution steps to ${resultsDirectory}`);
|
|
289
|
-
await mkdir(resultsDirectory, { recursive: true });
|
|
290
|
-
// Write the client IVC files read by the prover.
|
|
291
|
-
const ivcInputsPath = join(resultsDirectory, 'ivc-inputs.msgpack');
|
|
292
|
-
await writeFile(ivcInputsPath, serializePrivateExecutionSteps(result.executionSteps));
|
|
293
|
-
await writeFile(join(resultsDirectory, 'logs.json'), JSON.stringify(logs, null, 2));
|
|
294
|
-
await writeFile(join(resultsDirectory, 'benchmark.json'), JSON.stringify(benchmark, null, 2));
|
|
295
|
-
logger.info(`Wrote private execution steps to ${resultsDirectory}`);
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
const benchOutput = process.env.BENCH_OUTPUT;
|
|
299
|
-
if (benchOutput) {
|
|
300
|
-
await mkdir(benchOutput, { recursive: true });
|
|
301
|
-
const ghBenchmark = convertProfileToGHBenchmark(benchmark);
|
|
302
|
-
const benchFile = join(benchOutput, `${label}.bench.json`);
|
|
303
|
-
await writeFile(benchFile, JSON.stringify(ghBenchmark));
|
|
304
|
-
logger.info(`Wrote benchmark to ${benchFile}`);
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
return result;
|
|
308
|
-
}
|