@aztec/simulator 0.0.1-commit.03f7ef2 → 0.0.1-commit.1142ef1

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.
Files changed (35) hide show
  1. package/dest/private/circuit_recording/circuit_recorder.d.ts +1 -1
  2. package/dest/private/circuit_recording/circuit_recorder.d.ts.map +1 -1
  3. package/dest/private/circuit_recording/circuit_recorder.js +15 -14
  4. package/dest/public/avm/opcodes/accrued_substate.js +1 -1
  5. package/dest/public/avm/opcodes/environment_getters.d.ts +3 -3
  6. package/dest/public/avm/opcodes/environment_getters.d.ts.map +1 -1
  7. package/dest/public/avm/opcodes/environment_getters.js +2 -2
  8. package/dest/public/avm/opcodes/external_calls.d.ts +1 -1
  9. package/dest/public/avm/opcodes/external_calls.d.ts.map +1 -1
  10. package/dest/public/avm/opcodes/external_calls.js +1 -0
  11. package/dest/public/executor_metrics.d.ts +1 -1
  12. package/dest/public/executor_metrics.d.ts.map +1 -1
  13. package/dest/public/executor_metrics.js +8 -34
  14. package/dest/public/fixtures/bulk_test.js +1 -17
  15. package/dest/public/fuzzing/avm_simulator_bin.js +14 -3
  16. package/dest/public/hinting_db_sources.js +3 -1
  17. package/dest/public/public_processor/guarded_merkle_tree.js +3 -1
  18. package/dest/public/public_processor/public_processor.js +399 -20
  19. package/dest/public/public_processor/public_processor_metrics.d.ts +1 -1
  20. package/dest/public/public_processor/public_processor_metrics.d.ts.map +1 -1
  21. package/dest/public/public_processor/public_processor_metrics.js +12 -45
  22. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts +1 -1
  23. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.d.ts.map +1 -1
  24. package/dest/public/public_tx_simulator/cpp_public_tx_simulator.js +1 -1
  25. package/dest/public/public_tx_simulator/telemetry_public_tx_simulator.js +395 -19
  26. package/package.json +16 -16
  27. package/src/private/circuit_recording/circuit_recorder.ts +16 -15
  28. package/src/public/avm/opcodes/accrued_substate.ts +1 -1
  29. package/src/public/avm/opcodes/environment_getters.ts +4 -4
  30. package/src/public/avm/opcodes/external_calls.ts +1 -0
  31. package/src/public/executor_metrics.ts +7 -34
  32. package/src/public/fixtures/bulk_test.ts +2 -2
  33. package/src/public/fuzzing/avm_simulator_bin.ts +17 -4
  34. package/src/public/public_processor/public_processor_metrics.ts +11 -45
  35. package/src/public/public_tx_simulator/cpp_public_tx_simulator.ts +8 -1
