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