@aztec/simulator 5.0.0-rc.1 → 5.0.0-rc.2
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 +1 -3
- package/dest/client.d.ts.map +1 -1
- package/dest/client.js +0 -2
- package/dest/private/circuit_recording/circuit_recorder.d.ts +36 -23
- package/dest/private/circuit_recording/circuit_recorder.d.ts.map +1 -1
- package/dest/private/circuit_recording/circuit_recorder.js +65 -69
- package/dest/private/circuit_recording/file_circuit_recorder.d.ts +7 -19
- package/dest/private/circuit_recording/file_circuit_recorder.d.ts.map +1 -1
- package/dest/private/circuit_recording/file_circuit_recorder.js +38 -42
- package/dest/private/circuit_recording/simulator_recorder_wrapper.d.ts +1 -1
- package/dest/private/circuit_recording/simulator_recorder_wrapper.d.ts.map +1 -1
- package/dest/private/circuit_recording/simulator_recorder_wrapper.js +11 -14
- package/dest/public/avm/fixtures/base_avm_simulation_tester.js +1 -1
- package/dest/public/avm/fixtures/utils.js +1 -1
- package/dest/public/fixtures/amm_test.js +2 -2
- package/dest/public/fixtures/bulk_test.js +2 -2
- package/dest/public/fixtures/custom_bytecode_tester.d.ts +1 -1
- package/dest/public/fixtures/custom_bytecode_tester.d.ts.map +1 -1
- package/dest/public/fixtures/custom_bytecode_tester.js +2 -2
- package/dest/public/fixtures/token_test.js +3 -3
- package/dest/public/fixtures/utils.js +1 -1
- package/dest/public/public_tx_simulator/contract_provider_for_cpp.js +2 -2
- package/dest/public/state_manager/state_manager.js +1 -1
- package/package.json +16 -16
- package/src/client.ts +0 -2
- package/src/private/circuit_recording/circuit_recorder.ts +84 -78
- package/src/private/circuit_recording/file_circuit_recorder.ts +38 -48
- package/src/private/circuit_recording/simulator_recorder_wrapper.ts +9 -15
- package/src/public/avm/fixtures/base_avm_simulation_tester.ts +1 -1
- package/src/public/avm/fixtures/utils.ts +1 -1
- package/src/public/fixtures/amm_test.ts +2 -2
- package/src/public/fixtures/bulk_test.ts +2 -2
- package/src/public/fixtures/custom_bytecode_tester.ts +2 -2
- package/src/public/fixtures/token_test.ts +3 -3
- package/src/public/fixtures/utils.ts +1 -1
- package/src/public/public_tx_simulator/contract_provider_for_cpp.ts +2 -2
- package/src/public/state_manager/state_manager.ts +1 -1
package/dest/client.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
export * from './private/acvm/index.js';
|
|
2
2
|
export { WASMSimulator } from './private/acvm_wasm.js';
|
|
3
|
-
export { SimulatorRecorderWrapper } from './private/circuit_recording/simulator_recorder_wrapper.js';
|
|
4
|
-
export { MemoryCircuitRecorder } from './private/circuit_recording/memory_circuit_recorder.js';
|
|
5
3
|
export { type CircuitSimulator, type DecodedError } from './private/circuit_simulator.js';
|
|
6
4
|
export * from './common/index.js';
|
|
7
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
5
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2xpZW50LmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvY2xpZW50LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLGNBQWMseUJBQXlCLENBQUM7QUFDeEMsT0FBTyxFQUFFLGFBQWEsRUFBRSxNQUFNLHdCQUF3QixDQUFDO0FBQ3ZELE9BQU8sRUFBRSxLQUFLLGdCQUFnQixFQUFFLEtBQUssWUFBWSxFQUFFLE1BQU0sZ0NBQWdDLENBQUM7QUFDMUYsY0FBYyxtQkFBbUIsQ0FBQyJ9
|
package/dest/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,KAAK,gBAAgB,EAAE,KAAK,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAC1F,cAAc,mBAAmB,CAAC"}
|
package/dest/client.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
1
|
export * from './private/acvm/index.js';
|
|
2
2
|
export { WASMSimulator } from './private/acvm_wasm.js';
|
|
3
|
-
export { SimulatorRecorderWrapper } from './private/circuit_recording/simulator_recorder_wrapper.js';
|
|
4
|
-
export { MemoryCircuitRecorder } from './private/circuit_recording/memory_circuit_recorder.js';
|
|
5
3
|
export * from './common/index.js';
|
|
@@ -21,10 +21,22 @@ export declare class CircuitRecording {
|
|
|
21
21
|
constructor(circuitName: string, functionName: string, bytecodeSHA512Hash: string, inputs: Record<string, string>);
|
|
22
22
|
setParent(recording?: CircuitRecording): void;
|
|
23
23
|
}
|
|
24
|
+
/** Inputs needed to open a recording for a single circuit execution. */
|
|
25
|
+
export type RecordingMetadata = {
|
|
26
|
+
input: ACVMWitness;
|
|
27
|
+
bytecode: Buffer;
|
|
28
|
+
circuitName: string;
|
|
29
|
+
functionName: string;
|
|
30
|
+
};
|
|
24
31
|
/**
|
|
25
32
|
* Class responsible for recording circuit inputs necessary to replay the circuit. These inputs are the initial witness
|
|
26
33
|
* map and the oracle calls made during the circuit execution/witness generation.
|
|
27
34
|
*
|
|
35
|
+
* The active recording for an execution lives in `AsyncLocalStorage`, so each (possibly nested) circuit execution owns
|
|
36
|
+
* its own recording and concurrent or re-entrant executions cannot corrupt one another's state. Nested executions
|
|
37
|
+
* (`aztec_prv_callPrivateFunction`, utility calls) re-enter {@link record}, which links the child to the recording
|
|
38
|
+
* active in the enclosing async context and lets ALS restore the parent automatically when the child completes.
|
|
39
|
+
*
|
|
28
40
|
* Example recording object:
|
|
29
41
|
* ```json
|
|
30
42
|
* {
|
|
@@ -69,20 +81,21 @@ export declare class CircuitRecording {
|
|
|
69
81
|
export declare class CircuitRecorder {
|
|
70
82
|
#private;
|
|
71
83
|
protected readonly logger: Logger;
|
|
72
|
-
protected recording?: CircuitRecording;
|
|
73
|
-
private stackDepth;
|
|
74
|
-
private newCircuit;
|
|
75
84
|
protected constructor(loggerOrBindings?: Logger | LoggerBindings);
|
|
76
85
|
/**
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
86
|
+
* Records a single circuit execution. Opens a recording for the circuit (linked as a child of the recording active
|
|
87
|
+
* in the current async context, if any), runs `fn` within that recording's context, and finalizes it. The recording
|
|
88
|
+
* is returned alongside the result so callers can derive per-circuit stats (e.g. oracle timings).
|
|
89
|
+
*
|
|
90
|
+
* Recorder bookkeeping never alters execution: if `fn` throws, the error is attached to the recording and re-thrown
|
|
91
|
+
* unchanged.
|
|
92
|
+
* @param metadata - Identifies the circuit and its initial witness.
|
|
93
|
+
* @param fn - Runs the circuit execution; its oracle calls are recorded into this recording.
|
|
84
94
|
*/
|
|
85
|
-
|
|
95
|
+
record<T>(metadata: RecordingMetadata, fn: () => Promise<T>): Promise<{
|
|
96
|
+
result: T;
|
|
97
|
+
recording: CircuitRecording;
|
|
98
|
+
}>;
|
|
86
99
|
/**
|
|
87
100
|
* Wraps a callback to record all oracle/foreign calls.
|
|
88
101
|
* @param callback - The original callback to wrap, either a user circuit callback or protocol circuit callback.
|
|
@@ -90,20 +103,20 @@ export declare class CircuitRecorder {
|
|
|
90
103
|
*/
|
|
91
104
|
wrapCallback(callback: ACIRCallback | ForeignCallHandler | undefined): ACIRCallback | ForeignCallHandler | undefined;
|
|
92
105
|
/**
|
|
93
|
-
* Records a single oracle/foreign call with its inputs and outputs
|
|
106
|
+
* Records a single oracle/foreign call with its inputs and outputs against the recording active in the current
|
|
107
|
+
* async context.
|
|
94
108
|
* @param name - Name of the call
|
|
95
109
|
* @param inputs - Input arguments
|
|
96
110
|
* @param outputs - Output results
|
|
97
111
|
*/
|
|
98
|
-
recordCall(name: string, inputs: unknown[], outputs: unknown, time: number
|
|
99
|
-
/**
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
finishWithError(error: unknown): Promise<CircuitRecording>;
|
|
112
|
+
recordCall(name: string, inputs: unknown[], outputs: unknown, time: number): Promise<OracleCall>;
|
|
113
|
+
/** The recording active in the current async context, if any. */
|
|
114
|
+
protected currentRecording(): CircuitRecording | undefined;
|
|
115
|
+
/** Hook invoked when a recording opens, within the recording's context. Overridden to persist recordings. */
|
|
116
|
+
protected onStart(_recording: CircuitRecording): Promise<void>;
|
|
117
|
+
/** Hook invoked when a recording completes successfully, within the recording's context. */
|
|
118
|
+
protected onFinish(_recording: CircuitRecording): Promise<void>;
|
|
119
|
+
/** Hook invoked when a recording's execution throws, within the recording's context. */
|
|
120
|
+
protected onError(_recording: CircuitRecording, _error: unknown): Promise<void>;
|
|
108
121
|
}
|
|
109
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
122
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2lyY3VpdF9yZWNvcmRlci5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL3ByaXZhdGUvY2lyY3VpdF9yZWNvcmRpbmcvY2lyY3VpdF9yZWNvcmRlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFDQSxPQUFPLEVBQUUsS0FBSyxNQUFNLEVBQUUsS0FBSyxjQUFjLEVBQWlCLE1BQU0sdUJBQXVCLENBQUM7QUFFeEYsT0FBTyxLQUFLLEVBQUUsa0JBQWtCLEVBQXVDLE1BQU0scUJBQXFCLENBQUM7QUFJbkcsT0FBTyxLQUFLLEVBQUUsWUFBW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FVBQVUsRUFBRSxnQkFBZ0IsR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLENBRTdEO0lBRUQsNEZBQTRGO0lBQzVGLFNBQVMsQ0FBQyxRQUFRLENBQUMsVUFBVSxFQUFFLGdCQUFnQixHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0FFOUQ7SUFFRCx3RkFBd0Y7SUFDeEYsU0FBUyxDQUFDLE9BQU8sQ0FBQyxVQUFVLEVBQUUsZ0JBQWdCLEVBQUUsTUFBTSxFQUFFLE9BQU8sR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLENBRTlFO0NBQ0YifQ==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"circuit_recorder.d.ts","sourceRoot":"","sources":["../../../src/private/circuit_recording/circuit_recorder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,cAAc,EAAiB,MAAM,uBAAuB,CAAC;AAExF,OAAO,KAAK,EAAE,kBAAkB,EAAuC,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"circuit_recorder.d.ts","sourceRoot":"","sources":["../../../src/private/circuit_recording/circuit_recorder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,cAAc,EAAiB,MAAM,uBAAuB,CAAC;AAExF,OAAO,KAAK,EAAE,kBAAkB,EAAuC,MAAM,qBAAqB,CAAC;AAInG,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEzD,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,OAAO,EAAE,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IAMb,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,qBAAa,gBAAgB;IAC3B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nH;IAyDD;;;;;;OAMG;IACH,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAa/F;IAED,iEAAiE;IACjE,SAAS,CAAC,gBAAgB,IAAI,gBAAgB,GAAG,SAAS,CAEzD;IAED,6GAA6G;IAC7G,SAAS,CAAC,OAAO,CAAC,UAAU,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAE7D;IAED,4FAA4F;IAC5F,SAAS,CAAC,QAAQ,CAAC,UAAU,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAE9D;IAED,wFAAwF;IACxF,SAAS,CAAC,OAAO,CAAC,UAAU,EAAE,gBAAgB,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAE9E;CACF"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { sha512 } from '@aztec/foundation/crypto/sha512';
|
|
2
2
|
import { resolveLogger } from '@aztec/foundation/log';
|
|
3
3
|
import { Timer } from '@aztec/foundation/timer';
|
|
4
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
4
5
|
export class CircuitRecording {
|
|
5
6
|
circuitName;
|
|
6
7
|
functionName;
|
|
@@ -26,6 +27,11 @@ export class CircuitRecording {
|
|
|
26
27
|
* Class responsible for recording circuit inputs necessary to replay the circuit. These inputs are the initial witness
|
|
27
28
|
* map and the oracle calls made during the circuit execution/witness generation.
|
|
28
29
|
*
|
|
30
|
+
* The active recording for an execution lives in `AsyncLocalStorage`, so each (possibly nested) circuit execution owns
|
|
31
|
+
* its own recording and concurrent or re-entrant executions cannot corrupt one another's state. Nested executions
|
|
32
|
+
* (`aztec_prv_callPrivateFunction`, utility calls) re-enter {@link record}, which links the child to the recording
|
|
33
|
+
* active in the enclosing async context and lets ALS restore the parent automatically when the child completes.
|
|
34
|
+
*
|
|
29
35
|
* Example recording object:
|
|
30
36
|
* ```json
|
|
31
37
|
* {
|
|
@@ -68,27 +74,38 @@ export class CircuitRecording {
|
|
|
68
74
|
* ```
|
|
69
75
|
*/ export class CircuitRecorder {
|
|
70
76
|
logger;
|
|
71
|
-
|
|
72
|
-
stackDepth = 0;
|
|
73
|
-
newCircuit = true;
|
|
77
|
+
#recordings = new AsyncLocalStorage();
|
|
74
78
|
constructor(loggerOrBindings){
|
|
75
79
|
this.logger = resolveLogger('simulator:acvm:recording', loggerOrBindings);
|
|
76
80
|
}
|
|
77
81
|
/**
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
82
|
+
* Records a single circuit execution. Opens a recording for the circuit (linked as a child of the recording active
|
|
83
|
+
* in the current async context, if any), runs `fn` within that recording's context, and finalizes it. The recording
|
|
84
|
+
* is returned alongside the result so callers can derive per-circuit stats (e.g. oracle timings).
|
|
85
|
+
*
|
|
86
|
+
* Recorder bookkeeping never alters execution: if `fn` throws, the error is attached to the recording and re-thrown
|
|
87
|
+
* unchanged.
|
|
88
|
+
* @param metadata - Identifies the circuit and its initial witness.
|
|
89
|
+
* @param fn - Runs the circuit execution; its oracle calls are recorded into this recording.
|
|
90
|
+
*/ record(metadata, fn) {
|
|
91
|
+
const parent = this.#recordings.getStore();
|
|
92
|
+
const recording = new CircuitRecording(metadata.circuitName, metadata.functionName, sha512(metadata.bytecode).toString('hex'), Object.fromEntries(metadata.input));
|
|
93
|
+
recording.setParent(parent);
|
|
94
|
+
return this.#recordings.run(recording, async ()=>{
|
|
95
|
+
await this.onStart(recording);
|
|
96
|
+
try {
|
|
97
|
+
const result = await fn();
|
|
98
|
+
await this.onFinish(recording);
|
|
99
|
+
return {
|
|
100
|
+
result,
|
|
101
|
+
recording
|
|
102
|
+
};
|
|
103
|
+
} catch (error) {
|
|
104
|
+
recording.error = JSON.stringify(error);
|
|
105
|
+
await this.onError(recording, error);
|
|
106
|
+
throw error;
|
|
107
|
+
}
|
|
108
|
+
});
|
|
92
109
|
}
|
|
93
110
|
/**
|
|
94
111
|
* Wraps a callback to record all oracle/foreign calls.
|
|
@@ -109,7 +126,9 @@ export class CircuitRecording {
|
|
|
109
126
|
return typeof callback === 'object' && callback !== null && !('call' in callback);
|
|
110
127
|
}
|
|
111
128
|
/**
|
|
112
|
-
* Wraps a user circuit callback to record all oracle calls.
|
|
129
|
+
* Wraps a user circuit callback to record all oracle calls. A nested circuit entered via an oracle (e.g.
|
|
130
|
+
* `aztec_prv_callPrivateFunction`) re-enters {@link record}, so its own oracle calls land on the child recording and
|
|
131
|
+
* this circuit's calls (including the entering oracle call itself) land on this recording once the child completes.
|
|
113
132
|
* @param callback - The original circuit callback.
|
|
114
133
|
* @returns A wrapped callback that records all oracle interactions which is to be provided to the ACVM.
|
|
115
134
|
*/ #wrapUserCircuitCallback(callback) {
|
|
@@ -120,37 +139,16 @@ export class CircuitRecording {
|
|
|
120
139
|
if (!fn || typeof fn !== 'function') {
|
|
121
140
|
throw new Error(`Oracle method ${name} not found when setting up recording callback`);
|
|
122
141
|
}
|
|
123
|
-
const isExternalCall = name === 'aztec_prv_callPrivateFunction';
|
|
124
142
|
recordingCallback[name] = (...args)=>{
|
|
125
143
|
const timer = new Timer();
|
|
126
|
-
// If we're entering another circuit via `aztec_prv_callPrivateFunction`, we increase the stack depth and set the
|
|
127
|
-
// newCircuit variable to ensure we are creating a new recording object.
|
|
128
|
-
if (isExternalCall) {
|
|
129
|
-
this.stackDepth++;
|
|
130
|
-
this.newCircuit = true;
|
|
131
|
-
}
|
|
132
144
|
const result = fn.call(callback, ...args);
|
|
133
145
|
if (result instanceof Promise) {
|
|
134
146
|
return result.then(async (r)=>{
|
|
135
|
-
|
|
136
|
-
// so that the parent circuit continues with its existing recording
|
|
137
|
-
// Note: recording restoration is handled by finish()
|
|
138
|
-
if (isExternalCall) {
|
|
139
|
-
this.stackDepth--;
|
|
140
|
-
this.newCircuit = false;
|
|
141
|
-
}
|
|
142
|
-
await this.recordCall(name, args, r, timer.ms(), this.stackDepth);
|
|
147
|
+
await this.recordCall(name, args, r, timer.ms());
|
|
143
148
|
return r;
|
|
144
149
|
});
|
|
145
150
|
}
|
|
146
|
-
|
|
147
|
-
// so that the parent circuit continues with its existing recording
|
|
148
|
-
// Note: recording restoration is handled by finish()
|
|
149
|
-
if (isExternalCall) {
|
|
150
|
-
this.stackDepth--;
|
|
151
|
-
this.newCircuit = false;
|
|
152
|
-
}
|
|
153
|
-
void this.recordCall(name, args, result, timer.ms(), this.stackDepth);
|
|
151
|
+
void this.recordCall(name, args, result, timer.ms());
|
|
154
152
|
return result;
|
|
155
153
|
};
|
|
156
154
|
}
|
|
@@ -164,49 +162,47 @@ export class CircuitRecording {
|
|
|
164
162
|
return async (name, inputs)=>{
|
|
165
163
|
const timer = new Timer();
|
|
166
164
|
const result = await callback(name, inputs);
|
|
167
|
-
await this.recordCall(name, inputs, result, timer.ms()
|
|
165
|
+
await this.recordCall(name, inputs, result, timer.ms());
|
|
168
166
|
return result;
|
|
169
167
|
};
|
|
170
168
|
}
|
|
171
169
|
/**
|
|
172
|
-
* Records a single oracle/foreign call with its inputs and outputs
|
|
170
|
+
* Records a single oracle/foreign call with its inputs and outputs against the recording active in the current
|
|
171
|
+
* async context.
|
|
173
172
|
* @param name - Name of the call
|
|
174
173
|
* @param inputs - Input arguments
|
|
175
174
|
* @param outputs - Output results
|
|
176
|
-
*/ recordCall(name, inputs, outputs, time
|
|
175
|
+
*/ recordCall(name, inputs, outputs, time) {
|
|
176
|
+
const recording = this.#recordings.getStore();
|
|
177
177
|
const entry = {
|
|
178
178
|
name,
|
|
179
179
|
inputs,
|
|
180
180
|
outputs,
|
|
181
181
|
time,
|
|
182
|
-
stackDepth
|
|
182
|
+
stackDepth: depthOf(recording)
|
|
183
183
|
};
|
|
184
|
-
|
|
184
|
+
// Outside any active recording context (e.g. a stray call after the scope closed, or a direct unit-test call)
|
|
185
|
+
// there is nowhere to record; return the entry without throwing into the execution path.
|
|
186
|
+
recording?.oracleCalls.push(entry);
|
|
185
187
|
return Promise.resolve(entry);
|
|
186
188
|
}
|
|
187
|
-
/**
|
|
188
|
-
|
|
189
|
-
*/ finish() {
|
|
190
|
-
const result = this.recording;
|
|
191
|
-
// If this is the top-level circuit recording, we reset the state for the next simulator call
|
|
192
|
-
if (!result.parent) {
|
|
193
|
-
this.newCircuit = true;
|
|
194
|
-
this.recording = undefined;
|
|
195
|
-
} else {
|
|
196
|
-
// For nested circuits (utility calls, nested contract calls), restore to parent recording
|
|
197
|
-
// Note: we don't set newCircuit=false here because:
|
|
198
|
-
// - For privateCallPrivateFunction, the callback wrapper will set it to false
|
|
199
|
-
// - For utility calls, we want newCircuit to remain true so the next circuit creates its own recording
|
|
200
|
-
this.recording = result.parent;
|
|
201
|
-
}
|
|
202
|
-
return Promise.resolve(result);
|
|
189
|
+
/** The recording active in the current async context, if any. */ currentRecording() {
|
|
190
|
+
return this.#recordings.getStore();
|
|
203
191
|
}
|
|
204
|
-
/**
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
192
|
+
/** Hook invoked when a recording opens, within the recording's context. Overridden to persist recordings. */ onStart(_recording) {
|
|
193
|
+
return Promise.resolve();
|
|
194
|
+
}
|
|
195
|
+
/** Hook invoked when a recording completes successfully, within the recording's context. */ onFinish(_recording) {
|
|
196
|
+
return Promise.resolve();
|
|
197
|
+
}
|
|
198
|
+
/** Hook invoked when a recording's execution throws, within the recording's context. */ onError(_recording, _error) {
|
|
199
|
+
return Promise.resolve();
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
/** Depth of a recording in the call tree: 0 for a top-level circuit, incremented per nested circuit. */ function depthOf(recording) {
|
|
203
|
+
let depth = 0;
|
|
204
|
+
for(let ancestor = recording?.parent; ancestor; ancestor = ancestor.parent){
|
|
205
|
+
depth++;
|
|
211
206
|
}
|
|
207
|
+
return depth;
|
|
212
208
|
}
|
|
@@ -1,32 +1,20 @@
|
|
|
1
1
|
import type { Logger } from '@aztec/foundation/log';
|
|
2
|
-
import type { ACVMWitness } from '../acvm/acvm_types.js';
|
|
3
2
|
import { CircuitRecorder, type CircuitRecording } from './circuit_recorder.js';
|
|
4
3
|
export declare class FileCircuitRecorder extends CircuitRecorder {
|
|
5
4
|
#private;
|
|
6
5
|
private readonly recordDir;
|
|
7
|
-
recording?: CircuitRecording & {
|
|
8
|
-
filePath: string;
|
|
9
|
-
isFirstCall: boolean;
|
|
10
|
-
};
|
|
11
6
|
constructor(recordDir: string, logger?: Logger);
|
|
12
|
-
|
|
7
|
+
protected onStart(recording: CircuitRecording): Promise<void>;
|
|
13
8
|
/**
|
|
14
9
|
* Records a single oracle/foreign call with its inputs and outputs.
|
|
15
10
|
* @param name - Name of the call
|
|
16
11
|
* @param inputs - Input arguments
|
|
17
12
|
* @param outputs - Output results
|
|
18
13
|
*/
|
|
19
|
-
recordCall(name: string, inputs: unknown[], outputs: unknown, time: number
|
|
20
|
-
/**
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
finish(): Promise<CircuitRecording>;
|
|
25
|
-
/**
|
|
26
|
-
* Finalizes the recording file by adding the error and closing brackets. Without calling this method or `finish`,
|
|
27
|
-
* the recording file is incomplete and it fails to parse.
|
|
28
|
-
* @param error - The error that occurred during circuit execution
|
|
29
|
-
*/
|
|
30
|
-
finishWithError(error: unknown): Promise<CircuitRecording>;
|
|
14
|
+
recordCall(name: string, inputs: unknown[], outputs: unknown, time: number): Promise<import("./circuit_recorder.js").OracleCall>;
|
|
15
|
+
/** Closes the recording file with the trailing brackets so the JSON parses. */
|
|
16
|
+
protected onFinish(recording: CircuitRecording): Promise<void>;
|
|
17
|
+
/** Closes the recording file with the execution error and trailing brackets so the JSON parses. */
|
|
18
|
+
protected onError(recording: CircuitRecording, error: unknown): Promise<void>;
|
|
31
19
|
}
|
|
32
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
20
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZmlsZV9jaXJjdWl0X3JlY29yZGVyLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvcHJpdmF0ZS9jaXJjdWl0X3JlY29yZGluZy9maWxlX2NpcmN1aXRfcmVjb3JkZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLEVBQUUsTUFBTSxFQUFFLE1BQU0sdUJBQXVCLENBQUM7QUFLcEQsT0FBTyxFQUFFLGVBQWUsRUFBRSxLQUFLLGdCQUFnQixFQUFFLE1BQU0sdUJBQXVCLENBQUM7QUFLL0UscUJBQWEsbUJBQW9CLFNBQVEsZUFBZTs7SUFJcEQsT0FBTyxDQUFDLFFBQVEsQ0FBQyxTQUFTO0lBRDVCLFlBQ21CLFNBQVMsRUFBRSxNQUFNLEVBQ2xDLE1BQU0sQ0FBQyxFQUFFLE1BQU0sRUFHaEI7SUFFRCxVQUF5QixPQUFPLENBQUMsU0FBUyxFQUFFLGdCQUFnQixHQUFHLE9BQU8sQ0FBQyxJQUFJLENBQUMsQ0E2QjNFO0lBcUNEOzs7OztPQUtHO0lBQ1ksVUFBVSxDQUFDLElBQUksRUFBRSxNQUFNLEVBQUUsTUFBTSxFQUFFLE9BQU8sRUFBRSxFQUFFLE9BQU8sRUFBRSxPQUFPLEVBQUUsSUFBSSxFQUFFLE1BQU0sdURBY3hGO0lBRUQsK0VBQStFO0lBQy9FLFVBQXlCLFFBQVEsQ0FBQyxTQUFTLEVBQUUsZ0JBQWdCLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxDQVU1RTtJQUVELG1HQUFtRztJQUNuRyxVQUF5QixPQUFPLENBQUMsU0FBUyxFQUFFLGdCQUFnQixFQUFFLEtBQUssRUFBRSxPQUFPLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxDQVkzRjtDQUNGIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file_circuit_recorder.d.ts","sourceRoot":"","sources":["../../../src/private/circuit_recording/file_circuit_recorder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAKpD,OAAO,
|
|
1
|
+
{"version":3,"file":"file_circuit_recorder.d.ts","sourceRoot":"","sources":["../../../src/private/circuit_recording/file_circuit_recorder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAKpD,OAAO,EAAE,eAAe,EAAE,KAAK,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAK/E,qBAAa,mBAAoB,SAAQ,eAAe;;IAIpD,OAAO,CAAC,QAAQ,CAAC,SAAS;IAD5B,YACmB,SAAS,EAAE,MAAM,EAClC,MAAM,CAAC,EAAE,MAAM,EAGhB;IAED,UAAyB,OAAO,CAAC,SAAS,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CA6B3E;IAqCD;;;;;OAKG;IACY,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,uDAcxF;IAED,+EAA+E;IAC/E,UAAyB,QAAQ,CAAC,SAAS,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAU5E;IAED,mGAAmG;IACnG,UAAyB,OAAO,CAAC,SAAS,EAAE,gBAAgB,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAY3F;CACF"}
|
|
@@ -3,17 +3,15 @@ import path from 'path';
|
|
|
3
3
|
import { CircuitRecorder } from './circuit_recorder.js';
|
|
4
4
|
export class FileCircuitRecorder extends CircuitRecorder {
|
|
5
5
|
recordDir;
|
|
6
|
+
#fileState;
|
|
6
7
|
constructor(recordDir, logger){
|
|
7
|
-
super(logger), this.recordDir = recordDir;
|
|
8
|
+
super(logger), this.recordDir = recordDir, this.#fileState = new WeakMap();
|
|
8
9
|
}
|
|
9
|
-
async
|
|
10
|
-
await super.start(input, circuitBytecode, circuitName, functionName);
|
|
10
|
+
async onStart(recording) {
|
|
11
11
|
const recordingStringWithoutClosingBracket = JSON.stringify({
|
|
12
|
-
...
|
|
13
|
-
isFirstCall: undefined,
|
|
12
|
+
...recording,
|
|
14
13
|
parent: undefined,
|
|
15
|
-
oracleCalls: undefined
|
|
16
|
-
filePath: undefined
|
|
14
|
+
oracleCalls: undefined
|
|
17
15
|
}, null, 2).slice(0, -2);
|
|
18
16
|
try {
|
|
19
17
|
// Check if the recording directory exists and is a directory
|
|
@@ -31,8 +29,11 @@ export class FileCircuitRecorder extends CircuitRecorder {
|
|
|
31
29
|
throw err;
|
|
32
30
|
}
|
|
33
31
|
}
|
|
34
|
-
this.recording.
|
|
35
|
-
this.
|
|
32
|
+
const filePath = await FileCircuitRecorder.#computeFilePathAndStoreInitialRecording(this.recordDir, recording.circuitName, recording.functionName, recordingStringWithoutClosingBracket);
|
|
33
|
+
this.#fileState.set(recording, {
|
|
34
|
+
filePath,
|
|
35
|
+
isFirstCall: true
|
|
36
|
+
});
|
|
36
37
|
}
|
|
37
38
|
/**
|
|
38
39
|
* Computes a unique file path for the recording by trying different counter values.
|
|
@@ -67,55 +68,50 @@ export class FileCircuitRecorder extends CircuitRecorder {
|
|
|
67
68
|
* @param name - Name of the call
|
|
68
69
|
* @param inputs - Input arguments
|
|
69
70
|
* @param outputs - Output results
|
|
70
|
-
*/ async recordCall(name, inputs, outputs, time
|
|
71
|
-
const entry = await super.recordCall(name, inputs, outputs, time
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
})
|
|
71
|
+
*/ async recordCall(name, inputs, outputs, time) {
|
|
72
|
+
const entry = await super.recordCall(name, inputs, outputs, time);
|
|
73
|
+
const recording = this.currentRecording();
|
|
74
|
+
const state = recording && this.#fileState.get(recording);
|
|
75
|
+
if (state) {
|
|
76
|
+
try {
|
|
77
|
+
const prefix = state.isFirstCall ? ' ' : ' ,';
|
|
78
|
+
state.isFirstCall = false;
|
|
79
|
+
await fs.appendFile(state.filePath, prefix + JSON.stringify(entry) + '\n');
|
|
80
|
+
} catch (err) {
|
|
81
|
+
this.logger.error('Failed to log circuit call', {
|
|
82
|
+
error: err
|
|
83
|
+
});
|
|
84
|
+
}
|
|
80
85
|
}
|
|
81
86
|
return entry;
|
|
82
87
|
}
|
|
83
|
-
/**
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
// so we save the current file path before that
|
|
89
|
-
const filePath = this.recording.filePath;
|
|
90
|
-
const result = await super.finish();
|
|
88
|
+
/** Closes the recording file with the trailing brackets so the JSON parses. */ async onFinish(recording) {
|
|
89
|
+
const state = this.#fileState.get(recording);
|
|
90
|
+
if (!state) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
91
93
|
try {
|
|
92
|
-
await fs.appendFile(filePath, ' ]\n}\n');
|
|
94
|
+
await fs.appendFile(state.filePath, ' ]\n}\n');
|
|
93
95
|
} catch (err) {
|
|
94
96
|
this.logger.error('Failed to finalize recording file', {
|
|
95
97
|
error: err
|
|
96
98
|
});
|
|
97
99
|
}
|
|
98
|
-
return result;
|
|
99
100
|
}
|
|
100
|
-
/**
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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);
|
|
101
|
+
/** Closes the recording file with the execution error and trailing brackets so the JSON parses. */ async onError(recording, error) {
|
|
102
|
+
const state = this.#fileState.get(recording);
|
|
103
|
+
if (!state) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
109
106
|
try {
|
|
110
|
-
await fs.appendFile(filePath, ' ],\n');
|
|
111
|
-
await fs.appendFile(filePath, ` "error": ${JSON.stringify(error)}\n`);
|
|
112
|
-
await fs.appendFile(filePath, '}\n');
|
|
107
|
+
await fs.appendFile(state.filePath, ' ],\n');
|
|
108
|
+
await fs.appendFile(state.filePath, ` "error": ${JSON.stringify(error)}\n`);
|
|
109
|
+
await fs.appendFile(state.filePath, '}\n');
|
|
113
110
|
} catch (err) {
|
|
114
111
|
this.logger.error('Failed to finalize recording file with error', {
|
|
115
112
|
error: err
|
|
116
113
|
});
|
|
117
114
|
}
|
|
118
|
-
return result;
|
|
119
115
|
}
|
|
120
116
|
}
|
|
121
117
|
/**
|
|
@@ -18,4 +18,4 @@ export declare class SimulatorRecorderWrapper implements CircuitSimulator {
|
|
|
18
18
|
executeProtocolCircuit(input: ACVMWitness, artifact: NoirCompiledCircuitWithName, callback: ForeignCallHandler | undefined): Promise<ACVMSuccess>;
|
|
19
19
|
executeUserCircuit(input: ACVMWitness, artifact: FunctionArtifactWithContractName, callback: ACIRCallback): Promise<ACIRExecutionResult>;
|
|
20
20
|
}
|
|
21
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
21
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2ltdWxhdG9yX3JlY29yZGVyX3dyYXBwZXIuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9wcml2YXRlL2NpcmN1aXRfcmVjb3JkaW5nL3NpbXVsYXRvcl9yZWNvcmRlcl93cmFwcGVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxFQUFFLGtCQUFrQixFQUFFLE1BQU0scUJBQXFCLEN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apper.d.ts","sourceRoot":"","sources":["../../../src/private/circuit_recording/simulator_recorder_wrapper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,mBAAmB,CAAC;AAC1E,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AAEtE,OAAO,KAAK,EAAE,YAAY,EAAqB,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAC5F,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE7D;;;GAGG;AACH,qBAAa,wBAAyB,YAAW,gBAAgB;;IAE7D,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,QAAQ;IAFlB,YACU,SAAS,EAAE,gBAAgB,EAC3B,QAAQ,EAAE,eAAe,EAC/B;IAEJ,sBAAsB,CACpB,KAAK,EAAE,WAAW,EAClB,QAAQ,EAAE,2BAA2B,EACrC,QAAQ,EAAE,kBAAkB,GAAG,SAAS,GACvC,OAAO,CAAC,WAAW,CAAC,CAWtB;IAED,kBAAkB,CAChB,KAAK,EAAE,WAAW,EAClB,QAAQ,EAAE,gCAAgC,EAC1C,QAAQ,EAAE,YAAY,GACrB,OAAO,CAAC,mBAAmB,CAAC,CAS9B;
|
|
1
|
+
{"version":3,"file":"simulator_recorder_wrapper.d.ts","sourceRoot":"","sources":["../../../src/private/circuit_recording/simulator_recorder_wrapper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,KAAK,EAAE,gCAAgC,EAAE,MAAM,mBAAmB,CAAC;AAC1E,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AAEtE,OAAO,KAAK,EAAE,YAAY,EAAqB,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAC5F,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAE7D;;;GAGG;AACH,qBAAa,wBAAyB,YAAW,gBAAgB;;IAE7D,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,QAAQ;IAFlB,YACU,SAAS,EAAE,gBAAgB,EAC3B,QAAQ,EAAE,eAAe,EAC/B;IAEJ,sBAAsB,CACpB,KAAK,EAAE,WAAW,EAClB,QAAQ,EAAE,2BAA2B,EACrC,QAAQ,EAAE,kBAAkB,GAAG,SAAS,GACvC,OAAO,CAAC,WAAW,CAAC,CAWtB;IAED,kBAAkB,CAChB,KAAK,EAAE,WAAW,EAClB,QAAQ,EAAE,gCAAgC,EAC1C,QAAQ,EAAE,YAAY,GACrB,OAAO,CAAC,mBAAmB,CAAC,CAS9B;CAkCF"}
|
|
@@ -16,21 +16,18 @@
|
|
|
16
16
|
return this.#simulate((wrappedCallback)=>this.simulator.executeUserCircuit(input, artifact, wrappedCallback), input, artifact.bytecode, artifact.contractName, artifact.name, callback);
|
|
17
17
|
}
|
|
18
18
|
async #simulate(simulateFn, input, bytecode, contractName, functionName, callback) {
|
|
19
|
-
//
|
|
20
|
-
|
|
21
|
-
// If callback was provided, we wrap it in a circuit recorder callback wrapper
|
|
19
|
+
// If a callback was provided, we wrap it so that its oracle calls are recorded. The wrapped callback reads the
|
|
20
|
+
// active recording lazily, so it picks up the recording opened by record() below.
|
|
22
21
|
const wrappedCallback = this.recorder.wrapCallback(callback);
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const recording = await this.recorder.finish();
|
|
33
|
-
result.oracles = recording.oracleCalls?.reduce((acc, { time, name })=>{
|
|
22
|
+
// record() opens a recording for this circuit, runs the simulation within it, and finalizes it. A simulation
|
|
23
|
+
// failure is re-thrown unchanged, so recorder bookkeeping never masks the underlying error.
|
|
24
|
+
const { result, recording } = await this.recorder.record({
|
|
25
|
+
input,
|
|
26
|
+
bytecode,
|
|
27
|
+
circuitName: contractName,
|
|
28
|
+
functionName
|
|
29
|
+
}, ()=>simulateFn(wrappedCallback));
|
|
30
|
+
result.oracles = recording.oracleCalls.reduce((acc, { time, name })=>{
|
|
34
31
|
if (!acc[name]) {
|
|
35
32
|
acc[name] = {
|
|
36
33
|
times: []
|
|
@@ -107,7 +107,7 @@ import { createContractClassAndInstance } from './utils.js';
|
|
|
107
107
|
await this.contractDataSource.addContractInstance(contractInstance);
|
|
108
108
|
}
|
|
109
109
|
async insertContractAddressNullifier(contractAddress) {
|
|
110
|
-
const contractAddressNullifier = await siloNullifier(AztecAddress.
|
|
110
|
+
const contractAddressNullifier = await siloNullifier(AztecAddress.fromNumberUnsafe(CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS), contractAddress.toField());
|
|
111
111
|
await this.merkleTrees.sequentialInsert(MerkleTreeId.NULLIFIER_TREE, [
|
|
112
112
|
contractAddressNullifier.toBuffer()
|
|
113
113
|
]);
|
|
@@ -90,7 +90,7 @@ export function resolveContractAssertionMessage(functionName, revertReason, outp
|
|
|
90
90
|
immutablesHash,
|
|
91
91
|
publicKeys
|
|
92
92
|
});
|
|
93
|
-
const contractAddressNullifier = await siloNullifier(AztecAddress.
|
|
93
|
+
const contractAddressNullifier = await siloNullifier(AztecAddress.fromNumberUnsafe(CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS), contractInstance.address.toField());
|
|
94
94
|
return {
|
|
95
95
|
contractClass,
|
|
96
96
|
contractInstance,
|
|
@@ -11,8 +11,8 @@ const INITIAL_TOKEN_BALANCE = 1_000_000_000n;
|
|
|
11
11
|
* You do NOT need permission to remove this test!
|
|
12
12
|
*/ export async function ammTest(tester, logger, tokenArtifact, ammArtifact, expectToBeTrue) {
|
|
13
13
|
const timer = new Timer();
|
|
14
|
-
const admin = AztecAddress.
|
|
15
|
-
const sender = AztecAddress.
|
|
14
|
+
const admin = AztecAddress.fromNumberUnsafe(42);
|
|
15
|
+
const sender = AztecAddress.fromNumberUnsafe(111);
|
|
16
16
|
logger.debug(`Deploying tokens`);
|
|
17
17
|
const token0 = await setUpToken(tester, tokenArtifact, admin, expectToBeTrue, /*seed=*/ 0);
|
|
18
18
|
const token1 = await setUpToken(tester, tokenArtifact, admin, expectToBeTrue, /*seed=*/ 1);
|
|
@@ -3,7 +3,7 @@ import { Timer } from '@aztec/foundation/timer';
|
|
|
3
3
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
4
|
export async function bulkTest(tester, logger, avmTestContractArtifact) {
|
|
5
5
|
const timer = new Timer();
|
|
6
|
-
const deployer = AztecAddress.
|
|
6
|
+
const deployer = AztecAddress.fromNumberUnsafe(42);
|
|
7
7
|
const avmTestContract = await tester.registerAndDeployContract(/*constructorArgs=*/ [], deployer, avmTestContractArtifact);
|
|
8
8
|
// Needed since we invoke the Fee Juice Contract in the bulk test.registerFeeJuiceContract
|
|
9
9
|
await tester.registerFeeJuiceContract();
|
|
@@ -136,7 +136,7 @@ export async function bulkTest(tester, logger, avmTestContractArtifact) {
|
|
|
136
136
|
}
|
|
137
137
|
export async function megaBulkTest(tester, logger, avmTestContractArtifact) {
|
|
138
138
|
const timer = new Timer();
|
|
139
|
-
const deployer = AztecAddress.
|
|
139
|
+
const deployer = AztecAddress.fromNumberUnsafe(42);
|
|
140
140
|
const avmTestContract = await tester.registerAndDeployContract(/*constructorArgs=*/ [], deployer, avmTestContractArtifact);
|
|
141
141
|
// Needed since we invoke the Fee Juice Contract in the bulk test.registerFeeJuiceContract
|
|
142
142
|
await tester.registerFeeJuiceContract();
|