@@ -1,20 +1,409 @@
1
- function _ts_decorate(decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
1
+ function applyDecs2203RFactory() {
2
+ function createAddInitializerMethod(initializers, decoratorFinishedRef) {
3
+ return function addInitializer(initializer) {
4
+ assertNotFinished(decoratorFinishedRef, "addInitializer");
5
+ assertCallable(initializer, "An initializer");
6
+ initializers.push(initializer);
7
+ };
8
+ }
9
+ function memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value) {
10
+ var kindStr;
11
+ switch(kind){
12
+ case 1:
13
+ kindStr = "accessor";
14
+ break;
15
+ case 2:
16
+ kindStr = "method";
17
+ break;
18
+ case 3:
19
+ kindStr = "getter";
20
+ break;
21
+ case 4:
22
+ kindStr = "setter";
23
+ break;
24
+ default:
25
+ kindStr = "field";
26
+ }
27
+ var ctx = {
28
+ kind: kindStr,
29
+ name: isPrivate ? "#" + name : name,
30
+ static: isStatic,
31
+ private: isPrivate,
32
+ metadata: metadata
33
+ };
34
+ var decoratorFinishedRef = {
35
+ v: false
36
+ };
37
+ ctx.addInitializer = createAddInitializerMethod(initializers, decoratorFinishedRef);
38
+ var get, set;
39
+ if (kind === 0) {
40
+ if (isPrivate) {
41
+ get = desc.get;
42
+ set = desc.set;
43
+ } else {
44
+ get = function() {
45
+ return this[name];
46
+ };
47
+ set = function(v) {
48
+ this[name] = v;
49
+ };
50
+ }
51
+ } else if (kind === 2) {
52
+ get = function() {
53
+ return desc.value;
54
+ };
55
+ } else {
56
+ if (kind === 1 || kind === 3) {
57
+ get = function() {
58
+ return desc.get.call(this);
59
+ };
60
+ }
61
+ if (kind === 1 || kind === 4) {
62
+ set = function(v) {
63
+ desc.set.call(this, v);
64
+ };
65
+ }
66
+ }
67
+ ctx.access = get && set ? {
68
+ get: get,
69
+ set: set
70
+ } : get ? {
71
+ get: get
72
+ } : {
73
+ set: set
74
+ };
75
+ try {
76
+ return dec(value, ctx);
77
+ } finally{
78
+ decoratorFinishedRef.v = true;
79
+ }
80
+ }
81
+ function assertNotFinished(decoratorFinishedRef, fnName) {
82
+ if (decoratorFinishedRef.v) {
83
+ throw new Error("attempted to call " + fnName + " after decoration was finished");
84
+ }
85
+ }
86
+ function assertCallable(fn, hint) {
87
+ if (typeof fn !== "function") {
88
+ throw new TypeError(hint + " must be a function");
89
+ }
90
+ }
91
+ function assertValidReturnValue(kind, value) {
92
+ var type = typeof value;
93
+ if (kind === 1) {
94
+ if (type !== "object" || value === null) {
95
+ throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");
96
+ }
97
+ if (value.get !== undefined) {
98
+ assertCallable(value.get, "accessor.get");
99
+ }
100
+ if (value.set !== undefined) {
101
+ assertCallable(value.set, "accessor.set");
102
+ }
103
+ if (value.init !== undefined) {
104
+ assertCallable(value.init, "accessor.init");
105
+ }
106
+ } else if (type !== "function") {
107
+ var hint;
108
+ if (kind === 0) {
109
+ hint = "field";
110
+ } else if (kind === 10) {
111
+ hint = "class";
112
+ } else {
113
+ hint = "method";
114
+ }
115
+ throw new TypeError(hint + " decorators must return a function or void 0");
116
+ }
117
+ }
118
+ function applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata) {
119
+ var decs = decInfo[0];
120
+ var desc, init, value;
121
+ if (isPrivate) {
122
+ if (kind === 0 || kind === 1) {
123
+ desc = {
124
+ get: decInfo[3],
125
+ set: decInfo[4]
126
+ };
127
+ } else if (kind === 3) {
128
+ desc = {
129
+ get: decInfo[3]
130
+ };
131
+ } else if (kind === 4) {
132
+ desc = {
133
+ set: decInfo[3]
134
+ };
135
+ } else {
136
+ desc = {
137
+ value: decInfo[3]
138
+ };
139
+ }
140
+ } else if (kind !== 0) {
141
+ desc = Object.getOwnPropertyDescriptor(base, name);
142
+ }
143
+ if (kind === 1) {
144
+ value = {
145
+ get: desc.get,
146
+ set: desc.set
147
+ };
148
+ } else if (kind === 2) {
149
+ value = desc.value;
150
+ } else if (kind === 3) {
151
+ value = desc.get;
152
+ } else if (kind === 4) {
153
+ value = desc.set;
154
+ }
155
+ var newValue, get, set;
156
+ if (typeof decs === "function") {
157
+ newValue = memberDec(decs, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
158
+ if (newValue !== void 0) {
159
+ assertValidReturnValue(kind, newValue);
160
+ if (kind === 0) {
161
+ init = newValue;
162
+ } else if (kind === 1) {
163
+ init = newValue.init;
164
+ get = newValue.get || value.get;
165
+ set = newValue.set || value.set;
166
+ value = {
167
+ get: get,
168
+ set: set
169
+ };
170
+ } else {
171
+ value = newValue;
172
+ }
173
+ }
174
+ } else {
175
+ for(var i = decs.length - 1; i >= 0; i--){
176
+ var dec = decs[i];
177
+ newValue = memberDec(dec, name, desc, initializers, kind, isStatic, isPrivate, metadata, value);
178
+ if (newValue !== void 0) {
179
+ assertValidReturnValue(kind, newValue);
180
+ var newInit;
181
+ if (kind === 0) {
182
+ newInit = newValue;
183
+ } else if (kind === 1) {
184
+ newInit = newValue.init;
185
+ get = newValue.get || value.get;
186
+ set = newValue.set || value.set;
187
+ value = {
188
+ get: get,
189
+ set: set
190
+ };
191
+ } else {
192
+ value = newValue;
193
+ }
194
+ if (newInit !== void 0) {
195
+ if (init === void 0) {
196
+ init = newInit;
197
+ } else if (typeof init === "function") {
198
+ init = [
199
+ init,
200
+ newInit
201
+ ];
202
+ } else {
203
+ init.push(newInit);
204
+ }
205
+ }
206
+ }
207
+ }
208
+ }
209
+ if (kind === 0 || kind === 1) {
210
+ if (init === void 0) {
211
+ init = function(instance, init) {
212
+ return init;
213
+ };
214
+ } else if (typeof init !== "function") {
215
+ var ownInitializers = init;
216
+ init = function(instance, init) {
217
+ var value = init;
218
+ for(var i = 0; i < ownInitializers.length; i++){
219
+ value = ownInitializers[i].call(instance, value);
220
+ }
221
+ return value;
222
+ };
223
+ } else {
224
+ var originalInitializer = init;
225
+ init = function(instance, init) {
226
+ return originalInitializer.call(instance, init);
227
+ };
228
+ }
229
+ ret.push(init);
230
+ }
231
+ if (kind !== 0) {
232
+ if (kind === 1) {
233
+ desc.get = value.get;
234
+ desc.set = value.set;
235
+ } else if (kind === 2) {
236
+ desc.value = value;
237
+ } else if (kind === 3) {
238
+ desc.get = value;
239
+ } else if (kind === 4) {
240
+ desc.set = value;
241
+ }
242
+ if (isPrivate) {
243
+ if (kind === 1) {
244
+ ret.push(function(instance, args) {
245
+ return value.get.call(instance, args);
246
+ });
247
+ ret.push(function(instance, args) {
248
+ return value.set.call(instance, args);
249
+ });
250
+ } else if (kind === 2) {
251
+ ret.push(value);
252
+ } else {
253
+ ret.push(function(instance, args) {
254
+ return value.call(instance, args);
255
+ });
256
+ }
257
+ } else {
258
+ Object.defineProperty(base, name, desc);
259
+ }
260
+ }
261
+ }
262
+ function applyMemberDecs(Class, decInfos, metadata) {
263
+ var ret = [];
264
+ var protoInitializers;
265
+ var staticInitializers;
266
+ var existingProtoNonFields = new Map();
267
+ var existingStaticNonFields = new Map();
268
+ for(var i = 0; i < decInfos.length; i++){
269
+ var decInfo = decInfos[i];
270
+ if (!Array.isArray(decInfo)) continue;
271
+ var kind = decInfo[1];
272
+ var name = decInfo[2];
273
+ var isPrivate = decInfo.length > 3;
274
+ var isStatic = kind >= 5;
275
+ var base;
276
+ var initializers;
277
+ if (isStatic) {
278
+ base = Class;
279
+ kind = kind - 5;
280
+ staticInitializers = staticInitializers || [];
281
+ initializers = staticInitializers;
282
+ } else {
283
+ base = Class.prototype;
284
+ protoInitializers = protoInitializers || [];
285
+ initializers = protoInitializers;
286
+ }
287
+ if (kind !== 0 && !isPrivate) {
288
+ var existingNonFields = isStatic ? existingStaticNonFields : existingProtoNonFields;
289
+ var existingKind = existingNonFields.get(name) || 0;
290
+ if (existingKind === true || existingKind === 3 && kind !== 4 || existingKind === 4 && kind !== 3) {
291
+ throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: " + name);
292
+ } else if (!existingKind && kind > 2) {
293
+ existingNonFields.set(name, kind);
294
+ } else {
295
+ existingNonFields.set(name, true);
296
+ }
297
+ }
298
+ applyMemberDec(ret, base, decInfo, name, kind, isStatic, isPrivate, initializers, metadata);
299
+ }
300
+ pushInitializers(ret, protoInitializers);
301
+ pushInitializers(ret, staticInitializers);
302
+ return ret;
303
+ }
304
+ function pushInitializers(ret, initializers) {
305
+ if (initializers) {
306
+ ret.push(function(instance) {
307
+ for(var i = 0; i < initializers.length; i++){
308
+ initializers[i].call(instance);
309
+ }
310
+ return instance;
311
+ });
312
+ }
313
+ }
314
+ function applyClassDecs(targetClass, classDecs, metadata) {
315
+ if (classDecs.length > 0) {
316
+ var initializers = [];
317
+ var newClass = targetClass;
318
+ var name = targetClass.name;
319
+ for(var i = classDecs.length - 1; i >= 0; i--){
320
+ var decoratorFinishedRef = {
321
+ v: false
322
+ };
323
+ try {
324
+ var nextNewClass = classDecs[i](newClass, {
325
+ kind: "class",
326
+ name: name,
327
+ addInitializer: createAddInitializerMethod(initializers, decoratorFinishedRef),
328
+ metadata
329
+ });
330
+ } finally{
331
+ decoratorFinishedRef.v = true;
332
+ }
333
+ if (nextNewClass !== undefined) {
334
+ assertValidReturnValue(10, nextNewClass);
335
+ newClass = nextNewClass;
336
+ }
337
+ }
338
+ return [
339
+ defineMetadata(newClass, metadata),
340
+ function() {
341
+ for(var i = 0; i < initializers.length; i++){
342
+ initializers[i].call(newClass);
343
+ }
344
+ }
345
+ ];
346
+ }
347
+ }
348
+ function defineMetadata(Class, metadata) {
349
+ return Object.defineProperty(Class, Symbol.metadata || Symbol.for("Symbol.metadata"), {
350
+ configurable: true,
351
+ enumerable: true,
352
+ value: metadata
353
+ });
354
+ }
355
+ return function applyDecs2203R(targetClass, memberDecs, classDecs, parentClass) {
356
+ if (parentClass !== void 0) {
357
+ var parentMetadata = parentClass[Symbol.metadata || Symbol.for("Symbol.metadata")];
358
+ }
359
+ var metadata = Object.create(parentMetadata === void 0 ? null : parentMetadata);
360
+ var e = applyMemberDecs(targetClass, memberDecs, metadata);
361
+ if (!classDecs.length) defineMetadata(targetClass, metadata);
362
+ return {
363
+ e: e,
364
+ get c () {
365
+ return applyClassDecs(targetClass, classDecs, metadata);
366
+ }
367
+ };
368
+ };
369
+ }
370
+ function _apply_decs_2203_r(targetClass, memberDecs, classDecs, parentClass) {
371
+ return (_apply_decs_2203_r = applyDecs2203RFactory())(targetClass, memberDecs, classDecs, parentClass);
6
372
  }
