@aztec/simulator 0.40.0 → 0.41.0

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 (124) hide show
  1. package/dest/acvm/oracle/oracle.d.ts +4 -2
  2. package/dest/acvm/oracle/oracle.d.ts.map +1 -1
  3. package/dest/acvm/oracle/oracle.js +21 -18
  4. package/dest/acvm/oracle/typed_oracle.d.ts +6 -11
  5. package/dest/acvm/oracle/typed_oracle.d.ts.map +1 -1
  6. package/dest/acvm/oracle/typed_oracle.js +11 -5
  7. package/dest/avm/avm_execution_environment.d.ts +4 -3
  8. package/dest/avm/avm_execution_environment.d.ts.map +1 -1
  9. package/dest/avm/avm_execution_environment.js +7 -5
  10. package/dest/avm/avm_simulator.d.ts.map +1 -1
  11. package/dest/avm/avm_simulator.js +5 -4
  12. package/dest/avm/errors.d.ts +6 -0
  13. package/dest/avm/errors.d.ts.map +1 -1
  14. package/dest/avm/errors.js +10 -1
  15. package/dest/avm/fixtures/index.js +3 -3
  16. package/dest/avm/journal/journal.d.ts +2 -3
  17. package/dest/avm/journal/journal.d.ts.map +1 -1
  18. package/dest/avm/journal/journal.js +9 -14
  19. package/dest/avm/journal/nullifiers.d.ts +17 -5
  20. package/dest/avm/journal/nullifiers.d.ts.map +1 -1
  21. package/dest/avm/journal/nullifiers.js +27 -10
  22. package/dest/avm/journal/public_storage.d.ts +19 -6
  23. package/dest/avm/journal/public_storage.d.ts.map +1 -1
  24. package/dest/avm/journal/public_storage.js +30 -12
  25. package/dest/avm/journal/trace.js +9 -9
  26. package/dest/avm/opcodes/accrued_substate.d.ts.map +1 -1
  27. package/dest/avm/opcodes/accrued_substate.js +6 -7
  28. package/dest/avm/opcodes/external_calls.d.ts +2 -2
  29. package/dest/avm/opcodes/external_calls.d.ts.map +1 -1
  30. package/dest/avm/opcodes/external_calls.js +22 -11
  31. package/dest/avm/opcodes/storage.d.ts +0 -7
  32. package/dest/avm/opcodes/storage.d.ts.map +1 -1
  33. package/dest/avm/opcodes/storage.js +3 -12
  34. package/dest/client/client_execution_context.d.ts +35 -17
  35. package/dest/client/client_execution_context.d.ts.map +1 -1
  36. package/dest/client/client_execution_context.js +70 -33
  37. package/dest/client/db_oracle.d.ts +10 -11
  38. package/dest/client/db_oracle.d.ts.map +1 -1
  39. package/dest/client/execution_note_cache.d.ts +17 -0
  40. package/dest/client/execution_note_cache.d.ts.map +1 -1
  41. package/dest/client/execution_note_cache.js +25 -2
  42. package/dest/client/execution_result.d.ts +11 -0
  43. package/dest/client/execution_result.d.ts.map +1 -1
  44. package/dest/client/execution_result.js +21 -3
  45. package/dest/client/private_execution.d.ts.map +1 -1
  46. package/dest/client/private_execution.js +4 -1
  47. package/dest/client/simulator.d.ts.map +1 -1
  48. package/dest/client/simulator.js +6 -6
  49. package/dest/client/view_data_oracle.d.ts +11 -10
  50. package/dest/client/view_data_oracle.d.ts.map +1 -1
  51. package/dest/client/view_data_oracle.js +16 -12
  52. package/dest/common/index.d.ts +1 -0
  53. package/dest/common/index.d.ts.map +1 -1
  54. package/dest/common/index.js +2 -1
  55. package/dest/common/return_values.d.ts +11 -0
  56. package/dest/common/return_values.d.ts.map +1 -0
  57. package/dest/common/return_values.js +13 -0
  58. package/dest/mocks/fixtures.d.ts +2 -1
  59. package/dest/mocks/fixtures.d.ts.map +1 -1
  60. package/dest/mocks/fixtures.js +2 -3
  61. package/dest/public/abstract_phase_manager.d.ts +3 -3
  62. package/dest/public/abstract_phase_manager.d.ts.map +1 -1
  63. package/dest/public/abstract_phase_manager.js +17 -10
  64. package/dest/public/app_logic_phase_manager.d.ts +1 -1
  65. package/dest/public/execution.d.ts +2 -6
  66. package/dest/public/execution.d.ts.map +1 -1
  67. package/dest/public/execution.js +1 -1
  68. package/dest/public/executor.d.ts.map +1 -1
  69. package/dest/public/executor.js +11 -8
  70. package/dest/public/hints_builder.d.ts +2 -2
  71. package/dest/public/hints_builder.d.ts.map +1 -1
  72. package/dest/public/hints_builder.js +4 -4
  73. package/dest/public/public_processor.d.ts +2 -2
  74. package/dest/public/public_processor.d.ts.map +1 -1
  75. package/dest/public/public_processor.js +5 -5
  76. package/dest/public/setup_phase_manager.d.ts +1 -1
  77. package/dest/public/setup_phase_manager.js +2 -2
  78. package/dest/public/tail_phase_manager.d.ts +1 -1
  79. package/dest/public/tail_phase_manager.d.ts.map +1 -1
  80. package/dest/public/tail_phase_manager.js +4 -4
  81. package/dest/public/teardown_phase_manager.d.ts +1 -1
  82. package/dest/public/teardown_phase_manager.js +2 -2
  83. package/dest/public/transitional_adaptors.d.ts +2 -1
  84. package/dest/public/transitional_adaptors.d.ts.map +1 -1
  85. package/dest/public/transitional_adaptors.js +17 -3
  86. package/dest/public/utils.js +3 -3
  87. package/package.json +8 -8
  88. package/src/acvm/oracle/oracle.ts +26 -23
  89. package/src/acvm/oracle/typed_oracle.ts +15 -15
  90. package/src/avm/avm_execution_environment.ts +9 -5
  91. package/src/avm/avm_simulator.ts +5 -3
  92. package/src/avm/errors.ts +10 -0
  93. package/src/avm/fixtures/index.ts +2 -2
  94. package/src/avm/journal/journal.ts +14 -18
  95. package/src/avm/journal/nullifiers.ts +27 -14
  96. package/src/avm/journal/public_storage.ts +30 -16
  97. package/src/avm/journal/trace.ts +8 -8
  98. package/src/avm/opcodes/accrued_substate.ts +5 -6
  99. package/src/avm/opcodes/external_calls.ts +23 -9
  100. package/src/avm/opcodes/storage.ts +2 -12
  101. package/src/client/client_execution_context.ts +75 -37
  102. package/src/client/db_oracle.ts +10 -11
  103. package/src/client/execution_note_cache.ts +29 -1
  104. package/src/client/execution_result.ts +26 -2
  105. package/src/client/private_execution.ts +3 -0
  106. package/src/client/simulator.ts +4 -5
  107. package/src/client/view_data_oracle.ts +18 -13
  108. package/src/common/index.ts +1 -0
  109. package/src/common/return_values.ts +18 -0
  110. package/src/mocks/fixtures.ts +2 -2
  111. package/src/public/abstract_phase_manager.ts +21 -15
  112. package/src/public/execution.ts +2 -6
  113. package/src/public/executor.ts +14 -7
  114. package/src/public/hints_builder.ts +11 -3
  115. package/src/public/public_processor.ts +7 -7
  116. package/src/public/setup_phase_manager.ts +1 -1
  117. package/src/public/tail_phase_manager.ts +5 -7
  118. package/src/public/teardown_phase_manager.ts +1 -1
  119. package/src/public/transitional_adaptors.ts +17 -2
  120. package/src/public/utils.ts +2 -2
  121. package/dest/client/logs_cache.d.ts +0 -33
  122. package/dest/client/logs_cache.d.ts.map +0 -1
  123. package/dest/client/logs_cache.js +0 -59
  124. package/src/client/logs_cache.ts +0 -65
