@aztec/txe 0.0.1-commit.54489865 → 0.0.1-commit.5914bae
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/index.d.ts +1 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +88 -54
- package/dest/oracle/interfaces.d.ts +29 -28
- package/dest/oracle/interfaces.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.d.ts +13 -13
- package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.js +12 -12
- package/dest/oracle/txe_oracle_top_level_context.d.ts +28 -23
- package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_top_level_context.js +144 -58
- package/dest/rpc_translator.d.ts +121 -83
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +399 -164
- package/dest/state_machine/archiver.d.ts +3 -3
- package/dest/state_machine/archiver.d.ts.map +1 -1
- package/dest/state_machine/archiver.js +7 -7
- package/dest/state_machine/dummy_p2p_client.d.ts +16 -12
- package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
- package/dest/state_machine/dummy_p2p_client.js +28 -16
- package/dest/state_machine/index.d.ts +7 -5
- package/dest/state_machine/index.d.ts.map +1 -1
- package/dest/state_machine/index.js +19 -10
- package/dest/state_machine/mock_epoch_cache.d.ts +3 -1
- package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
- package/dest/state_machine/mock_epoch_cache.js +4 -0
- 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 +10 -6
- package/dest/txe_session.d.ts.map +1 -1
- package/dest/txe_session.js +97 -26
- package/dest/util/encoding.d.ts +40 -41
- package/dest/util/encoding.d.ts.map +1 -1
- package/dest/util/txe_public_contract_data_source.d.ts +2 -3
- package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
- package/dest/util/txe_public_contract_data_source.js +5 -22
- package/dest/utils/block_creation.d.ts +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 +32 -31
- package/src/oracle/txe_oracle_public_context.ts +12 -12
- package/src/oracle/txe_oracle_top_level_context.ts +167 -110
- package/src/rpc_translator.ts +463 -181
- package/src/state_machine/archiver.ts +7 -5
- package/src/state_machine/dummy_p2p_client.ts +40 -22
- package/src/state_machine/index.ts +29 -9
- package/src/state_machine/mock_epoch_cache.ts +5 -0
- package/src/state_machine/synchronizer.ts +4 -4
- package/src/txe_session.ts +109 -85
- package/src/util/txe_public_contract_data_source.ts +10 -36
- 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/dest/rpc_translator.js
CHANGED
|
@@ -6,7 +6,7 @@ import { EventSelector, FunctionSelector, NoteSelector } from '@aztec/stdlib/abi
|
|
|
6
6
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
7
7
|
import { BlockHash } from '@aztec/stdlib/block';
|
|
8
8
|
import { addressFromSingle, arrayOfArraysToBoundedVecOfArrays, arrayToBoundedVec, bufferToU8Array, fromArray, fromSingle, fromUintArray, fromUintBoundedVec, toArray, toForeignCallResult, toSingle } from './util/encoding.js';
|
|
9
|
-
const MAX_EVENT_LEN =
|
|
9
|
+
const MAX_EVENT_LEN = 10; // This is MAX_MESSAGE_CONTENT_LEN - PRIVATE_EVENT_MSG_PLAINTEXT_RESERVED_FIELDS_LEN
|
|
10
10
|
const MAX_PRIVATE_EVENTS_PER_TXE_QUERY = 5;
|
|
11
11
|
export class UnavailableOracleError extends Error {
|
|
12
12
|
constructor(oracleName){
|
|
@@ -61,59 +61,69 @@ export class RPCTranslator {
|
|
|
61
61
|
return this.oracleHandler;
|
|
62
62
|
}
|
|
63
63
|
// TXE session state transition functions - these get handled by the state handler
|
|
64
|
-
|
|
64
|
+
// eslint-disable-next-line camelcase
|
|
65
|
+
async aztec_txe_setTopLevelTXEContext() {
|
|
65
66
|
await this.stateHandler.enterTopLevelState();
|
|
66
67
|
return toForeignCallResult([]);
|
|
67
68
|
}
|
|
68
|
-
|
|
69
|
+
// eslint-disable-next-line camelcase
|
|
70
|
+
async aztec_txe_setPrivateTXEContext(foreignContractAddressIsSome, foreignContractAddressValue, foreignAnchorBlockNumberIsSome, foreignAnchorBlockNumberValue) {
|
|
69
71
|
const contractAddress = fromSingle(foreignContractAddressIsSome).toBool() ? AztecAddress.fromField(fromSingle(foreignContractAddressValue)) : undefined;
|
|
70
72
|
const anchorBlockNumber = fromSingle(foreignAnchorBlockNumberIsSome).toBool() ? BlockNumber(fromSingle(foreignAnchorBlockNumberValue).toNumber()) : undefined;
|
|
71
73
|
const privateContextInputs = await this.stateHandler.enterPrivateState(contractAddress, anchorBlockNumber);
|
|
72
74
|
return toForeignCallResult(privateContextInputs.toFields().map(toSingle));
|
|
73
75
|
}
|
|
74
|
-
|
|
76
|
+
// eslint-disable-next-line camelcase
|
|
77
|
+
async aztec_txe_setPublicTXEContext(foreignContractAddressIsSome, foreignContractAddressValue) {
|
|
75
78
|
const contractAddress = fromSingle(foreignContractAddressIsSome).toBool() ? AztecAddress.fromField(fromSingle(foreignContractAddressValue)) : undefined;
|
|
76
79
|
await this.stateHandler.enterPublicState(contractAddress);
|
|
77
80
|
return toForeignCallResult([]);
|
|
78
81
|
}
|
|
79
|
-
|
|
82
|
+
// eslint-disable-next-line camelcase
|
|
83
|
+
async aztec_txe_setUtilityTXEContext(foreignContractAddressIsSome, foreignContractAddressValue) {
|
|
80
84
|
const contractAddress = fromSingle(foreignContractAddressIsSome).toBool() ? AztecAddress.fromField(fromSingle(foreignContractAddressValue)) : undefined;
|
|
81
85
|
await this.stateHandler.enterUtilityState(contractAddress);
|
|
82
86
|
return toForeignCallResult([]);
|
|
83
87
|
}
|
|
84
88
|
// Other oracles - these get handled by the oracle handler
|
|
85
89
|
// TXE-specific oracles
|
|
86
|
-
|
|
87
|
-
|
|
90
|
+
// eslint-disable-next-line camelcase
|
|
91
|
+
aztec_txe_getDefaultAddress() {
|
|
92
|
+
const defaultAddress = this.handlerAsTxe().getDefaultAddress();
|
|
88
93
|
return toForeignCallResult([
|
|
89
94
|
toSingle(defaultAddress)
|
|
90
95
|
]);
|
|
91
96
|
}
|
|
92
|
-
|
|
93
|
-
|
|
97
|
+
// eslint-disable-next-line camelcase
|
|
98
|
+
async aztec_txe_getNextBlockNumber() {
|
|
99
|
+
const nextBlockNumber = await this.handlerAsTxe().getNextBlockNumber();
|
|
94
100
|
return toForeignCallResult([
|
|
95
101
|
toSingle(nextBlockNumber)
|
|
96
102
|
]);
|
|
97
103
|
}
|
|
98
|
-
|
|
99
|
-
|
|
104
|
+
// eslint-disable-next-line camelcase
|
|
105
|
+
async aztec_txe_getNextBlockTimestamp() {
|
|
106
|
+
const nextBlockTimestamp = await this.handlerAsTxe().getNextBlockTimestamp();
|
|
100
107
|
return toForeignCallResult([
|
|
101
108
|
toSingle(nextBlockTimestamp)
|
|
102
109
|
]);
|
|
103
110
|
}
|
|
104
|
-
|
|
111
|
+
// eslint-disable-next-line camelcase
|
|
112
|
+
async aztec_txe_advanceBlocksBy(foreignBlocks) {
|
|
105
113
|
const blocks = fromSingle(foreignBlocks).toNumber();
|
|
106
|
-
await this.handlerAsTxe().
|
|
114
|
+
await this.handlerAsTxe().advanceBlocksBy(blocks);
|
|
107
115
|
return toForeignCallResult([]);
|
|
108
116
|
}
|
|
109
|
-
|
|
117
|
+
// eslint-disable-next-line camelcase
|
|
118
|
+
aztec_txe_advanceTimestampBy(foreignDuration) {
|
|
110
119
|
const duration = fromSingle(foreignDuration).toBigInt();
|
|
111
|
-
this.handlerAsTxe().
|
|
120
|
+
this.handlerAsTxe().advanceTimestampBy(duration);
|
|
112
121
|
return toForeignCallResult([]);
|
|
113
122
|
}
|
|
114
|
-
|
|
123
|
+
// eslint-disable-next-line camelcase
|
|
124
|
+
async aztec_txe_deploy(artifact, instance, foreignSecret) {
|
|
115
125
|
const secret = fromSingle(foreignSecret);
|
|
116
|
-
await this.handlerAsTxe().
|
|
126
|
+
await this.handlerAsTxe().deploy(artifact, instance, secret);
|
|
117
127
|
return toForeignCallResult([
|
|
118
128
|
toArray([
|
|
119
129
|
instance.salt,
|
|
@@ -124,59 +134,74 @@ export class RPCTranslator {
|
|
|
124
134
|
])
|
|
125
135
|
]);
|
|
126
136
|
}
|
|
127
|
-
|
|
137
|
+
// eslint-disable-next-line camelcase
|
|
138
|
+
async aztec_txe_createAccount(foreignSecret) {
|
|
128
139
|
const secret = fromSingle(foreignSecret);
|
|
129
|
-
const completeAddress = await this.handlerAsTxe().
|
|
140
|
+
const completeAddress = await this.handlerAsTxe().createAccount(secret);
|
|
130
141
|
return toForeignCallResult([
|
|
131
142
|
toSingle(completeAddress.address),
|
|
132
143
|
...completeAddress.publicKeys.toFields().map(toSingle)
|
|
133
144
|
]);
|
|
134
145
|
}
|
|
135
|
-
|
|
146
|
+
// eslint-disable-next-line camelcase
|
|
147
|
+
async aztec_txe_addAccount(artifact, instance, foreignSecret) {
|
|
136
148
|
const secret = fromSingle(foreignSecret);
|
|
137
|
-
const completeAddress = await this.handlerAsTxe().
|
|
149
|
+
const completeAddress = await this.handlerAsTxe().addAccount(artifact, instance, secret);
|
|
138
150
|
return toForeignCallResult([
|
|
139
151
|
toSingle(completeAddress.address),
|
|
140
152
|
...completeAddress.publicKeys.toFields().map(toSingle)
|
|
141
153
|
]);
|
|
142
154
|
}
|
|
143
|
-
|
|
155
|
+
// eslint-disable-next-line camelcase
|
|
156
|
+
async aztec_txe_addAuthWitness(foreignAddress, foreignMessageHash) {
|
|
144
157
|
const address = addressFromSingle(foreignAddress);
|
|
145
158
|
const messageHash = fromSingle(foreignMessageHash);
|
|
146
|
-
await this.handlerAsTxe().
|
|
159
|
+
await this.handlerAsTxe().addAuthWitness(address, messageHash);
|
|
147
160
|
return toForeignCallResult([]);
|
|
148
161
|
}
|
|
149
162
|
// PXE oracles
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
163
|
+
// eslint-disable-next-line camelcase
|
|
164
|
+
aztec_utl_assertCompatibleOracleVersionV2(foreignMajor, foreignMinor) {
|
|
165
|
+
const major = fromSingle(foreignMajor).toNumber();
|
|
166
|
+
const minor = fromSingle(foreignMinor).toNumber();
|
|
167
|
+
this.handlerAsMisc().assertCompatibleOracleVersion(major, minor);
|
|
153
168
|
return toForeignCallResult([]);
|
|
154
169
|
}
|
|
155
|
-
|
|
156
|
-
|
|
170
|
+
// eslint-disable-next-line camelcase
|
|
171
|
+
aztec_utl_getRandomField() {
|
|
172
|
+
const randomField = this.handlerAsMisc().getRandomField();
|
|
157
173
|
return toForeignCallResult([
|
|
158
174
|
toSingle(randomField)
|
|
159
175
|
]);
|
|
160
176
|
}
|
|
161
|
-
|
|
162
|
-
|
|
177
|
+
// eslint-disable-next-line camelcase
|
|
178
|
+
async aztec_txe_getLastBlockTimestamp() {
|
|
179
|
+
const timestamp = await this.handlerAsTxe().getLastBlockTimestamp();
|
|
163
180
|
return toForeignCallResult([
|
|
164
181
|
toSingle(new Fr(timestamp))
|
|
165
182
|
]);
|
|
166
183
|
}
|
|
167
|
-
|
|
168
|
-
|
|
184
|
+
// eslint-disable-next-line camelcase
|
|
185
|
+
async aztec_txe_getLastTxEffects() {
|
|
186
|
+
const { txHash, noteHashes, nullifiers } = await this.handlerAsTxe().getLastTxEffects();
|
|
169
187
|
return toForeignCallResult([
|
|
170
188
|
toSingle(txHash.hash),
|
|
171
189
|
...arrayToBoundedVec(toArray(noteHashes), MAX_NOTE_HASHES_PER_TX),
|
|
172
190
|
...arrayToBoundedVec(toArray(nullifiers), MAX_NULLIFIERS_PER_TX)
|
|
173
191
|
]);
|
|
174
192
|
}
|
|
175
|
-
|
|
193
|
+
// eslint-disable-next-line camelcase
|
|
194
|
+
async aztec_txe_getPrivateEvents(foreignSelector, foreignContractAddress, foreignScope) {
|
|
176
195
|
const selector = EventSelector.fromField(fromSingle(foreignSelector));
|
|
177
196
|
const contractAddress = addressFromSingle(foreignContractAddress);
|
|
178
197
|
const scope = addressFromSingle(foreignScope);
|
|
179
|
-
|
|
198
|
+
// TODO(F-335): Avoid doing the following 2 calls here.
|
|
199
|
+
{
|
|
200
|
+
await this.handlerAsTxe().syncContractNonOracleMethod(contractAddress, scope, this.stateHandler.getCurrentJob());
|
|
201
|
+
// We cycle job to commit the stores after the contract sync.
|
|
202
|
+
await this.stateHandler.cycleJob();
|
|
203
|
+
}
|
|
204
|
+
const events = await this.handlerAsTxe().getPrivateEvents(selector, contractAddress, scope);
|
|
180
205
|
if (events.length > MAX_PRIVATE_EVENTS_PER_TXE_QUERY) {
|
|
181
206
|
throw new Error(`Array of length ${events.length} larger than maxLen ${MAX_PRIVATE_EVENTS_PER_TXE_QUERY}`);
|
|
182
207
|
}
|
|
@@ -194,48 +219,54 @@ export class RPCTranslator {
|
|
|
194
219
|
toSingle(queryLength)
|
|
195
220
|
]);
|
|
196
221
|
}
|
|
197
|
-
|
|
222
|
+
// eslint-disable-next-line camelcase
|
|
223
|
+
aztec_prv_setHashPreimage(foreignValues, foreignHash) {
|
|
198
224
|
const values = fromArray(foreignValues);
|
|
199
225
|
const hash = fromSingle(foreignHash);
|
|
200
|
-
this.handlerAsPrivate().
|
|
226
|
+
this.handlerAsPrivate().setHashPreimage(values, hash);
|
|
201
227
|
return toForeignCallResult([]);
|
|
202
228
|
}
|
|
203
|
-
|
|
229
|
+
// eslint-disable-next-line camelcase
|
|
230
|
+
async aztec_prv_getHashPreimage(foreignHash) {
|
|
204
231
|
const hash = fromSingle(foreignHash);
|
|
205
|
-
const returns = await this.handlerAsPrivate().
|
|
232
|
+
const returns = await this.handlerAsPrivate().getHashPreimage(hash);
|
|
206
233
|
return toForeignCallResult([
|
|
207
234
|
toArray(returns)
|
|
208
235
|
]);
|
|
209
236
|
}
|
|
210
237
|
// When the argument is a slice, noir automatically adds a length field to oracle call.
|
|
211
238
|
// When the argument is an array, we add the field length manually to the signature.
|
|
212
|
-
|
|
239
|
+
// eslint-disable-next-line camelcase
|
|
240
|
+
async aztec_utl_log(foreignLevel, foreignMessage, _foreignLength, foreignFields) {
|
|
213
241
|
const level = fromSingle(foreignLevel).toNumber();
|
|
214
242
|
const message = fromArray(foreignMessage).map((field)=>String.fromCharCode(field.toNumber())).join('');
|
|
215
243
|
const fields = fromArray(foreignFields);
|
|
216
|
-
this.handlerAsMisc().
|
|
244
|
+
await this.handlerAsMisc().log(level, message, fields);
|
|
217
245
|
return toForeignCallResult([]);
|
|
218
246
|
}
|
|
219
|
-
|
|
247
|
+
// eslint-disable-next-line camelcase
|
|
248
|
+
async aztec_utl_getFromPublicStorage(foreignBlockHash, foreignContractAddress, foreignStartStorageSlot, foreignNumberOfElements) {
|
|
220
249
|
const blockHash = new BlockHash(fromSingle(foreignBlockHash));
|
|
221
250
|
const contractAddress = addressFromSingle(foreignContractAddress);
|
|
222
251
|
const startStorageSlot = fromSingle(foreignStartStorageSlot);
|
|
223
252
|
const numberOfElements = fromSingle(foreignNumberOfElements).toNumber();
|
|
224
|
-
const values = await this.handlerAsUtility().
|
|
253
|
+
const values = await this.handlerAsUtility().getFromPublicStorage(blockHash, contractAddress, startStorageSlot, numberOfElements);
|
|
225
254
|
return toForeignCallResult([
|
|
226
255
|
toArray(values)
|
|
227
256
|
]);
|
|
228
257
|
}
|
|
229
|
-
|
|
258
|
+
// eslint-disable-next-line camelcase
|
|
259
|
+
async aztec_utl_getPublicDataWitness(foreignBlockHash, foreignLeafSlot) {
|
|
230
260
|
const blockHash = new BlockHash(fromSingle(foreignBlockHash));
|
|
231
261
|
const leafSlot = fromSingle(foreignLeafSlot);
|
|
232
|
-
const witness = await this.handlerAsUtility().
|
|
262
|
+
const witness = await this.handlerAsUtility().getPublicDataWitness(blockHash, leafSlot);
|
|
233
263
|
if (!witness) {
|
|
234
264
|
throw new Error(`Public data witness not found for slot ${leafSlot} at block ${blockHash.toString()}.`);
|
|
235
265
|
}
|
|
236
266
|
return toForeignCallResult(witness.toNoirRepresentation());
|
|
237
267
|
}
|
|
238
|
-
|
|
268
|
+
// eslint-disable-next-line camelcase
|
|
269
|
+
async aztec_utl_getNotes(foreignOwnerIsSome, foreignOwnerValue, foreignStorageSlot, foreignNumSelects, foreignSelectByIndexes, foreignSelectByOffsets, foreignSelectByLengths, foreignSelectValues, foreignSelectComparators, foreignSortByIndexes, foreignSortByOffsets, foreignSortByLengths, foreignSortOrder, foreignLimit, foreignOffset, foreignStatus, foreignMaxNotes, foreignPackedHintedNoteLength) {
|
|
239
270
|
// Parse Option<AztecAddress>: ownerIsSome is 0 for None, 1 for Some
|
|
240
271
|
const owner = fromSingle(foreignOwnerIsSome).toBool() ? AztecAddress.fromField(fromSingle(foreignOwnerValue)) : undefined;
|
|
241
272
|
const storageSlot = fromSingle(foreignStorageSlot);
|
|
@@ -254,7 +285,7 @@ export class RPCTranslator {
|
|
|
254
285
|
const status = fromSingle(foreignStatus).toNumber();
|
|
255
286
|
const maxNotes = fromSingle(foreignMaxNotes).toNumber();
|
|
256
287
|
const packedHintedNoteLength = fromSingle(foreignPackedHintedNoteLength).toNumber();
|
|
257
|
-
const noteDatas = await this.handlerAsUtility().
|
|
288
|
+
const noteDatas = await this.handlerAsUtility().getNotes(owner, storageSlot, numSelects, selectByIndexes, selectByOffsets, selectByLengths, selectValues, selectComparators, sortByIndexes, sortByOffsets, sortByLengths, sortOrder, limit, offset, status);
|
|
258
289
|
const returnDataAsArrayOfArrays = noteDatas.map((noteData)=>packAsHintedNote({
|
|
259
290
|
contractAddress: noteData.contractAddress,
|
|
260
291
|
owner: noteData.owner,
|
|
@@ -269,7 +300,8 @@ export class RPCTranslator {
|
|
|
269
300
|
// At last we convert the array of arrays to a bounded vec of arrays
|
|
270
301
|
return toForeignCallResult(arrayOfArraysToBoundedVecOfArrays(returnDataAsArrayOfForeignCallSingleArrays, maxNotes, packedHintedNoteLength));
|
|
271
302
|
}
|
|
272
|
-
|
|
303
|
+
// eslint-disable-next-line camelcase
|
|
304
|
+
aztec_prv_notifyCreatedNote(foreignOwner, foreignStorageSlot, foreignRandomness, foreignNoteTypeId, foreignNote, foreignNoteHash, foreignCounter) {
|
|
273
305
|
const owner = addressFromSingle(foreignOwner);
|
|
274
306
|
const storageSlot = fromSingle(foreignStorageSlot);
|
|
275
307
|
const randomness = fromSingle(foreignRandomness);
|
|
@@ -277,39 +309,44 @@ export class RPCTranslator {
|
|
|
277
309
|
const note = fromArray(foreignNote);
|
|
278
310
|
const noteHash = fromSingle(foreignNoteHash);
|
|
279
311
|
const counter = fromSingle(foreignCounter).toNumber();
|
|
280
|
-
this.handlerAsPrivate().
|
|
312
|
+
this.handlerAsPrivate().notifyCreatedNote(owner, storageSlot, randomness, noteTypeId, note, noteHash, counter);
|
|
281
313
|
return toForeignCallResult([]);
|
|
282
314
|
}
|
|
283
|
-
|
|
315
|
+
// eslint-disable-next-line camelcase
|
|
316
|
+
async aztec_prv_notifyNullifiedNote(foreignInnerNullifier, foreignNoteHash, foreignCounter) {
|
|
284
317
|
const innerNullifier = fromSingle(foreignInnerNullifier);
|
|
285
318
|
const noteHash = fromSingle(foreignNoteHash);
|
|
286
319
|
const counter = fromSingle(foreignCounter).toNumber();
|
|
287
|
-
await this.handlerAsPrivate().
|
|
320
|
+
await this.handlerAsPrivate().notifyNullifiedNote(innerNullifier, noteHash, counter);
|
|
288
321
|
return toForeignCallResult([]);
|
|
289
322
|
}
|
|
290
|
-
|
|
323
|
+
// eslint-disable-next-line camelcase
|
|
324
|
+
async aztec_prv_notifyCreatedNullifier(foreignInnerNullifier) {
|
|
291
325
|
const innerNullifier = fromSingle(foreignInnerNullifier);
|
|
292
|
-
await this.handlerAsPrivate().
|
|
326
|
+
await this.handlerAsPrivate().notifyCreatedNullifier(innerNullifier);
|
|
293
327
|
return toForeignCallResult([]);
|
|
294
328
|
}
|
|
295
|
-
|
|
329
|
+
// eslint-disable-next-line camelcase
|
|
330
|
+
async aztec_prv_isNullifierPending(foreignInnerNullifier, foreignContractAddress) {
|
|
296
331
|
const innerNullifier = fromSingle(foreignInnerNullifier);
|
|
297
332
|
const contractAddress = addressFromSingle(foreignContractAddress);
|
|
298
|
-
const isPending = await this.handlerAsPrivate().
|
|
333
|
+
const isPending = await this.handlerAsPrivate().isNullifierPending(innerNullifier, contractAddress);
|
|
299
334
|
return toForeignCallResult([
|
|
300
335
|
toSingle(new Fr(isPending))
|
|
301
336
|
]);
|
|
302
337
|
}
|
|
303
|
-
|
|
338
|
+
// eslint-disable-next-line camelcase
|
|
339
|
+
async aztec_utl_doesNullifierExist(foreignInnerNullifier) {
|
|
304
340
|
const innerNullifier = fromSingle(foreignInnerNullifier);
|
|
305
|
-
const exists = await this.handlerAsUtility().
|
|
341
|
+
const exists = await this.handlerAsUtility().doesNullifierExist(innerNullifier);
|
|
306
342
|
return toForeignCallResult([
|
|
307
343
|
toSingle(new Fr(exists))
|
|
308
344
|
]);
|
|
309
345
|
}
|
|
310
|
-
|
|
346
|
+
// eslint-disable-next-line camelcase
|
|
347
|
+
async aztec_utl_getContractInstance(foreignAddress) {
|
|
311
348
|
const address = addressFromSingle(foreignAddress);
|
|
312
|
-
const instance = await this.handlerAsUtility().
|
|
349
|
+
const instance = await this.handlerAsUtility().getContractInstance(address);
|
|
313
350
|
return toForeignCallResult([
|
|
314
351
|
instance.salt,
|
|
315
352
|
instance.deployer.toField(),
|
|
@@ -318,36 +355,53 @@ export class RPCTranslator {
|
|
|
318
355
|
...instance.publicKeys.toFields()
|
|
319
356
|
].map(toSingle));
|
|
320
357
|
}
|
|
321
|
-
|
|
358
|
+
// eslint-disable-next-line camelcase
|
|
359
|
+
async aztec_utl_getPublicKeysAndPartialAddress(foreignAddress) {
|
|
322
360
|
const address = addressFromSingle(foreignAddress);
|
|
323
|
-
const
|
|
324
|
-
return
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
361
|
+
const result = await this.handlerAsUtility().getPublicKeysAndPartialAddress(address);
|
|
362
|
+
// We are going to return a Noir Option struct to represent the possibility of null values. Options are a struct
|
|
363
|
+
// with two fields: `some` (a boolean) and `value` (a field array in this case).
|
|
364
|
+
if (result === undefined) {
|
|
365
|
+
// No data was found so we set `some` to 0 and pad `value` with zeros get the correct return size.
|
|
366
|
+
return toForeignCallResult([
|
|
367
|
+
toSingle(new Fr(0)),
|
|
368
|
+
toArray(Array(13).fill(new Fr(0)))
|
|
369
|
+
]);
|
|
370
|
+
} else {
|
|
371
|
+
// Data was found so we set `some` to 1 and return it along with `value`.
|
|
372
|
+
return toForeignCallResult([
|
|
373
|
+
toSingle(new Fr(1)),
|
|
374
|
+
toArray([
|
|
375
|
+
...result.publicKeys.toFields(),
|
|
376
|
+
result.partialAddress
|
|
377
|
+
])
|
|
378
|
+
]);
|
|
379
|
+
}
|
|
330
380
|
}
|
|
331
|
-
|
|
381
|
+
// eslint-disable-next-line camelcase
|
|
382
|
+
async aztec_utl_getKeyValidationRequest(foreignPkMHash) {
|
|
332
383
|
const pkMHash = fromSingle(foreignPkMHash);
|
|
333
|
-
const keyValidationRequest = await this.handlerAsUtility().
|
|
384
|
+
const keyValidationRequest = await this.handlerAsUtility().getKeyValidationRequest(pkMHash);
|
|
334
385
|
return toForeignCallResult(keyValidationRequest.toFields().map(toSingle));
|
|
335
386
|
}
|
|
336
|
-
|
|
387
|
+
// eslint-disable-next-line camelcase
|
|
388
|
+
aztec_prv_callPrivateFunction(_foreignTargetContractAddress, _foreignFunctionSelector, _foreignArgsHash, _foreignSideEffectCounter, _foreignIsStaticCall) {
|
|
337
389
|
throw new Error('Contract calls are forbidden inside a `TestEnvironment::private_context`, use `private_call` instead');
|
|
338
390
|
}
|
|
339
|
-
|
|
391
|
+
// eslint-disable-next-line camelcase
|
|
392
|
+
async aztec_utl_getNullifierMembershipWitness(foreignBlockHash, foreignNullifier) {
|
|
340
393
|
const blockHash = new BlockHash(fromSingle(foreignBlockHash));
|
|
341
394
|
const nullifier = fromSingle(foreignNullifier);
|
|
342
|
-
const witness = await this.handlerAsUtility().
|
|
395
|
+
const witness = await this.handlerAsUtility().getNullifierMembershipWitness(blockHash, nullifier);
|
|
343
396
|
if (!witness) {
|
|
344
397
|
throw new Error(`Nullifier membership witness not found at block ${blockHash}.`);
|
|
345
398
|
}
|
|
346
399
|
return toForeignCallResult(witness.toNoirRepresentation());
|
|
347
400
|
}
|
|
348
|
-
|
|
401
|
+
// eslint-disable-next-line camelcase
|
|
402
|
+
async aztec_utl_getAuthWitness(foreignMessageHash) {
|
|
349
403
|
const messageHash = fromSingle(foreignMessageHash);
|
|
350
|
-
const authWitness = await this.handlerAsUtility().
|
|
404
|
+
const authWitness = await this.handlerAsUtility().getAuthWitness(messageHash);
|
|
351
405
|
if (!authWitness) {
|
|
352
406
|
throw new Error(`Auth witness not found for message hash ${messageHash}.`);
|
|
353
407
|
}
|
|
@@ -355,92 +409,152 @@ export class RPCTranslator {
|
|
|
355
409
|
toArray(authWitness)
|
|
356
410
|
]);
|
|
357
411
|
}
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
}
|
|
361
|
-
privateNotifySetPublicTeardownFunctionCall(_foreignTargetContractAddress, _foreignCalldataHash, _foreignSideEffectCounter, _foreignIsStaticCall) {
|
|
412
|
+
// eslint-disable-next-line camelcase
|
|
413
|
+
aztec_prv_assertValidPublicCalldata(_foreignCalldataHash) {
|
|
362
414
|
throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
|
|
363
415
|
}
|
|
364
|
-
|
|
416
|
+
// eslint-disable-next-line camelcase
|
|
417
|
+
aztec_prv_notifyRevertiblePhaseStart(_foreignMinRevertibleSideEffectCounter) {
|
|
365
418
|
throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
|
|
366
419
|
}
|
|
367
|
-
|
|
420
|
+
// eslint-disable-next-line camelcase
|
|
421
|
+
async aztec_prv_isExecutionInRevertiblePhase(foreignSideEffectCounter) {
|
|
368
422
|
const sideEffectCounter = fromSingle(foreignSideEffectCounter).toNumber();
|
|
369
|
-
const isRevertible = await this.handlerAsPrivate().
|
|
423
|
+
const isRevertible = await this.handlerAsPrivate().isExecutionInRevertiblePhase(sideEffectCounter);
|
|
370
424
|
return toForeignCallResult([
|
|
371
425
|
toSingle(new Fr(isRevertible))
|
|
372
426
|
]);
|
|
373
427
|
}
|
|
374
|
-
|
|
375
|
-
|
|
428
|
+
// eslint-disable-next-line camelcase
|
|
429
|
+
aztec_utl_getUtilityContext() {
|
|
430
|
+
const context = this.handlerAsUtility().getUtilityContext();
|
|
376
431
|
return toForeignCallResult(context.toNoirRepresentation());
|
|
377
432
|
}
|
|
378
|
-
|
|
433
|
+
// eslint-disable-next-line camelcase
|
|
434
|
+
async aztec_utl_getBlockHeader(foreignBlockNumber) {
|
|
379
435
|
const blockNumber = BlockNumber(fromSingle(foreignBlockNumber).toNumber());
|
|
380
|
-
const header = await this.handlerAsUtility().
|
|
436
|
+
const header = await this.handlerAsUtility().getBlockHeader(blockNumber);
|
|
381
437
|
if (!header) {
|
|
382
438
|
throw new Error(`Block header not found for block ${blockNumber}.`);
|
|
383
439
|
}
|
|
384
440
|
return toForeignCallResult(header.toFields().map(toSingle));
|
|
385
441
|
}
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
const
|
|
389
|
-
const
|
|
442
|
+
// eslint-disable-next-line camelcase
|
|
443
|
+
async aztec_utl_getNoteHashMembershipWitness(foreignAnchorBlockHash, foreignNoteHash) {
|
|
444
|
+
const blockHash = new BlockHash(fromSingle(foreignAnchorBlockHash));
|
|
445
|
+
const noteHash = fromSingle(foreignNoteHash);
|
|
446
|
+
const witness = await this.handlerAsUtility().getNoteHashMembershipWitness(blockHash, noteHash);
|
|
390
447
|
if (!witness) {
|
|
391
|
-
throw new Error(`Note hash ${
|
|
448
|
+
throw new Error(`Note hash ${noteHash} not found in the note hash tree at block ${blockHash.toString()}.`);
|
|
392
449
|
}
|
|
393
450
|
return toForeignCallResult(witness.toNoirRepresentation());
|
|
394
451
|
}
|
|
395
|
-
|
|
452
|
+
// eslint-disable-next-line camelcase
|
|
453
|
+
async aztec_utl_getBlockHashMembershipWitness(foreignAnchorBlockHash, foreignBlockHash) {
|
|
454
|
+
const anchorBlockHash = new BlockHash(fromSingle(foreignAnchorBlockHash));
|
|
396
455
|
const blockHash = new BlockHash(fromSingle(foreignBlockHash));
|
|
397
|
-
const
|
|
398
|
-
const witness = await this.handlerAsUtility().utilityGetArchiveMembershipWitness(blockHash, leafValue);
|
|
456
|
+
const witness = await this.handlerAsUtility().getBlockHashMembershipWitness(anchorBlockHash, blockHash);
|
|
399
457
|
if (!witness) {
|
|
400
|
-
throw new Error(`Block hash ${
|
|
458
|
+
throw new Error(`Block hash ${blockHash.toString()} not found in the archive tree at anchor block ${anchorBlockHash.toString()}.`);
|
|
401
459
|
}
|
|
402
460
|
return toForeignCallResult(witness.toNoirRepresentation());
|
|
403
461
|
}
|
|
404
|
-
|
|
462
|
+
// eslint-disable-next-line camelcase
|
|
463
|
+
async aztec_utl_getLowNullifierMembershipWitness(foreignBlockHash, foreignNullifier) {
|
|
405
464
|
const blockHash = new BlockHash(fromSingle(foreignBlockHash));
|
|
406
465
|
const nullifier = fromSingle(foreignNullifier);
|
|
407
|
-
const witness = await this.handlerAsUtility().
|
|
466
|
+
const witness = await this.handlerAsUtility().getLowNullifierMembershipWitness(blockHash, nullifier);
|
|
408
467
|
if (!witness) {
|
|
409
468
|
throw new Error(`Low nullifier witness not found for nullifier ${nullifier} at block ${blockHash}.`);
|
|
410
469
|
}
|
|
411
470
|
return toForeignCallResult(witness.toNoirRepresentation());
|
|
412
471
|
}
|
|
413
|
-
|
|
472
|
+
// eslint-disable-next-line camelcase
|
|
473
|
+
async aztec_utl_getPendingTaggedLogs(foreignPendingTaggedLogArrayBaseSlot, foreignScope) {
|
|
414
474
|
const pendingTaggedLogArrayBaseSlot = fromSingle(foreignPendingTaggedLogArrayBaseSlot);
|
|
415
|
-
|
|
475
|
+
const scope = AztecAddress.fromField(fromSingle(foreignScope));
|
|
476
|
+
await this.handlerAsUtility().getPendingTaggedLogs(pendingTaggedLogArrayBaseSlot, scope);
|
|
416
477
|
return toForeignCallResult([]);
|
|
417
478
|
}
|
|
418
|
-
|
|
479
|
+
// eslint-disable-next-line camelcase
|
|
480
|
+
async aztec_utl_getPendingTaggedLogs_v2(foreignScope) {
|
|
481
|
+
const scope = AztecAddress.fromField(fromSingle(foreignScope));
|
|
482
|
+
const slot = await this.handlerAsUtility().getPendingTaggedLogsV2(scope);
|
|
483
|
+
return toForeignCallResult([
|
|
484
|
+
toSingle(slot)
|
|
485
|
+
]);
|
|
486
|
+
}
|
|
487
|
+
// eslint-disable-next-line camelcase
|
|
488
|
+
async aztec_utl_validateAndStoreEnqueuedNotesAndEvents(foreignContractAddress, foreignNoteValidationRequestsArrayBaseSlot, foreignEventValidationRequestsArrayBaseSlot, foreignMaxNotePackedLen, foreignMaxEventSerializedLen, foreignScope) {
|
|
419
489
|
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
420
490
|
const noteValidationRequestsArrayBaseSlot = fromSingle(foreignNoteValidationRequestsArrayBaseSlot);
|
|
421
491
|
const eventValidationRequestsArrayBaseSlot = fromSingle(foreignEventValidationRequestsArrayBaseSlot);
|
|
422
|
-
|
|
492
|
+
const maxNotePackedLen = fromSingle(foreignMaxNotePackedLen).toNumber();
|
|
493
|
+
const maxEventSerializedLen = fromSingle(foreignMaxEventSerializedLen).toNumber();
|
|
494
|
+
const scope = AztecAddress.fromField(fromSingle(foreignScope));
|
|
495
|
+
await this.handlerAsUtility().validateAndStoreEnqueuedNotesAndEvents(contractAddress, noteValidationRequestsArrayBaseSlot, eventValidationRequestsArrayBaseSlot, maxNotePackedLen, maxEventSerializedLen, scope);
|
|
496
|
+
return toForeignCallResult([]);
|
|
497
|
+
}
|
|
498
|
+
// eslint-disable-next-line camelcase
|
|
499
|
+
async aztec_utl_validateAndStoreEnqueuedNotesAndEvents_v2(foreignNoteValidationRequestsArrayBaseSlot, foreignEventValidationRequestsArrayBaseSlot, foreignMaxNotePackedLen, foreignMaxEventSerializedLen, foreignScope) {
|
|
500
|
+
const noteValidationRequestsArrayBaseSlot = fromSingle(foreignNoteValidationRequestsArrayBaseSlot);
|
|
501
|
+
const eventValidationRequestsArrayBaseSlot = fromSingle(foreignEventValidationRequestsArrayBaseSlot);
|
|
502
|
+
const maxNotePackedLen = fromSingle(foreignMaxNotePackedLen).toNumber();
|
|
503
|
+
const maxEventSerializedLen = fromSingle(foreignMaxEventSerializedLen).toNumber();
|
|
504
|
+
const scope = AztecAddress.fromField(fromSingle(foreignScope));
|
|
505
|
+
await this.handlerAsUtility().validateAndStoreEnqueuedNotesAndEventsV2(noteValidationRequestsArrayBaseSlot, eventValidationRequestsArrayBaseSlot, maxNotePackedLen, maxEventSerializedLen, scope);
|
|
423
506
|
return toForeignCallResult([]);
|
|
424
507
|
}
|
|
425
|
-
|
|
508
|
+
// eslint-disable-next-line camelcase
|
|
509
|
+
async aztec_utl_getLogsByTag(foreignContractAddress, foreignLogRetrievalRequestsArrayBaseSlot, foreignLogRetrievalResponsesArrayBaseSlot, foreignScope) {
|
|
426
510
|
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
427
511
|
const logRetrievalRequestsArrayBaseSlot = fromSingle(foreignLogRetrievalRequestsArrayBaseSlot);
|
|
428
512
|
const logRetrievalResponsesArrayBaseSlot = fromSingle(foreignLogRetrievalResponsesArrayBaseSlot);
|
|
429
|
-
|
|
513
|
+
const scope = AztecAddress.fromField(fromSingle(foreignScope));
|
|
514
|
+
await this.handlerAsUtility().getLogsByTag(contractAddress, logRetrievalRequestsArrayBaseSlot, logRetrievalResponsesArrayBaseSlot, scope);
|
|
430
515
|
return toForeignCallResult([]);
|
|
431
516
|
}
|
|
432
|
-
|
|
517
|
+
// eslint-disable-next-line camelcase
|
|
518
|
+
async aztec_utl_getMessageContextsByTxHash(foreignContractAddress, foreignMessageContextRequestsArrayBaseSlot, foreignMessageContextResponsesArrayBaseSlot, foreignScope) {
|
|
519
|
+
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
520
|
+
const messageContextRequestsArrayBaseSlot = fromSingle(foreignMessageContextRequestsArrayBaseSlot);
|
|
521
|
+
const messageContextResponsesArrayBaseSlot = fromSingle(foreignMessageContextResponsesArrayBaseSlot);
|
|
522
|
+
const scope = AztecAddress.fromField(fromSingle(foreignScope));
|
|
523
|
+
await this.handlerAsUtility().getMessageContextsByTxHash(contractAddress, messageContextRequestsArrayBaseSlot, messageContextResponsesArrayBaseSlot, scope);
|
|
524
|
+
return toForeignCallResult([]);
|
|
525
|
+
}
|
|
526
|
+
// eslint-disable-next-line camelcase
|
|
527
|
+
async aztec_utl_getLogsByTag_v2(foreignRequestArrayBaseSlot) {
|
|
528
|
+
const requestArrayBaseSlot = fromSingle(foreignRequestArrayBaseSlot);
|
|
529
|
+
const responseSlot = await this.handlerAsUtility().getLogsByTagV2(requestArrayBaseSlot);
|
|
530
|
+
return toForeignCallResult([
|
|
531
|
+
toSingle(responseSlot)
|
|
532
|
+
]);
|
|
533
|
+
}
|
|
534
|
+
// eslint-disable-next-line camelcase
|
|
535
|
+
async aztec_utl_getMessageContextsByTxHash_v2(foreignRequestArrayBaseSlot) {
|
|
536
|
+
const requestArrayBaseSlot = fromSingle(foreignRequestArrayBaseSlot);
|
|
537
|
+
const responseSlot = await this.handlerAsUtility().getMessageContextsByTxHashV2(requestArrayBaseSlot);
|
|
538
|
+
return toForeignCallResult([
|
|
539
|
+
toSingle(responseSlot)
|
|
540
|
+
]);
|
|
541
|
+
}
|
|
542
|
+
// eslint-disable-next-line camelcase
|
|
543
|
+
aztec_utl_setCapsule(foreignContractAddress, foreignSlot, foreignCapsule, foreignScope) {
|
|
433
544
|
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
434
545
|
const slot = fromSingle(foreignSlot);
|
|
435
546
|
const capsule = fromArray(foreignCapsule);
|
|
436
|
-
|
|
547
|
+
const scope = AztecAddress.fromField(fromSingle(foreignScope));
|
|
548
|
+
this.handlerAsUtility().setCapsule(contractAddress, slot, capsule, scope);
|
|
437
549
|
return toForeignCallResult([]);
|
|
438
550
|
}
|
|
439
|
-
|
|
551
|
+
// eslint-disable-next-line camelcase
|
|
552
|
+
async aztec_utl_getCapsule(foreignContractAddress, foreignSlot, foreignTSize, foreignScope) {
|
|
440
553
|
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
441
554
|
const slot = fromSingle(foreignSlot);
|
|
442
555
|
const tSize = fromSingle(foreignTSize).toNumber();
|
|
443
|
-
const
|
|
556
|
+
const scope = AztecAddress.fromField(fromSingle(foreignScope));
|
|
557
|
+
const values = await this.handlerAsUtility().getCapsule(contractAddress, slot, scope);
|
|
444
558
|
// We are going to return a Noir Option struct to represent the possibility of null values. Options are a struct
|
|
445
559
|
// with two fields: `some` (a boolean) and `value` (a field array in this case).
|
|
446
560
|
if (values === null) {
|
|
@@ -457,197 +571,316 @@ export class RPCTranslator {
|
|
|
457
571
|
]);
|
|
458
572
|
}
|
|
459
573
|
}
|
|
460
|
-
|
|
574
|
+
// eslint-disable-next-line camelcase
|
|
575
|
+
aztec_utl_deleteCapsule(foreignContractAddress, foreignSlot, foreignScope) {
|
|
461
576
|
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
462
577
|
const slot = fromSingle(foreignSlot);
|
|
463
|
-
|
|
578
|
+
const scope = AztecAddress.fromField(fromSingle(foreignScope));
|
|
579
|
+
this.handlerAsUtility().deleteCapsule(contractAddress, slot, scope);
|
|
464
580
|
return toForeignCallResult([]);
|
|
465
581
|
}
|
|
466
|
-
|
|
582
|
+
// eslint-disable-next-line camelcase
|
|
583
|
+
async aztec_utl_copyCapsule(foreignContractAddress, foreignSrcSlot, foreignDstSlot, foreignNumEntries, foreignScope) {
|
|
467
584
|
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
468
585
|
const srcSlot = fromSingle(foreignSrcSlot);
|
|
469
586
|
const dstSlot = fromSingle(foreignDstSlot);
|
|
470
587
|
const numEntries = fromSingle(foreignNumEntries).toNumber();
|
|
471
|
-
|
|
588
|
+
const scope = AztecAddress.fromField(fromSingle(foreignScope));
|
|
589
|
+
await this.handlerAsUtility().copyCapsule(contractAddress, srcSlot, dstSlot, numEntries, scope);
|
|
590
|
+
return toForeignCallResult([]);
|
|
591
|
+
}
|
|
592
|
+
// eslint-disable-next-line camelcase
|
|
593
|
+
aztec_utl_pushEphemeral(foreignSlot, foreignElements) {
|
|
594
|
+
const slot = fromSingle(foreignSlot);
|
|
595
|
+
const elements = fromArray(foreignElements);
|
|
596
|
+
const newLen = this.handlerAsUtility().pushEphemeral(slot, elements);
|
|
597
|
+
return toForeignCallResult([
|
|
598
|
+
toSingle(new Fr(newLen))
|
|
599
|
+
]);
|
|
600
|
+
}
|
|
601
|
+
// eslint-disable-next-line camelcase
|
|
602
|
+
aztec_utl_popEphemeral(foreignSlot) {
|
|
603
|
+
const slot = fromSingle(foreignSlot);
|
|
604
|
+
const element = this.handlerAsUtility().popEphemeral(slot);
|
|
605
|
+
return toForeignCallResult([
|
|
606
|
+
toArray(element)
|
|
607
|
+
]);
|
|
608
|
+
}
|
|
609
|
+
// eslint-disable-next-line camelcase
|
|
610
|
+
aztec_utl_getEphemeral(foreignSlot, foreignIndex) {
|
|
611
|
+
const slot = fromSingle(foreignSlot);
|
|
612
|
+
const index = fromSingle(foreignIndex).toNumber();
|
|
613
|
+
const element = this.handlerAsUtility().getEphemeral(slot, index);
|
|
614
|
+
return toForeignCallResult([
|
|
615
|
+
toArray(element)
|
|
616
|
+
]);
|
|
617
|
+
}
|
|
618
|
+
// eslint-disable-next-line camelcase
|
|
619
|
+
aztec_utl_setEphemeral(foreignSlot, foreignIndex, foreignElements) {
|
|
620
|
+
const slot = fromSingle(foreignSlot);
|
|
621
|
+
const index = fromSingle(foreignIndex).toNumber();
|
|
622
|
+
const elements = fromArray(foreignElements);
|
|
623
|
+
this.handlerAsUtility().setEphemeral(slot, index, elements);
|
|
624
|
+
return toForeignCallResult([]);
|
|
625
|
+
}
|
|
626
|
+
// eslint-disable-next-line camelcase
|
|
627
|
+
aztec_utl_getEphemeralLen(foreignSlot) {
|
|
628
|
+
const slot = fromSingle(foreignSlot);
|
|
629
|
+
const len = this.handlerAsUtility().getEphemeralLen(slot);
|
|
630
|
+
return toForeignCallResult([
|
|
631
|
+
toSingle(new Fr(len))
|
|
632
|
+
]);
|
|
633
|
+
}
|
|
634
|
+
// eslint-disable-next-line camelcase
|
|
635
|
+
aztec_utl_removeEphemeral(foreignSlot, foreignIndex) {
|
|
636
|
+
const slot = fromSingle(foreignSlot);
|
|
637
|
+
const index = fromSingle(foreignIndex).toNumber();
|
|
638
|
+
this.handlerAsUtility().removeEphemeral(slot, index);
|
|
639
|
+
return toForeignCallResult([]);
|
|
640
|
+
}
|
|
641
|
+
// eslint-disable-next-line camelcase
|
|
642
|
+
aztec_utl_clearEphemeral(foreignSlot) {
|
|
643
|
+
const slot = fromSingle(foreignSlot);
|
|
644
|
+
this.handlerAsUtility().clearEphemeral(slot);
|
|
472
645
|
return toForeignCallResult([]);
|
|
473
646
|
}
|
|
474
647
|
// TODO: I forgot to add a corresponding function here, when I introduced an oracle method to txe_oracle.ts.
|
|
475
648
|
// 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
|
|
476
649
|
// to implement this function here. Isn't there a way to programmatically identify that this is missing, given the
|
|
477
650
|
// existence of a txe_oracle method?
|
|
478
|
-
|
|
651
|
+
// eslint-disable-next-line camelcase
|
|
652
|
+
async aztec_utl_decryptAes128(foreignCiphertextBVecStorage, foreignCiphertextLength, foreignIv, foreignSymKey) {
|
|
479
653
|
const ciphertext = fromUintBoundedVec(foreignCiphertextBVecStorage, foreignCiphertextLength, 8);
|
|
480
654
|
const iv = fromUintArray(foreignIv, 8);
|
|
481
655
|
const symKey = fromUintArray(foreignSymKey, 8);
|
|
482
|
-
|
|
483
|
-
|
|
656
|
+
// Noir Option<BoundedVec> is encoded as [is_some: Field, storage: Field[], length: Field].
|
|
657
|
+
try {
|
|
658
|
+
const plaintextBuffer = await this.handlerAsUtility().decryptAes128(ciphertext, iv, symKey);
|
|
659
|
+
const [storage, length] = arrayToBoundedVec(bufferToU8Array(plaintextBuffer), foreignCiphertextBVecStorage.length);
|
|
660
|
+
return toForeignCallResult([
|
|
661
|
+
toSingle(new Fr(1)),
|
|
662
|
+
storage,
|
|
663
|
+
length
|
|
664
|
+
]);
|
|
665
|
+
} catch {
|
|
666
|
+
const zeroStorage = toArray(Array(foreignCiphertextBVecStorage.length).fill(new Fr(0)));
|
|
667
|
+
return toForeignCallResult([
|
|
668
|
+
toSingle(new Fr(0)),
|
|
669
|
+
zeroStorage,
|
|
670
|
+
toSingle(new Fr(0))
|
|
671
|
+
]);
|
|
672
|
+
}
|
|
484
673
|
}
|
|
485
|
-
|
|
674
|
+
// eslint-disable-next-line camelcase
|
|
675
|
+
async aztec_utl_getSharedSecret(foreignAddress, foreignEphPKField0, foreignEphPKField1, foreignEphPKField2, foreignContractAddress) {
|
|
486
676
|
const address = AztecAddress.fromField(fromSingle(foreignAddress));
|
|
487
677
|
const ephPK = Point.fromFields([
|
|
488
678
|
fromSingle(foreignEphPKField0),
|
|
489
679
|
fromSingle(foreignEphPKField1),
|
|
490
680
|
fromSingle(foreignEphPKField2)
|
|
491
681
|
]);
|
|
492
|
-
const
|
|
493
|
-
|
|
682
|
+
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
683
|
+
const secret = await this.handlerAsUtility().getSharedSecret(address, ephPK, contractAddress);
|
|
684
|
+
return toForeignCallResult([
|
|
685
|
+
toSingle(secret)
|
|
686
|
+
]);
|
|
687
|
+
}
|
|
688
|
+
// eslint-disable-next-line camelcase
|
|
689
|
+
aztec_utl_setContractSyncCacheInvalid(foreignContractAddress, foreignScopes, foreignScopeCount) {
|
|
690
|
+
const contractAddress = addressFromSingle(foreignContractAddress);
|
|
691
|
+
const count = fromSingle(foreignScopeCount).toNumber();
|
|
692
|
+
const scopes = fromArray(foreignScopes).slice(0, count).map((f)=>new AztecAddress(f));
|
|
693
|
+
this.handlerAsUtility().setContractSyncCacheInvalid(contractAddress, scopes);
|
|
694
|
+
return Promise.resolve(toForeignCallResult([]));
|
|
494
695
|
}
|
|
495
|
-
|
|
696
|
+
// eslint-disable-next-line camelcase
|
|
697
|
+
aztec_utl_emitOffchainEffect(_foreignData) {
|
|
496
698
|
throw new Error('Offchain effects are not yet supported in the TestEnvironment');
|
|
497
699
|
}
|
|
498
700
|
// AVM opcodes
|
|
499
|
-
|
|
701
|
+
// eslint-disable-next-line camelcase
|
|
702
|
+
aztec_avm_emitPublicLog(_foreignMessage) {
|
|
500
703
|
// TODO(#8811): Implement
|
|
501
704
|
return toForeignCallResult([]);
|
|
502
705
|
}
|
|
503
|
-
|
|
706
|
+
// eslint-disable-next-line camelcase
|
|
707
|
+
async aztec_avm_storageRead(foreignSlot, foreignContractAddress) {
|
|
504
708
|
const slot = fromSingle(foreignSlot);
|
|
505
709
|
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
506
|
-
const value = (await this.handlerAsAvm().
|
|
710
|
+
const value = (await this.handlerAsAvm().storageRead(slot, contractAddress)).value;
|
|
507
711
|
return toForeignCallResult([
|
|
508
712
|
toSingle(new Fr(value))
|
|
509
713
|
]);
|
|
510
714
|
}
|
|
511
|
-
|
|
715
|
+
// eslint-disable-next-line camelcase
|
|
716
|
+
async aztec_avm_storageWrite(foreignSlot, foreignValue) {
|
|
512
717
|
const slot = fromSingle(foreignSlot);
|
|
513
718
|
const value = fromSingle(foreignValue);
|
|
514
|
-
await this.handlerAsAvm().
|
|
719
|
+
await this.handlerAsAvm().storageWrite(slot, value);
|
|
515
720
|
return toForeignCallResult([]);
|
|
516
721
|
}
|
|
517
|
-
|
|
722
|
+
// eslint-disable-next-line camelcase
|
|
723
|
+
async aztec_avm_getContractInstanceDeployer(foreignAddress) {
|
|
518
724
|
const address = addressFromSingle(foreignAddress);
|
|
519
|
-
const instance = await this.handlerAsUtility().
|
|
725
|
+
const instance = await this.handlerAsUtility().getContractInstance(address);
|
|
520
726
|
return toForeignCallResult([
|
|
521
727
|
toSingle(instance.deployer),
|
|
522
728
|
// AVM requires an extra boolean indicating the instance was found
|
|
523
729
|
toSingle(new Fr(1))
|
|
524
730
|
]);
|
|
525
731
|
}
|
|
526
|
-
|
|
732
|
+
// eslint-disable-next-line camelcase
|
|
733
|
+
async aztec_avm_getContractInstanceClassId(foreignAddress) {
|
|
527
734
|
const address = addressFromSingle(foreignAddress);
|
|
528
|
-
const instance = await this.handlerAsUtility().
|
|
735
|
+
const instance = await this.handlerAsUtility().getContractInstance(address);
|
|
529
736
|
return toForeignCallResult([
|
|
530
737
|
toSingle(instance.currentContractClassId),
|
|
531
738
|
// AVM requires an extra boolean indicating the instance was found
|
|
532
739
|
toSingle(new Fr(1))
|
|
533
740
|
]);
|
|
534
741
|
}
|
|
535
|
-
|
|
742
|
+
// eslint-disable-next-line camelcase
|
|
743
|
+
async aztec_avm_getContractInstanceInitializationHash(foreignAddress) {
|
|
536
744
|
const address = addressFromSingle(foreignAddress);
|
|
537
|
-
const instance = await this.handlerAsUtility().
|
|
745
|
+
const instance = await this.handlerAsUtility().getContractInstance(address);
|
|
538
746
|
return toForeignCallResult([
|
|
539
747
|
toSingle(instance.initializationHash),
|
|
540
748
|
// AVM requires an extra boolean indicating the instance was found
|
|
541
749
|
toSingle(new Fr(1))
|
|
542
750
|
]);
|
|
543
751
|
}
|
|
544
|
-
|
|
545
|
-
|
|
752
|
+
// eslint-disable-next-line camelcase
|
|
753
|
+
async aztec_avm_sender() {
|
|
754
|
+
const sender = await this.handlerAsAvm().sender();
|
|
546
755
|
return toForeignCallResult([
|
|
547
756
|
toSingle(sender)
|
|
548
757
|
]);
|
|
549
758
|
}
|
|
550
|
-
|
|
759
|
+
// eslint-disable-next-line camelcase
|
|
760
|
+
async aztec_avm_emitNullifier(foreignNullifier) {
|
|
551
761
|
const nullifier = fromSingle(foreignNullifier);
|
|
552
|
-
await this.handlerAsAvm().
|
|
762
|
+
await this.handlerAsAvm().emitNullifier(nullifier);
|
|
553
763
|
return toForeignCallResult([]);
|
|
554
764
|
}
|
|
555
|
-
|
|
765
|
+
// eslint-disable-next-line camelcase
|
|
766
|
+
async aztec_avm_emitNoteHash(foreignNoteHash) {
|
|
556
767
|
const noteHash = fromSingle(foreignNoteHash);
|
|
557
|
-
await this.handlerAsAvm().
|
|
768
|
+
await this.handlerAsAvm().emitNoteHash(noteHash);
|
|
558
769
|
return toForeignCallResult([]);
|
|
559
770
|
}
|
|
560
|
-
|
|
771
|
+
// eslint-disable-next-line camelcase
|
|
772
|
+
async aztec_avm_nullifierExists(foreignSiloedNullifier) {
|
|
561
773
|
const siloedNullifier = fromSingle(foreignSiloedNullifier);
|
|
562
|
-
const exists = await this.handlerAsAvm().
|
|
774
|
+
const exists = await this.handlerAsAvm().nullifierExists(siloedNullifier);
|
|
563
775
|
return toForeignCallResult([
|
|
564
776
|
toSingle(new Fr(exists))
|
|
565
777
|
]);
|
|
566
778
|
}
|
|
567
|
-
|
|
568
|
-
|
|
779
|
+
// eslint-disable-next-line camelcase
|
|
780
|
+
async aztec_avm_address() {
|
|
781
|
+
const contractAddress = await this.handlerAsAvm().address();
|
|
569
782
|
return toForeignCallResult([
|
|
570
783
|
toSingle(contractAddress.toField())
|
|
571
784
|
]);
|
|
572
785
|
}
|
|
573
|
-
|
|
574
|
-
|
|
786
|
+
// eslint-disable-next-line camelcase
|
|
787
|
+
async aztec_avm_blockNumber() {
|
|
788
|
+
const blockNumber = await this.handlerAsAvm().blockNumber();
|
|
575
789
|
return toForeignCallResult([
|
|
576
790
|
toSingle(new Fr(blockNumber))
|
|
577
791
|
]);
|
|
578
792
|
}
|
|
579
|
-
|
|
580
|
-
|
|
793
|
+
// eslint-disable-next-line camelcase
|
|
794
|
+
async aztec_avm_timestamp() {
|
|
795
|
+
const timestamp = await this.handlerAsAvm().timestamp();
|
|
581
796
|
return toForeignCallResult([
|
|
582
797
|
toSingle(new Fr(timestamp))
|
|
583
798
|
]);
|
|
584
799
|
}
|
|
585
|
-
|
|
586
|
-
|
|
800
|
+
// eslint-disable-next-line camelcase
|
|
801
|
+
async aztec_avm_isStaticCall() {
|
|
802
|
+
const isStaticCall = await this.handlerAsAvm().isStaticCall();
|
|
587
803
|
return toForeignCallResult([
|
|
588
804
|
toSingle(new Fr(isStaticCall ? 1 : 0))
|
|
589
805
|
]);
|
|
590
806
|
}
|
|
591
|
-
|
|
592
|
-
|
|
807
|
+
// eslint-disable-next-line camelcase
|
|
808
|
+
async aztec_avm_chainId() {
|
|
809
|
+
const chainId = await this.handlerAsAvm().chainId();
|
|
593
810
|
return toForeignCallResult([
|
|
594
811
|
toSingle(chainId)
|
|
595
812
|
]);
|
|
596
813
|
}
|
|
597
|
-
|
|
598
|
-
|
|
814
|
+
// eslint-disable-next-line camelcase
|
|
815
|
+
async aztec_avm_version() {
|
|
816
|
+
const version = await this.handlerAsAvm().version();
|
|
599
817
|
return toForeignCallResult([
|
|
600
818
|
toSingle(version)
|
|
601
819
|
]);
|
|
602
820
|
}
|
|
603
|
-
|
|
821
|
+
// eslint-disable-next-line camelcase
|
|
822
|
+
aztec_avm_returndataSize() {
|
|
604
823
|
throw new Error('Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead');
|
|
605
824
|
}
|
|
606
|
-
|
|
825
|
+
// eslint-disable-next-line camelcase
|
|
826
|
+
aztec_avm_returndataCopy(_foreignRdOffset, _foreignCopySize) {
|
|
607
827
|
throw new Error('Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead');
|
|
608
828
|
}
|
|
609
|
-
|
|
829
|
+
// eslint-disable-next-line camelcase
|
|
830
|
+
aztec_avm_call(_foreignL2Gas, _foreignDaGas, _foreignAddress, _foreignLength, _foreignArgs) {
|
|
610
831
|
throw new Error('Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead');
|
|
611
832
|
}
|
|
612
|
-
|
|
833
|
+
// eslint-disable-next-line camelcase
|
|
834
|
+
aztec_avm_staticCall(_foreignL2Gas, _foreignDaGas, _foreignAddress, _foreignLength, _foreignArgs) {
|
|
613
835
|
throw new Error('Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead');
|
|
614
836
|
}
|
|
615
|
-
|
|
837
|
+
// eslint-disable-next-line camelcase
|
|
838
|
+
aztec_avm_successCopy() {
|
|
616
839
|
throw new Error('Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead');
|
|
617
840
|
}
|
|
618
|
-
|
|
841
|
+
// eslint-disable-next-line camelcase
|
|
842
|
+
async aztec_txe_privateCallNewFlow(foreignFrom, foreignTargetContractAddress, foreignFunctionSelector, foreignArgs, foreignArgsHash, foreignIsStaticCall) {
|
|
619
843
|
const from = addressFromSingle(foreignFrom);
|
|
620
844
|
const targetContractAddress = addressFromSingle(foreignTargetContractAddress);
|
|
621
845
|
const functionSelector = FunctionSelector.fromField(fromSingle(foreignFunctionSelector));
|
|
622
846
|
const args = fromArray(foreignArgs);
|
|
623
847
|
const argsHash = fromSingle(foreignArgsHash);
|
|
624
848
|
const isStaticCall = fromSingle(foreignIsStaticCall).toBool();
|
|
625
|
-
const returnValues = await this.handlerAsTxe().
|
|
849
|
+
const returnValues = await this.handlerAsTxe().privateCallNewFlow(from, targetContractAddress, functionSelector, args, argsHash, isStaticCall, this.stateHandler.getCurrentJob());
|
|
850
|
+
// TODO(F-335): Avoid doing the following call here.
|
|
851
|
+
await this.stateHandler.cycleJob();
|
|
626
852
|
return toForeignCallResult([
|
|
627
853
|
toArray(returnValues)
|
|
628
854
|
]);
|
|
629
855
|
}
|
|
630
|
-
|
|
856
|
+
// eslint-disable-next-line camelcase
|
|
857
|
+
async aztec_txe_executeUtilityFunction(foreignTargetContractAddress, foreignFunctionSelector, foreignArgs) {
|
|
631
858
|
const targetContractAddress = addressFromSingle(foreignTargetContractAddress);
|
|
632
859
|
const functionSelector = FunctionSelector.fromField(fromSingle(foreignFunctionSelector));
|
|
633
860
|
const args = fromArray(foreignArgs);
|
|
634
|
-
const returnValues = await this.handlerAsTxe().
|
|
861
|
+
const returnValues = await this.handlerAsTxe().executeUtilityFunction(targetContractAddress, functionSelector, args, this.stateHandler.getCurrentJob());
|
|
862
|
+
// TODO(F-335): Avoid doing the following call here.
|
|
863
|
+
await this.stateHandler.cycleJob();
|
|
635
864
|
return toForeignCallResult([
|
|
636
865
|
toArray(returnValues)
|
|
637
866
|
]);
|
|
638
867
|
}
|
|
639
|
-
|
|
868
|
+
// eslint-disable-next-line camelcase
|
|
869
|
+
async aztec_txe_publicCallNewFlow(foreignFrom, foreignAddress, foreignCalldata, foreignIsStaticCall) {
|
|
640
870
|
const from = addressFromSingle(foreignFrom);
|
|
641
871
|
const address = addressFromSingle(foreignAddress);
|
|
642
872
|
const calldata = fromArray(foreignCalldata);
|
|
643
873
|
const isStaticCall = fromSingle(foreignIsStaticCall).toBool();
|
|
644
|
-
const returnValues = await this.handlerAsTxe().
|
|
874
|
+
const returnValues = await this.handlerAsTxe().publicCallNewFlow(from, address, calldata, isStaticCall);
|
|
875
|
+
// TODO(F-335): Avoid doing the following call here.
|
|
876
|
+
await this.stateHandler.cycleJob();
|
|
645
877
|
return toForeignCallResult([
|
|
646
878
|
toArray(returnValues)
|
|
647
879
|
]);
|
|
648
880
|
}
|
|
649
|
-
|
|
650
|
-
|
|
881
|
+
// eslint-disable-next-line camelcase
|
|
882
|
+
async aztec_prv_getSenderForTags() {
|
|
883
|
+
const sender = await this.handlerAsPrivate().getSenderForTags();
|
|
651
884
|
// Return a Noir Option struct with `some` and `value` fields
|
|
652
885
|
if (sender === undefined) {
|
|
653
886
|
// No sender found, return Option with some=0 and value=0
|
|
@@ -663,15 +896,17 @@ export class RPCTranslator {
|
|
|
663
896
|
]);
|
|
664
897
|
}
|
|
665
898
|
}
|
|
666
|
-
|
|
899
|
+
// eslint-disable-next-line camelcase
|
|
900
|
+
async aztec_prv_setSenderForTags(foreignSenderForTags) {
|
|
667
901
|
const senderForTags = AztecAddress.fromField(fromSingle(foreignSenderForTags));
|
|
668
|
-
await this.handlerAsPrivate().
|
|
902
|
+
await this.handlerAsPrivate().setSenderForTags(senderForTags);
|
|
669
903
|
return toForeignCallResult([]);
|
|
670
904
|
}
|
|
671
|
-
|
|
905
|
+
// eslint-disable-next-line camelcase
|
|
906
|
+
async aztec_prv_getNextAppTagAsSender(foreignSender, foreignRecipient) {
|
|
672
907
|
const sender = AztecAddress.fromField(fromSingle(foreignSender));
|
|
673
908
|
const recipient = AztecAddress.fromField(fromSingle(foreignRecipient));
|
|
674
|
-
const nextAppTag = await this.handlerAsPrivate().
|
|
909
|
+
const nextAppTag = await this.handlerAsPrivate().getNextAppTagAsSender(sender, recipient);
|
|
675
910
|
return toForeignCallResult([
|
|
676
911
|
toSingle(nextAppTag.value)
|
|
677
912
|
]);
|