@aztec/simulator 0.87.4 → 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/client.d.ts +0 -2
- package/dest/client.d.ts.map +1 -1
- package/dest/client.js +0 -2
- package/dest/private/acvm/acvm.d.ts +0 -4
- package/dest/private/acvm/acvm.d.ts.map +1 -1
- package/dest/private/acvm/oracle/oracle.d.ts +1 -1
- package/dest/private/acvm/oracle/oracle.d.ts.map +1 -1
- package/dest/private/acvm/oracle/oracle.js +2 -2
- package/dest/private/acvm/oracle/typed_oracle.d.ts +1 -1
- package/dest/private/acvm/oracle/typed_oracle.d.ts.map +1 -1
- package/dest/private/acvm/oracle/typed_oracle.js +2 -2
- package/dest/private/private_execution.d.ts.map +1 -1
- package/dest/private/private_execution.js +1 -2
- package/dest/private/private_execution_oracle.d.ts +1 -1
- package/dest/private/private_execution_oracle.d.ts.map +1 -1
- package/dest/private/private_execution_oracle.js +1 -1
- package/dest/private/providers/circuit_recording/circuit_recorder.d.ts +19 -39
- package/dest/private/providers/circuit_recording/circuit_recorder.d.ts.map +1 -1
- package/dest/private/providers/circuit_recording/circuit_recorder.js +126 -90
- package/dest/private/providers/circuit_recording/simulation_provider_recorder_wrapper.d.ts +1 -3
- package/dest/private/providers/circuit_recording/simulation_provider_recorder_wrapper.d.ts.map +1 -1
- package/dest/private/providers/circuit_recording/simulation_provider_recorder_wrapper.js +11 -16
- package/dest/private/utility_execution_oracle.d.ts +1 -1
- package/dest/private/utility_execution_oracle.d.ts.map +1 -1
- package/dest/private/utility_execution_oracle.js +1 -1
- package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts +0 -1
- package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts.map +1 -1
- package/dest/public/avm/fixtures/base_avm_simulation_tester.js +0 -6
- package/dest/public/public_tx_simulator/apps_tests/amm_test.d.ts.map +1 -1
- package/dest/public/public_tx_simulator/apps_tests/amm_test.js +55 -27
- package/dest/server.d.ts +0 -2
- package/dest/server.d.ts.map +1 -1
- package/dest/server.js +0 -2
- package/dest/testing.d.ts +1 -1
- package/dest/testing.d.ts.map +1 -1
- package/dest/testing.js +1 -1
- package/package.json +15 -15
- package/src/client.ts +0 -2
- package/src/private/acvm/acvm.ts +0 -3
- package/src/private/acvm/oracle/oracle.ts +2 -2
- package/src/private/acvm/oracle/typed_oracle.ts +2 -2
- package/src/private/private_execution.ts +0 -1
- package/src/private/private_execution_oracle.ts +1 -1
- package/src/private/providers/circuit_recording/circuit_recorder.ts +136 -114
- package/src/private/providers/circuit_recording/simulation_provider_recorder_wrapper.ts +14 -22
- package/src/private/utility_execution_oracle.ts +1 -1
- package/src/public/avm/fixtures/base_avm_simulation_tester.ts +0 -5
- package/src/public/public_tx_simulator/apps_tests/amm_test.ts +44 -49
- package/src/server.ts +0 -2
- package/src/testing.ts +1 -1
- package/dest/private/providers/circuit_recording/file_circuit_recorder.d.ts +0 -31
- package/dest/private/providers/circuit_recording/file_circuit_recorder.d.ts.map +0 -1
- package/dest/private/providers/circuit_recording/file_circuit_recorder.js +0 -135
- package/dest/private/providers/circuit_recording/memory_circuit_recorder.d.ts +0 -5
- package/dest/private/providers/circuit_recording/memory_circuit_recorder.d.ts.map +0 -1
- package/dest/private/providers/circuit_recording/memory_circuit_recorder.js +0 -9
- package/src/private/providers/circuit_recording/file_circuit_recorder.ts +0 -158
- package/src/private/providers/circuit_recording/memory_circuit_recorder.ts +0 -11
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import fs from 'fs/promises';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import { CircuitRecorder } from './circuit_recorder.js';
|
|
4
|
-
export class FileCircuitRecorder extends CircuitRecorder {
|
|
5
|
-
recordDir;
|
|
6
|
-
constructor(recordDir){
|
|
7
|
-
super(), this.recordDir = recordDir;
|
|
8
|
-
}
|
|
9
|
-
async start(input, circuitBytecode, circuitName, functionName = 'main') {
|
|
10
|
-
await super.start(input, circuitBytecode, circuitName, functionName);
|
|
11
|
-
const recordingStringWithoutClosingBracket = JSON.stringify({
|
|
12
|
-
...this.recording,
|
|
13
|
-
isFirstCall: undefined,
|
|
14
|
-
parent: undefined,
|
|
15
|
-
oracleCalls: undefined,
|
|
16
|
-
filePath: undefined
|
|
17
|
-
}, null, 2).slice(0, -2);
|
|
18
|
-
try {
|
|
19
|
-
// Check if the recording directory exists and is a directory
|
|
20
|
-
const stats = await fs.stat(this.recordDir);
|
|
21
|
-
if (!stats.isDirectory()) {
|
|
22
|
-
throw new Error(`Recording path ${this.recordDir} exists but is not a directory`);
|
|
23
|
-
}
|
|
24
|
-
} catch (err) {
|
|
25
|
-
if (err.code === 'ENOENT') {
|
|
26
|
-
// The directory does not exist so we create it
|
|
27
|
-
await fs.mkdir(this.recordDir, {
|
|
28
|
-
recursive: true
|
|
29
|
-
});
|
|
30
|
-
} else {
|
|
31
|
-
throw err;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
this.recording.isFirstCall = true;
|
|
35
|
-
this.recording.filePath = await FileCircuitRecorder.#computeFilePathAndStoreInitialRecording(this.recordDir, this.recording.circuitName, this.recording.functionName, recordingStringWithoutClosingBracket);
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Computes a unique file path for the recording by trying different counter values.
|
|
39
|
-
* This is needed because multiple recordings of the same circuit could be happening simultaneously or an older
|
|
40
|
-
* recording might be present.
|
|
41
|
-
* @param recordDir - Directory to store the recording
|
|
42
|
-
* @param circuitName - Name of the circuit
|
|
43
|
-
* @param functionName - Name of the circuit function
|
|
44
|
-
* @param recordingContent - Initial recording content
|
|
45
|
-
* @returns A unique file path for the recording
|
|
46
|
-
*/ static async #computeFilePathAndStoreInitialRecording(recordDir, circuitName, functionName, recordingContent) {
|
|
47
|
-
let counter = 0;
|
|
48
|
-
while(true){
|
|
49
|
-
try {
|
|
50
|
-
const filePath = getFilePath(recordDir, circuitName, functionName, counter);
|
|
51
|
-
// Write the initial recording content to the file
|
|
52
|
-
await fs.writeFile(filePath, recordingContent + ',\n "oracleCalls": [\n', {
|
|
53
|
-
flag: 'wx'
|
|
54
|
-
});
|
|
55
|
-
return filePath;
|
|
56
|
-
} catch (err) {
|
|
57
|
-
if (err.code === 'EEXIST') {
|
|
58
|
-
counter++;
|
|
59
|
-
continue;
|
|
60
|
-
}
|
|
61
|
-
throw err;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Records a single oracle/foreign call with its inputs and outputs.
|
|
67
|
-
* @param name - Name of the call
|
|
68
|
-
* @param inputs - Input arguments
|
|
69
|
-
* @param outputs - Output results
|
|
70
|
-
*/ async recordCall(name, inputs, outputs, time, stackDepth) {
|
|
71
|
-
const entry = await super.recordCall(name, inputs, outputs, time, stackDepth);
|
|
72
|
-
try {
|
|
73
|
-
const prefix = this.recording.isFirstCall ? ' ' : ' ,';
|
|
74
|
-
this.recording.isFirstCall = false;
|
|
75
|
-
await fs.appendFile(this.recording.filePath, prefix + JSON.stringify(entry) + '\n');
|
|
76
|
-
} catch (err) {
|
|
77
|
-
this.logger.error('Failed to log circuit call', {
|
|
78
|
-
error: err
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
return entry;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Finalizes the recording file by adding closing brackets. Without calling this method, the recording file is
|
|
85
|
-
* incomplete and it fails to parse.
|
|
86
|
-
*/ async finish() {
|
|
87
|
-
// Finish sets the recording to undefined if we are at the topmost circuit,
|
|
88
|
-
// so we save the current file path before that
|
|
89
|
-
const filePath = this.recording.filePath;
|
|
90
|
-
const result = await super.finish();
|
|
91
|
-
try {
|
|
92
|
-
await fs.appendFile(filePath, ' ]\n}\n');
|
|
93
|
-
} catch (err) {
|
|
94
|
-
this.logger.error('Failed to finalize recording file', {
|
|
95
|
-
error: err
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
return result;
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Finalizes the recording file by adding the error and closing brackets. Without calling this method or `finish`,
|
|
102
|
-
* the recording file is incomplete and it fails to parse.
|
|
103
|
-
* @param error - The error that occurred during circuit execution
|
|
104
|
-
*/ async finishWithError(error) {
|
|
105
|
-
// Finish sets the recording to undefined if we are at the topmost circuit,
|
|
106
|
-
// so we save the current file path before that
|
|
107
|
-
const filePath = this.recording.filePath;
|
|
108
|
-
const result = await super.finishWithError(error);
|
|
109
|
-
try {
|
|
110
|
-
await fs.appendFile(filePath, ' ],\n');
|
|
111
|
-
await fs.appendFile(filePath, ` "error": ${JSON.stringify(error)}\n`);
|
|
112
|
-
await fs.appendFile(filePath, '}\n');
|
|
113
|
-
} catch (err) {
|
|
114
|
-
this.logger.error('Failed to finalize recording file with error', {
|
|
115
|
-
error: err
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
return result;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Generates a file path for storing circuit recordings. The format of the filename is:
|
|
123
|
-
* `circuit_name_circuit_function_name_YYYY-MM-DD_N.json` where N is a counter to ensure unique filenames.
|
|
124
|
-
* @param recordDir - Base directory for recordings
|
|
125
|
-
* @param circuitName - Name of the circuit
|
|
126
|
-
* @param functionName - Name of the circuit function
|
|
127
|
-
* @param counter - Counter to ensure unique filenames. This is expected to be incremented in a loop until there is no
|
|
128
|
-
* existing file with the same name.
|
|
129
|
-
* @returns A file path for the recording.
|
|
130
|
-
*/ function getFilePath(recordDir, circuitName, functionName, counter) {
|
|
131
|
-
const date = new Date();
|
|
132
|
-
const formattedDate = date.toISOString().split('T')[0];
|
|
133
|
-
const filename = `${circuitName}_${functionName}_${formattedDate}_${counter}.json`;
|
|
134
|
-
return path.join(recordDir, filename);
|
|
135
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"memory_circuit_recorder.d.ts","sourceRoot":"","sources":["../../../../src/private/providers/circuit_recording/memory_circuit_recorder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAMxD,qBAAa,qBAAsB,SAAQ,eAAe;;CAIzD"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { CircuitRecorder } from './circuit_recorder.js';
|
|
2
|
-
/*
|
|
3
|
-
* In memory circuit recorder uses the default implementation. This is kept
|
|
4
|
-
* while we decide the fate of the FileCircuitRecorder
|
|
5
|
-
*/ export class MemoryCircuitRecorder extends CircuitRecorder {
|
|
6
|
-
constructor(){
|
|
7
|
-
super();
|
|
8
|
-
}
|
|
9
|
-
}
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
import fs from 'fs/promises';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
|
|
4
|
-
import type { ACVMWitness } from '../../acvm/acvm_types.js';
|
|
5
|
-
import { CircuitRecorder, type CircuitRecording } from './circuit_recorder.js';
|
|
6
|
-
|
|
7
|
-
export class FileCircuitRecorder extends CircuitRecorder {
|
|
8
|
-
declare recording?: CircuitRecording & { filePath: string; isFirstCall: boolean };
|
|
9
|
-
|
|
10
|
-
constructor(private readonly recordDir: string) {
|
|
11
|
-
super();
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
override async start(
|
|
15
|
-
input: ACVMWitness,
|
|
16
|
-
circuitBytecode: Buffer,
|
|
17
|
-
circuitName: string,
|
|
18
|
-
functionName: string = 'main',
|
|
19
|
-
) {
|
|
20
|
-
await super.start(input, circuitBytecode, circuitName, functionName);
|
|
21
|
-
|
|
22
|
-
const recordingStringWithoutClosingBracket = JSON.stringify(
|
|
23
|
-
{ ...this.recording, isFirstCall: undefined, parent: undefined, oracleCalls: undefined, filePath: undefined },
|
|
24
|
-
null,
|
|
25
|
-
2,
|
|
26
|
-
).slice(0, -2);
|
|
27
|
-
|
|
28
|
-
try {
|
|
29
|
-
// Check if the recording directory exists and is a directory
|
|
30
|
-
const stats = await fs.stat(this.recordDir);
|
|
31
|
-
if (!stats.isDirectory()) {
|
|
32
|
-
throw new Error(`Recording path ${this.recordDir} exists but is not a directory`);
|
|
33
|
-
}
|
|
34
|
-
} catch (err) {
|
|
35
|
-
if ((err as NodeJS.ErrnoException).code === 'ENOENT') {
|
|
36
|
-
// The directory does not exist so we create it
|
|
37
|
-
await fs.mkdir(this.recordDir, { recursive: true });
|
|
38
|
-
} else {
|
|
39
|
-
throw err;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
this.recording!.isFirstCall = true;
|
|
44
|
-
this.recording!.filePath = await FileCircuitRecorder.#computeFilePathAndStoreInitialRecording(
|
|
45
|
-
this.recordDir,
|
|
46
|
-
this.recording!.circuitName,
|
|
47
|
-
this.recording!.functionName,
|
|
48
|
-
recordingStringWithoutClosingBracket,
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Computes a unique file path for the recording by trying different counter values.
|
|
54
|
-
* This is needed because multiple recordings of the same circuit could be happening simultaneously or an older
|
|
55
|
-
* recording might be present.
|
|
56
|
-
* @param recordDir - Directory to store the recording
|
|
57
|
-
* @param circuitName - Name of the circuit
|
|
58
|
-
* @param functionName - Name of the circuit function
|
|
59
|
-
* @param recordingContent - Initial recording content
|
|
60
|
-
* @returns A unique file path for the recording
|
|
61
|
-
*/
|
|
62
|
-
static async #computeFilePathAndStoreInitialRecording(
|
|
63
|
-
recordDir: string,
|
|
64
|
-
circuitName: string,
|
|
65
|
-
functionName: string,
|
|
66
|
-
recordingContent: string,
|
|
67
|
-
): Promise<string> {
|
|
68
|
-
let counter = 0;
|
|
69
|
-
while (true) {
|
|
70
|
-
try {
|
|
71
|
-
const filePath = getFilePath(recordDir, circuitName, functionName, counter);
|
|
72
|
-
// Write the initial recording content to the file
|
|
73
|
-
await fs.writeFile(filePath, recordingContent + ',\n "oracleCalls": [\n', {
|
|
74
|
-
flag: 'wx', // wx flag fails if file exists
|
|
75
|
-
});
|
|
76
|
-
return filePath;
|
|
77
|
-
} catch (err) {
|
|
78
|
-
if ((err as NodeJS.ErrnoException).code === 'EEXIST') {
|
|
79
|
-
counter++;
|
|
80
|
-
continue;
|
|
81
|
-
}
|
|
82
|
-
throw err;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Records a single oracle/foreign call with its inputs and outputs.
|
|
89
|
-
* @param name - Name of the call
|
|
90
|
-
* @param inputs - Input arguments
|
|
91
|
-
* @param outputs - Output results
|
|
92
|
-
*/
|
|
93
|
-
override async recordCall(name: string, inputs: unknown[], outputs: unknown, time: number, stackDepth: number) {
|
|
94
|
-
const entry = await super.recordCall(name, inputs, outputs, time, stackDepth);
|
|
95
|
-
try {
|
|
96
|
-
const prefix = this.recording!.isFirstCall ? ' ' : ' ,';
|
|
97
|
-
this.recording!.isFirstCall = false;
|
|
98
|
-
await fs.appendFile(this.recording!.filePath, prefix + JSON.stringify(entry) + '\n');
|
|
99
|
-
} catch (err) {
|
|
100
|
-
this.logger.error('Failed to log circuit call', { error: err });
|
|
101
|
-
}
|
|
102
|
-
return entry;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Finalizes the recording file by adding closing brackets. Without calling this method, the recording file is
|
|
107
|
-
* incomplete and it fails to parse.
|
|
108
|
-
*/
|
|
109
|
-
override async finish(): Promise<CircuitRecording> {
|
|
110
|
-
// Finish sets the recording to undefined if we are at the topmost circuit,
|
|
111
|
-
// so we save the current file path before that
|
|
112
|
-
const filePath = this.recording!.filePath;
|
|
113
|
-
const result = await super.finish();
|
|
114
|
-
try {
|
|
115
|
-
await fs.appendFile(filePath, ' ]\n}\n');
|
|
116
|
-
} catch (err) {
|
|
117
|
-
this.logger.error('Failed to finalize recording file', { error: err });
|
|
118
|
-
}
|
|
119
|
-
return result!;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Finalizes the recording file by adding the error and closing brackets. Without calling this method or `finish`,
|
|
124
|
-
* the recording file is incomplete and it fails to parse.
|
|
125
|
-
* @param error - The error that occurred during circuit execution
|
|
126
|
-
*/
|
|
127
|
-
override async finishWithError(error: unknown): Promise<CircuitRecording> {
|
|
128
|
-
// Finish sets the recording to undefined if we are at the topmost circuit,
|
|
129
|
-
// so we save the current file path before that
|
|
130
|
-
const filePath = this.recording!.filePath;
|
|
131
|
-
const result = await super.finishWithError(error);
|
|
132
|
-
try {
|
|
133
|
-
await fs.appendFile(filePath, ' ],\n');
|
|
134
|
-
await fs.appendFile(filePath, ` "error": ${JSON.stringify(error)}\n`);
|
|
135
|
-
await fs.appendFile(filePath, '}\n');
|
|
136
|
-
} catch (err) {
|
|
137
|
-
this.logger.error('Failed to finalize recording file with error', { error: err });
|
|
138
|
-
}
|
|
139
|
-
return result!;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Generates a file path for storing circuit recordings. The format of the filename is:
|
|
145
|
-
* `circuit_name_circuit_function_name_YYYY-MM-DD_N.json` where N is a counter to ensure unique filenames.
|
|
146
|
-
* @param recordDir - Base directory for recordings
|
|
147
|
-
* @param circuitName - Name of the circuit
|
|
148
|
-
* @param functionName - Name of the circuit function
|
|
149
|
-
* @param counter - Counter to ensure unique filenames. This is expected to be incremented in a loop until there is no
|
|
150
|
-
* existing file with the same name.
|
|
151
|
-
* @returns A file path for the recording.
|
|
152
|
-
*/
|
|
153
|
-
function getFilePath(recordDir: string, circuitName: string, functionName: string, counter: number): string {
|
|
154
|
-
const date = new Date();
|
|
155
|
-
const formattedDate = date.toISOString().split('T')[0];
|
|
156
|
-
const filename = `${circuitName}_${functionName}_${formattedDate}_${counter}.json`;
|
|
157
|
-
return path.join(recordDir, filename);
|
|
158
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { CircuitRecorder } from './circuit_recorder.js';
|
|
2
|
-
|
|
3
|
-
/*
|
|
4
|
-
* In memory circuit recorder uses the default implementation. This is kept
|
|
5
|
-
* while we decide the fate of the FileCircuitRecorder
|
|
6
|
-
*/
|
|
7
|
-
export class MemoryCircuitRecorder extends CircuitRecorder {
|
|
8
|
-
constructor() {
|
|
9
|
-
super();
|
|
10
|
-
}
|
|
11
|
-
}
|