@aztec/simulator 0.87.5 → 0.87.7

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 (129) hide show
  1. package/dest/client.d.ts +5 -3
  2. package/dest/client.d.ts.map +1 -1
  3. package/dest/client.js +4 -2
  4. package/dest/private/acvm/acvm.d.ts +5 -2
  5. package/dest/private/acvm/acvm.d.ts.map +1 -1
  6. package/dest/private/acvm/index.d.ts +0 -1
  7. package/dest/private/acvm/index.d.ts.map +1 -1
  8. package/dest/private/acvm/index.js +0 -1
  9. package/dest/private/{providers/acvm_native.d.ts → acvm_native.d.ts} +4 -4
  10. package/dest/private/acvm_native.d.ts.map +1 -0
  11. package/dest/private/{providers/acvm_wasm.d.ts → acvm_wasm.d.ts} +4 -4
  12. package/dest/private/acvm_wasm.d.ts.map +1 -0
  13. package/dest/private/{providers/acvm_wasm.js → acvm_wasm.js} +2 -2
  14. package/dest/private/{providers/acvm_wasm_with_blobs.d.ts → acvm_wasm_with_blobs.d.ts} +5 -5
  15. package/dest/private/acvm_wasm_with_blobs.d.ts.map +1 -0
  16. package/dest/private/{providers/acvm_wasm_with_blobs.js → acvm_wasm_with_blobs.js} +2 -2
  17. package/dest/private/{providers/circuit_recording → circuit_recording}/circuit_recorder.d.ts +41 -21
  18. package/dest/private/circuit_recording/circuit_recorder.d.ts.map +1 -0
  19. package/dest/private/circuit_recording/circuit_recorder.js +209 -0
  20. package/dest/private/circuit_recording/file_circuit_recorder.d.ts +31 -0
  21. package/dest/private/circuit_recording/file_circuit_recorder.d.ts.map +1 -0
  22. package/dest/private/circuit_recording/file_circuit_recorder.js +135 -0
  23. package/dest/private/circuit_recording/memory_circuit_recorder.d.ts +5 -0
  24. package/dest/private/circuit_recording/memory_circuit_recorder.d.ts.map +1 -0
  25. package/dest/private/circuit_recording/memory_circuit_recorder.js +9 -0
  26. package/dest/private/{providers/circuit_recording/simulation_provider_recorder_wrapper.d.ts → circuit_recording/simulator_recorder_wrapper.d.ts} +9 -7
  27. package/dest/private/circuit_recording/simulator_recorder_wrapper.d.ts.map +1 -0
  28. package/dest/private/{providers/circuit_recording/simulation_provider_recorder_wrapper.js → circuit_recording/simulator_recorder_wrapper.js} +18 -13
  29. package/dest/private/{providers/simulation_provider.d.ts → circuit_simulator.d.ts} +4 -4
  30. package/dest/private/circuit_simulator.d.ts.map +1 -0
  31. package/dest/private/{providers/simulation_provider.js → circuit_simulator.js} +1 -1
  32. package/dest/private/factory.d.ts +12 -0
  33. package/dest/private/factory.d.ts.map +1 -0
  34. package/dest/private/{providers/factory.js → factory.js} +2 -2
  35. package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts +1 -0
  36. package/dest/public/avm/fixtures/base_avm_simulation_tester.d.ts.map +1 -1
  37. package/dest/public/avm/fixtures/base_avm_simulation_tester.js +6 -0
  38. package/dest/public/public_tx_simulator/apps_tests/amm_test.d.ts.map +1 -1
  39. package/dest/public/public_tx_simulator/apps_tests/amm_test.js +27 -55
  40. package/dest/server.d.ts +6 -3
  41. package/dest/server.d.ts.map +1 -1
  42. package/dest/server.js +5 -2
  43. package/dest/testing.d.ts +1 -1
  44. package/dest/testing.d.ts.map +1 -1
  45. package/dest/testing.js +1 -1
  46. package/package.json +15 -15
  47. package/src/client.ts +5 -3
  48. package/src/private/acvm/acvm.ts +5 -3
  49. package/src/private/acvm/index.ts +0 -1
  50. package/src/private/{providers/acvm_native.ts → acvm_native.ts} +4 -4
  51. package/src/private/{providers/acvm_wasm.ts → acvm_wasm.ts} +4 -4
  52. package/src/private/{providers/acvm_wasm_with_blobs.ts → acvm_wasm_with_blobs.ts} +5 -5
  53. package/src/private/circuit_recording/circuit_recorder.ts +260 -0
  54. package/src/private/circuit_recording/file_circuit_recorder.ts +158 -0
  55. package/src/private/circuit_recording/memory_circuit_recorder.ts +11 -0
  56. package/src/private/{providers/circuit_recording/simulation_provider_recorder_wrapper.ts → circuit_recording/simulator_recorder_wrapper.ts} +26 -18
  57. package/src/private/{providers/simulation_provider.ts → circuit_simulator.ts} +3 -3
  58. package/src/private/{providers/factory.ts → factory.ts} +6 -6
  59. package/src/public/avm/fixtures/base_avm_simulation_tester.ts +5 -0
  60. package/src/public/public_tx_simulator/apps_tests/amm_test.ts +49 -44
  61. package/src/server.ts +6 -3
  62. package/src/testing.ts +1 -1
  63. package/dest/private/acvm/oracle/index.d.ts +0 -14
  64. package/dest/private/acvm/oracle/index.d.ts.map +0 -1
  65. package/dest/private/acvm/oracle/index.js +0 -2
  66. package/dest/private/acvm/oracle/oracle.d.ts +0 -52
  67. package/dest/private/acvm/oracle/oracle.d.ts.map +0 -1
  68. package/dest/private/acvm/oracle/oracle.js +0 -312
  69. package/dest/private/acvm/oracle/typed_oracle.d.ts +0 -83
  70. package/dest/private/acvm/oracle/typed_oracle.d.ts.map +0 -1
  71. package/dest/private/acvm/oracle/typed_oracle.js +0 -138
  72. package/dest/private/execution_data_provider.d.ts +0 -301
  73. package/dest/private/execution_data_provider.d.ts.map +0 -1
  74. package/dest/private/execution_data_provider.js +0 -14
  75. package/dest/private/execution_note_cache.d.ts +0 -93
  76. package/dest/private/execution_note_cache.d.ts.map +0 -1
  77. package/dest/private/execution_note_cache.js +0 -180
  78. package/dest/private/hashed_values_cache.d.ts +0 -28
  79. package/dest/private/hashed_values_cache.d.ts.map +0 -1
  80. package/dest/private/hashed_values_cache.js +0 -36
  81. package/dest/private/index.d.ts +0 -16
  82. package/dest/private/index.d.ts.map +0 -1
  83. package/dest/private/index.js +0 -15
  84. package/dest/private/message_load_oracle_inputs.d.ts +0 -19
  85. package/dest/private/message_load_oracle_inputs.d.ts.map +0 -1
  86. package/dest/private/message_load_oracle_inputs.js +0 -24
  87. package/dest/private/pick_notes.d.ts +0 -85
  88. package/dest/private/pick_notes.d.ts.map +0 -1
  89. package/dest/private/pick_notes.js +0 -51
  90. package/dest/private/private_execution.d.ts +0 -25
  91. package/dest/private/private_execution.d.ts.map +0 -1
  92. package/dest/private/private_execution.js +0 -95
  93. package/dest/private/private_execution_oracle.d.ts +0 -187
  94. package/dest/private/private_execution_oracle.d.ts.map +0 -1
  95. package/dest/private/private_execution_oracle.js +0 -318
  96. package/dest/private/providers/acvm_native.d.ts.map +0 -1
  97. package/dest/private/providers/acvm_wasm.d.ts.map +0 -1
  98. package/dest/private/providers/acvm_wasm_with_blobs.d.ts.map +0 -1
  99. package/dest/private/providers/circuit_recording/circuit_recorder.d.ts.map +0 -1
  100. package/dest/private/providers/circuit_recording/circuit_recorder.js +0 -246
  101. package/dest/private/providers/circuit_recording/simulation_provider_recorder_wrapper.d.ts.map +0 -1
  102. package/dest/private/providers/factory.d.ts +0 -12
  103. package/dest/private/providers/factory.d.ts.map +0 -1
  104. package/dest/private/providers/simulation_provider.d.ts.map +0 -1
  105. package/dest/private/simulator.d.ts +0 -36
  106. package/dest/private/simulator.d.ts.map +0 -1
  107. package/dest/private/simulator.js +0 -104
  108. package/dest/private/utility_execution_oracle.d.ts +0 -163
  109. package/dest/private/utility_execution_oracle.d.ts.map +0 -1
  110. package/dest/private/utility_execution_oracle.js +0 -257
  111. package/dest/test/utils.d.ts +0 -13
  112. package/dest/test/utils.d.ts.map +0 -1
  113. package/dest/test/utils.js +0 -22
  114. package/src/private/acvm/oracle/index.ts +0 -16
  115. package/src/private/acvm/oracle/oracle.ts +0 -523
  116. package/src/private/acvm/oracle/typed_oracle.ts +0 -273
  117. package/src/private/execution_data_provider.ts +0 -388
  118. package/src/private/execution_note_cache.ts +0 -217
  119. package/src/private/hashed_values_cache.ts +0 -47
  120. package/src/private/index.ts +0 -19
  121. package/src/private/message_load_oracle_inputs.ts +0 -23
  122. package/src/private/pick_notes.ts +0 -141
  123. package/src/private/private_execution.ts +0 -159
  124. package/src/private/private_execution_oracle.ts +0 -508
  125. package/src/private/providers/circuit_recording/circuit_recorder.ts +0 -283
  126. package/src/private/simulator.ts +0 -170
  127. package/src/private/utility_execution_oracle.ts +0 -384
  128. package/src/test/utils.ts +0 -36
  129. /package/dest/private/{providers/acvm_native.js → acvm_native.js} +0 -0