373
+ var _dec, _dec1, _initProto;
7
374
  import { TxExecutionPhase } from '@aztec/stdlib/tx';
8
375
  import { Attributes, getTelemetryClient, trackSpan } from '@aztec/telemetry-client';
9
376
  import { ExecutorMetrics } from '../executor_metrics.js';
10
377
  import { MeasuredPublicTxSimulator } from './measured_public_tx_simulator.js';
378
+ _dec = trackSpan('PublicTxSimulator.simulateEnqueuedCall', (phase, context, callRequest)=>({
379
+ [Attributes.TX_HASH]: context.txHash.toString(),
380
+ [Attributes.TARGET_ADDRESS]: callRequest.request.contractAddress.toString(),
381
+ [Attributes.SENDER_ADDRESS]: callRequest.request.msgSender.toString(),
382
+ [Attributes.SIMULATOR_PHASE]: TxExecutionPhase[phase].toString()
383
+ })), _dec1 = trackSpan('PublicTxSimulator.simulateEnqueuedCallInternal', (_stateManager, _callRequest, _allocatedGas, _transactionFee, fnName)=>({
384
+ [Attributes.APP_CIRCUIT_NAME]: fnName
385
+ }));
11
386
  /**
12
387
  * A public tx simulator that tracks runtime/production metrics with telemetry.
13
388
  */ export class TelemetryPublicTxSimulator extends MeasuredPublicTxSimulator {
389
+ static{
390
+ ({ e: [_initProto] } = _apply_decs_2203_r(this, [
391
+ [
392
+ _dec,
393
+ 2,
394
+ "simulateEnqueuedCall"
395
+ ],
396
+ [
397
+ _dec1,
398
+ 2,
399
+ "simulateEnqueuedCallInternal"
400
+ ]
401
+ ], []));
402
+ }
14
403
  /* tracer needed by trackSpans */ tracer;
15
404
  constructor(merkleTree, contractsDB, globalVariables, telemetryClient = getTelemetryClient(), config){
16
405
  const metrics = new ExecutorMetrics(telemetryClient, 'PublicTxSimulator');
17
- super(merkleTree, contractsDB, globalVariables, metrics, config);
406
+ super(merkleTree, contractsDB, globalVariables, metrics, config), _initProto(this);
18
407
  this.tracer = metrics.tracer;
19
408
  }
20
409
  async simulateEnqueuedCall(phase, context, callRequest) {
@@ -24,16 +413,3 @@ import { MeasuredPublicTxSimulator } from './measured_public_tx_simulator.js';
24
413
  return await super.simulateEnqueuedCallInternal(stateManager, callRequest, allocatedGas, transactionFee, fnName);
25
414
  }
26
415
  }