@@ -1,9 +1,10 @@
1
1
  import { type PublicKernelRequest, PublicKernelType, type Tx } from '@aztec/circuit-types';
2
2
  import {
3
- Fr,
3
+ type Fr,
4
4
  type GlobalVariables,
5
5
  type Header,
6
6
  type KernelCircuitPublicInputs,
7
+ type LogHash,
7
8
  MAX_NEW_NOTE_HASHES_PER_TX,
8
9
  MAX_NEW_NULLIFIERS_PER_TX,
9
10
  MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_TX,
@@ -12,7 +13,6 @@ import {
12
13
  type Proof,
13
14
  type PublicKernelCircuitPublicInputs,
14
15
  PublicKernelTailCircuitPrivateInputs,
15
- SideEffect,
16
16
  makeEmptyProof,
17
17
  mergeAccumulatedData,
18
18
  sortByCounter,
@@ -70,7 +70,7 @@ export class TailPhaseManager extends AbstractPhaseManager {
70
70
  finalKernelOutput,
71
71
  publicKernelProof: makeEmptyProof(),
72
72
  revertReason: undefined,
73
- returnValues: undefined,
73
+ returnValues: [],
74
74
  gasUsed: undefined,
75
75
  };
76
76
  }
@@ -159,10 +159,8 @@ export class TailPhaseManager extends AbstractPhaseManager {
159
159
  return sortByCounter(noteHashes).map(n => n.value) as Tuple<Fr, N>;
160
160
  }
161
161
 
162
- private sortLogsHashes<N extends number>(unencryptedLogsHashes: Tuple<SideEffect, N>): Tuple<SideEffect, N> {
162
+ private sortLogsHashes<N extends number>(unencryptedLogsHashes: Tuple<LogHash, N>): Tuple<LogHash, N> {
163
163
  // TODO(6052): logs here may have duplicate counters from nested calls
164
- return sortByCounter(
165
- unencryptedLogsHashes.map(n => ({ ...n, counter: n.counter.toNumber(), isEmpty: () => n.isEmpty() })),
166
- ).map(h => new SideEffect(h.value, new Fr(h.counter))) as Tuple<SideEffect, N>;
164
+ return sortByCounter(unencryptedLogsHashes);
167
165
  }
168
166
  }
@@ -71,7 +71,7 @@ export class TeardownPhaseManager extends AbstractPhaseManager {
71
71
  publicKernelOutput,
72
72
  publicKernelProof,
73
73
  revertReason,
74
- returnValues: undefined,
74
+ returnValues: [],
75
75
  gasUsed,
76
76
  };
77
77
  }
