@aztec/simulator 6.0.0-nightly.20260810 → 6.0.0-nightly.20260821
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/public/avm_simulator_pool.d.ts +43 -4
- package/dest/public/avm_simulator_pool.d.ts.map +1 -1
- package/dest/public/avm_simulator_pool.js +171 -57
- package/dest/public/executor_metrics.d.ts +2 -2
- package/dest/public/executor_metrics.d.ts.map +1 -1
- package/dest/public/executor_metrics.js +1 -1
- package/dest/public/executor_metrics_interface.d.ts +2 -2
- package/dest/public/executor_metrics_interface.d.ts.map +1 -1
- package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts +2 -4
- package/dest/public/fuzzing/avm_fuzzer_simulator.d.ts.map +1 -1
- package/dest/public/fuzzing/avm_fuzzer_simulator.js +2 -6
- package/dest/public/fuzzing/avm_simulator_bin.js +11 -21
- package/dest/public/public_tx_simulator/public_tx_simulator.js +1 -1
- package/dest/public/test_executor_metrics.d.ts +2 -2
- package/dest/public/test_executor_metrics.d.ts.map +1 -1
- package/dest/public/test_executor_metrics.js +3 -5
- package/package.json +18 -18
- package/src/public/avm_simulator_pool.ts +195 -67
- package/src/public/executor_metrics.ts +6 -1
- package/src/public/executor_metrics_interface.ts +6 -1
- package/src/public/fuzzing/avm_fuzzer_simulator.ts +0 -4
- package/src/public/fuzzing/avm_simulator_bin.ts +9 -25
- package/src/public/public_tx_simulator/public_tx_simulator.ts +1 -1
- package/src/public/test_executor_metrics.ts +8 -5
|
@@ -8,13 +8,47 @@ export interface AvmSimulatorPoolOptions {
|
|
|
8
8
|
wsdbIpcPath: string;
|
|
9
9
|
/** Optional logger function for AVM process output. */
|
|
10
10
|
logger?: (msg: string) => void;
|
|
11
|
+
/**
|
|
12
|
+
* Flat delay between environmental spawn failures (default 1s). No backoff: sequencers live on
|
|
13
|
+
* ~6s slots, so sleeping longer than this after a failure costs whole blocks while the machine may
|
|
14
|
+
* have recovered — and a spawn attempt is cheap. Spawning never gives up on its own; the caller's
|
|
15
|
+
* deadline (abort signal) is the bound.
|
|
16
|
+
*/
|
|
17
|
+
spawnRetryIntervalMs?: number;
|
|
18
|
+
/** Process spawner override. Test hook; defaults to spawning a real bb-avm-sim via the generated AvmService. */
|
|
19
|
+
spawnProcess?: (options: AvmProcessSpawnOptions) => Promise<AvmProcessHandle>;
|
|
20
|
+
}
|
|
21
|
+
/** Options handed to the process spawner for each new pool slot. */
|
|
22
|
+
export interface AvmProcessSpawnOptions {
|
|
23
|
+
binaryPath?: string;
|
|
24
|
+
wsdbIpcPath: string;
|
|
25
|
+
cdbIpcPath: string;
|
|
26
|
+
logger?: (msg: string) => void;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* A handle to a single bb-avm-sim service: it runs serialized simulations and connects back to the
|
|
30
|
+
* shared CDB/WSDB servers for state, but is unaware of which fork's contract data it is reading — that is
|
|
31
|
+
* routed by the fork id baked into the input buffer. The underlying service owns its process lifecycle
|
|
32
|
+
* (including respawn-on-death), so a handle stays usable for the life of the pool.
|
|
33
|
+
*/
|
|
34
|
+
export interface AvmProcessHandle {
|
|
35
|
+
simulate(inputBuffer: Uint8Array, signal?: AbortSignal): Promise<Uint8Array>;
|
|
36
|
+
simulateWithHints(inputBuffer: Uint8Array): Promise<Uint8Array>;
|
|
37
|
+
destroy(): Promise<void>;
|
|
11
38
|
}
|
|
12
39
|
/**
|
|
13
|
-
* The public-execution AVM backend: a lazily-grown pool of bb-avm-sim
|
|
40
|
+
* The public-execution AVM backend: a lazily-grown pool of bb-avm-sim services plus the CDB server that
|
|
14
41
|
* answers those processes' contract-data callbacks. Callers hold this as an {@link AvmSimulator}; the pool,
|
|
15
42
|
* the CDB server, its IPC path, and fork-id routing are all hidden behind that interface. Each `simulate`
|
|
16
43
|
* registers the call's contracts DB on the CDB server for the duration of the simulation (keyed by fork id
|
|
17
44
|
* so concurrent simulations on different forks don't collide) and unregisters it once the call returns.
|
|
45
|
+
*
|
|
46
|
+
* Process lifecycle is invisible to callers, exactly as when the simulator ran in-process: a simulation
|
|
47
|
+
* either produces a result, fails on its own merits, or runs until the caller's deadline aborts it.
|
|
48
|
+
* Environmental trouble is absorbed here — spawn failures retry indefinitely on a backoff ladder (bounded
|
|
49
|
+
* only by the caller's abort signal), and a simulation whose process dies is re-issued on the respawned
|
|
50
|
+
* process. The one deliberate exception: an input that kills the process twice is treated as a failing
|
|
51
|
+
* transaction, so a simulator-crashing tx gets evicted instead of burning a process per block forever.
|
|
18
52
|
*/
|
|
19
53
|
export declare class AvmSimulatorPool implements AvmSimulator {
|
|
20
54
|
private options;
|
|
@@ -22,24 +56,29 @@ export declare class AvmSimulatorPool implements AvmSimulator {
|
|
|
22
56
|
private available;
|
|
23
57
|
private waiters;
|
|
24
58
|
private createdCount;
|
|
59
|
+
private destroyed;
|
|
25
60
|
private log;
|
|
26
61
|
private maxSize;
|
|
27
62
|
private cdbServer;
|
|
63
|
+
private readonly spawnRetryIntervalMs;
|
|
64
|
+
private readonly spawnProcess;
|
|
28
65
|
constructor(options: AvmSimulatorPoolOptions);
|
|
29
66
|
static spawn(options: AvmSimulatorPoolOptions): Promise<AvmSimulatorPool>;
|
|
30
67
|
[Symbol.asyncDispose](): Promise<void>;
|
|
31
68
|
simulate(inputBuffer: Uint8Array, context: AvmContractsDBContext, signal?: AbortSignal): Promise<Uint8Array>;
|
|
32
69
|
simulateWithHints(inputBuffer: Uint8Array): Promise<Uint8Array>;
|
|
33
|
-
/** Destroy all AVM
|
|
70
|
+
/** Destroy all AVM services in the pool and close the CDB server. */
|
|
34
71
|
destroy(): Promise<void>;
|
|
35
72
|
/**
|
|
36
73
|
* Eagerly spawn up to `count` AVM processes (capped at maxSize) and leave them available, so the
|
|
37
74
|
* first simulate() doesn't pay process spawn/connect cost. Idempotent.
|
|
38
75
|
*/
|
|
39
76
|
prewarm(count?: number): Promise<void>;
|
|
77
|
+
private runOnPool;
|
|
40
78
|
private checkout;
|
|
41
|
-
/** Return an AVM
|
|
79
|
+
/** Return an AVM service to the pool after use. */
|
|
42
80
|
private return;
|
|
43
81
|
private createSlot;
|
|
82
|
+
private spawnUntilUp;
|
|
44
83
|
}
|
|
45
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
84
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXZtX3NpbXVsYXRvcl9wb29sLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvcHVibGljL2F2bV9zaW11bGF0b3JfcG9vbC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFLQSxPQUFPLEtBQUssRUFBRSxxQkFBcUIsRUFBRSxZQUFZLEVBQUUsTUFBTSxvQkFBb0IsQ0FBQztBQUc5RSxNQUFNLFdBQVcsdUJBQXVCO0lBQ3RDLHVIQUF1SDtJQUN2SCxPQUFPLENBQUMsRUFBRSxNQUFNLENBQUM7SUFDakIsb0ZBQW9GO0lBQ3BGLGFBQWEsQ0FBQyxFQUFFLE1BQU0sQ0FBQztJQUN2QiwyQ0FBMkM7SUFDM0MsV0FBVyxFQUFFLE1BQU0sQ0FBQztJQUNwQix1REFBdUQ7SUFDdkQsTUFBTSxDQUFDLEVBQUUsQ0FBQyxHQUFHLEVBQUUsTUFBTSxLQUFLLElBQUksQ0FBQztJQUMvQjs7Ozs7T0FLRztJQUNILG9CQUFvQixDQUFDLEVBQUUsTUFBTSxDQUFDO0lBQzlCLGdIQUFnSDtJQUNoSCxZQUFZLENBQUMsRUFBRSxDQUFDLE9BQU8sRUFBRSxzQkFBc0IsS0FBSyxPQUFPLENBQUMsZ0JBQWdCLENBQUMsQ0FBQztDQUMvRTtBQUVELG9FQUFvRTtBQUNwRSxNQUFNLFdBQVcsc0JBQXNCO0lBQ3JDLFVBQVUsQ0FBQyxFQUFFLE1BQU0sQ0FBQztJQUNwQixXQUFXLEVBQUUsTUFBTSxDQUFDO0lBQ3BCLFVBQVUsRUFBRSxN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BQyxNQUFNLENBQUMsWUFBWSxDQUFDLElBQUksT0FBTyxDQUFDLElBQUksQ0FBQyxDQUUzQztJQUVLLFFBQVEsQ0FBQyxXQUFXLEVBQUUsVUFBVSxFQUFFLE9BQU8sRUFBRSxxQkFBcUIsRUFBRSxNQUFNLENBQUMsRUFBRSxXQUFXLEdBQUcsT0FBTyxDQUFDLFVBQVUsQ0FBQyxDQVNqSDtJQUVLLGlCQUFpQixDQUFDLFdBQVcsRUFBRSxVQUFVLEdBQUcsT0FBTyxDQUFDLFVBQVUsQ0FBQyxDQUdwRTtJQUVELHFFQUFxRTtJQUMvRCxPQUFPLElBQUksT0FBTyxDQUFDLElBQUksQ0FBQyxDQWE3QjtJQUVEOzs7T0FHRztJQUNHLE9BQU8sQ0FBQyxLQUFLLFNBQUksR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLENBVXRDO1lBUWEsU0FBUztZQXdCVCxRQUFRO0lBcUN0QixtREFBbUQ7SUFDbkQsT0FBTyxDQUFDLE1BQU07WUFZQSxVQUFVO1lBeUJWLFlBQVk7Q0EyQjNCIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"avm_simulator_pool.d.ts","sourceRoot":"","sources":["../../src/public/avm_simulator_pool.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"avm_simulator_pool.d.ts","sourceRoot":"","sources":["../../src/public/avm_simulator_pool.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAG9E,MAAM,WAAW,uBAAuB;IACtC,uHAAuH;IACvH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,oFAAoF;IACpF,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,2CAA2C;IAC3C,WAAW,EAAE,MAAM,CAAC;IACpB,uDAAuD;IACvD,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/B;;;;;O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AO,CAAC,IAAI,CAAC,CAE3C;IAEK,QAAQ,CAAC,WAAW,EAAE,UAAU,EAAE,OAAO,EAAE,qBAAqB,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,CASjH;IAEK,iBAAiB,CAAC,WAAW,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,CAGpE;IAED,qEAAqE;IAC/D,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAa7B;IAED;;;OAGG;IACG,OAAO,CAAC,KAAK,SAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAUtC;YAQa,SAAS;YAwBT,QAAQ;IAqCtB,mDAAmD;IACnD,OAAO,CAAC,MAAM;YAYA,UAAU;YAyBV,YAAY;CA2B3B"}
|
|
@@ -1,36 +1,83 @@
|
|
|
1
1
|
var _computedKey;
|
|
2
2
|
import { AvmService } from '@aztec/bb-avm-sim';
|
|
3
|
+
import { AbortError } from '@aztec/foundation/error';
|
|
3
4
|
import { createLogger } from '@aztec/foundation/log';
|
|
5
|
+
import { sleep } from '@aztec/foundation/sleep';
|
|
4
6
|
import { CdbIpcServer } from './cdb_ipc_server.js';
|
|
7
|
+
/**
|
|
8
|
+
* The generated service flags errors caused by the death of the underlying process (rather than by the
|
|
9
|
+
* request itself) with `retry: true`. That distinction is interpreted here and goes no further: process
|
|
10
|
+
* lifecycle is invisible to the pool's callers.
|
|
11
|
+
*/ function isProcessFailure(err) {
|
|
12
|
+
return err instanceof Error && err.retry === true;
|
|
13
|
+
}
|
|
14
|
+
/** Sleep that wakes early (without throwing) when the signal aborts; callers re-check the signal. */ async function abortableSleep(ms, signal) {
|
|
15
|
+
if (!signal) {
|
|
16
|
+
return sleep(ms);
|
|
17
|
+
}
|
|
18
|
+
let onAbort;
|
|
19
|
+
const aborted = new Promise((resolve)=>{
|
|
20
|
+
onAbort = resolve;
|
|
21
|
+
signal.addEventListener('abort', onAbort, {
|
|
22
|
+
once: true
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
try {
|
|
26
|
+
await Promise.race([
|
|
27
|
+
sleep(ms),
|
|
28
|
+
aborted
|
|
29
|
+
]);
|
|
30
|
+
} finally{
|
|
31
|
+
signal.removeEventListener('abort', onAbort);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
// After a cancellation is requested, how long the C++ process gets to cancel cooperatively (SIGUSR1
|
|
35
|
+
// checkpoint) before it is SIGKILLed. Killing is safe: the service respawns its process lazily, so the
|
|
36
|
+
// pool slot recovers instead of being leaked to a wedged simulation.
|
|
37
|
+
const CANCEL_KILL_GRACE_MS = 5_000;
|
|
5
38
|
_computedKey = Symbol.asyncDispose;
|
|
6
39
|
/**
|
|
7
|
-
* The public-execution AVM backend: a lazily-grown pool of bb-avm-sim
|
|
40
|
+
* The public-execution AVM backend: a lazily-grown pool of bb-avm-sim services plus the CDB server that
|
|
8
41
|
* answers those processes' contract-data callbacks. Callers hold this as an {@link AvmSimulator}; the pool,
|
|
9
42
|
* the CDB server, its IPC path, and fork-id routing are all hidden behind that interface. Each `simulate`
|
|
10
43
|
* registers the call's contracts DB on the CDB server for the duration of the simulation (keyed by fork id
|
|
11
44
|
* so concurrent simulations on different forks don't collide) and unregisters it once the call returns.
|
|
45
|
+
*
|
|
46
|
+
* Process lifecycle is invisible to callers, exactly as when the simulator ran in-process: a simulation
|
|
47
|
+
* either produces a result, fails on its own merits, or runs until the caller's deadline aborts it.
|
|
48
|
+
* Environmental trouble is absorbed here — spawn failures retry indefinitely on a backoff ladder (bounded
|
|
49
|
+
* only by the caller's abort signal), and a simulation whose process dies is re-issued on the respawned
|
|
50
|
+
* process. The one deliberate exception: an input that kills the process twice is treated as a failing
|
|
51
|
+
* transaction, so a simulator-crashing tx gets evicted instead of burning a process per block forever.
|
|
12
52
|
*/ export class AvmSimulatorPool {
|
|
13
53
|
options;
|
|
14
54
|
slots;
|
|
15
55
|
available;
|
|
16
56
|
waiters;
|
|
17
57
|
createdCount;
|
|
58
|
+
destroyed;
|
|
18
59
|
log;
|
|
19
60
|
maxSize;
|
|
20
61
|
cdbServer;
|
|
62
|
+
spawnRetryIntervalMs;
|
|
63
|
+
spawnProcess;
|
|
21
64
|
constructor(options){
|
|
22
65
|
this.options = options;
|
|
23
66
|
this.slots = [];
|
|
24
67
|
this.available = [];
|
|
25
68
|
this.waiters = [];
|
|
26
69
|
this.createdCount = 0;
|
|
70
|
+
this.destroyed = false;
|
|
27
71
|
this.log = createLogger('simulator:avm-pool');
|
|
28
72
|
this.maxSize = options.maxSize ?? parseInt(process.env.AVM_MAX_CONCURRENT_SIMULATIONS ?? '4', 10);
|
|
29
73
|
this.cdbServer = new CdbIpcServer();
|
|
74
|
+
this.spawnRetryIntervalMs = options.spawnRetryIntervalMs ?? 1_000;
|
|
75
|
+
this.spawnProcess = options.spawnProcess ?? ((spawnOptions)=>AvmSimulatorProcess.spawn(spawnOptions));
|
|
30
76
|
}
|
|
31
77
|
static async spawn(options) {
|
|
32
78
|
const pool = new AvmSimulatorPool(options);
|
|
33
79
|
// Always start one process up front so the first simulate() doesn't pay process spawn/connect cost.
|
|
80
|
+
// This is also where configuration errors (missing binary) surface, fast and fatally.
|
|
34
81
|
await pool.prewarm();
|
|
35
82
|
return pool;
|
|
36
83
|
}
|
|
@@ -42,37 +89,21 @@ _computedKey = Symbol.asyncDispose;
|
|
|
42
89
|
// and unregister once the simulation returns — registration is only needed while the call is running.
|
|
43
90
|
this.cdbServer.registerFork(context.forkId, context.contractsDB, context.timestamp);
|
|
44
91
|
try {
|
|
45
|
-
|
|
46
|
-
try {
|
|
47
|
-
return await simulator.simulate(inputBuffer, signal);
|
|
48
|
-
} finally{
|
|
49
|
-
this.return(simulator);
|
|
50
|
-
}
|
|
92
|
+
return await this.runOnPool((simulator)=>simulator.simulate(inputBuffer, signal), signal);
|
|
51
93
|
} finally{
|
|
52
94
|
this.cdbServer.unregisterFork(context.forkId);
|
|
53
95
|
}
|
|
54
96
|
}
|
|
55
97
|
async simulateWithHints(inputBuffer) {
|
|
56
98
|
// The hinted path makes no contract-data callbacks, so no CDB registration is needed.
|
|
57
|
-
|
|
58
|
-
try {
|
|
59
|
-
return await simulator.simulateWithHints(inputBuffer);
|
|
60
|
-
} finally{
|
|
61
|
-
this.return(simulator);
|
|
62
|
-
}
|
|
99
|
+
return await this.runOnPool((simulator)=>simulator.simulateWithHints(inputBuffer));
|
|
63
100
|
}
|
|
64
|
-
/** Destroy all AVM
|
|
65
|
-
|
|
101
|
+
/** Destroy all AVM services in the pool and close the CDB server. */ async destroy() {
|
|
102
|
+
this.destroyed = true;
|
|
103
|
+
for (const waiter of this.waiters.splice(0)){
|
|
66
104
|
waiter.reject(new Error('AVM simulator pool destroyed'));
|
|
67
105
|
}
|
|
68
|
-
this.
|
|
69
|
-
const destroyPromises = [];
|
|
70
|
-
for (const slot of this.slots){
|
|
71
|
-
if (slot) {
|
|
72
|
-
destroyPromises.push(slot.destroy());
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
await Promise.all(destroyPromises);
|
|
106
|
+
await Promise.all(this.slots.map((slot)=>slot.destroy()));
|
|
76
107
|
this.slots = [];
|
|
77
108
|
this.available = [];
|
|
78
109
|
this.createdCount = 0;
|
|
@@ -86,29 +117,81 @@ _computedKey = Symbol.asyncDispose;
|
|
|
86
117
|
const target = Math.min(count, this.maxSize);
|
|
87
118
|
const created = [];
|
|
88
119
|
while(this.createdCount < target){
|
|
89
|
-
created.push(await this.
|
|
120
|
+
created.push(await this.checkout());
|
|
90
121
|
}
|
|
91
|
-
// Hand the
|
|
122
|
+
// Hand the checked-out processes back to the pool so checkout() reuses them.
|
|
92
123
|
for (const simulator of created){
|
|
93
124
|
this.return(simulator);
|
|
94
125
|
}
|
|
95
126
|
}
|
|
96
|
-
/**
|
|
127
|
+
/**
|
|
128
|
+
* Run a call on a pooled service. A call that fails because its process died is re-issued on the
|
|
129
|
+
* respawned process; a second death for the same input is attributed to the input and surfaces as an
|
|
130
|
+
* ordinary error (the pre-IPC equivalent — a native crash — took down the whole node, so a failed tx
|
|
131
|
+
* is strictly gentler). Non-process failures surface as-is: they are the simulation's own verdict.
|
|
132
|
+
*/ async runOnPool(fn, signal) {
|
|
133
|
+
for(let attempt = 0;; attempt++){
|
|
134
|
+
const simulator = await this.checkout(signal);
|
|
135
|
+
try {
|
|
136
|
+
return await fn(simulator);
|
|
137
|
+
} catch (err) {
|
|
138
|
+
if (!isProcessFailure(err) || signal?.aborted) {
|
|
139
|
+
throw err;
|
|
140
|
+
}
|
|
141
|
+
if (attempt > 0) {
|
|
142
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
143
|
+
throw new Error(`AVM simulator process died twice running this simulation; attributing the failure to the input: ${message}`, {
|
|
144
|
+
cause: err
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
this.log.warn(`AVM process died during simulation; re-issuing once on the respawned process`, {
|
|
148
|
+
err
|
|
149
|
+
});
|
|
150
|
+
} finally{
|
|
151
|
+
this.return(simulator);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
/** Check out an AVM service from the pool, blocking until one is free. Caller must return() it when done. */ async checkout(signal) {
|
|
156
|
+
if (this.destroyed) {
|
|
157
|
+
throw new Error('AVM simulator pool destroyed');
|
|
158
|
+
}
|
|
97
159
|
const idx = this.available.pop();
|
|
98
|
-
if (idx !== undefined
|
|
160
|
+
if (idx !== undefined) {
|
|
99
161
|
return this.slots[idx];
|
|
100
162
|
}
|
|
101
|
-
if (this.createdCount < this.maxSize
|
|
102
|
-
return await this.createSlot(
|
|
163
|
+
if (this.createdCount < this.maxSize) {
|
|
164
|
+
return await this.createSlot(signal);
|
|
103
165
|
}
|
|
104
166
|
return new Promise((resolve, reject)=>{
|
|
105
|
-
|
|
167
|
+
const waiter = {
|
|
106
168
|
resolve,
|
|
107
169
|
reject
|
|
108
|
-
}
|
|
170
|
+
};
|
|
171
|
+
if (signal) {
|
|
172
|
+
const onAbort = ()=>{
|
|
173
|
+
const at = this.waiters.indexOf(waiter);
|
|
174
|
+
if (at >= 0) {
|
|
175
|
+
this.waiters.splice(at, 1);
|
|
176
|
+
reject(new AbortError('AVM checkout aborted'));
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
signal.addEventListener('abort', onAbort, {
|
|
180
|
+
once: true
|
|
181
|
+
});
|
|
182
|
+
waiter.resolve = (simulator)=>{
|
|
183
|
+
signal.removeEventListener('abort', onAbort);
|
|
184
|
+
resolve(simulator);
|
|
185
|
+
};
|
|
186
|
+
waiter.reject = (err)=>{
|
|
187
|
+
signal.removeEventListener('abort', onAbort);
|
|
188
|
+
reject(err);
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
this.waiters.push(waiter);
|
|
109
192
|
});
|
|
110
193
|
}
|
|
111
|
-
/** Return an AVM
|
|
194
|
+
/** Return an AVM service to the pool after use. */ return(simulator) {
|
|
112
195
|
const waiter = this.waiters.shift();
|
|
113
196
|
if (waiter) {
|
|
114
197
|
waiter.resolve(simulator);
|
|
@@ -119,35 +202,54 @@ _computedKey = Symbol.asyncDispose;
|
|
|
119
202
|
}
|
|
120
203
|
}
|
|
121
204
|
}
|
|
122
|
-
async createSlot(
|
|
123
|
-
const reuse = reuseIdx !== undefined && reuseIdx < this.slots.length;
|
|
205
|
+
async createSlot(signal) {
|
|
124
206
|
// Reserve the slot count synchronously, before the async spawn, so concurrent checkouts can't all
|
|
125
207
|
// observe `createdCount < maxSize` and overshoot the pool (the count is only bumped once control has
|
|
126
|
-
// yielded on the await). Roll back the reservation if the spawn
|
|
127
|
-
|
|
128
|
-
this.createdCount++;
|
|
129
|
-
}
|
|
130
|
-
let simulator;
|
|
208
|
+
// yielded on the await). Roll back the reservation if the spawn is abandoned.
|
|
209
|
+
this.createdCount++;
|
|
131
210
|
try {
|
|
132
|
-
simulator = await
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
logger: this.options.logger
|
|
137
|
-
});
|
|
211
|
+
const simulator = await this.spawnUntilUp(signal);
|
|
212
|
+
this.slots.push(simulator);
|
|
213
|
+
this.log.debug(`Created AVM pool slot (${this.createdCount}/${this.maxSize})`);
|
|
214
|
+
return simulator;
|
|
138
215
|
} catch (err) {
|
|
139
|
-
|
|
140
|
-
this.createdCount--;
|
|
141
|
-
}
|
|
216
|
+
this.createdCount--;
|
|
142
217
|
throw err;
|
|
143
218
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Spawn a service, retrying environmental failures on a flat cadence indefinitely — the bound is
|
|
222
|
+
* the caller's own deadline (abort signal), matching the pre-IPC contract where a simulation either
|
|
223
|
+
* completed or was deadlined out. The cadence is deliberately fast and constant: an attempt is cheap,
|
|
224
|
+
* a slow one self-paces inside the backend's connect backstop, and backing off would cost a
|
|
225
|
+
* ~6s-slot sequencer whole blocks after the machine has already recovered. Configuration errors
|
|
226
|
+
* (missing binary, flagged non-retryable by the generated service) throw immediately; the boot-time
|
|
227
|
+
* prewarm is where those are meant to surface.
|
|
228
|
+
*/ async spawnUntilUp(signal) {
|
|
229
|
+
for(let failures = 0;; failures++){
|
|
230
|
+
if (this.destroyed) {
|
|
231
|
+
throw new Error('AVM simulator pool destroyed');
|
|
232
|
+
}
|
|
233
|
+
if (signal?.aborted) {
|
|
234
|
+
throw new AbortError('AVM process spawn aborted');
|
|
235
|
+
}
|
|
236
|
+
try {
|
|
237
|
+
return await this.spawnProcess({
|
|
238
|
+
binaryPath: this.options.avmBinaryPath,
|
|
239
|
+
wsdbIpcPath: this.options.wsdbIpcPath,
|
|
240
|
+
cdbIpcPath: this.cdbServer.ipcPath,
|
|
241
|
+
logger: this.options.logger
|
|
242
|
+
});
|
|
243
|
+
} catch (err) {
|
|
244
|
+
if (!isProcessFailure(err)) {
|
|
245
|
+
throw err;
|
|
246
|
+
}
|
|
247
|
+
this.log.warn(`Failed to spawn AVM process (attempt ${failures + 1}); retrying in ${this.spawnRetryIntervalMs}ms`, {
|
|
248
|
+
err
|
|
249
|
+
});
|
|
250
|
+
await abortableSleep(this.spawnRetryIntervalMs, signal);
|
|
251
|
+
}
|
|
148
252
|
}
|
|
149
|
-
this.log.debug(`Created AVM pool slot (${this.createdCount}/${this.maxSize})`);
|
|
150
|
-
return simulator;
|
|
151
253
|
}
|
|
152
254
|
}
|
|
153
255
|
class AvmSimulatorProcess {
|
|
@@ -165,13 +267,22 @@ class AvmSimulatorProcess {
|
|
|
165
267
|
options.wsdbIpcPath,
|
|
166
268
|
'--cdb',
|
|
167
269
|
options.cdbIpcPath
|
|
168
|
-
]
|
|
270
|
+
],
|
|
271
|
+
// Each simulation is self-contained (state comes from the WSDB/CDB servers, routed by fork id),
|
|
272
|
+
// so a fresh process can safely serve the next call after a death.
|
|
273
|
+
respawn: true
|
|
169
274
|
});
|
|
170
275
|
return new AvmSimulatorProcess(service);
|
|
171
276
|
}
|
|
172
277
|
async simulate(inputBuffer, signal) {
|
|
173
|
-
|
|
174
|
-
|
|
278
|
+
let killTimer;
|
|
279
|
+
// Cooperative cancellation first: SIGUSR1 makes the C++ process stop at its next cancellation
|
|
280
|
+
// checkpoint. If it doesn't respond within the grace (wedged in a slow op), SIGKILL it — the
|
|
281
|
+
// service respawns lazily, so this reclaims the pool slot rather than leaking it.
|
|
282
|
+
const onAbort = ()=>{
|
|
283
|
+
this.service.sendProcessSignal('SIGUSR1');
|
|
284
|
+
killTimer = setTimeout(()=>this.service.sendProcessSignal('SIGKILL'), CANCEL_KILL_GRACE_MS);
|
|
285
|
+
};
|
|
175
286
|
if (signal?.aborted) {
|
|
176
287
|
onAbort();
|
|
177
288
|
}
|
|
@@ -184,6 +295,9 @@ class AvmSimulatorProcess {
|
|
|
184
295
|
})).result;
|
|
185
296
|
} finally{
|
|
186
297
|
signal?.removeEventListener('abort', onAbort);
|
|
298
|
+
if (killTimer !== undefined) {
|
|
299
|
+
clearTimeout(killTimer);
|
|
300
|
+
}
|
|
187
301
|
}
|
|
188
302
|
}
|
|
189
303
|
async simulateWithHints(inputBuffer) {
|
|
@@ -13,9 +13,9 @@ export declare class ExecutorMetrics implements ExecutorMetricsInterface {
|
|
|
13
13
|
private privateEffectsInsertions;
|
|
14
14
|
constructor(client: TelemetryClient, name?: string);
|
|
15
15
|
startRecordingTxSimulation(_txLabel: string): void;
|
|
16
|
-
stopRecordingTxSimulation(_txLabel: string, _gasUsed?: GasUsed, _revertedCode?: RevertCode): void;
|
|
16
|
+
stopRecordingTxSimulation(_txLabel: string, _gasUsed?: GasUsed, _revertedCode?: RevertCode, _stats?: Record<string, string>): void;
|
|
17
17
|
recordEnqueuedCallSimulation(fnName: string, durationMs: number, manaUsed: number, totalInstructionsExecuted: number): void;
|
|
18
18
|
recordEnqueuedCallSimulationFailure(_fnName: string, _durationMs: number, _manaUsed: number, _totalInstructionsExecuted: number): void;
|
|
19
19
|
recordPrivateEffectsInsertion(durationUs: number, type: 'revertible' | 'non-revertible'): void;
|
|
20
20
|
}
|
|
21
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
21
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXhlY3V0b3JfbWV0cmljcy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3B1YmxpYy9leGVjdXRvcl9tZXRyaWNzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxFQUFFLFVBQVUsRUFBRSxNQUFNLG1CQUFtQixDQUFDO0FBQ3BELE9BQU8sS0FBSyxFQUFFLE9BQU8sRUFBRSxNQUFNLG1CQUFtQixDQUFDO0FBQ2pELE9BQU8sRUFJTCxLQUFLLGVBQWUsRUFDcEIsS0FBSyxNQUFNLEVBR1osTUFBTSx5QkFBeUIsQ0FBQztBQUVqQyxPQUFPLEtBQUssRUFBRSx3QkFBd0IsRUFBRSxNQUFNLGlDQUFpQyxDQUFDO0FBRWhGLHFCQ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"version":3,"file":"executor_metrics.d.ts","sourceRoot":"","sources":["../../src/public/executor_metrics.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAIL,KAAK,eAAe,EACpB,KAAK,MAAM,EAGZ,MAAM,yBAAyB,CAAC;AAEjC,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAEhF,qBAAa,eAAgB,YAAW,wBAAwB;IAC9D,SAAgB,MAAM,EAAE,MAAM,CAAC;IAC/B,OAAO,CAAC,OAAO,CAAgB;IAC/B,OAAO,CAAC,UAAU,CAAY;IAC9B,OAAO,CAAC,aAAa,CAAY;IACjC,OAAO,CAAC,QAAQ,CAAY;IAC5B,OAAO,CAAC,yBAAyB,CAAY;IAC7C,OAAO,CAAC,SAAS,CAAY;IAC7B,OAAO,CAAC,wBAAwB,CAAY;IAE5C,YAAY,MAAM,EAAE,eAAe,EAAE,IAAI,SAAmB,EAmB3D;IAED,0BAA0B,CAAC,QAAQ,EAAE,MAAM,QAE1C;IAED,yBAAyB,
|
|
1
|
+
{"version":3,"file":"executor_metrics.d.ts","sourceRoot":"","sources":["../../src/public/executor_metrics.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAIL,KAAK,eAAe,EACpB,KAAK,MAAM,EAGZ,MAAM,yBAAyB,CAAC;AAEjC,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAEhF,qBAAa,eAAgB,YAAW,wBAAwB;IAC9D,SAAgB,MAAM,EAAE,MAAM,CAAC;IAC/B,OAAO,CAAC,OAAO,CAAgB;IAC/B,OAAO,CAAC,UAAU,CAAY;IAC9B,OAAO,CAAC,aAAa,CAAY;IACjC,OAAO,CAAC,QAAQ,CAAY;IAC5B,OAAO,CAAC,yBAAyB,CAAY;IAC7C,OAAO,CAAC,SAAS,CAAY;IAC7B,OAAO,CAAC,wBAAwB,CAAY;IAE5C,YAAY,MAAM,EAAE,eAAe,EAAE,IAAI,SAAmB,EAmB3D;IAED,0BAA0B,CAAC,QAAQ,EAAE,MAAM,QAE1C;IAED,yBAAyB,CACvB,QAAQ,EAAE,MAAM,EAChB,QAAQ,CAAC,EAAE,OAAO,EAClB,aAAa,CAAC,EAAE,UAAU,EAC1B,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,QAGhC;IAED,4BAA4B,CAC1B,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,yBAAyB,EAAE,MAAM,QAqBlC;IAED,mCAAmC,CACjC,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EACjB,0BAA0B,EAAE,MAAM,QAKnC;IAED,6BAA6B,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,GAAG,gBAAgB,QAItF;CACF"}
|
|
@@ -27,7 +27,7 @@ export class ExecutorMetrics {
|
|
|
27
27
|
startRecordingTxSimulation(_txLabel) {
|
|
28
28
|
// do nothing (unimplemented)
|
|
29
29
|
}
|
|
30
|
-
stopRecordingTxSimulation(_txLabel, _gasUsed, _revertedCode) {
|
|
30
|
+
stopRecordingTxSimulation(_txLabel, _gasUsed, _revertedCode, _stats) {
|
|
31
31
|
// do nothing (unimplemented)
|
|
32
32
|
}
|
|
33
33
|
recordEnqueuedCallSimulation(fnName, durationMs, manaUsed, totalInstructionsExecuted) {
|
|
@@ -2,9 +2,9 @@ import type { RevertCode } from '@aztec/stdlib/avm';
|
|
|
2
2
|
import type { GasUsed } from '@aztec/stdlib/gas';
|
|
3
3
|
export interface ExecutorMetricsInterface {
|
|
4
4
|
startRecordingTxSimulation(txLabel: string): void;
|
|
5
|
-
stopRecordingTxSimulation(txLabel: string, gasUsed?: GasUsed, revertedCode?: RevertCode): void;
|
|
5
|
+
stopRecordingTxSimulation(txLabel: string, gasUsed?: GasUsed, revertedCode?: RevertCode, stats?: Record<string, string>): void;
|
|
6
6
|
recordEnqueuedCallSimulation(fnName: string, durationMs: number, manaUsed: number, totalInstructions: number): void;
|
|
7
7
|
recordEnqueuedCallSimulationFailure(fnName: string, durationMs: number, manaUsed: number, totalInstructionsExecuted: number): void;
|
|
8
8
|
recordPrivateEffectsInsertion(durationUs: number, type: 'revertible' | 'non-revertible'): void;
|
|
9
9
|
}
|
|
10
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
10
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXhlY3V0b3JfbWV0cmljc19pbnRlcmZhY2UuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9wdWJsaWMvZXhlY3V0b3JfbWV0cmljc19pbnRlcmZhY2UudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLEVBQUUsVUFBVSxFQUFFLE1BQU0sbUJBQW1CLENBQUM7QUFDcEQsT0FBTyxLQUFLLEVBQUUsT0FBTyxFQUFFLE1BQU0sbUJBQW1CLENBQUM7QUFFakQsTUFBTSxXQUFXLHdCQUF3QjtJQUN2QywwQkFBMEIsQ0FBQyxPQUFPLEVBQUUsTUFBTSxHQUFHLElBQUksQ0FBQztJQUNsRCx5QkFBeUIsQ0FDdkIsT0FBTyxFQUFFLE1BQU0sRUFDZixPQUFPLENBQUMsRUFBRSxPQUFPLEVBQ2pCLFlBQVksQ0FBQyxFQUFFLFVBQVUsRUFDekIsS0FBSyxDQUFDLEVBQUUsTUFBTSxDQUFDLE1BQU0sRUFBRSxNQUFNLENBQUMsR0FDN0IsSUFBSSxDQUFDO0lBQ1IsNEJBQTRCLENBQUMsTUFBTSxFQUFFLE1BQU0sRUFBRSxVQUFVLEVBQUUsTUFBTSxFQUFFLFFBQVEsRUFBRSxNQUFNLEVBQUUsaUJBQWlCLEVBQUUsTUFBTSxHQUFHLElBQUksQ0FBQztJQUNwSCxtQ0FBbUMsQ0FDakMsTUFBTSxFQUFFLE1BQU0sRUFDZCxVQUFVLEVBQUUsTUFBTSxFQUNsQixRQUFRLEVBQUUsTUFBTSxFQUNoQix5QkFBeUIsRUFBRSxNQUFNLEdBQ2hDLElBQUksQ0FBQztJQUNSLDZCQUE2QixDQUFDLFVBQVUsRUFBRSxNQUFNLEVBQUUsSUFBSSxFQUFFLFlBQVksR0FBRyxnQkFBZ0IsR0FBRyxJQUFJLENBQUM7Q0FDaEcifQ==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executor_metrics_interface.d.ts","sourceRoot":"","sources":["../../src/public/executor_metrics_interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEjD,MAAM,WAAW,wBAAwB;IACvC,0BAA0B,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAClD,yBAAyB,
|
|
1
|
+
{"version":3,"file":"executor_metrics_interface.d.ts","sourceRoot":"","sources":["../../src/public/executor_metrics_interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEjD,MAAM,WAAW,wBAAwB;IACvC,0BAA0B,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAClD,yBAAyB,CACvB,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,OAAO,EACjB,YAAY,CAAC,EAAE,UAAU,EACzB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC7B,IAAI,CAAC;IACR,4BAA4B,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;IACpH,mCAAmC,CACjC,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,yBAAyB,EAAE,MAAM,GAChC,IAAI,CAAC;IACR,6BAA6B,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,GAAG,gBAAgB,GAAG,IAAI,CAAC;CAChG"}
|
|
@@ -11,8 +11,6 @@ import { PublicContractsDB } from '../public_db_sources.js';
|
|
|
11
11
|
* Matches the C++ FuzzerSimulationRequest struct
|
|
12
12
|
*/
|
|
13
13
|
export declare class FuzzerSimulationRequest {
|
|
14
|
-
readonly wsDataDir: string;
|
|
15
|
-
readonly wsMapSizeKb: number;
|
|
16
14
|
readonly tx: AvmTxHint;
|
|
17
15
|
readonly globals: GlobalVariables;
|
|
18
16
|
readonly contractClasses: any[];
|
|
@@ -20,7 +18,7 @@ export declare class FuzzerSimulationRequest {
|
|
|
20
18
|
readonly publicDataWrites: any[];
|
|
21
19
|
readonly noteHashes: any[];
|
|
22
20
|
readonly protocolContracts: ProtocolContracts;
|
|
23
|
-
constructor(
|
|
21
|
+
constructor(tx: AvmTxHint, globals: GlobalVariables, contractClasses: any[], contractInstances: [any, any][], publicDataWrites: any[], noteHashes: any[], protocolContracts: ProtocolContracts);
|
|
24
22
|
static fromPlainObject(obj: any): FuzzerSimulationRequest;
|
|
25
23
|
}
|
|
26
24
|
/**
|
|
@@ -64,4 +62,4 @@ export declare class AvmFuzzerSimulator extends BaseAvmSimulationTester {
|
|
|
64
62
|
*/
|
|
65
63
|
applyNoteHashes(rawNoteHashes: any[]): Promise<void>;
|
|
66
64
|
}
|
|
67
|
-
//# sourceMappingURL=data:application/json;base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UNVLHVCQUF1QixDQUFDLFFBQVEsRUFBRSxHQUFHLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxDQUdqRTtJQUVEOzs7O09BSUc7SUFDVSwwQkFBMEIsQ0FBQyxVQUFVLEVBQUUsR0FBRyxFQUFFLFdBQVcsRUFBRSxHQUFHLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQyxDQU14RjtJQUVEOzs7T0FHRztJQUNVLHFCQUFxQixDQUFDLFNBQVMsRUFBRSxHQUFHLEVBQUUsR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLENBS2xFO0lBRUQ7OztPQUdHO0lBQ1UsZUFBZSxDQUFDLGFBQWEsRUFBRSxHQUFHLEVBQUUsR0FBRyxPQUFPLENBQUMsSUFBSSxDQUFDLENBSWhFO0NBQ0YifQ==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"avm_fuzzer_simulator.d.ts","sourceRoot":"","sources":["../../../src/public/fuzzing/avm_fuzzer_simulator.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,SAAS,EAAE,KAAK,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAYnE,OAAO,EAAgB,KAAK,yBAAyB,EAAsB,MAAM,qBAAqB,CAAC;AACvG,OAAO,EAEL,eAAe,EAEf,iBAAiB,EAKlB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAElE,OAAO,EAAE,uBAAuB,EAAE,MAAM,8CAA8C,CAAC;AACvF,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,wBAAwB,EAAE,MAAM,4CAA4C,CAAC;AACtF,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAG5D;;;GAGG;AACH,qBAAa,uBAAuB;aAEhB,
|
|
1
|
+
{"version":3,"file":"avm_fuzzer_simulator.d.ts","sourceRoot":"","sources":["../../../src/public/fuzzing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kBAAkB,EAAE,wBAAwB,EAC5C,OAAO,EAAE,eAAe,EAChB,YAAY,EAAE,gBAAgB,EACtC,WAAW,EAAE,iBAAiB,EAC9B,MAAM,EAAE,MAAM,EAoBf;IAED;;OAEG;IACH,OAAoB,MAAM,CACxB,iBAAiB,EAAE,uBAAuB,EAC1C,OAAO,EAAE,eAAe,GACvB,OAAO,CAAC,kBAAkB,CAAC,CAO7B;IAED,uEAAuE;IAC1D,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAElC;IAED;;OAEG;IACU,QAAQ,CAAC,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,cAAc,CAAC,CAUhE;IAED;;OAEG;IACU,uBAAuB,CAAC,QAAQ,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAGjE;IAED;;;;OAIG;IACU,0BAA0B,CAAC,UAAU,EAAE,GAAG,EAAE,WAAW,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAMxF;IAED;;;OAGG;IACU,qBAAqB,CAAC,SAAS,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAKlE;IAED;;;OAGG;IACU,eAAe,CAAC,aAAa,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAIhE;CACF"}
|
|
@@ -19,8 +19,6 @@ import { PublicTxSimulator } from '../public_tx_simulator/public_tx_simulator.js
|
|
|
19
19
|
* Request structure for fuzzer simulation communication from C++.
|
|
20
20
|
* Matches the C++ FuzzerSimulationRequest struct
|
|
21
21
|
*/ export class FuzzerSimulationRequest {
|
|
22
|
-
wsDataDir;
|
|
23
|
-
wsMapSizeKb;
|
|
24
22
|
tx;
|
|
25
23
|
globals;
|
|
26
24
|
contractClasses;
|
|
@@ -28,9 +26,7 @@ import { PublicTxSimulator } from '../public_tx_simulator/public_tx_simulator.js
|
|
|
28
26
|
publicDataWrites;
|
|
29
27
|
noteHashes;
|
|
30
28
|
protocolContracts;
|
|
31
|
-
constructor(
|
|
32
|
-
this.wsDataDir = wsDataDir;
|
|
33
|
-
this.wsMapSizeKb = wsMapSizeKb;
|
|
29
|
+
constructor(tx, globals, contractClasses, contractInstances, publicDataWrites, noteHashes, protocolContracts){
|
|
34
30
|
this.tx = tx;
|
|
35
31
|
this.globals = globals;
|
|
36
32
|
this.contractClasses = contractClasses;
|
|
@@ -43,7 +39,7 @@ import { PublicTxSimulator } from '../public_tx_simulator/public_tx_simulator.js
|
|
|
43
39
|
if (obj instanceof FuzzerSimulationRequest) {
|
|
44
40
|
return obj;
|
|
45
41
|
}
|
|
46
|
-
return new FuzzerSimulationRequest(
|
|
42
|
+
return new FuzzerSimulationRequest(AvmTxHint.fromPlainObject(obj.tx), GlobalVariables.fromPlainObject(obj.globals), obj.contractClasses, obj.contractInstances, obj.publicDataWrites ?? [], obj.noteHashes ?? [], ProtocolContracts.fromPlainObject(obj.protocolContracts));
|
|
47
43
|
}
|
|
48
44
|
}
|
|
49
45
|
/**
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
2
1
|
import { PublicTxEffect, deserializeFromMessagePack, serializeWithMessagePack } from '@aztec/stdlib/avm';
|
|
3
2
|
import { TreeSnapshots } from '@aztec/stdlib/tx';
|
|
4
3
|
import { NativeWorldStateService } from '@aztec/world-state';
|
|
@@ -15,26 +14,17 @@ import { AvmFuzzerSimulator, FuzzerSimulationRequest } from './avm_fuzzer_simula
|
|
|
15
14
|
});
|
|
16
15
|
});
|
|
17
16
|
}
|
|
18
|
-
//
|
|
19
|
-
//
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const ws = await NativeWorldStateService.new(EthAddress.ZERO, dataDir, {
|
|
27
|
-
archiveTreeMapSizeKb: mapSizeKb,
|
|
28
|
-
nullifierTreeMapSizeKb: mapSizeKb,
|
|
29
|
-
noteHashTreeMapSizeKb: mapSizeKb,
|
|
30
|
-
messageTreeMapSizeKb: mapSizeKb,
|
|
31
|
-
publicDataTreeMapSizeKb: mapSizeKb
|
|
32
|
-
});
|
|
33
|
-
worldStateCache.set(dataDir, ws);
|
|
34
|
-
return ws;
|
|
17
|
+
// The fuzzer self-bootstraps its own world state instead of reading a shared on-disk database written by
|
|
18
|
+
// the C++ side. A fresh NativeWorldStateService produces a genesis identical to the C++ MemoryMerkleDB by
|
|
19
|
+
// construction (same 128 nullifier/public-data tree prefill and header-generator point), and the dynamic
|
|
20
|
+
// state is applied per-input below. The instance is opened once and reused across inputs; each input forks
|
|
21
|
+
// from it (in AvmFuzzerSimulator.create).
|
|
22
|
+
let worldStatePromise;
|
|
23
|
+
function getWorldState() {
|
|
24
|
+
return worldStatePromise ??= NativeWorldStateService.tmp();
|
|
35
25
|
}
|
|
36
|
-
async function simulateWithFuzzer(
|
|
37
|
-
const worldStateService = await
|
|
26
|
+
async function simulateWithFuzzer(txHint, globals, rawContractClasses, rawContractInstances, rawPublicDataWrites, rawNoteHashes) {
|
|
27
|
+
const worldStateService = await getWorldState();
|
|
38
28
|
const simulator = await AvmFuzzerSimulator.create(worldStateService, globals);
|
|
39
29
|
await simulator.applyNoteHashes(rawNoteHashes);
|
|
40
30
|
// Register contract classes from C++ (must happen before public data writes to match C++ order)
|
|
@@ -65,7 +55,7 @@ async function execute(base64Line) {
|
|
|
65
55
|
const rawRequest = deserializeFromMessagePack(buffer);
|
|
66
56
|
const request = FuzzerSimulationRequest.fromPlainObject(rawRequest);
|
|
67
57
|
// Run the simulation on the C++ AVM simulator
|
|
68
|
-
const result = await simulateWithFuzzer(request.
|
|
58
|
+
const result = await simulateWithFuzzer(request.tx, request.globals, request.contractClasses, request.contractInstances, request.publicDataWrites, request.noteHashes);
|
|
69
59
|
// Serialize the result to msgpack and encode it in base64 for output
|
|
70
60
|
const resultBuffer = serializeWithMessagePack({
|
|
71
61
|
reverted: result.reverted,
|
|
@@ -110,7 +110,7 @@ export class MeasuredPublicTxSimulator extends PublicTxSimulator {
|
|
|
110
110
|
try {
|
|
111
111
|
result = await super.simulate(tx);
|
|
112
112
|
} finally{
|
|
113
|
-
this.metrics.stopRecordingTxSimulation(txLabel, result?.gasUsed, result?.revertCode);
|
|
113
|
+
this.metrics.stopRecordingTxSimulation(txLabel, result?.gasUsed, result?.revertCode, result?.stats);
|
|
114
114
|
}
|
|
115
115
|
return result;
|
|
116
116
|
}
|