@aztec/txe 0.0.1-commit.5daedc8 → 0.0.1-commit.6201a7b05
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 +91 -56
- package/dest/oracle/interfaces.d.ts +36 -29
- package/dest/oracle/interfaces.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.d.ts +16 -16
- package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.js +20 -22
- package/dest/oracle/txe_oracle_top_level_context.d.ts +44 -27
- package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_top_level_context.js +245 -109
- package/dest/rpc_translator.d.ts +136 -78
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +545 -178
- package/dest/state_machine/archiver.d.ts +21 -52
- package/dest/state_machine/archiver.d.ts.map +1 -1
- package/dest/state_machine/archiver.js +67 -99
- package/dest/state_machine/dummy_p2p_client.d.ts +21 -15
- package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
- package/dest/state_machine/dummy_p2p_client.js +45 -25
- package/dest/state_machine/global_variable_builder.d.ts +11 -5
- package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
- package/dest/state_machine/global_variable_builder.js +21 -3
- package/dest/state_machine/index.d.ts +9 -7
- package/dest/state_machine/index.d.ts.map +1 -1
- package/dest/state_machine/index.js +45 -24
- package/dest/state_machine/mock_epoch_cache.d.ts +26 -8
- package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
- package/dest/state_machine/mock_epoch_cache.js +49 -9
- package/dest/state_machine/synchronizer.d.ts +6 -5
- package/dest/state_machine/synchronizer.d.ts.map +1 -1
- package/dest/state_machine/synchronizer.js +8 -7
- package/dest/txe_session.d.ts +71 -15
- package/dest/txe_session.d.ts.map +1 -1
- package/dest/txe_session.js +228 -57
- package/dest/util/encoding.d.ts +688 -19
- package/dest/util/encoding.d.ts.map +1 -1
- package/dest/util/encoding.js +5 -1
- 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 +8 -8
- package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
- package/dest/util/txe_public_contract_data_source.js +13 -32
- package/dest/utils/block_creation.d.ts +21 -6
- package/dest/utils/block_creation.d.ts.map +1 -1
- package/dest/utils/block_creation.js +38 -4
- package/dest/utils/tx_effect_creation.d.ts +3 -3
- package/dest/utils/tx_effect_creation.d.ts.map +1 -1
- package/dest/utils/tx_effect_creation.js +4 -7
- package/package.json +18 -18
- package/src/constants.ts +3 -0
- package/src/index.ts +103 -63
- package/src/oracle/interfaces.ts +37 -33
- package/src/oracle/txe_oracle_public_context.ts +21 -28
- package/src/oracle/txe_oracle_top_level_context.ts +291 -151
- package/src/rpc_translator.ts +645 -206
- package/src/state_machine/archiver.ts +63 -117
- package/src/state_machine/dummy_p2p_client.ts +62 -33
- package/src/state_machine/global_variable_builder.ts +38 -6
- package/src/state_machine/index.ts +68 -22
- package/src/state_machine/mock_epoch_cache.ts +61 -14
- package/src/state_machine/synchronizer.ts +9 -8
- package/src/txe_session.ts +351 -105
- package/src/util/encoding.ts +6 -1
- package/src/util/{txe_account_data_provider.ts → txe_account_store.ts} +1 -1
- package/src/util/txe_public_contract_data_source.ts +20 -47
- package/src/utils/block_creation.ts +49 -15
- package/src/utils/tx_effect_creation.ts +5 -12
- 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
|
@@ -1,15 +1,15 @@
|
|
|
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
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
4
5
|
import {
|
|
5
6
|
type IMiscOracle,
|
|
6
7
|
type IPrivateExecutionOracle,
|
|
7
8
|
type IUtilityExecutionOracle,
|
|
8
|
-
|
|
9
|
+
packAsHintedNote,
|
|
9
10
|
} from '@aztec/pxe/simulator';
|
|
10
|
-
import { type ContractArtifact, FunctionSelector, NoteSelector } from '@aztec/stdlib/abi';
|
|
11
|
+
import { type ContractArtifact, EventSelector, FunctionSelector, NoteSelector } from '@aztec/stdlib/abi';
|
|
11
12
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
12
|
-
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
13
13
|
|
|
14
14
|
import type { IAvmExecutionOracle, ITxeExecutionOracle } from './oracle/interfaces.js';
|
|
15
15
|
import type { TXESessionStateHandler } from './txe_session.js';
|
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
addressFromSingle,
|
|
20
20
|
arrayOfArraysToBoundedVecOfArrays,
|
|
21
21
|
arrayToBoundedVec,
|
|
22
|
+
blockHashFromSingle,
|
|
22
23
|
bufferToU8Array,
|
|
23
24
|
fromArray,
|
|
24
25
|
fromSingle,
|
|
@@ -29,6 +30,9 @@ import {
|
|
|
29
30
|
toSingle,
|
|
30
31
|
} from './util/encoding.js';
|
|
31
32
|
|
|
33
|
+
const MAX_EVENT_LEN = 10; // This is MAX_MESSAGE_CONTENT_LEN - PRIVATE_EVENT_MSG_PLAINTEXT_RESERVED_FIELDS_LEN
|
|
34
|
+
const MAX_PRIVATE_EVENTS_PER_TXE_QUERY = 5;
|
|
35
|
+
|
|
32
36
|
export class UnavailableOracleError extends Error {
|
|
33
37
|
constructor(oracleName: string) {
|
|
34
38
|
super(`${oracleName} oracles not available with the current handler`);
|
|
@@ -100,13 +104,15 @@ export class RPCTranslator {
|
|
|
100
104
|
|
|
101
105
|
// TXE session state transition functions - these get handled by the state handler
|
|
102
106
|
|
|
103
|
-
|
|
107
|
+
// eslint-disable-next-line camelcase
|
|
108
|
+
async aztec_txe_setTopLevelTXEContext() {
|
|
104
109
|
await this.stateHandler.enterTopLevelState();
|
|
105
110
|
|
|
106
111
|
return toForeignCallResult([]);
|
|
107
112
|
}
|
|
108
113
|
|
|
109
|
-
|
|
114
|
+
// eslint-disable-next-line camelcase
|
|
115
|
+
async aztec_txe_setPrivateTXEContext(
|
|
110
116
|
foreignContractAddressIsSome: ForeignCallSingle,
|
|
111
117
|
foreignContractAddressValue: ForeignCallSingle,
|
|
112
118
|
foreignAnchorBlockNumberIsSome: ForeignCallSingle,
|
|
@@ -117,7 +123,7 @@ export class RPCTranslator {
|
|
|
117
123
|
: undefined;
|
|
118
124
|
|
|
119
125
|
const anchorBlockNumber = fromSingle(foreignAnchorBlockNumberIsSome).toBool()
|
|
120
|
-
? fromSingle(foreignAnchorBlockNumberValue).toNumber()
|
|
126
|
+
? BlockNumber(fromSingle(foreignAnchorBlockNumberValue).toNumber())
|
|
121
127
|
: undefined;
|
|
122
128
|
|
|
123
129
|
const privateContextInputs = await this.stateHandler.enterPrivateState(contractAddress, anchorBlockNumber);
|
|
@@ -125,7 +131,8 @@ export class RPCTranslator {
|
|
|
125
131
|
return toForeignCallResult(privateContextInputs.toFields().map(toSingle));
|
|
126
132
|
}
|
|
127
133
|
|
|
128
|
-
|
|
134
|
+
// eslint-disable-next-line camelcase
|
|
135
|
+
async aztec_txe_setPublicTXEContext(
|
|
129
136
|
foreignContractAddressIsSome: ForeignCallSingle,
|
|
130
137
|
foreignContractAddressValue: ForeignCallSingle,
|
|
131
138
|
) {
|
|
@@ -138,7 +145,8 @@ export class RPCTranslator {
|
|
|
138
145
|
return toForeignCallResult([]);
|
|
139
146
|
}
|
|
140
147
|
|
|
141
|
-
|
|
148
|
+
// eslint-disable-next-line camelcase
|
|
149
|
+
async aztec_txe_setUtilityTXEContext(
|
|
142
150
|
foreignContractAddressIsSome: ForeignCallSingle,
|
|
143
151
|
foreignContractAddressValue: ForeignCallSingle,
|
|
144
152
|
) {
|
|
@@ -155,38 +163,54 @@ export class RPCTranslator {
|
|
|
155
163
|
|
|
156
164
|
// TXE-specific oracles
|
|
157
165
|
|
|
158
|
-
|
|
159
|
-
|
|
166
|
+
// eslint-disable-next-line camelcase
|
|
167
|
+
aztec_txe_getDefaultAddress() {
|
|
168
|
+
const defaultAddress = this.handlerAsTxe().getDefaultAddress();
|
|
169
|
+
|
|
170
|
+
return toForeignCallResult([toSingle(defaultAddress)]);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// eslint-disable-next-line camelcase
|
|
174
|
+
async aztec_txe_getNextBlockNumber() {
|
|
175
|
+
const nextBlockNumber = await this.handlerAsTxe().getNextBlockNumber();
|
|
160
176
|
|
|
161
177
|
return toForeignCallResult([toSingle(nextBlockNumber)]);
|
|
162
178
|
}
|
|
163
179
|
|
|
164
|
-
|
|
165
|
-
|
|
180
|
+
// eslint-disable-next-line camelcase
|
|
181
|
+
async aztec_txe_getNextBlockTimestamp() {
|
|
182
|
+
const nextBlockTimestamp = await this.handlerAsTxe().getNextBlockTimestamp();
|
|
166
183
|
|
|
167
184
|
return toForeignCallResult([toSingle(nextBlockTimestamp)]);
|
|
168
185
|
}
|
|
169
186
|
|
|
170
|
-
|
|
187
|
+
// eslint-disable-next-line camelcase
|
|
188
|
+
async aztec_txe_advanceBlocksBy(foreignBlocks: ForeignCallSingle) {
|
|
171
189
|
const blocks = fromSingle(foreignBlocks).toNumber();
|
|
172
190
|
|
|
173
|
-
await this.handlerAsTxe().
|
|
191
|
+
await this.handlerAsTxe().advanceBlocksBy(blocks);
|
|
174
192
|
|
|
175
193
|
return toForeignCallResult([]);
|
|
176
194
|
}
|
|
177
195
|
|
|
178
|
-
|
|
196
|
+
// eslint-disable-next-line camelcase
|
|
197
|
+
aztec_txe_advanceTimestampBy(foreignDuration: ForeignCallSingle) {
|
|
179
198
|
const duration = fromSingle(foreignDuration).toBigInt();
|
|
180
199
|
|
|
181
|
-
this.handlerAsTxe().
|
|
200
|
+
this.handlerAsTxe().advanceTimestampBy(duration);
|
|
182
201
|
|
|
183
202
|
return toForeignCallResult([]);
|
|
184
203
|
}
|
|
185
204
|
|
|
186
|
-
|
|
205
|
+
// eslint-disable-next-line camelcase
|
|
206
|
+
async aztec_txe_deploy(
|
|
207
|
+
artifact: ContractArtifact,
|
|
208
|
+
instance: ContractInstanceWithAddress,
|
|
209
|
+
foreignSecret: ForeignCallSingle,
|
|
210
|
+
) {
|
|
187
211
|
const secret = fromSingle(foreignSecret);
|
|
188
212
|
|
|
189
|
-
await this.handlerAsTxe().
|
|
213
|
+
await this.handlerAsTxe().deploy(artifact, instance, secret);
|
|
190
214
|
|
|
191
215
|
return toForeignCallResult([
|
|
192
216
|
toArray([
|
|
@@ -199,10 +223,11 @@ export class RPCTranslator {
|
|
|
199
223
|
]);
|
|
200
224
|
}
|
|
201
225
|
|
|
202
|
-
|
|
226
|
+
// eslint-disable-next-line camelcase
|
|
227
|
+
async aztec_txe_createAccount(foreignSecret: ForeignCallSingle) {
|
|
203
228
|
const secret = fromSingle(foreignSecret);
|
|
204
229
|
|
|
205
|
-
const completeAddress = await this.handlerAsTxe().
|
|
230
|
+
const completeAddress = await this.handlerAsTxe().createAccount(secret);
|
|
206
231
|
|
|
207
232
|
return toForeignCallResult([
|
|
208
233
|
toSingle(completeAddress.address),
|
|
@@ -210,14 +235,15 @@ export class RPCTranslator {
|
|
|
210
235
|
]);
|
|
211
236
|
}
|
|
212
237
|
|
|
213
|
-
|
|
238
|
+
// eslint-disable-next-line camelcase
|
|
239
|
+
async aztec_txe_addAccount(
|
|
214
240
|
artifact: ContractArtifact,
|
|
215
241
|
instance: ContractInstanceWithAddress,
|
|
216
242
|
foreignSecret: ForeignCallSingle,
|
|
217
243
|
) {
|
|
218
244
|
const secret = fromSingle(foreignSecret);
|
|
219
245
|
|
|
220
|
-
const completeAddress = await this.handlerAsTxe().
|
|
246
|
+
const completeAddress = await this.handlerAsTxe().addAccount(artifact, instance, secret);
|
|
221
247
|
|
|
222
248
|
return toForeignCallResult([
|
|
223
249
|
toSingle(completeAddress.address),
|
|
@@ -225,39 +251,45 @@ export class RPCTranslator {
|
|
|
225
251
|
]);
|
|
226
252
|
}
|
|
227
253
|
|
|
228
|
-
|
|
254
|
+
// eslint-disable-next-line camelcase
|
|
255
|
+
async aztec_txe_addAuthWitness(foreignAddress: ForeignCallSingle, foreignMessageHash: ForeignCallSingle) {
|
|
229
256
|
const address = addressFromSingle(foreignAddress);
|
|
230
257
|
const messageHash = fromSingle(foreignMessageHash);
|
|
231
258
|
|
|
232
|
-
await this.handlerAsTxe().
|
|
259
|
+
await this.handlerAsTxe().addAuthWitness(address, messageHash);
|
|
233
260
|
|
|
234
261
|
return toForeignCallResult([]);
|
|
235
262
|
}
|
|
236
263
|
|
|
237
264
|
// PXE oracles
|
|
238
265
|
|
|
239
|
-
|
|
240
|
-
|
|
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();
|
|
241
270
|
|
|
242
|
-
this.handlerAsMisc().
|
|
271
|
+
this.handlerAsMisc().assertCompatibleOracleVersion(major, minor);
|
|
243
272
|
|
|
244
273
|
return toForeignCallResult([]);
|
|
245
274
|
}
|
|
246
275
|
|
|
247
|
-
|
|
248
|
-
|
|
276
|
+
// eslint-disable-next-line camelcase
|
|
277
|
+
aztec_utl_getRandomField() {
|
|
278
|
+
const randomField = this.handlerAsMisc().getRandomField();
|
|
249
279
|
|
|
250
280
|
return toForeignCallResult([toSingle(randomField)]);
|
|
251
281
|
}
|
|
252
282
|
|
|
253
|
-
|
|
254
|
-
|
|
283
|
+
// eslint-disable-next-line camelcase
|
|
284
|
+
async aztec_txe_getLastBlockTimestamp() {
|
|
285
|
+
const timestamp = await this.handlerAsTxe().getLastBlockTimestamp();
|
|
255
286
|
|
|
256
287
|
return toForeignCallResult([toSingle(new Fr(timestamp))]);
|
|
257
288
|
}
|
|
258
289
|
|
|
259
|
-
|
|
260
|
-
|
|
290
|
+
// eslint-disable-next-line camelcase
|
|
291
|
+
async aztec_txe_getLastTxEffects() {
|
|
292
|
+
const { txHash, noteHashes, nullifiers } = await this.handlerAsTxe().getLastTxEffects();
|
|
261
293
|
|
|
262
294
|
return toForeignCallResult([
|
|
263
295
|
toSingle(txHash.hash),
|
|
@@ -266,26 +298,110 @@ export class RPCTranslator {
|
|
|
266
298
|
]);
|
|
267
299
|
}
|
|
268
300
|
|
|
269
|
-
|
|
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(
|
|
343
|
+
foreignSelector: ForeignCallSingle,
|
|
344
|
+
foreignContractAddress: ForeignCallSingle,
|
|
345
|
+
foreignScope: ForeignCallSingle,
|
|
346
|
+
) {
|
|
347
|
+
const selector = EventSelector.fromField(fromSingle(foreignSelector));
|
|
348
|
+
const contractAddress = addressFromSingle(foreignContractAddress);
|
|
349
|
+
const scope = addressFromSingle(foreignScope);
|
|
350
|
+
|
|
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);
|
|
359
|
+
|
|
360
|
+
if (events.length > MAX_PRIVATE_EVENTS_PER_TXE_QUERY) {
|
|
361
|
+
throw new Error(`Array of length ${events.length} larger than maxLen ${MAX_PRIVATE_EVENTS_PER_TXE_QUERY}`);
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
if (events.some(e => e.length > MAX_EVENT_LEN)) {
|
|
365
|
+
throw new Error(`Some private event has length larger than maxLen ${MAX_EVENT_LEN}`);
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
// This is a workaround as Noir does not currently let us return nested structs with arrays. We instead return a raw
|
|
369
|
+
// multidimensional array in get_private_events_oracle and create the BoundedVecs here.
|
|
370
|
+
const rawArrayStorage = events
|
|
371
|
+
.map(e => e.concat(Array(MAX_EVENT_LEN - e.length).fill(new Fr(0))))
|
|
372
|
+
.concat(Array(MAX_PRIVATE_EVENTS_PER_TXE_QUERY - events.length).fill(Array(MAX_EVENT_LEN).fill(new Fr(0))))
|
|
373
|
+
.flat();
|
|
374
|
+
const eventLengths = events
|
|
375
|
+
.map(e => new Fr(e.length))
|
|
376
|
+
.concat(Array(MAX_PRIVATE_EVENTS_PER_TXE_QUERY - events.length).fill(new Fr(0)));
|
|
377
|
+
const queryLength = new Fr(events.length);
|
|
378
|
+
|
|
379
|
+
return toForeignCallResult([toArray(rawArrayStorage), toArray(eventLengths), toSingle(queryLength)]);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
// eslint-disable-next-line camelcase
|
|
383
|
+
aztec_prv_setHashPreimage(foreignValues: ForeignCallArray, foreignHash: ForeignCallSingle) {
|
|
270
384
|
const values = fromArray(foreignValues);
|
|
271
385
|
const hash = fromSingle(foreignHash);
|
|
272
386
|
|
|
273
|
-
this.handlerAsPrivate().
|
|
387
|
+
this.handlerAsPrivate().setHashPreimage(values, hash);
|
|
274
388
|
|
|
275
389
|
return toForeignCallResult([]);
|
|
276
390
|
}
|
|
277
391
|
|
|
278
|
-
|
|
392
|
+
// eslint-disable-next-line camelcase
|
|
393
|
+
async aztec_prv_getHashPreimage(foreignHash: ForeignCallSingle) {
|
|
279
394
|
const hash = fromSingle(foreignHash);
|
|
280
395
|
|
|
281
|
-
const returns = await this.handlerAsPrivate().
|
|
396
|
+
const returns = await this.handlerAsPrivate().getHashPreimage(hash);
|
|
282
397
|
|
|
283
398
|
return toForeignCallResult([toArray(returns)]);
|
|
284
399
|
}
|
|
285
400
|
|
|
286
401
|
// When the argument is a slice, noir automatically adds a length field to oracle call.
|
|
287
402
|
// When the argument is an array, we add the field length manually to the signature.
|
|
288
|
-
|
|
403
|
+
// eslint-disable-next-line camelcase
|
|
404
|
+
async aztec_utl_log(
|
|
289
405
|
foreignLevel: ForeignCallSingle,
|
|
290
406
|
foreignMessage: ForeignCallArray,
|
|
291
407
|
_foreignLength: ForeignCallSingle,
|
|
@@ -297,45 +413,50 @@ export class RPCTranslator {
|
|
|
297
413
|
.join('');
|
|
298
414
|
const fields = fromArray(foreignFields);
|
|
299
415
|
|
|
300
|
-
this.handlerAsMisc().
|
|
416
|
+
await this.handlerAsMisc().log(level, message, fields);
|
|
301
417
|
|
|
302
418
|
return toForeignCallResult([]);
|
|
303
419
|
}
|
|
304
420
|
|
|
305
|
-
|
|
421
|
+
// eslint-disable-next-line camelcase
|
|
422
|
+
async aztec_utl_getFromPublicStorage(
|
|
423
|
+
foreignBlockHash: ForeignCallSingle,
|
|
306
424
|
foreignContractAddress: ForeignCallSingle,
|
|
307
425
|
foreignStartStorageSlot: ForeignCallSingle,
|
|
308
|
-
foreignBlockNumber: ForeignCallSingle,
|
|
309
426
|
foreignNumberOfElements: ForeignCallSingle,
|
|
310
427
|
) {
|
|
428
|
+
const blockHash = blockHashFromSingle(foreignBlockHash);
|
|
311
429
|
const contractAddress = addressFromSingle(foreignContractAddress);
|
|
312
430
|
const startStorageSlot = fromSingle(foreignStartStorageSlot);
|
|
313
|
-
const blockNumber = fromSingle(foreignBlockNumber).toNumber();
|
|
314
431
|
const numberOfElements = fromSingle(foreignNumberOfElements).toNumber();
|
|
315
432
|
|
|
316
|
-
const values = await this.handlerAsUtility().
|
|
433
|
+
const values = await this.handlerAsUtility().getFromPublicStorage(
|
|
434
|
+
blockHash,
|
|
317
435
|
contractAddress,
|
|
318
436
|
startStorageSlot,
|
|
319
|
-
blockNumber,
|
|
320
437
|
numberOfElements,
|
|
321
438
|
);
|
|
322
439
|
|
|
323
440
|
return toForeignCallResult([toArray(values)]);
|
|
324
441
|
}
|
|
325
442
|
|
|
326
|
-
|
|
327
|
-
|
|
443
|
+
// eslint-disable-next-line camelcase
|
|
444
|
+
async aztec_utl_getPublicDataWitness(foreignBlockHash: ForeignCallSingle, foreignLeafSlot: ForeignCallSingle) {
|
|
445
|
+
const blockHash = blockHashFromSingle(foreignBlockHash);
|
|
328
446
|
const leafSlot = fromSingle(foreignLeafSlot);
|
|
329
447
|
|
|
330
|
-
const witness = await this.handlerAsUtility().
|
|
448
|
+
const witness = await this.handlerAsUtility().getPublicDataWitness(blockHash, leafSlot);
|
|
331
449
|
|
|
332
450
|
if (!witness) {
|
|
333
|
-
throw new Error(`Public data witness not found for slot ${leafSlot} at block ${
|
|
451
|
+
throw new Error(`Public data witness not found for slot ${leafSlot} at block ${blockHash.toString()}.`);
|
|
334
452
|
}
|
|
335
453
|
return toForeignCallResult(witness.toNoirRepresentation());
|
|
336
454
|
}
|
|
337
455
|
|
|
338
|
-
|
|
456
|
+
// eslint-disable-next-line camelcase
|
|
457
|
+
async aztec_utl_getNotes(
|
|
458
|
+
foreignOwnerIsSome: ForeignCallSingle,
|
|
459
|
+
foreignOwnerValue: ForeignCallSingle,
|
|
339
460
|
foreignStorageSlot: ForeignCallSingle,
|
|
340
461
|
foreignNumSelects: ForeignCallSingle,
|
|
341
462
|
foreignSelectByIndexes: ForeignCallArray,
|
|
@@ -351,8 +472,12 @@ export class RPCTranslator {
|
|
|
351
472
|
foreignOffset: ForeignCallSingle,
|
|
352
473
|
foreignStatus: ForeignCallSingle,
|
|
353
474
|
foreignMaxNotes: ForeignCallSingle,
|
|
354
|
-
|
|
475
|
+
foreignPackedHintedNoteLength: ForeignCallSingle,
|
|
355
476
|
) {
|
|
477
|
+
// Parse Option<AztecAddress>: ownerIsSome is 0 for None, 1 for Some
|
|
478
|
+
const owner = fromSingle(foreignOwnerIsSome).toBool()
|
|
479
|
+
? AztecAddress.fromField(fromSingle(foreignOwnerValue))
|
|
480
|
+
: undefined;
|
|
356
481
|
const storageSlot = fromSingle(foreignStorageSlot);
|
|
357
482
|
const numSelects = fromSingle(foreignNumSelects).toNumber();
|
|
358
483
|
const selectByIndexes = fromArray(foreignSelectByIndexes).map(fr => fr.toNumber());
|
|
@@ -368,9 +493,10 @@ export class RPCTranslator {
|
|
|
368
493
|
const offset = fromSingle(foreignOffset).toNumber();
|
|
369
494
|
const status = fromSingle(foreignStatus).toNumber();
|
|
370
495
|
const maxNotes = fromSingle(foreignMaxNotes).toNumber();
|
|
371
|
-
const
|
|
496
|
+
const packedHintedNoteLength = fromSingle(foreignPackedHintedNoteLength).toNumber();
|
|
372
497
|
|
|
373
|
-
const noteDatas = await this.handlerAsUtility().
|
|
498
|
+
const noteDatas = await this.handlerAsUtility().getNotes(
|
|
499
|
+
owner,
|
|
374
500
|
storageSlot,
|
|
375
501
|
numSelects,
|
|
376
502
|
selectByIndexes,
|
|
@@ -387,7 +513,17 @@ export class RPCTranslator {
|
|
|
387
513
|
status,
|
|
388
514
|
);
|
|
389
515
|
|
|
390
|
-
const returnDataAsArrayOfArrays = noteDatas.map(
|
|
516
|
+
const returnDataAsArrayOfArrays = noteDatas.map(noteData =>
|
|
517
|
+
packAsHintedNote({
|
|
518
|
+
contractAddress: noteData.contractAddress,
|
|
519
|
+
owner: noteData.owner,
|
|
520
|
+
randomness: noteData.randomness,
|
|
521
|
+
storageSlot: noteData.storageSlot,
|
|
522
|
+
noteNonce: noteData.noteNonce,
|
|
523
|
+
isPending: noteData.isPending,
|
|
524
|
+
note: noteData.note,
|
|
525
|
+
}),
|
|
526
|
+
);
|
|
391
527
|
|
|
392
528
|
// Now we convert each sub-array to an array of ForeignCallSingles
|
|
393
529
|
const returnDataAsArrayOfForeignCallSingleArrays = returnDataAsArrayOfArrays.map(subArray =>
|
|
@@ -396,15 +532,13 @@ export class RPCTranslator {
|
|
|
396
532
|
|
|
397
533
|
// At last we convert the array of arrays to a bounded vec of arrays
|
|
398
534
|
return toForeignCallResult(
|
|
399
|
-
arrayOfArraysToBoundedVecOfArrays(
|
|
400
|
-
returnDataAsArrayOfForeignCallSingleArrays,
|
|
401
|
-
maxNotes,
|
|
402
|
-
packedRetrievedNoteLength,
|
|
403
|
-
),
|
|
535
|
+
arrayOfArraysToBoundedVecOfArrays(returnDataAsArrayOfForeignCallSingleArrays, maxNotes, packedHintedNoteLength),
|
|
404
536
|
);
|
|
405
537
|
}
|
|
406
538
|
|
|
407
|
-
|
|
539
|
+
// eslint-disable-next-line camelcase
|
|
540
|
+
aztec_prv_notifyCreatedNote(
|
|
541
|
+
foreignOwner: ForeignCallSingle,
|
|
408
542
|
foreignStorageSlot: ForeignCallSingle,
|
|
409
543
|
foreignRandomness: ForeignCallSingle,
|
|
410
544
|
foreignNoteTypeId: ForeignCallSingle,
|
|
@@ -412,6 +546,7 @@ export class RPCTranslator {
|
|
|
412
546
|
foreignNoteHash: ForeignCallSingle,
|
|
413
547
|
foreignCounter: ForeignCallSingle,
|
|
414
548
|
) {
|
|
549
|
+
const owner = addressFromSingle(foreignOwner);
|
|
415
550
|
const storageSlot = fromSingle(foreignStorageSlot);
|
|
416
551
|
const randomness = fromSingle(foreignRandomness);
|
|
417
552
|
const noteTypeId = NoteSelector.fromField(fromSingle(foreignNoteTypeId));
|
|
@@ -419,12 +554,13 @@ export class RPCTranslator {
|
|
|
419
554
|
const noteHash = fromSingle(foreignNoteHash);
|
|
420
555
|
const counter = fromSingle(foreignCounter).toNumber();
|
|
421
556
|
|
|
422
|
-
this.handlerAsPrivate().
|
|
557
|
+
this.handlerAsPrivate().notifyCreatedNote(owner, storageSlot, randomness, noteTypeId, note, noteHash, counter);
|
|
423
558
|
|
|
424
559
|
return toForeignCallResult([]);
|
|
425
560
|
}
|
|
426
561
|
|
|
427
|
-
|
|
562
|
+
// eslint-disable-next-line camelcase
|
|
563
|
+
async aztec_prv_notifyNullifiedNote(
|
|
428
564
|
foreignInnerNullifier: ForeignCallSingle,
|
|
429
565
|
foreignNoteHash: ForeignCallSingle,
|
|
430
566
|
foreignCounter: ForeignCallSingle,
|
|
@@ -433,31 +569,47 @@ export class RPCTranslator {
|
|
|
433
569
|
const noteHash = fromSingle(foreignNoteHash);
|
|
434
570
|
const counter = fromSingle(foreignCounter).toNumber();
|
|
435
571
|
|
|
436
|
-
await this.handlerAsPrivate().
|
|
572
|
+
await this.handlerAsPrivate().notifyNullifiedNote(innerNullifier, noteHash, counter);
|
|
437
573
|
|
|
438
574
|
return toForeignCallResult([]);
|
|
439
575
|
}
|
|
440
576
|
|
|
441
|
-
|
|
577
|
+
// eslint-disable-next-line camelcase
|
|
578
|
+
async aztec_prv_notifyCreatedNullifier(foreignInnerNullifier: ForeignCallSingle) {
|
|
442
579
|
const innerNullifier = fromSingle(foreignInnerNullifier);
|
|
443
580
|
|
|
444
|
-
await this.handlerAsPrivate().
|
|
581
|
+
await this.handlerAsPrivate().notifyCreatedNullifier(innerNullifier);
|
|
445
582
|
|
|
446
583
|
return toForeignCallResult([]);
|
|
447
584
|
}
|
|
448
585
|
|
|
449
|
-
|
|
586
|
+
// eslint-disable-next-line camelcase
|
|
587
|
+
async aztec_prv_isNullifierPending(
|
|
588
|
+
foreignInnerNullifier: ForeignCallSingle,
|
|
589
|
+
foreignContractAddress: ForeignCallSingle,
|
|
590
|
+
) {
|
|
450
591
|
const innerNullifier = fromSingle(foreignInnerNullifier);
|
|
592
|
+
const contractAddress = addressFromSingle(foreignContractAddress);
|
|
451
593
|
|
|
452
|
-
const
|
|
594
|
+
const isPending = await this.handlerAsPrivate().isNullifierPending(innerNullifier, contractAddress);
|
|
595
|
+
|
|
596
|
+
return toForeignCallResult([toSingle(new Fr(isPending))]);
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
// eslint-disable-next-line camelcase
|
|
600
|
+
async aztec_utl_doesNullifierExist(foreignInnerNullifier: ForeignCallSingle) {
|
|
601
|
+
const innerNullifier = fromSingle(foreignInnerNullifier);
|
|
602
|
+
|
|
603
|
+
const exists = await this.handlerAsUtility().doesNullifierExist(innerNullifier);
|
|
453
604
|
|
|
454
605
|
return toForeignCallResult([toSingle(new Fr(exists))]);
|
|
455
606
|
}
|
|
456
607
|
|
|
457
|
-
|
|
608
|
+
// eslint-disable-next-line camelcase
|
|
609
|
+
async aztec_utl_getContractInstance(foreignAddress: ForeignCallSingle) {
|
|
458
610
|
const address = addressFromSingle(foreignAddress);
|
|
459
611
|
|
|
460
|
-
const instance = await this.handlerAsUtility().
|
|
612
|
+
const instance = await this.handlerAsUtility().getContractInstance(address);
|
|
461
613
|
|
|
462
614
|
return toForeignCallResult(
|
|
463
615
|
[
|
|
@@ -470,23 +622,37 @@ export class RPCTranslator {
|
|
|
470
622
|
);
|
|
471
623
|
}
|
|
472
624
|
|
|
473
|
-
|
|
625
|
+
// eslint-disable-next-line camelcase
|
|
626
|
+
async aztec_utl_getPublicKeysAndPartialAddress(foreignAddress: ForeignCallSingle) {
|
|
474
627
|
const address = addressFromSingle(foreignAddress);
|
|
475
628
|
|
|
476
|
-
const
|
|
629
|
+
const result = await this.handlerAsUtility().getPublicKeysAndPartialAddress(address);
|
|
477
630
|
|
|
478
|
-
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
|
+
}
|
|
479
643
|
}
|
|
480
644
|
|
|
481
|
-
|
|
645
|
+
// eslint-disable-next-line camelcase
|
|
646
|
+
async aztec_utl_getKeyValidationRequest(foreignPkMHash: ForeignCallSingle) {
|
|
482
647
|
const pkMHash = fromSingle(foreignPkMHash);
|
|
483
648
|
|
|
484
|
-
const keyValidationRequest = await this.handlerAsUtility().
|
|
649
|
+
const keyValidationRequest = await this.handlerAsUtility().getKeyValidationRequest(pkMHash);
|
|
485
650
|
|
|
486
651
|
return toForeignCallResult(keyValidationRequest.toFields().map(toSingle));
|
|
487
652
|
}
|
|
488
653
|
|
|
489
|
-
|
|
654
|
+
// eslint-disable-next-line camelcase
|
|
655
|
+
aztec_prv_callPrivateFunction(
|
|
490
656
|
_foreignTargetContractAddress: ForeignCallSingle,
|
|
491
657
|
_foreignFunctionSelector: ForeignCallSingle,
|
|
492
658
|
_foreignArgsHash: ForeignCallSingle,
|
|
@@ -498,25 +664,27 @@ export class RPCTranslator {
|
|
|
498
664
|
);
|
|
499
665
|
}
|
|
500
666
|
|
|
501
|
-
|
|
502
|
-
|
|
667
|
+
// eslint-disable-next-line camelcase
|
|
668
|
+
async aztec_utl_getNullifierMembershipWitness(
|
|
669
|
+
foreignBlockHash: ForeignCallSingle,
|
|
503
670
|
foreignNullifier: ForeignCallSingle,
|
|
504
671
|
) {
|
|
505
|
-
const
|
|
672
|
+
const blockHash = blockHashFromSingle(foreignBlockHash);
|
|
506
673
|
const nullifier = fromSingle(foreignNullifier);
|
|
507
674
|
|
|
508
|
-
const witness = await this.handlerAsUtility().
|
|
675
|
+
const witness = await this.handlerAsUtility().getNullifierMembershipWitness(blockHash, nullifier);
|
|
509
676
|
|
|
510
677
|
if (!witness) {
|
|
511
|
-
throw new Error(`Nullifier membership witness not found at block ${
|
|
678
|
+
throw new Error(`Nullifier membership witness not found at block ${blockHash}.`);
|
|
512
679
|
}
|
|
513
680
|
return toForeignCallResult(witness.toNoirRepresentation());
|
|
514
681
|
}
|
|
515
682
|
|
|
516
|
-
|
|
683
|
+
// eslint-disable-next-line camelcase
|
|
684
|
+
async aztec_utl_getAuthWitness(foreignMessageHash: ForeignCallSingle) {
|
|
517
685
|
const messageHash = fromSingle(foreignMessageHash);
|
|
518
686
|
|
|
519
|
-
const authWitness = await this.handlerAsUtility().
|
|
687
|
+
const authWitness = await this.handlerAsUtility().getAuthWitness(messageHash);
|
|
520
688
|
|
|
521
689
|
if (!authWitness) {
|
|
522
690
|
throw new Error(`Auth witness not found for message hash ${messageHash}.`);
|
|
@@ -524,44 +692,35 @@ export class RPCTranslator {
|
|
|
524
692
|
return toForeignCallResult([toArray(authWitness)]);
|
|
525
693
|
}
|
|
526
694
|
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
_foreignCalldataHash: ForeignCallSingle,
|
|
530
|
-
_foreignSideEffectCounter: ForeignCallSingle,
|
|
531
|
-
_foreignIsStaticCall: ForeignCallSingle,
|
|
532
|
-
) {
|
|
695
|
+
// eslint-disable-next-line camelcase
|
|
696
|
+
public aztec_prv_assertValidPublicCalldata(_foreignCalldataHash: ForeignCallSingle) {
|
|
533
697
|
throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
|
|
534
698
|
}
|
|
535
699
|
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
_foreignCalldataHash: ForeignCallSingle,
|
|
539
|
-
_foreignSideEffectCounter: ForeignCallSingle,
|
|
540
|
-
_foreignIsStaticCall: ForeignCallSingle,
|
|
541
|
-
) {
|
|
700
|
+
// eslint-disable-next-line camelcase
|
|
701
|
+
public aztec_prv_notifyRevertiblePhaseStart(_foreignMinRevertibleSideEffectCounter: ForeignCallSingle) {
|
|
542
702
|
throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
|
|
543
703
|
}
|
|
544
704
|
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
public async privateIsSideEffectCounterRevertible(foreignSideEffectCounter: ForeignCallSingle) {
|
|
705
|
+
// eslint-disable-next-line camelcase
|
|
706
|
+
public async aztec_prv_isExecutionInRevertiblePhase(foreignSideEffectCounter: ForeignCallSingle) {
|
|
550
707
|
const sideEffectCounter = fromSingle(foreignSideEffectCounter).toNumber();
|
|
551
|
-
const isRevertible = await this.handlerAsPrivate().
|
|
708
|
+
const isRevertible = await this.handlerAsPrivate().isExecutionInRevertiblePhase(sideEffectCounter);
|
|
552
709
|
return toForeignCallResult([toSingle(new Fr(isRevertible))]);
|
|
553
710
|
}
|
|
554
711
|
|
|
555
|
-
|
|
556
|
-
|
|
712
|
+
// eslint-disable-next-line camelcase
|
|
713
|
+
aztec_utl_getUtilityContext() {
|
|
714
|
+
const context = this.handlerAsUtility().getUtilityContext();
|
|
557
715
|
|
|
558
716
|
return toForeignCallResult(context.toNoirRepresentation());
|
|
559
717
|
}
|
|
560
718
|
|
|
561
|
-
|
|
562
|
-
|
|
719
|
+
// eslint-disable-next-line camelcase
|
|
720
|
+
async aztec_utl_getBlockHeader(foreignBlockNumber: ForeignCallSingle) {
|
|
721
|
+
const blockNumber = BlockNumber(fromSingle(foreignBlockNumber).toNumber());
|
|
563
722
|
|
|
564
|
-
const header = await this.handlerAsUtility().
|
|
723
|
+
const header = await this.handlerAsUtility().getBlockHeader(blockNumber);
|
|
565
724
|
|
|
566
725
|
if (!header) {
|
|
567
726
|
throw new Error(`Block header not found for block ${blockNumber}.`);
|
|
@@ -569,108 +728,217 @@ export class RPCTranslator {
|
|
|
569
728
|
return toForeignCallResult(header.toFields().map(toSingle));
|
|
570
729
|
}
|
|
571
730
|
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
731
|
+
// eslint-disable-next-line camelcase
|
|
732
|
+
async aztec_utl_getNoteHashMembershipWitness(
|
|
733
|
+
foreignAnchorBlockHash: ForeignCallSingle,
|
|
734
|
+
foreignNoteHash: ForeignCallSingle,
|
|
576
735
|
) {
|
|
577
|
-
const
|
|
578
|
-
const
|
|
579
|
-
const leafValue = fromSingle(foreignLeafValue);
|
|
736
|
+
const blockHash = blockHashFromSingle(foreignAnchorBlockHash);
|
|
737
|
+
const noteHash = fromSingle(foreignNoteHash);
|
|
580
738
|
|
|
581
|
-
const witness = await this.handlerAsUtility().
|
|
739
|
+
const witness = await this.handlerAsUtility().getNoteHashMembershipWitness(blockHash, noteHash);
|
|
740
|
+
|
|
741
|
+
if (!witness) {
|
|
742
|
+
throw new Error(`Note hash ${noteHash} not found in the note hash tree at block ${blockHash.toString()}.`);
|
|
743
|
+
}
|
|
744
|
+
return toForeignCallResult(witness.toNoirRepresentation());
|
|
745
|
+
}
|
|
746
|
+
|
|
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);
|
|
754
|
+
|
|
755
|
+
const witness = await this.handlerAsUtility().getBlockHashMembershipWitness(anchorBlockHash, blockHash);
|
|
582
756
|
|
|
583
757
|
if (!witness) {
|
|
584
758
|
throw new Error(
|
|
585
|
-
`
|
|
759
|
+
`Block hash ${blockHash.toString()} not found in the archive tree at anchor block ${anchorBlockHash.toString()}.`,
|
|
586
760
|
);
|
|
587
761
|
}
|
|
588
|
-
return toForeignCallResult(
|
|
762
|
+
return toForeignCallResult(witness.toNoirRepresentation());
|
|
589
763
|
}
|
|
590
764
|
|
|
591
|
-
|
|
592
|
-
|
|
765
|
+
// eslint-disable-next-line camelcase
|
|
766
|
+
async aztec_utl_getLowNullifierMembershipWitness(
|
|
767
|
+
foreignBlockHash: ForeignCallSingle,
|
|
593
768
|
foreignNullifier: ForeignCallSingle,
|
|
594
769
|
) {
|
|
595
|
-
const
|
|
770
|
+
const blockHash = blockHashFromSingle(foreignBlockHash);
|
|
596
771
|
const nullifier = fromSingle(foreignNullifier);
|
|
597
772
|
|
|
598
|
-
const witness = await this.handlerAsUtility().
|
|
773
|
+
const witness = await this.handlerAsUtility().getLowNullifierMembershipWitness(blockHash, nullifier);
|
|
599
774
|
|
|
600
775
|
if (!witness) {
|
|
601
|
-
throw new Error(`Low nullifier witness not found for nullifier ${nullifier} at block ${
|
|
776
|
+
throw new Error(`Low nullifier witness not found for nullifier ${nullifier} at block ${blockHash}.`);
|
|
602
777
|
}
|
|
603
778
|
return toForeignCallResult(witness.toNoirRepresentation());
|
|
604
779
|
}
|
|
605
780
|
|
|
606
|
-
|
|
781
|
+
// eslint-disable-next-line camelcase
|
|
782
|
+
async aztec_utl_getPendingTaggedLogs(
|
|
783
|
+
foreignPendingTaggedLogArrayBaseSlot: ForeignCallSingle,
|
|
784
|
+
foreignScope: ForeignCallSingle,
|
|
785
|
+
) {
|
|
607
786
|
const pendingTaggedLogArrayBaseSlot = fromSingle(foreignPendingTaggedLogArrayBaseSlot);
|
|
787
|
+
const scope = AztecAddress.fromField(fromSingle(foreignScope));
|
|
608
788
|
|
|
609
|
-
await this.handlerAsUtility().
|
|
789
|
+
await this.handlerAsUtility().getPendingTaggedLogs(pendingTaggedLogArrayBaseSlot, scope);
|
|
610
790
|
|
|
611
791
|
return toForeignCallResult([]);
|
|
612
792
|
}
|
|
613
793
|
|
|
614
|
-
|
|
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(
|
|
615
803
|
foreignContractAddress: ForeignCallSingle,
|
|
616
804
|
foreignNoteValidationRequestsArrayBaseSlot: ForeignCallSingle,
|
|
617
805
|
foreignEventValidationRequestsArrayBaseSlot: ForeignCallSingle,
|
|
806
|
+
foreignMaxNotePackedLen: ForeignCallSingle,
|
|
807
|
+
foreignMaxEventSerializedLen: ForeignCallSingle,
|
|
808
|
+
foreignScope: ForeignCallSingle,
|
|
618
809
|
) {
|
|
619
810
|
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
620
811
|
const noteValidationRequestsArrayBaseSlot = fromSingle(foreignNoteValidationRequestsArrayBaseSlot);
|
|
621
812
|
const eventValidationRequestsArrayBaseSlot = fromSingle(foreignEventValidationRequestsArrayBaseSlot);
|
|
813
|
+
const maxNotePackedLen = fromSingle(foreignMaxNotePackedLen).toNumber();
|
|
814
|
+
const maxEventSerializedLen = fromSingle(foreignMaxEventSerializedLen).toNumber();
|
|
815
|
+
const scope = AztecAddress.fromField(fromSingle(foreignScope));
|
|
622
816
|
|
|
623
|
-
await this.handlerAsUtility().
|
|
817
|
+
await this.handlerAsUtility().validateAndStoreEnqueuedNotesAndEvents(
|
|
624
818
|
contractAddress,
|
|
625
819
|
noteValidationRequestsArrayBaseSlot,
|
|
626
820
|
eventValidationRequestsArrayBaseSlot,
|
|
821
|
+
maxNotePackedLen,
|
|
822
|
+
maxEventSerializedLen,
|
|
823
|
+
scope,
|
|
627
824
|
);
|
|
628
825
|
|
|
629
826
|
return toForeignCallResult([]);
|
|
630
827
|
}
|
|
631
828
|
|
|
632
|
-
|
|
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,
|
|
849
|
+
);
|
|
850
|
+
|
|
851
|
+
return toForeignCallResult([]);
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
// eslint-disable-next-line camelcase
|
|
855
|
+
public async aztec_utl_getLogsByTag(
|
|
633
856
|
foreignContractAddress: ForeignCallSingle,
|
|
634
857
|
foreignLogRetrievalRequestsArrayBaseSlot: ForeignCallSingle,
|
|
635
858
|
foreignLogRetrievalResponsesArrayBaseSlot: ForeignCallSingle,
|
|
859
|
+
foreignScope: ForeignCallSingle,
|
|
636
860
|
) {
|
|
637
861
|
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
638
862
|
const logRetrievalRequestsArrayBaseSlot = fromSingle(foreignLogRetrievalRequestsArrayBaseSlot);
|
|
639
863
|
const logRetrievalResponsesArrayBaseSlot = fromSingle(foreignLogRetrievalResponsesArrayBaseSlot);
|
|
864
|
+
const scope = AztecAddress.fromField(fromSingle(foreignScope));
|
|
640
865
|
|
|
641
|
-
await this.handlerAsUtility().
|
|
866
|
+
await this.handlerAsUtility().getLogsByTag(
|
|
642
867
|
contractAddress,
|
|
643
868
|
logRetrievalRequestsArrayBaseSlot,
|
|
644
869
|
logRetrievalResponsesArrayBaseSlot,
|
|
870
|
+
scope,
|
|
645
871
|
);
|
|
646
872
|
|
|
647
873
|
return toForeignCallResult([]);
|
|
648
874
|
}
|
|
649
875
|
|
|
650
|
-
|
|
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,
|
|
893
|
+
);
|
|
894
|
+
|
|
895
|
+
return toForeignCallResult([]);
|
|
896
|
+
}
|
|
897
|
+
|
|
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(
|
|
651
914
|
foreignContractAddress: ForeignCallSingle,
|
|
652
915
|
foreignSlot: ForeignCallSingle,
|
|
653
916
|
foreignCapsule: ForeignCallArray,
|
|
917
|
+
foreignScope: ForeignCallSingle,
|
|
654
918
|
) {
|
|
655
919
|
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
656
920
|
const slot = fromSingle(foreignSlot);
|
|
657
921
|
const capsule = fromArray(foreignCapsule);
|
|
922
|
+
const scope = AztecAddress.fromField(fromSingle(foreignScope));
|
|
658
923
|
|
|
659
|
-
|
|
924
|
+
this.handlerAsUtility().setCapsule(contractAddress, slot, capsule, scope);
|
|
660
925
|
|
|
661
926
|
return toForeignCallResult([]);
|
|
662
927
|
}
|
|
663
928
|
|
|
664
|
-
|
|
929
|
+
// eslint-disable-next-line camelcase
|
|
930
|
+
async aztec_utl_getCapsule(
|
|
665
931
|
foreignContractAddress: ForeignCallSingle,
|
|
666
932
|
foreignSlot: ForeignCallSingle,
|
|
667
933
|
foreignTSize: ForeignCallSingle,
|
|
934
|
+
foreignScope: ForeignCallSingle,
|
|
668
935
|
) {
|
|
669
936
|
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
670
937
|
const slot = fromSingle(foreignSlot);
|
|
671
938
|
const tSize = fromSingle(foreignTSize).toNumber();
|
|
939
|
+
const scope = AztecAddress.fromField(fromSingle(foreignScope));
|
|
672
940
|
|
|
673
|
-
const values = await this.handlerAsUtility().
|
|
941
|
+
const values = await this.handlerAsUtility().getCapsule(contractAddress, slot, scope);
|
|
674
942
|
|
|
675
943
|
// We are going to return a Noir Option struct to represent the possibility of null values. Options are a struct
|
|
676
944
|
// with two fields: `some` (a boolean) and `value` (a field array in this case).
|
|
@@ -683,28 +951,95 @@ export class RPCTranslator {
|
|
|
683
951
|
}
|
|
684
952
|
}
|
|
685
953
|
|
|
686
|
-
|
|
954
|
+
// eslint-disable-next-line camelcase
|
|
955
|
+
aztec_utl_deleteCapsule(
|
|
956
|
+
foreignContractAddress: ForeignCallSingle,
|
|
957
|
+
foreignSlot: ForeignCallSingle,
|
|
958
|
+
foreignScope: ForeignCallSingle,
|
|
959
|
+
) {
|
|
687
960
|
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
688
961
|
const slot = fromSingle(foreignSlot);
|
|
962
|
+
const scope = AztecAddress.fromField(fromSingle(foreignScope));
|
|
689
963
|
|
|
690
|
-
|
|
964
|
+
this.handlerAsUtility().deleteCapsule(contractAddress, slot, scope);
|
|
691
965
|
|
|
692
966
|
return toForeignCallResult([]);
|
|
693
967
|
}
|
|
694
968
|
|
|
695
|
-
|
|
969
|
+
// eslint-disable-next-line camelcase
|
|
970
|
+
async aztec_utl_copyCapsule(
|
|
696
971
|
foreignContractAddress: ForeignCallSingle,
|
|
697
972
|
foreignSrcSlot: ForeignCallSingle,
|
|
698
973
|
foreignDstSlot: ForeignCallSingle,
|
|
699
974
|
foreignNumEntries: ForeignCallSingle,
|
|
975
|
+
foreignScope: ForeignCallSingle,
|
|
700
976
|
) {
|
|
701
977
|
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
702
978
|
const srcSlot = fromSingle(foreignSrcSlot);
|
|
703
979
|
const dstSlot = fromSingle(foreignDstSlot);
|
|
704
980
|
const numEntries = fromSingle(foreignNumEntries).toNumber();
|
|
981
|
+
const scope = AztecAddress.fromField(fromSingle(foreignScope));
|
|
982
|
+
|
|
983
|
+
await this.handlerAsUtility().copyCapsule(contractAddress, srcSlot, dstSlot, numEntries, scope);
|
|
984
|
+
|
|
985
|
+
return toForeignCallResult([]);
|
|
986
|
+
}
|
|
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
|
+
}
|
|
705
1030
|
|
|
706
|
-
|
|
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
|
+
}
|
|
707
1038
|
|
|
1039
|
+
// eslint-disable-next-line camelcase
|
|
1040
|
+
aztec_utl_clearEphemeral(foreignSlot: ForeignCallSingle) {
|
|
1041
|
+
const slot = fromSingle(foreignSlot);
|
|
1042
|
+
this.handlerAsUtility().clearEphemeral(slot);
|
|
708
1043
|
return toForeignCallResult([]);
|
|
709
1044
|
}
|
|
710
1045
|
|
|
@@ -712,7 +1047,8 @@ export class RPCTranslator {
|
|
|
712
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
|
|
713
1048
|
// to implement this function here. Isn't there a way to programmatically identify that this is missing, given the
|
|
714
1049
|
// existence of a txe_oracle method?
|
|
715
|
-
|
|
1050
|
+
// eslint-disable-next-line camelcase
|
|
1051
|
+
async aztec_utl_decryptAes128(
|
|
716
1052
|
foreignCiphertextBVecStorage: ForeignCallArray,
|
|
717
1053
|
foreignCiphertextLength: ForeignCallSingle,
|
|
718
1054
|
foreignIv: ForeignCallArray,
|
|
@@ -722,18 +1058,27 @@ export class RPCTranslator {
|
|
|
722
1058
|
const iv = fromUintArray(foreignIv, 8);
|
|
723
1059
|
const symKey = fromUintArray(foreignSymKey, 8);
|
|
724
1060
|
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
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
|
+
}
|
|
730
1073
|
}
|
|
731
1074
|
|
|
732
|
-
|
|
1075
|
+
// eslint-disable-next-line camelcase
|
|
1076
|
+
async aztec_utl_getSharedSecret(
|
|
733
1077
|
foreignAddress: ForeignCallSingle,
|
|
734
1078
|
foreignEphPKField0: ForeignCallSingle,
|
|
735
1079
|
foreignEphPKField1: ForeignCallSingle,
|
|
736
1080
|
foreignEphPKField2: ForeignCallSingle,
|
|
1081
|
+
foreignContractAddress: ForeignCallSingle,
|
|
737
1082
|
) {
|
|
738
1083
|
const address = AztecAddress.fromField(fromSingle(foreignAddress));
|
|
739
1084
|
const ephPK = Point.fromFields([
|
|
@@ -741,44 +1086,73 @@ export class RPCTranslator {
|
|
|
741
1086
|
fromSingle(foreignEphPKField1),
|
|
742
1087
|
fromSingle(foreignEphPKField2),
|
|
743
1088
|
]);
|
|
1089
|
+
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
1090
|
+
|
|
1091
|
+
const secret = await this.handlerAsUtility().getSharedSecret(address, ephPK, contractAddress);
|
|
1092
|
+
|
|
1093
|
+
return toForeignCallResult([toSingle(secret)]);
|
|
1094
|
+
}
|
|
1095
|
+
|
|
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));
|
|
744
1107
|
|
|
745
|
-
|
|
1108
|
+
this.handlerAsUtility().setContractSyncCacheInvalid(contractAddress, scopes);
|
|
746
1109
|
|
|
747
|
-
return
|
|
1110
|
+
return Promise.resolve(toForeignCallResult([]));
|
|
748
1111
|
}
|
|
749
1112
|
|
|
750
|
-
|
|
751
|
-
|
|
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([]));
|
|
752
1121
|
}
|
|
753
1122
|
|
|
754
1123
|
// AVM opcodes
|
|
755
1124
|
|
|
756
|
-
|
|
1125
|
+
// eslint-disable-next-line camelcase
|
|
1126
|
+
aztec_avm_emitPublicLog(_foreignMessage: ForeignCallArray) {
|
|
757
1127
|
// TODO(#8811): Implement
|
|
758
1128
|
return toForeignCallResult([]);
|
|
759
1129
|
}
|
|
760
1130
|
|
|
761
|
-
|
|
1131
|
+
// eslint-disable-next-line camelcase
|
|
1132
|
+
async aztec_avm_storageRead(foreignSlot: ForeignCallSingle, foreignContractAddress: ForeignCallSingle) {
|
|
762
1133
|
const slot = fromSingle(foreignSlot);
|
|
1134
|
+
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
763
1135
|
|
|
764
|
-
const value = (await this.handlerAsAvm().
|
|
1136
|
+
const value = (await this.handlerAsAvm().storageRead(slot, contractAddress)).value;
|
|
765
1137
|
|
|
766
1138
|
return toForeignCallResult([toSingle(new Fr(value))]);
|
|
767
1139
|
}
|
|
768
1140
|
|
|
769
|
-
|
|
1141
|
+
// eslint-disable-next-line camelcase
|
|
1142
|
+
async aztec_avm_storageWrite(foreignSlot: ForeignCallSingle, foreignValue: ForeignCallSingle) {
|
|
770
1143
|
const slot = fromSingle(foreignSlot);
|
|
771
1144
|
const value = fromSingle(foreignValue);
|
|
772
1145
|
|
|
773
|
-
await this.handlerAsAvm().
|
|
1146
|
+
await this.handlerAsAvm().storageWrite(slot, value);
|
|
774
1147
|
|
|
775
1148
|
return toForeignCallResult([]);
|
|
776
1149
|
}
|
|
777
1150
|
|
|
778
|
-
|
|
1151
|
+
// eslint-disable-next-line camelcase
|
|
1152
|
+
async aztec_avm_getContractInstanceDeployer(foreignAddress: ForeignCallSingle) {
|
|
779
1153
|
const address = addressFromSingle(foreignAddress);
|
|
780
1154
|
|
|
781
|
-
const instance = await this.handlerAsUtility().
|
|
1155
|
+
const instance = await this.handlerAsUtility().getContractInstance(address);
|
|
782
1156
|
|
|
783
1157
|
return toForeignCallResult([
|
|
784
1158
|
toSingle(instance.deployer),
|
|
@@ -787,10 +1161,11 @@ export class RPCTranslator {
|
|
|
787
1161
|
]);
|
|
788
1162
|
}
|
|
789
1163
|
|
|
790
|
-
|
|
1164
|
+
// eslint-disable-next-line camelcase
|
|
1165
|
+
async aztec_avm_getContractInstanceClassId(foreignAddress: ForeignCallSingle) {
|
|
791
1166
|
const address = addressFromSingle(foreignAddress);
|
|
792
1167
|
|
|
793
|
-
const instance = await this.handlerAsUtility().
|
|
1168
|
+
const instance = await this.handlerAsUtility().getContractInstance(address);
|
|
794
1169
|
|
|
795
1170
|
return toForeignCallResult([
|
|
796
1171
|
toSingle(instance.currentContractClassId),
|
|
@@ -799,10 +1174,11 @@ export class RPCTranslator {
|
|
|
799
1174
|
]);
|
|
800
1175
|
}
|
|
801
1176
|
|
|
802
|
-
|
|
1177
|
+
// eslint-disable-next-line camelcase
|
|
1178
|
+
async aztec_avm_getContractInstanceInitializationHash(foreignAddress: ForeignCallSingle) {
|
|
803
1179
|
const address = addressFromSingle(foreignAddress);
|
|
804
1180
|
|
|
805
|
-
const instance = await this.handlerAsUtility().
|
|
1181
|
+
const instance = await this.handlerAsUtility().getContractInstance(address);
|
|
806
1182
|
|
|
807
1183
|
return toForeignCallResult([
|
|
808
1184
|
toSingle(instance.initializationHash),
|
|
@@ -811,86 +1187,98 @@ export class RPCTranslator {
|
|
|
811
1187
|
]);
|
|
812
1188
|
}
|
|
813
1189
|
|
|
814
|
-
|
|
815
|
-
|
|
1190
|
+
// eslint-disable-next-line camelcase
|
|
1191
|
+
async aztec_avm_sender() {
|
|
1192
|
+
const sender = await this.handlerAsAvm().sender();
|
|
816
1193
|
|
|
817
1194
|
return toForeignCallResult([toSingle(sender)]);
|
|
818
1195
|
}
|
|
819
1196
|
|
|
820
|
-
|
|
1197
|
+
// eslint-disable-next-line camelcase
|
|
1198
|
+
async aztec_avm_emitNullifier(foreignNullifier: ForeignCallSingle) {
|
|
821
1199
|
const nullifier = fromSingle(foreignNullifier);
|
|
822
1200
|
|
|
823
|
-
await this.handlerAsAvm().
|
|
1201
|
+
await this.handlerAsAvm().emitNullifier(nullifier);
|
|
824
1202
|
|
|
825
1203
|
return toForeignCallResult([]);
|
|
826
1204
|
}
|
|
827
1205
|
|
|
828
|
-
|
|
1206
|
+
// eslint-disable-next-line camelcase
|
|
1207
|
+
async aztec_avm_emitNoteHash(foreignNoteHash: ForeignCallSingle) {
|
|
829
1208
|
const noteHash = fromSingle(foreignNoteHash);
|
|
830
1209
|
|
|
831
|
-
await this.handlerAsAvm().
|
|
1210
|
+
await this.handlerAsAvm().emitNoteHash(noteHash);
|
|
832
1211
|
|
|
833
1212
|
return toForeignCallResult([]);
|
|
834
1213
|
}
|
|
835
1214
|
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
const
|
|
1215
|
+
// eslint-disable-next-line camelcase
|
|
1216
|
+
async aztec_avm_nullifierExists(foreignSiloedNullifier: ForeignCallSingle) {
|
|
1217
|
+
const siloedNullifier = fromSingle(foreignSiloedNullifier);
|
|
839
1218
|
|
|
840
|
-
const exists = await this.handlerAsAvm().
|
|
1219
|
+
const exists = await this.handlerAsAvm().nullifierExists(siloedNullifier);
|
|
841
1220
|
|
|
842
1221
|
return toForeignCallResult([toSingle(new Fr(exists))]);
|
|
843
1222
|
}
|
|
844
1223
|
|
|
845
|
-
|
|
846
|
-
|
|
1224
|
+
// eslint-disable-next-line camelcase
|
|
1225
|
+
async aztec_avm_address() {
|
|
1226
|
+
const contractAddress = await this.handlerAsAvm().address();
|
|
847
1227
|
|
|
848
1228
|
return toForeignCallResult([toSingle(contractAddress.toField())]);
|
|
849
1229
|
}
|
|
850
1230
|
|
|
851
|
-
|
|
852
|
-
|
|
1231
|
+
// eslint-disable-next-line camelcase
|
|
1232
|
+
async aztec_avm_blockNumber() {
|
|
1233
|
+
const blockNumber = await this.handlerAsAvm().blockNumber();
|
|
853
1234
|
|
|
854
1235
|
return toForeignCallResult([toSingle(new Fr(blockNumber))]);
|
|
855
1236
|
}
|
|
856
1237
|
|
|
857
|
-
|
|
858
|
-
|
|
1238
|
+
// eslint-disable-next-line camelcase
|
|
1239
|
+
async aztec_avm_timestamp() {
|
|
1240
|
+
const timestamp = await this.handlerAsAvm().timestamp();
|
|
859
1241
|
|
|
860
1242
|
return toForeignCallResult([toSingle(new Fr(timestamp))]);
|
|
861
1243
|
}
|
|
862
1244
|
|
|
863
|
-
|
|
864
|
-
|
|
1245
|
+
// eslint-disable-next-line camelcase
|
|
1246
|
+
async aztec_avm_isStaticCall() {
|
|
1247
|
+
const isStaticCall = await this.handlerAsAvm().isStaticCall();
|
|
865
1248
|
|
|
866
1249
|
return toForeignCallResult([toSingle(new Fr(isStaticCall ? 1 : 0))]);
|
|
867
1250
|
}
|
|
868
1251
|
|
|
869
|
-
|
|
870
|
-
|
|
1252
|
+
// eslint-disable-next-line camelcase
|
|
1253
|
+
async aztec_avm_chainId() {
|
|
1254
|
+
const chainId = await this.handlerAsAvm().chainId();
|
|
871
1255
|
|
|
872
1256
|
return toForeignCallResult([toSingle(chainId)]);
|
|
873
1257
|
}
|
|
874
1258
|
|
|
875
|
-
|
|
876
|
-
|
|
1259
|
+
// eslint-disable-next-line camelcase
|
|
1260
|
+
async aztec_avm_version() {
|
|
1261
|
+
const version = await this.handlerAsAvm().version();
|
|
877
1262
|
|
|
878
1263
|
return toForeignCallResult([toSingle(version)]);
|
|
879
1264
|
}
|
|
880
1265
|
|
|
881
|
-
|
|
1266
|
+
// eslint-disable-next-line camelcase
|
|
1267
|
+
aztec_avm_returndataSize() {
|
|
882
1268
|
throw new Error(
|
|
883
1269
|
'Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead',
|
|
884
1270
|
);
|
|
885
1271
|
}
|
|
886
1272
|
|
|
887
|
-
|
|
1273
|
+
// eslint-disable-next-line camelcase
|
|
1274
|
+
aztec_avm_returndataCopy(_foreignRdOffset: ForeignCallSingle, _foreignCopySize: ForeignCallSingle) {
|
|
888
1275
|
throw new Error(
|
|
889
1276
|
'Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead',
|
|
890
1277
|
);
|
|
891
1278
|
}
|
|
892
1279
|
|
|
893
|
-
|
|
1280
|
+
// eslint-disable-next-line camelcase
|
|
1281
|
+
aztec_avm_call(
|
|
894
1282
|
_foreignL2Gas: ForeignCallSingle,
|
|
895
1283
|
_foreignDaGas: ForeignCallSingle,
|
|
896
1284
|
_foreignAddress: ForeignCallSingle,
|
|
@@ -902,7 +1290,8 @@ export class RPCTranslator {
|
|
|
902
1290
|
);
|
|
903
1291
|
}
|
|
904
1292
|
|
|
905
|
-
|
|
1293
|
+
// eslint-disable-next-line camelcase
|
|
1294
|
+
aztec_avm_staticCall(
|
|
906
1295
|
_foreignL2Gas: ForeignCallSingle,
|
|
907
1296
|
_foreignDaGas: ForeignCallSingle,
|
|
908
1297
|
_foreignAddress: ForeignCallSingle,
|
|
@@ -914,13 +1303,15 @@ export class RPCTranslator {
|
|
|
914
1303
|
);
|
|
915
1304
|
}
|
|
916
1305
|
|
|
917
|
-
|
|
1306
|
+
// eslint-disable-next-line camelcase
|
|
1307
|
+
aztec_avm_successCopy() {
|
|
918
1308
|
throw new Error(
|
|
919
1309
|
'Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead',
|
|
920
1310
|
);
|
|
921
1311
|
}
|
|
922
1312
|
|
|
923
|
-
|
|
1313
|
+
// eslint-disable-next-line camelcase
|
|
1314
|
+
async aztec_txe_privateCallNewFlow(
|
|
924
1315
|
foreignFrom: ForeignCallSingle,
|
|
925
1316
|
foreignTargetContractAddress: ForeignCallSingle,
|
|
926
1317
|
foreignFunctionSelector: ForeignCallSingle,
|
|
@@ -935,19 +1326,43 @@ export class RPCTranslator {
|
|
|
935
1326
|
const argsHash = fromSingle(foreignArgsHash);
|
|
936
1327
|
const isStaticCall = fromSingle(foreignIsStaticCall).toBool();
|
|
937
1328
|
|
|
938
|
-
const returnValues = await this.
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
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
|
+
});
|
|
946
1360
|
|
|
947
1361
|
return toForeignCallResult([toArray(returnValues)]);
|
|
948
1362
|
}
|
|
949
1363
|
|
|
950
|
-
|
|
1364
|
+
// eslint-disable-next-line camelcase
|
|
1365
|
+
async aztec_txe_executeUtilityFunction(
|
|
951
1366
|
foreignTargetContractAddress: ForeignCallSingle,
|
|
952
1367
|
foreignFunctionSelector: ForeignCallSingle,
|
|
953
1368
|
foreignArgs: ForeignCallArray,
|
|
@@ -956,16 +1371,25 @@ export class RPCTranslator {
|
|
|
956
1371
|
const functionSelector = FunctionSelector.fromField(fromSingle(foreignFunctionSelector));
|
|
957
1372
|
const args = fromArray(foreignArgs);
|
|
958
1373
|
|
|
959
|
-
const returnValues = await this.
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
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
|
+
});
|
|
964
1387
|
|
|
965
1388
|
return toForeignCallResult([toArray(returnValues)]);
|
|
966
1389
|
}
|
|
967
1390
|
|
|
968
|
-
|
|
1391
|
+
// eslint-disable-next-line camelcase
|
|
1392
|
+
async aztec_txe_publicCallNewFlow(
|
|
969
1393
|
foreignFrom: ForeignCallSingle,
|
|
970
1394
|
foreignAddress: ForeignCallSingle,
|
|
971
1395
|
foreignCalldata: ForeignCallArray,
|
|
@@ -976,13 +1400,26 @@ export class RPCTranslator {
|
|
|
976
1400
|
const calldata = fromArray(foreignCalldata);
|
|
977
1401
|
const isStaticCall = fromSingle(foreignIsStaticCall).toBool();
|
|
978
1402
|
|
|
979
|
-
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
|
+
});
|
|
980
1416
|
|
|
981
1417
|
return toForeignCallResult([toArray(returnValues)]);
|
|
982
1418
|
}
|
|
983
1419
|
|
|
984
|
-
|
|
985
|
-
|
|
1420
|
+
// eslint-disable-next-line camelcase
|
|
1421
|
+
async aztec_prv_getSenderForTags() {
|
|
1422
|
+
const sender = await this.handlerAsPrivate().getSenderForTags();
|
|
986
1423
|
|
|
987
1424
|
// Return a Noir Option struct with `some` and `value` fields
|
|
988
1425
|
if (sender === undefined) {
|
|
@@ -994,19 +1431,21 @@ export class RPCTranslator {
|
|
|
994
1431
|
}
|
|
995
1432
|
}
|
|
996
1433
|
|
|
997
|
-
|
|
1434
|
+
// eslint-disable-next-line camelcase
|
|
1435
|
+
async aztec_prv_setSenderForTags(foreignSenderForTags: ForeignCallSingle) {
|
|
998
1436
|
const senderForTags = AztecAddress.fromField(fromSingle(foreignSenderForTags));
|
|
999
1437
|
|
|
1000
|
-
await this.handlerAsPrivate().
|
|
1438
|
+
await this.handlerAsPrivate().setSenderForTags(senderForTags);
|
|
1001
1439
|
|
|
1002
1440
|
return toForeignCallResult([]);
|
|
1003
1441
|
}
|
|
1004
1442
|
|
|
1005
|
-
|
|
1443
|
+
// eslint-disable-next-line camelcase
|
|
1444
|
+
async aztec_prv_getNextAppTagAsSender(foreignSender: ForeignCallSingle, foreignRecipient: ForeignCallSingle) {
|
|
1006
1445
|
const sender = AztecAddress.fromField(fromSingle(foreignSender));
|
|
1007
1446
|
const recipient = AztecAddress.fromField(fromSingle(foreignRecipient));
|
|
1008
1447
|
|
|
1009
|
-
const nextAppTag = await this.handlerAsPrivate().
|
|
1448
|
+
const nextAppTag = await this.handlerAsPrivate().getNextAppTagAsSender(sender, recipient);
|
|
1010
1449
|
|
|
1011
1450
|
return toForeignCallResult([toSingle(nextAppTag.value)]);
|
|
1012
1451
|
}
|