27
- _ts_decorate([
28
- trackSpan('PublicTxSimulator.simulateEnqueuedCall', (phase, context, callRequest)=>({
29
- [Attributes.TX_HASH]: context.txHash.toString(),
30
- [Attributes.TARGET_ADDRESS]: callRequest.request.contractAddress.toString(),
31
- [Attributes.SENDER_ADDRESS]: callRequest.request.msgSender.toString(),
32
- [Attributes.SIMULATOR_PHASE]: TxExecutionPhase[phase].toString()
33
- }))
34
- ], TelemetryPublicTxSimulator.prototype, "simulateEnqueuedCall", null);
35
- _ts_decorate([
36
- trackSpan('PublicTxSimulator.simulateEnqueuedCallInternal', (_stateManager, _callRequest, _allocatedGas, _transactionFee, fnName)=>({
37
- [Attributes.APP_CIRCUIT_NAME]: fnName
38
- }))
39
- ], TelemetryPublicTxSimulator.prototype, "simulateEnqueuedCallInternal", null);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/simulator",
3
- "version": "0.0.1-commit.03f7ef2",
3
+ "version": "0.0.1-commit.1142ef1",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  "./server": "./dest/server.js",
@@ -64,26 +64,26 @@
64
64
  ]
65
65
  },
66
66
  "dependencies": {
67
- "@aztec/constants": "0.0.1-commit.03f7ef2",
68
- "@aztec/foundation": "0.0.1-commit.03f7ef2",
69
- "@aztec/native": "0.0.1-commit.03f7ef2",
70
- "@aztec/noir-acvm_js": "0.0.1-commit.03f7ef2",
71
- "@aztec/noir-noirc_abi": "0.0.1-commit.03f7ef2",
72
- "@aztec/noir-protocol-circuits-types": "0.0.1-commit.03f7ef2",
73
- "@aztec/noir-types": "0.0.1-commit.03f7ef2",
74
- "@aztec/protocol-contracts": "0.0.1-commit.03f7ef2",
75
- "@aztec/stdlib": "0.0.1-commit.03f7ef2",
76
- "@aztec/telemetry-client": "0.0.1-commit.03f7ef2",
77
- "@aztec/world-state": "0.0.1-commit.03f7ef2",
67
+ "@aztec/constants": "0.0.1-commit.1142ef1",
68
+ "@aztec/foundation": "0.0.1-commit.1142ef1",
69
+ "@aztec/native": "0.0.1-commit.1142ef1",
70
+ "@aztec/noir-acvm_js": "0.0.1-commit.1142ef1",
71
+ "@aztec/noir-noirc_abi": "0.0.1-commit.1142ef1",
72
+ "@aztec/noir-protocol-circuits-types": "0.0.1-commit.1142ef1",
73
+ "@aztec/noir-types": "0.0.1-commit.1142ef1",
74
+ "@aztec/protocol-contracts": "0.0.1-commit.1142ef1",
75
+ "@aztec/stdlib": "0.0.1-commit.1142ef1",
76
+ "@aztec/telemetry-client": "0.0.1-commit.1142ef1",
77
+ "@aztec/world-state": "0.0.1-commit.1142ef1",
78
78
  "lodash.clonedeep": "^4.5.0",
79
79
  "lodash.merge": "^4.6.2",
80
80
  "tslib": "^2.4.0"
81
81
  },