@@ -10,6 +10,9 @@ import {
10
10
  } from '@aztec/circuits.js';
11
11
  import { Fr } from '@aztec/foundation/fields';
12
12
 
13
+ import { promisify } from 'util';
14
+ import { gunzip } from 'zlib';
15
+
13
16
  import { type AvmContext } from '../avm/avm_context.js';
14
17
  import { AvmExecutionEnvironment } from '../avm/avm_execution_environment.js';
15
18
  import { type AvmContractCallResults } from '../avm/avm_message_call_result.js';
@@ -111,7 +114,19 @@ export function markBytecodeAsAvm(bytecode: Buffer): Buffer {
111
114
  return Buffer.concat([bytecode, AVM_MAGIC_SUFFIX]);
112
115
  }
113
116
 
114
- export function isAvmBytecode(bytecode: Buffer): boolean {
117
+ // This is just a helper function for the AVM circuit.
118
+ export async function decompressBytecodeIfCompressed(bytecode: Buffer): Promise<Buffer> {
119
+ try {
120
+ return await promisify(gunzip)(bytecode);
121
+ } catch {
122
+ // If the bytecode is not compressed, the gunzip call will throw an error
123
+ // In this case, we assume the bytecode is not compressed and continue.
124
+ return Promise.resolve(bytecode);
125
+ }
126
+ }
127
+
128
+ export async function isAvmBytecode(bytecode: Buffer): Promise<boolean> {
129
+ const decompressedBytecode = await decompressBytecodeIfCompressed(bytecode);
115
130
  const magicSize = AVM_MAGIC_SUFFIX.length;
116
- return bytecode.subarray(-magicSize).equals(AVM_MAGIC_SUFFIX);
131
+ return decompressedBytecode.subarray(-magicSize).equals(AVM_MAGIC_SUFFIX);
117
132
  }
@@ -11,6 +11,7 @@ export function lastSideEffectCounter(tx: Tx): number {
11
11
  const sideEffectCounters = [
12
12
  ...data.endNonRevertibleData.newNoteHashes,
13
13
  ...data.endNonRevertibleData.newNullifiers,
14
+ ...data.endNonRevertibleData.unencryptedLogsHashes,
14
15
  ...data.endNonRevertibleData.publicCallStack,
15
16
  ...data.end.newNoteHashes,
16
17
  ...data.end.newNullifiers,
@@ -24,8 +25,7 @@ export function lastSideEffectCounter(tx: Tx): number {
24
25
  // look at both start and end counters because for enqueued public calls start > 0 while end === 0
25
26
  max = Math.max(max, sideEffect.startSideEffectCounter.toNumber(), sideEffect.endSideEffectCounter.toNumber());
26
27
  } else {
27
- const counter = typeof sideEffect.counter === 'number' ? sideEffect.counter : sideEffect.counter.toNumber();
28
- max = Math.max(max, counter);
28
+ max = Math.max(max, sideEffect.counter);
29
29
  }
30
30
  }
31
31
 
@@ -1,33 +0,0 @@
1
- import { type EncryptedL2Log, type UnencryptedL2Log } from '@aztec/circuit-types';
2
- /**
3
- * Log data that's accessible by all the function calls in an execution.
4
- * This class exists to:
5
- * 1. Keep track of logs emitted through nested calls in the correct order.
6
- * 2. TODO(1641): Remove encrypted logs based on notes nullified in the same scope.
7
- */
8
- export declare class LogsCache {
9
- /**
10
- * Logs notes created in this transaction.
11
- */
12
- private encryptedLogs;
13
- private unencryptedLogs;
14
- /**
15
- * Add a new encrypted log to cache.
16
- * @param log - New log created during execution.
17
- */
18
- addEncryptedLog(log: EncryptedL2Log): void;
19
- /**
20
- * Add a new unencrypted log to cache.
21
- * @param log - New log created during execution.
22
- */
23
- addUnencryptedLog(log: UnencryptedL2Log): void;
24
- /**
25
- * Return the encrypted logs.
26
- */
27
- getEncryptedLogs(): EncryptedL2Log[];
28
- /**
29
- * Return the encrypted logs.
30
- */
31
- getUnencryptedLogs(): UnencryptedL2Log[];
32
- }
33
- //# sourceMappingURL=logs_cache.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"logs_cache.d.ts","sourceRoot":"","sources":["../../src/client/logs_cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAElF;;;;;GAKG;AACH,qBAAa,SAAS;IACpB;;OAEG;IACH,OAAO,CAAC,aAAa,CAAwB;IAC7C,OAAO,CAAC,eAAe,CAA0B;IAsBjD;;;OAGG;IACI,eAAe,CAAC,GAAG,EAAE,cAAc;IAI1C;;;OAGG;IACI,iBAAiB,CAAC,GAAG,EAAE,gBAAgB;IAI9C;;OAEG;IACI,gBAAgB;IAIvB;;OAEG;IACI,kBAAkB;CAG1B"}
@@ -1,59 +0,0 @@
1
- /**
2
- * Log data that's accessible by all the function calls in an execution.
3
- * This class exists to:
4
- * 1. Keep track of logs emitted through nested calls in the correct order.
5
- * 2. TODO(1641): Remove encrypted logs based on notes nullified in the same scope.
6
- */
7
- export class LogsCache {
8
- constructor() {
9
- /**
10
- * Logs notes created in this transaction.
11
- */
12
- this.encryptedLogs = [];
13
- this.unencryptedLogs = [];
14
- }
15
- // TODO Separate encrypted logs linked to note hashes and arbitrary logs:
16
- // Maps from note hash to encrypted log - useful for removing transient logs
17
- // private encryptedLogsLinkedToNotes: Map<bigint, EncryptedL2Log> = new Map();
18
- // /**
19
- // * Remove the encrypted log for a nullified note.
20
- // * This fn should only be called if the note's innerNoteHash != 0.
21
- // * @param noteHashCounter - Side effect counter of the note.
22
- // */
23
- // public nullifyNote(noteHashCounter: Fr) {
24
- // // Find and remove the matching new note if the emitted innerNoteHash is not empty.
25
- // const log = this.encryptedLogsLinkedToNotes.get(noteHashCounter.toBigInt()) ?? false;
26
- // // TODO: throw here? Will the log always be here?
27
- // if (!log) {
28
- // throw new Error('Attempt to remove a pending note log that does not exist.');
29
- // }
30
- // this.encryptedLogsLinkedToNotes.delete(noteHashCounter.toBigInt());
31
- // }
32
- /**
33
- * Add a new encrypted log to cache.
34
- * @param log - New log created during execution.
35
- */
36
- addEncryptedLog(log) {
37
- this.encryptedLogs.push(log);
38
- }
39
- /**
40
- * Add a new unencrypted log to cache.
41
- * @param log - New log created during execution.
42
- */
43
- addUnencryptedLog(log) {
44
- this.unencryptedLogs.push(log);
45
- }
46
- /**
47
- * Return the encrypted logs.
48
- */
49
- getEncryptedLogs() {
50
- return this.encryptedLogs;
51
- }
52
- /**
53
- * Return the encrypted logs.
54
- */
55
- getUnencryptedLogs() {
56
- return this.unencryptedLogs;
57
- }
58
- }
59
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibG9nc19jYWNoZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9jbGllbnQvbG9nc19jYWNoZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFFQTs7Ozs7R0FLRztBQUNILE1BQU0sT0FBTyxTQUFTO0lBQXRCO1FBQ0U7O1dBRUc7UUFDSyxrQkFBYSxHQUFxQixFQUFFLENBQUM7UUFDckMsb0JBQWUsR0FBdUIsRUFBRSxDQUFDO0lBbURuRCxDQUFDO0lBakRDLHlFQUF5RTtJQUV6RSw0RUFBNEU7SUFDNUUsK0VBQStFO0lBRS9FLE1BQU07SUFDTixvREFBb0Q7SUFDcEQscUVBQXFFO0lBQ3JFLCtEQUErRDtJQUMvRCxNQUFNO0lBQ04sNENBQTRDO0lBQzVDLHVGQUF1RjtJQUN2Rix5RkFBeUY7SUFDekYscURBQXFEO0lBQ3JELGVBQWU7SUFDZixtRkFBbUY7SUFDbkYsS0FBSztJQUNMLHVFQUF1RTtJQUN2RSxJQUFJO0lBRUo7OztPQUdHO0lBQ0ksZUFBZSxDQUFDLEdBQW1CO1FBQ3hDLElBQUksQ0FBQyxhQUFhLENBQUMsSUFBSSxDQUFDLEdBQUcsQ0FBQyxDQUFDO0lBQy9CLENBQUM7SUFFRDs7O09BR0c7SUFDSSxpQkFBaUIsQ0FBQyxHQUFxQjtRQUM1QyxJQUFJLENBQUMsZUFBZSxDQUFDLElBQUksQ0FBQyxHQUFHLENBQUMsQ0FBQztJQUNqQyxDQUFDO0lBRUQ7O09BRUc7SUFDSSxnQkFBZ0I7UUFDckIsT0FBTyxJQUFJLENBQUMsYUFBYSxDQUFDO0lBQzVCLENBQUM7SUFFRDs7T0FFRztJQUNJLGtCQUFrQjtRQUN2QixPQUFPLElBQUksQ0FBQyxlQUFlLENBQUM7SUFDOUIsQ0FBQztDQUNGIn0=
@@ -1,65 +0,0 @@
1
- import { type EncryptedL2Log, type UnencryptedL2Log } from '@aztec/circuit-types';
2
-
3
- /**
4
- * Log data that's accessible by all the function calls in an execution.
5
- * This class exists to:
6
- * 1. Keep track of logs emitted through nested calls in the correct order.
7
- * 2. TODO(1641): Remove encrypted logs based on notes nullified in the same scope.
8
- */
9
- export class LogsCache {
10
- /**
11
- * Logs notes created in this transaction.
12
- */
13
- private encryptedLogs: EncryptedL2Log[] = [];
14
- private unencryptedLogs: UnencryptedL2Log[] = [];
15
-
16
- // TODO Separate encrypted logs linked to note hashes and arbitrary logs:
17
-
18
- // Maps from note hash to encrypted log - useful for removing transient logs
19
- // private encryptedLogsLinkedToNotes: Map<bigint, EncryptedL2Log> = new Map();
20
-
21
- // /**
22
- // * Remove the encrypted log for a nullified note.
23
- // * This fn should only be called if the note's innerNoteHash != 0.
24
- // * @param noteHashCounter - Side effect counter of the note.
25
- // */
26
- // public nullifyNote(noteHashCounter: Fr) {
27
- // // Find and remove the matching new note if the emitted innerNoteHash is not empty.
28
- // const log = this.encryptedLogsLinkedToNotes.get(noteHashCounter.toBigInt()) ?? false;
29
- // // TODO: throw here? Will the log always be here?
30
- // if (!log) {
31
- // throw new Error('Attempt to remove a pending note log that does not exist.');
32
- // }
33
- // this.encryptedLogsLinkedToNotes.delete(noteHashCounter.toBigInt());
34
- // }
35
-
36
- /**
37
- * Add a new encrypted log to cache.
38
- * @param log - New log created during execution.
39
- */
40
- public addEncryptedLog(log: EncryptedL2Log) {
41
- this.encryptedLogs.push(log);
42
- }
43
-
44
- /**
45
- * Add a new unencrypted log to cache.
46
- * @param log - New log created during execution.
47
- */
48
- public addUnencryptedLog(log: UnencryptedL2Log) {
49
- this.unencryptedLogs.push(log);
50
- }
51
-
52
- /**
53
- * Return the encrypted logs.
54
- */
55
- public getEncryptedLogs() {
56
- return this.encryptedLogs;
57
- }
58
-
59
- /**
60
- * Return the encrypted logs.
61
- */
62
- public getUnencryptedLogs() {
63
- return this.unencryptedLogs;
64
- }
65
- }