@aztec/txe 0.0.1-commit.ec5f612 → 0.0.1-commit.ec7ac5448
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/index.d.ts +1 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +8 -6
- package/dest/oracle/interfaces.d.ts +28 -28
- package/dest/oracle/interfaces.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.d.ts +13 -13
- package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.js +12 -12
- package/dest/oracle/txe_oracle_top_level_context.d.ts +27 -21
- package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_top_level_context.js +54 -39
- package/dest/rpc_translator.d.ts +120 -82
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +363 -152
- package/dest/state_machine/archiver.d.ts +3 -3
- package/dest/state_machine/archiver.d.ts.map +1 -1
- package/dest/state_machine/archiver.js +7 -8
- package/dest/state_machine/dummy_p2p_client.d.ts +3 -2
- package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
- package/dest/state_machine/dummy_p2p_client.js +5 -2
- package/dest/state_machine/global_variable_builder.d.ts +3 -2
- package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
- package/dest/state_machine/global_variable_builder.js +1 -1
- package/dest/state_machine/index.d.ts +4 -2
- package/dest/state_machine/index.d.ts.map +1 -1
- package/dest/state_machine/index.js +7 -3
- package/dest/state_machine/mock_epoch_cache.d.ts +18 -3
- package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
- package/dest/state_machine/mock_epoch_cache.js +35 -2
- package/dest/state_machine/synchronizer.d.ts +5 -5
- package/dest/state_machine/synchronizer.d.ts.map +1 -1
- package/dest/state_machine/synchronizer.js +3 -3
- package/dest/txe_session.d.ts +4 -3
- package/dest/txe_session.d.ts.map +1 -1
- package/dest/txe_session.js +24 -15
- package/dest/util/encoding.d.ts +69 -1
- package/dest/util/encoding.d.ts.map +1 -1
- package/dest/util/txe_public_contract_data_source.d.ts +1 -1
- package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
- package/dest/util/txe_public_contract_data_source.js +1 -3
- package/package.json +15 -15
- package/src/index.ts +8 -5
- package/src/oracle/interfaces.ts +27 -31
- package/src/oracle/txe_oracle_public_context.ts +12 -12
- package/src/oracle/txe_oracle_top_level_context.ts +64 -43
- package/src/rpc_translator.ts +422 -174
- package/src/state_machine/archiver.ts +6 -5
- package/src/state_machine/dummy_p2p_client.ts +6 -2
- package/src/state_machine/global_variable_builder.ts +2 -0
- package/src/state_machine/index.ts +6 -1
- package/src/state_machine/mock_epoch_cache.ts +46 -3
- package/src/state_machine/synchronizer.ts +4 -4
- package/src/txe_session.ts +26 -13
- package/src/util/txe_public_contract_data_source.ts +0 -2
package/dest/rpc_translator.js
CHANGED
|
@@ -61,59 +61,69 @@ export class RPCTranslator {
|
|
|
61
61
|
return this.oracleHandler;
|
|
62
62
|
}
|
|
63
63
|
// TXE session state transition functions - these get handled by the state handler
|
|
64
|
-
|
|
64
|
+
// eslint-disable-next-line camelcase
|
|
65
|
+
async aztec_txe_setTopLevelTXEContext() {
|
|
65
66
|
await this.stateHandler.enterTopLevelState();
|
|
66
67
|
return toForeignCallResult([]);
|
|
67
68
|
}
|
|
68
|
-
|
|
69
|
+
// eslint-disable-next-line camelcase
|
|
70
|
+
async aztec_txe_setPrivateTXEContext(foreignContractAddressIsSome, foreignContractAddressValue, foreignAnchorBlockNumberIsSome, foreignAnchorBlockNumberValue) {
|
|
69
71
|
const contractAddress = fromSingle(foreignContractAddressIsSome).toBool() ? AztecAddress.fromField(fromSingle(foreignContractAddressValue)) : undefined;
|
|
70
72
|
const anchorBlockNumber = fromSingle(foreignAnchorBlockNumberIsSome).toBool() ? BlockNumber(fromSingle(foreignAnchorBlockNumberValue).toNumber()) : undefined;
|
|
71
73
|
const privateContextInputs = await this.stateHandler.enterPrivateState(contractAddress, anchorBlockNumber);
|
|
72
74
|
return toForeignCallResult(privateContextInputs.toFields().map(toSingle));
|
|
73
75
|
}
|
|
74
|
-
|
|
76
|
+
// eslint-disable-next-line camelcase
|
|
77
|
+
async aztec_txe_setPublicTXEContext(foreignContractAddressIsSome, foreignContractAddressValue) {
|
|
75
78
|
const contractAddress = fromSingle(foreignContractAddressIsSome).toBool() ? AztecAddress.fromField(fromSingle(foreignContractAddressValue)) : undefined;
|
|
76
79
|
await this.stateHandler.enterPublicState(contractAddress);
|
|
77
80
|
return toForeignCallResult([]);
|
|
78
81
|
}
|
|
79
|
-
|
|
82
|
+
// eslint-disable-next-line camelcase
|
|
83
|
+
async aztec_txe_setUtilityTXEContext(foreignContractAddressIsSome, foreignContractAddressValue) {
|
|
80
84
|
const contractAddress = fromSingle(foreignContractAddressIsSome).toBool() ? AztecAddress.fromField(fromSingle(foreignContractAddressValue)) : undefined;
|
|
81
85
|
await this.stateHandler.enterUtilityState(contractAddress);
|
|
82
86
|
return toForeignCallResult([]);
|
|
83
87
|
}
|
|
84
88
|
// Other oracles - these get handled by the oracle handler
|
|
85
89
|
// TXE-specific oracles
|
|
86
|
-
|
|
87
|
-
|
|
90
|
+
// eslint-disable-next-line camelcase
|
|
91
|
+
aztec_txe_getDefaultAddress() {
|
|
92
|
+
const defaultAddress = this.handlerAsTxe().getDefaultAddress();
|
|
88
93
|
return toForeignCallResult([
|
|
89
94
|
toSingle(defaultAddress)
|
|
90
95
|
]);
|
|
91
96
|
}
|
|
92
|
-
|
|
93
|
-
|
|
97
|
+
// eslint-disable-next-line camelcase
|
|
98
|
+
async aztec_txe_getNextBlockNumber() {
|
|
99
|
+
const nextBlockNumber = await this.handlerAsTxe().getNextBlockNumber();
|
|
94
100
|
return toForeignCallResult([
|
|
95
101
|
toSingle(nextBlockNumber)
|
|
96
102
|
]);
|
|
97
103
|
}
|
|
98
|
-
|
|
99
|
-
|
|
104
|
+
// eslint-disable-next-line camelcase
|
|
105
|
+
async aztec_txe_getNextBlockTimestamp() {
|
|
106
|
+
const nextBlockTimestamp = await this.handlerAsTxe().getNextBlockTimestamp();
|
|
100
107
|
return toForeignCallResult([
|
|
101
108
|
toSingle(nextBlockTimestamp)
|
|
102
109
|
]);
|
|
103
110
|
}
|
|
104
|
-
|
|
111
|
+
// eslint-disable-next-line camelcase
|
|
112
|
+
async aztec_txe_advanceBlocksBy(foreignBlocks) {
|
|
105
113
|
const blocks = fromSingle(foreignBlocks).toNumber();
|
|
106
|
-
await this.handlerAsTxe().
|
|
114
|
+
await this.handlerAsTxe().advanceBlocksBy(blocks);
|
|
107
115
|
return toForeignCallResult([]);
|
|
108
116
|
}
|
|
109
|
-
|
|
117
|
+
// eslint-disable-next-line camelcase
|
|
118
|
+
aztec_txe_advanceTimestampBy(foreignDuration) {
|
|
110
119
|
const duration = fromSingle(foreignDuration).toBigInt();
|
|
111
|
-
this.handlerAsTxe().
|
|
120
|
+
this.handlerAsTxe().advanceTimestampBy(duration);
|
|
112
121
|
return toForeignCallResult([]);
|
|
113
122
|
}
|
|
114
|
-
|
|
123
|
+
// eslint-disable-next-line camelcase
|
|
124
|
+
async aztec_txe_deploy(artifact, instance, foreignSecret) {
|
|
115
125
|
const secret = fromSingle(foreignSecret);
|
|
116
|
-
await this.handlerAsTxe().
|
|
126
|
+
await this.handlerAsTxe().deploy(artifact, instance, secret);
|
|
117
127
|
return toForeignCallResult([
|
|
118
128
|
toArray([
|
|
119
129
|
instance.salt,
|
|
@@ -124,55 +134,64 @@ export class RPCTranslator {
|
|
|
124
134
|
])
|
|
125
135
|
]);
|
|
126
136
|
}
|
|
127
|
-
|
|
137
|
+
// eslint-disable-next-line camelcase
|
|
138
|
+
async aztec_txe_createAccount(foreignSecret) {
|
|
128
139
|
const secret = fromSingle(foreignSecret);
|
|
129
|
-
const completeAddress = await this.handlerAsTxe().
|
|
140
|
+
const completeAddress = await this.handlerAsTxe().createAccount(secret);
|
|
130
141
|
return toForeignCallResult([
|
|
131
142
|
toSingle(completeAddress.address),
|
|
132
143
|
...completeAddress.publicKeys.toFields().map(toSingle)
|
|
133
144
|
]);
|
|
134
145
|
}
|
|
135
|
-
|
|
146
|
+
// eslint-disable-next-line camelcase
|
|
147
|
+
async aztec_txe_addAccount(artifact, instance, foreignSecret) {
|
|
136
148
|
const secret = fromSingle(foreignSecret);
|
|
137
|
-
const completeAddress = await this.handlerAsTxe().
|
|
149
|
+
const completeAddress = await this.handlerAsTxe().addAccount(artifact, instance, secret);
|
|
138
150
|
return toForeignCallResult([
|
|
139
151
|
toSingle(completeAddress.address),
|
|
140
152
|
...completeAddress.publicKeys.toFields().map(toSingle)
|
|
141
153
|
]);
|
|
142
154
|
}
|
|
143
|
-
|
|
155
|
+
// eslint-disable-next-line camelcase
|
|
156
|
+
async aztec_txe_addAuthWitness(foreignAddress, foreignMessageHash) {
|
|
144
157
|
const address = addressFromSingle(foreignAddress);
|
|
145
158
|
const messageHash = fromSingle(foreignMessageHash);
|
|
146
|
-
await this.handlerAsTxe().
|
|
159
|
+
await this.handlerAsTxe().addAuthWitness(address, messageHash);
|
|
147
160
|
return toForeignCallResult([]);
|
|
148
161
|
}
|
|
149
162
|
// PXE oracles
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
163
|
+
// eslint-disable-next-line camelcase
|
|
164
|
+
aztec_utl_assertCompatibleOracleVersionV2(foreignMajor, foreignMinor) {
|
|
165
|
+
const major = fromSingle(foreignMajor).toNumber();
|
|
166
|
+
const minor = fromSingle(foreignMinor).toNumber();
|
|
167
|
+
this.handlerAsMisc().assertCompatibleOracleVersion(major, minor);
|
|
153
168
|
return toForeignCallResult([]);
|
|
154
169
|
}
|
|
155
|
-
|
|
156
|
-
|
|
170
|
+
// eslint-disable-next-line camelcase
|
|
171
|
+
aztec_utl_getRandomField() {
|
|
172
|
+
const randomField = this.handlerAsMisc().getRandomField();
|
|
157
173
|
return toForeignCallResult([
|
|
158
174
|
toSingle(randomField)
|
|
159
175
|
]);
|
|
160
176
|
}
|
|
161
|
-
|
|
162
|
-
|
|
177
|
+
// eslint-disable-next-line camelcase
|
|
178
|
+
async aztec_txe_getLastBlockTimestamp() {
|
|
179
|
+
const timestamp = await this.handlerAsTxe().getLastBlockTimestamp();
|
|
163
180
|
return toForeignCallResult([
|
|
164
181
|
toSingle(new Fr(timestamp))
|
|
165
182
|
]);
|
|
166
183
|
}
|
|
167
|
-
|
|
168
|
-
|
|
184
|
+
// eslint-disable-next-line camelcase
|
|
185
|
+
async aztec_txe_getLastTxEffects() {
|
|
186
|
+
const { txHash, noteHashes, nullifiers } = await this.handlerAsTxe().getLastTxEffects();
|
|
169
187
|
return toForeignCallResult([
|
|
170
188
|
toSingle(txHash.hash),
|
|
171
189
|
...arrayToBoundedVec(toArray(noteHashes), MAX_NOTE_HASHES_PER_TX),
|
|
172
190
|
...arrayToBoundedVec(toArray(nullifiers), MAX_NULLIFIERS_PER_TX)
|
|
173
191
|
]);
|
|
174
192
|
}
|
|
175
|
-
|
|
193
|
+
// eslint-disable-next-line camelcase
|
|
194
|
+
async aztec_txe_getPrivateEvents(foreignSelector, foreignContractAddress, foreignScope) {
|
|
176
195
|
const selector = EventSelector.fromField(fromSingle(foreignSelector));
|
|
177
196
|
const contractAddress = addressFromSingle(foreignContractAddress);
|
|
178
197
|
const scope = addressFromSingle(foreignScope);
|
|
@@ -182,7 +201,7 @@ export class RPCTranslator {
|
|
|
182
201
|
// We cycle job to commit the stores after the contract sync.
|
|
183
202
|
await this.stateHandler.cycleJob();
|
|
184
203
|
}
|
|
185
|
-
const events = await this.handlerAsTxe().
|
|
204
|
+
const events = await this.handlerAsTxe().getPrivateEvents(selector, contractAddress, scope);
|
|
186
205
|
if (events.length > MAX_PRIVATE_EVENTS_PER_TXE_QUERY) {
|
|
187
206
|
throw new Error(`Array of length ${events.length} larger than maxLen ${MAX_PRIVATE_EVENTS_PER_TXE_QUERY}`);
|
|
188
207
|
}
|
|
@@ -200,48 +219,54 @@ export class RPCTranslator {
|
|
|
200
219
|
toSingle(queryLength)
|
|
201
220
|
]);
|
|
202
221
|
}
|
|
203
|
-
|
|
222
|
+
// eslint-disable-next-line camelcase
|
|
223
|
+
aztec_prv_setHashPreimage(foreignValues, foreignHash) {
|
|
204
224
|
const values = fromArray(foreignValues);
|
|
205
225
|
const hash = fromSingle(foreignHash);
|
|
206
|
-
this.handlerAsPrivate().
|
|
226
|
+
this.handlerAsPrivate().setHashPreimage(values, hash);
|
|
207
227
|
return toForeignCallResult([]);
|
|
208
228
|
}
|
|
209
|
-
|
|
229
|
+
// eslint-disable-next-line camelcase
|
|
230
|
+
async aztec_prv_getHashPreimage(foreignHash) {
|
|
210
231
|
const hash = fromSingle(foreignHash);
|
|
211
|
-
const returns = await this.handlerAsPrivate().
|
|
232
|
+
const returns = await this.handlerAsPrivate().getHashPreimage(hash);
|
|
212
233
|
return toForeignCallResult([
|
|
213
234
|
toArray(returns)
|
|
214
235
|
]);
|
|
215
236
|
}
|
|
216
237
|
// When the argument is a slice, noir automatically adds a length field to oracle call.
|
|
217
238
|
// When the argument is an array, we add the field length manually to the signature.
|
|
218
|
-
|
|
239
|
+
// eslint-disable-next-line camelcase
|
|
240
|
+
async aztec_utl_log(foreignLevel, foreignMessage, _foreignLength, foreignFields) {
|
|
219
241
|
const level = fromSingle(foreignLevel).toNumber();
|
|
220
242
|
const message = fromArray(foreignMessage).map((field)=>String.fromCharCode(field.toNumber())).join('');
|
|
221
243
|
const fields = fromArray(foreignFields);
|
|
222
|
-
await this.handlerAsMisc().
|
|
244
|
+
await this.handlerAsMisc().log(level, message, fields);
|
|
223
245
|
return toForeignCallResult([]);
|
|
224
246
|
}
|
|
225
|
-
|
|
247
|
+
// eslint-disable-next-line camelcase
|
|
248
|
+
async aztec_utl_getFromPublicStorage(foreignBlockHash, foreignContractAddress, foreignStartStorageSlot, foreignNumberOfElements) {
|
|
226
249
|
const blockHash = new BlockHash(fromSingle(foreignBlockHash));
|
|
227
250
|
const contractAddress = addressFromSingle(foreignContractAddress);
|
|
228
251
|
const startStorageSlot = fromSingle(foreignStartStorageSlot);
|
|
229
252
|
const numberOfElements = fromSingle(foreignNumberOfElements).toNumber();
|
|
230
|
-
const values = await this.handlerAsUtility().
|
|
253
|
+
const values = await this.handlerAsUtility().getFromPublicStorage(blockHash, contractAddress, startStorageSlot, numberOfElements);
|
|
231
254
|
return toForeignCallResult([
|
|
232
255
|
toArray(values)
|
|
233
256
|
]);
|
|
234
257
|
}
|
|
235
|
-
|
|
258
|
+
// eslint-disable-next-line camelcase
|
|
259
|
+
async aztec_utl_getPublicDataWitness(foreignBlockHash, foreignLeafSlot) {
|
|
236
260
|
const blockHash = new BlockHash(fromSingle(foreignBlockHash));
|
|
237
261
|
const leafSlot = fromSingle(foreignLeafSlot);
|
|
238
|
-
const witness = await this.handlerAsUtility().
|
|
262
|
+
const witness = await this.handlerAsUtility().getPublicDataWitness(blockHash, leafSlot);
|
|
239
263
|
if (!witness) {
|
|
240
264
|
throw new Error(`Public data witness not found for slot ${leafSlot} at block ${blockHash.toString()}.`);
|
|
241
265
|
}
|
|
242
266
|
return toForeignCallResult(witness.toNoirRepresentation());
|
|
243
267
|
}
|
|
244
|
-
|
|
268
|
+
// eslint-disable-next-line camelcase
|
|
269
|
+
async aztec_utl_getNotes(foreignOwnerIsSome, foreignOwnerValue, foreignStorageSlot, foreignNumSelects, foreignSelectByIndexes, foreignSelectByOffsets, foreignSelectByLengths, foreignSelectValues, foreignSelectComparators, foreignSortByIndexes, foreignSortByOffsets, foreignSortByLengths, foreignSortOrder, foreignLimit, foreignOffset, foreignStatus, foreignMaxNotes, foreignPackedHintedNoteLength) {
|
|
245
270
|
// Parse Option<AztecAddress>: ownerIsSome is 0 for None, 1 for Some
|
|
246
271
|
const owner = fromSingle(foreignOwnerIsSome).toBool() ? AztecAddress.fromField(fromSingle(foreignOwnerValue)) : undefined;
|
|
247
272
|
const storageSlot = fromSingle(foreignStorageSlot);
|
|
@@ -260,7 +285,7 @@ export class RPCTranslator {
|
|
|
260
285
|
const status = fromSingle(foreignStatus).toNumber();
|
|
261
286
|
const maxNotes = fromSingle(foreignMaxNotes).toNumber();
|
|
262
287
|
const packedHintedNoteLength = fromSingle(foreignPackedHintedNoteLength).toNumber();
|
|
263
|
-
const noteDatas = await this.handlerAsUtility().
|
|
288
|
+
const noteDatas = await this.handlerAsUtility().getNotes(owner, storageSlot, numSelects, selectByIndexes, selectByOffsets, selectByLengths, selectValues, selectComparators, sortByIndexes, sortByOffsets, sortByLengths, sortOrder, limit, offset, status);
|
|
264
289
|
const returnDataAsArrayOfArrays = noteDatas.map((noteData)=>packAsHintedNote({
|
|
265
290
|
contractAddress: noteData.contractAddress,
|
|
266
291
|
owner: noteData.owner,
|
|
@@ -275,7 +300,8 @@ export class RPCTranslator {
|
|
|
275
300
|
// At last we convert the array of arrays to a bounded vec of arrays
|
|
276
301
|
return toForeignCallResult(arrayOfArraysToBoundedVecOfArrays(returnDataAsArrayOfForeignCallSingleArrays, maxNotes, packedHintedNoteLength));
|
|
277
302
|
}
|
|
278
|
-
|
|
303
|
+
// eslint-disable-next-line camelcase
|
|
304
|
+
aztec_prv_notifyCreatedNote(foreignOwner, foreignStorageSlot, foreignRandomness, foreignNoteTypeId, foreignNote, foreignNoteHash, foreignCounter) {
|
|
279
305
|
const owner = addressFromSingle(foreignOwner);
|
|
280
306
|
const storageSlot = fromSingle(foreignStorageSlot);
|
|
281
307
|
const randomness = fromSingle(foreignRandomness);
|
|
@@ -283,39 +309,44 @@ export class RPCTranslator {
|
|
|
283
309
|
const note = fromArray(foreignNote);
|
|
284
310
|
const noteHash = fromSingle(foreignNoteHash);
|
|
285
311
|
const counter = fromSingle(foreignCounter).toNumber();
|
|
286
|
-
this.handlerAsPrivate().
|
|
312
|
+
this.handlerAsPrivate().notifyCreatedNote(owner, storageSlot, randomness, noteTypeId, note, noteHash, counter);
|
|
287
313
|
return toForeignCallResult([]);
|
|
288
314
|
}
|
|
289
|
-
|
|
315
|
+
// eslint-disable-next-line camelcase
|
|
316
|
+
async aztec_prv_notifyNullifiedNote(foreignInnerNullifier, foreignNoteHash, foreignCounter) {
|
|
290
317
|
const innerNullifier = fromSingle(foreignInnerNullifier);
|
|
291
318
|
const noteHash = fromSingle(foreignNoteHash);
|
|
292
319
|
const counter = fromSingle(foreignCounter).toNumber();
|
|
293
|
-
await this.handlerAsPrivate().
|
|
320
|
+
await this.handlerAsPrivate().notifyNullifiedNote(innerNullifier, noteHash, counter);
|
|
294
321
|
return toForeignCallResult([]);
|
|
295
322
|
}
|
|
296
|
-
|
|
323
|
+
// eslint-disable-next-line camelcase
|
|
324
|
+
async aztec_prv_notifyCreatedNullifier(foreignInnerNullifier) {
|
|
297
325
|
const innerNullifier = fromSingle(foreignInnerNullifier);
|
|
298
|
-
await this.handlerAsPrivate().
|
|
326
|
+
await this.handlerAsPrivate().notifyCreatedNullifier(innerNullifier);
|
|
299
327
|
return toForeignCallResult([]);
|
|
300
328
|
}
|
|
301
|
-
|
|
329
|
+
// eslint-disable-next-line camelcase
|
|
330
|
+
async aztec_prv_isNullifierPending(foreignInnerNullifier, foreignContractAddress) {
|
|
302
331
|
const innerNullifier = fromSingle(foreignInnerNullifier);
|
|
303
332
|
const contractAddress = addressFromSingle(foreignContractAddress);
|
|
304
|
-
const isPending = await this.handlerAsPrivate().
|
|
333
|
+
const isPending = await this.handlerAsPrivate().isNullifierPending(innerNullifier, contractAddress);
|
|
305
334
|
return toForeignCallResult([
|
|
306
335
|
toSingle(new Fr(isPending))
|
|
307
336
|
]);
|
|
308
337
|
}
|
|
309
|
-
|
|
338
|
+
// eslint-disable-next-line camelcase
|
|
339
|
+
async aztec_utl_doesNullifierExist(foreignInnerNullifier) {
|
|
310
340
|
const innerNullifier = fromSingle(foreignInnerNullifier);
|
|
311
|
-
const exists = await this.handlerAsUtility().
|
|
341
|
+
const exists = await this.handlerAsUtility().doesNullifierExist(innerNullifier);
|
|
312
342
|
return toForeignCallResult([
|
|
313
343
|
toSingle(new Fr(exists))
|
|
314
344
|
]);
|
|
315
345
|
}
|
|
316
|
-
|
|
346
|
+
// eslint-disable-next-line camelcase
|
|
347
|
+
async aztec_utl_getContractInstance(foreignAddress) {
|
|
317
348
|
const address = addressFromSingle(foreignAddress);
|
|
318
|
-
const instance = await this.handlerAsUtility().
|
|
349
|
+
const instance = await this.handlerAsUtility().getContractInstance(address);
|
|
319
350
|
return toForeignCallResult([
|
|
320
351
|
instance.salt,
|
|
321
352
|
instance.deployer.toField(),
|
|
@@ -324,9 +355,10 @@ export class RPCTranslator {
|
|
|
324
355
|
...instance.publicKeys.toFields()
|
|
325
356
|
].map(toSingle));
|
|
326
357
|
}
|
|
327
|
-
|
|
358
|
+
// eslint-disable-next-line camelcase
|
|
359
|
+
async aztec_utl_getPublicKeysAndPartialAddress(foreignAddress) {
|
|
328
360
|
const address = addressFromSingle(foreignAddress);
|
|
329
|
-
const result = await this.handlerAsUtility().
|
|
361
|
+
const result = await this.handlerAsUtility().getPublicKeysAndPartialAddress(address);
|
|
330
362
|
// We are going to return a Noir Option struct to represent the possibility of null values. Options are a struct
|
|
331
363
|
// with two fields: `some` (a boolean) and `value` (a field array in this case).
|
|
332
364
|
if (result === undefined) {
|
|
@@ -346,26 +378,30 @@ export class RPCTranslator {
|
|
|
346
378
|
]);
|
|
347
379
|
}
|
|
348
380
|
}
|
|
349
|
-
|
|
381
|
+
// eslint-disable-next-line camelcase
|
|
382
|
+
async aztec_utl_getKeyValidationRequest(foreignPkMHash) {
|
|
350
383
|
const pkMHash = fromSingle(foreignPkMHash);
|
|
351
|
-
const keyValidationRequest = await this.handlerAsUtility().
|
|
384
|
+
const keyValidationRequest = await this.handlerAsUtility().getKeyValidationRequest(pkMHash);
|
|
352
385
|
return toForeignCallResult(keyValidationRequest.toFields().map(toSingle));
|
|
353
386
|
}
|
|
354
|
-
|
|
387
|
+
// eslint-disable-next-line camelcase
|
|
388
|
+
aztec_prv_callPrivateFunction(_foreignTargetContractAddress, _foreignFunctionSelector, _foreignArgsHash, _foreignSideEffectCounter, _foreignIsStaticCall) {
|
|
355
389
|
throw new Error('Contract calls are forbidden inside a `TestEnvironment::private_context`, use `private_call` instead');
|
|
356
390
|
}
|
|
357
|
-
|
|
391
|
+
// eslint-disable-next-line camelcase
|
|
392
|
+
async aztec_utl_getNullifierMembershipWitness(foreignBlockHash, foreignNullifier) {
|
|
358
393
|
const blockHash = new BlockHash(fromSingle(foreignBlockHash));
|
|
359
394
|
const nullifier = fromSingle(foreignNullifier);
|
|
360
|
-
const witness = await this.handlerAsUtility().
|
|
395
|
+
const witness = await this.handlerAsUtility().getNullifierMembershipWitness(blockHash, nullifier);
|
|
361
396
|
if (!witness) {
|
|
362
397
|
throw new Error(`Nullifier membership witness not found at block ${blockHash}.`);
|
|
363
398
|
}
|
|
364
399
|
return toForeignCallResult(witness.toNoirRepresentation());
|
|
365
400
|
}
|
|
366
|
-
|
|
401
|
+
// eslint-disable-next-line camelcase
|
|
402
|
+
async aztec_utl_getAuthWitness(foreignMessageHash) {
|
|
367
403
|
const messageHash = fromSingle(foreignMessageHash);
|
|
368
|
-
const authWitness = await this.handlerAsUtility().
|
|
404
|
+
const authWitness = await this.handlerAsUtility().getAuthWitness(messageHash);
|
|
369
405
|
if (!authWitness) {
|
|
370
406
|
throw new Error(`Auth witness not found for message hash ${messageHash}.`);
|
|
371
407
|
}
|
|
@@ -373,92 +409,152 @@ export class RPCTranslator {
|
|
|
373
409
|
toArray(authWitness)
|
|
374
410
|
]);
|
|
375
411
|
}
|
|
376
|
-
|
|
412
|
+
// eslint-disable-next-line camelcase
|
|
413
|
+
aztec_prv_assertValidPublicCalldata(_foreignCalldataHash) {
|
|
377
414
|
throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
|
|
378
415
|
}
|
|
379
|
-
|
|
416
|
+
// eslint-disable-next-line camelcase
|
|
417
|
+
aztec_prv_notifyRevertiblePhaseStart(_foreignMinRevertibleSideEffectCounter) {
|
|
380
418
|
throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
|
|
381
419
|
}
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
}
|
|
385
|
-
async privateIsSideEffectCounterRevertible(foreignSideEffectCounter) {
|
|
420
|
+
// eslint-disable-next-line camelcase
|
|
421
|
+
async aztec_prv_isExecutionInRevertiblePhase(foreignSideEffectCounter) {
|
|
386
422
|
const sideEffectCounter = fromSingle(foreignSideEffectCounter).toNumber();
|
|
387
|
-
const isRevertible = await this.handlerAsPrivate().
|
|
423
|
+
const isRevertible = await this.handlerAsPrivate().isExecutionInRevertiblePhase(sideEffectCounter);
|
|
388
424
|
return toForeignCallResult([
|
|
389
425
|
toSingle(new Fr(isRevertible))
|
|
390
426
|
]);
|
|
391
427
|
}
|
|
392
|
-
|
|
393
|
-
|
|
428
|
+
// eslint-disable-next-line camelcase
|
|
429
|
+
aztec_utl_getUtilityContext() {
|
|
430
|
+
const context = this.handlerAsUtility().getUtilityContext();
|
|
394
431
|
return toForeignCallResult(context.toNoirRepresentation());
|
|
395
432
|
}
|
|
396
|
-
|
|
433
|
+
// eslint-disable-next-line camelcase
|
|
434
|
+
async aztec_utl_getBlockHeader(foreignBlockNumber) {
|
|
397
435
|
const blockNumber = BlockNumber(fromSingle(foreignBlockNumber).toNumber());
|
|
398
|
-
const header = await this.handlerAsUtility().
|
|
436
|
+
const header = await this.handlerAsUtility().getBlockHeader(blockNumber);
|
|
399
437
|
if (!header) {
|
|
400
438
|
throw new Error(`Block header not found for block ${blockNumber}.`);
|
|
401
439
|
}
|
|
402
440
|
return toForeignCallResult(header.toFields().map(toSingle));
|
|
403
441
|
}
|
|
404
|
-
|
|
442
|
+
// eslint-disable-next-line camelcase
|
|
443
|
+
async aztec_utl_getNoteHashMembershipWitness(foreignAnchorBlockHash, foreignNoteHash) {
|
|
405
444
|
const blockHash = new BlockHash(fromSingle(foreignAnchorBlockHash));
|
|
406
445
|
const noteHash = fromSingle(foreignNoteHash);
|
|
407
|
-
const witness = await this.handlerAsUtility().
|
|
446
|
+
const witness = await this.handlerAsUtility().getNoteHashMembershipWitness(blockHash, noteHash);
|
|
408
447
|
if (!witness) {
|
|
409
448
|
throw new Error(`Note hash ${noteHash} not found in the note hash tree at block ${blockHash.toString()}.`);
|
|
410
449
|
}
|
|
411
450
|
return toForeignCallResult(witness.toNoirRepresentation());
|
|
412
451
|
}
|
|
413
|
-
|
|
452
|
+
// eslint-disable-next-line camelcase
|
|
453
|
+
async aztec_utl_getBlockHashMembershipWitness(foreignAnchorBlockHash, foreignBlockHash) {
|
|
414
454
|
const anchorBlockHash = new BlockHash(fromSingle(foreignAnchorBlockHash));
|
|
415
455
|
const blockHash = new BlockHash(fromSingle(foreignBlockHash));
|
|
416
|
-
const witness = await this.handlerAsUtility().
|
|
456
|
+
const witness = await this.handlerAsUtility().getBlockHashMembershipWitness(anchorBlockHash, blockHash);
|
|
417
457
|
if (!witness) {
|
|
418
458
|
throw new Error(`Block hash ${blockHash.toString()} not found in the archive tree at anchor block ${anchorBlockHash.toString()}.`);
|
|
419
459
|
}
|
|
420
460
|
return toForeignCallResult(witness.toNoirRepresentation());
|
|
421
461
|
}
|
|
422
|
-
|
|
462
|
+
// eslint-disable-next-line camelcase
|
|
463
|
+
async aztec_utl_getLowNullifierMembershipWitness(foreignBlockHash, foreignNullifier) {
|
|
423
464
|
const blockHash = new BlockHash(fromSingle(foreignBlockHash));
|
|
424
465
|
const nullifier = fromSingle(foreignNullifier);
|
|
425
|
-
const witness = await this.handlerAsUtility().
|
|
466
|
+
const witness = await this.handlerAsUtility().getLowNullifierMembershipWitness(blockHash, nullifier);
|
|
426
467
|
if (!witness) {
|
|
427
468
|
throw new Error(`Low nullifier witness not found for nullifier ${nullifier} at block ${blockHash}.`);
|
|
428
469
|
}
|
|
429
470
|
return toForeignCallResult(witness.toNoirRepresentation());
|
|
430
471
|
}
|
|
431
|
-
|
|
472
|
+
// eslint-disable-next-line camelcase
|
|
473
|
+
async aztec_utl_getPendingTaggedLogs(foreignPendingTaggedLogArrayBaseSlot, foreignScope) {
|
|
432
474
|
const pendingTaggedLogArrayBaseSlot = fromSingle(foreignPendingTaggedLogArrayBaseSlot);
|
|
433
|
-
|
|
475
|
+
const scope = AztecAddress.fromField(fromSingle(foreignScope));
|
|
476
|
+
await this.handlerAsUtility().getPendingTaggedLogs(pendingTaggedLogArrayBaseSlot, scope);
|
|
434
477
|
return toForeignCallResult([]);
|
|
435
478
|
}
|
|
436
|
-
|
|
479
|
+
// eslint-disable-next-line camelcase
|
|
480
|
+
async aztec_utl_getPendingTaggedLogs_v2(foreignScope) {
|
|
481
|
+
const scope = AztecAddress.fromField(fromSingle(foreignScope));
|
|
482
|
+
const slot = await this.handlerAsUtility().getPendingTaggedLogsV2(scope);
|
|
483
|
+
return toForeignCallResult([
|
|
484
|
+
toSingle(slot)
|
|
485
|
+
]);
|
|
486
|
+
}
|
|
487
|
+
// eslint-disable-next-line camelcase
|
|
488
|
+
async aztec_utl_validateAndStoreEnqueuedNotesAndEvents(foreignContractAddress, foreignNoteValidationRequestsArrayBaseSlot, foreignEventValidationRequestsArrayBaseSlot, foreignMaxNotePackedLen, foreignMaxEventSerializedLen, foreignScope) {
|
|
437
489
|
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
438
490
|
const noteValidationRequestsArrayBaseSlot = fromSingle(foreignNoteValidationRequestsArrayBaseSlot);
|
|
439
491
|
const eventValidationRequestsArrayBaseSlot = fromSingle(foreignEventValidationRequestsArrayBaseSlot);
|
|
440
|
-
|
|
492
|
+
const maxNotePackedLen = fromSingle(foreignMaxNotePackedLen).toNumber();
|
|
493
|
+
const maxEventSerializedLen = fromSingle(foreignMaxEventSerializedLen).toNumber();
|
|
494
|
+
const scope = AztecAddress.fromField(fromSingle(foreignScope));
|
|
495
|
+
await this.handlerAsUtility().validateAndStoreEnqueuedNotesAndEvents(contractAddress, noteValidationRequestsArrayBaseSlot, eventValidationRequestsArrayBaseSlot, maxNotePackedLen, maxEventSerializedLen, scope);
|
|
496
|
+
return toForeignCallResult([]);
|
|
497
|
+
}
|
|
498
|
+
// eslint-disable-next-line camelcase
|
|
499
|
+
async aztec_utl_validateAndStoreEnqueuedNotesAndEvents_v2(foreignNoteValidationRequestsArrayBaseSlot, foreignEventValidationRequestsArrayBaseSlot, foreignMaxNotePackedLen, foreignMaxEventSerializedLen, foreignScope) {
|
|
500
|
+
const noteValidationRequestsArrayBaseSlot = fromSingle(foreignNoteValidationRequestsArrayBaseSlot);
|
|
501
|
+
const eventValidationRequestsArrayBaseSlot = fromSingle(foreignEventValidationRequestsArrayBaseSlot);
|
|
502
|
+
const maxNotePackedLen = fromSingle(foreignMaxNotePackedLen).toNumber();
|
|
503
|
+
const maxEventSerializedLen = fromSingle(foreignMaxEventSerializedLen).toNumber();
|
|
504
|
+
const scope = AztecAddress.fromField(fromSingle(foreignScope));
|
|
505
|
+
await this.handlerAsUtility().validateAndStoreEnqueuedNotesAndEventsV2(noteValidationRequestsArrayBaseSlot, eventValidationRequestsArrayBaseSlot, maxNotePackedLen, maxEventSerializedLen, scope);
|
|
441
506
|
return toForeignCallResult([]);
|
|
442
507
|
}
|
|
443
|
-
|
|
508
|
+
// eslint-disable-next-line camelcase
|
|
509
|
+
async aztec_utl_getLogsByTag(foreignContractAddress, foreignLogRetrievalRequestsArrayBaseSlot, foreignLogRetrievalResponsesArrayBaseSlot, foreignScope) {
|
|
444
510
|
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
445
511
|
const logRetrievalRequestsArrayBaseSlot = fromSingle(foreignLogRetrievalRequestsArrayBaseSlot);
|
|
446
512
|
const logRetrievalResponsesArrayBaseSlot = fromSingle(foreignLogRetrievalResponsesArrayBaseSlot);
|
|
447
|
-
|
|
513
|
+
const scope = AztecAddress.fromField(fromSingle(foreignScope));
|
|
514
|
+
await this.handlerAsUtility().getLogsByTag(contractAddress, logRetrievalRequestsArrayBaseSlot, logRetrievalResponsesArrayBaseSlot, scope);
|
|
448
515
|
return toForeignCallResult([]);
|
|
449
516
|
}
|
|
450
|
-
|
|
517
|
+
// eslint-disable-next-line camelcase
|
|
518
|
+
async aztec_utl_getMessageContextsByTxHash(foreignContractAddress, foreignMessageContextRequestsArrayBaseSlot, foreignMessageContextResponsesArrayBaseSlot, foreignScope) {
|
|
519
|
+
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
520
|
+
const messageContextRequestsArrayBaseSlot = fromSingle(foreignMessageContextRequestsArrayBaseSlot);
|
|
521
|
+
const messageContextResponsesArrayBaseSlot = fromSingle(foreignMessageContextResponsesArrayBaseSlot);
|
|
522
|
+
const scope = AztecAddress.fromField(fromSingle(foreignScope));
|
|
523
|
+
await this.handlerAsUtility().getMessageContextsByTxHash(contractAddress, messageContextRequestsArrayBaseSlot, messageContextResponsesArrayBaseSlot, scope);
|
|
524
|
+
return toForeignCallResult([]);
|
|
525
|
+
}
|
|
526
|
+
// eslint-disable-next-line camelcase
|
|
527
|
+
async aztec_utl_getLogsByTag_v2(foreignRequestArrayBaseSlot) {
|
|
528
|
+
const requestArrayBaseSlot = fromSingle(foreignRequestArrayBaseSlot);
|
|
529
|
+
const responseSlot = await this.handlerAsUtility().getLogsByTagV2(requestArrayBaseSlot);
|
|
530
|
+
return toForeignCallResult([
|
|
531
|
+
toSingle(responseSlot)
|
|
532
|
+
]);
|
|
533
|
+
}
|
|
534
|
+
// eslint-disable-next-line camelcase
|
|
535
|
+
async aztec_utl_getMessageContextsByTxHash_v2(foreignRequestArrayBaseSlot) {
|
|
536
|
+
const requestArrayBaseSlot = fromSingle(foreignRequestArrayBaseSlot);
|
|
537
|
+
const responseSlot = await this.handlerAsUtility().getMessageContextsByTxHashV2(requestArrayBaseSlot);
|
|
538
|
+
return toForeignCallResult([
|
|
539
|
+
toSingle(responseSlot)
|
|
540
|
+
]);
|
|
541
|
+
}
|
|
542
|
+
// eslint-disable-next-line camelcase
|
|
543
|
+
aztec_utl_setCapsule(foreignContractAddress, foreignSlot, foreignCapsule, foreignScope) {
|
|
451
544
|
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
452
545
|
const slot = fromSingle(foreignSlot);
|
|
453
546
|
const capsule = fromArray(foreignCapsule);
|
|
454
|
-
|
|
547
|
+
const scope = AztecAddress.fromField(fromSingle(foreignScope));
|
|
548
|
+
this.handlerAsUtility().setCapsule(contractAddress, slot, capsule, scope);
|
|
455
549
|
return toForeignCallResult([]);
|
|
456
550
|
}
|
|
457
|
-
|
|
551
|
+
// eslint-disable-next-line camelcase
|
|
552
|
+
async aztec_utl_getCapsule(foreignContractAddress, foreignSlot, foreignTSize, foreignScope) {
|
|
458
553
|
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
459
554
|
const slot = fromSingle(foreignSlot);
|
|
460
555
|
const tSize = fromSingle(foreignTSize).toNumber();
|
|
461
|
-
const
|
|
556
|
+
const scope = AztecAddress.fromField(fromSingle(foreignScope));
|
|
557
|
+
const values = await this.handlerAsUtility().getCapsule(contractAddress, slot, scope);
|
|
462
558
|
// We are going to return a Noir Option struct to represent the possibility of null values. Options are a struct
|
|
463
559
|
// with two fields: `some` (a boolean) and `value` (a field array in this case).
|
|
464
560
|
if (values === null) {
|
|
@@ -475,203 +571,316 @@ export class RPCTranslator {
|
|
|
475
571
|
]);
|
|
476
572
|
}
|
|
477
573
|
}
|
|
478
|
-
|
|
574
|
+
// eslint-disable-next-line camelcase
|
|
575
|
+
aztec_utl_deleteCapsule(foreignContractAddress, foreignSlot, foreignScope) {
|
|
479
576
|
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
480
577
|
const slot = fromSingle(foreignSlot);
|
|
481
|
-
|
|
578
|
+
const scope = AztecAddress.fromField(fromSingle(foreignScope));
|
|
579
|
+
this.handlerAsUtility().deleteCapsule(contractAddress, slot, scope);
|
|
482
580
|
return toForeignCallResult([]);
|
|
483
581
|
}
|
|
484
|
-
|
|
582
|
+
// eslint-disable-next-line camelcase
|
|
583
|
+
async aztec_utl_copyCapsule(foreignContractAddress, foreignSrcSlot, foreignDstSlot, foreignNumEntries, foreignScope) {
|
|
485
584
|
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
486
585
|
const srcSlot = fromSingle(foreignSrcSlot);
|
|
487
586
|
const dstSlot = fromSingle(foreignDstSlot);
|
|
488
587
|
const numEntries = fromSingle(foreignNumEntries).toNumber();
|
|
489
|
-
|
|
588
|
+
const scope = AztecAddress.fromField(fromSingle(foreignScope));
|
|
589
|
+
await this.handlerAsUtility().copyCapsule(contractAddress, srcSlot, dstSlot, numEntries, scope);
|
|
590
|
+
return toForeignCallResult([]);
|
|
591
|
+
}
|
|
592
|
+
// eslint-disable-next-line camelcase
|
|
593
|
+
aztec_utl_pushEphemeral(foreignSlot, foreignElements) {
|
|
594
|
+
const slot = fromSingle(foreignSlot);
|
|
595
|
+
const elements = fromArray(foreignElements);
|
|
596
|
+
const newLen = this.handlerAsUtility().pushEphemeral(slot, elements);
|
|
597
|
+
return toForeignCallResult([
|
|
598
|
+
toSingle(new Fr(newLen))
|
|
599
|
+
]);
|
|
600
|
+
}
|
|
601
|
+
// eslint-disable-next-line camelcase
|
|
602
|
+
aztec_utl_popEphemeral(foreignSlot) {
|
|
603
|
+
const slot = fromSingle(foreignSlot);
|
|
604
|
+
const element = this.handlerAsUtility().popEphemeral(slot);
|
|
605
|
+
return toForeignCallResult([
|
|
606
|
+
toArray(element)
|
|
607
|
+
]);
|
|
608
|
+
}
|
|
609
|
+
// eslint-disable-next-line camelcase
|
|
610
|
+
aztec_utl_getEphemeral(foreignSlot, foreignIndex) {
|
|
611
|
+
const slot = fromSingle(foreignSlot);
|
|
612
|
+
const index = fromSingle(foreignIndex).toNumber();
|
|
613
|
+
const element = this.handlerAsUtility().getEphemeral(slot, index);
|
|
614
|
+
return toForeignCallResult([
|
|
615
|
+
toArray(element)
|
|
616
|
+
]);
|
|
617
|
+
}
|
|
618
|
+
// eslint-disable-next-line camelcase
|
|
619
|
+
aztec_utl_setEphemeral(foreignSlot, foreignIndex, foreignElements) {
|
|
620
|
+
const slot = fromSingle(foreignSlot);
|
|
621
|
+
const index = fromSingle(foreignIndex).toNumber();
|
|
622
|
+
const elements = fromArray(foreignElements);
|
|
623
|
+
this.handlerAsUtility().setEphemeral(slot, index, elements);
|
|
624
|
+
return toForeignCallResult([]);
|
|
625
|
+
}
|
|
626
|
+
// eslint-disable-next-line camelcase
|
|
627
|
+
aztec_utl_getEphemeralLen(foreignSlot) {
|
|
628
|
+
const slot = fromSingle(foreignSlot);
|
|
629
|
+
const len = this.handlerAsUtility().getEphemeralLen(slot);
|
|
630
|
+
return toForeignCallResult([
|
|
631
|
+
toSingle(new Fr(len))
|
|
632
|
+
]);
|
|
633
|
+
}
|
|
634
|
+
// eslint-disable-next-line camelcase
|
|
635
|
+
aztec_utl_removeEphemeral(foreignSlot, foreignIndex) {
|
|
636
|
+
const slot = fromSingle(foreignSlot);
|
|
637
|
+
const index = fromSingle(foreignIndex).toNumber();
|
|
638
|
+
this.handlerAsUtility().removeEphemeral(slot, index);
|
|
639
|
+
return toForeignCallResult([]);
|
|
640
|
+
}
|
|
641
|
+
// eslint-disable-next-line camelcase
|
|
642
|
+
aztec_utl_clearEphemeral(foreignSlot) {
|
|
643
|
+
const slot = fromSingle(foreignSlot);
|
|
644
|
+
this.handlerAsUtility().clearEphemeral(slot);
|
|
490
645
|
return toForeignCallResult([]);
|
|
491
646
|
}
|
|
492
647
|
// TODO: I forgot to add a corresponding function here, when I introduced an oracle method to txe_oracle.ts.
|
|
493
648
|
// The compiler didn't throw an error, so it took me a while to learn of the existence of this file, and that I need
|
|
494
649
|
// to implement this function here. Isn't there a way to programmatically identify that this is missing, given the
|
|
495
650
|
// existence of a txe_oracle method?
|
|
496
|
-
|
|
651
|
+
// eslint-disable-next-line camelcase
|
|
652
|
+
async aztec_utl_decryptAes128(foreignCiphertextBVecStorage, foreignCiphertextLength, foreignIv, foreignSymKey) {
|
|
497
653
|
const ciphertext = fromUintBoundedVec(foreignCiphertextBVecStorage, foreignCiphertextLength, 8);
|
|
498
654
|
const iv = fromUintArray(foreignIv, 8);
|
|
499
655
|
const symKey = fromUintArray(foreignSymKey, 8);
|
|
500
|
-
|
|
501
|
-
|
|
656
|
+
// Noir Option<BoundedVec> is encoded as [is_some: Field, storage: Field[], length: Field].
|
|
657
|
+
try {
|
|
658
|
+
const plaintextBuffer = await this.handlerAsUtility().decryptAes128(ciphertext, iv, symKey);
|
|
659
|
+
const [storage, length] = arrayToBoundedVec(bufferToU8Array(plaintextBuffer), foreignCiphertextBVecStorage.length);
|
|
660
|
+
return toForeignCallResult([
|
|
661
|
+
toSingle(new Fr(1)),
|
|
662
|
+
storage,
|
|
663
|
+
length
|
|
664
|
+
]);
|
|
665
|
+
} catch {
|
|
666
|
+
const zeroStorage = toArray(Array(foreignCiphertextBVecStorage.length).fill(new Fr(0)));
|
|
667
|
+
return toForeignCallResult([
|
|
668
|
+
toSingle(new Fr(0)),
|
|
669
|
+
zeroStorage,
|
|
670
|
+
toSingle(new Fr(0))
|
|
671
|
+
]);
|
|
672
|
+
}
|
|
502
673
|
}
|
|
503
|
-
|
|
674
|
+
// eslint-disable-next-line camelcase
|
|
675
|
+
async aztec_utl_getSharedSecret(foreignAddress, foreignEphPKField0, foreignEphPKField1, foreignEphPKField2, foreignContractAddress) {
|
|
504
676
|
const address = AztecAddress.fromField(fromSingle(foreignAddress));
|
|
505
677
|
const ephPK = Point.fromFields([
|
|
506
678
|
fromSingle(foreignEphPKField0),
|
|
507
679
|
fromSingle(foreignEphPKField1),
|
|
508
680
|
fromSingle(foreignEphPKField2)
|
|
509
681
|
]);
|
|
510
|
-
const
|
|
511
|
-
|
|
682
|
+
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
683
|
+
const secret = await this.handlerAsUtility().getSharedSecret(address, ephPK, contractAddress);
|
|
684
|
+
return toForeignCallResult([
|
|
685
|
+
toSingle(secret)
|
|
686
|
+
]);
|
|
687
|
+
}
|
|
688
|
+
// eslint-disable-next-line camelcase
|
|
689
|
+
aztec_utl_setContractSyncCacheInvalid(foreignContractAddress, foreignScopes, foreignScopeCount) {
|
|
690
|
+
const contractAddress = addressFromSingle(foreignContractAddress);
|
|
691
|
+
const count = fromSingle(foreignScopeCount).toNumber();
|
|
692
|
+
const scopes = fromArray(foreignScopes).slice(0, count).map((f)=>new AztecAddress(f));
|
|
693
|
+
this.handlerAsUtility().setContractSyncCacheInvalid(contractAddress, scopes);
|
|
694
|
+
return Promise.resolve(toForeignCallResult([]));
|
|
512
695
|
}
|
|
513
|
-
|
|
696
|
+
// eslint-disable-next-line camelcase
|
|
697
|
+
aztec_utl_emitOffchainEffect(_foreignData) {
|
|
514
698
|
throw new Error('Offchain effects are not yet supported in the TestEnvironment');
|
|
515
699
|
}
|
|
516
700
|
// AVM opcodes
|
|
517
|
-
|
|
701
|
+
// eslint-disable-next-line camelcase
|
|
702
|
+
aztec_avm_emitPublicLog(_foreignMessage) {
|
|
518
703
|
// TODO(#8811): Implement
|
|
519
704
|
return toForeignCallResult([]);
|
|
520
705
|
}
|
|
521
|
-
|
|
706
|
+
// eslint-disable-next-line camelcase
|
|
707
|
+
async aztec_avm_storageRead(foreignSlot, foreignContractAddress) {
|
|
522
708
|
const slot = fromSingle(foreignSlot);
|
|
523
709
|
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
524
|
-
const value = (await this.handlerAsAvm().
|
|
710
|
+
const value = (await this.handlerAsAvm().storageRead(slot, contractAddress)).value;
|
|
525
711
|
return toForeignCallResult([
|
|
526
712
|
toSingle(new Fr(value))
|
|
527
713
|
]);
|
|
528
714
|
}
|
|
529
|
-
|
|
715
|
+
// eslint-disable-next-line camelcase
|
|
716
|
+
async aztec_avm_storageWrite(foreignSlot, foreignValue) {
|
|
530
717
|
const slot = fromSingle(foreignSlot);
|
|
531
718
|
const value = fromSingle(foreignValue);
|
|
532
|
-
await this.handlerAsAvm().
|
|
719
|
+
await this.handlerAsAvm().storageWrite(slot, value);
|
|
533
720
|
return toForeignCallResult([]);
|
|
534
721
|
}
|
|
535
|
-
|
|
722
|
+
// eslint-disable-next-line camelcase
|
|
723
|
+
async aztec_avm_getContractInstanceDeployer(foreignAddress) {
|
|
536
724
|
const address = addressFromSingle(foreignAddress);
|
|
537
|
-
const instance = await this.handlerAsUtility().
|
|
725
|
+
const instance = await this.handlerAsUtility().getContractInstance(address);
|
|
538
726
|
return toForeignCallResult([
|
|
539
727
|
toSingle(instance.deployer),
|
|
540
728
|
// AVM requires an extra boolean indicating the instance was found
|
|
541
729
|
toSingle(new Fr(1))
|
|
542
730
|
]);
|
|
543
731
|
}
|
|
544
|
-
|
|
732
|
+
// eslint-disable-next-line camelcase
|
|
733
|
+
async aztec_avm_getContractInstanceClassId(foreignAddress) {
|
|
545
734
|
const address = addressFromSingle(foreignAddress);
|
|
546
|
-
const instance = await this.handlerAsUtility().
|
|
735
|
+
const instance = await this.handlerAsUtility().getContractInstance(address);
|
|
547
736
|
return toForeignCallResult([
|
|
548
737
|
toSingle(instance.currentContractClassId),
|
|
549
738
|
// AVM requires an extra boolean indicating the instance was found
|
|
550
739
|
toSingle(new Fr(1))
|
|
551
740
|
]);
|
|
552
741
|
}
|
|
553
|
-
|
|
742
|
+
// eslint-disable-next-line camelcase
|
|
743
|
+
async aztec_avm_getContractInstanceInitializationHash(foreignAddress) {
|
|
554
744
|
const address = addressFromSingle(foreignAddress);
|
|
555
|
-
const instance = await this.handlerAsUtility().
|
|
745
|
+
const instance = await this.handlerAsUtility().getContractInstance(address);
|
|
556
746
|
return toForeignCallResult([
|
|
557
747
|
toSingle(instance.initializationHash),
|
|
558
748
|
// AVM requires an extra boolean indicating the instance was found
|
|
559
749
|
toSingle(new Fr(1))
|
|
560
750
|
]);
|
|
561
751
|
}
|
|
562
|
-
|
|
563
|
-
|
|
752
|
+
// eslint-disable-next-line camelcase
|
|
753
|
+
async aztec_avm_sender() {
|
|
754
|
+
const sender = await this.handlerAsAvm().sender();
|
|
564
755
|
return toForeignCallResult([
|
|
565
756
|
toSingle(sender)
|
|
566
757
|
]);
|
|
567
758
|
}
|
|
568
|
-
|
|
759
|
+
// eslint-disable-next-line camelcase
|
|
760
|
+
async aztec_avm_emitNullifier(foreignNullifier) {
|
|
569
761
|
const nullifier = fromSingle(foreignNullifier);
|
|
570
|
-
await this.handlerAsAvm().
|
|
762
|
+
await this.handlerAsAvm().emitNullifier(nullifier);
|
|
571
763
|
return toForeignCallResult([]);
|
|
572
764
|
}
|
|
573
|
-
|
|
765
|
+
// eslint-disable-next-line camelcase
|
|
766
|
+
async aztec_avm_emitNoteHash(foreignNoteHash) {
|
|
574
767
|
const noteHash = fromSingle(foreignNoteHash);
|
|
575
|
-
await this.handlerAsAvm().
|
|
768
|
+
await this.handlerAsAvm().emitNoteHash(noteHash);
|
|
576
769
|
return toForeignCallResult([]);
|
|
577
770
|
}
|
|
578
|
-
|
|
771
|
+
// eslint-disable-next-line camelcase
|
|
772
|
+
async aztec_avm_nullifierExists(foreignSiloedNullifier) {
|
|
579
773
|
const siloedNullifier = fromSingle(foreignSiloedNullifier);
|
|
580
|
-
const exists = await this.handlerAsAvm().
|
|
774
|
+
const exists = await this.handlerAsAvm().nullifierExists(siloedNullifier);
|
|
581
775
|
return toForeignCallResult([
|
|
582
776
|
toSingle(new Fr(exists))
|
|
583
777
|
]);
|
|
584
778
|
}
|
|
585
|
-
|
|
586
|
-
|
|
779
|
+
// eslint-disable-next-line camelcase
|
|
780
|
+
async aztec_avm_address() {
|
|
781
|
+
const contractAddress = await this.handlerAsAvm().address();
|
|
587
782
|
return toForeignCallResult([
|
|
588
783
|
toSingle(contractAddress.toField())
|
|
589
784
|
]);
|
|
590
785
|
}
|
|
591
|
-
|
|
592
|
-
|
|
786
|
+
// eslint-disable-next-line camelcase
|
|
787
|
+
async aztec_avm_blockNumber() {
|
|
788
|
+
const blockNumber = await this.handlerAsAvm().blockNumber();
|
|
593
789
|
return toForeignCallResult([
|
|
594
790
|
toSingle(new Fr(blockNumber))
|
|
595
791
|
]);
|
|
596
792
|
}
|
|
597
|
-
|
|
598
|
-
|
|
793
|
+
// eslint-disable-next-line camelcase
|
|
794
|
+
async aztec_avm_timestamp() {
|
|
795
|
+
const timestamp = await this.handlerAsAvm().timestamp();
|
|
599
796
|
return toForeignCallResult([
|
|
600
797
|
toSingle(new Fr(timestamp))
|
|
601
798
|
]);
|
|
602
799
|
}
|
|
603
|
-
|
|
604
|
-
|
|
800
|
+
// eslint-disable-next-line camelcase
|
|
801
|
+
async aztec_avm_isStaticCall() {
|
|
802
|
+
const isStaticCall = await this.handlerAsAvm().isStaticCall();
|
|
605
803
|
return toForeignCallResult([
|
|
606
804
|
toSingle(new Fr(isStaticCall ? 1 : 0))
|
|
607
805
|
]);
|
|
608
806
|
}
|
|
609
|
-
|
|
610
|
-
|
|
807
|
+
// eslint-disable-next-line camelcase
|
|
808
|
+
async aztec_avm_chainId() {
|
|
809
|
+
const chainId = await this.handlerAsAvm().chainId();
|
|
611
810
|
return toForeignCallResult([
|
|
612
811
|
toSingle(chainId)
|
|
613
812
|
]);
|
|
614
813
|
}
|
|
615
|
-
|
|
616
|
-
|
|
814
|
+
// eslint-disable-next-line camelcase
|
|
815
|
+
async aztec_avm_version() {
|
|
816
|
+
const version = await this.handlerAsAvm().version();
|
|
617
817
|
return toForeignCallResult([
|
|
618
818
|
toSingle(version)
|
|
619
819
|
]);
|
|
620
820
|
}
|
|
621
|
-
|
|
821
|
+
// eslint-disable-next-line camelcase
|
|
822
|
+
aztec_avm_returndataSize() {
|
|
622
823
|
throw new Error('Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead');
|
|
623
824
|
}
|
|
624
|
-
|
|
825
|
+
// eslint-disable-next-line camelcase
|
|
826
|
+
aztec_avm_returndataCopy(_foreignRdOffset, _foreignCopySize) {
|
|
625
827
|
throw new Error('Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead');
|
|
626
828
|
}
|
|
627
|
-
|
|
829
|
+
// eslint-disable-next-line camelcase
|
|
830
|
+
aztec_avm_call(_foreignL2Gas, _foreignDaGas, _foreignAddress, _foreignLength, _foreignArgs) {
|
|
628
831
|
throw new Error('Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead');
|
|
629
832
|
}
|
|
630
|
-
|
|
833
|
+
// eslint-disable-next-line camelcase
|
|
834
|
+
aztec_avm_staticCall(_foreignL2Gas, _foreignDaGas, _foreignAddress, _foreignLength, _foreignArgs) {
|
|
631
835
|
throw new Error('Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead');
|
|
632
836
|
}
|
|
633
|
-
|
|
837
|
+
// eslint-disable-next-line camelcase
|
|
838
|
+
aztec_avm_successCopy() {
|
|
634
839
|
throw new Error('Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead');
|
|
635
840
|
}
|
|
636
|
-
|
|
841
|
+
// eslint-disable-next-line camelcase
|
|
842
|
+
async aztec_txe_privateCallNewFlow(foreignFrom, foreignTargetContractAddress, foreignFunctionSelector, foreignArgs, foreignArgsHash, foreignIsStaticCall) {
|
|
637
843
|
const from = addressFromSingle(foreignFrom);
|
|
638
844
|
const targetContractAddress = addressFromSingle(foreignTargetContractAddress);
|
|
639
845
|
const functionSelector = FunctionSelector.fromField(fromSingle(foreignFunctionSelector));
|
|
640
846
|
const args = fromArray(foreignArgs);
|
|
641
847
|
const argsHash = fromSingle(foreignArgsHash);
|
|
642
848
|
const isStaticCall = fromSingle(foreignIsStaticCall).toBool();
|
|
643
|
-
const returnValues = await this.handlerAsTxe().
|
|
849
|
+
const returnValues = await this.handlerAsTxe().privateCallNewFlow(from, targetContractAddress, functionSelector, args, argsHash, isStaticCall, this.stateHandler.getCurrentJob());
|
|
644
850
|
// TODO(F-335): Avoid doing the following call here.
|
|
645
851
|
await this.stateHandler.cycleJob();
|
|
646
852
|
return toForeignCallResult([
|
|
647
853
|
toArray(returnValues)
|
|
648
854
|
]);
|
|
649
855
|
}
|
|
650
|
-
|
|
856
|
+
// eslint-disable-next-line camelcase
|
|
857
|
+
async aztec_txe_executeUtilityFunction(foreignTargetContractAddress, foreignFunctionSelector, foreignArgs) {
|
|
651
858
|
const targetContractAddress = addressFromSingle(foreignTargetContractAddress);
|
|
652
859
|
const functionSelector = FunctionSelector.fromField(fromSingle(foreignFunctionSelector));
|
|
653
860
|
const args = fromArray(foreignArgs);
|
|
654
|
-
const returnValues = await this.handlerAsTxe().
|
|
861
|
+
const returnValues = await this.handlerAsTxe().executeUtilityFunction(targetContractAddress, functionSelector, args, this.stateHandler.getCurrentJob());
|
|
655
862
|
// TODO(F-335): Avoid doing the following call here.
|
|
656
863
|
await this.stateHandler.cycleJob();
|
|
657
864
|
return toForeignCallResult([
|
|
658
865
|
toArray(returnValues)
|
|
659
866
|
]);
|
|
660
867
|
}
|
|
661
|
-
|
|
868
|
+
// eslint-disable-next-line camelcase
|
|
869
|
+
async aztec_txe_publicCallNewFlow(foreignFrom, foreignAddress, foreignCalldata, foreignIsStaticCall) {
|
|
662
870
|
const from = addressFromSingle(foreignFrom);
|
|
663
871
|
const address = addressFromSingle(foreignAddress);
|
|
664
872
|
const calldata = fromArray(foreignCalldata);
|
|
665
873
|
const isStaticCall = fromSingle(foreignIsStaticCall).toBool();
|
|
666
|
-
const returnValues = await this.handlerAsTxe().
|
|
874
|
+
const returnValues = await this.handlerAsTxe().publicCallNewFlow(from, address, calldata, isStaticCall);
|
|
667
875
|
// TODO(F-335): Avoid doing the following call here.
|
|
668
876
|
await this.stateHandler.cycleJob();
|
|
669
877
|
return toForeignCallResult([
|
|
670
878
|
toArray(returnValues)
|
|
671
879
|
]);
|
|
672
880
|
}
|
|
673
|
-
|
|
674
|
-
|
|
881
|
+
// eslint-disable-next-line camelcase
|
|
882
|
+
async aztec_prv_getSenderForTags() {
|
|
883
|
+
const sender = await this.handlerAsPrivate().getSenderForTags();
|
|
675
884
|
// Return a Noir Option struct with `some` and `value` fields
|
|
676
885
|
if (sender === undefined) {
|
|
677
886
|
// No sender found, return Option with some=0 and value=0
|
|
@@ -687,15 +896,17 @@ export class RPCTranslator {
|
|
|
687
896
|
]);
|
|
688
897
|
}
|
|
689
898
|
}
|
|
690
|
-
|
|
899
|
+
// eslint-disable-next-line camelcase
|
|
900
|
+
async aztec_prv_setSenderForTags(foreignSenderForTags) {
|
|
691
901
|
const senderForTags = AztecAddress.fromField(fromSingle(foreignSenderForTags));
|
|
692
|
-
await this.handlerAsPrivate().
|
|
902
|
+
await this.handlerAsPrivate().setSenderForTags(senderForTags);
|
|
693
903
|
return toForeignCallResult([]);
|
|
694
904
|
}
|
|
695
|
-
|
|
905
|
+
// eslint-disable-next-line camelcase
|
|
906
|
+
async aztec_prv_getNextAppTagAsSender(foreignSender, foreignRecipient) {
|
|
696
907
|
const sender = AztecAddress.fromField(fromSingle(foreignSender));
|
|
697
908
|
const recipient = AztecAddress.fromField(fromSingle(foreignRecipient));
|
|
698
|
-
const nextAppTag = await this.handlerAsPrivate().
|
|
909
|
+
const nextAppTag = await this.handlerAsPrivate().getNextAppTagAsSender(sender, recipient);
|
|
699
910
|
return toForeignCallResult([
|
|
700
911
|
toSingle(nextAppTag.value)
|
|
701
912
|
]);
|