@aztec/txe 0.0.1-commit.03f7ef2 → 0.0.1-commit.04852196a
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 +3 -0
- package/dest/constants.d.ts.map +1 -0
- package/dest/constants.js +2 -0
- 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 +33 -31
- package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_top_level_context.js +179 -92
- package/dest/rpc_translator.d.ts +87 -81
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +291 -173
- package/dest/state_machine/archiver.d.ts +20 -67
- package/dest/state_machine/archiver.d.ts.map +1 -1
- package/dest/state_machine/archiver.js +59 -178
- package/dest/state_machine/dummy_p2p_client.d.ts +20 -15
- package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
- package/dest/state_machine/dummy_p2p_client.js +39 -24
- package/dest/state_machine/global_variable_builder.d.ts +2 -2
- package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
- package/dest/state_machine/global_variable_builder.js +1 -1
- package/dest/state_machine/index.d.ts +6 -6
- package/dest/state_machine/index.d.ts.map +1 -1
- package/dest/state_machine/index.js +37 -14
- package/dest/state_machine/mock_epoch_cache.d.ts +9 -6
- package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
- package/dest/state_machine/mock_epoch_cache.js +14 -7
- 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 +22 -16
- package/dest/txe_session.d.ts.map +1 -1
- package/dest/txe_session.js +153 -56
- package/dest/util/encoding.d.ts +17 -17
- package/dest/util/txe_account_store.d.ts +10 -0
- package/dest/util/txe_account_store.d.ts.map +1 -0
- package/dest/util/{txe_account_data_provider.js → txe_account_store.js} +1 -1
- package/dest/util/txe_public_contract_data_source.d.ts +5 -6
- package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
- package/dest/util/txe_public_contract_data_source.js +12 -29
- 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 -5
- 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 +3 -0
- 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 +217 -133
- package/src/rpc_translator.ts +309 -185
- package/src/state_machine/archiver.ts +54 -220
- package/src/state_machine/dummy_p2p_client.ts +55 -32
- package/src/state_machine/global_variable_builder.ts +1 -1
- package/src/state_machine/index.ts +50 -12
- package/src/state_machine/mock_epoch_cache.ts +15 -11
- package/src/state_machine/synchronizer.ts +2 -2
- package/src/txe_session.ts +207 -120
- package/src/util/{txe_account_data_provider.ts → txe_account_store.ts} +1 -1
- package/src/util/txe_public_contract_data_source.ts +16 -42
- package/src/utils/block_creation.ts +19 -16
- package/src/utils/tx_effect_creation.ts +3 -11
- package/dest/util/txe_account_data_provider.d.ts +0 -10
- package/dest/util/txe_account_data_provider.d.ts.map +0 -1
- package/dest/util/txe_contract_data_provider.d.ts +0 -12
- package/dest/util/txe_contract_data_provider.d.ts.map +0 -1
- package/dest/util/txe_contract_data_provider.js +0 -22
- package/src/util/txe_contract_data_provider.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,7 +651,8 @@ export class RPCTranslator {
|
|
|
594
651
|
return toForeignCallResult([toArray(authWitness)]);
|
|
595
652
|
}
|
|
596
653
|
|
|
597
|
-
|
|
654
|
+
// eslint-disable-next-line camelcase
|
|
655
|
+
public aztec_prv_notifyEnqueuedPublicFunctionCall(
|
|
598
656
|
_foreignTargetContractAddress: ForeignCallSingle,
|
|
599
657
|
_foreignCalldataHash: ForeignCallSingle,
|
|
600
658
|
_foreignSideEffectCounter: ForeignCallSingle,
|
|
@@ -603,7 +661,8 @@ export class RPCTranslator {
|
|
|
603
661
|
throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
|
|
604
662
|
}
|
|
605
663
|
|
|
606
|
-
|
|
664
|
+
// eslint-disable-next-line camelcase
|
|
665
|
+
public aztec_prv_notifySetPublicTeardownFunctionCall(
|
|
607
666
|
_foreignTargetContractAddress: ForeignCallSingle,
|
|
608
667
|
_foreignCalldataHash: ForeignCallSingle,
|
|
609
668
|
_foreignSideEffectCounter: ForeignCallSingle,
|
|
@@ -612,26 +671,30 @@ export class RPCTranslator {
|
|
|
612
671
|
throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
|
|
613
672
|
}
|
|
614
673
|
|
|
615
|
-
|
|
674
|
+
// eslint-disable-next-line camelcase
|
|
675
|
+
public aztec_prv_notifySetMinRevertibleSideEffectCounter(_foreignMinRevertibleSideEffectCounter: ForeignCallSingle) {
|
|
616
676
|
throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
|
|
617
677
|
}
|
|
618
678
|
|
|
619
|
-
|
|
679
|
+
// eslint-disable-next-line camelcase
|
|
680
|
+
public async aztec_prv_isSideEffectCounterRevertible(foreignSideEffectCounter: ForeignCallSingle) {
|
|
620
681
|
const sideEffectCounter = fromSingle(foreignSideEffectCounter).toNumber();
|
|
621
|
-
const isRevertible = await this.handlerAsPrivate().
|
|
682
|
+
const isRevertible = await this.handlerAsPrivate().isSideEffectCounterRevertible(sideEffectCounter);
|
|
622
683
|
return toForeignCallResult([toSingle(new Fr(isRevertible))]);
|
|
623
684
|
}
|
|
624
685
|
|
|
625
|
-
|
|
626
|
-
|
|
686
|
+
// eslint-disable-next-line camelcase
|
|
687
|
+
aztec_utl_getUtilityContext() {
|
|
688
|
+
const context = this.handlerAsUtility().getUtilityContext();
|
|
627
689
|
|
|
628
690
|
return toForeignCallResult(context.toNoirRepresentation());
|
|
629
691
|
}
|
|
630
692
|
|
|
631
|
-
|
|
693
|
+
// eslint-disable-next-line camelcase
|
|
694
|
+
async aztec_utl_getBlockHeader(foreignBlockNumber: ForeignCallSingle) {
|
|
632
695
|
const blockNumber = BlockNumber(fromSingle(foreignBlockNumber).toNumber());
|
|
633
696
|
|
|
634
|
-
const header = await this.handlerAsUtility().
|
|
697
|
+
const header = await this.handlerAsUtility().getBlockHeader(blockNumber);
|
|
635
698
|
|
|
636
699
|
if (!header) {
|
|
637
700
|
throw new Error(`Block header not found for block ${blockNumber}.`);
|
|
@@ -639,49 +702,67 @@ export class RPCTranslator {
|
|
|
639
702
|
return toForeignCallResult(header.toFields().map(toSingle));
|
|
640
703
|
}
|
|
641
704
|
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
705
|
+
// eslint-disable-next-line camelcase
|
|
706
|
+
async aztec_utl_getNoteHashMembershipWitness(
|
|
707
|
+
foreignAnchorBlockHash: ForeignCallSingle,
|
|
708
|
+
foreignNoteHash: ForeignCallSingle,
|
|
646
709
|
) {
|
|
647
|
-
const
|
|
648
|
-
const
|
|
649
|
-
const leafValue = fromSingle(foreignLeafValue);
|
|
710
|
+
const blockHash = new BlockHash(fromSingle(foreignAnchorBlockHash));
|
|
711
|
+
const noteHash = fromSingle(foreignNoteHash);
|
|
650
712
|
|
|
651
|
-
const witness = await this.handlerAsUtility().
|
|
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,
|
|
724
|
+
foreignBlockHash: ForeignCallSingle,
|
|
725
|
+
) {
|
|
726
|
+
const anchorBlockHash = new BlockHash(fromSingle(foreignAnchorBlockHash));
|
|
727
|
+
const blockHash = new BlockHash(fromSingle(foreignBlockHash));
|
|
728
|
+
|
|
729
|
+
const witness = await this.handlerAsUtility().getBlockHashMembershipWitness(anchorBlockHash, blockHash);
|
|
652
730
|
|
|
653
731
|
if (!witness) {
|
|
654
732
|
throw new Error(
|
|
655
|
-
`
|
|
733
|
+
`Block hash ${blockHash.toString()} not found in the archive tree at anchor block ${anchorBlockHash.toString()}.`,
|
|
656
734
|
);
|
|
657
735
|
}
|
|
658
|
-
return toForeignCallResult(
|
|
736
|
+
return toForeignCallResult(witness.toNoirRepresentation());
|
|
659
737
|
}
|
|
660
738
|
|
|
661
|
-
|
|
662
|
-
|
|
739
|
+
// eslint-disable-next-line camelcase
|
|
740
|
+
async aztec_utl_getLowNullifierMembershipWitness(
|
|
741
|
+
foreignBlockHash: ForeignCallSingle,
|
|
663
742
|
foreignNullifier: ForeignCallSingle,
|
|
664
743
|
) {
|
|
665
|
-
const
|
|
744
|
+
const blockHash = new BlockHash(fromSingle(foreignBlockHash));
|
|
666
745
|
const nullifier = fromSingle(foreignNullifier);
|
|
667
746
|
|
|
668
|
-
const witness = await this.handlerAsUtility().
|
|
747
|
+
const witness = await this.handlerAsUtility().getLowNullifierMembershipWitness(blockHash, nullifier);
|
|
669
748
|
|
|
670
749
|
if (!witness) {
|
|
671
|
-
throw new Error(`Low nullifier witness not found for nullifier ${nullifier} at block ${
|
|
750
|
+
throw new Error(`Low nullifier witness not found for nullifier ${nullifier} at block ${blockHash}.`);
|
|
672
751
|
}
|
|
673
752
|
return toForeignCallResult(witness.toNoirRepresentation());
|
|
674
753
|
}
|
|
675
754
|
|
|
676
|
-
|
|
755
|
+
// eslint-disable-next-line camelcase
|
|
756
|
+
async aztec_utl_fetchTaggedLogs(foreignPendingTaggedLogArrayBaseSlot: ForeignCallSingle) {
|
|
677
757
|
const pendingTaggedLogArrayBaseSlot = fromSingle(foreignPendingTaggedLogArrayBaseSlot);
|
|
678
758
|
|
|
679
|
-
await this.handlerAsUtility().
|
|
759
|
+
await this.handlerAsUtility().fetchTaggedLogs(pendingTaggedLogArrayBaseSlot);
|
|
680
760
|
|
|
681
761
|
return toForeignCallResult([]);
|
|
682
762
|
}
|
|
683
763
|
|
|
684
|
-
|
|
764
|
+
// eslint-disable-next-line camelcase
|
|
765
|
+
public async aztec_utl_validateAndStoreEnqueuedNotesAndEvents(
|
|
685
766
|
foreignContractAddress: ForeignCallSingle,
|
|
686
767
|
foreignNoteValidationRequestsArrayBaseSlot: ForeignCallSingle,
|
|
687
768
|
foreignEventValidationRequestsArrayBaseSlot: ForeignCallSingle,
|
|
@@ -690,7 +771,7 @@ export class RPCTranslator {
|
|
|
690
771
|
const noteValidationRequestsArrayBaseSlot = fromSingle(foreignNoteValidationRequestsArrayBaseSlot);
|
|
691
772
|
const eventValidationRequestsArrayBaseSlot = fromSingle(foreignEventValidationRequestsArrayBaseSlot);
|
|
692
773
|
|
|
693
|
-
await this.handlerAsUtility().
|
|
774
|
+
await this.handlerAsUtility().validateAndStoreEnqueuedNotesAndEvents(
|
|
694
775
|
contractAddress,
|
|
695
776
|
noteValidationRequestsArrayBaseSlot,
|
|
696
777
|
eventValidationRequestsArrayBaseSlot,
|
|
@@ -699,7 +780,8 @@ export class RPCTranslator {
|
|
|
699
780
|
return toForeignCallResult([]);
|
|
700
781
|
}
|
|
701
782
|
|
|
702
|
-
|
|
783
|
+
// eslint-disable-next-line camelcase
|
|
784
|
+
public async aztec_utl_bulkRetrieveLogs(
|
|
703
785
|
foreignContractAddress: ForeignCallSingle,
|
|
704
786
|
foreignLogRetrievalRequestsArrayBaseSlot: ForeignCallSingle,
|
|
705
787
|
foreignLogRetrievalResponsesArrayBaseSlot: ForeignCallSingle,
|
|
@@ -708,7 +790,7 @@ export class RPCTranslator {
|
|
|
708
790
|
const logRetrievalRequestsArrayBaseSlot = fromSingle(foreignLogRetrievalRequestsArrayBaseSlot);
|
|
709
791
|
const logRetrievalResponsesArrayBaseSlot = fromSingle(foreignLogRetrievalResponsesArrayBaseSlot);
|
|
710
792
|
|
|
711
|
-
await this.handlerAsUtility().
|
|
793
|
+
await this.handlerAsUtility().bulkRetrieveLogs(
|
|
712
794
|
contractAddress,
|
|
713
795
|
logRetrievalRequestsArrayBaseSlot,
|
|
714
796
|
logRetrievalResponsesArrayBaseSlot,
|
|
@@ -717,7 +799,8 @@ export class RPCTranslator {
|
|
|
717
799
|
return toForeignCallResult([]);
|
|
718
800
|
}
|
|
719
801
|
|
|
720
|
-
|
|
802
|
+
// eslint-disable-next-line camelcase
|
|
803
|
+
async aztec_utl_storeCapsule(
|
|
721
804
|
foreignContractAddress: ForeignCallSingle,
|
|
722
805
|
foreignSlot: ForeignCallSingle,
|
|
723
806
|
foreignCapsule: ForeignCallArray,
|
|
@@ -726,12 +809,13 @@ export class RPCTranslator {
|
|
|
726
809
|
const slot = fromSingle(foreignSlot);
|
|
727
810
|
const capsule = fromArray(foreignCapsule);
|
|
728
811
|
|
|
729
|
-
await this.handlerAsUtility().
|
|
812
|
+
await this.handlerAsUtility().storeCapsule(contractAddress, slot, capsule);
|
|
730
813
|
|
|
731
814
|
return toForeignCallResult([]);
|
|
732
815
|
}
|
|
733
816
|
|
|
734
|
-
|
|
817
|
+
// eslint-disable-next-line camelcase
|
|
818
|
+
async aztec_utl_loadCapsule(
|
|
735
819
|
foreignContractAddress: ForeignCallSingle,
|
|
736
820
|
foreignSlot: ForeignCallSingle,
|
|
737
821
|
foreignTSize: ForeignCallSingle,
|
|
@@ -740,7 +824,7 @@ export class RPCTranslator {
|
|
|
740
824
|
const slot = fromSingle(foreignSlot);
|
|
741
825
|
const tSize = fromSingle(foreignTSize).toNumber();
|
|
742
826
|
|
|
743
|
-
const values = await this.handlerAsUtility().
|
|
827
|
+
const values = await this.handlerAsUtility().loadCapsule(contractAddress, slot);
|
|
744
828
|
|
|
745
829
|
// We are going to return a Noir Option struct to represent the possibility of null values. Options are a struct
|
|
746
830
|
// with two fields: `some` (a boolean) and `value` (a field array in this case).
|
|
@@ -753,16 +837,18 @@ export class RPCTranslator {
|
|
|
753
837
|
}
|
|
754
838
|
}
|
|
755
839
|
|
|
756
|
-
|
|
840
|
+
// eslint-disable-next-line camelcase
|
|
841
|
+
async aztec_utl_deleteCapsule(foreignContractAddress: ForeignCallSingle, foreignSlot: ForeignCallSingle) {
|
|
757
842
|
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
758
843
|
const slot = fromSingle(foreignSlot);
|
|
759
844
|
|
|
760
|
-
await this.handlerAsUtility().
|
|
845
|
+
await this.handlerAsUtility().deleteCapsule(contractAddress, slot);
|
|
761
846
|
|
|
762
847
|
return toForeignCallResult([]);
|
|
763
848
|
}
|
|
764
849
|
|
|
765
|
-
|
|
850
|
+
// eslint-disable-next-line camelcase
|
|
851
|
+
async aztec_utl_copyCapsule(
|
|
766
852
|
foreignContractAddress: ForeignCallSingle,
|
|
767
853
|
foreignSrcSlot: ForeignCallSingle,
|
|
768
854
|
foreignDstSlot: ForeignCallSingle,
|
|
@@ -773,7 +859,7 @@ export class RPCTranslator {
|
|
|
773
859
|
const dstSlot = fromSingle(foreignDstSlot);
|
|
774
860
|
const numEntries = fromSingle(foreignNumEntries).toNumber();
|
|
775
861
|
|
|
776
|
-
await this.handlerAsUtility().
|
|
862
|
+
await this.handlerAsUtility().copyCapsule(contractAddress, srcSlot, dstSlot, numEntries);
|
|
777
863
|
|
|
778
864
|
return toForeignCallResult([]);
|
|
779
865
|
}
|
|
@@ -782,7 +868,8 @@ export class RPCTranslator {
|
|
|
782
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
|
|
783
869
|
// to implement this function here. Isn't there a way to programmatically identify that this is missing, given the
|
|
784
870
|
// existence of a txe_oracle method?
|
|
785
|
-
|
|
871
|
+
// eslint-disable-next-line camelcase
|
|
872
|
+
async aztec_utl_aes128Decrypt(
|
|
786
873
|
foreignCiphertextBVecStorage: ForeignCallArray,
|
|
787
874
|
foreignCiphertextLength: ForeignCallSingle,
|
|
788
875
|
foreignIv: ForeignCallArray,
|
|
@@ -792,14 +879,15 @@ export class RPCTranslator {
|
|
|
792
879
|
const iv = fromUintArray(foreignIv, 8);
|
|
793
880
|
const symKey = fromUintArray(foreignSymKey, 8);
|
|
794
881
|
|
|
795
|
-
const plaintextBuffer = await this.handlerAsUtility().
|
|
882
|
+
const plaintextBuffer = await this.handlerAsUtility().aes128Decrypt(ciphertext, iv, symKey);
|
|
796
883
|
|
|
797
884
|
return toForeignCallResult(
|
|
798
885
|
arrayToBoundedVec(bufferToU8Array(plaintextBuffer), foreignCiphertextBVecStorage.length),
|
|
799
886
|
);
|
|
800
887
|
}
|
|
801
888
|
|
|
802
|
-
|
|
889
|
+
// eslint-disable-next-line camelcase
|
|
890
|
+
async aztec_utl_getSharedSecret(
|
|
803
891
|
foreignAddress: ForeignCallSingle,
|
|
804
892
|
foreignEphPKField0: ForeignCallSingle,
|
|
805
893
|
foreignEphPKField1: ForeignCallSingle,
|
|
@@ -812,43 +900,49 @@ export class RPCTranslator {
|
|
|
812
900
|
fromSingle(foreignEphPKField2),
|
|
813
901
|
]);
|
|
814
902
|
|
|
815
|
-
const secret = await this.handlerAsUtility().
|
|
903
|
+
const secret = await this.handlerAsUtility().getSharedSecret(address, ephPK);
|
|
816
904
|
|
|
817
905
|
return toForeignCallResult(secret.toFields().map(toSingle));
|
|
818
906
|
}
|
|
819
907
|
|
|
820
|
-
|
|
908
|
+
// eslint-disable-next-line camelcase
|
|
909
|
+
aztec_utl_emitOffchainEffect(_foreignData: ForeignCallArray) {
|
|
821
910
|
throw new Error('Offchain effects are not yet supported in the TestEnvironment');
|
|
822
911
|
}
|
|
823
912
|
|
|
824
913
|
// AVM opcodes
|
|
825
914
|
|
|
826
|
-
|
|
915
|
+
// eslint-disable-next-line camelcase
|
|
916
|
+
aztec_avm_emitPublicLog(_foreignMessage: ForeignCallArray) {
|
|
827
917
|
// TODO(#8811): Implement
|
|
828
918
|
return toForeignCallResult([]);
|
|
829
919
|
}
|
|
830
920
|
|
|
831
|
-
|
|
921
|
+
// eslint-disable-next-line camelcase
|
|
922
|
+
async aztec_avm_storageRead(foreignSlot: ForeignCallSingle, foreignContractAddress: ForeignCallSingle) {
|
|
832
923
|
const slot = fromSingle(foreignSlot);
|
|
924
|
+
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
833
925
|
|
|
834
|
-
const value = (await this.handlerAsAvm().
|
|
926
|
+
const value = (await this.handlerAsAvm().storageRead(slot, contractAddress)).value;
|
|
835
927
|
|
|
836
928
|
return toForeignCallResult([toSingle(new Fr(value))]);
|
|
837
929
|
}
|
|
838
930
|
|
|
839
|
-
|
|
931
|
+
// eslint-disable-next-line camelcase
|
|
932
|
+
async aztec_avm_storageWrite(foreignSlot: ForeignCallSingle, foreignValue: ForeignCallSingle) {
|
|
840
933
|
const slot = fromSingle(foreignSlot);
|
|
841
934
|
const value = fromSingle(foreignValue);
|
|
842
935
|
|
|
843
|
-
await this.handlerAsAvm().
|
|
936
|
+
await this.handlerAsAvm().storageWrite(slot, value);
|
|
844
937
|
|
|
845
938
|
return toForeignCallResult([]);
|
|
846
939
|
}
|
|
847
940
|
|
|
848
|
-
|
|
941
|
+
// eslint-disable-next-line camelcase
|
|
942
|
+
async aztec_avm_getContractInstanceDeployer(foreignAddress: ForeignCallSingle) {
|
|
849
943
|
const address = addressFromSingle(foreignAddress);
|
|
850
944
|
|
|
851
|
-
const instance = await this.handlerAsUtility().
|
|
945
|
+
const instance = await this.handlerAsUtility().getContractInstance(address);
|
|
852
946
|
|
|
853
947
|
return toForeignCallResult([
|
|
854
948
|
toSingle(instance.deployer),
|
|
@@ -857,10 +951,11 @@ export class RPCTranslator {
|
|
|
857
951
|
]);
|
|
858
952
|
}
|
|
859
953
|
|
|
860
|
-
|
|
954
|
+
// eslint-disable-next-line camelcase
|
|
955
|
+
async aztec_avm_getContractInstanceClassId(foreignAddress: ForeignCallSingle) {
|
|
861
956
|
const address = addressFromSingle(foreignAddress);
|
|
862
957
|
|
|
863
|
-
const instance = await this.handlerAsUtility().
|
|
958
|
+
const instance = await this.handlerAsUtility().getContractInstance(address);
|
|
864
959
|
|
|
865
960
|
return toForeignCallResult([
|
|
866
961
|
toSingle(instance.currentContractClassId),
|
|
@@ -869,10 +964,11 @@ export class RPCTranslator {
|
|
|
869
964
|
]);
|
|
870
965
|
}
|
|
871
966
|
|
|
872
|
-
|
|
967
|
+
// eslint-disable-next-line camelcase
|
|
968
|
+
async aztec_avm_getContractInstanceInitializationHash(foreignAddress: ForeignCallSingle) {
|
|
873
969
|
const address = addressFromSingle(foreignAddress);
|
|
874
970
|
|
|
875
|
-
const instance = await this.handlerAsUtility().
|
|
971
|
+
const instance = await this.handlerAsUtility().getContractInstance(address);
|
|
876
972
|
|
|
877
973
|
return toForeignCallResult([
|
|
878
974
|
toSingle(instance.initializationHash),
|
|
@@ -881,86 +977,98 @@ export class RPCTranslator {
|
|
|
881
977
|
]);
|
|
882
978
|
}
|
|
883
979
|
|
|
884
|
-
|
|
885
|
-
|
|
980
|
+
// eslint-disable-next-line camelcase
|
|
981
|
+
async aztec_avm_sender() {
|
|
982
|
+
const sender = await this.handlerAsAvm().sender();
|
|
886
983
|
|
|
887
984
|
return toForeignCallResult([toSingle(sender)]);
|
|
888
985
|
}
|
|
889
986
|
|
|
890
|
-
|
|
987
|
+
// eslint-disable-next-line camelcase
|
|
988
|
+
async aztec_avm_emitNullifier(foreignNullifier: ForeignCallSingle) {
|
|
891
989
|
const nullifier = fromSingle(foreignNullifier);
|
|
892
990
|
|
|
893
|
-
await this.handlerAsAvm().
|
|
991
|
+
await this.handlerAsAvm().emitNullifier(nullifier);
|
|
894
992
|
|
|
895
993
|
return toForeignCallResult([]);
|
|
896
994
|
}
|
|
897
995
|
|
|
898
|
-
|
|
996
|
+
// eslint-disable-next-line camelcase
|
|
997
|
+
async aztec_avm_emitNoteHash(foreignNoteHash: ForeignCallSingle) {
|
|
899
998
|
const noteHash = fromSingle(foreignNoteHash);
|
|
900
999
|
|
|
901
|
-
await this.handlerAsAvm().
|
|
1000
|
+
await this.handlerAsAvm().emitNoteHash(noteHash);
|
|
902
1001
|
|
|
903
1002
|
return toForeignCallResult([]);
|
|
904
1003
|
}
|
|
905
1004
|
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
const
|
|
1005
|
+
// eslint-disable-next-line camelcase
|
|
1006
|
+
async aztec_avm_nullifierExists(foreignSiloedNullifier: ForeignCallSingle) {
|
|
1007
|
+
const siloedNullifier = fromSingle(foreignSiloedNullifier);
|
|
909
1008
|
|
|
910
|
-
const exists = await this.handlerAsAvm().
|
|
1009
|
+
const exists = await this.handlerAsAvm().nullifierExists(siloedNullifier);
|
|
911
1010
|
|
|
912
1011
|
return toForeignCallResult([toSingle(new Fr(exists))]);
|
|
913
1012
|
}
|
|
914
1013
|
|
|
915
|
-
|
|
916
|
-
|
|
1014
|
+
// eslint-disable-next-line camelcase
|
|
1015
|
+
async aztec_avm_address() {
|
|
1016
|
+
const contractAddress = await this.handlerAsAvm().address();
|
|
917
1017
|
|
|
918
1018
|
return toForeignCallResult([toSingle(contractAddress.toField())]);
|
|
919
1019
|
}
|
|
920
1020
|
|
|
921
|
-
|
|
922
|
-
|
|
1021
|
+
// eslint-disable-next-line camelcase
|
|
1022
|
+
async aztec_avm_blockNumber() {
|
|
1023
|
+
const blockNumber = await this.handlerAsAvm().blockNumber();
|
|
923
1024
|
|
|
924
1025
|
return toForeignCallResult([toSingle(new Fr(blockNumber))]);
|
|
925
1026
|
}
|
|
926
1027
|
|
|
927
|
-
|
|
928
|
-
|
|
1028
|
+
// eslint-disable-next-line camelcase
|
|
1029
|
+
async aztec_avm_timestamp() {
|
|
1030
|
+
const timestamp = await this.handlerAsAvm().timestamp();
|
|
929
1031
|
|
|
930
1032
|
return toForeignCallResult([toSingle(new Fr(timestamp))]);
|
|
931
1033
|
}
|
|
932
1034
|
|
|
933
|
-
|
|
934
|
-
|
|
1035
|
+
// eslint-disable-next-line camelcase
|
|
1036
|
+
async aztec_avm_isStaticCall() {
|
|
1037
|
+
const isStaticCall = await this.handlerAsAvm().isStaticCall();
|
|
935
1038
|
|
|
936
1039
|
return toForeignCallResult([toSingle(new Fr(isStaticCall ? 1 : 0))]);
|
|
937
1040
|
}
|
|
938
1041
|
|
|
939
|
-
|
|
940
|
-
|
|
1042
|
+
// eslint-disable-next-line camelcase
|
|
1043
|
+
async aztec_avm_chainId() {
|
|
1044
|
+
const chainId = await this.handlerAsAvm().chainId();
|
|
941
1045
|
|
|
942
1046
|
return toForeignCallResult([toSingle(chainId)]);
|
|
943
1047
|
}
|
|
944
1048
|
|
|
945
|
-
|
|
946
|
-
|
|
1049
|
+
// eslint-disable-next-line camelcase
|
|
1050
|
+
async aztec_avm_version() {
|
|
1051
|
+
const version = await this.handlerAsAvm().version();
|
|
947
1052
|
|
|
948
1053
|
return toForeignCallResult([toSingle(version)]);
|
|
949
1054
|
}
|
|
950
1055
|
|
|
951
|
-
|
|
1056
|
+
// eslint-disable-next-line camelcase
|
|
1057
|
+
aztec_avm_returndataSize() {
|
|
952
1058
|
throw new Error(
|
|
953
1059
|
'Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead',
|
|
954
1060
|
);
|
|
955
1061
|
}
|
|
956
1062
|
|
|
957
|
-
|
|
1063
|
+
// eslint-disable-next-line camelcase
|
|
1064
|
+
aztec_avm_returndataCopy(_foreignRdOffset: ForeignCallSingle, _foreignCopySize: ForeignCallSingle) {
|
|
958
1065
|
throw new Error(
|
|
959
1066
|
'Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead',
|
|
960
1067
|
);
|
|
961
1068
|
}
|
|
962
1069
|
|
|
963
|
-
|
|
1070
|
+
// eslint-disable-next-line camelcase
|
|
1071
|
+
aztec_avm_call(
|
|
964
1072
|
_foreignL2Gas: ForeignCallSingle,
|
|
965
1073
|
_foreignDaGas: ForeignCallSingle,
|
|
966
1074
|
_foreignAddress: ForeignCallSingle,
|
|
@@ -972,7 +1080,8 @@ export class RPCTranslator {
|
|
|
972
1080
|
);
|
|
973
1081
|
}
|
|
974
1082
|
|
|
975
|
-
|
|
1083
|
+
// eslint-disable-next-line camelcase
|
|
1084
|
+
aztec_avm_staticCall(
|
|
976
1085
|
_foreignL2Gas: ForeignCallSingle,
|
|
977
1086
|
_foreignDaGas: ForeignCallSingle,
|
|
978
1087
|
_foreignAddress: ForeignCallSingle,
|
|
@@ -984,13 +1093,15 @@ export class RPCTranslator {
|
|
|
984
1093
|
);
|
|
985
1094
|
}
|
|
986
1095
|
|
|
987
|
-
|
|
1096
|
+
// eslint-disable-next-line camelcase
|
|
1097
|
+
aztec_avm_successCopy() {
|
|
988
1098
|
throw new Error(
|
|
989
1099
|
'Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead',
|
|
990
1100
|
);
|
|
991
1101
|
}
|
|
992
1102
|
|
|
993
|
-
|
|
1103
|
+
// eslint-disable-next-line camelcase
|
|
1104
|
+
async aztec_txe_privateCallNewFlow(
|
|
994
1105
|
foreignFrom: ForeignCallSingle,
|
|
995
1106
|
foreignTargetContractAddress: ForeignCallSingle,
|
|
996
1107
|
foreignFunctionSelector: ForeignCallSingle,
|
|
@@ -1005,19 +1116,23 @@ export class RPCTranslator {
|
|
|
1005
1116
|
const argsHash = fromSingle(foreignArgsHash);
|
|
1006
1117
|
const isStaticCall = fromSingle(foreignIsStaticCall).toBool();
|
|
1007
1118
|
|
|
1008
|
-
const returnValues = await this.handlerAsTxe().
|
|
1119
|
+
const returnValues = await this.handlerAsTxe().privateCallNewFlow(
|
|
1009
1120
|
from,
|
|
1010
1121
|
targetContractAddress,
|
|
1011
1122
|
functionSelector,
|
|
1012
1123
|
args,
|
|
1013
1124
|
argsHash,
|
|
1014
1125
|
isStaticCall,
|
|
1126
|
+
this.stateHandler.getCurrentJob(),
|
|
1015
1127
|
);
|
|
1016
1128
|
|
|
1129
|
+
// TODO(F-335): Avoid doing the following call here.
|
|
1130
|
+
await this.stateHandler.cycleJob();
|
|
1017
1131
|
return toForeignCallResult([toArray(returnValues)]);
|
|
1018
1132
|
}
|
|
1019
1133
|
|
|
1020
|
-
|
|
1134
|
+
// eslint-disable-next-line camelcase
|
|
1135
|
+
async aztec_txe_executeUtilityFunction(
|
|
1021
1136
|
foreignTargetContractAddress: ForeignCallSingle,
|
|
1022
1137
|
foreignFunctionSelector: ForeignCallSingle,
|
|
1023
1138
|
foreignArgs: ForeignCallArray,
|
|
@@ -1026,16 +1141,20 @@ export class RPCTranslator {
|
|
|
1026
1141
|
const functionSelector = FunctionSelector.fromField(fromSingle(foreignFunctionSelector));
|
|
1027
1142
|
const args = fromArray(foreignArgs);
|
|
1028
1143
|
|
|
1029
|
-
const returnValues = await this.handlerAsTxe().
|
|
1144
|
+
const returnValues = await this.handlerAsTxe().executeUtilityFunction(
|
|
1030
1145
|
targetContractAddress,
|
|
1031
1146
|
functionSelector,
|
|
1032
1147
|
args,
|
|
1148
|
+
this.stateHandler.getCurrentJob(),
|
|
1033
1149
|
);
|
|
1034
1150
|
|
|
1151
|
+
// TODO(F-335): Avoid doing the following call here.
|
|
1152
|
+
await this.stateHandler.cycleJob();
|
|
1035
1153
|
return toForeignCallResult([toArray(returnValues)]);
|
|
1036
1154
|
}
|
|
1037
1155
|
|
|
1038
|
-
|
|
1156
|
+
// eslint-disable-next-line camelcase
|
|
1157
|
+
async aztec_txe_publicCallNewFlow(
|
|
1039
1158
|
foreignFrom: ForeignCallSingle,
|
|
1040
1159
|
foreignAddress: ForeignCallSingle,
|
|
1041
1160
|
foreignCalldata: ForeignCallArray,
|
|
@@ -1046,13 +1165,16 @@ export class RPCTranslator {
|
|
|
1046
1165
|
const calldata = fromArray(foreignCalldata);
|
|
1047
1166
|
const isStaticCall = fromSingle(foreignIsStaticCall).toBool();
|
|
1048
1167
|
|
|
1049
|
-
const returnValues = await this.handlerAsTxe().
|
|
1168
|
+
const returnValues = await this.handlerAsTxe().publicCallNewFlow(from, address, calldata, isStaticCall);
|
|
1050
1169
|
|
|
1170
|
+
// TODO(F-335): Avoid doing the following call here.
|
|
1171
|
+
await this.stateHandler.cycleJob();
|
|
1051
1172
|
return toForeignCallResult([toArray(returnValues)]);
|
|
1052
1173
|
}
|
|
1053
1174
|
|
|
1054
|
-
|
|
1055
|
-
|
|
1175
|
+
// eslint-disable-next-line camelcase
|
|
1176
|
+
async aztec_prv_getSenderForTags() {
|
|
1177
|
+
const sender = await this.handlerAsPrivate().getSenderForTags();
|
|
1056
1178
|
|
|
1057
1179
|
// Return a Noir Option struct with `some` and `value` fields
|
|
1058
1180
|
if (sender === undefined) {
|
|
@@ -1064,19 +1186,21 @@ export class RPCTranslator {
|
|
|
1064
1186
|
}
|
|
1065
1187
|
}
|
|
1066
1188
|
|
|
1067
|
-
|
|
1189
|
+
// eslint-disable-next-line camelcase
|
|
1190
|
+
async aztec_prv_setSenderForTags(foreignSenderForTags: ForeignCallSingle) {
|
|
1068
1191
|
const senderForTags = AztecAddress.fromField(fromSingle(foreignSenderForTags));
|
|
1069
1192
|
|
|
1070
|
-
await this.handlerAsPrivate().
|
|
1193
|
+
await this.handlerAsPrivate().setSenderForTags(senderForTags);
|
|
1071
1194
|
|
|
1072
1195
|
return toForeignCallResult([]);
|
|
1073
1196
|
}
|
|
1074
1197
|
|
|
1075
|
-
|
|
1198
|
+
// eslint-disable-next-line camelcase
|
|
1199
|
+
async aztec_prv_getNextAppTagAsSender(foreignSender: ForeignCallSingle, foreignRecipient: ForeignCallSingle) {
|
|
1076
1200
|
const sender = AztecAddress.fromField(fromSingle(foreignSender));
|
|
1077
1201
|
const recipient = AztecAddress.fromField(fromSingle(foreignRecipient));
|
|
1078
1202
|
|
|
1079
|
-
const nextAppTag = await this.handlerAsPrivate().
|
|
1203
|
+
const nextAppTag = await this.handlerAsPrivate().getNextAppTagAsSender(sender, recipient);
|
|
1080
1204
|
|
|
1081
1205
|
return toForeignCallResult([toSingle(nextAppTag.value)]);
|
|
1082
1206
|
}
|