@aztec/txe 0.0.1-commit.6d3c34e → 0.0.1-commit.7035c9bd6
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/constants.d.ts +1 -2
- package/dest/constants.d.ts.map +1 -1
- package/dest/constants.js +0 -1
- 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 +16 -16
- package/dest/oracle/txe_oracle_top_level_context.d.ts +23 -22
- package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_top_level_context.js +144 -62
- package/dest/rpc_translator.d.ts +92 -81
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +323 -176
- package/dest/state_machine/archiver.d.ts +20 -69
- package/dest/state_machine/archiver.d.ts.map +1 -1
- package/dest/state_machine/archiver.js +34 -178
- 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 -5
- package/dest/state_machine/index.d.ts.map +1 -1
- package/dest/state_machine/index.js +39 -12
- package/dest/state_machine/mock_epoch_cache.d.ts +24 -8
- package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
- package/dest/state_machine/mock_epoch_cache.js +43 -9
- package/dest/state_machine/synchronizer.d.ts +6 -6
- package/dest/state_machine/synchronizer.d.ts.map +1 -1
- package/dest/state_machine/synchronizer.js +3 -3
- package/dest/txe_session.d.ts +12 -6
- package/dest/txe_session.d.ts.map +1 -1
- package/dest/txe_session.js +112 -28
- package/dest/util/encoding.d.ts +17 -17
- 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 +4 -4
- package/dest/utils/block_creation.d.ts.map +1 -1
- package/dest/utils/block_creation.js +18 -4
- package/dest/utils/tx_effect_creation.d.ts +2 -3
- package/dest/utils/tx_effect_creation.d.ts.map +1 -1
- package/dest/utils/tx_effect_creation.js +3 -6
- package/package.json +16 -16
- package/src/constants.ts +0 -1
- package/src/index.ts +89 -52
- package/src/oracle/interfaces.ts +32 -31
- package/src/oracle/txe_oracle_public_context.ts +16 -18
- package/src/oracle/txe_oracle_top_level_context.ts +178 -111
- package/src/rpc_translator.ts +360 -202
- package/src/state_machine/archiver.ts +37 -234
- package/src/state_machine/dummy_p2p_client.ts +40 -22
- package/src/state_machine/index.ts +53 -11
- package/src/state_machine/mock_epoch_cache.ts +53 -14
- package/src/state_machine/synchronizer.ts +5 -5
- package/src/txe_session.ts +129 -88
- package/src/util/txe_public_contract_data_source.ts +10 -36
- package/src/utils/block_creation.ts +19 -16
- package/src/utils/tx_effect_creation.ts +3 -11
- 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,11 +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 {
|
|
13
|
+
import { BlockHash } from '@aztec/stdlib/block';
|
|
14
14
|
|
|
15
15
|
import type { IAvmExecutionOracle, ITxeExecutionOracle } from './oracle/interfaces.js';
|
|
16
16
|
import type { TXESessionStateHandler } from './txe_session.js';
|
|
@@ -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_storeInExecutionCache(foreignValues: ForeignCallArray, foreignHash: ForeignCallSingle) {
|
|
313
343
|
const values = fromArray(foreignValues);
|
|
314
344
|
const hash = fromSingle(foreignHash);
|
|
315
345
|
|
|
316
|
-
this.handlerAsPrivate().
|
|
346
|
+
this.handlerAsPrivate().storeInExecutionCache(values, hash);
|
|
317
347
|
|
|
318
348
|
return toForeignCallResult([]);
|
|
319
349
|
}
|
|
320
350
|
|
|
321
|
-
|
|
351
|
+
// eslint-disable-next-line camelcase
|
|
352
|
+
async aztec_prv_loadFromExecutionCache(foreignHash: ForeignCallSingle) {
|
|
322
353
|
const hash = fromSingle(foreignHash);
|
|
323
354
|
|
|
324
|
-
const returns = await this.handlerAsPrivate().
|
|
355
|
+
const returns = await this.handlerAsPrivate().loadFromExecutionCache(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,45 +372,48 @@ 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_storageRead(
|
|
382
|
+
foreignBlockHash: ForeignCallSingle,
|
|
349
383
|
foreignContractAddress: ForeignCallSingle,
|
|
350
384
|
foreignStartStorageSlot: ForeignCallSingle,
|
|
351
|
-
foreignBlockNumber: ForeignCallSingle,
|
|
352
385
|
foreignNumberOfElements: ForeignCallSingle,
|
|
353
386
|
) {
|
|
387
|
+
const blockHash = new BlockHash(fromSingle(foreignBlockHash));
|
|
354
388
|
const contractAddress = addressFromSingle(foreignContractAddress);
|
|
355
389
|
const startStorageSlot = fromSingle(foreignStartStorageSlot);
|
|
356
|
-
const blockNumber = BlockNumber(fromSingle(foreignBlockNumber).toNumber());
|
|
357
390
|
const numberOfElements = fromSingle(foreignNumberOfElements).toNumber();
|
|
358
391
|
|
|
359
|
-
const values = await this.handlerAsUtility().
|
|
392
|
+
const values = await this.handlerAsUtility().storageRead(
|
|
393
|
+
blockHash,
|
|
360
394
|
contractAddress,
|
|
361
395
|
startStorageSlot,
|
|
362
|
-
blockNumber,
|
|
363
396
|
numberOfElements,
|
|
364
397
|
);
|
|
365
398
|
|
|
366
399
|
return toForeignCallResult([toArray(values)]);
|
|
367
400
|
}
|
|
368
401
|
|
|
369
|
-
|
|
370
|
-
|
|
402
|
+
// eslint-disable-next-line camelcase
|
|
403
|
+
async aztec_utl_getPublicDataWitness(foreignBlockHash: ForeignCallSingle, foreignLeafSlot: ForeignCallSingle) {
|
|
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
|
-
throw new Error(`Public data witness not found for slot ${leafSlot} at block ${
|
|
410
|
+
throw new Error(`Public data witness not found for slot ${leafSlot} at block ${blockHash.toString()}.`);
|
|
377
411
|
}
|
|
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,
|
|
@@ -396,7 +431,7 @@ export class RPCTranslator {
|
|
|
396
431
|
foreignOffset: ForeignCallSingle,
|
|
397
432
|
foreignStatus: ForeignCallSingle,
|
|
398
433
|
foreignMaxNotes: ForeignCallSingle,
|
|
399
|
-
|
|
434
|
+
foreignPackedHintedNoteLength: ForeignCallSingle,
|
|
400
435
|
) {
|
|
401
436
|
// Parse Option<AztecAddress>: ownerIsSome is 0 for None, 1 for Some
|
|
402
437
|
const owner = fromSingle(foreignOwnerIsSome).toBool()
|
|
@@ -417,9 +452,9 @@ export class RPCTranslator {
|
|
|
417
452
|
const offset = fromSingle(foreignOffset).toNumber();
|
|
418
453
|
const status = fromSingle(foreignStatus).toNumber();
|
|
419
454
|
const maxNotes = fromSingle(foreignMaxNotes).toNumber();
|
|
420
|
-
const
|
|
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,
|
|
@@ -438,13 +473,13 @@ export class RPCTranslator {
|
|
|
438
473
|
);
|
|
439
474
|
|
|
440
475
|
const returnDataAsArrayOfArrays = noteDatas.map(noteData =>
|
|
441
|
-
|
|
476
|
+
packAsHintedNote({
|
|
442
477
|
contractAddress: noteData.contractAddress,
|
|
443
478
|
owner: noteData.owner,
|
|
444
479
|
randomness: noteData.randomness,
|
|
445
480
|
storageSlot: noteData.storageSlot,
|
|
446
481
|
noteNonce: noteData.noteNonce,
|
|
447
|
-
|
|
482
|
+
isPending: noteData.isPending,
|
|
448
483
|
note: noteData.note,
|
|
449
484
|
}),
|
|
450
485
|
);
|
|
@@ -456,15 +491,12 @@ export class RPCTranslator {
|
|
|
456
491
|
|
|
457
492
|
// At last we convert the array of arrays to a bounded vec of arrays
|
|
458
493
|
return toForeignCallResult(
|
|
459
|
-
arrayOfArraysToBoundedVecOfArrays(
|
|
460
|
-
returnDataAsArrayOfForeignCallSingleArrays,
|
|
461
|
-
maxNotes,
|
|
462
|
-
packedRetrievedNoteLength,
|
|
463
|
-
),
|
|
494
|
+
arrayOfArraysToBoundedVecOfArrays(returnDataAsArrayOfForeignCallSingleArrays, maxNotes, packedHintedNoteLength),
|
|
464
495
|
);
|
|
465
496
|
}
|
|
466
497
|
|
|
467
|
-
|
|
498
|
+
// eslint-disable-next-line camelcase
|
|
499
|
+
aztec_prv_notifyCreatedNote(
|
|
468
500
|
foreignOwner: ForeignCallSingle,
|
|
469
501
|
foreignStorageSlot: ForeignCallSingle,
|
|
470
502
|
foreignRandomness: ForeignCallSingle,
|
|
@@ -481,20 +513,13 @@ export class RPCTranslator {
|
|
|
481
513
|
const noteHash = fromSingle(foreignNoteHash);
|
|
482
514
|
const counter = fromSingle(foreignCounter).toNumber();
|
|
483
515
|
|
|
484
|
-
this.handlerAsPrivate().
|
|
485
|
-
owner,
|
|
486
|
-
storageSlot,
|
|
487
|
-
randomness,
|
|
488
|
-
noteTypeId,
|
|
489
|
-
note,
|
|
490
|
-
noteHash,
|
|
491
|
-
counter,
|
|
492
|
-
);
|
|
516
|
+
this.handlerAsPrivate().notifyCreatedNote(owner, storageSlot, randomness, noteTypeId, note, noteHash, counter);
|
|
493
517
|
|
|
494
518
|
return toForeignCallResult([]);
|
|
495
519
|
}
|
|
496
520
|
|
|
497
|
-
|
|
521
|
+
// eslint-disable-next-line camelcase
|
|
522
|
+
async aztec_prv_notifyNullifiedNote(
|
|
498
523
|
foreignInnerNullifier: ForeignCallSingle,
|
|
499
524
|
foreignNoteHash: ForeignCallSingle,
|
|
500
525
|
foreignCounter: ForeignCallSingle,
|
|
@@ -503,31 +528,47 @@ export class RPCTranslator {
|
|
|
503
528
|
const noteHash = fromSingle(foreignNoteHash);
|
|
504
529
|
const counter = fromSingle(foreignCounter).toNumber();
|
|
505
530
|
|
|
506
|
-
await this.handlerAsPrivate().
|
|
531
|
+
await this.handlerAsPrivate().notifyNullifiedNote(innerNullifier, noteHash, counter);
|
|
507
532
|
|
|
508
533
|
return toForeignCallResult([]);
|
|
509
534
|
}
|
|
510
535
|
|
|
511
|
-
|
|
536
|
+
// eslint-disable-next-line camelcase
|
|
537
|
+
async aztec_prv_notifyCreatedNullifier(foreignInnerNullifier: ForeignCallSingle) {
|
|
512
538
|
const innerNullifier = fromSingle(foreignInnerNullifier);
|
|
513
539
|
|
|
514
|
-
await this.handlerAsPrivate().
|
|
540
|
+
await this.handlerAsPrivate().notifyCreatedNullifier(innerNullifier);
|
|
515
541
|
|
|
516
542
|
return toForeignCallResult([]);
|
|
517
543
|
}
|
|
518
544
|
|
|
519
|
-
|
|
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) {
|
|
520
560
|
const innerNullifier = fromSingle(foreignInnerNullifier);
|
|
521
561
|
|
|
522
|
-
const exists = await this.handlerAsUtility().
|
|
562
|
+
const exists = await this.handlerAsUtility().checkNullifierExists(innerNullifier);
|
|
523
563
|
|
|
524
564
|
return toForeignCallResult([toSingle(new Fr(exists))]);
|
|
525
565
|
}
|
|
526
566
|
|
|
527
|
-
|
|
567
|
+
// eslint-disable-next-line camelcase
|
|
568
|
+
async aztec_utl_getContractInstance(foreignAddress: ForeignCallSingle) {
|
|
528
569
|
const address = addressFromSingle(foreignAddress);
|
|
529
570
|
|
|
530
|
-
const instance = await this.handlerAsUtility().
|
|
571
|
+
const instance = await this.handlerAsUtility().getContractInstance(address);
|
|
531
572
|
|
|
532
573
|
return toForeignCallResult(
|
|
533
574
|
[
|
|
@@ -540,23 +581,37 @@ export class RPCTranslator {
|
|
|
540
581
|
);
|
|
541
582
|
}
|
|
542
583
|
|
|
543
|
-
|
|
584
|
+
// eslint-disable-next-line camelcase
|
|
585
|
+
async aztec_utl_tryGetPublicKeysAndPartialAddress(foreignAddress: ForeignCallSingle) {
|
|
544
586
|
const address = addressFromSingle(foreignAddress);
|
|
545
587
|
|
|
546
|
-
const
|
|
588
|
+
const result = await this.handlerAsUtility().tryGetPublicKeysAndPartialAddress(address);
|
|
547
589
|
|
|
548
|
-
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
|
+
}
|
|
549
602
|
}
|
|
550
603
|
|
|
551
|
-
|
|
604
|
+
// eslint-disable-next-line camelcase
|
|
605
|
+
async aztec_utl_getKeyValidationRequest(foreignPkMHash: ForeignCallSingle) {
|
|
552
606
|
const pkMHash = fromSingle(foreignPkMHash);
|
|
553
607
|
|
|
554
|
-
const keyValidationRequest = await this.handlerAsUtility().
|
|
608
|
+
const keyValidationRequest = await this.handlerAsUtility().getKeyValidationRequest(pkMHash);
|
|
555
609
|
|
|
556
610
|
return toForeignCallResult(keyValidationRequest.toFields().map(toSingle));
|
|
557
611
|
}
|
|
558
612
|
|
|
559
|
-
|
|
613
|
+
// eslint-disable-next-line camelcase
|
|
614
|
+
aztec_prv_callPrivateFunction(
|
|
560
615
|
_foreignTargetContractAddress: ForeignCallSingle,
|
|
561
616
|
_foreignFunctionSelector: ForeignCallSingle,
|
|
562
617
|
_foreignArgsHash: ForeignCallSingle,
|
|
@@ -568,25 +623,27 @@ export class RPCTranslator {
|
|
|
568
623
|
);
|
|
569
624
|
}
|
|
570
625
|
|
|
571
|
-
|
|
572
|
-
|
|
626
|
+
// eslint-disable-next-line camelcase
|
|
627
|
+
async aztec_utl_getNullifierMembershipWitness(
|
|
628
|
+
foreignBlockHash: ForeignCallSingle,
|
|
573
629
|
foreignNullifier: ForeignCallSingle,
|
|
574
630
|
) {
|
|
575
|
-
const
|
|
631
|
+
const blockHash = new BlockHash(fromSingle(foreignBlockHash));
|
|
576
632
|
const nullifier = fromSingle(foreignNullifier);
|
|
577
633
|
|
|
578
|
-
const witness = await this.handlerAsUtility().
|
|
634
|
+
const witness = await this.handlerAsUtility().getNullifierMembershipWitness(blockHash, nullifier);
|
|
579
635
|
|
|
580
636
|
if (!witness) {
|
|
581
|
-
throw new Error(`Nullifier membership witness not found at block ${
|
|
637
|
+
throw new Error(`Nullifier membership witness not found at block ${blockHash}.`);
|
|
582
638
|
}
|
|
583
639
|
return toForeignCallResult(witness.toNoirRepresentation());
|
|
584
640
|
}
|
|
585
641
|
|
|
586
|
-
|
|
642
|
+
// eslint-disable-next-line camelcase
|
|
643
|
+
async aztec_utl_getAuthWitness(foreignMessageHash: ForeignCallSingle) {
|
|
587
644
|
const messageHash = fromSingle(foreignMessageHash);
|
|
588
645
|
|
|
589
|
-
const authWitness = await this.handlerAsUtility().
|
|
646
|
+
const authWitness = await this.handlerAsUtility().getAuthWitness(messageHash);
|
|
590
647
|
|
|
591
648
|
if (!authWitness) {
|
|
592
649
|
throw new Error(`Auth witness not found for message hash ${messageHash}.`);
|
|
@@ -594,44 +651,35 @@ export class RPCTranslator {
|
|
|
594
651
|
return toForeignCallResult([toArray(authWitness)]);
|
|
595
652
|
}
|
|
596
653
|
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
_foreignCalldataHash: ForeignCallSingle,
|
|
600
|
-
_foreignSideEffectCounter: ForeignCallSingle,
|
|
601
|
-
_foreignIsStaticCall: ForeignCallSingle,
|
|
602
|
-
) {
|
|
603
|
-
throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
|
|
604
|
-
}
|
|
605
|
-
|
|
606
|
-
public privateNotifySetPublicTeardownFunctionCall(
|
|
607
|
-
_foreignTargetContractAddress: ForeignCallSingle,
|
|
608
|
-
_foreignCalldataHash: ForeignCallSingle,
|
|
609
|
-
_foreignSideEffectCounter: ForeignCallSingle,
|
|
610
|
-
_foreignIsStaticCall: ForeignCallSingle,
|
|
611
|
-
) {
|
|
654
|
+
// eslint-disable-next-line camelcase
|
|
655
|
+
public aztec_prv_validatePublicCalldata(_foreignCalldataHash: ForeignCallSingle) {
|
|
612
656
|
throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
|
|
613
657
|
}
|
|
614
658
|
|
|
615
|
-
|
|
659
|
+
// eslint-disable-next-line camelcase
|
|
660
|
+
public aztec_prv_notifyRevertiblePhaseStart(_foreignMinRevertibleSideEffectCounter: ForeignCallSingle) {
|
|
616
661
|
throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
|
|
617
662
|
}
|
|
618
663
|
|
|
619
|
-
|
|
664
|
+
// eslint-disable-next-line camelcase
|
|
665
|
+
public async aztec_prv_inRevertiblePhase(foreignSideEffectCounter: ForeignCallSingle) {
|
|
620
666
|
const sideEffectCounter = fromSingle(foreignSideEffectCounter).toNumber();
|
|
621
|
-
const isRevertible = await this.handlerAsPrivate().
|
|
667
|
+
const isRevertible = await this.handlerAsPrivate().inRevertiblePhase(sideEffectCounter);
|
|
622
668
|
return toForeignCallResult([toSingle(new Fr(isRevertible))]);
|
|
623
669
|
}
|
|
624
670
|
|
|
625
|
-
|
|
626
|
-
|
|
671
|
+
// eslint-disable-next-line camelcase
|
|
672
|
+
aztec_utl_getUtilityContext() {
|
|
673
|
+
const context = this.handlerAsUtility().getUtilityContext();
|
|
627
674
|
|
|
628
675
|
return toForeignCallResult(context.toNoirRepresentation());
|
|
629
676
|
}
|
|
630
677
|
|
|
631
|
-
|
|
678
|
+
// eslint-disable-next-line camelcase
|
|
679
|
+
async aztec_utl_getBlockHeader(foreignBlockNumber: ForeignCallSingle) {
|
|
632
680
|
const blockNumber = BlockNumber(fromSingle(foreignBlockNumber).toNumber());
|
|
633
681
|
|
|
634
|
-
const header = await this.handlerAsUtility().
|
|
682
|
+
const header = await this.handlerAsUtility().getBlockHeader(blockNumber);
|
|
635
683
|
|
|
636
684
|
if (!header) {
|
|
637
685
|
throw new Error(`Block header not found for block ${blockNumber}.`);
|
|
@@ -639,67 +687,92 @@ export class RPCTranslator {
|
|
|
639
687
|
return toForeignCallResult(header.toFields().map(toSingle));
|
|
640
688
|
}
|
|
641
689
|
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
690
|
+
// eslint-disable-next-line camelcase
|
|
691
|
+
async aztec_utl_getNoteHashMembershipWitness(
|
|
692
|
+
foreignAnchorBlockHash: ForeignCallSingle,
|
|
693
|
+
foreignNoteHash: ForeignCallSingle,
|
|
646
694
|
) {
|
|
647
|
-
const
|
|
648
|
-
const
|
|
649
|
-
const leafValue = fromSingle(foreignLeafValue);
|
|
695
|
+
const blockHash = new BlockHash(fromSingle(foreignAnchorBlockHash));
|
|
696
|
+
const noteHash = fromSingle(foreignNoteHash);
|
|
650
697
|
|
|
651
|
-
const witness = await this.handlerAsUtility().
|
|
698
|
+
const witness = await this.handlerAsUtility().getNoteHashMembershipWitness(blockHash, noteHash);
|
|
699
|
+
|
|
700
|
+
if (!witness) {
|
|
701
|
+
throw new Error(`Note hash ${noteHash} not found in the note hash tree at block ${blockHash.toString()}.`);
|
|
702
|
+
}
|
|
703
|
+
return toForeignCallResult(witness.toNoirRepresentation());
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
// eslint-disable-next-line camelcase
|
|
707
|
+
async aztec_utl_getBlockHashMembershipWitness(
|
|
708
|
+
foreignAnchorBlockHash: ForeignCallSingle,
|
|
709
|
+
foreignBlockHash: ForeignCallSingle,
|
|
710
|
+
) {
|
|
711
|
+
const anchorBlockHash = new BlockHash(fromSingle(foreignAnchorBlockHash));
|
|
712
|
+
const blockHash = new BlockHash(fromSingle(foreignBlockHash));
|
|
713
|
+
|
|
714
|
+
const witness = await this.handlerAsUtility().getBlockHashMembershipWitness(anchorBlockHash, blockHash);
|
|
652
715
|
|
|
653
716
|
if (!witness) {
|
|
654
717
|
throw new Error(
|
|
655
|
-
`
|
|
718
|
+
`Block hash ${blockHash.toString()} not found in the archive tree at anchor block ${anchorBlockHash.toString()}.`,
|
|
656
719
|
);
|
|
657
720
|
}
|
|
658
|
-
return toForeignCallResult(
|
|
721
|
+
return toForeignCallResult(witness.toNoirRepresentation());
|
|
659
722
|
}
|
|
660
723
|
|
|
661
|
-
|
|
662
|
-
|
|
724
|
+
// eslint-disable-next-line camelcase
|
|
725
|
+
async aztec_utl_getLowNullifierMembershipWitness(
|
|
726
|
+
foreignBlockHash: ForeignCallSingle,
|
|
663
727
|
foreignNullifier: ForeignCallSingle,
|
|
664
728
|
) {
|
|
665
|
-
const
|
|
729
|
+
const blockHash = new BlockHash(fromSingle(foreignBlockHash));
|
|
666
730
|
const nullifier = fromSingle(foreignNullifier);
|
|
667
731
|
|
|
668
|
-
const witness = await this.handlerAsUtility().
|
|
732
|
+
const witness = await this.handlerAsUtility().getLowNullifierMembershipWitness(blockHash, nullifier);
|
|
669
733
|
|
|
670
734
|
if (!witness) {
|
|
671
|
-
throw new Error(`Low nullifier witness not found for nullifier ${nullifier} at block ${
|
|
735
|
+
throw new Error(`Low nullifier witness not found for nullifier ${nullifier} at block ${blockHash}.`);
|
|
672
736
|
}
|
|
673
737
|
return toForeignCallResult(witness.toNoirRepresentation());
|
|
674
738
|
}
|
|
675
739
|
|
|
676
|
-
|
|
740
|
+
// eslint-disable-next-line camelcase
|
|
741
|
+
async aztec_utl_fetchTaggedLogs(foreignPendingTaggedLogArrayBaseSlot: ForeignCallSingle) {
|
|
677
742
|
const pendingTaggedLogArrayBaseSlot = fromSingle(foreignPendingTaggedLogArrayBaseSlot);
|
|
678
743
|
|
|
679
|
-
await this.handlerAsUtility().
|
|
744
|
+
await this.handlerAsUtility().fetchTaggedLogs(pendingTaggedLogArrayBaseSlot);
|
|
680
745
|
|
|
681
746
|
return toForeignCallResult([]);
|
|
682
747
|
}
|
|
683
748
|
|
|
684
|
-
|
|
749
|
+
// eslint-disable-next-line camelcase
|
|
750
|
+
public async aztec_utl_validateAndStoreEnqueuedNotesAndEvents(
|
|
685
751
|
foreignContractAddress: ForeignCallSingle,
|
|
686
752
|
foreignNoteValidationRequestsArrayBaseSlot: ForeignCallSingle,
|
|
687
753
|
foreignEventValidationRequestsArrayBaseSlot: ForeignCallSingle,
|
|
754
|
+
foreignMaxNotePackedLen: ForeignCallSingle,
|
|
755
|
+
foreignMaxEventSerializedLen: ForeignCallSingle,
|
|
688
756
|
) {
|
|
689
757
|
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
690
758
|
const noteValidationRequestsArrayBaseSlot = fromSingle(foreignNoteValidationRequestsArrayBaseSlot);
|
|
691
759
|
const eventValidationRequestsArrayBaseSlot = fromSingle(foreignEventValidationRequestsArrayBaseSlot);
|
|
760
|
+
const maxNotePackedLen = fromSingle(foreignMaxNotePackedLen).toNumber();
|
|
761
|
+
const maxEventSerializedLen = fromSingle(foreignMaxEventSerializedLen).toNumber();
|
|
692
762
|
|
|
693
|
-
await this.handlerAsUtility().
|
|
763
|
+
await this.handlerAsUtility().validateAndStoreEnqueuedNotesAndEvents(
|
|
694
764
|
contractAddress,
|
|
695
765
|
noteValidationRequestsArrayBaseSlot,
|
|
696
766
|
eventValidationRequestsArrayBaseSlot,
|
|
767
|
+
maxNotePackedLen,
|
|
768
|
+
maxEventSerializedLen,
|
|
697
769
|
);
|
|
698
770
|
|
|
699
771
|
return toForeignCallResult([]);
|
|
700
772
|
}
|
|
701
773
|
|
|
702
|
-
|
|
774
|
+
// eslint-disable-next-line camelcase
|
|
775
|
+
public async aztec_utl_bulkRetrieveLogs(
|
|
703
776
|
foreignContractAddress: ForeignCallSingle,
|
|
704
777
|
foreignLogRetrievalRequestsArrayBaseSlot: ForeignCallSingle,
|
|
705
778
|
foreignLogRetrievalResponsesArrayBaseSlot: ForeignCallSingle,
|
|
@@ -708,7 +781,7 @@ export class RPCTranslator {
|
|
|
708
781
|
const logRetrievalRequestsArrayBaseSlot = fromSingle(foreignLogRetrievalRequestsArrayBaseSlot);
|
|
709
782
|
const logRetrievalResponsesArrayBaseSlot = fromSingle(foreignLogRetrievalResponsesArrayBaseSlot);
|
|
710
783
|
|
|
711
|
-
await this.handlerAsUtility().
|
|
784
|
+
await this.handlerAsUtility().bulkRetrieveLogs(
|
|
712
785
|
contractAddress,
|
|
713
786
|
logRetrievalRequestsArrayBaseSlot,
|
|
714
787
|
logRetrievalResponsesArrayBaseSlot,
|
|
@@ -717,7 +790,27 @@ export class RPCTranslator {
|
|
|
717
790
|
return toForeignCallResult([]);
|
|
718
791
|
}
|
|
719
792
|
|
|
720
|
-
|
|
793
|
+
// eslint-disable-next-line camelcase
|
|
794
|
+
public async aztec_utl_utilityResolveMessageContexts(
|
|
795
|
+
foreignContractAddress: ForeignCallSingle,
|
|
796
|
+
foreignMessageContextRequestsArrayBaseSlot: ForeignCallSingle,
|
|
797
|
+
foreignMessageContextResponsesArrayBaseSlot: ForeignCallSingle,
|
|
798
|
+
) {
|
|
799
|
+
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
800
|
+
const messageContextRequestsArrayBaseSlot = fromSingle(foreignMessageContextRequestsArrayBaseSlot);
|
|
801
|
+
const messageContextResponsesArrayBaseSlot = fromSingle(foreignMessageContextResponsesArrayBaseSlot);
|
|
802
|
+
|
|
803
|
+
await this.handlerAsUtility().utilityResolveMessageContexts(
|
|
804
|
+
contractAddress,
|
|
805
|
+
messageContextRequestsArrayBaseSlot,
|
|
806
|
+
messageContextResponsesArrayBaseSlot,
|
|
807
|
+
);
|
|
808
|
+
|
|
809
|
+
return toForeignCallResult([]);
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
// eslint-disable-next-line camelcase
|
|
813
|
+
async aztec_utl_storeCapsule(
|
|
721
814
|
foreignContractAddress: ForeignCallSingle,
|
|
722
815
|
foreignSlot: ForeignCallSingle,
|
|
723
816
|
foreignCapsule: ForeignCallArray,
|
|
@@ -726,12 +819,13 @@ export class RPCTranslator {
|
|
|
726
819
|
const slot = fromSingle(foreignSlot);
|
|
727
820
|
const capsule = fromArray(foreignCapsule);
|
|
728
821
|
|
|
729
|
-
await this.handlerAsUtility().
|
|
822
|
+
await this.handlerAsUtility().storeCapsule(contractAddress, slot, capsule);
|
|
730
823
|
|
|
731
824
|
return toForeignCallResult([]);
|
|
732
825
|
}
|
|
733
826
|
|
|
734
|
-
|
|
827
|
+
// eslint-disable-next-line camelcase
|
|
828
|
+
async aztec_utl_loadCapsule(
|
|
735
829
|
foreignContractAddress: ForeignCallSingle,
|
|
736
830
|
foreignSlot: ForeignCallSingle,
|
|
737
831
|
foreignTSize: ForeignCallSingle,
|
|
@@ -740,7 +834,7 @@ export class RPCTranslator {
|
|
|
740
834
|
const slot = fromSingle(foreignSlot);
|
|
741
835
|
const tSize = fromSingle(foreignTSize).toNumber();
|
|
742
836
|
|
|
743
|
-
const values = await this.handlerAsUtility().
|
|
837
|
+
const values = await this.handlerAsUtility().loadCapsule(contractAddress, slot);
|
|
744
838
|
|
|
745
839
|
// We are going to return a Noir Option struct to represent the possibility of null values. Options are a struct
|
|
746
840
|
// with two fields: `some` (a boolean) and `value` (a field array in this case).
|
|
@@ -753,16 +847,18 @@ export class RPCTranslator {
|
|
|
753
847
|
}
|
|
754
848
|
}
|
|
755
849
|
|
|
756
|
-
|
|
850
|
+
// eslint-disable-next-line camelcase
|
|
851
|
+
async aztec_utl_deleteCapsule(foreignContractAddress: ForeignCallSingle, foreignSlot: ForeignCallSingle) {
|
|
757
852
|
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
758
853
|
const slot = fromSingle(foreignSlot);
|
|
759
854
|
|
|
760
|
-
await this.handlerAsUtility().
|
|
855
|
+
await this.handlerAsUtility().deleteCapsule(contractAddress, slot);
|
|
761
856
|
|
|
762
857
|
return toForeignCallResult([]);
|
|
763
858
|
}
|
|
764
859
|
|
|
765
|
-
|
|
860
|
+
// eslint-disable-next-line camelcase
|
|
861
|
+
async aztec_utl_copyCapsule(
|
|
766
862
|
foreignContractAddress: ForeignCallSingle,
|
|
767
863
|
foreignSrcSlot: ForeignCallSingle,
|
|
768
864
|
foreignDstSlot: ForeignCallSingle,
|
|
@@ -773,7 +869,7 @@ export class RPCTranslator {
|
|
|
773
869
|
const dstSlot = fromSingle(foreignDstSlot);
|
|
774
870
|
const numEntries = fromSingle(foreignNumEntries).toNumber();
|
|
775
871
|
|
|
776
|
-
await this.handlerAsUtility().
|
|
872
|
+
await this.handlerAsUtility().copyCapsule(contractAddress, srcSlot, dstSlot, numEntries);
|
|
777
873
|
|
|
778
874
|
return toForeignCallResult([]);
|
|
779
875
|
}
|
|
@@ -782,7 +878,8 @@ export class RPCTranslator {
|
|
|
782
878
|
// 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
|
|
783
879
|
// to implement this function here. Isn't there a way to programmatically identify that this is missing, given the
|
|
784
880
|
// existence of a txe_oracle method?
|
|
785
|
-
|
|
881
|
+
// eslint-disable-next-line camelcase
|
|
882
|
+
async aztec_utl_tryAes128Decrypt(
|
|
786
883
|
foreignCiphertextBVecStorage: ForeignCallArray,
|
|
787
884
|
foreignCiphertextLength: ForeignCallSingle,
|
|
788
885
|
foreignIv: ForeignCallArray,
|
|
@@ -792,14 +889,22 @@ export class RPCTranslator {
|
|
|
792
889
|
const iv = fromUintArray(foreignIv, 8);
|
|
793
890
|
const symKey = fromUintArray(foreignSymKey, 8);
|
|
794
891
|
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
892
|
+
// Noir Option<BoundedVec> is encoded as [is_some: Field, storage: Field[], length: Field].
|
|
893
|
+
try {
|
|
894
|
+
const plaintextBuffer = await this.handlerAsUtility().aes128Decrypt(ciphertext, iv, symKey);
|
|
895
|
+
const [storage, length] = arrayToBoundedVec(
|
|
896
|
+
bufferToU8Array(plaintextBuffer),
|
|
897
|
+
foreignCiphertextBVecStorage.length,
|
|
898
|
+
);
|
|
899
|
+
return toForeignCallResult([toSingle(new Fr(1)), storage, length]);
|
|
900
|
+
} catch {
|
|
901
|
+
const zeroStorage = toArray(Array(foreignCiphertextBVecStorage.length).fill(new Fr(0)));
|
|
902
|
+
return toForeignCallResult([toSingle(new Fr(0)), zeroStorage, toSingle(new Fr(0))]);
|
|
903
|
+
}
|
|
800
904
|
}
|
|
801
905
|
|
|
802
|
-
|
|
906
|
+
// eslint-disable-next-line camelcase
|
|
907
|
+
async aztec_utl_getSharedSecret(
|
|
803
908
|
foreignAddress: ForeignCallSingle,
|
|
804
909
|
foreignEphPKField0: ForeignCallSingle,
|
|
805
910
|
foreignEphPKField1: ForeignCallSingle,
|
|
@@ -812,43 +917,66 @@ export class RPCTranslator {
|
|
|
812
917
|
fromSingle(foreignEphPKField2),
|
|
813
918
|
]);
|
|
814
919
|
|
|
815
|
-
const secret = await this.handlerAsUtility().
|
|
920
|
+
const secret = await this.handlerAsUtility().getSharedSecret(address, ephPK);
|
|
816
921
|
|
|
817
922
|
return toForeignCallResult(secret.toFields().map(toSingle));
|
|
818
923
|
}
|
|
819
924
|
|
|
820
|
-
|
|
925
|
+
// eslint-disable-next-line camelcase
|
|
926
|
+
aztec_utl_invalidateContractSyncCache(
|
|
927
|
+
foreignContractAddress: ForeignCallSingle,
|
|
928
|
+
foreignScopes: ForeignCallArray,
|
|
929
|
+
foreignScopeCount: ForeignCallSingle,
|
|
930
|
+
) {
|
|
931
|
+
const contractAddress = addressFromSingle(foreignContractAddress);
|
|
932
|
+
const count = fromSingle(foreignScopeCount).toNumber();
|
|
933
|
+
const scopes = fromArray(foreignScopes)
|
|
934
|
+
.slice(0, count)
|
|
935
|
+
.map(f => new AztecAddress(f));
|
|
936
|
+
|
|
937
|
+
this.handlerAsUtility().invalidateContractSyncCache(contractAddress, scopes);
|
|
938
|
+
|
|
939
|
+
return Promise.resolve(toForeignCallResult([]));
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
// eslint-disable-next-line camelcase
|
|
943
|
+
aztec_utl_emitOffchainEffect(_foreignData: ForeignCallArray) {
|
|
821
944
|
throw new Error('Offchain effects are not yet supported in the TestEnvironment');
|
|
822
945
|
}
|
|
823
946
|
|
|
824
947
|
// AVM opcodes
|
|
825
948
|
|
|
826
|
-
|
|
949
|
+
// eslint-disable-next-line camelcase
|
|
950
|
+
aztec_avm_emitPublicLog(_foreignMessage: ForeignCallArray) {
|
|
827
951
|
// TODO(#8811): Implement
|
|
828
952
|
return toForeignCallResult([]);
|
|
829
953
|
}
|
|
830
954
|
|
|
831
|
-
|
|
955
|
+
// eslint-disable-next-line camelcase
|
|
956
|
+
async aztec_avm_storageRead(foreignSlot: ForeignCallSingle, foreignContractAddress: ForeignCallSingle) {
|
|
832
957
|
const slot = fromSingle(foreignSlot);
|
|
958
|
+
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
833
959
|
|
|
834
|
-
const value = (await this.handlerAsAvm().
|
|
960
|
+
const value = (await this.handlerAsAvm().storageRead(slot, contractAddress)).value;
|
|
835
961
|
|
|
836
962
|
return toForeignCallResult([toSingle(new Fr(value))]);
|
|
837
963
|
}
|
|
838
964
|
|
|
839
|
-
|
|
965
|
+
// eslint-disable-next-line camelcase
|
|
966
|
+
async aztec_avm_storageWrite(foreignSlot: ForeignCallSingle, foreignValue: ForeignCallSingle) {
|
|
840
967
|
const slot = fromSingle(foreignSlot);
|
|
841
968
|
const value = fromSingle(foreignValue);
|
|
842
969
|
|
|
843
|
-
await this.handlerAsAvm().
|
|
970
|
+
await this.handlerAsAvm().storageWrite(slot, value);
|
|
844
971
|
|
|
845
972
|
return toForeignCallResult([]);
|
|
846
973
|
}
|
|
847
974
|
|
|
848
|
-
|
|
975
|
+
// eslint-disable-next-line camelcase
|
|
976
|
+
async aztec_avm_getContractInstanceDeployer(foreignAddress: ForeignCallSingle) {
|
|
849
977
|
const address = addressFromSingle(foreignAddress);
|
|
850
978
|
|
|
851
|
-
const instance = await this.handlerAsUtility().
|
|
979
|
+
const instance = await this.handlerAsUtility().getContractInstance(address);
|
|
852
980
|
|
|
853
981
|
return toForeignCallResult([
|
|
854
982
|
toSingle(instance.deployer),
|
|
@@ -857,10 +985,11 @@ export class RPCTranslator {
|
|
|
857
985
|
]);
|
|
858
986
|
}
|
|
859
987
|
|
|
860
|
-
|
|
988
|
+
// eslint-disable-next-line camelcase
|
|
989
|
+
async aztec_avm_getContractInstanceClassId(foreignAddress: ForeignCallSingle) {
|
|
861
990
|
const address = addressFromSingle(foreignAddress);
|
|
862
991
|
|
|
863
|
-
const instance = await this.handlerAsUtility().
|
|
992
|
+
const instance = await this.handlerAsUtility().getContractInstance(address);
|
|
864
993
|
|
|
865
994
|
return toForeignCallResult([
|
|
866
995
|
toSingle(instance.currentContractClassId),
|
|
@@ -869,10 +998,11 @@ export class RPCTranslator {
|
|
|
869
998
|
]);
|
|
870
999
|
}
|
|
871
1000
|
|
|
872
|
-
|
|
1001
|
+
// eslint-disable-next-line camelcase
|
|
1002
|
+
async aztec_avm_getContractInstanceInitializationHash(foreignAddress: ForeignCallSingle) {
|
|
873
1003
|
const address = addressFromSingle(foreignAddress);
|
|
874
1004
|
|
|
875
|
-
const instance = await this.handlerAsUtility().
|
|
1005
|
+
const instance = await this.handlerAsUtility().getContractInstance(address);
|
|
876
1006
|
|
|
877
1007
|
return toForeignCallResult([
|
|
878
1008
|
toSingle(instance.initializationHash),
|
|
@@ -881,86 +1011,98 @@ export class RPCTranslator {
|
|
|
881
1011
|
]);
|
|
882
1012
|
}
|
|
883
1013
|
|
|
884
|
-
|
|
885
|
-
|
|
1014
|
+
// eslint-disable-next-line camelcase
|
|
1015
|
+
async aztec_avm_sender() {
|
|
1016
|
+
const sender = await this.handlerAsAvm().sender();
|
|
886
1017
|
|
|
887
1018
|
return toForeignCallResult([toSingle(sender)]);
|
|
888
1019
|
}
|
|
889
1020
|
|
|
890
|
-
|
|
1021
|
+
// eslint-disable-next-line camelcase
|
|
1022
|
+
async aztec_avm_emitNullifier(foreignNullifier: ForeignCallSingle) {
|
|
891
1023
|
const nullifier = fromSingle(foreignNullifier);
|
|
892
1024
|
|
|
893
|
-
await this.handlerAsAvm().
|
|
1025
|
+
await this.handlerAsAvm().emitNullifier(nullifier);
|
|
894
1026
|
|
|
895
1027
|
return toForeignCallResult([]);
|
|
896
1028
|
}
|
|
897
1029
|
|
|
898
|
-
|
|
1030
|
+
// eslint-disable-next-line camelcase
|
|
1031
|
+
async aztec_avm_emitNoteHash(foreignNoteHash: ForeignCallSingle) {
|
|
899
1032
|
const noteHash = fromSingle(foreignNoteHash);
|
|
900
1033
|
|
|
901
|
-
await this.handlerAsAvm().
|
|
1034
|
+
await this.handlerAsAvm().emitNoteHash(noteHash);
|
|
902
1035
|
|
|
903
1036
|
return toForeignCallResult([]);
|
|
904
1037
|
}
|
|
905
1038
|
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
const
|
|
1039
|
+
// eslint-disable-next-line camelcase
|
|
1040
|
+
async aztec_avm_nullifierExists(foreignSiloedNullifier: ForeignCallSingle) {
|
|
1041
|
+
const siloedNullifier = fromSingle(foreignSiloedNullifier);
|
|
909
1042
|
|
|
910
|
-
const exists = await this.handlerAsAvm().
|
|
1043
|
+
const exists = await this.handlerAsAvm().nullifierExists(siloedNullifier);
|
|
911
1044
|
|
|
912
1045
|
return toForeignCallResult([toSingle(new Fr(exists))]);
|
|
913
1046
|
}
|
|
914
1047
|
|
|
915
|
-
|
|
916
|
-
|
|
1048
|
+
// eslint-disable-next-line camelcase
|
|
1049
|
+
async aztec_avm_address() {
|
|
1050
|
+
const contractAddress = await this.handlerAsAvm().address();
|
|
917
1051
|
|
|
918
1052
|
return toForeignCallResult([toSingle(contractAddress.toField())]);
|
|
919
1053
|
}
|
|
920
1054
|
|
|
921
|
-
|
|
922
|
-
|
|
1055
|
+
// eslint-disable-next-line camelcase
|
|
1056
|
+
async aztec_avm_blockNumber() {
|
|
1057
|
+
const blockNumber = await this.handlerAsAvm().blockNumber();
|
|
923
1058
|
|
|
924
1059
|
return toForeignCallResult([toSingle(new Fr(blockNumber))]);
|
|
925
1060
|
}
|
|
926
1061
|
|
|
927
|
-
|
|
928
|
-
|
|
1062
|
+
// eslint-disable-next-line camelcase
|
|
1063
|
+
async aztec_avm_timestamp() {
|
|
1064
|
+
const timestamp = await this.handlerAsAvm().timestamp();
|
|
929
1065
|
|
|
930
1066
|
return toForeignCallResult([toSingle(new Fr(timestamp))]);
|
|
931
1067
|
}
|
|
932
1068
|
|
|
933
|
-
|
|
934
|
-
|
|
1069
|
+
// eslint-disable-next-line camelcase
|
|
1070
|
+
async aztec_avm_isStaticCall() {
|
|
1071
|
+
const isStaticCall = await this.handlerAsAvm().isStaticCall();
|
|
935
1072
|
|
|
936
1073
|
return toForeignCallResult([toSingle(new Fr(isStaticCall ? 1 : 0))]);
|
|
937
1074
|
}
|
|
938
1075
|
|
|
939
|
-
|
|
940
|
-
|
|
1076
|
+
// eslint-disable-next-line camelcase
|
|
1077
|
+
async aztec_avm_chainId() {
|
|
1078
|
+
const chainId = await this.handlerAsAvm().chainId();
|
|
941
1079
|
|
|
942
1080
|
return toForeignCallResult([toSingle(chainId)]);
|
|
943
1081
|
}
|
|
944
1082
|
|
|
945
|
-
|
|
946
|
-
|
|
1083
|
+
// eslint-disable-next-line camelcase
|
|
1084
|
+
async aztec_avm_version() {
|
|
1085
|
+
const version = await this.handlerAsAvm().version();
|
|
947
1086
|
|
|
948
1087
|
return toForeignCallResult([toSingle(version)]);
|
|
949
1088
|
}
|
|
950
1089
|
|
|
951
|
-
|
|
1090
|
+
// eslint-disable-next-line camelcase
|
|
1091
|
+
aztec_avm_returndataSize() {
|
|
952
1092
|
throw new Error(
|
|
953
1093
|
'Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead',
|
|
954
1094
|
);
|
|
955
1095
|
}
|
|
956
1096
|
|
|
957
|
-
|
|
1097
|
+
// eslint-disable-next-line camelcase
|
|
1098
|
+
aztec_avm_returndataCopy(_foreignRdOffset: ForeignCallSingle, _foreignCopySize: ForeignCallSingle) {
|
|
958
1099
|
throw new Error(
|
|
959
1100
|
'Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead',
|
|
960
1101
|
);
|
|
961
1102
|
}
|
|
962
1103
|
|
|
963
|
-
|
|
1104
|
+
// eslint-disable-next-line camelcase
|
|
1105
|
+
aztec_avm_call(
|
|
964
1106
|
_foreignL2Gas: ForeignCallSingle,
|
|
965
1107
|
_foreignDaGas: ForeignCallSingle,
|
|
966
1108
|
_foreignAddress: ForeignCallSingle,
|
|
@@ -972,7 +1114,8 @@ export class RPCTranslator {
|
|
|
972
1114
|
);
|
|
973
1115
|
}
|
|
974
1116
|
|
|
975
|
-
|
|
1117
|
+
// eslint-disable-next-line camelcase
|
|
1118
|
+
aztec_avm_staticCall(
|
|
976
1119
|
_foreignL2Gas: ForeignCallSingle,
|
|
977
1120
|
_foreignDaGas: ForeignCallSingle,
|
|
978
1121
|
_foreignAddress: ForeignCallSingle,
|
|
@@ -984,13 +1127,15 @@ export class RPCTranslator {
|
|
|
984
1127
|
);
|
|
985
1128
|
}
|
|
986
1129
|
|
|
987
|
-
|
|
1130
|
+
// eslint-disable-next-line camelcase
|
|
1131
|
+
aztec_avm_successCopy() {
|
|
988
1132
|
throw new Error(
|
|
989
1133
|
'Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead',
|
|
990
1134
|
);
|
|
991
1135
|
}
|
|
992
1136
|
|
|
993
|
-
|
|
1137
|
+
// eslint-disable-next-line camelcase
|
|
1138
|
+
async aztec_txe_privateCallNewFlow(
|
|
994
1139
|
foreignFrom: ForeignCallSingle,
|
|
995
1140
|
foreignTargetContractAddress: ForeignCallSingle,
|
|
996
1141
|
foreignFunctionSelector: ForeignCallSingle,
|
|
@@ -1005,19 +1150,23 @@ export class RPCTranslator {
|
|
|
1005
1150
|
const argsHash = fromSingle(foreignArgsHash);
|
|
1006
1151
|
const isStaticCall = fromSingle(foreignIsStaticCall).toBool();
|
|
1007
1152
|
|
|
1008
|
-
const returnValues = await this.handlerAsTxe().
|
|
1153
|
+
const returnValues = await this.handlerAsTxe().privateCallNewFlow(
|
|
1009
1154
|
from,
|
|
1010
1155
|
targetContractAddress,
|
|
1011
1156
|
functionSelector,
|
|
1012
1157
|
args,
|
|
1013
1158
|
argsHash,
|
|
1014
1159
|
isStaticCall,
|
|
1160
|
+
this.stateHandler.getCurrentJob(),
|
|
1015
1161
|
);
|
|
1016
1162
|
|
|
1163
|
+
// TODO(F-335): Avoid doing the following call here.
|
|
1164
|
+
await this.stateHandler.cycleJob();
|
|
1017
1165
|
return toForeignCallResult([toArray(returnValues)]);
|
|
1018
1166
|
}
|
|
1019
1167
|
|
|
1020
|
-
|
|
1168
|
+
// eslint-disable-next-line camelcase
|
|
1169
|
+
async aztec_txe_executeUtilityFunction(
|
|
1021
1170
|
foreignTargetContractAddress: ForeignCallSingle,
|
|
1022
1171
|
foreignFunctionSelector: ForeignCallSingle,
|
|
1023
1172
|
foreignArgs: ForeignCallArray,
|
|
@@ -1026,16 +1175,20 @@ export class RPCTranslator {
|
|
|
1026
1175
|
const functionSelector = FunctionSelector.fromField(fromSingle(foreignFunctionSelector));
|
|
1027
1176
|
const args = fromArray(foreignArgs);
|
|
1028
1177
|
|
|
1029
|
-
const returnValues = await this.handlerAsTxe().
|
|
1178
|
+
const returnValues = await this.handlerAsTxe().executeUtilityFunction(
|
|
1030
1179
|
targetContractAddress,
|
|
1031
1180
|
functionSelector,
|
|
1032
1181
|
args,
|
|
1182
|
+
this.stateHandler.getCurrentJob(),
|
|
1033
1183
|
);
|
|
1034
1184
|
|
|
1185
|
+
// TODO(F-335): Avoid doing the following call here.
|
|
1186
|
+
await this.stateHandler.cycleJob();
|
|
1035
1187
|
return toForeignCallResult([toArray(returnValues)]);
|
|
1036
1188
|
}
|
|
1037
1189
|
|
|
1038
|
-
|
|
1190
|
+
// eslint-disable-next-line camelcase
|
|
1191
|
+
async aztec_txe_publicCallNewFlow(
|
|
1039
1192
|
foreignFrom: ForeignCallSingle,
|
|
1040
1193
|
foreignAddress: ForeignCallSingle,
|
|
1041
1194
|
foreignCalldata: ForeignCallArray,
|
|
@@ -1046,13 +1199,16 @@ export class RPCTranslator {
|
|
|
1046
1199
|
const calldata = fromArray(foreignCalldata);
|
|
1047
1200
|
const isStaticCall = fromSingle(foreignIsStaticCall).toBool();
|
|
1048
1201
|
|
|
1049
|
-
const returnValues = await this.handlerAsTxe().
|
|
1202
|
+
const returnValues = await this.handlerAsTxe().publicCallNewFlow(from, address, calldata, isStaticCall);
|
|
1050
1203
|
|
|
1204
|
+
// TODO(F-335): Avoid doing the following call here.
|
|
1205
|
+
await this.stateHandler.cycleJob();
|
|
1051
1206
|
return toForeignCallResult([toArray(returnValues)]);
|
|
1052
1207
|
}
|
|
1053
1208
|
|
|
1054
|
-
|
|
1055
|
-
|
|
1209
|
+
// eslint-disable-next-line camelcase
|
|
1210
|
+
async aztec_prv_getSenderForTags() {
|
|
1211
|
+
const sender = await this.handlerAsPrivate().getSenderForTags();
|
|
1056
1212
|
|
|
1057
1213
|
// Return a Noir Option struct with `some` and `value` fields
|
|
1058
1214
|
if (sender === undefined) {
|
|
@@ -1064,19 +1220,21 @@ export class RPCTranslator {
|
|
|
1064
1220
|
}
|
|
1065
1221
|
}
|
|
1066
1222
|
|
|
1067
|
-
|
|
1223
|
+
// eslint-disable-next-line camelcase
|
|
1224
|
+
async aztec_prv_setSenderForTags(foreignSenderForTags: ForeignCallSingle) {
|
|
1068
1225
|
const senderForTags = AztecAddress.fromField(fromSingle(foreignSenderForTags));
|
|
1069
1226
|
|
|
1070
|
-
await this.handlerAsPrivate().
|
|
1227
|
+
await this.handlerAsPrivate().setSenderForTags(senderForTags);
|
|
1071
1228
|
|
|
1072
1229
|
return toForeignCallResult([]);
|
|
1073
1230
|
}
|
|
1074
1231
|
|
|
1075
|
-
|
|
1232
|
+
// eslint-disable-next-line camelcase
|
|
1233
|
+
async aztec_prv_getNextAppTagAsSender(foreignSender: ForeignCallSingle, foreignRecipient: ForeignCallSingle) {
|
|
1076
1234
|
const sender = AztecAddress.fromField(fromSingle(foreignSender));
|
|
1077
1235
|
const recipient = AztecAddress.fromField(fromSingle(foreignRecipient));
|
|
1078
1236
|
|
|
1079
|
-
const nextAppTag = await this.handlerAsPrivate().
|
|
1237
|
+
const nextAppTag = await this.handlerAsPrivate().getNextAppTagAsSender(sender, recipient);
|
|
1080
1238
|
|
|
1081
1239
|
return toForeignCallResult([toSingle(nextAppTag.value)]);
|
|
1082
1240
|
}
|