@@ -1 +0,0 @@
1
- {"version":3,"file":"execution_note_cache.d.ts","sourceRoot":"","sources":["../../src/private/execution_note_cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAC9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAGhE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAEhD,UAAU,WAAW;IACnB,IAAI,EAAE,QAAQ,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,sBAAsB,EAAE,EAAE,CAAC;CAC5B;AAED;;GAEG;AACH,qBAAa,kBAAkB;;IAiCjB,OAAO,CAAC,QAAQ,CAAC,aAAa;IAhC1C;;;OAGG;IACH,OAAO,CAAC,KAAK,CAAqB;IAClC;;OAEG;IACH,OAAO,CAAC,OAAO,CAAyC;IAExD;;;;OAIG;IACH,OAAO,CAAC,YAAY,CAAuC;IAE3D;;OAEG;IACH,OAAO,CAAC,aAAa,CAA0B;IAE/C,OAAO,CAAC,8BAA8B,CAAK;IAE3C,OAAO,CAAC,iBAAiB,CAAS;IAElC;;;OAGG;IACH,OAAO,CAAC,0BAA0B,CAAQ;gBAEb,aAAa,EAAE,EAAE;IAE9C;;;OAGG;IACU,iCAAiC,CAAC,8BAA8B,EAAE,MAAM;IAwC9E,MAAM;;;IAWb;;;OAGG;IACI,UAAU,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM;IAWjD;;;;;;OAMG;IACU,WAAW,CAAC,eAAe,EAAE,YAAY,EAAE,cAAc,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE;IA2BxF;;;;OAIG;IACU,gBAAgB,CAAC,eAAe,EAAE,YAAY,EAAE,cAAc,EAAE,EAAE;IAK/E;;;;;QAKI;IACG,QAAQ,CAAC,eAAe,EAAE,YAAY,EAAE,WAAW,EAAE,EAAE;IAK9D;;;;;QAKI;IACG,eAAe,CAAC,eAAe,EAAE,YAAY,EAAE,QAAQ,EAAE,EAAE;IAKlE;;;OAGG;IACI,aAAa,CAAC,eAAe,EAAE,YAAY,GAAG,GAAG,CAAC,MAAM,CAAC;IAYhE,WAAW,IAAI,WAAW,EAAE;IAI5B,gBAAgB,IAAI,EAAE,EAAE;IAIxB,eAAe,CAAC,eAAe,EAAE,YAAY,EAAE,eAAe,EAAE,EAAE;CAMnE"}
@@ -1,180 +0,0 @@
1
- import { Fr } from '@aztec/foundation/fields';
2
- import { computeNoteHashNonce, computeUniqueNoteHash, siloNoteHash, siloNullifier } from '@aztec/stdlib/hash';
3
- /**
4
- * Data that's accessible by all the function calls in an execution.
5
- */ export class ExecutionNoteCache {
6
- txRequestHash;
7
- /**
8
- * New notes created in this transaction.
9
- * They are pushed to this array in the same order as they are emitted.
10
- */ notes;
11
- /**
12
- * This mapping maps from a contract address to the notes in the contract.
13
- */ noteMap;
14
- /**
15
- * This maps from a contract address to the nullifiers emitted from the contract.
16
- * The note which is nullified might be new or not (i.e., was generated in a previous transaction).
17
- * Note that their value (bigint representation) is used because Frs cannot be looked up in Sets.
18
- */ nullifierMap;
19
- /**
20
- * All nullifiers emitted in this transaction.
21
- */ allNullifiers;
22
- minRevertibleSideEffectCounter;
23
- inRevertiblePhase;
24
- /**
25
- * We don't need to use the tx request hash for nonces if another non revertible nullifier is emitted.
26
- * In that case we disable injecting the tx request hash as a nullifier.
27
- */ usedTxRequestHashForNonces;
28
- constructor(txRequestHash){
29
- this.txRequestHash = txRequestHash;
30
- this.notes = [];
31
- this.noteMap = new Map();
32
- this.nullifierMap = new Map();
33
- this.allNullifiers = new Set();
34
- this.minRevertibleSideEffectCounter = 0;
35
- this.inRevertiblePhase = false;
36
- this.usedTxRequestHashForNonces = true;
37
- }
38
- /**
39
- * Enters the revertible phase of the transaction.
40
- * @param minRevertibleSideEffectCounter - The counter at which the transaction enters the revertible phase.
41
- */ async setMinRevertibleSideEffectCounter(minRevertibleSideEffectCounter) {
42
- if (this.inRevertiblePhase) {
43
- throw new Error(`Cannot enter the revertible phase twice. Current counter: ${minRevertibleSideEffectCounter}. Previous enter counter: ${this.minRevertibleSideEffectCounter}`);
44
- }
45
- this.inRevertiblePhase = true;
46
- this.minRevertibleSideEffectCounter = minRevertibleSideEffectCounter;
47
- let nonceGenerator = this.txRequestHash;
48
- const nullifiers = this.getAllNullifiers();
49
- if (nullifiers.length > 0) {
50
- nonceGenerator = new Fr(nullifiers[0]);
51
- this.usedTxRequestHashForNonces = false;
52
- }
53
- // The existing pending notes are all non-revertible.
54
- // They cannot be squashed by nullifiers emitted after minRevertibleSideEffectCounter is set.
55
- // Their indexes in the tx are known at this point and won't change. So we can assign a nonce to each one of them.
56
- // The nonces will be used to create the "complete" nullifier.
57
- const updatedNotes = await Promise.all(this.notes.map(async ({ note, counter }, i)=>{
58
- const nonce = await computeNoteHashNonce(nonceGenerator, i);
59
- const uniqueNoteHash = await computeUniqueNoteHash(nonce, await siloNoteHash(note.contractAddress, note.noteHash));
60
- return {
61
- counter,
62
- note: {
63
- ...note,
64
- nonce
65
- },
66
- noteHashForConsumption: uniqueNoteHash
67
- };
68
- }));
69
- // Rebuild the data.
70
- this.notes = [];
71
- this.noteMap = new Map();
72
- updatedNotes.forEach((n)=>this.#addNote(n));
73
- }
74
- finish() {
75
- // If we never entered the revertible phase, we need to use the tx request hash as a nonce for the notes if no nullifiers have been emitted.
76
- if (!this.inRevertiblePhase) {
77
- this.usedTxRequestHashForNonces = this.getAllNullifiers().length === 0;
78
- }
79
- // If we entered the revertible phase, the nonce generator was decided based on wether or not a nullifier was emitted before entering.
80
- return {
81
- usedTxRequestHashForNonces: this.usedTxRequestHashForNonces
82
- };
83
- }
84
- /**
85
- * Add a new note to cache.
86
- * @param note - New note created during execution.
87
- */ addNewNote(note, counter) {
88
- const previousNote = this.notes[this.notes.length - 1];
89
- if (previousNote && previousNote.counter >= counter) {
90
- throw new Error(`Note hash counters must be strictly increasing. Current counter: ${counter}. Previous counter: ${previousNote.counter}.`);
91
- }
92
- this.#addNote({
93
- note,
94
- counter,
95
- noteHashForConsumption: note.noteHash
96
- });
97
- }
98
- /**
99
- * Add a nullifier to cache. It could be for a db note or a new note created during execution.
100
- * @param contractAddress - Contract address of the note.
101
- * @param innerNullifier - Inner nullifier of the note.
102
- * @param noteHash - A hash of the note. If this value equals 0, it means the note being nullified is from a previous
103
- * transaction (and thus not a new note).
104
- */ async nullifyNote(contractAddress, innerNullifier, noteHash) {
105
- const siloedNullifier = await siloNullifier(contractAddress, innerNullifier);
106
- let nullifiedNoteHashCounter = undefined;
107
- // Find and remove the matching new note and log(s) if the emitted noteHash is not empty.
108
- if (!noteHash.isEmpty()) {
109
- const notesInContract = this.noteMap.get(contractAddress.toBigInt()) ?? [];
110
- const noteIndexToRemove = notesInContract.findIndex((n)=>n.noteHashForConsumption.equals(noteHash));
111
- if (noteIndexToRemove === -1) {
112
- throw new Error('Attempt to remove a pending note that does not exist.');
113
- }
114
- const note = notesInContract.splice(noteIndexToRemove, 1)[0];
115
- nullifiedNoteHashCounter = note.counter;
116
- this.noteMap.set(contractAddress.toBigInt(), notesInContract);
117
- this.notes = this.notes.filter((n)=>n.counter !== note.counter);
118
- // If the note is non revertible and the nullifier was emitted in the revertible phase, both the note hash and the nullifier will be emitted
119
- if (this.inRevertiblePhase && note.counter < this.minRevertibleSideEffectCounter) {
120
- this.recordNullifier(contractAddress, siloedNullifier);
121
- }
122
- } else {
123
- // If the note being nullified comes from a previous tx the nullifier will be emitted.
124
- this.recordNullifier(contractAddress, siloedNullifier);
125
- }
126
- return nullifiedNoteHashCounter;
127
- }
128
- /**
129
- * Adds a nullifier to the cache. Note cache needs to track all nullifiers to decide which nullifier to use for note siloing.
130
- * @param contractAddress - Contract address that emitted the nullifier.
131
- * @param innerNullifier
132
- */ async nullifierCreated(contractAddress, innerNullifier) {
133
- const siloedNullifier = await siloNullifier(contractAddress, innerNullifier);
134
- this.recordNullifier(contractAddress, siloedNullifier);
135
- }
136
- /**
137
- * Return notes created up to current point in execution.
138
- * If a nullifier for a note in this list is emitted, the note will be deleted.
139
- * @param contractAddress - Contract address of the notes.
140
- * @param storageSlot - Storage slot of the notes.
141
- **/ getNotes(contractAddress, storageSlot) {
142
- const notes = this.noteMap.get(contractAddress.toBigInt()) ?? [];
143
- return notes.filter((n)=>n.note.storageSlot.equals(storageSlot)).map((n)=>n.note);
144
- }
145
- /**
146
- * Check if a note exists in the newNotes array.
147
- * @param contractAddress - Contract address of the note.
148
- * @param storageSlot - Storage slot of the note.
149
- * @param noteHash - A hash of the note.
150
- **/ checkNoteExists(contractAddress, noteHash) {
151
- const notes = this.noteMap.get(contractAddress.toBigInt()) ?? [];
152
- return notes.some((n)=>n.note.noteHash.equals(noteHash));
153
- }
154
- /**
155
- * Return all nullifiers emitted from a contract.
156
- * @param contractAddress - Address of the contract.
157
- */ getNullifiers(contractAddress) {
158
- return this.nullifierMap.get(contractAddress.toBigInt()) ?? new Set();
159
- }
160
- #addNote(note) {
161
- this.notes.push(note);
162
- const notes = this.noteMap.get(note.note.contractAddress.toBigInt()) ?? [];
163
- notes.push(note);
164
- this.noteMap.set(note.note.contractAddress.toBigInt(), notes);
165
- }
166
- getAllNotes() {
167
- return this.notes;
168
- }
169
- getAllNullifiers() {
170
- return [
171
- ...this.allNullifiers
172
- ].map((n)=>new Fr(n));
173
- }
174
- recordNullifier(contractAddress, siloedNullifier) {
175
- const nullifiers = this.getNullifiers(contractAddress);
176
- nullifiers.add(siloedNullifier.toBigInt());
177
- this.nullifierMap.set(contractAddress.toBigInt(), nullifiers);
178
- this.allNullifiers.add(siloedNullifier.toBigInt());
179
- }
180
- }
@@ -1,28 +0,0 @@
1
- import { Fr } from '@aztec/foundation/fields';
2
- import { HashedValues } from '@aztec/stdlib/tx';
3
- /**
4
- * A cache for hashed values (arguments, returns) during transaction execution.
5
- */
6
- export declare class HashedValuesCache {
7
- private cache;
8
- constructor(initialArguments?: HashedValues[]);
9
- /**
10
- * Creates a new hashed values cache.
11
- * @param initialArguments - The initial arguments to add to the cache.
12
- * @returns The new hashed values cache.
13
- */
14
- static create(initialArguments?: HashedValues[]): HashedValuesCache;
15
- /**
16
- * Gets preimage of a hash.
17
- * @param hash - The hash to get the preimage of.
18
- * @returns The preimage.
19
- */
20
- getPreimage(hash: Fr): Fr[] | undefined;
21
- /**
22
- * Stores values in cache and returns its hash.
23
- * @param values - The values to store.
24
- * @returns The hash of the values.
25
- */
26
- store(values: Fr[], hash: Fr): void;
27
- }
28
- //# sourceMappingURL=hashed_values_cache.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hashed_values_cache.d.ts","sourceRoot":"","sources":["../../src/private/hashed_values_cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEhD;;GAEG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,KAAK,CAAoB;gBAErB,gBAAgB,GAAE,YAAY,EAAO;IAOjD;;;;OAIG;WACW,MAAM,CAAC,gBAAgB,GAAE,YAAY,EAAO;IAI1D;;;;OAIG;IACI,WAAW,CAAC,IAAI,EAAE,EAAE,GAAG,EAAE,EAAE,GAAG,SAAS;IAQ9C;;;;OAIG;IACI,KAAK,CAAC,MAAM,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE;CAGpC"}
@@ -1,36 +0,0 @@
1
- /**
2
- * A cache for hashed values (arguments, returns) during transaction execution.
3
- */ export class HashedValuesCache {
4
- cache;
5
- constructor(initialArguments = []){
6
- this.cache = new Map();
7
- for (const initialArg of initialArguments){
8
- this.cache.set(initialArg.hash.toBigInt(), initialArg.values);
9
- }
10
- }
11
- /**
12
- * Creates a new hashed values cache.
13
- * @param initialArguments - The initial arguments to add to the cache.
14
- * @returns The new hashed values cache.
15
- */ static create(initialArguments = []) {
16
- return new HashedValuesCache(initialArguments);
17
- }
18
- /**
19
- * Gets preimage of a hash.
20
- * @param hash - The hash to get the preimage of.
21
- * @returns The preimage.
22
- */ getPreimage(hash) {
23
- if (hash.isEmpty()) {
24
- return [];
25
- } else {
26
- return this.cache.get(hash.toBigInt());
27
- }
28
- }
29
- /**
30
- * Stores values in cache and returns its hash.
31
- * @param values - The values to store.
32
- * @returns The hash of the values.
33
- */ store(values, hash) {
34
- this.cache.set(hash.toBigInt(), values);
35
- }
36
- }
@@ -1,16 +0,0 @@
1
- export { AcirSimulator } from './simulator.js';
2
- export { type ExecutionDataProvider, ContractClassNotFoundError, ContractNotFoundError, } from './execution_data_provider.js';
3
- export * from './pick_notes.js';
4
- export { ExecutionNoteCache } from './execution_note_cache.js';
5
- export { extractPrivateCircuitPublicInputs, readCurrentClassId } from './private_execution.js';
6
- export { witnessMapToFields } from './acvm/deserialize.js';
7
- export { toACVMWitness } from './acvm/serialize.js';
8
- export { executePrivateFunction } from './private_execution.js';
9
- export { PrivateExecutionOracle } from './private_execution_oracle.js';
10
- export { UtilityExecutionOracle } from './utility_execution_oracle.js';
11
- export { extractCallStack } from './acvm/acvm.js';
12
- export { type NoteData, TypedOracle } from './acvm/oracle/typed_oracle.js';
13
- export { Oracle } from './acvm/oracle/oracle.js';
14
- export { HashedValuesCache } from './hashed_values_cache.js';
15
- export { MessageLoadOracleInputs } from './message_load_oracle_inputs.js';
16
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/private/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EACL,KAAK,qBAAqB,EAC1B,0BAA0B,EAC1B,qBAAqB,GACtB,MAAM,8BAA8B,CAAC;AACtC,cAAc,iBAAiB,CAAC;AAChC,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,iCAAiC,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC/F,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,KAAK,QAAQ,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAC3E,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC"}
@@ -1,15 +0,0 @@
1
- export { AcirSimulator } from './simulator.js';
2
- export { ContractClassNotFoundError, ContractNotFoundError } from './execution_data_provider.js';
3
- export * from './pick_notes.js';
4
- export { ExecutionNoteCache } from './execution_note_cache.js';
5
- export { extractPrivateCircuitPublicInputs, readCurrentClassId } from './private_execution.js';
6
- export { witnessMapToFields } from './acvm/deserialize.js';
7
- export { toACVMWitness } from './acvm/serialize.js';
8
- export { executePrivateFunction } from './private_execution.js';
9
- export { PrivateExecutionOracle } from './private_execution_oracle.js';
10
- export { UtilityExecutionOracle } from './utility_execution_oracle.js';
11
- export { extractCallStack } from './acvm/acvm.js';
12
- export { TypedOracle } from './acvm/oracle/typed_oracle.js';
13
- export { Oracle } from './acvm/oracle/oracle.js';
14
- export { HashedValuesCache } from './hashed_values_cache.js';
15
- export { MessageLoadOracleInputs } from './message_load_oracle_inputs.js';
@@ -1,19 +0,0 @@
1
- import { Fr } from '@aztec/foundation/fields';
2
- import type { SiblingPath } from '@aztec/foundation/trees';
3
- export declare class MessageLoadOracleInputs<N extends number> {
4
- /** The index of the message commitment in the merkle tree. */
5
- index: bigint;
6
- /** The path in the merkle tree to the message. */
7
- siblingPath: SiblingPath<N>;
8
- constructor(
9
- /** The index of the message commitment in the merkle tree. */
10
- index: bigint,
11
- /** The path in the merkle tree to the message. */
12
- siblingPath: SiblingPath<N>);
13
- toFields(): Fr[];
14
- /**
15
- * Returns a representation of the public data witness as expected by intrinsic Noir deserialization.
16
- */
17
- toNoirRepresentation(): (string | string[])[];
18
- }
19
- //# sourceMappingURL=message_load_oracle_inputs.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"message_load_oracle_inputs.d.ts","sourceRoot":"","sources":["../../src/private/message_load_oracle_inputs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAC9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAE3D,qBAAa,uBAAuB,CAAC,CAAC,SAAS,MAAM;IAEjD,8DAA8D;IACvD,KAAK,EAAE,MAAM;IACpB,kDAAkD;IAC3C,WAAW,EAAE,WAAW,CAAC,CAAC,CAAC;;IAHlC,8DAA8D;IACvD,KAAK,EAAE,MAAM;IACpB,kDAAkD;IAC3C,WAAW,EAAE,WAAW,CAAC,CAAC,CAAC;IAGpC,QAAQ,IAAI,EAAE,EAAE;IAIhB;;OAEG;IACI,oBAAoB,IAAI,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC,EAAE;CAIrD"}
@@ -1,24 +0,0 @@
1
- import { Fr } from '@aztec/foundation/fields';
2
- export class MessageLoadOracleInputs {
3
- index;
4
- siblingPath;
5
- constructor(/** The index of the message commitment in the merkle tree. */ index, /** The path in the merkle tree to the message. */ siblingPath){
6
- this.index = index;
7
- this.siblingPath = siblingPath;
8
- }
9
- toFields() {
10
- return [
11
- new Fr(this.index),
12
- ...this.siblingPath.toFields()
13
- ];
14
- }
15
- /**
16
- * Returns a representation of the public data witness as expected by intrinsic Noir deserialization.
17
- */ toNoirRepresentation() {
18
- // TODO(#12874): remove the stupid as string conversion by modifying ForeignCallOutput type in acvm.js
19
- return [
20
- new Fr(this.index).toString(),
21
- this.siblingPath.toFields().map((fr)=>fr.toString())
22
- ];
23
- }
24
- }
@@ -1,85 +0,0 @@
1
- import { Fr } from '@aztec/foundation/fields';
2
- import { Comparator, type Note } from '@aztec/stdlib/note';
3
- export interface PropertySelector {
4
- index: number;
5
- offset: number;
6
- length: number;
7
- }
8
- /**
9
- * Configuration for selecting values.
10
- */
11
- export interface Select {
12
- /**
13
- * Selector of the field to select and match.
14
- */
15
- selector: PropertySelector;
16
- /**
17
- * Required value of the field.
18
- */
19
- value: Fr;
20
- /**
21
- * The comparator to use
22
- */
23
- comparator: Comparator;
24
- }
25
- /**
26
- * The order to sort an array.
27
- */
28
- export declare enum SortOrder {
29
- NADA = 0,
30
- DESC = 1,
31
- ASC = 2
32
- }
33
- /**
34
- * Configuration for sorting values.
35
- */
36
- export interface Sort {
37
- /**
38
- * Selector of the field to sort.
39
- */
40
- selector: PropertySelector;
41
- /**
42
- * Order to sort the field.
43
- */
44
- order: SortOrder;
45
- }
46
- /**
47
- * Options for picking items from an array of BasicNoteData.
48
- */
49
- interface GetOptions {
50
- /**
51
- * Configurations for selecting items.
52
- * Default: empty array.
53
- */
54
- selects?: Select[];
55
- /**
56
- * Configurations for sorting items.
57
- * Default: empty array.
58
- */
59
- sorts?: Sort[];
60
- /**
61
- * The number of items to retrieve per query.
62
- * Default: 0. No limit.
63
- */
64
- limit?: number;
65
- /**
66
- * The starting index for pagination.
67
- * Default: 0.
68
- */
69
- offset?: number;
70
- }
71
- /**
72
- * Data needed from to perform sort.
73
- */
74
- interface ContainsNote {
75
- /**
76
- * The note.
77
- */
78
- note: Note;
79
- }
80
- /**
81
- * Pick from a note array a number of notes that meet the criteria.
82
- */
83
- export declare function pickNotes<T extends ContainsNote>(noteDatas: T[], { selects, sorts, limit, offset }: GetOptions): T[];
84
- export {};
85
- //# sourceMappingURL=pick_notes.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"pick_notes.d.ts","sourceRoot":"","sources":["../../src/private/pick_notes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,KAAK,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAE3D,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,MAAM;IACrB;;OAEG;IACH,QAAQ,EAAE,gBAAgB,CAAC;IAC3B;;OAEG;IACH,KAAK,EAAE,EAAE,CAAC;IACV;;OAEG;IACH,UAAU,EAAE,UAAU,CAAC;CACxB;AAED;;GAEG;AACH,oBAAY,SAAS;IACnB,IAAI,IAAI;IACR,IAAI,IAAI;IACR,GAAG,IAAI;CACR;AAED;;GAEG;AACH,MAAM,WAAW,IAAI;IACnB;;OAEG;IACH,QAAQ,EAAE,gBAAgB,CAAC;IAC3B;;OAEG;IACH,KAAK,EAAE,SAAS,CAAC;CAClB;AAED;;GAEG;AACH,UAAU,UAAU;IAClB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB;;;OAGG;IACH,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC;IACf;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,UAAU,YAAY;IACpB;;OAEG;IACH,IAAI,EAAE,IAAI,CAAC;CACZ;AA8CD;;GAEG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,YAAY,EAC9C,SAAS,EAAE,CAAC,EAAE,EACd,EAAE,OAAY,EAAE,KAAU,EAAE,KAAS,EAAE,MAAU,EAAE,EAAE,UAAU,GAC9D,CAAC,EAAE,CAIL"}
@@ -1,51 +0,0 @@
1
- import { Fr } from '@aztec/foundation/fields';
2
- import { Comparator } from '@aztec/stdlib/note';
3
- /**
4
- * The order to sort an array.
5
- */ export var SortOrder = /*#__PURE__*/ function(SortOrder) {
6
- SortOrder[SortOrder["NADA"] = 0] = "NADA";
7
- SortOrder[SortOrder["DESC"] = 1] = "DESC";
8
- SortOrder[SortOrder["ASC"] = 2] = "ASC";
9
- return SortOrder;
10
- }({});
11
- const selectPropertyFromPackedNoteContent = (noteData, selector)=>{
12
- const noteValueBuffer = noteData[selector.index].toBuffer();
13
- const noteValue = noteValueBuffer.subarray(selector.offset, selector.offset + selector.length);
14
- return Fr.fromBuffer(noteValue);
15
- };
16
- const selectNotes = (noteDatas, selects)=>noteDatas.filter((noteData)=>selects.every(({ selector, value, comparator })=>{
17
- const noteValueFr = selectPropertyFromPackedNoteContent(noteData.note.items, selector);
18
- const comparatorSelector = {
19
- [Comparator.EQ]: ()=>noteValueFr.equals(value),
20
- [Comparator.NEQ]: ()=>!noteValueFr.equals(value),
21
- [Comparator.LT]: ()=>noteValueFr.lt(value),
22
- [Comparator.LTE]: ()=>noteValueFr.lt(value) || noteValueFr.equals(value),
23
- [Comparator.GT]: ()=>!noteValueFr.lt(value) && !noteValueFr.equals(value),
24
- [Comparator.GTE]: ()=>!noteValueFr.lt(value)
25
- };
26
- return comparatorSelector[comparator]();
27
- }));
28
- const sortNotes = (a, b, sorts, level = 0)=>{
29
- if (sorts[level] === undefined) {
30
- return 0;
31
- }
32
- const { selector, order } = sorts[level];
33
- if (order === 0) {
34
- return 0;
35
- }
36
- const aValue = selectPropertyFromPackedNoteContent(a, selector);
37
- const bValue = selectPropertyFromPackedNoteContent(b, selector);
38
- const dir = order === 1 ? [
39
- -1,
40
- 1
41
- ] : [
42
- 1,
43
- -1
44
- ];
45
- return aValue.toBigInt() === bValue.toBigInt() ? sortNotes(a, b, sorts, level + 1) : aValue.toBigInt() > bValue.toBigInt() ? dir[0] : dir[1];
46
- };
47
- /**
48
- * Pick from a note array a number of notes that meet the criteria.
49
- */ export function pickNotes(noteDatas, { selects = [], sorts = [], limit = 0, offset = 0 }) {
50
- return selectNotes(noteDatas, selects).sort((a, b)=>sortNotes(a.note.items, b.note.items, sorts)).slice(offset, limit ? offset + limit : undefined);
51
- }
@@ -1,25 +0,0 @@
1
- import { Fr } from '@aztec/foundation/fields';
2
- import { type FunctionArtifact, type FunctionArtifactWithContractName, type FunctionSelector } from '@aztec/stdlib/abi';
3
- import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
- import type { ContractInstance } from '@aztec/stdlib/contract';
5
- import type { AztecNode } from '@aztec/stdlib/interfaces/client';
6
- import { PrivateCircuitPublicInputs } from '@aztec/stdlib/kernel';
7
- import { PrivateCallExecutionResult } from '@aztec/stdlib/tx';
8
- import { type ACVMWitness } from './acvm/index.js';
9
- import type { ExecutionDataProvider } from './execution_data_provider.js';
10
- import type { PrivateExecutionOracle } from './private_execution_oracle.js';
11
- import type { SimulationProvider } from './providers/simulation_provider.js';
12
- /**
13
- * Execute a private function and return the execution result.
14
- */
15
- export declare function executePrivateFunction(simulator: SimulationProvider, privateExecutionOracle: PrivateExecutionOracle, artifact: FunctionArtifactWithContractName, contractAddress: AztecAddress, functionSelector: FunctionSelector, log?: import("@aztec/foundation/log").Logger): Promise<PrivateCallExecutionResult>;
16
- /**
17
- * Get the private circuit public inputs from the partial witness.
18
- * @param artifact - The function artifact
19
- * @param partialWitness - The partial witness, result of simulating the function.
20
- * @returns - The public inputs.
21
- */
22
- export declare function extractPrivateCircuitPublicInputs(artifact: FunctionArtifact, partialWitness: ACVMWitness): PrivateCircuitPublicInputs;
23
- export declare function readCurrentClassId(contractAddress: AztecAddress, instance: ContractInstance, executionDataProvider: ExecutionDataProvider | AztecNode, blockNumber: number): Promise<Fr>;
24
- export declare function verifyCurrentClassId(contractAddress: AztecAddress, executionDataProvider: ExecutionDataProvider, blockNumber?: number): Promise<void>;
25
- //# sourceMappingURL=private_execution.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"private_execution.d.ts","sourceRoot":"","sources":["../../src/private/private_execution.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAI9C,OAAO,EACL,KAAK,gBAAgB,EACrB,KAAK,gCAAgC,EACrC,KAAK,gBAAgB,EAEtB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AAGlE,OAAO,EAAE,0BAA0B,EAAE,MAAM,kBAAkB,CAAC;AAI9D,OAAO,EAAE,KAAK,WAAW,EAA4B,MAAM,iBAAiB,CAAC;AAC7E,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAC5E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AAE7E;;GAEG;AACH,wBAAsB,sBAAsB,CAC1C,SAAS,EAAE,kBAAkB,EAC7B,sBAAsB,EAAE,sBAAsB,EAC9C,QAAQ,EAAE,gCAAgC,EAC1C,eAAe,EAAE,YAAY,EAC7B,gBAAgB,EAAE,gBAAgB,EAClC,GAAG,yCAA8C,GAChD,OAAO,CAAC,0BAA0B,CAAC,CAkErC;AAED;;;;;GAKG;AACH,wBAAgB,iCAAiC,CAC/C,QAAQ,EAAE,gBAAgB,EAC1B,cAAc,EAAE,WAAW,GAC1B,0BAA0B,CAa5B;AAED,wBAAsB,kBAAkB,CACtC,eAAe,EAAE,YAAY,EAC7B,QAAQ,EAAE,gBAAgB,EAC1B,qBAAqB,EAAE,qBAAqB,GAAG,SAAS,EACxD,WAAW,EAAE,MAAM,eAWpB;AAED,wBAAsB,oBAAoB,CACxC,eAAe,EAAE,YAAY,EAC7B,qBAAqB,EAAE,qBAAqB,EAC5C,WAAW,CAAC,EAAE,MAAM,iBAUrB"}
@@ -1,95 +0,0 @@
1
- import { PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH, PRIVATE_CONTEXT_INPUTS_LENGTH } from '@aztec/constants';
2
- import { Fr } from '@aztec/foundation/fields';
3
- import { createLogger } from '@aztec/foundation/log';
4
- import { Timer } from '@aztec/foundation/timer';
5
- import { ProtocolContractAddress } from '@aztec/protocol-contracts';
6
- import { countArgumentsSize } from '@aztec/stdlib/abi';
7
- import { PrivateCircuitPublicInputs } from '@aztec/stdlib/kernel';
8
- import { SharedMutableValues, SharedMutableValuesWithHash } from '@aztec/stdlib/shared-mutable';
9
- import { PrivateCallExecutionResult } from '@aztec/stdlib/tx';
10
- import { ExecutionError, resolveAssertionMessageFromError } from '../common/errors.js';
11
- import { witnessMapToFields } from './acvm/deserialize.js';
12
- import { Oracle, extractCallStack } from './acvm/index.js';
13
- /**
14
- * Execute a private function and return the execution result.
15
- */ export async function executePrivateFunction(simulator, privateExecutionOracle, artifact, contractAddress, functionSelector, log = createLogger('simulator:private_execution')) {
16
- const functionName = await privateExecutionOracle.getDebugFunctionName();
17
- log.verbose(`Executing private function ${functionName}`, {
18
- contract: contractAddress
19
- });
20
- const initialWitness = privateExecutionOracle.getInitialWitness(artifact);
21
- const acvmCallback = new Oracle(privateExecutionOracle);
22
- const timer = new Timer();
23
- const acirExecutionResult = await simulator.executeUserCircuit(initialWitness, artifact, acvmCallback).catch((err)=>{
24
- err.message = resolveAssertionMessageFromError(err, artifact);
25
- throw new ExecutionError(err.message, {
26
- contractAddress,
27
- functionSelector
28
- }, extractCallStack(err, artifact.debug), {
29
- cause: err
30
- });
31
- });
32
- const duration = timer.ms();
33
- const partialWitness = acirExecutionResult.partialWitness;
34
- const publicInputs = extractPrivateCircuitPublicInputs(artifact, partialWitness);
35
- // TODO (alexg) estimate this size
36
- const initialWitnessSize = witnessMapToFields(initialWitness).length * Fr.SIZE_IN_BYTES;
37
- log.debug(`Ran external function ${contractAddress.toString()}:${functionSelector}`, {
38
- circuitName: 'app-circuit',
39
- duration,
40
- eventName: 'circuit-witness-generation',
41
- inputSize: initialWitnessSize,
42
- outputSize: publicInputs.toBuffer().length,
43
- appCircuitName: functionName
44
- });
45
- const contractClassLogs = privateExecutionOracle.getContractClassLogs();
46
- const rawReturnValues = await privateExecutionOracle.loadFromExecutionCache(publicInputs.returnsHash);
47
- const noteHashLeafIndexMap = privateExecutionOracle.getNoteHashLeafIndexMap();
48
- const newNotes = privateExecutionOracle.getNewNotes();
49
- const noteHashNullifierCounterMap = privateExecutionOracle.getNoteHashNullifierCounterMap();
50
- const nestedExecutions = privateExecutionOracle.getNestedExecutions();
51
- log.debug(`Returning from call to ${contractAddress.toString()}:${functionSelector}`);
52
- return new PrivateCallExecutionResult(artifact.bytecode, Buffer.from(artifact.verificationKey, 'base64'), partialWitness, publicInputs, noteHashLeafIndexMap, newNotes, noteHashNullifierCounterMap, rawReturnValues, nestedExecutions, contractClassLogs, {
53
- timings: {
54
- witgen: // Due to the recursive nature of execution, we have to subtract the time taken by the first level of
55
- // child executions
56
- duration - nestedExecutions.reduce((acc, nested)=>acc + (nested.profileResult?.timings.witgen ?? 0), 0)
57
- }
58
- });
59
- }
60
- /**
61
- * Get the private circuit public inputs from the partial witness.
62
- * @param artifact - The function artifact
63
- * @param partialWitness - The partial witness, result of simulating the function.
64
- * @returns - The public inputs.
65
- */ export function extractPrivateCircuitPublicInputs(artifact, partialWitness) {
66
- const parametersSize = countArgumentsSize(artifact) + PRIVATE_CONTEXT_INPUTS_LENGTH;
67
- const returnsSize = PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH;
68
- const returnData = [];
69
- // Return values always appear in the witness after arguments.
70
- for(let i = parametersSize; i < parametersSize + returnsSize; i++){
71
- const returnedField = partialWitness.get(i);
72
- if (returnedField === undefined) {
73
- throw new Error(`Missing return value for index ${i}`);
74
- }
75
- returnData.push(Fr.fromString(returnedField));
76
- }
77
- return PrivateCircuitPublicInputs.fromFields(returnData);
78
- }
79
- export async function readCurrentClassId(contractAddress, instance, executionDataProvider, blockNumber) {
80
- const { sharedMutableSlot } = await SharedMutableValuesWithHash.getContractUpdateSlots(contractAddress);
81
- const sharedMutableValues = await SharedMutableValues.readFromTree(sharedMutableSlot, (slot)=>executionDataProvider.getPublicStorageAt(blockNumber, ProtocolContractAddress.ContractInstanceDeployer, slot));
82
- let currentClassId = sharedMutableValues.svc.getCurrentAt(blockNumber)[0];
83
- if (currentClassId.isZero()) {
84
- currentClassId = instance.originalContractClassId;
85
- }
86
- return currentClassId;
87
- }
88
- export async function verifyCurrentClassId(contractAddress, executionDataProvider, blockNumber) {
89
- const instance = await executionDataProvider.getContractInstance(contractAddress);
90
- blockNumber = blockNumber ?? await executionDataProvider.getBlockNumber();
91
- const currentClassId = await readCurrentClassId(contractAddress, instance, executionDataProvider, blockNumber);
92
- if (!instance.currentContractClassId.equals(currentClassId)) {
93
- throw new Error(`Contract ${contractAddress} is outdated, current class id is ${currentClassId}, local class id is ${instance.currentContractClassId}`);
94
- }
95
- }