82
82
  "devDependencies": {
83
- "@aztec/kv-store": "0.0.1-commit.03f7ef2",
84
- "@aztec/merkle-tree": "0.0.1-commit.03f7ef2",
85
- "@aztec/noir-contracts.js": "0.0.1-commit.03f7ef2",
86
- "@aztec/noir-test-contracts.js": "0.0.1-commit.03f7ef2",
83
+ "@aztec/kv-store": "0.0.1-commit.1142ef1",
84
+ "@aztec/merkle-tree": "0.0.1-commit.1142ef1",
85
+ "@aztec/noir-contracts.js": "0.0.1-commit.1142ef1",
86
+ "@aztec/noir-test-contracts.js": "0.0.1-commit.1142ef1",
87
87
  "@jest/globals": "^30.0.0",
88
88
  "@types/jest": "^30.0.0",
89
89
  "@types/lodash.clonedeep": "^4.5.7",
@@ -108,16 +108,16 @@ export class CircuitRecorder {
108
108
  * contracts as protocol circuits artifacts always contain a single entrypoint function called 'main'.
109
109
  */
110
110
  start(input: ACVMWitness, circuitBytecode: Buffer, circuitName: string, functionName: string): Promise<void> {
111
- const parentRef = this.recording;
112
111
  if (this.newCircuit) {
112
+ const parentRef = this.recording;
113
113
  this.recording = new CircuitRecording(
114
114
  circuitName,
115
115
  functionName,
116
116
  sha512(circuitBytecode).toString('hex'),
117
117
  Object.fromEntries(input),
118
118
  );
119
+ this.recording.setParent(parentRef);
119
120
  }
120
- this.recording!.setParent(parentRef);
121
121
 
122
122
  return Promise.resolve();
123
123
  }
@@ -173,22 +173,22 @@ export class CircuitRecorder {
173
173
  if (result instanceof Promise) {
174
174
  return result.then(async r => {
175
175
  // Once we leave the nested circuit, we decrease the stack depth and set newCircuit to false
176
- // since we are going back to the "parent" circuit which can never be new
176
+ // so that the parent circuit continues with its existing recording
177
+ // Note: recording restoration is handled by finish()
177
178
  if (isExternalCall) {
178
179
  this.stackDepth--;
179
180
  this.newCircuit = false;
180
- this.recording = this.recording!.parent;
181
181
  }
182
182
  await this.recordCall(name, args, r, timer.ms(), this.stackDepth);
183
183
  return r;
184
184
  }) as ReturnType<typeof fn>;
185
185
  }
186
186
  // Once we leave the nested circuit, we decrease the stack depth and set newCircuit to false
187
- // since we are going back to the "parent" circuit which can never be new
187
+ // so that the parent circuit continues with its existing recording
188
+ // Note: recording restoration is handled by finish()
188
189
  if (isExternalCall) {
189
190
  this.stackDepth--;
190
191
  this.newCircuit = false;
191
- this.recording = this.recording!.parent;
192
192
  }
193
193
  void this.recordCall(name, args, result, timer.ms(), this.stackDepth);
194
194
  return result;
@@ -239,6 +239,12 @@ export class CircuitRecorder {
239
239
  if (!result!.parent) {
240
240
  this.newCircuit = true;
241
241
  this.recording = undefined;
242
+ } else {
243
+ // For nested circuits (utility calls, nested contract calls), restore to parent recording
244
+ // Note: we don't set newCircuit=false here because:
245
+ // - For privateCallPrivateFunction, the callback wrapper will set it to false
246
+ // - For utility calls, we want newCircuit to remain true so the next circuit creates its own recording
247
+ this.recording = result!.parent;
242
248
  }
243
249
  return Promise.resolve(result!);
244
250
  }
@@ -247,14 +253,9 @@ export class CircuitRecorder {
247
253
  * Finalizes the recording by resetting the state and returning the recording object with an attached error.
248
254
  * @param error - The error that occurred during circuit execution
249
255
  */
250
- finishWithError(error: unknown): Promise<CircuitRecording> {
251
- const result = this.recording;
252
- // If this is the top-level circuit recording, we reset the state for the next simulator call
253
- if (!result!.parent) {
254
- this.newCircuit = true;
255
- this.recording = undefined;
256
- }
257
- result!.error = JSON.stringify(error);
258
- return Promise.resolve(result!);
256
+ async finishWithError(error: unknown): Promise<CircuitRecording> {
257
+ const result = await this.finish();
258
+ result.error = JSON.stringify(error);
259
+ return result;
259
260
  }
260
261
  }
@@ -241,11 +241,11 @@ export class EmitUnencryptedLog extends Instruction {
241
241
  const [logSizeOffset, logOffset] = addressing.resolve(operands, memory);
242
242
  memory.checkTag(TypeTag.UINT32, logSizeOffset);
243
243
  const logSize = memory.get(logSizeOffset).toNumber();
244
- memory.checkTagsRange(TypeTag.FIELD, logOffset, logSize);
245
244
 
246
245
  const contractAddress = context.environment.address;
247
246
 
248
247
  context.machineState.consumeGas(this.dynamicGasCost(logSize));
248
+ memory.checkTagsRange(TypeTag.FIELD, logOffset, logSize);
249
249
  const log = memory.getSlice(logOffset, logSize).map(f => f.toFr());
250
250
  context.persistableState.writePublicLog(contractAddress, log);
251
251
  }
@@ -13,8 +13,8 @@ export enum EnvironmentVariable {
13
13
  VERSION,
14
14
  BLOCKNUMBER,
15
15
  TIMESTAMP,
16
- BASEFEEPERL2GAS,
17
- BASEFEEPERDAGAS,
16
+ MINFEEPERL2GAS,
17
+ MINFEEPERDAGAS,
18
18
  ISSTATICCALL,
19
19
  L2GASLEFT,
20
20
  DAGASLEFT,
@@ -36,9 +36,9 @@ function getValue(varEnum: EnvironmentVariable, ctx: AvmContext) {
36
36
  return new Uint32(ctx.environment.globals.blockNumber);
37
37
  case EnvironmentVariable.TIMESTAMP:
38
38
  return new Uint64(ctx.environment.globals.timestamp);
39
- case EnvironmentVariable.BASEFEEPERL2GAS:
39
+ case EnvironmentVariable.MINFEEPERL2GAS:
40
40
  return new Uint128(ctx.environment.globals.gasFees.feePerL2Gas);
41
- case EnvironmentVariable.BASEFEEPERDAGAS:
41
+ case EnvironmentVariable.MINFEEPERDAGAS:
42
42
  return new Uint128(ctx.environment.globals.gasFees.feePerDaGas);
43
43
  case EnvironmentVariable.ISSTATICCALL:
44
44
  return new Uint1(ctx.environment.isStaticCall ? 1 : 0);
@@ -45,6 +45,7 @@ abstract class ExternalCall extends Instruction {
45
45
  memory.checkTag(TypeTag.UINT32, argsSizeOffset);
46
46
 
47
47
  const calldataSize = memory.get(argsSizeOffset).toNumber();
48
+ // This is a DOS vector. CalldataSize is chosen by the bytecode, and can be arbitrarily large leading to a OOM here.
48
49
  const calldata = memory.getSlice(argsOffset, calldataSize).map(f => f.toFr());
49
50
 
50
51
  const callAddress = memory.getAs<Field>(addrOffset);
@@ -7,7 +7,6 @@ import {
7
7
  type TelemetryClient,
8
8
  type Tracer,
9
9
  type UpDownCounter,
10
- ValueType,
11
10
  } from '@aztec/telemetry-client';
12
11
 
13
12
  import type { ExecutorMetricsInterface } from './executor_metrics_interface.js';
@@ -26,45 +25,19 @@ export class ExecutorMetrics implements ExecutorMetricsInterface {
26
25
  this.tracer = client.getTracer(name);
27
26
  const meter = client.getMeter(name);
28
27
 
29
- this.fnCount = meter.createUpDownCounter(Metrics.PUBLIC_EXECUTOR_SIMULATION_COUNT, {
30
- description: 'Number of functions executed',
31
- });
28
+ this.fnCount = meter.createUpDownCounter(Metrics.PUBLIC_EXECUTOR_SIMULATION_COUNT);
32
29
 
33
- this.fnDuration = meter.createHistogram(Metrics.PUBLIC_EXECUTOR_SIMULATION_DURATION, {
34
- description: 'How long it takes to execute a function',
35
- unit: 'ms',
36
- valueType: ValueType.INT,
37
- });
30
+ this.fnDuration = meter.createHistogram(Metrics.PUBLIC_EXECUTOR_SIMULATION_DURATION);
38
31
 
39
- this.manaPerSecond = meter.createHistogram(Metrics.PUBLIC_EXECUTOR_SIMULATION_MANA_PER_SECOND, {
40
- description: 'Mana used per second',
41
- unit: 'mana/s',
42
- valueType: ValueType.INT,
43
- });
32
+ this.manaPerSecond = meter.createHistogram(Metrics.PUBLIC_EXECUTOR_SIMULATION_MANA_PER_SECOND);
44
33
 
45
- this.manaUsed = meter.createHistogram(Metrics.PUBLIC_EXECUTOR_SIMULATION_MANA_USED, {
46
- description: 'Total mana used',
47
- unit: 'mana',
48
- valueType: ValueType.INT,
49
- });
34
+ this.manaUsed = meter.createHistogram(Metrics.PUBLIC_EXECUTOR_SIMULATION_MANA_USED);
50
35
 
51
- this.totalInstructionsExecuted = meter.createHistogram(Metrics.PUBLIC_EXECUTOR_SIMULATION_TOTAL_INSTRUCTIONS, {
52
- description: 'Total number of instructions executed',
53
- unit: '#instructions',
54
- valueType: ValueType.INT,
55
- });
36
+ this.totalInstructionsExecuted = meter.createHistogram(Metrics.PUBLIC_EXECUTOR_SIMULATION_TOTAL_INSTRUCTIONS);
56
37
 
57
- this.txHashing = meter.createHistogram(Metrics.PUBLIC_EXECUTOR_TX_HASHING, {
58
- description: 'Tx hashing time',
59
- unit: 'ms',
60
- valueType: ValueType.INT,
61
- });
38
+ this.txHashing = meter.createHistogram(Metrics.PUBLIC_EXECUTOR_TX_HASHING);
62
39
 
63
- this.privateEffectsInsertions = meter.createHistogram(Metrics.PUBLIC_EXECUTOR_PRIVATE_EFFECTS_INSERTION, {
64
- description: 'Private effects insertion time',
65
- unit: 'us',
66
- valueType: ValueType.INT,
67
- });
40
+ this.privateEffectsInsertions = meter.createHistogram(Metrics.PUBLIC_EXECUTOR_PRIVATE_EFFECTS_INSERTION);
68
41
  }
69
42
 
70
43
  startRecordingTxSimulation(_txLabel: string) {