@aztec/txe 0.0.1-commit.f146247c → 0.0.1-commit.f1b29a41e
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 +88 -54
- package/dest/oracle/interfaces.d.ts +29 -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 +23 -23
- package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_top_level_context.js +126 -51
- package/dest/rpc_translator.d.ts +88 -83
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +303 -158
- 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 +9 -8
- package/dest/state_machine/dummy_p2p_client.d.ts +18 -13
- package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
- package/dest/state_machine/dummy_p2p_client.js +33 -18
- package/dest/state_machine/global_variable_builder.d.ts +3 -3
- 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 +8 -5
- package/dest/state_machine/index.d.ts.map +1 -1
- package/dest/state_machine/index.js +19 -10
- package/dest/state_machine/mock_epoch_cache.d.ts +19 -3
- package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
- package/dest/state_machine/mock_epoch_cache.js +36 -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 +10 -6
- package/dest/txe_session.d.ts.map +1 -1
- package/dest/txe_session.js +93 -25
- 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 +2 -3
- package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
- package/dest/util/txe_public_contract_data_source.js +6 -25
- package/dest/utils/block_creation.d.ts +1 -1
- package/dest/utils/block_creation.d.ts.map +1 -1
- package/dest/utils/block_creation.js +3 -1
- package/package.json +15 -15
- package/src/index.ts +89 -52
- package/src/oracle/interfaces.ts +32 -31
- package/src/oracle/txe_oracle_public_context.ts +12 -12
- package/src/oracle/txe_oracle_top_level_context.ts +143 -97
- package/src/rpc_translator.ts +344 -175
- package/src/state_machine/archiver.ts +8 -5
- package/src/state_machine/dummy_p2p_client.ts +46 -24
- package/src/state_machine/global_variable_builder.ts +7 -1
- package/src/state_machine/index.ts +33 -9
- package/src/state_machine/mock_epoch_cache.ts +47 -3
- package/src/state_machine/synchronizer.ts +4 -4
- package/src/txe_session.ts +106 -72
- package/src/util/txe_public_contract_data_source.ts +10 -38
- package/src/utils/block_creation.ts +3 -1
- package/dest/util/txe_contract_store.d.ts +0 -12
- package/dest/util/txe_contract_store.d.ts.map +0 -1
- package/dest/util/txe_contract_store.js +0 -22
- package/src/util/txe_contract_store.ts +0 -36
package/src/rpc_translator.ts
CHANGED
|
@@ -30,7 +30,7 @@ import {
|
|
|
30
30
|
toSingle,
|
|
31
31
|
} from './util/encoding.js';
|
|
32
32
|
|
|
33
|
-
const MAX_EVENT_LEN =
|
|
33
|
+
const MAX_EVENT_LEN = 10; // This is MAX_MESSAGE_CONTENT_LEN - PRIVATE_EVENT_MSG_PLAINTEXT_RESERVED_FIELDS_LEN
|
|
34
34
|
const MAX_PRIVATE_EVENTS_PER_TXE_QUERY = 5;
|
|
35
35
|
|
|
36
36
|
export class UnavailableOracleError extends Error {
|
|
@@ -104,13 +104,15 @@ export class RPCTranslator {
|
|
|
104
104
|
|
|
105
105
|
// TXE session state transition functions - these get handled by the state handler
|
|
106
106
|
|
|
107
|
-
|
|
107
|
+
// eslint-disable-next-line camelcase
|
|
108
|
+
async aztec_txe_setTopLevelTXEContext() {
|
|
108
109
|
await this.stateHandler.enterTopLevelState();
|
|
109
110
|
|
|
110
111
|
return toForeignCallResult([]);
|
|
111
112
|
}
|
|
112
113
|
|
|
113
|
-
|
|
114
|
+
// eslint-disable-next-line camelcase
|
|
115
|
+
async aztec_txe_setPrivateTXEContext(
|
|
114
116
|
foreignContractAddressIsSome: ForeignCallSingle,
|
|
115
117
|
foreignContractAddressValue: ForeignCallSingle,
|
|
116
118
|
foreignAnchorBlockNumberIsSome: ForeignCallSingle,
|
|
@@ -129,7 +131,8 @@ export class RPCTranslator {
|
|
|
129
131
|
return toForeignCallResult(privateContextInputs.toFields().map(toSingle));
|
|
130
132
|
}
|
|
131
133
|
|
|
132
|
-
|
|
134
|
+
// eslint-disable-next-line camelcase
|
|
135
|
+
async aztec_txe_setPublicTXEContext(
|
|
133
136
|
foreignContractAddressIsSome: ForeignCallSingle,
|
|
134
137
|
foreignContractAddressValue: ForeignCallSingle,
|
|
135
138
|
) {
|
|
@@ -142,7 +145,8 @@ export class RPCTranslator {
|
|
|
142
145
|
return toForeignCallResult([]);
|
|
143
146
|
}
|
|
144
147
|
|
|
145
|
-
|
|
148
|
+
// eslint-disable-next-line camelcase
|
|
149
|
+
async aztec_txe_setUtilityTXEContext(
|
|
146
150
|
foreignContractAddressIsSome: ForeignCallSingle,
|
|
147
151
|
foreignContractAddressValue: ForeignCallSingle,
|
|
148
152
|
) {
|
|
@@ -159,44 +163,54 @@ export class RPCTranslator {
|
|
|
159
163
|
|
|
160
164
|
// TXE-specific oracles
|
|
161
165
|
|
|
162
|
-
|
|
163
|
-
|
|
166
|
+
// eslint-disable-next-line camelcase
|
|
167
|
+
aztec_txe_getDefaultAddress() {
|
|
168
|
+
const defaultAddress = this.handlerAsTxe().getDefaultAddress();
|
|
164
169
|
|
|
165
170
|
return toForeignCallResult([toSingle(defaultAddress)]);
|
|
166
171
|
}
|
|
167
172
|
|
|
168
|
-
|
|
169
|
-
|
|
173
|
+
// eslint-disable-next-line camelcase
|
|
174
|
+
async aztec_txe_getNextBlockNumber() {
|
|
175
|
+
const nextBlockNumber = await this.handlerAsTxe().getNextBlockNumber();
|
|
170
176
|
|
|
171
177
|
return toForeignCallResult([toSingle(nextBlockNumber)]);
|
|
172
178
|
}
|
|
173
179
|
|
|
174
|
-
|
|
175
|
-
|
|
180
|
+
// eslint-disable-next-line camelcase
|
|
181
|
+
async aztec_txe_getNextBlockTimestamp() {
|
|
182
|
+
const nextBlockTimestamp = await this.handlerAsTxe().getNextBlockTimestamp();
|
|
176
183
|
|
|
177
184
|
return toForeignCallResult([toSingle(nextBlockTimestamp)]);
|
|
178
185
|
}
|
|
179
186
|
|
|
180
|
-
|
|
187
|
+
// eslint-disable-next-line camelcase
|
|
188
|
+
async aztec_txe_advanceBlocksBy(foreignBlocks: ForeignCallSingle) {
|
|
181
189
|
const blocks = fromSingle(foreignBlocks).toNumber();
|
|
182
190
|
|
|
183
|
-
await this.handlerAsTxe().
|
|
191
|
+
await this.handlerAsTxe().advanceBlocksBy(blocks);
|
|
184
192
|
|
|
185
193
|
return toForeignCallResult([]);
|
|
186
194
|
}
|
|
187
195
|
|
|
188
|
-
|
|
196
|
+
// eslint-disable-next-line camelcase
|
|
197
|
+
aztec_txe_advanceTimestampBy(foreignDuration: ForeignCallSingle) {
|
|
189
198
|
const duration = fromSingle(foreignDuration).toBigInt();
|
|
190
199
|
|
|
191
|
-
this.handlerAsTxe().
|
|
200
|
+
this.handlerAsTxe().advanceTimestampBy(duration);
|
|
192
201
|
|
|
193
202
|
return toForeignCallResult([]);
|
|
194
203
|
}
|
|
195
204
|
|
|
196
|
-
|
|
205
|
+
// eslint-disable-next-line camelcase
|
|
206
|
+
async aztec_txe_deploy(
|
|
207
|
+
artifact: ContractArtifact,
|
|
208
|
+
instance: ContractInstanceWithAddress,
|
|
209
|
+
foreignSecret: ForeignCallSingle,
|
|
210
|
+
) {
|
|
197
211
|
const secret = fromSingle(foreignSecret);
|
|
198
212
|
|
|
199
|
-
await this.handlerAsTxe().
|
|
213
|
+
await this.handlerAsTxe().deploy(artifact, instance, secret);
|
|
200
214
|
|
|
201
215
|
return toForeignCallResult([
|
|
202
216
|
toArray([
|
|
@@ -209,10 +223,11 @@ export class RPCTranslator {
|
|
|
209
223
|
]);
|
|
210
224
|
}
|
|
211
225
|
|
|
212
|
-
|
|
226
|
+
// eslint-disable-next-line camelcase
|
|
227
|
+
async aztec_txe_createAccount(foreignSecret: ForeignCallSingle) {
|
|
213
228
|
const secret = fromSingle(foreignSecret);
|
|
214
229
|
|
|
215
|
-
const completeAddress = await this.handlerAsTxe().
|
|
230
|
+
const completeAddress = await this.handlerAsTxe().createAccount(secret);
|
|
216
231
|
|
|
217
232
|
return toForeignCallResult([
|
|
218
233
|
toSingle(completeAddress.address),
|
|
@@ -220,14 +235,15 @@ export class RPCTranslator {
|
|
|
220
235
|
]);
|
|
221
236
|
}
|
|
222
237
|
|
|
223
|
-
|
|
238
|
+
// eslint-disable-next-line camelcase
|
|
239
|
+
async aztec_txe_addAccount(
|
|
224
240
|
artifact: ContractArtifact,
|
|
225
241
|
instance: ContractInstanceWithAddress,
|
|
226
242
|
foreignSecret: ForeignCallSingle,
|
|
227
243
|
) {
|
|
228
244
|
const secret = fromSingle(foreignSecret);
|
|
229
245
|
|
|
230
|
-
const completeAddress = await this.handlerAsTxe().
|
|
246
|
+
const completeAddress = await this.handlerAsTxe().addAccount(artifact, instance, secret);
|
|
231
247
|
|
|
232
248
|
return toForeignCallResult([
|
|
233
249
|
toSingle(completeAddress.address),
|
|
@@ -235,39 +251,44 @@ export class RPCTranslator {
|
|
|
235
251
|
]);
|
|
236
252
|
}
|
|
237
253
|
|
|
238
|
-
|
|
254
|
+
// eslint-disable-next-line camelcase
|
|
255
|
+
async aztec_txe_addAuthWitness(foreignAddress: ForeignCallSingle, foreignMessageHash: ForeignCallSingle) {
|
|
239
256
|
const address = addressFromSingle(foreignAddress);
|
|
240
257
|
const messageHash = fromSingle(foreignMessageHash);
|
|
241
258
|
|
|
242
|
-
await this.handlerAsTxe().
|
|
259
|
+
await this.handlerAsTxe().addAuthWitness(address, messageHash);
|
|
243
260
|
|
|
244
261
|
return toForeignCallResult([]);
|
|
245
262
|
}
|
|
246
263
|
|
|
247
264
|
// PXE oracles
|
|
248
265
|
|
|
249
|
-
|
|
266
|
+
// eslint-disable-next-line camelcase
|
|
267
|
+
aztec_utl_assertCompatibleOracleVersion(foreignVersion: ForeignCallSingle) {
|
|
250
268
|
const version = fromSingle(foreignVersion).toNumber();
|
|
251
269
|
|
|
252
|
-
this.handlerAsMisc().
|
|
270
|
+
this.handlerAsMisc().assertCompatibleOracleVersion(version);
|
|
253
271
|
|
|
254
272
|
return toForeignCallResult([]);
|
|
255
273
|
}
|
|
256
274
|
|
|
257
|
-
|
|
258
|
-
|
|
275
|
+
// eslint-disable-next-line camelcase
|
|
276
|
+
aztec_utl_getRandomField() {
|
|
277
|
+
const randomField = this.handlerAsMisc().getRandomField();
|
|
259
278
|
|
|
260
279
|
return toForeignCallResult([toSingle(randomField)]);
|
|
261
280
|
}
|
|
262
281
|
|
|
263
|
-
|
|
264
|
-
|
|
282
|
+
// eslint-disable-next-line camelcase
|
|
283
|
+
async aztec_txe_getLastBlockTimestamp() {
|
|
284
|
+
const timestamp = await this.handlerAsTxe().getLastBlockTimestamp();
|
|
265
285
|
|
|
266
286
|
return toForeignCallResult([toSingle(new Fr(timestamp))]);
|
|
267
287
|
}
|
|
268
288
|
|
|
269
|
-
|
|
270
|
-
|
|
289
|
+
// eslint-disable-next-line camelcase
|
|
290
|
+
async aztec_txe_getLastTxEffects() {
|
|
291
|
+
const { txHash, noteHashes, nullifiers } = await this.handlerAsTxe().getLastTxEffects();
|
|
271
292
|
|
|
272
293
|
return toForeignCallResult([
|
|
273
294
|
toSingle(txHash.hash),
|
|
@@ -276,7 +297,8 @@ export class RPCTranslator {
|
|
|
276
297
|
]);
|
|
277
298
|
}
|
|
278
299
|
|
|
279
|
-
|
|
300
|
+
// eslint-disable-next-line camelcase
|
|
301
|
+
async aztec_txe_getPrivateEvents(
|
|
280
302
|
foreignSelector: ForeignCallSingle,
|
|
281
303
|
foreignContractAddress: ForeignCallSingle,
|
|
282
304
|
foreignScope: ForeignCallSingle,
|
|
@@ -285,7 +307,14 @@ export class RPCTranslator {
|
|
|
285
307
|
const contractAddress = addressFromSingle(foreignContractAddress);
|
|
286
308
|
const scope = addressFromSingle(foreignScope);
|
|
287
309
|
|
|
288
|
-
|
|
310
|
+
// TODO(F-335): Avoid doing the following 2 calls here.
|
|
311
|
+
{
|
|
312
|
+
await this.handlerAsTxe().syncContractNonOracleMethod(contractAddress, scope, this.stateHandler.getCurrentJob());
|
|
313
|
+
// We cycle job to commit the stores after the contract sync.
|
|
314
|
+
await this.stateHandler.cycleJob();
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
const events = await this.handlerAsTxe().getPrivateEvents(selector, contractAddress, scope);
|
|
289
318
|
|
|
290
319
|
if (events.length > MAX_PRIVATE_EVENTS_PER_TXE_QUERY) {
|
|
291
320
|
throw new Error(`Array of length ${events.length} larger than maxLen ${MAX_PRIVATE_EVENTS_PER_TXE_QUERY}`);
|
|
@@ -309,26 +338,29 @@ export class RPCTranslator {
|
|
|
309
338
|
return toForeignCallResult([toArray(rawArrayStorage), toArray(eventLengths), toSingle(queryLength)]);
|
|
310
339
|
}
|
|
311
340
|
|
|
312
|
-
|
|
341
|
+
// eslint-disable-next-line camelcase
|
|
342
|
+
aztec_prv_setHashPreimage(foreignValues: ForeignCallArray, foreignHash: ForeignCallSingle) {
|
|
313
343
|
const values = fromArray(foreignValues);
|
|
314
344
|
const hash = fromSingle(foreignHash);
|
|
315
345
|
|
|
316
|
-
this.handlerAsPrivate().
|
|
346
|
+
this.handlerAsPrivate().setHashPreimage(values, hash);
|
|
317
347
|
|
|
318
348
|
return toForeignCallResult([]);
|
|
319
349
|
}
|
|
320
350
|
|
|
321
|
-
|
|
351
|
+
// eslint-disable-next-line camelcase
|
|
352
|
+
async aztec_prv_getHashPreimage(foreignHash: ForeignCallSingle) {
|
|
322
353
|
const hash = fromSingle(foreignHash);
|
|
323
354
|
|
|
324
|
-
const returns = await this.handlerAsPrivate().
|
|
355
|
+
const returns = await this.handlerAsPrivate().getHashPreimage(hash);
|
|
325
356
|
|
|
326
357
|
return toForeignCallResult([toArray(returns)]);
|
|
327
358
|
}
|
|
328
359
|
|
|
329
360
|
// When the argument is a slice, noir automatically adds a length field to oracle call.
|
|
330
361
|
// When the argument is an array, we add the field length manually to the signature.
|
|
331
|
-
|
|
362
|
+
// eslint-disable-next-line camelcase
|
|
363
|
+
async aztec_utl_log(
|
|
332
364
|
foreignLevel: ForeignCallSingle,
|
|
333
365
|
foreignMessage: ForeignCallArray,
|
|
334
366
|
_foreignLength: ForeignCallSingle,
|
|
@@ -340,12 +372,13 @@ export class RPCTranslator {
|
|
|
340
372
|
.join('');
|
|
341
373
|
const fields = fromArray(foreignFields);
|
|
342
374
|
|
|
343
|
-
this.handlerAsMisc().
|
|
375
|
+
await this.handlerAsMisc().log(level, message, fields);
|
|
344
376
|
|
|
345
377
|
return toForeignCallResult([]);
|
|
346
378
|
}
|
|
347
379
|
|
|
348
|
-
|
|
380
|
+
// eslint-disable-next-line camelcase
|
|
381
|
+
async aztec_utl_getFromPublicStorage(
|
|
349
382
|
foreignBlockHash: ForeignCallSingle,
|
|
350
383
|
foreignContractAddress: ForeignCallSingle,
|
|
351
384
|
foreignStartStorageSlot: ForeignCallSingle,
|
|
@@ -356,7 +389,7 @@ export class RPCTranslator {
|
|
|
356
389
|
const startStorageSlot = fromSingle(foreignStartStorageSlot);
|
|
357
390
|
const numberOfElements = fromSingle(foreignNumberOfElements).toNumber();
|
|
358
391
|
|
|
359
|
-
const values = await this.handlerAsUtility().
|
|
392
|
+
const values = await this.handlerAsUtility().getFromPublicStorage(
|
|
360
393
|
blockHash,
|
|
361
394
|
contractAddress,
|
|
362
395
|
startStorageSlot,
|
|
@@ -366,11 +399,12 @@ export class RPCTranslator {
|
|
|
366
399
|
return toForeignCallResult([toArray(values)]);
|
|
367
400
|
}
|
|
368
401
|
|
|
369
|
-
|
|
402
|
+
// eslint-disable-next-line camelcase
|
|
403
|
+
async aztec_utl_getPublicDataWitness(foreignBlockHash: ForeignCallSingle, foreignLeafSlot: ForeignCallSingle) {
|
|
370
404
|
const blockHash = new BlockHash(fromSingle(foreignBlockHash));
|
|
371
405
|
const leafSlot = fromSingle(foreignLeafSlot);
|
|
372
406
|
|
|
373
|
-
const witness = await this.handlerAsUtility().
|
|
407
|
+
const witness = await this.handlerAsUtility().getPublicDataWitness(blockHash, leafSlot);
|
|
374
408
|
|
|
375
409
|
if (!witness) {
|
|
376
410
|
throw new Error(`Public data witness not found for slot ${leafSlot} at block ${blockHash.toString()}.`);
|
|
@@ -378,7 +412,8 @@ export class RPCTranslator {
|
|
|
378
412
|
return toForeignCallResult(witness.toNoirRepresentation());
|
|
379
413
|
}
|
|
380
414
|
|
|
381
|
-
|
|
415
|
+
// eslint-disable-next-line camelcase
|
|
416
|
+
async aztec_utl_getNotes(
|
|
382
417
|
foreignOwnerIsSome: ForeignCallSingle,
|
|
383
418
|
foreignOwnerValue: ForeignCallSingle,
|
|
384
419
|
foreignStorageSlot: ForeignCallSingle,
|
|
@@ -419,7 +454,7 @@ export class RPCTranslator {
|
|
|
419
454
|
const maxNotes = fromSingle(foreignMaxNotes).toNumber();
|
|
420
455
|
const packedHintedNoteLength = fromSingle(foreignPackedHintedNoteLength).toNumber();
|
|
421
456
|
|
|
422
|
-
const noteDatas = await this.handlerAsUtility().
|
|
457
|
+
const noteDatas = await this.handlerAsUtility().getNotes(
|
|
423
458
|
owner,
|
|
424
459
|
storageSlot,
|
|
425
460
|
numSelects,
|
|
@@ -460,7 +495,8 @@ export class RPCTranslator {
|
|
|
460
495
|
);
|
|
461
496
|
}
|
|
462
497
|
|
|
463
|
-
|
|
498
|
+
// eslint-disable-next-line camelcase
|
|
499
|
+
aztec_prv_notifyCreatedNote(
|
|
464
500
|
foreignOwner: ForeignCallSingle,
|
|
465
501
|
foreignStorageSlot: ForeignCallSingle,
|
|
466
502
|
foreignRandomness: ForeignCallSingle,
|
|
@@ -477,20 +513,13 @@ export class RPCTranslator {
|
|
|
477
513
|
const noteHash = fromSingle(foreignNoteHash);
|
|
478
514
|
const counter = fromSingle(foreignCounter).toNumber();
|
|
479
515
|
|
|
480
|
-
this.handlerAsPrivate().
|
|
481
|
-
owner,
|
|
482
|
-
storageSlot,
|
|
483
|
-
randomness,
|
|
484
|
-
noteTypeId,
|
|
485
|
-
note,
|
|
486
|
-
noteHash,
|
|
487
|
-
counter,
|
|
488
|
-
);
|
|
516
|
+
this.handlerAsPrivate().notifyCreatedNote(owner, storageSlot, randomness, noteTypeId, note, noteHash, counter);
|
|
489
517
|
|
|
490
518
|
return toForeignCallResult([]);
|
|
491
519
|
}
|
|
492
520
|
|
|
493
|
-
|
|
521
|
+
// eslint-disable-next-line camelcase
|
|
522
|
+
async aztec_prv_notifyNullifiedNote(
|
|
494
523
|
foreignInnerNullifier: ForeignCallSingle,
|
|
495
524
|
foreignNoteHash: ForeignCallSingle,
|
|
496
525
|
foreignCounter: ForeignCallSingle,
|
|
@@ -499,40 +528,47 @@ export class RPCTranslator {
|
|
|
499
528
|
const noteHash = fromSingle(foreignNoteHash);
|
|
500
529
|
const counter = fromSingle(foreignCounter).toNumber();
|
|
501
530
|
|
|
502
|
-
await this.handlerAsPrivate().
|
|
531
|
+
await this.handlerAsPrivate().notifyNullifiedNote(innerNullifier, noteHash, counter);
|
|
503
532
|
|
|
504
533
|
return toForeignCallResult([]);
|
|
505
534
|
}
|
|
506
535
|
|
|
507
|
-
|
|
536
|
+
// eslint-disable-next-line camelcase
|
|
537
|
+
async aztec_prv_notifyCreatedNullifier(foreignInnerNullifier: ForeignCallSingle) {
|
|
508
538
|
const innerNullifier = fromSingle(foreignInnerNullifier);
|
|
509
539
|
|
|
510
|
-
await this.handlerAsPrivate().
|
|
540
|
+
await this.handlerAsPrivate().notifyCreatedNullifier(innerNullifier);
|
|
511
541
|
|
|
512
542
|
return toForeignCallResult([]);
|
|
513
543
|
}
|
|
514
544
|
|
|
515
|
-
|
|
545
|
+
// eslint-disable-next-line camelcase
|
|
546
|
+
async aztec_prv_isNullifierPending(
|
|
547
|
+
foreignInnerNullifier: ForeignCallSingle,
|
|
548
|
+
foreignContractAddress: ForeignCallSingle,
|
|
549
|
+
) {
|
|
516
550
|
const innerNullifier = fromSingle(foreignInnerNullifier);
|
|
517
551
|
const contractAddress = addressFromSingle(foreignContractAddress);
|
|
518
552
|
|
|
519
|
-
const isPending = await this.handlerAsPrivate().
|
|
553
|
+
const isPending = await this.handlerAsPrivate().isNullifierPending(innerNullifier, contractAddress);
|
|
520
554
|
|
|
521
555
|
return toForeignCallResult([toSingle(new Fr(isPending))]);
|
|
522
556
|
}
|
|
523
557
|
|
|
524
|
-
|
|
558
|
+
// eslint-disable-next-line camelcase
|
|
559
|
+
async aztec_utl_doesNullifierExist(foreignInnerNullifier: ForeignCallSingle) {
|
|
525
560
|
const innerNullifier = fromSingle(foreignInnerNullifier);
|
|
526
561
|
|
|
527
|
-
const exists = await this.handlerAsUtility().
|
|
562
|
+
const exists = await this.handlerAsUtility().doesNullifierExist(innerNullifier);
|
|
528
563
|
|
|
529
564
|
return toForeignCallResult([toSingle(new Fr(exists))]);
|
|
530
565
|
}
|
|
531
566
|
|
|
532
|
-
|
|
567
|
+
// eslint-disable-next-line camelcase
|
|
568
|
+
async aztec_utl_getContractInstance(foreignAddress: ForeignCallSingle) {
|
|
533
569
|
const address = addressFromSingle(foreignAddress);
|
|
534
570
|
|
|
535
|
-
const instance = await this.handlerAsUtility().
|
|
571
|
+
const instance = await this.handlerAsUtility().getContractInstance(address);
|
|
536
572
|
|
|
537
573
|
return toForeignCallResult(
|
|
538
574
|
[
|
|
@@ -545,23 +581,37 @@ export class RPCTranslator {
|
|
|
545
581
|
);
|
|
546
582
|
}
|
|
547
583
|
|
|
548
|
-
|
|
584
|
+
// eslint-disable-next-line camelcase
|
|
585
|
+
async aztec_utl_getPublicKeysAndPartialAddress(foreignAddress: ForeignCallSingle) {
|
|
549
586
|
const address = addressFromSingle(foreignAddress);
|
|
550
587
|
|
|
551
|
-
const
|
|
588
|
+
const result = await this.handlerAsUtility().getPublicKeysAndPartialAddress(address);
|
|
552
589
|
|
|
553
|
-
return
|
|
590
|
+
// We are going to return a Noir Option struct to represent the possibility of null values. Options are a struct
|
|
591
|
+
// with two fields: `some` (a boolean) and `value` (a field array in this case).
|
|
592
|
+
if (result === undefined) {
|
|
593
|
+
// No data was found so we set `some` to 0 and pad `value` with zeros get the correct return size.
|
|
594
|
+
return toForeignCallResult([toSingle(new Fr(0)), toArray(Array(13).fill(new Fr(0)))]);
|
|
595
|
+
} else {
|
|
596
|
+
// Data was found so we set `some` to 1 and return it along with `value`.
|
|
597
|
+
return toForeignCallResult([
|
|
598
|
+
toSingle(new Fr(1)),
|
|
599
|
+
toArray([...result.publicKeys.toFields(), result.partialAddress]),
|
|
600
|
+
]);
|
|
601
|
+
}
|
|
554
602
|
}
|
|
555
603
|
|
|
556
|
-
|
|
604
|
+
// eslint-disable-next-line camelcase
|
|
605
|
+
async aztec_utl_getKeyValidationRequest(foreignPkMHash: ForeignCallSingle) {
|
|
557
606
|
const pkMHash = fromSingle(foreignPkMHash);
|
|
558
607
|
|
|
559
|
-
const keyValidationRequest = await this.handlerAsUtility().
|
|
608
|
+
const keyValidationRequest = await this.handlerAsUtility().getKeyValidationRequest(pkMHash);
|
|
560
609
|
|
|
561
610
|
return toForeignCallResult(keyValidationRequest.toFields().map(toSingle));
|
|
562
611
|
}
|
|
563
612
|
|
|
564
|
-
|
|
613
|
+
// eslint-disable-next-line camelcase
|
|
614
|
+
aztec_prv_callPrivateFunction(
|
|
565
615
|
_foreignTargetContractAddress: ForeignCallSingle,
|
|
566
616
|
_foreignFunctionSelector: ForeignCallSingle,
|
|
567
617
|
_foreignArgsHash: ForeignCallSingle,
|
|
@@ -573,11 +623,15 @@ export class RPCTranslator {
|
|
|
573
623
|
);
|
|
574
624
|
}
|
|
575
625
|
|
|
576
|
-
|
|
626
|
+
// eslint-disable-next-line camelcase
|
|
627
|
+
async aztec_utl_getNullifierMembershipWitness(
|
|
628
|
+
foreignBlockHash: ForeignCallSingle,
|
|
629
|
+
foreignNullifier: ForeignCallSingle,
|
|
630
|
+
) {
|
|
577
631
|
const blockHash = new BlockHash(fromSingle(foreignBlockHash));
|
|
578
632
|
const nullifier = fromSingle(foreignNullifier);
|
|
579
633
|
|
|
580
|
-
const witness = await this.handlerAsUtility().
|
|
634
|
+
const witness = await this.handlerAsUtility().getNullifierMembershipWitness(blockHash, nullifier);
|
|
581
635
|
|
|
582
636
|
if (!witness) {
|
|
583
637
|
throw new Error(`Nullifier membership witness not found at block ${blockHash}.`);
|
|
@@ -585,10 +639,11 @@ export class RPCTranslator {
|
|
|
585
639
|
return toForeignCallResult(witness.toNoirRepresentation());
|
|
586
640
|
}
|
|
587
641
|
|
|
588
|
-
|
|
642
|
+
// eslint-disable-next-line camelcase
|
|
643
|
+
async aztec_utl_getAuthWitness(foreignMessageHash: ForeignCallSingle) {
|
|
589
644
|
const messageHash = fromSingle(foreignMessageHash);
|
|
590
645
|
|
|
591
|
-
const authWitness = await this.handlerAsUtility().
|
|
646
|
+
const authWitness = await this.handlerAsUtility().getAuthWitness(messageHash);
|
|
592
647
|
|
|
593
648
|
if (!authWitness) {
|
|
594
649
|
throw new Error(`Auth witness not found for message hash ${messageHash}.`);
|
|
@@ -596,44 +651,35 @@ export class RPCTranslator {
|
|
|
596
651
|
return toForeignCallResult([toArray(authWitness)]);
|
|
597
652
|
}
|
|
598
653
|
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
_foreignCalldataHash: ForeignCallSingle,
|
|
602
|
-
_foreignSideEffectCounter: ForeignCallSingle,
|
|
603
|
-
_foreignIsStaticCall: ForeignCallSingle,
|
|
604
|
-
) {
|
|
654
|
+
// eslint-disable-next-line camelcase
|
|
655
|
+
public aztec_prv_assertValidPublicCalldata(_foreignCalldataHash: ForeignCallSingle) {
|
|
605
656
|
throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
|
|
606
657
|
}
|
|
607
658
|
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
_foreignCalldataHash: ForeignCallSingle,
|
|
611
|
-
_foreignSideEffectCounter: ForeignCallSingle,
|
|
612
|
-
_foreignIsStaticCall: ForeignCallSingle,
|
|
613
|
-
) {
|
|
614
|
-
throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
|
|
615
|
-
}
|
|
616
|
-
|
|
617
|
-
public privateNotifySetMinRevertibleSideEffectCounter(_foreignMinRevertibleSideEffectCounter: ForeignCallSingle) {
|
|
659
|
+
// eslint-disable-next-line camelcase
|
|
660
|
+
public aztec_prv_notifyRevertiblePhaseStart(_foreignMinRevertibleSideEffectCounter: ForeignCallSingle) {
|
|
618
661
|
throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
|
|
619
662
|
}
|
|
620
663
|
|
|
621
|
-
|
|
664
|
+
// eslint-disable-next-line camelcase
|
|
665
|
+
public async aztec_prv_isExecutionInRevertiblePhase(foreignSideEffectCounter: ForeignCallSingle) {
|
|
622
666
|
const sideEffectCounter = fromSingle(foreignSideEffectCounter).toNumber();
|
|
623
|
-
const isRevertible = await this.handlerAsPrivate().
|
|
667
|
+
const isRevertible = await this.handlerAsPrivate().isExecutionInRevertiblePhase(sideEffectCounter);
|
|
624
668
|
return toForeignCallResult([toSingle(new Fr(isRevertible))]);
|
|
625
669
|
}
|
|
626
670
|
|
|
627
|
-
|
|
628
|
-
|
|
671
|
+
// eslint-disable-next-line camelcase
|
|
672
|
+
aztec_utl_getUtilityContext() {
|
|
673
|
+
const context = this.handlerAsUtility().getUtilityContext();
|
|
629
674
|
|
|
630
675
|
return toForeignCallResult(context.toNoirRepresentation());
|
|
631
676
|
}
|
|
632
677
|
|
|
633
|
-
|
|
678
|
+
// eslint-disable-next-line camelcase
|
|
679
|
+
async aztec_utl_getBlockHeader(foreignBlockNumber: ForeignCallSingle) {
|
|
634
680
|
const blockNumber = BlockNumber(fromSingle(foreignBlockNumber).toNumber());
|
|
635
681
|
|
|
636
|
-
const header = await this.handlerAsUtility().
|
|
682
|
+
const header = await this.handlerAsUtility().getBlockHeader(blockNumber);
|
|
637
683
|
|
|
638
684
|
if (!header) {
|
|
639
685
|
throw new Error(`Block header not found for block ${blockNumber}.`);
|
|
@@ -641,14 +687,15 @@ export class RPCTranslator {
|
|
|
641
687
|
return toForeignCallResult(header.toFields().map(toSingle));
|
|
642
688
|
}
|
|
643
689
|
|
|
644
|
-
|
|
690
|
+
// eslint-disable-next-line camelcase
|
|
691
|
+
async aztec_utl_getNoteHashMembershipWitness(
|
|
645
692
|
foreignAnchorBlockHash: ForeignCallSingle,
|
|
646
693
|
foreignNoteHash: ForeignCallSingle,
|
|
647
694
|
) {
|
|
648
695
|
const blockHash = new BlockHash(fromSingle(foreignAnchorBlockHash));
|
|
649
696
|
const noteHash = fromSingle(foreignNoteHash);
|
|
650
697
|
|
|
651
|
-
const witness = await this.handlerAsUtility().
|
|
698
|
+
const witness = await this.handlerAsUtility().getNoteHashMembershipWitness(blockHash, noteHash);
|
|
652
699
|
|
|
653
700
|
if (!witness) {
|
|
654
701
|
throw new Error(`Note hash ${noteHash} not found in the note hash tree at block ${blockHash.toString()}.`);
|
|
@@ -656,14 +703,15 @@ export class RPCTranslator {
|
|
|
656
703
|
return toForeignCallResult(witness.toNoirRepresentation());
|
|
657
704
|
}
|
|
658
705
|
|
|
659
|
-
|
|
706
|
+
// eslint-disable-next-line camelcase
|
|
707
|
+
async aztec_utl_getBlockHashMembershipWitness(
|
|
660
708
|
foreignAnchorBlockHash: ForeignCallSingle,
|
|
661
709
|
foreignBlockHash: ForeignCallSingle,
|
|
662
710
|
) {
|
|
663
711
|
const anchorBlockHash = new BlockHash(fromSingle(foreignAnchorBlockHash));
|
|
664
712
|
const blockHash = new BlockHash(fromSingle(foreignBlockHash));
|
|
665
713
|
|
|
666
|
-
const witness = await this.handlerAsUtility().
|
|
714
|
+
const witness = await this.handlerAsUtility().getBlockHashMembershipWitness(anchorBlockHash, blockHash);
|
|
667
715
|
|
|
668
716
|
if (!witness) {
|
|
669
717
|
throw new Error(
|
|
@@ -673,14 +721,15 @@ export class RPCTranslator {
|
|
|
673
721
|
return toForeignCallResult(witness.toNoirRepresentation());
|
|
674
722
|
}
|
|
675
723
|
|
|
676
|
-
|
|
724
|
+
// eslint-disable-next-line camelcase
|
|
725
|
+
async aztec_utl_getLowNullifierMembershipWitness(
|
|
677
726
|
foreignBlockHash: ForeignCallSingle,
|
|
678
727
|
foreignNullifier: ForeignCallSingle,
|
|
679
728
|
) {
|
|
680
729
|
const blockHash = new BlockHash(fromSingle(foreignBlockHash));
|
|
681
730
|
const nullifier = fromSingle(foreignNullifier);
|
|
682
731
|
|
|
683
|
-
const witness = await this.handlerAsUtility().
|
|
732
|
+
const witness = await this.handlerAsUtility().getLowNullifierMembershipWitness(blockHash, nullifier);
|
|
684
733
|
|
|
685
734
|
if (!witness) {
|
|
686
735
|
throw new Error(`Low nullifier witness not found for nullifier ${nullifier} at block ${blockHash}.`);
|
|
@@ -688,74 +737,121 @@ export class RPCTranslator {
|
|
|
688
737
|
return toForeignCallResult(witness.toNoirRepresentation());
|
|
689
738
|
}
|
|
690
739
|
|
|
691
|
-
|
|
740
|
+
// eslint-disable-next-line camelcase
|
|
741
|
+
async aztec_utl_getPendingTaggedLogs(
|
|
742
|
+
foreignPendingTaggedLogArrayBaseSlot: ForeignCallSingle,
|
|
743
|
+
foreignScope: ForeignCallSingle,
|
|
744
|
+
) {
|
|
692
745
|
const pendingTaggedLogArrayBaseSlot = fromSingle(foreignPendingTaggedLogArrayBaseSlot);
|
|
746
|
+
const scope = AztecAddress.fromField(fromSingle(foreignScope));
|
|
693
747
|
|
|
694
|
-
await this.handlerAsUtility().
|
|
748
|
+
await this.handlerAsUtility().getPendingTaggedLogs(pendingTaggedLogArrayBaseSlot, scope);
|
|
695
749
|
|
|
696
750
|
return toForeignCallResult([]);
|
|
697
751
|
}
|
|
698
752
|
|
|
699
|
-
|
|
753
|
+
// eslint-disable-next-line camelcase
|
|
754
|
+
public async aztec_utl_validateAndStoreEnqueuedNotesAndEvents(
|
|
700
755
|
foreignContractAddress: ForeignCallSingle,
|
|
701
756
|
foreignNoteValidationRequestsArrayBaseSlot: ForeignCallSingle,
|
|
702
757
|
foreignEventValidationRequestsArrayBaseSlot: ForeignCallSingle,
|
|
758
|
+
foreignMaxNotePackedLen: ForeignCallSingle,
|
|
759
|
+
foreignMaxEventSerializedLen: ForeignCallSingle,
|
|
760
|
+
foreignScope: ForeignCallSingle,
|
|
703
761
|
) {
|
|
704
762
|
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
705
763
|
const noteValidationRequestsArrayBaseSlot = fromSingle(foreignNoteValidationRequestsArrayBaseSlot);
|
|
706
764
|
const eventValidationRequestsArrayBaseSlot = fromSingle(foreignEventValidationRequestsArrayBaseSlot);
|
|
765
|
+
const maxNotePackedLen = fromSingle(foreignMaxNotePackedLen).toNumber();
|
|
766
|
+
const maxEventSerializedLen = fromSingle(foreignMaxEventSerializedLen).toNumber();
|
|
767
|
+
const scope = AztecAddress.fromField(fromSingle(foreignScope));
|
|
707
768
|
|
|
708
|
-
await this.handlerAsUtility().
|
|
769
|
+
await this.handlerAsUtility().validateAndStoreEnqueuedNotesAndEvents(
|
|
709
770
|
contractAddress,
|
|
710
771
|
noteValidationRequestsArrayBaseSlot,
|
|
711
772
|
eventValidationRequestsArrayBaseSlot,
|
|
773
|
+
maxNotePackedLen,
|
|
774
|
+
maxEventSerializedLen,
|
|
775
|
+
scope,
|
|
712
776
|
);
|
|
713
777
|
|
|
714
778
|
return toForeignCallResult([]);
|
|
715
779
|
}
|
|
716
780
|
|
|
717
|
-
|
|
781
|
+
// eslint-disable-next-line camelcase
|
|
782
|
+
public async aztec_utl_getLogsByTag(
|
|
718
783
|
foreignContractAddress: ForeignCallSingle,
|
|
719
784
|
foreignLogRetrievalRequestsArrayBaseSlot: ForeignCallSingle,
|
|
720
785
|
foreignLogRetrievalResponsesArrayBaseSlot: ForeignCallSingle,
|
|
786
|
+
foreignScope: ForeignCallSingle,
|
|
721
787
|
) {
|
|
722
788
|
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
723
789
|
const logRetrievalRequestsArrayBaseSlot = fromSingle(foreignLogRetrievalRequestsArrayBaseSlot);
|
|
724
790
|
const logRetrievalResponsesArrayBaseSlot = fromSingle(foreignLogRetrievalResponsesArrayBaseSlot);
|
|
791
|
+
const scope = AztecAddress.fromField(fromSingle(foreignScope));
|
|
725
792
|
|
|
726
|
-
await this.handlerAsUtility().
|
|
793
|
+
await this.handlerAsUtility().getLogsByTag(
|
|
727
794
|
contractAddress,
|
|
728
795
|
logRetrievalRequestsArrayBaseSlot,
|
|
729
796
|
logRetrievalResponsesArrayBaseSlot,
|
|
797
|
+
scope,
|
|
730
798
|
);
|
|
731
799
|
|
|
732
800
|
return toForeignCallResult([]);
|
|
733
801
|
}
|
|
734
802
|
|
|
735
|
-
|
|
803
|
+
// eslint-disable-next-line camelcase
|
|
804
|
+
public async aztec_utl_getMessageContextsByTxHash(
|
|
805
|
+
foreignContractAddress: ForeignCallSingle,
|
|
806
|
+
foreignMessageContextRequestsArrayBaseSlot: ForeignCallSingle,
|
|
807
|
+
foreignMessageContextResponsesArrayBaseSlot: ForeignCallSingle,
|
|
808
|
+
foreignScope: ForeignCallSingle,
|
|
809
|
+
) {
|
|
810
|
+
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
811
|
+
const messageContextRequestsArrayBaseSlot = fromSingle(foreignMessageContextRequestsArrayBaseSlot);
|
|
812
|
+
const messageContextResponsesArrayBaseSlot = fromSingle(foreignMessageContextResponsesArrayBaseSlot);
|
|
813
|
+
const scope = AztecAddress.fromField(fromSingle(foreignScope));
|
|
814
|
+
|
|
815
|
+
await this.handlerAsUtility().getMessageContextsByTxHash(
|
|
816
|
+
contractAddress,
|
|
817
|
+
messageContextRequestsArrayBaseSlot,
|
|
818
|
+
messageContextResponsesArrayBaseSlot,
|
|
819
|
+
scope,
|
|
820
|
+
);
|
|
821
|
+
|
|
822
|
+
return toForeignCallResult([]);
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
// eslint-disable-next-line camelcase
|
|
826
|
+
aztec_utl_setCapsule(
|
|
736
827
|
foreignContractAddress: ForeignCallSingle,
|
|
737
828
|
foreignSlot: ForeignCallSingle,
|
|
738
829
|
foreignCapsule: ForeignCallArray,
|
|
830
|
+
foreignScope: ForeignCallSingle,
|
|
739
831
|
) {
|
|
740
832
|
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
741
833
|
const slot = fromSingle(foreignSlot);
|
|
742
834
|
const capsule = fromArray(foreignCapsule);
|
|
835
|
+
const scope = AztecAddress.fromField(fromSingle(foreignScope));
|
|
743
836
|
|
|
744
|
-
|
|
837
|
+
this.handlerAsUtility().setCapsule(contractAddress, slot, capsule, scope);
|
|
745
838
|
|
|
746
839
|
return toForeignCallResult([]);
|
|
747
840
|
}
|
|
748
841
|
|
|
749
|
-
|
|
842
|
+
// eslint-disable-next-line camelcase
|
|
843
|
+
async aztec_utl_getCapsule(
|
|
750
844
|
foreignContractAddress: ForeignCallSingle,
|
|
751
845
|
foreignSlot: ForeignCallSingle,
|
|
752
846
|
foreignTSize: ForeignCallSingle,
|
|
847
|
+
foreignScope: ForeignCallSingle,
|
|
753
848
|
) {
|
|
754
849
|
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
755
850
|
const slot = fromSingle(foreignSlot);
|
|
756
851
|
const tSize = fromSingle(foreignTSize).toNumber();
|
|
852
|
+
const scope = AztecAddress.fromField(fromSingle(foreignScope));
|
|
757
853
|
|
|
758
|
-
const values = await this.handlerAsUtility().
|
|
854
|
+
const values = await this.handlerAsUtility().getCapsule(contractAddress, slot, scope);
|
|
759
855
|
|
|
760
856
|
// We are going to return a Noir Option struct to represent the possibility of null values. Options are a struct
|
|
761
857
|
// with two fields: `some` (a boolean) and `value` (a field array in this case).
|
|
@@ -768,27 +864,36 @@ export class RPCTranslator {
|
|
|
768
864
|
}
|
|
769
865
|
}
|
|
770
866
|
|
|
771
|
-
|
|
867
|
+
// eslint-disable-next-line camelcase
|
|
868
|
+
aztec_utl_deleteCapsule(
|
|
869
|
+
foreignContractAddress: ForeignCallSingle,
|
|
870
|
+
foreignSlot: ForeignCallSingle,
|
|
871
|
+
foreignScope: ForeignCallSingle,
|
|
872
|
+
) {
|
|
772
873
|
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
773
874
|
const slot = fromSingle(foreignSlot);
|
|
875
|
+
const scope = AztecAddress.fromField(fromSingle(foreignScope));
|
|
774
876
|
|
|
775
|
-
|
|
877
|
+
this.handlerAsUtility().deleteCapsule(contractAddress, slot, scope);
|
|
776
878
|
|
|
777
879
|
return toForeignCallResult([]);
|
|
778
880
|
}
|
|
779
881
|
|
|
780
|
-
|
|
882
|
+
// eslint-disable-next-line camelcase
|
|
883
|
+
async aztec_utl_copyCapsule(
|
|
781
884
|
foreignContractAddress: ForeignCallSingle,
|
|
782
885
|
foreignSrcSlot: ForeignCallSingle,
|
|
783
886
|
foreignDstSlot: ForeignCallSingle,
|
|
784
887
|
foreignNumEntries: ForeignCallSingle,
|
|
888
|
+
foreignScope: ForeignCallSingle,
|
|
785
889
|
) {
|
|
786
890
|
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
787
891
|
const srcSlot = fromSingle(foreignSrcSlot);
|
|
788
892
|
const dstSlot = fromSingle(foreignDstSlot);
|
|
789
893
|
const numEntries = fromSingle(foreignNumEntries).toNumber();
|
|
894
|
+
const scope = AztecAddress.fromField(fromSingle(foreignScope));
|
|
790
895
|
|
|
791
|
-
await this.handlerAsUtility().
|
|
896
|
+
await this.handlerAsUtility().copyCapsule(contractAddress, srcSlot, dstSlot, numEntries, scope);
|
|
792
897
|
|
|
793
898
|
return toForeignCallResult([]);
|
|
794
899
|
}
|
|
@@ -797,7 +902,8 @@ export class RPCTranslator {
|
|
|
797
902
|
// 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
|
|
798
903
|
// to implement this function here. Isn't there a way to programmatically identify that this is missing, given the
|
|
799
904
|
// existence of a txe_oracle method?
|
|
800
|
-
|
|
905
|
+
// eslint-disable-next-line camelcase
|
|
906
|
+
async aztec_utl_decryptAes128(
|
|
801
907
|
foreignCiphertextBVecStorage: ForeignCallArray,
|
|
802
908
|
foreignCiphertextLength: ForeignCallSingle,
|
|
803
909
|
foreignIv: ForeignCallArray,
|
|
@@ -807,18 +913,27 @@ export class RPCTranslator {
|
|
|
807
913
|
const iv = fromUintArray(foreignIv, 8);
|
|
808
914
|
const symKey = fromUintArray(foreignSymKey, 8);
|
|
809
915
|
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
916
|
+
// Noir Option<BoundedVec> is encoded as [is_some: Field, storage: Field[], length: Field].
|
|
917
|
+
try {
|
|
918
|
+
const plaintextBuffer = await this.handlerAsUtility().decryptAes128(ciphertext, iv, symKey);
|
|
919
|
+
const [storage, length] = arrayToBoundedVec(
|
|
920
|
+
bufferToU8Array(plaintextBuffer),
|
|
921
|
+
foreignCiphertextBVecStorage.length,
|
|
922
|
+
);
|
|
923
|
+
return toForeignCallResult([toSingle(new Fr(1)), storage, length]);
|
|
924
|
+
} catch {
|
|
925
|
+
const zeroStorage = toArray(Array(foreignCiphertextBVecStorage.length).fill(new Fr(0)));
|
|
926
|
+
return toForeignCallResult([toSingle(new Fr(0)), zeroStorage, toSingle(new Fr(0))]);
|
|
927
|
+
}
|
|
815
928
|
}
|
|
816
929
|
|
|
817
|
-
|
|
930
|
+
// eslint-disable-next-line camelcase
|
|
931
|
+
async aztec_utl_getSharedSecret(
|
|
818
932
|
foreignAddress: ForeignCallSingle,
|
|
819
933
|
foreignEphPKField0: ForeignCallSingle,
|
|
820
934
|
foreignEphPKField1: ForeignCallSingle,
|
|
821
935
|
foreignEphPKField2: ForeignCallSingle,
|
|
936
|
+
foreignContractAddress: ForeignCallSingle,
|
|
822
937
|
) {
|
|
823
938
|
const address = AztecAddress.fromField(fromSingle(foreignAddress));
|
|
824
939
|
const ephPK = Point.fromFields([
|
|
@@ -826,45 +941,68 @@ export class RPCTranslator {
|
|
|
826
941
|
fromSingle(foreignEphPKField1),
|
|
827
942
|
fromSingle(foreignEphPKField2),
|
|
828
943
|
]);
|
|
944
|
+
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
945
|
+
|
|
946
|
+
const secret = await this.handlerAsUtility().getSharedSecret(address, ephPK, contractAddress);
|
|
947
|
+
|
|
948
|
+
return toForeignCallResult([toSingle(secret)]);
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
// eslint-disable-next-line camelcase
|
|
952
|
+
aztec_utl_setContractSyncCacheInvalid(
|
|
953
|
+
foreignContractAddress: ForeignCallSingle,
|
|
954
|
+
foreignScopes: ForeignCallArray,
|
|
955
|
+
foreignScopeCount: ForeignCallSingle,
|
|
956
|
+
) {
|
|
957
|
+
const contractAddress = addressFromSingle(foreignContractAddress);
|
|
958
|
+
const count = fromSingle(foreignScopeCount).toNumber();
|
|
959
|
+
const scopes = fromArray(foreignScopes)
|
|
960
|
+
.slice(0, count)
|
|
961
|
+
.map(f => new AztecAddress(f));
|
|
829
962
|
|
|
830
|
-
|
|
963
|
+
this.handlerAsUtility().setContractSyncCacheInvalid(contractAddress, scopes);
|
|
831
964
|
|
|
832
|
-
return
|
|
965
|
+
return Promise.resolve(toForeignCallResult([]));
|
|
833
966
|
}
|
|
834
967
|
|
|
835
|
-
|
|
968
|
+
// eslint-disable-next-line camelcase
|
|
969
|
+
aztec_utl_emitOffchainEffect(_foreignData: ForeignCallArray) {
|
|
836
970
|
throw new Error('Offchain effects are not yet supported in the TestEnvironment');
|
|
837
971
|
}
|
|
838
972
|
|
|
839
973
|
// AVM opcodes
|
|
840
974
|
|
|
841
|
-
|
|
975
|
+
// eslint-disable-next-line camelcase
|
|
976
|
+
aztec_avm_emitPublicLog(_foreignMessage: ForeignCallArray) {
|
|
842
977
|
// TODO(#8811): Implement
|
|
843
978
|
return toForeignCallResult([]);
|
|
844
979
|
}
|
|
845
980
|
|
|
846
|
-
|
|
981
|
+
// eslint-disable-next-line camelcase
|
|
982
|
+
async aztec_avm_storageRead(foreignSlot: ForeignCallSingle, foreignContractAddress: ForeignCallSingle) {
|
|
847
983
|
const slot = fromSingle(foreignSlot);
|
|
848
984
|
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
849
985
|
|
|
850
|
-
const value = (await this.handlerAsAvm().
|
|
986
|
+
const value = (await this.handlerAsAvm().storageRead(slot, contractAddress)).value;
|
|
851
987
|
|
|
852
988
|
return toForeignCallResult([toSingle(new Fr(value))]);
|
|
853
989
|
}
|
|
854
990
|
|
|
855
|
-
|
|
991
|
+
// eslint-disable-next-line camelcase
|
|
992
|
+
async aztec_avm_storageWrite(foreignSlot: ForeignCallSingle, foreignValue: ForeignCallSingle) {
|
|
856
993
|
const slot = fromSingle(foreignSlot);
|
|
857
994
|
const value = fromSingle(foreignValue);
|
|
858
995
|
|
|
859
|
-
await this.handlerAsAvm().
|
|
996
|
+
await this.handlerAsAvm().storageWrite(slot, value);
|
|
860
997
|
|
|
861
998
|
return toForeignCallResult([]);
|
|
862
999
|
}
|
|
863
1000
|
|
|
864
|
-
|
|
1001
|
+
// eslint-disable-next-line camelcase
|
|
1002
|
+
async aztec_avm_getContractInstanceDeployer(foreignAddress: ForeignCallSingle) {
|
|
865
1003
|
const address = addressFromSingle(foreignAddress);
|
|
866
1004
|
|
|
867
|
-
const instance = await this.handlerAsUtility().
|
|
1005
|
+
const instance = await this.handlerAsUtility().getContractInstance(address);
|
|
868
1006
|
|
|
869
1007
|
return toForeignCallResult([
|
|
870
1008
|
toSingle(instance.deployer),
|
|
@@ -873,10 +1011,11 @@ export class RPCTranslator {
|
|
|
873
1011
|
]);
|
|
874
1012
|
}
|
|
875
1013
|
|
|
876
|
-
|
|
1014
|
+
// eslint-disable-next-line camelcase
|
|
1015
|
+
async aztec_avm_getContractInstanceClassId(foreignAddress: ForeignCallSingle) {
|
|
877
1016
|
const address = addressFromSingle(foreignAddress);
|
|
878
1017
|
|
|
879
|
-
const instance = await this.handlerAsUtility().
|
|
1018
|
+
const instance = await this.handlerAsUtility().getContractInstance(address);
|
|
880
1019
|
|
|
881
1020
|
return toForeignCallResult([
|
|
882
1021
|
toSingle(instance.currentContractClassId),
|
|
@@ -885,10 +1024,11 @@ export class RPCTranslator {
|
|
|
885
1024
|
]);
|
|
886
1025
|
}
|
|
887
1026
|
|
|
888
|
-
|
|
1027
|
+
// eslint-disable-next-line camelcase
|
|
1028
|
+
async aztec_avm_getContractInstanceInitializationHash(foreignAddress: ForeignCallSingle) {
|
|
889
1029
|
const address = addressFromSingle(foreignAddress);
|
|
890
1030
|
|
|
891
|
-
const instance = await this.handlerAsUtility().
|
|
1031
|
+
const instance = await this.handlerAsUtility().getContractInstance(address);
|
|
892
1032
|
|
|
893
1033
|
return toForeignCallResult([
|
|
894
1034
|
toSingle(instance.initializationHash),
|
|
@@ -897,85 +1037,98 @@ export class RPCTranslator {
|
|
|
897
1037
|
]);
|
|
898
1038
|
}
|
|
899
1039
|
|
|
900
|
-
|
|
901
|
-
|
|
1040
|
+
// eslint-disable-next-line camelcase
|
|
1041
|
+
async aztec_avm_sender() {
|
|
1042
|
+
const sender = await this.handlerAsAvm().sender();
|
|
902
1043
|
|
|
903
1044
|
return toForeignCallResult([toSingle(sender)]);
|
|
904
1045
|
}
|
|
905
1046
|
|
|
906
|
-
|
|
1047
|
+
// eslint-disable-next-line camelcase
|
|
1048
|
+
async aztec_avm_emitNullifier(foreignNullifier: ForeignCallSingle) {
|
|
907
1049
|
const nullifier = fromSingle(foreignNullifier);
|
|
908
1050
|
|
|
909
|
-
await this.handlerAsAvm().
|
|
1051
|
+
await this.handlerAsAvm().emitNullifier(nullifier);
|
|
910
1052
|
|
|
911
1053
|
return toForeignCallResult([]);
|
|
912
1054
|
}
|
|
913
1055
|
|
|
914
|
-
|
|
1056
|
+
// eslint-disable-next-line camelcase
|
|
1057
|
+
async aztec_avm_emitNoteHash(foreignNoteHash: ForeignCallSingle) {
|
|
915
1058
|
const noteHash = fromSingle(foreignNoteHash);
|
|
916
1059
|
|
|
917
|
-
await this.handlerAsAvm().
|
|
1060
|
+
await this.handlerAsAvm().emitNoteHash(noteHash);
|
|
918
1061
|
|
|
919
1062
|
return toForeignCallResult([]);
|
|
920
1063
|
}
|
|
921
1064
|
|
|
922
|
-
|
|
1065
|
+
// eslint-disable-next-line camelcase
|
|
1066
|
+
async aztec_avm_nullifierExists(foreignSiloedNullifier: ForeignCallSingle) {
|
|
923
1067
|
const siloedNullifier = fromSingle(foreignSiloedNullifier);
|
|
924
1068
|
|
|
925
|
-
const exists = await this.handlerAsAvm().
|
|
1069
|
+
const exists = await this.handlerAsAvm().nullifierExists(siloedNullifier);
|
|
926
1070
|
|
|
927
1071
|
return toForeignCallResult([toSingle(new Fr(exists))]);
|
|
928
1072
|
}
|
|
929
1073
|
|
|
930
|
-
|
|
931
|
-
|
|
1074
|
+
// eslint-disable-next-line camelcase
|
|
1075
|
+
async aztec_avm_address() {
|
|
1076
|
+
const contractAddress = await this.handlerAsAvm().address();
|
|
932
1077
|
|
|
933
1078
|
return toForeignCallResult([toSingle(contractAddress.toField())]);
|
|
934
1079
|
}
|
|
935
1080
|
|
|
936
|
-
|
|
937
|
-
|
|
1081
|
+
// eslint-disable-next-line camelcase
|
|
1082
|
+
async aztec_avm_blockNumber() {
|
|
1083
|
+
const blockNumber = await this.handlerAsAvm().blockNumber();
|
|
938
1084
|
|
|
939
1085
|
return toForeignCallResult([toSingle(new Fr(blockNumber))]);
|
|
940
1086
|
}
|
|
941
1087
|
|
|
942
|
-
|
|
943
|
-
|
|
1088
|
+
// eslint-disable-next-line camelcase
|
|
1089
|
+
async aztec_avm_timestamp() {
|
|
1090
|
+
const timestamp = await this.handlerAsAvm().timestamp();
|
|
944
1091
|
|
|
945
1092
|
return toForeignCallResult([toSingle(new Fr(timestamp))]);
|
|
946
1093
|
}
|
|
947
1094
|
|
|
948
|
-
|
|
949
|
-
|
|
1095
|
+
// eslint-disable-next-line camelcase
|
|
1096
|
+
async aztec_avm_isStaticCall() {
|
|
1097
|
+
const isStaticCall = await this.handlerAsAvm().isStaticCall();
|
|
950
1098
|
|
|
951
1099
|
return toForeignCallResult([toSingle(new Fr(isStaticCall ? 1 : 0))]);
|
|
952
1100
|
}
|
|
953
1101
|
|
|
954
|
-
|
|
955
|
-
|
|
1102
|
+
// eslint-disable-next-line camelcase
|
|
1103
|
+
async aztec_avm_chainId() {
|
|
1104
|
+
const chainId = await this.handlerAsAvm().chainId();
|
|
956
1105
|
|
|
957
1106
|
return toForeignCallResult([toSingle(chainId)]);
|
|
958
1107
|
}
|
|
959
1108
|
|
|
960
|
-
|
|
961
|
-
|
|
1109
|
+
// eslint-disable-next-line camelcase
|
|
1110
|
+
async aztec_avm_version() {
|
|
1111
|
+
const version = await this.handlerAsAvm().version();
|
|
962
1112
|
|
|
963
1113
|
return toForeignCallResult([toSingle(version)]);
|
|
964
1114
|
}
|
|
965
1115
|
|
|
966
|
-
|
|
1116
|
+
// eslint-disable-next-line camelcase
|
|
1117
|
+
aztec_avm_returndataSize() {
|
|
967
1118
|
throw new Error(
|
|
968
1119
|
'Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead',
|
|
969
1120
|
);
|
|
970
1121
|
}
|
|
971
1122
|
|
|
972
|
-
|
|
1123
|
+
// eslint-disable-next-line camelcase
|
|
1124
|
+
aztec_avm_returndataCopy(_foreignRdOffset: ForeignCallSingle, _foreignCopySize: ForeignCallSingle) {
|
|
973
1125
|
throw new Error(
|
|
974
1126
|
'Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead',
|
|
975
1127
|
);
|
|
976
1128
|
}
|
|
977
1129
|
|
|
978
|
-
|
|
1130
|
+
// eslint-disable-next-line camelcase
|
|
1131
|
+
aztec_avm_call(
|
|
979
1132
|
_foreignL2Gas: ForeignCallSingle,
|
|
980
1133
|
_foreignDaGas: ForeignCallSingle,
|
|
981
1134
|
_foreignAddress: ForeignCallSingle,
|
|
@@ -987,7 +1140,8 @@ export class RPCTranslator {
|
|
|
987
1140
|
);
|
|
988
1141
|
}
|
|
989
1142
|
|
|
990
|
-
|
|
1143
|
+
// eslint-disable-next-line camelcase
|
|
1144
|
+
aztec_avm_staticCall(
|
|
991
1145
|
_foreignL2Gas: ForeignCallSingle,
|
|
992
1146
|
_foreignDaGas: ForeignCallSingle,
|
|
993
1147
|
_foreignAddress: ForeignCallSingle,
|
|
@@ -999,13 +1153,15 @@ export class RPCTranslator {
|
|
|
999
1153
|
);
|
|
1000
1154
|
}
|
|
1001
1155
|
|
|
1002
|
-
|
|
1156
|
+
// eslint-disable-next-line camelcase
|
|
1157
|
+
aztec_avm_successCopy() {
|
|
1003
1158
|
throw new Error(
|
|
1004
1159
|
'Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead',
|
|
1005
1160
|
);
|
|
1006
1161
|
}
|
|
1007
1162
|
|
|
1008
|
-
|
|
1163
|
+
// eslint-disable-next-line camelcase
|
|
1164
|
+
async aztec_txe_privateCallNewFlow(
|
|
1009
1165
|
foreignFrom: ForeignCallSingle,
|
|
1010
1166
|
foreignTargetContractAddress: ForeignCallSingle,
|
|
1011
1167
|
foreignFunctionSelector: ForeignCallSingle,
|
|
@@ -1020,19 +1176,23 @@ export class RPCTranslator {
|
|
|
1020
1176
|
const argsHash = fromSingle(foreignArgsHash);
|
|
1021
1177
|
const isStaticCall = fromSingle(foreignIsStaticCall).toBool();
|
|
1022
1178
|
|
|
1023
|
-
const returnValues = await this.handlerAsTxe().
|
|
1179
|
+
const returnValues = await this.handlerAsTxe().privateCallNewFlow(
|
|
1024
1180
|
from,
|
|
1025
1181
|
targetContractAddress,
|
|
1026
1182
|
functionSelector,
|
|
1027
1183
|
args,
|
|
1028
1184
|
argsHash,
|
|
1029
1185
|
isStaticCall,
|
|
1186
|
+
this.stateHandler.getCurrentJob(),
|
|
1030
1187
|
);
|
|
1031
1188
|
|
|
1189
|
+
// TODO(F-335): Avoid doing the following call here.
|
|
1190
|
+
await this.stateHandler.cycleJob();
|
|
1032
1191
|
return toForeignCallResult([toArray(returnValues)]);
|
|
1033
1192
|
}
|
|
1034
1193
|
|
|
1035
|
-
|
|
1194
|
+
// eslint-disable-next-line camelcase
|
|
1195
|
+
async aztec_txe_executeUtilityFunction(
|
|
1036
1196
|
foreignTargetContractAddress: ForeignCallSingle,
|
|
1037
1197
|
foreignFunctionSelector: ForeignCallSingle,
|
|
1038
1198
|
foreignArgs: ForeignCallArray,
|
|
@@ -1041,16 +1201,20 @@ export class RPCTranslator {
|
|
|
1041
1201
|
const functionSelector = FunctionSelector.fromField(fromSingle(foreignFunctionSelector));
|
|
1042
1202
|
const args = fromArray(foreignArgs);
|
|
1043
1203
|
|
|
1044
|
-
const returnValues = await this.handlerAsTxe().
|
|
1204
|
+
const returnValues = await this.handlerAsTxe().executeUtilityFunction(
|
|
1045
1205
|
targetContractAddress,
|
|
1046
1206
|
functionSelector,
|
|
1047
1207
|
args,
|
|
1208
|
+
this.stateHandler.getCurrentJob(),
|
|
1048
1209
|
);
|
|
1049
1210
|
|
|
1211
|
+
// TODO(F-335): Avoid doing the following call here.
|
|
1212
|
+
await this.stateHandler.cycleJob();
|
|
1050
1213
|
return toForeignCallResult([toArray(returnValues)]);
|
|
1051
1214
|
}
|
|
1052
1215
|
|
|
1053
|
-
|
|
1216
|
+
// eslint-disable-next-line camelcase
|
|
1217
|
+
async aztec_txe_publicCallNewFlow(
|
|
1054
1218
|
foreignFrom: ForeignCallSingle,
|
|
1055
1219
|
foreignAddress: ForeignCallSingle,
|
|
1056
1220
|
foreignCalldata: ForeignCallArray,
|
|
@@ -1061,13 +1225,16 @@ export class RPCTranslator {
|
|
|
1061
1225
|
const calldata = fromArray(foreignCalldata);
|
|
1062
1226
|
const isStaticCall = fromSingle(foreignIsStaticCall).toBool();
|
|
1063
1227
|
|
|
1064
|
-
const returnValues = await this.handlerAsTxe().
|
|
1228
|
+
const returnValues = await this.handlerAsTxe().publicCallNewFlow(from, address, calldata, isStaticCall);
|
|
1065
1229
|
|
|
1230
|
+
// TODO(F-335): Avoid doing the following call here.
|
|
1231
|
+
await this.stateHandler.cycleJob();
|
|
1066
1232
|
return toForeignCallResult([toArray(returnValues)]);
|
|
1067
1233
|
}
|
|
1068
1234
|
|
|
1069
|
-
|
|
1070
|
-
|
|
1235
|
+
// eslint-disable-next-line camelcase
|
|
1236
|
+
async aztec_prv_getSenderForTags() {
|
|
1237
|
+
const sender = await this.handlerAsPrivate().getSenderForTags();
|
|
1071
1238
|
|
|
1072
1239
|
// Return a Noir Option struct with `some` and `value` fields
|
|
1073
1240
|
if (sender === undefined) {
|
|
@@ -1079,19 +1246,21 @@ export class RPCTranslator {
|
|
|
1079
1246
|
}
|
|
1080
1247
|
}
|
|
1081
1248
|
|
|
1082
|
-
|
|
1249
|
+
// eslint-disable-next-line camelcase
|
|
1250
|
+
async aztec_prv_setSenderForTags(foreignSenderForTags: ForeignCallSingle) {
|
|
1083
1251
|
const senderForTags = AztecAddress.fromField(fromSingle(foreignSenderForTags));
|
|
1084
1252
|
|
|
1085
|
-
await this.handlerAsPrivate().
|
|
1253
|
+
await this.handlerAsPrivate().setSenderForTags(senderForTags);
|
|
1086
1254
|
|
|
1087
1255
|
return toForeignCallResult([]);
|
|
1088
1256
|
}
|
|
1089
1257
|
|
|
1090
|
-
|
|
1258
|
+
// eslint-disable-next-line camelcase
|
|
1259
|
+
async aztec_prv_getNextAppTagAsSender(foreignSender: ForeignCallSingle, foreignRecipient: ForeignCallSingle) {
|
|
1091
1260
|
const sender = AztecAddress.fromField(fromSingle(foreignSender));
|
|
1092
1261
|
const recipient = AztecAddress.fromField(fromSingle(foreignRecipient));
|
|
1093
1262
|
|
|
1094
|
-
const nextAppTag = await this.handlerAsPrivate().
|
|
1263
|
+
const nextAppTag = await this.handlerAsPrivate().getNextAppTagAsSender(sender, recipient);
|
|
1095
1264
|
|
|
1096
1265
|
return toForeignCallResult([toSingle(nextAppTag.value)]);
|
|
1097
1266
|
}
|