@aztec/txe 0.0.1-commit.d1f2d6c → 0.0.1-commit.d20b825a7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/index.d.ts +1 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +88 -54
- package/dest/oracle/interfaces.d.ts +32 -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 +14 -15
- package/dest/oracle/txe_oracle_top_level_context.d.ts +30 -23
- package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_top_level_context.js +164 -65
- package/dest/rpc_translator.d.ts +129 -83
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +486 -175
- package/dest/state_machine/archiver.d.ts +4 -4
- package/dest/state_machine/archiver.d.ts.map +1 -1
- package/dest/state_machine/archiver.js +10 -12
- package/dest/state_machine/dummy_p2p_client.d.ts +18 -13
- package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
- package/dest/state_machine/dummy_p2p_client.js +33 -18
- package/dest/state_machine/global_variable_builder.d.ts +9 -4
- package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
- package/dest/state_machine/global_variable_builder.js +9 -3
- 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 +36 -18
- package/dest/state_machine/mock_epoch_cache.d.ts +20 -3
- package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
- package/dest/state_machine/mock_epoch_cache.js +39 -2
- package/dest/state_machine/synchronizer.d.ts +5 -5
- package/dest/state_machine/synchronizer.d.ts.map +1 -1
- package/dest/state_machine/synchronizer.js +3 -3
- package/dest/txe_session.d.ts +54 -6
- package/dest/txe_session.d.ts.map +1 -1
- package/dest/txe_session.js +152 -28
- package/dest/util/encoding.d.ts +71 -1
- package/dest/util/encoding.d.ts.map +1 -1
- package/dest/util/encoding.js +4 -0
- package/dest/util/txe_public_contract_data_source.d.ts +2 -3
- package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
- package/dest/util/txe_public_contract_data_source.js +6 -25
- package/dest/utils/block_creation.d.ts +1 -1
- package/dest/utils/block_creation.d.ts.map +1 -1
- package/dest/utils/block_creation.js +3 -1
- package/package.json +15 -15
- package/src/index.ts +89 -52
- package/src/oracle/interfaces.ts +33 -32
- package/src/oracle/txe_oracle_public_context.ts +14 -16
- package/src/oracle/txe_oracle_top_level_context.ts +196 -116
- package/src/rpc_translator.ts +563 -202
- package/src/state_machine/archiver.ts +10 -11
- package/src/state_machine/dummy_p2p_client.ts +46 -24
- package/src/state_machine/global_variable_builder.ts +18 -3
- package/src/state_machine/index.ts +54 -18
- package/src/state_machine/mock_epoch_cache.ts +51 -3
- package/src/state_machine/synchronizer.ts +4 -4
- package/src/txe_session.ts +223 -88
- package/src/util/encoding.ts +5 -0
- package/src/util/txe_public_contract_data_source.ts +10 -38
- package/src/utils/block_creation.ts +3 -1
- package/dest/util/txe_contract_store.d.ts +0 -12
- package/dest/util/txe_contract_store.d.ts.map +0 -1
- package/dest/util/txe_contract_store.js +0 -22
- package/src/util/txe_contract_store.ts +0 -36
package/src/rpc_translator.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ContractInstanceWithAddress } from '@aztec/aztec.js/contracts';
|
|
2
2
|
import { Fr, Point } from '@aztec/aztec.js/fields';
|
|
3
|
-
import { MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX } from '@aztec/constants';
|
|
3
|
+
import { MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX, PRIVATE_LOG_CIPHERTEXT_LEN } from '@aztec/constants';
|
|
4
4
|
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
5
5
|
import {
|
|
6
6
|
type IMiscOracle,
|
|
@@ -10,7 +10,6 @@ import {
|
|
|
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 { L2BlockHash } from '@aztec/stdlib/block';
|
|
14
13
|
|
|
15
14
|
import type { IAvmExecutionOracle, ITxeExecutionOracle } from './oracle/interfaces.js';
|
|
16
15
|
import type { TXESessionStateHandler } from './txe_session.js';
|
|
@@ -20,6 +19,7 @@ import {
|
|
|
20
19
|
addressFromSingle,
|
|
21
20
|
arrayOfArraysToBoundedVecOfArrays,
|
|
22
21
|
arrayToBoundedVec,
|
|
22
|
+
blockHashFromSingle,
|
|
23
23
|
bufferToU8Array,
|
|
24
24
|
fromArray,
|
|
25
25
|
fromSingle,
|
|
@@ -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,45 @@ 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
|
-
|
|
250
|
-
|
|
266
|
+
// eslint-disable-next-line camelcase
|
|
267
|
+
aztec_utl_assertCompatibleOracleVersionV2(foreignMajor: ForeignCallSingle, foreignMinor: ForeignCallSingle) {
|
|
268
|
+
const major = fromSingle(foreignMajor).toNumber();
|
|
269
|
+
const minor = fromSingle(foreignMinor).toNumber();
|
|
251
270
|
|
|
252
|
-
this.handlerAsMisc().
|
|
271
|
+
this.handlerAsMisc().assertCompatibleOracleVersion(major, minor);
|
|
253
272
|
|
|
254
273
|
return toForeignCallResult([]);
|
|
255
274
|
}
|
|
256
275
|
|
|
257
|
-
|
|
258
|
-
|
|
276
|
+
// eslint-disable-next-line camelcase
|
|
277
|
+
aztec_utl_getRandomField() {
|
|
278
|
+
const randomField = this.handlerAsMisc().getRandomField();
|
|
259
279
|
|
|
260
280
|
return toForeignCallResult([toSingle(randomField)]);
|
|
261
281
|
}
|
|
262
282
|
|
|
263
|
-
|
|
264
|
-
|
|
283
|
+
// eslint-disable-next-line camelcase
|
|
284
|
+
async aztec_txe_getLastBlockTimestamp() {
|
|
285
|
+
const timestamp = await this.handlerAsTxe().getLastBlockTimestamp();
|
|
265
286
|
|
|
266
287
|
return toForeignCallResult([toSingle(new Fr(timestamp))]);
|
|
267
288
|
}
|
|
268
289
|
|
|
269
|
-
|
|
270
|
-
|
|
290
|
+
// eslint-disable-next-line camelcase
|
|
291
|
+
async aztec_txe_getLastTxEffects() {
|
|
292
|
+
const { txHash, noteHashes, nullifiers } = await this.handlerAsTxe().getLastTxEffects();
|
|
271
293
|
|
|
272
294
|
return toForeignCallResult([
|
|
273
295
|
toSingle(txHash.hash),
|
|
@@ -276,7 +298,48 @@ export class RPCTranslator {
|
|
|
276
298
|
]);
|
|
277
299
|
}
|
|
278
300
|
|
|
279
|
-
|
|
301
|
+
// eslint-disable-next-line camelcase
|
|
302
|
+
aztec_txe_getLastCallOffchainEffects() {
|
|
303
|
+
// This oracle returns all offchain effect payloads (messages, authwit requests, etc.) emitted by the last top-level call,
|
|
304
|
+
// MAX_OFFCHAIN_EFFECTS_PER_TXE_QUERY is arbitrarily set at 64 because we need a bound. Nothing inherent about it.
|
|
305
|
+
const MAX_OFFCHAIN_EFFECTS_PER_TXE_QUERY = 64;
|
|
306
|
+
// Must match MAX_OFFCHAIN_EFFECT_LEN in txe_oracles.nr.
|
|
307
|
+
const MAX_OFFCHAIN_EFFECT_LEN = 2 + PRIVATE_LOG_CIPHERTEXT_LEN;
|
|
308
|
+
|
|
309
|
+
const { effects } = this.stateHandler.getLastCallOffchainEffects();
|
|
310
|
+
|
|
311
|
+
if (effects.length > MAX_OFFCHAIN_EFFECTS_PER_TXE_QUERY) {
|
|
312
|
+
throw new Error(`${effects.length} offchain effects exceed max ${MAX_OFFCHAIN_EFFECTS_PER_TXE_QUERY}`);
|
|
313
|
+
}
|
|
314
|
+
if (effects.some(e => e.length > MAX_OFFCHAIN_EFFECT_LEN)) {
|
|
315
|
+
throw new Error(`Some offchain effect has length larger than max ${MAX_OFFCHAIN_EFFECT_LEN}`);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
const rawArrayStorage = effects
|
|
319
|
+
.map(e => e.concat(Array(MAX_OFFCHAIN_EFFECT_LEN - e.length).fill(new Fr(0))))
|
|
320
|
+
.concat(
|
|
321
|
+
Array(MAX_OFFCHAIN_EFFECTS_PER_TXE_QUERY - effects.length).fill(Array(MAX_OFFCHAIN_EFFECT_LEN).fill(new Fr(0))),
|
|
322
|
+
)
|
|
323
|
+
.flat();
|
|
324
|
+
|
|
325
|
+
const effectLengths = effects
|
|
326
|
+
.map(e => new Fr(e.length))
|
|
327
|
+
.concat(Array(MAX_OFFCHAIN_EFFECTS_PER_TXE_QUERY - effects.length).fill(new Fr(0)));
|
|
328
|
+
|
|
329
|
+
const count = new Fr(effects.length);
|
|
330
|
+
|
|
331
|
+
return toForeignCallResult([toArray(rawArrayStorage), toArray(effectLengths), toSingle(count)]);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
// eslint-disable-next-line camelcase
|
|
335
|
+
aztec_txe_getLastCallContext() {
|
|
336
|
+
const { txHash, anchorBlockTimestamp } = this.stateHandler.getLastCallContext();
|
|
337
|
+
const isSome = txHash.isZero() ? 0 : 1;
|
|
338
|
+
return toForeignCallResult([toSingle(isSome), toSingle(txHash), toSingle(new Fr(anchorBlockTimestamp))]);
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
// eslint-disable-next-line camelcase
|
|
342
|
+
async aztec_txe_getPrivateEvents(
|
|
280
343
|
foreignSelector: ForeignCallSingle,
|
|
281
344
|
foreignContractAddress: ForeignCallSingle,
|
|
282
345
|
foreignScope: ForeignCallSingle,
|
|
@@ -285,7 +348,14 @@ export class RPCTranslator {
|
|
|
285
348
|
const contractAddress = addressFromSingle(foreignContractAddress);
|
|
286
349
|
const scope = addressFromSingle(foreignScope);
|
|
287
350
|
|
|
288
|
-
|
|
351
|
+
// TODO(F-335): Avoid doing the following 2 calls here.
|
|
352
|
+
{
|
|
353
|
+
await this.handlerAsTxe().syncContractNonOracleMethod(contractAddress, scope, this.stateHandler.getCurrentJob());
|
|
354
|
+
// We cycle job to commit the stores after the contract sync.
|
|
355
|
+
await this.stateHandler.cycleJob();
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
const events = await this.handlerAsTxe().getPrivateEvents(selector, contractAddress, scope);
|
|
289
359
|
|
|
290
360
|
if (events.length > MAX_PRIVATE_EVENTS_PER_TXE_QUERY) {
|
|
291
361
|
throw new Error(`Array of length ${events.length} larger than maxLen ${MAX_PRIVATE_EVENTS_PER_TXE_QUERY}`);
|
|
@@ -309,26 +379,29 @@ export class RPCTranslator {
|
|
|
309
379
|
return toForeignCallResult([toArray(rawArrayStorage), toArray(eventLengths), toSingle(queryLength)]);
|
|
310
380
|
}
|
|
311
381
|
|
|
312
|
-
|
|
382
|
+
// eslint-disable-next-line camelcase
|
|
383
|
+
aztec_prv_setHashPreimage(foreignValues: ForeignCallArray, foreignHash: ForeignCallSingle) {
|
|
313
384
|
const values = fromArray(foreignValues);
|
|
314
385
|
const hash = fromSingle(foreignHash);
|
|
315
386
|
|
|
316
|
-
this.handlerAsPrivate().
|
|
387
|
+
this.handlerAsPrivate().setHashPreimage(values, hash);
|
|
317
388
|
|
|
318
389
|
return toForeignCallResult([]);
|
|
319
390
|
}
|
|
320
391
|
|
|
321
|
-
|
|
392
|
+
// eslint-disable-next-line camelcase
|
|
393
|
+
async aztec_prv_getHashPreimage(foreignHash: ForeignCallSingle) {
|
|
322
394
|
const hash = fromSingle(foreignHash);
|
|
323
395
|
|
|
324
|
-
const returns = await this.handlerAsPrivate().
|
|
396
|
+
const returns = await this.handlerAsPrivate().getHashPreimage(hash);
|
|
325
397
|
|
|
326
398
|
return toForeignCallResult([toArray(returns)]);
|
|
327
399
|
}
|
|
328
400
|
|
|
329
401
|
// When the argument is a slice, noir automatically adds a length field to oracle call.
|
|
330
402
|
// When the argument is an array, we add the field length manually to the signature.
|
|
331
|
-
|
|
403
|
+
// eslint-disable-next-line camelcase
|
|
404
|
+
async aztec_utl_log(
|
|
332
405
|
foreignLevel: ForeignCallSingle,
|
|
333
406
|
foreignMessage: ForeignCallArray,
|
|
334
407
|
_foreignLength: ForeignCallSingle,
|
|
@@ -340,23 +413,24 @@ export class RPCTranslator {
|
|
|
340
413
|
.join('');
|
|
341
414
|
const fields = fromArray(foreignFields);
|
|
342
415
|
|
|
343
|
-
this.handlerAsMisc().
|
|
416
|
+
await this.handlerAsMisc().log(level, message, fields);
|
|
344
417
|
|
|
345
418
|
return toForeignCallResult([]);
|
|
346
419
|
}
|
|
347
420
|
|
|
348
|
-
|
|
421
|
+
// eslint-disable-next-line camelcase
|
|
422
|
+
async aztec_utl_getFromPublicStorage(
|
|
349
423
|
foreignBlockHash: ForeignCallSingle,
|
|
350
424
|
foreignContractAddress: ForeignCallSingle,
|
|
351
425
|
foreignStartStorageSlot: ForeignCallSingle,
|
|
352
426
|
foreignNumberOfElements: ForeignCallSingle,
|
|
353
427
|
) {
|
|
354
|
-
const blockHash =
|
|
428
|
+
const blockHash = blockHashFromSingle(foreignBlockHash);
|
|
355
429
|
const contractAddress = addressFromSingle(foreignContractAddress);
|
|
356
430
|
const startStorageSlot = fromSingle(foreignStartStorageSlot);
|
|
357
431
|
const numberOfElements = fromSingle(foreignNumberOfElements).toNumber();
|
|
358
432
|
|
|
359
|
-
const values = await this.handlerAsUtility().
|
|
433
|
+
const values = await this.handlerAsUtility().getFromPublicStorage(
|
|
360
434
|
blockHash,
|
|
361
435
|
contractAddress,
|
|
362
436
|
startStorageSlot,
|
|
@@ -366,11 +440,12 @@ export class RPCTranslator {
|
|
|
366
440
|
return toForeignCallResult([toArray(values)]);
|
|
367
441
|
}
|
|
368
442
|
|
|
369
|
-
|
|
370
|
-
|
|
443
|
+
// eslint-disable-next-line camelcase
|
|
444
|
+
async aztec_utl_getPublicDataWitness(foreignBlockHash: ForeignCallSingle, foreignLeafSlot: ForeignCallSingle) {
|
|
445
|
+
const blockHash = blockHashFromSingle(foreignBlockHash);
|
|
371
446
|
const leafSlot = fromSingle(foreignLeafSlot);
|
|
372
447
|
|
|
373
|
-
const witness = await this.handlerAsUtility().
|
|
448
|
+
const witness = await this.handlerAsUtility().getPublicDataWitness(blockHash, leafSlot);
|
|
374
449
|
|
|
375
450
|
if (!witness) {
|
|
376
451
|
throw new Error(`Public data witness not found for slot ${leafSlot} at block ${blockHash.toString()}.`);
|
|
@@ -378,7 +453,8 @@ export class RPCTranslator {
|
|
|
378
453
|
return toForeignCallResult(witness.toNoirRepresentation());
|
|
379
454
|
}
|
|
380
455
|
|
|
381
|
-
|
|
456
|
+
// eslint-disable-next-line camelcase
|
|
457
|
+
async aztec_utl_getNotes(
|
|
382
458
|
foreignOwnerIsSome: ForeignCallSingle,
|
|
383
459
|
foreignOwnerValue: ForeignCallSingle,
|
|
384
460
|
foreignStorageSlot: ForeignCallSingle,
|
|
@@ -419,7 +495,7 @@ export class RPCTranslator {
|
|
|
419
495
|
const maxNotes = fromSingle(foreignMaxNotes).toNumber();
|
|
420
496
|
const packedHintedNoteLength = fromSingle(foreignPackedHintedNoteLength).toNumber();
|
|
421
497
|
|
|
422
|
-
const noteDatas = await this.handlerAsUtility().
|
|
498
|
+
const noteDatas = await this.handlerAsUtility().getNotes(
|
|
423
499
|
owner,
|
|
424
500
|
storageSlot,
|
|
425
501
|
numSelects,
|
|
@@ -460,7 +536,8 @@ export class RPCTranslator {
|
|
|
460
536
|
);
|
|
461
537
|
}
|
|
462
538
|
|
|
463
|
-
|
|
539
|
+
// eslint-disable-next-line camelcase
|
|
540
|
+
aztec_prv_notifyCreatedNote(
|
|
464
541
|
foreignOwner: ForeignCallSingle,
|
|
465
542
|
foreignStorageSlot: ForeignCallSingle,
|
|
466
543
|
foreignRandomness: ForeignCallSingle,
|
|
@@ -477,20 +554,13 @@ export class RPCTranslator {
|
|
|
477
554
|
const noteHash = fromSingle(foreignNoteHash);
|
|
478
555
|
const counter = fromSingle(foreignCounter).toNumber();
|
|
479
556
|
|
|
480
|
-
this.handlerAsPrivate().
|
|
481
|
-
owner,
|
|
482
|
-
storageSlot,
|
|
483
|
-
randomness,
|
|
484
|
-
noteTypeId,
|
|
485
|
-
note,
|
|
486
|
-
noteHash,
|
|
487
|
-
counter,
|
|
488
|
-
);
|
|
557
|
+
this.handlerAsPrivate().notifyCreatedNote(owner, storageSlot, randomness, noteTypeId, note, noteHash, counter);
|
|
489
558
|
|
|
490
559
|
return toForeignCallResult([]);
|
|
491
560
|
}
|
|
492
561
|
|
|
493
|
-
|
|
562
|
+
// eslint-disable-next-line camelcase
|
|
563
|
+
async aztec_prv_notifyNullifiedNote(
|
|
494
564
|
foreignInnerNullifier: ForeignCallSingle,
|
|
495
565
|
foreignNoteHash: ForeignCallSingle,
|
|
496
566
|
foreignCounter: ForeignCallSingle,
|
|
@@ -499,40 +569,47 @@ export class RPCTranslator {
|
|
|
499
569
|
const noteHash = fromSingle(foreignNoteHash);
|
|
500
570
|
const counter = fromSingle(foreignCounter).toNumber();
|
|
501
571
|
|
|
502
|
-
await this.handlerAsPrivate().
|
|
572
|
+
await this.handlerAsPrivate().notifyNullifiedNote(innerNullifier, noteHash, counter);
|
|
503
573
|
|
|
504
574
|
return toForeignCallResult([]);
|
|
505
575
|
}
|
|
506
576
|
|
|
507
|
-
|
|
577
|
+
// eslint-disable-next-line camelcase
|
|
578
|
+
async aztec_prv_notifyCreatedNullifier(foreignInnerNullifier: ForeignCallSingle) {
|
|
508
579
|
const innerNullifier = fromSingle(foreignInnerNullifier);
|
|
509
580
|
|
|
510
|
-
await this.handlerAsPrivate().
|
|
581
|
+
await this.handlerAsPrivate().notifyCreatedNullifier(innerNullifier);
|
|
511
582
|
|
|
512
583
|
return toForeignCallResult([]);
|
|
513
584
|
}
|
|
514
585
|
|
|
515
|
-
|
|
586
|
+
// eslint-disable-next-line camelcase
|
|
587
|
+
async aztec_prv_isNullifierPending(
|
|
588
|
+
foreignInnerNullifier: ForeignCallSingle,
|
|
589
|
+
foreignContractAddress: ForeignCallSingle,
|
|
590
|
+
) {
|
|
516
591
|
const innerNullifier = fromSingle(foreignInnerNullifier);
|
|
517
592
|
const contractAddress = addressFromSingle(foreignContractAddress);
|
|
518
593
|
|
|
519
|
-
const isPending = await this.handlerAsPrivate().
|
|
594
|
+
const isPending = await this.handlerAsPrivate().isNullifierPending(innerNullifier, contractAddress);
|
|
520
595
|
|
|
521
596
|
return toForeignCallResult([toSingle(new Fr(isPending))]);
|
|
522
597
|
}
|
|
523
598
|
|
|
524
|
-
|
|
599
|
+
// eslint-disable-next-line camelcase
|
|
600
|
+
async aztec_utl_doesNullifierExist(foreignInnerNullifier: ForeignCallSingle) {
|
|
525
601
|
const innerNullifier = fromSingle(foreignInnerNullifier);
|
|
526
602
|
|
|
527
|
-
const exists = await this.handlerAsUtility().
|
|
603
|
+
const exists = await this.handlerAsUtility().doesNullifierExist(innerNullifier);
|
|
528
604
|
|
|
529
605
|
return toForeignCallResult([toSingle(new Fr(exists))]);
|
|
530
606
|
}
|
|
531
607
|
|
|
532
|
-
|
|
608
|
+
// eslint-disable-next-line camelcase
|
|
609
|
+
async aztec_utl_getContractInstance(foreignAddress: ForeignCallSingle) {
|
|
533
610
|
const address = addressFromSingle(foreignAddress);
|
|
534
611
|
|
|
535
|
-
const instance = await this.handlerAsUtility().
|
|
612
|
+
const instance = await this.handlerAsUtility().getContractInstance(address);
|
|
536
613
|
|
|
537
614
|
return toForeignCallResult(
|
|
538
615
|
[
|
|
@@ -545,23 +622,37 @@ export class RPCTranslator {
|
|
|
545
622
|
);
|
|
546
623
|
}
|
|
547
624
|
|
|
548
|
-
|
|
625
|
+
// eslint-disable-next-line camelcase
|
|
626
|
+
async aztec_utl_getPublicKeysAndPartialAddress(foreignAddress: ForeignCallSingle) {
|
|
549
627
|
const address = addressFromSingle(foreignAddress);
|
|
550
628
|
|
|
551
|
-
const
|
|
629
|
+
const result = await this.handlerAsUtility().getPublicKeysAndPartialAddress(address);
|
|
552
630
|
|
|
553
|
-
return
|
|
631
|
+
// We are going to return a Noir Option struct to represent the possibility of null values. Options are a struct
|
|
632
|
+
// with two fields: `some` (a boolean) and `value` (a field array in this case).
|
|
633
|
+
if (result === undefined) {
|
|
634
|
+
// No data was found so we set `some` to 0 and pad `value` with zeros get the correct return size.
|
|
635
|
+
return toForeignCallResult([toSingle(new Fr(0)), toArray(Array(13).fill(new Fr(0)))]);
|
|
636
|
+
} else {
|
|
637
|
+
// Data was found so we set `some` to 1 and return it along with `value`.
|
|
638
|
+
return toForeignCallResult([
|
|
639
|
+
toSingle(new Fr(1)),
|
|
640
|
+
toArray([...result.publicKeys.toFields(), result.partialAddress]),
|
|
641
|
+
]);
|
|
642
|
+
}
|
|
554
643
|
}
|
|
555
644
|
|
|
556
|
-
|
|
645
|
+
// eslint-disable-next-line camelcase
|
|
646
|
+
async aztec_utl_getKeyValidationRequest(foreignPkMHash: ForeignCallSingle) {
|
|
557
647
|
const pkMHash = fromSingle(foreignPkMHash);
|
|
558
648
|
|
|
559
|
-
const keyValidationRequest = await this.handlerAsUtility().
|
|
649
|
+
const keyValidationRequest = await this.handlerAsUtility().getKeyValidationRequest(pkMHash);
|
|
560
650
|
|
|
561
651
|
return toForeignCallResult(keyValidationRequest.toFields().map(toSingle));
|
|
562
652
|
}
|
|
563
653
|
|
|
564
|
-
|
|
654
|
+
// eslint-disable-next-line camelcase
|
|
655
|
+
aztec_prv_callPrivateFunction(
|
|
565
656
|
_foreignTargetContractAddress: ForeignCallSingle,
|
|
566
657
|
_foreignFunctionSelector: ForeignCallSingle,
|
|
567
658
|
_foreignArgsHash: ForeignCallSingle,
|
|
@@ -573,11 +664,15 @@ export class RPCTranslator {
|
|
|
573
664
|
);
|
|
574
665
|
}
|
|
575
666
|
|
|
576
|
-
|
|
577
|
-
|
|
667
|
+
// eslint-disable-next-line camelcase
|
|
668
|
+
async aztec_utl_getNullifierMembershipWitness(
|
|
669
|
+
foreignBlockHash: ForeignCallSingle,
|
|
670
|
+
foreignNullifier: ForeignCallSingle,
|
|
671
|
+
) {
|
|
672
|
+
const blockHash = blockHashFromSingle(foreignBlockHash);
|
|
578
673
|
const nullifier = fromSingle(foreignNullifier);
|
|
579
674
|
|
|
580
|
-
const witness = await this.handlerAsUtility().
|
|
675
|
+
const witness = await this.handlerAsUtility().getNullifierMembershipWitness(blockHash, nullifier);
|
|
581
676
|
|
|
582
677
|
if (!witness) {
|
|
583
678
|
throw new Error(`Nullifier membership witness not found at block ${blockHash}.`);
|
|
@@ -585,10 +680,11 @@ export class RPCTranslator {
|
|
|
585
680
|
return toForeignCallResult(witness.toNoirRepresentation());
|
|
586
681
|
}
|
|
587
682
|
|
|
588
|
-
|
|
683
|
+
// eslint-disable-next-line camelcase
|
|
684
|
+
async aztec_utl_getAuthWitness(foreignMessageHash: ForeignCallSingle) {
|
|
589
685
|
const messageHash = fromSingle(foreignMessageHash);
|
|
590
686
|
|
|
591
|
-
const authWitness = await this.handlerAsUtility().
|
|
687
|
+
const authWitness = await this.handlerAsUtility().getAuthWitness(messageHash);
|
|
592
688
|
|
|
593
689
|
if (!authWitness) {
|
|
594
690
|
throw new Error(`Auth witness not found for message hash ${messageHash}.`);
|
|
@@ -596,44 +692,35 @@ export class RPCTranslator {
|
|
|
596
692
|
return toForeignCallResult([toArray(authWitness)]);
|
|
597
693
|
}
|
|
598
694
|
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
_foreignCalldataHash: ForeignCallSingle,
|
|
602
|
-
_foreignSideEffectCounter: ForeignCallSingle,
|
|
603
|
-
_foreignIsStaticCall: ForeignCallSingle,
|
|
604
|
-
) {
|
|
605
|
-
throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
|
|
606
|
-
}
|
|
607
|
-
|
|
608
|
-
public privateNotifySetPublicTeardownFunctionCall(
|
|
609
|
-
_foreignTargetContractAddress: ForeignCallSingle,
|
|
610
|
-
_foreignCalldataHash: ForeignCallSingle,
|
|
611
|
-
_foreignSideEffectCounter: ForeignCallSingle,
|
|
612
|
-
_foreignIsStaticCall: ForeignCallSingle,
|
|
613
|
-
) {
|
|
695
|
+
// eslint-disable-next-line camelcase
|
|
696
|
+
public aztec_prv_assertValidPublicCalldata(_foreignCalldataHash: ForeignCallSingle) {
|
|
614
697
|
throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
|
|
615
698
|
}
|
|
616
699
|
|
|
617
|
-
|
|
700
|
+
// eslint-disable-next-line camelcase
|
|
701
|
+
public aztec_prv_notifyRevertiblePhaseStart(_foreignMinRevertibleSideEffectCounter: ForeignCallSingle) {
|
|
618
702
|
throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
|
|
619
703
|
}
|
|
620
704
|
|
|
621
|
-
|
|
705
|
+
// eslint-disable-next-line camelcase
|
|
706
|
+
public async aztec_prv_isExecutionInRevertiblePhase(foreignSideEffectCounter: ForeignCallSingle) {
|
|
622
707
|
const sideEffectCounter = fromSingle(foreignSideEffectCounter).toNumber();
|
|
623
|
-
const isRevertible = await this.handlerAsPrivate().
|
|
708
|
+
const isRevertible = await this.handlerAsPrivate().isExecutionInRevertiblePhase(sideEffectCounter);
|
|
624
709
|
return toForeignCallResult([toSingle(new Fr(isRevertible))]);
|
|
625
710
|
}
|
|
626
711
|
|
|
627
|
-
|
|
628
|
-
|
|
712
|
+
// eslint-disable-next-line camelcase
|
|
713
|
+
aztec_utl_getUtilityContext() {
|
|
714
|
+
const context = this.handlerAsUtility().getUtilityContext();
|
|
629
715
|
|
|
630
716
|
return toForeignCallResult(context.toNoirRepresentation());
|
|
631
717
|
}
|
|
632
718
|
|
|
633
|
-
|
|
719
|
+
// eslint-disable-next-line camelcase
|
|
720
|
+
async aztec_utl_getBlockHeader(foreignBlockNumber: ForeignCallSingle) {
|
|
634
721
|
const blockNumber = BlockNumber(fromSingle(foreignBlockNumber).toNumber());
|
|
635
722
|
|
|
636
|
-
const header = await this.handlerAsUtility().
|
|
723
|
+
const header = await this.handlerAsUtility().getBlockHeader(blockNumber);
|
|
637
724
|
|
|
638
725
|
if (!header) {
|
|
639
726
|
throw new Error(`Block header not found for block ${blockNumber}.`);
|
|
@@ -641,38 +728,49 @@ export class RPCTranslator {
|
|
|
641
728
|
return toForeignCallResult(header.toFields().map(toSingle));
|
|
642
729
|
}
|
|
643
730
|
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
731
|
+
// eslint-disable-next-line camelcase
|
|
732
|
+
async aztec_utl_getNoteHashMembershipWitness(
|
|
733
|
+
foreignAnchorBlockHash: ForeignCallSingle,
|
|
734
|
+
foreignNoteHash: ForeignCallSingle,
|
|
735
|
+
) {
|
|
736
|
+
const blockHash = blockHashFromSingle(foreignAnchorBlockHash);
|
|
737
|
+
const noteHash = fromSingle(foreignNoteHash);
|
|
647
738
|
|
|
648
|
-
const witness = await this.handlerAsUtility().
|
|
739
|
+
const witness = await this.handlerAsUtility().getNoteHashMembershipWitness(blockHash, noteHash);
|
|
649
740
|
|
|
650
741
|
if (!witness) {
|
|
651
|
-
throw new Error(`Note hash ${
|
|
742
|
+
throw new Error(`Note hash ${noteHash} not found in the note hash tree at block ${blockHash.toString()}.`);
|
|
652
743
|
}
|
|
653
744
|
return toForeignCallResult(witness.toNoirRepresentation());
|
|
654
745
|
}
|
|
655
746
|
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
747
|
+
// eslint-disable-next-line camelcase
|
|
748
|
+
async aztec_utl_getBlockHashMembershipWitness(
|
|
749
|
+
foreignAnchorBlockHash: ForeignCallSingle,
|
|
750
|
+
foreignBlockHash: ForeignCallSingle,
|
|
751
|
+
) {
|
|
752
|
+
const anchorBlockHash = blockHashFromSingle(foreignAnchorBlockHash);
|
|
753
|
+
const blockHash = blockHashFromSingle(foreignBlockHash);
|
|
659
754
|
|
|
660
|
-
const witness = await this.handlerAsUtility().
|
|
755
|
+
const witness = await this.handlerAsUtility().getBlockHashMembershipWitness(anchorBlockHash, blockHash);
|
|
661
756
|
|
|
662
757
|
if (!witness) {
|
|
663
|
-
throw new Error(
|
|
758
|
+
throw new Error(
|
|
759
|
+
`Block hash ${blockHash.toString()} not found in the archive tree at anchor block ${anchorBlockHash.toString()}.`,
|
|
760
|
+
);
|
|
664
761
|
}
|
|
665
762
|
return toForeignCallResult(witness.toNoirRepresentation());
|
|
666
763
|
}
|
|
667
764
|
|
|
668
|
-
|
|
765
|
+
// eslint-disable-next-line camelcase
|
|
766
|
+
async aztec_utl_getLowNullifierMembershipWitness(
|
|
669
767
|
foreignBlockHash: ForeignCallSingle,
|
|
670
768
|
foreignNullifier: ForeignCallSingle,
|
|
671
769
|
) {
|
|
672
|
-
const blockHash =
|
|
770
|
+
const blockHash = blockHashFromSingle(foreignBlockHash);
|
|
673
771
|
const nullifier = fromSingle(foreignNullifier);
|
|
674
772
|
|
|
675
|
-
const witness = await this.handlerAsUtility().
|
|
773
|
+
const witness = await this.handlerAsUtility().getLowNullifierMembershipWitness(blockHash, nullifier);
|
|
676
774
|
|
|
677
775
|
if (!witness) {
|
|
678
776
|
throw new Error(`Low nullifier witness not found for nullifier ${nullifier} at block ${blockHash}.`);
|
|
@@ -680,74 +778,167 @@ export class RPCTranslator {
|
|
|
680
778
|
return toForeignCallResult(witness.toNoirRepresentation());
|
|
681
779
|
}
|
|
682
780
|
|
|
683
|
-
|
|
781
|
+
// eslint-disable-next-line camelcase
|
|
782
|
+
async aztec_utl_getPendingTaggedLogs(
|
|
783
|
+
foreignPendingTaggedLogArrayBaseSlot: ForeignCallSingle,
|
|
784
|
+
foreignScope: ForeignCallSingle,
|
|
785
|
+
) {
|
|
684
786
|
const pendingTaggedLogArrayBaseSlot = fromSingle(foreignPendingTaggedLogArrayBaseSlot);
|
|
787
|
+
const scope = AztecAddress.fromField(fromSingle(foreignScope));
|
|
685
788
|
|
|
686
|
-
await this.handlerAsUtility().
|
|
789
|
+
await this.handlerAsUtility().getPendingTaggedLogs(pendingTaggedLogArrayBaseSlot, scope);
|
|
687
790
|
|
|
688
791
|
return toForeignCallResult([]);
|
|
689
792
|
}
|
|
690
793
|
|
|
691
|
-
|
|
794
|
+
// eslint-disable-next-line camelcase
|
|
795
|
+
async aztec_utl_getPendingTaggedLogs_v2(foreignScope: ForeignCallSingle) {
|
|
796
|
+
const scope = AztecAddress.fromField(fromSingle(foreignScope));
|
|
797
|
+
const slot = await this.handlerAsUtility().getPendingTaggedLogsV2(scope);
|
|
798
|
+
return toForeignCallResult([toSingle(slot)]);
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
// eslint-disable-next-line camelcase
|
|
802
|
+
public async aztec_utl_validateAndStoreEnqueuedNotesAndEvents(
|
|
692
803
|
foreignContractAddress: ForeignCallSingle,
|
|
693
804
|
foreignNoteValidationRequestsArrayBaseSlot: ForeignCallSingle,
|
|
694
805
|
foreignEventValidationRequestsArrayBaseSlot: ForeignCallSingle,
|
|
806
|
+
foreignMaxNotePackedLen: ForeignCallSingle,
|
|
807
|
+
foreignMaxEventSerializedLen: ForeignCallSingle,
|
|
808
|
+
foreignScope: ForeignCallSingle,
|
|
695
809
|
) {
|
|
696
810
|
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
697
811
|
const noteValidationRequestsArrayBaseSlot = fromSingle(foreignNoteValidationRequestsArrayBaseSlot);
|
|
698
812
|
const eventValidationRequestsArrayBaseSlot = fromSingle(foreignEventValidationRequestsArrayBaseSlot);
|
|
813
|
+
const maxNotePackedLen = fromSingle(foreignMaxNotePackedLen).toNumber();
|
|
814
|
+
const maxEventSerializedLen = fromSingle(foreignMaxEventSerializedLen).toNumber();
|
|
815
|
+
const scope = AztecAddress.fromField(fromSingle(foreignScope));
|
|
699
816
|
|
|
700
|
-
await this.handlerAsUtility().
|
|
817
|
+
await this.handlerAsUtility().validateAndStoreEnqueuedNotesAndEvents(
|
|
701
818
|
contractAddress,
|
|
702
819
|
noteValidationRequestsArrayBaseSlot,
|
|
703
820
|
eventValidationRequestsArrayBaseSlot,
|
|
821
|
+
maxNotePackedLen,
|
|
822
|
+
maxEventSerializedLen,
|
|
823
|
+
scope,
|
|
824
|
+
);
|
|
825
|
+
|
|
826
|
+
return toForeignCallResult([]);
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
// eslint-disable-next-line camelcase
|
|
830
|
+
public async aztec_utl_validateAndStoreEnqueuedNotesAndEvents_v2(
|
|
831
|
+
foreignNoteValidationRequestsArrayBaseSlot: ForeignCallSingle,
|
|
832
|
+
foreignEventValidationRequestsArrayBaseSlot: ForeignCallSingle,
|
|
833
|
+
foreignMaxNotePackedLen: ForeignCallSingle,
|
|
834
|
+
foreignMaxEventSerializedLen: ForeignCallSingle,
|
|
835
|
+
foreignScope: ForeignCallSingle,
|
|
836
|
+
) {
|
|
837
|
+
const noteValidationRequestsArrayBaseSlot = fromSingle(foreignNoteValidationRequestsArrayBaseSlot);
|
|
838
|
+
const eventValidationRequestsArrayBaseSlot = fromSingle(foreignEventValidationRequestsArrayBaseSlot);
|
|
839
|
+
const maxNotePackedLen = fromSingle(foreignMaxNotePackedLen).toNumber();
|
|
840
|
+
const maxEventSerializedLen = fromSingle(foreignMaxEventSerializedLen).toNumber();
|
|
841
|
+
const scope = AztecAddress.fromField(fromSingle(foreignScope));
|
|
842
|
+
|
|
843
|
+
await this.handlerAsUtility().validateAndStoreEnqueuedNotesAndEventsV2(
|
|
844
|
+
noteValidationRequestsArrayBaseSlot,
|
|
845
|
+
eventValidationRequestsArrayBaseSlot,
|
|
846
|
+
maxNotePackedLen,
|
|
847
|
+
maxEventSerializedLen,
|
|
848
|
+
scope,
|
|
704
849
|
);
|
|
705
850
|
|
|
706
851
|
return toForeignCallResult([]);
|
|
707
852
|
}
|
|
708
853
|
|
|
709
|
-
|
|
854
|
+
// eslint-disable-next-line camelcase
|
|
855
|
+
public async aztec_utl_getLogsByTag(
|
|
710
856
|
foreignContractAddress: ForeignCallSingle,
|
|
711
857
|
foreignLogRetrievalRequestsArrayBaseSlot: ForeignCallSingle,
|
|
712
858
|
foreignLogRetrievalResponsesArrayBaseSlot: ForeignCallSingle,
|
|
859
|
+
foreignScope: ForeignCallSingle,
|
|
713
860
|
) {
|
|
714
861
|
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
715
862
|
const logRetrievalRequestsArrayBaseSlot = fromSingle(foreignLogRetrievalRequestsArrayBaseSlot);
|
|
716
863
|
const logRetrievalResponsesArrayBaseSlot = fromSingle(foreignLogRetrievalResponsesArrayBaseSlot);
|
|
864
|
+
const scope = AztecAddress.fromField(fromSingle(foreignScope));
|
|
717
865
|
|
|
718
|
-
await this.handlerAsUtility().
|
|
866
|
+
await this.handlerAsUtility().getLogsByTag(
|
|
719
867
|
contractAddress,
|
|
720
868
|
logRetrievalRequestsArrayBaseSlot,
|
|
721
869
|
logRetrievalResponsesArrayBaseSlot,
|
|
870
|
+
scope,
|
|
871
|
+
);
|
|
872
|
+
|
|
873
|
+
return toForeignCallResult([]);
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
// eslint-disable-next-line camelcase
|
|
877
|
+
public async aztec_utl_getMessageContextsByTxHash(
|
|
878
|
+
foreignContractAddress: ForeignCallSingle,
|
|
879
|
+
foreignMessageContextRequestsArrayBaseSlot: ForeignCallSingle,
|
|
880
|
+
foreignMessageContextResponsesArrayBaseSlot: ForeignCallSingle,
|
|
881
|
+
foreignScope: ForeignCallSingle,
|
|
882
|
+
) {
|
|
883
|
+
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
884
|
+
const messageContextRequestsArrayBaseSlot = fromSingle(foreignMessageContextRequestsArrayBaseSlot);
|
|
885
|
+
const messageContextResponsesArrayBaseSlot = fromSingle(foreignMessageContextResponsesArrayBaseSlot);
|
|
886
|
+
const scope = AztecAddress.fromField(fromSingle(foreignScope));
|
|
887
|
+
|
|
888
|
+
await this.handlerAsUtility().getMessageContextsByTxHash(
|
|
889
|
+
contractAddress,
|
|
890
|
+
messageContextRequestsArrayBaseSlot,
|
|
891
|
+
messageContextResponsesArrayBaseSlot,
|
|
892
|
+
scope,
|
|
722
893
|
);
|
|
723
894
|
|
|
724
895
|
return toForeignCallResult([]);
|
|
725
896
|
}
|
|
726
897
|
|
|
727
|
-
|
|
898
|
+
// eslint-disable-next-line camelcase
|
|
899
|
+
async aztec_utl_getLogsByTag_v2(foreignRequestArrayBaseSlot: ForeignCallSingle) {
|
|
900
|
+
const requestArrayBaseSlot = fromSingle(foreignRequestArrayBaseSlot);
|
|
901
|
+
const responseSlot = await this.handlerAsUtility().getLogsByTagV2(requestArrayBaseSlot);
|
|
902
|
+
return toForeignCallResult([toSingle(responseSlot)]);
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
// eslint-disable-next-line camelcase
|
|
906
|
+
async aztec_utl_getMessageContextsByTxHash_v2(foreignRequestArrayBaseSlot: ForeignCallSingle) {
|
|
907
|
+
const requestArrayBaseSlot = fromSingle(foreignRequestArrayBaseSlot);
|
|
908
|
+
const responseSlot = await this.handlerAsUtility().getMessageContextsByTxHashV2(requestArrayBaseSlot);
|
|
909
|
+
return toForeignCallResult([toSingle(responseSlot)]);
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
// eslint-disable-next-line camelcase
|
|
913
|
+
aztec_utl_setCapsule(
|
|
728
914
|
foreignContractAddress: ForeignCallSingle,
|
|
729
915
|
foreignSlot: ForeignCallSingle,
|
|
730
916
|
foreignCapsule: ForeignCallArray,
|
|
917
|
+
foreignScope: ForeignCallSingle,
|
|
731
918
|
) {
|
|
732
919
|
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
733
920
|
const slot = fromSingle(foreignSlot);
|
|
734
921
|
const capsule = fromArray(foreignCapsule);
|
|
922
|
+
const scope = AztecAddress.fromField(fromSingle(foreignScope));
|
|
735
923
|
|
|
736
|
-
|
|
924
|
+
this.handlerAsUtility().setCapsule(contractAddress, slot, capsule, scope);
|
|
737
925
|
|
|
738
926
|
return toForeignCallResult([]);
|
|
739
927
|
}
|
|
740
928
|
|
|
741
|
-
|
|
929
|
+
// eslint-disable-next-line camelcase
|
|
930
|
+
async aztec_utl_getCapsule(
|
|
742
931
|
foreignContractAddress: ForeignCallSingle,
|
|
743
932
|
foreignSlot: ForeignCallSingle,
|
|
744
933
|
foreignTSize: ForeignCallSingle,
|
|
934
|
+
foreignScope: ForeignCallSingle,
|
|
745
935
|
) {
|
|
746
936
|
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
747
937
|
const slot = fromSingle(foreignSlot);
|
|
748
938
|
const tSize = fromSingle(foreignTSize).toNumber();
|
|
939
|
+
const scope = AztecAddress.fromField(fromSingle(foreignScope));
|
|
749
940
|
|
|
750
|
-
const values = await this.handlerAsUtility().
|
|
941
|
+
const values = await this.handlerAsUtility().getCapsule(contractAddress, slot, scope);
|
|
751
942
|
|
|
752
943
|
// We are going to return a Noir Option struct to represent the possibility of null values. Options are a struct
|
|
753
944
|
// with two fields: `some` (a boolean) and `value` (a field array in this case).
|
|
@@ -760,36 +951,104 @@ export class RPCTranslator {
|
|
|
760
951
|
}
|
|
761
952
|
}
|
|
762
953
|
|
|
763
|
-
|
|
954
|
+
// eslint-disable-next-line camelcase
|
|
955
|
+
aztec_utl_deleteCapsule(
|
|
956
|
+
foreignContractAddress: ForeignCallSingle,
|
|
957
|
+
foreignSlot: ForeignCallSingle,
|
|
958
|
+
foreignScope: ForeignCallSingle,
|
|
959
|
+
) {
|
|
764
960
|
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
765
961
|
const slot = fromSingle(foreignSlot);
|
|
962
|
+
const scope = AztecAddress.fromField(fromSingle(foreignScope));
|
|
766
963
|
|
|
767
|
-
|
|
964
|
+
this.handlerAsUtility().deleteCapsule(contractAddress, slot, scope);
|
|
768
965
|
|
|
769
966
|
return toForeignCallResult([]);
|
|
770
967
|
}
|
|
771
968
|
|
|
772
|
-
|
|
969
|
+
// eslint-disable-next-line camelcase
|
|
970
|
+
async aztec_utl_copyCapsule(
|
|
773
971
|
foreignContractAddress: ForeignCallSingle,
|
|
774
972
|
foreignSrcSlot: ForeignCallSingle,
|
|
775
973
|
foreignDstSlot: ForeignCallSingle,
|
|
776
974
|
foreignNumEntries: ForeignCallSingle,
|
|
975
|
+
foreignScope: ForeignCallSingle,
|
|
777
976
|
) {
|
|
778
977
|
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
779
978
|
const srcSlot = fromSingle(foreignSrcSlot);
|
|
780
979
|
const dstSlot = fromSingle(foreignDstSlot);
|
|
781
980
|
const numEntries = fromSingle(foreignNumEntries).toNumber();
|
|
981
|
+
const scope = AztecAddress.fromField(fromSingle(foreignScope));
|
|
782
982
|
|
|
783
|
-
await this.handlerAsUtility().
|
|
983
|
+
await this.handlerAsUtility().copyCapsule(contractAddress, srcSlot, dstSlot, numEntries, scope);
|
|
784
984
|
|
|
785
985
|
return toForeignCallResult([]);
|
|
786
986
|
}
|
|
787
987
|
|
|
988
|
+
// eslint-disable-next-line camelcase
|
|
989
|
+
aztec_utl_pushEphemeral(foreignSlot: ForeignCallSingle, foreignElements: ForeignCallArray) {
|
|
990
|
+
const slot = fromSingle(foreignSlot);
|
|
991
|
+
const elements = fromArray(foreignElements);
|
|
992
|
+
const newLen = this.handlerAsUtility().pushEphemeral(slot, elements);
|
|
993
|
+
return toForeignCallResult([toSingle(new Fr(newLen))]);
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
// eslint-disable-next-line camelcase
|
|
997
|
+
aztec_utl_popEphemeral(foreignSlot: ForeignCallSingle) {
|
|
998
|
+
const slot = fromSingle(foreignSlot);
|
|
999
|
+
const element = this.handlerAsUtility().popEphemeral(slot);
|
|
1000
|
+
return toForeignCallResult([toArray(element)]);
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
// eslint-disable-next-line camelcase
|
|
1004
|
+
aztec_utl_getEphemeral(foreignSlot: ForeignCallSingle, foreignIndex: ForeignCallSingle) {
|
|
1005
|
+
const slot = fromSingle(foreignSlot);
|
|
1006
|
+
const index = fromSingle(foreignIndex).toNumber();
|
|
1007
|
+
const element = this.handlerAsUtility().getEphemeral(slot, index);
|
|
1008
|
+
return toForeignCallResult([toArray(element)]);
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
// eslint-disable-next-line camelcase
|
|
1012
|
+
aztec_utl_setEphemeral(
|
|
1013
|
+
foreignSlot: ForeignCallSingle,
|
|
1014
|
+
foreignIndex: ForeignCallSingle,
|
|
1015
|
+
foreignElements: ForeignCallArray,
|
|
1016
|
+
) {
|
|
1017
|
+
const slot = fromSingle(foreignSlot);
|
|
1018
|
+
const index = fromSingle(foreignIndex).toNumber();
|
|
1019
|
+
const elements = fromArray(foreignElements);
|
|
1020
|
+
this.handlerAsUtility().setEphemeral(slot, index, elements);
|
|
1021
|
+
return toForeignCallResult([]);
|
|
1022
|
+
}
|
|
1023
|
+
|
|
1024
|
+
// eslint-disable-next-line camelcase
|
|
1025
|
+
aztec_utl_getEphemeralLen(foreignSlot: ForeignCallSingle) {
|
|
1026
|
+
const slot = fromSingle(foreignSlot);
|
|
1027
|
+
const len = this.handlerAsUtility().getEphemeralLen(slot);
|
|
1028
|
+
return toForeignCallResult([toSingle(new Fr(len))]);
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
// eslint-disable-next-line camelcase
|
|
1032
|
+
aztec_utl_removeEphemeral(foreignSlot: ForeignCallSingle, foreignIndex: ForeignCallSingle) {
|
|
1033
|
+
const slot = fromSingle(foreignSlot);
|
|
1034
|
+
const index = fromSingle(foreignIndex).toNumber();
|
|
1035
|
+
this.handlerAsUtility().removeEphemeral(slot, index);
|
|
1036
|
+
return toForeignCallResult([]);
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
// eslint-disable-next-line camelcase
|
|
1040
|
+
aztec_utl_clearEphemeral(foreignSlot: ForeignCallSingle) {
|
|
1041
|
+
const slot = fromSingle(foreignSlot);
|
|
1042
|
+
this.handlerAsUtility().clearEphemeral(slot);
|
|
1043
|
+
return toForeignCallResult([]);
|
|
1044
|
+
}
|
|
1045
|
+
|
|
788
1046
|
// TODO: I forgot to add a corresponding function here, when I introduced an oracle method to txe_oracle.ts.
|
|
789
1047
|
// 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
|
|
790
1048
|
// to implement this function here. Isn't there a way to programmatically identify that this is missing, given the
|
|
791
1049
|
// existence of a txe_oracle method?
|
|
792
|
-
|
|
1050
|
+
// eslint-disable-next-line camelcase
|
|
1051
|
+
async aztec_utl_decryptAes128(
|
|
793
1052
|
foreignCiphertextBVecStorage: ForeignCallArray,
|
|
794
1053
|
foreignCiphertextLength: ForeignCallSingle,
|
|
795
1054
|
foreignIv: ForeignCallArray,
|
|
@@ -799,18 +1058,27 @@ export class RPCTranslator {
|
|
|
799
1058
|
const iv = fromUintArray(foreignIv, 8);
|
|
800
1059
|
const symKey = fromUintArray(foreignSymKey, 8);
|
|
801
1060
|
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
1061
|
+
// Noir Option<BoundedVec> is encoded as [is_some: Field, storage: Field[], length: Field].
|
|
1062
|
+
try {
|
|
1063
|
+
const plaintextBuffer = await this.handlerAsUtility().decryptAes128(ciphertext, iv, symKey);
|
|
1064
|
+
const [storage, length] = arrayToBoundedVec(
|
|
1065
|
+
bufferToU8Array(plaintextBuffer),
|
|
1066
|
+
foreignCiphertextBVecStorage.length,
|
|
1067
|
+
);
|
|
1068
|
+
return toForeignCallResult([toSingle(new Fr(1)), storage, length]);
|
|
1069
|
+
} catch {
|
|
1070
|
+
const zeroStorage = toArray(Array(foreignCiphertextBVecStorage.length).fill(new Fr(0)));
|
|
1071
|
+
return toForeignCallResult([toSingle(new Fr(0)), zeroStorage, toSingle(new Fr(0))]);
|
|
1072
|
+
}
|
|
807
1073
|
}
|
|
808
1074
|
|
|
809
|
-
|
|
1075
|
+
// eslint-disable-next-line camelcase
|
|
1076
|
+
async aztec_utl_getSharedSecret(
|
|
810
1077
|
foreignAddress: ForeignCallSingle,
|
|
811
1078
|
foreignEphPKField0: ForeignCallSingle,
|
|
812
1079
|
foreignEphPKField1: ForeignCallSingle,
|
|
813
1080
|
foreignEphPKField2: ForeignCallSingle,
|
|
1081
|
+
foreignContractAddress: ForeignCallSingle,
|
|
814
1082
|
) {
|
|
815
1083
|
const address = AztecAddress.fromField(fromSingle(foreignAddress));
|
|
816
1084
|
const ephPK = Point.fromFields([
|
|
@@ -818,45 +1086,73 @@ export class RPCTranslator {
|
|
|
818
1086
|
fromSingle(foreignEphPKField1),
|
|
819
1087
|
fromSingle(foreignEphPKField2),
|
|
820
1088
|
]);
|
|
1089
|
+
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
821
1090
|
|
|
822
|
-
const secret = await this.handlerAsUtility().
|
|
1091
|
+
const secret = await this.handlerAsUtility().getSharedSecret(address, ephPK, contractAddress);
|
|
823
1092
|
|
|
824
|
-
return toForeignCallResult(secret
|
|
1093
|
+
return toForeignCallResult([toSingle(secret)]);
|
|
825
1094
|
}
|
|
826
1095
|
|
|
827
|
-
|
|
828
|
-
|
|
1096
|
+
// eslint-disable-next-line camelcase
|
|
1097
|
+
aztec_utl_setContractSyncCacheInvalid(
|
|
1098
|
+
foreignContractAddress: ForeignCallSingle,
|
|
1099
|
+
foreignScopes: ForeignCallArray,
|
|
1100
|
+
foreignScopeCount: ForeignCallSingle,
|
|
1101
|
+
) {
|
|
1102
|
+
const contractAddress = addressFromSingle(foreignContractAddress);
|
|
1103
|
+
const count = fromSingle(foreignScopeCount).toNumber();
|
|
1104
|
+
const scopes = fromArray(foreignScopes)
|
|
1105
|
+
.slice(0, count)
|
|
1106
|
+
.map(f => new AztecAddress(f));
|
|
1107
|
+
|
|
1108
|
+
this.handlerAsUtility().setContractSyncCacheInvalid(contractAddress, scopes);
|
|
1109
|
+
|
|
1110
|
+
return Promise.resolve(toForeignCallResult([]));
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1113
|
+
// eslint-disable-next-line camelcase
|
|
1114
|
+
aztec_utl_emitOffchainEffect(foreignData: ForeignCallArray) {
|
|
1115
|
+
// Record the raw payload against the currently-executing top-level call. The Noir side
|
|
1116
|
+
// (via `env.offchain_messages()`) is responsible for decoding the protocol-reserved prefix
|
|
1117
|
+
// (`OFFCHAIN_MESSAGE_IDENTIFIER`, recipient) and turning each payload into an `OffchainMessage` struct suitable
|
|
1118
|
+
// for `offchain_receive`.
|
|
1119
|
+
this.stateHandler.recordOffchainEffect(fromArray(foreignData));
|
|
1120
|
+
return Promise.resolve(toForeignCallResult([]));
|
|
829
1121
|
}
|
|
830
1122
|
|
|
831
1123
|
// AVM opcodes
|
|
832
1124
|
|
|
833
|
-
|
|
1125
|
+
// eslint-disable-next-line camelcase
|
|
1126
|
+
aztec_avm_emitPublicLog(_foreignMessage: ForeignCallArray) {
|
|
834
1127
|
// TODO(#8811): Implement
|
|
835
1128
|
return toForeignCallResult([]);
|
|
836
1129
|
}
|
|
837
1130
|
|
|
838
|
-
|
|
1131
|
+
// eslint-disable-next-line camelcase
|
|
1132
|
+
async aztec_avm_storageRead(foreignSlot: ForeignCallSingle, foreignContractAddress: ForeignCallSingle) {
|
|
839
1133
|
const slot = fromSingle(foreignSlot);
|
|
840
1134
|
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
841
1135
|
|
|
842
|
-
const value = (await this.handlerAsAvm().
|
|
1136
|
+
const value = (await this.handlerAsAvm().storageRead(slot, contractAddress)).value;
|
|
843
1137
|
|
|
844
1138
|
return toForeignCallResult([toSingle(new Fr(value))]);
|
|
845
1139
|
}
|
|
846
1140
|
|
|
847
|
-
|
|
1141
|
+
// eslint-disable-next-line camelcase
|
|
1142
|
+
async aztec_avm_storageWrite(foreignSlot: ForeignCallSingle, foreignValue: ForeignCallSingle) {
|
|
848
1143
|
const slot = fromSingle(foreignSlot);
|
|
849
1144
|
const value = fromSingle(foreignValue);
|
|
850
1145
|
|
|
851
|
-
await this.handlerAsAvm().
|
|
1146
|
+
await this.handlerAsAvm().storageWrite(slot, value);
|
|
852
1147
|
|
|
853
1148
|
return toForeignCallResult([]);
|
|
854
1149
|
}
|
|
855
1150
|
|
|
856
|
-
|
|
1151
|
+
// eslint-disable-next-line camelcase
|
|
1152
|
+
async aztec_avm_getContractInstanceDeployer(foreignAddress: ForeignCallSingle) {
|
|
857
1153
|
const address = addressFromSingle(foreignAddress);
|
|
858
1154
|
|
|
859
|
-
const instance = await this.handlerAsUtility().
|
|
1155
|
+
const instance = await this.handlerAsUtility().getContractInstance(address);
|
|
860
1156
|
|
|
861
1157
|
return toForeignCallResult([
|
|
862
1158
|
toSingle(instance.deployer),
|
|
@@ -865,10 +1161,11 @@ export class RPCTranslator {
|
|
|
865
1161
|
]);
|
|
866
1162
|
}
|
|
867
1163
|
|
|
868
|
-
|
|
1164
|
+
// eslint-disable-next-line camelcase
|
|
1165
|
+
async aztec_avm_getContractInstanceClassId(foreignAddress: ForeignCallSingle) {
|
|
869
1166
|
const address = addressFromSingle(foreignAddress);
|
|
870
1167
|
|
|
871
|
-
const instance = await this.handlerAsUtility().
|
|
1168
|
+
const instance = await this.handlerAsUtility().getContractInstance(address);
|
|
872
1169
|
|
|
873
1170
|
return toForeignCallResult([
|
|
874
1171
|
toSingle(instance.currentContractClassId),
|
|
@@ -877,10 +1174,11 @@ export class RPCTranslator {
|
|
|
877
1174
|
]);
|
|
878
1175
|
}
|
|
879
1176
|
|
|
880
|
-
|
|
1177
|
+
// eslint-disable-next-line camelcase
|
|
1178
|
+
async aztec_avm_getContractInstanceInitializationHash(foreignAddress: ForeignCallSingle) {
|
|
881
1179
|
const address = addressFromSingle(foreignAddress);
|
|
882
1180
|
|
|
883
|
-
const instance = await this.handlerAsUtility().
|
|
1181
|
+
const instance = await this.handlerAsUtility().getContractInstance(address);
|
|
884
1182
|
|
|
885
1183
|
return toForeignCallResult([
|
|
886
1184
|
toSingle(instance.initializationHash),
|
|
@@ -889,86 +1187,98 @@ export class RPCTranslator {
|
|
|
889
1187
|
]);
|
|
890
1188
|
}
|
|
891
1189
|
|
|
892
|
-
|
|
893
|
-
|
|
1190
|
+
// eslint-disable-next-line camelcase
|
|
1191
|
+
async aztec_avm_sender() {
|
|
1192
|
+
const sender = await this.handlerAsAvm().sender();
|
|
894
1193
|
|
|
895
1194
|
return toForeignCallResult([toSingle(sender)]);
|
|
896
1195
|
}
|
|
897
1196
|
|
|
898
|
-
|
|
1197
|
+
// eslint-disable-next-line camelcase
|
|
1198
|
+
async aztec_avm_emitNullifier(foreignNullifier: ForeignCallSingle) {
|
|
899
1199
|
const nullifier = fromSingle(foreignNullifier);
|
|
900
1200
|
|
|
901
|
-
await this.handlerAsAvm().
|
|
1201
|
+
await this.handlerAsAvm().emitNullifier(nullifier);
|
|
902
1202
|
|
|
903
1203
|
return toForeignCallResult([]);
|
|
904
1204
|
}
|
|
905
1205
|
|
|
906
|
-
|
|
1206
|
+
// eslint-disable-next-line camelcase
|
|
1207
|
+
async aztec_avm_emitNoteHash(foreignNoteHash: ForeignCallSingle) {
|
|
907
1208
|
const noteHash = fromSingle(foreignNoteHash);
|
|
908
1209
|
|
|
909
|
-
await this.handlerAsAvm().
|
|
1210
|
+
await this.handlerAsAvm().emitNoteHash(noteHash);
|
|
910
1211
|
|
|
911
1212
|
return toForeignCallResult([]);
|
|
912
1213
|
}
|
|
913
1214
|
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
const
|
|
1215
|
+
// eslint-disable-next-line camelcase
|
|
1216
|
+
async aztec_avm_nullifierExists(foreignSiloedNullifier: ForeignCallSingle) {
|
|
1217
|
+
const siloedNullifier = fromSingle(foreignSiloedNullifier);
|
|
917
1218
|
|
|
918
|
-
const exists = await this.handlerAsAvm().
|
|
1219
|
+
const exists = await this.handlerAsAvm().nullifierExists(siloedNullifier);
|
|
919
1220
|
|
|
920
1221
|
return toForeignCallResult([toSingle(new Fr(exists))]);
|
|
921
1222
|
}
|
|
922
1223
|
|
|
923
|
-
|
|
924
|
-
|
|
1224
|
+
// eslint-disable-next-line camelcase
|
|
1225
|
+
async aztec_avm_address() {
|
|
1226
|
+
const contractAddress = await this.handlerAsAvm().address();
|
|
925
1227
|
|
|
926
1228
|
return toForeignCallResult([toSingle(contractAddress.toField())]);
|
|
927
1229
|
}
|
|
928
1230
|
|
|
929
|
-
|
|
930
|
-
|
|
1231
|
+
// eslint-disable-next-line camelcase
|
|
1232
|
+
async aztec_avm_blockNumber() {
|
|
1233
|
+
const blockNumber = await this.handlerAsAvm().blockNumber();
|
|
931
1234
|
|
|
932
1235
|
return toForeignCallResult([toSingle(new Fr(blockNumber))]);
|
|
933
1236
|
}
|
|
934
1237
|
|
|
935
|
-
|
|
936
|
-
|
|
1238
|
+
// eslint-disable-next-line camelcase
|
|
1239
|
+
async aztec_avm_timestamp() {
|
|
1240
|
+
const timestamp = await this.handlerAsAvm().timestamp();
|
|
937
1241
|
|
|
938
1242
|
return toForeignCallResult([toSingle(new Fr(timestamp))]);
|
|
939
1243
|
}
|
|
940
1244
|
|
|
941
|
-
|
|
942
|
-
|
|
1245
|
+
// eslint-disable-next-line camelcase
|
|
1246
|
+
async aztec_avm_isStaticCall() {
|
|
1247
|
+
const isStaticCall = await this.handlerAsAvm().isStaticCall();
|
|
943
1248
|
|
|
944
1249
|
return toForeignCallResult([toSingle(new Fr(isStaticCall ? 1 : 0))]);
|
|
945
1250
|
}
|
|
946
1251
|
|
|
947
|
-
|
|
948
|
-
|
|
1252
|
+
// eslint-disable-next-line camelcase
|
|
1253
|
+
async aztec_avm_chainId() {
|
|
1254
|
+
const chainId = await this.handlerAsAvm().chainId();
|
|
949
1255
|
|
|
950
1256
|
return toForeignCallResult([toSingle(chainId)]);
|
|
951
1257
|
}
|
|
952
1258
|
|
|
953
|
-
|
|
954
|
-
|
|
1259
|
+
// eslint-disable-next-line camelcase
|
|
1260
|
+
async aztec_avm_version() {
|
|
1261
|
+
const version = await this.handlerAsAvm().version();
|
|
955
1262
|
|
|
956
1263
|
return toForeignCallResult([toSingle(version)]);
|
|
957
1264
|
}
|
|
958
1265
|
|
|
959
|
-
|
|
1266
|
+
// eslint-disable-next-line camelcase
|
|
1267
|
+
aztec_avm_returndataSize() {
|
|
960
1268
|
throw new Error(
|
|
961
1269
|
'Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead',
|
|
962
1270
|
);
|
|
963
1271
|
}
|
|
964
1272
|
|
|
965
|
-
|
|
1273
|
+
// eslint-disable-next-line camelcase
|
|
1274
|
+
aztec_avm_returndataCopy(_foreignRdOffset: ForeignCallSingle, _foreignCopySize: ForeignCallSingle) {
|
|
966
1275
|
throw new Error(
|
|
967
1276
|
'Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead',
|
|
968
1277
|
);
|
|
969
1278
|
}
|
|
970
1279
|
|
|
971
|
-
|
|
1280
|
+
// eslint-disable-next-line camelcase
|
|
1281
|
+
aztec_avm_call(
|
|
972
1282
|
_foreignL2Gas: ForeignCallSingle,
|
|
973
1283
|
_foreignDaGas: ForeignCallSingle,
|
|
974
1284
|
_foreignAddress: ForeignCallSingle,
|
|
@@ -980,7 +1290,8 @@ export class RPCTranslator {
|
|
|
980
1290
|
);
|
|
981
1291
|
}
|
|
982
1292
|
|
|
983
|
-
|
|
1293
|
+
// eslint-disable-next-line camelcase
|
|
1294
|
+
aztec_avm_staticCall(
|
|
984
1295
|
_foreignL2Gas: ForeignCallSingle,
|
|
985
1296
|
_foreignDaGas: ForeignCallSingle,
|
|
986
1297
|
_foreignAddress: ForeignCallSingle,
|
|
@@ -992,13 +1303,15 @@ export class RPCTranslator {
|
|
|
992
1303
|
);
|
|
993
1304
|
}
|
|
994
1305
|
|
|
995
|
-
|
|
1306
|
+
// eslint-disable-next-line camelcase
|
|
1307
|
+
aztec_avm_successCopy() {
|
|
996
1308
|
throw new Error(
|
|
997
1309
|
'Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead',
|
|
998
1310
|
);
|
|
999
1311
|
}
|
|
1000
1312
|
|
|
1001
|
-
|
|
1313
|
+
// eslint-disable-next-line camelcase
|
|
1314
|
+
async aztec_txe_privateCallNewFlow(
|
|
1002
1315
|
foreignFrom: ForeignCallSingle,
|
|
1003
1316
|
foreignTargetContractAddress: ForeignCallSingle,
|
|
1004
1317
|
foreignFunctionSelector: ForeignCallSingle,
|
|
@@ -1013,19 +1326,43 @@ export class RPCTranslator {
|
|
|
1013
1326
|
const argsHash = fromSingle(foreignArgsHash);
|
|
1014
1327
|
const isStaticCall = fromSingle(foreignIsStaticCall).toBool();
|
|
1015
1328
|
|
|
1016
|
-
const returnValues = await this.
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1329
|
+
const returnValues = await this.stateHandler.withTopLevelCallTracking(async () => {
|
|
1330
|
+
const { returnValues, offchainEffects } = await this.handlerAsTxe().privateCallNewFlow(
|
|
1331
|
+
from,
|
|
1332
|
+
targetContractAddress,
|
|
1333
|
+
functionSelector,
|
|
1334
|
+
args,
|
|
1335
|
+
argsHash,
|
|
1336
|
+
isStaticCall,
|
|
1337
|
+
this.stateHandler.getCurrentJob(),
|
|
1338
|
+
);
|
|
1339
|
+
|
|
1340
|
+
// Private execution collects offchain effects inside PXE's PrivateExecutionOracle rather than
|
|
1341
|
+
// round-tripping them through `aztec_utl_emitOffchainEffect`, so the session buffer is empty
|
|
1342
|
+
// at this point. Drain the effects from the execution tree into the session buffer so the
|
|
1343
|
+
// next `env.offchain_messages()` call in the test sees them.
|
|
1344
|
+
for (const data of offchainEffects) {
|
|
1345
|
+
this.stateHandler.recordOffchainEffect(data);
|
|
1346
|
+
}
|
|
1347
|
+
|
|
1348
|
+
// TODO(F-335): Avoid doing the following call here.
|
|
1349
|
+
await this.stateHandler.cycleJob();
|
|
1350
|
+
|
|
1351
|
+
if (isStaticCall) {
|
|
1352
|
+
// Static calls revert their checkpoint and mine no block, so there is no tx hash to tag
|
|
1353
|
+
// offchain effects with. Querying `getLastTxEffects()` here would return an unrelated
|
|
1354
|
+
// predecessor tx.
|
|
1355
|
+
return { result: returnValues };
|
|
1356
|
+
}
|
|
1357
|
+
const { txHash } = await this.handlerAsTxe().getLastTxEffects();
|
|
1358
|
+
return { result: returnValues, txHash: txHash.hash };
|
|
1359
|
+
});
|
|
1024
1360
|
|
|
1025
1361
|
return toForeignCallResult([toArray(returnValues)]);
|
|
1026
1362
|
}
|
|
1027
1363
|
|
|
1028
|
-
|
|
1364
|
+
// eslint-disable-next-line camelcase
|
|
1365
|
+
async aztec_txe_executeUtilityFunction(
|
|
1029
1366
|
foreignTargetContractAddress: ForeignCallSingle,
|
|
1030
1367
|
foreignFunctionSelector: ForeignCallSingle,
|
|
1031
1368
|
foreignArgs: ForeignCallArray,
|
|
@@ -1034,16 +1371,25 @@ export class RPCTranslator {
|
|
|
1034
1371
|
const functionSelector = FunctionSelector.fromField(fromSingle(foreignFunctionSelector));
|
|
1035
1372
|
const args = fromArray(foreignArgs);
|
|
1036
1373
|
|
|
1037
|
-
const returnValues = await this.
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1374
|
+
const returnValues = await this.stateHandler.withTopLevelCallTracking(async () => {
|
|
1375
|
+
const returnValues = await this.handlerAsTxe().executeUtilityFunction(
|
|
1376
|
+
targetContractAddress,
|
|
1377
|
+
functionSelector,
|
|
1378
|
+
args,
|
|
1379
|
+
this.stateHandler.getCurrentJob(),
|
|
1380
|
+
);
|
|
1381
|
+
|
|
1382
|
+
// TODO(F-335): Avoid doing the following call here.
|
|
1383
|
+
await this.stateHandler.cycleJob();
|
|
1384
|
+
|
|
1385
|
+
return { result: returnValues };
|
|
1386
|
+
});
|
|
1042
1387
|
|
|
1043
1388
|
return toForeignCallResult([toArray(returnValues)]);
|
|
1044
1389
|
}
|
|
1045
1390
|
|
|
1046
|
-
|
|
1391
|
+
// eslint-disable-next-line camelcase
|
|
1392
|
+
async aztec_txe_publicCallNewFlow(
|
|
1047
1393
|
foreignFrom: ForeignCallSingle,
|
|
1048
1394
|
foreignAddress: ForeignCallSingle,
|
|
1049
1395
|
foreignCalldata: ForeignCallArray,
|
|
@@ -1054,13 +1400,26 @@ export class RPCTranslator {
|
|
|
1054
1400
|
const calldata = fromArray(foreignCalldata);
|
|
1055
1401
|
const isStaticCall = fromSingle(foreignIsStaticCall).toBool();
|
|
1056
1402
|
|
|
1057
|
-
const returnValues = await this.
|
|
1403
|
+
const returnValues = await this.stateHandler.withTopLevelCallTracking(async () => {
|
|
1404
|
+
const returnValues = await this.handlerAsTxe().publicCallNewFlow(from, address, calldata, isStaticCall);
|
|
1405
|
+
|
|
1406
|
+
// TODO(F-335): Avoid doing the following call here.
|
|
1407
|
+
await this.stateHandler.cycleJob();
|
|
1408
|
+
|
|
1409
|
+
if (isStaticCall) {
|
|
1410
|
+
// See equivalent branch in `aztec_txe_privateCallNewFlow`.
|
|
1411
|
+
return { result: returnValues };
|
|
1412
|
+
}
|
|
1413
|
+
const { txHash } = await this.handlerAsTxe().getLastTxEffects();
|
|
1414
|
+
return { result: returnValues, txHash: txHash.hash };
|
|
1415
|
+
});
|
|
1058
1416
|
|
|
1059
1417
|
return toForeignCallResult([toArray(returnValues)]);
|
|
1060
1418
|
}
|
|
1061
1419
|
|
|
1062
|
-
|
|
1063
|
-
|
|
1420
|
+
// eslint-disable-next-line camelcase
|
|
1421
|
+
async aztec_prv_getSenderForTags() {
|
|
1422
|
+
const sender = await this.handlerAsPrivate().getSenderForTags();
|
|
1064
1423
|
|
|
1065
1424
|
// Return a Noir Option struct with `some` and `value` fields
|
|
1066
1425
|
if (sender === undefined) {
|
|
@@ -1072,19 +1431,21 @@ export class RPCTranslator {
|
|
|
1072
1431
|
}
|
|
1073
1432
|
}
|
|
1074
1433
|
|
|
1075
|
-
|
|
1434
|
+
// eslint-disable-next-line camelcase
|
|
1435
|
+
async aztec_prv_setSenderForTags(foreignSenderForTags: ForeignCallSingle) {
|
|
1076
1436
|
const senderForTags = AztecAddress.fromField(fromSingle(foreignSenderForTags));
|
|
1077
1437
|
|
|
1078
|
-
await this.handlerAsPrivate().
|
|
1438
|
+
await this.handlerAsPrivate().setSenderForTags(senderForTags);
|
|
1079
1439
|
|
|
1080
1440
|
return toForeignCallResult([]);
|
|
1081
1441
|
}
|
|
1082
1442
|
|
|
1083
|
-
|
|
1443
|
+
// eslint-disable-next-line camelcase
|
|
1444
|
+
async aztec_prv_getNextAppTagAsSender(foreignSender: ForeignCallSingle, foreignRecipient: ForeignCallSingle) {
|
|
1084
1445
|
const sender = AztecAddress.fromField(fromSingle(foreignSender));
|
|
1085
1446
|
const recipient = AztecAddress.fromField(fromSingle(foreignRecipient));
|
|
1086
1447
|
|
|
1087
|
-
const nextAppTag = await this.handlerAsPrivate().
|
|
1448
|
+
const nextAppTag = await this.handlerAsPrivate().getNextAppTagAsSender(sender, recipient);
|
|
1088
1449
|
|
|
1089
1450
|
return toForeignCallResult([toSingle(nextAppTag.value)]);
|
|
1090
1451
|
}
|