@aztec/txe 0.0.1-commit.cd76b27 → 0.0.1-commit.ce4f8c4f2
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 +23 -23
- package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_top_level_context.js +52 -37
- package/dest/rpc_translator.d.ts +87 -82
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +273 -151
- 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 +5 -7
- package/dest/state_machine/dummy_p2p_client.d.ts +2 -2
- package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
- package/dest/state_machine/dummy_p2p_client.js +1 -1
- package/dest/state_machine/index.d.ts +4 -2
- package/dest/state_machine/index.d.ts.map +1 -1
- package/dest/state_machine/index.js +7 -3
- package/dest/state_machine/mock_epoch_cache.d.ts +17 -3
- package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
- package/dest/state_machine/mock_epoch_cache.js +32 -2
- package/dest/state_machine/synchronizer.d.ts +5 -5
- package/dest/state_machine/synchronizer.d.ts.map +1 -1
- package/dest/state_machine/synchronizer.js +3 -3
- package/dest/txe_session.d.ts +10 -6
- package/dest/txe_session.d.ts.map +1 -1
- package/dest/txe_session.js +28 -19
- package/dest/util/encoding.d.ts +69 -1
- 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 +6 -25
- 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 +65 -36
- package/src/rpc_translator.ts +305 -173
- package/src/state_machine/archiver.ts +5 -5
- package/src/state_machine/dummy_p2p_client.ts +1 -1
- package/src/state_machine/index.ts +6 -1
- package/src/state_machine/mock_epoch_cache.ts +42 -3
- package/src/state_machine/synchronizer.ts +4 -4
- package/src/txe_session.ts +36 -19
- package/src/util/txe_public_contract_data_source.ts +10 -38
- 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,73 @@ 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
|
-
|
|
163
|
+
// eslint-disable-next-line camelcase
|
|
164
|
+
aztec_utl_assertCompatibleOracleVersion(foreignVersion) {
|
|
151
165
|
const version = fromSingle(foreignVersion).toNumber();
|
|
152
|
-
this.handlerAsMisc().
|
|
166
|
+
this.handlerAsMisc().assertCompatibleOracleVersion(version);
|
|
153
167
|
return toForeignCallResult([]);
|
|
154
168
|
}
|
|
155
|
-
|
|
156
|
-
|
|
169
|
+
// eslint-disable-next-line camelcase
|
|
170
|
+
aztec_utl_getRandomField() {
|
|
171
|
+
const randomField = this.handlerAsMisc().getRandomField();
|
|
157
172
|
return toForeignCallResult([
|
|
158
173
|
toSingle(randomField)
|
|
159
174
|
]);
|
|
160
175
|
}
|
|
161
|
-
|
|
162
|
-
|
|
176
|
+
// eslint-disable-next-line camelcase
|
|
177
|
+
async aztec_txe_getLastBlockTimestamp() {
|
|
178
|
+
const timestamp = await this.handlerAsTxe().getLastBlockTimestamp();
|
|
163
179
|
return toForeignCallResult([
|
|
164
180
|
toSingle(new Fr(timestamp))
|
|
165
181
|
]);
|
|
166
182
|
}
|
|
167
|
-
|
|
168
|
-
|
|
183
|
+
// eslint-disable-next-line camelcase
|
|
184
|
+
async aztec_txe_getLastTxEffects() {
|
|
185
|
+
const { txHash, noteHashes, nullifiers } = await this.handlerAsTxe().getLastTxEffects();
|
|
169
186
|
return toForeignCallResult([
|
|
170
187
|
toSingle(txHash.hash),
|
|
171
188
|
...arrayToBoundedVec(toArray(noteHashes), MAX_NOTE_HASHES_PER_TX),
|
|
172
189
|
...arrayToBoundedVec(toArray(nullifiers), MAX_NULLIFIERS_PER_TX)
|
|
173
190
|
]);
|
|
174
191
|
}
|
|
175
|
-
|
|
192
|
+
// eslint-disable-next-line camelcase
|
|
193
|
+
async aztec_txe_getPrivateEvents(foreignSelector, foreignContractAddress, foreignScope) {
|
|
176
194
|
const selector = EventSelector.fromField(fromSingle(foreignSelector));
|
|
177
195
|
const contractAddress = addressFromSingle(foreignContractAddress);
|
|
178
196
|
const scope = addressFromSingle(foreignScope);
|
|
179
|
-
|
|
197
|
+
// TODO(F-335): Avoid doing the following 2 calls here.
|
|
198
|
+
{
|
|
199
|
+
await this.handlerAsTxe().syncContractNonOracleMethod(contractAddress, scope, this.stateHandler.getCurrentJob());
|
|
200
|
+
// We cycle job to commit the stores after the contract sync.
|
|
201
|
+
await this.stateHandler.cycleJob();
|
|
202
|
+
}
|
|
203
|
+
const events = await this.handlerAsTxe().getPrivateEvents(selector, contractAddress, scope);
|
|
180
204
|
if (events.length > MAX_PRIVATE_EVENTS_PER_TXE_QUERY) {
|
|
181
205
|
throw new Error(`Array of length ${events.length} larger than maxLen ${MAX_PRIVATE_EVENTS_PER_TXE_QUERY}`);
|
|
182
206
|
}
|
|
@@ -194,48 +218,54 @@ export class RPCTranslator {
|
|
|
194
218
|
toSingle(queryLength)
|
|
195
219
|
]);
|
|
196
220
|
}
|
|
197
|
-
|
|
221
|
+
// eslint-disable-next-line camelcase
|
|
222
|
+
aztec_prv_storeInExecutionCache(foreignValues, foreignHash) {
|
|
198
223
|
const values = fromArray(foreignValues);
|
|
199
224
|
const hash = fromSingle(foreignHash);
|
|
200
|
-
this.handlerAsPrivate().
|
|
225
|
+
this.handlerAsPrivate().storeInExecutionCache(values, hash);
|
|
201
226
|
return toForeignCallResult([]);
|
|
202
227
|
}
|
|
203
|
-
|
|
228
|
+
// eslint-disable-next-line camelcase
|
|
229
|
+
async aztec_prv_loadFromExecutionCache(foreignHash) {
|
|
204
230
|
const hash = fromSingle(foreignHash);
|
|
205
|
-
const returns = await this.handlerAsPrivate().
|
|
231
|
+
const returns = await this.handlerAsPrivate().loadFromExecutionCache(hash);
|
|
206
232
|
return toForeignCallResult([
|
|
207
233
|
toArray(returns)
|
|
208
234
|
]);
|
|
209
235
|
}
|
|
210
236
|
// When the argument is a slice, noir automatically adds a length field to oracle call.
|
|
211
237
|
// When the argument is an array, we add the field length manually to the signature.
|
|
212
|
-
|
|
238
|
+
// eslint-disable-next-line camelcase
|
|
239
|
+
async aztec_utl_log(foreignLevel, foreignMessage, _foreignLength, foreignFields) {
|
|
213
240
|
const level = fromSingle(foreignLevel).toNumber();
|
|
214
241
|
const message = fromArray(foreignMessage).map((field)=>String.fromCharCode(field.toNumber())).join('');
|
|
215
242
|
const fields = fromArray(foreignFields);
|
|
216
|
-
await this.handlerAsMisc().
|
|
243
|
+
await this.handlerAsMisc().log(level, message, fields);
|
|
217
244
|
return toForeignCallResult([]);
|
|
218
245
|
}
|
|
219
|
-
|
|
246
|
+
// eslint-disable-next-line camelcase
|
|
247
|
+
async aztec_utl_storageRead(foreignBlockHash, foreignContractAddress, foreignStartStorageSlot, foreignNumberOfElements) {
|
|
220
248
|
const blockHash = new BlockHash(fromSingle(foreignBlockHash));
|
|
221
249
|
const contractAddress = addressFromSingle(foreignContractAddress);
|
|
222
250
|
const startStorageSlot = fromSingle(foreignStartStorageSlot);
|
|
223
251
|
const numberOfElements = fromSingle(foreignNumberOfElements).toNumber();
|
|
224
|
-
const values = await this.handlerAsUtility().
|
|
252
|
+
const values = await this.handlerAsUtility().storageRead(blockHash, contractAddress, startStorageSlot, numberOfElements);
|
|
225
253
|
return toForeignCallResult([
|
|
226
254
|
toArray(values)
|
|
227
255
|
]);
|
|
228
256
|
}
|
|
229
|
-
|
|
257
|
+
// eslint-disable-next-line camelcase
|
|
258
|
+
async aztec_utl_getPublicDataWitness(foreignBlockHash, foreignLeafSlot) {
|
|
230
259
|
const blockHash = new BlockHash(fromSingle(foreignBlockHash));
|
|
231
260
|
const leafSlot = fromSingle(foreignLeafSlot);
|
|
232
|
-
const witness = await this.handlerAsUtility().
|
|
261
|
+
const witness = await this.handlerAsUtility().getPublicDataWitness(blockHash, leafSlot);
|
|
233
262
|
if (!witness) {
|
|
234
263
|
throw new Error(`Public data witness not found for slot ${leafSlot} at block ${blockHash.toString()}.`);
|
|
235
264
|
}
|
|
236
265
|
return toForeignCallResult(witness.toNoirRepresentation());
|
|
237
266
|
}
|
|
238
|
-
|
|
267
|
+
// eslint-disable-next-line camelcase
|
|
268
|
+
async aztec_utl_getNotes(foreignOwnerIsSome, foreignOwnerValue, foreignStorageSlot, foreignNumSelects, foreignSelectByIndexes, foreignSelectByOffsets, foreignSelectByLengths, foreignSelectValues, foreignSelectComparators, foreignSortByIndexes, foreignSortByOffsets, foreignSortByLengths, foreignSortOrder, foreignLimit, foreignOffset, foreignStatus, foreignMaxNotes, foreignPackedHintedNoteLength) {
|
|
239
269
|
// Parse Option<AztecAddress>: ownerIsSome is 0 for None, 1 for Some
|
|
240
270
|
const owner = fromSingle(foreignOwnerIsSome).toBool() ? AztecAddress.fromField(fromSingle(foreignOwnerValue)) : undefined;
|
|
241
271
|
const storageSlot = fromSingle(foreignStorageSlot);
|
|
@@ -254,7 +284,7 @@ export class RPCTranslator {
|
|
|
254
284
|
const status = fromSingle(foreignStatus).toNumber();
|
|
255
285
|
const maxNotes = fromSingle(foreignMaxNotes).toNumber();
|
|
256
286
|
const packedHintedNoteLength = fromSingle(foreignPackedHintedNoteLength).toNumber();
|
|
257
|
-
const noteDatas = await this.handlerAsUtility().
|
|
287
|
+
const noteDatas = await this.handlerAsUtility().getNotes(owner, storageSlot, numSelects, selectByIndexes, selectByOffsets, selectByLengths, selectValues, selectComparators, sortByIndexes, sortByOffsets, sortByLengths, sortOrder, limit, offset, status);
|
|
258
288
|
const returnDataAsArrayOfArrays = noteDatas.map((noteData)=>packAsHintedNote({
|
|
259
289
|
contractAddress: noteData.contractAddress,
|
|
260
290
|
owner: noteData.owner,
|
|
@@ -269,7 +299,8 @@ export class RPCTranslator {
|
|
|
269
299
|
// At last we convert the array of arrays to a bounded vec of arrays
|
|
270
300
|
return toForeignCallResult(arrayOfArraysToBoundedVecOfArrays(returnDataAsArrayOfForeignCallSingleArrays, maxNotes, packedHintedNoteLength));
|
|
271
301
|
}
|
|
272
|
-
|
|
302
|
+
// eslint-disable-next-line camelcase
|
|
303
|
+
aztec_prv_notifyCreatedNote(foreignOwner, foreignStorageSlot, foreignRandomness, foreignNoteTypeId, foreignNote, foreignNoteHash, foreignCounter) {
|
|
273
304
|
const owner = addressFromSingle(foreignOwner);
|
|
274
305
|
const storageSlot = fromSingle(foreignStorageSlot);
|
|
275
306
|
const randomness = fromSingle(foreignRandomness);
|
|
@@ -277,39 +308,44 @@ export class RPCTranslator {
|
|
|
277
308
|
const note = fromArray(foreignNote);
|
|
278
309
|
const noteHash = fromSingle(foreignNoteHash);
|
|
279
310
|
const counter = fromSingle(foreignCounter).toNumber();
|
|
280
|
-
this.handlerAsPrivate().
|
|
311
|
+
this.handlerAsPrivate().notifyCreatedNote(owner, storageSlot, randomness, noteTypeId, note, noteHash, counter);
|
|
281
312
|
return toForeignCallResult([]);
|
|
282
313
|
}
|
|
283
|
-
|
|
314
|
+
// eslint-disable-next-line camelcase
|
|
315
|
+
async aztec_prv_notifyNullifiedNote(foreignInnerNullifier, foreignNoteHash, foreignCounter) {
|
|
284
316
|
const innerNullifier = fromSingle(foreignInnerNullifier);
|
|
285
317
|
const noteHash = fromSingle(foreignNoteHash);
|
|
286
318
|
const counter = fromSingle(foreignCounter).toNumber();
|
|
287
|
-
await this.handlerAsPrivate().
|
|
319
|
+
await this.handlerAsPrivate().notifyNullifiedNote(innerNullifier, noteHash, counter);
|
|
288
320
|
return toForeignCallResult([]);
|
|
289
321
|
}
|
|
290
|
-
|
|
322
|
+
// eslint-disable-next-line camelcase
|
|
323
|
+
async aztec_prv_notifyCreatedNullifier(foreignInnerNullifier) {
|
|
291
324
|
const innerNullifier = fromSingle(foreignInnerNullifier);
|
|
292
|
-
await this.handlerAsPrivate().
|
|
325
|
+
await this.handlerAsPrivate().notifyCreatedNullifier(innerNullifier);
|
|
293
326
|
return toForeignCallResult([]);
|
|
294
327
|
}
|
|
295
|
-
|
|
328
|
+
// eslint-disable-next-line camelcase
|
|
329
|
+
async aztec_prv_isNullifierPending(foreignInnerNullifier, foreignContractAddress) {
|
|
296
330
|
const innerNullifier = fromSingle(foreignInnerNullifier);
|
|
297
331
|
const contractAddress = addressFromSingle(foreignContractAddress);
|
|
298
|
-
const isPending = await this.handlerAsPrivate().
|
|
332
|
+
const isPending = await this.handlerAsPrivate().isNullifierPending(innerNullifier, contractAddress);
|
|
299
333
|
return toForeignCallResult([
|
|
300
334
|
toSingle(new Fr(isPending))
|
|
301
335
|
]);
|
|
302
336
|
}
|
|
303
|
-
|
|
337
|
+
// eslint-disable-next-line camelcase
|
|
338
|
+
async aztec_utl_checkNullifierExists(foreignInnerNullifier) {
|
|
304
339
|
const innerNullifier = fromSingle(foreignInnerNullifier);
|
|
305
|
-
const exists = await this.handlerAsUtility().
|
|
340
|
+
const exists = await this.handlerAsUtility().checkNullifierExists(innerNullifier);
|
|
306
341
|
return toForeignCallResult([
|
|
307
342
|
toSingle(new Fr(exists))
|
|
308
343
|
]);
|
|
309
344
|
}
|
|
310
|
-
|
|
345
|
+
// eslint-disable-next-line camelcase
|
|
346
|
+
async aztec_utl_getContractInstance(foreignAddress) {
|
|
311
347
|
const address = addressFromSingle(foreignAddress);
|
|
312
|
-
const instance = await this.handlerAsUtility().
|
|
348
|
+
const instance = await this.handlerAsUtility().getContractInstance(address);
|
|
313
349
|
return toForeignCallResult([
|
|
314
350
|
instance.salt,
|
|
315
351
|
instance.deployer.toField(),
|
|
@@ -318,9 +354,10 @@ export class RPCTranslator {
|
|
|
318
354
|
...instance.publicKeys.toFields()
|
|
319
355
|
].map(toSingle));
|
|
320
356
|
}
|
|
321
|
-
|
|
357
|
+
// eslint-disable-next-line camelcase
|
|
358
|
+
async aztec_utl_tryGetPublicKeysAndPartialAddress(foreignAddress) {
|
|
322
359
|
const address = addressFromSingle(foreignAddress);
|
|
323
|
-
const result = await this.handlerAsUtility().
|
|
360
|
+
const result = await this.handlerAsUtility().tryGetPublicKeysAndPartialAddress(address);
|
|
324
361
|
// We are going to return a Noir Option struct to represent the possibility of null values. Options are a struct
|
|
325
362
|
// with two fields: `some` (a boolean) and `value` (a field array in this case).
|
|
326
363
|
if (result === undefined) {
|
|
@@ -340,26 +377,30 @@ export class RPCTranslator {
|
|
|
340
377
|
]);
|
|
341
378
|
}
|
|
342
379
|
}
|
|
343
|
-
|
|
380
|
+
// eslint-disable-next-line camelcase
|
|
381
|
+
async aztec_utl_getKeyValidationRequest(foreignPkMHash) {
|
|
344
382
|
const pkMHash = fromSingle(foreignPkMHash);
|
|
345
|
-
const keyValidationRequest = await this.handlerAsUtility().
|
|
383
|
+
const keyValidationRequest = await this.handlerAsUtility().getKeyValidationRequest(pkMHash);
|
|
346
384
|
return toForeignCallResult(keyValidationRequest.toFields().map(toSingle));
|
|
347
385
|
}
|
|
348
|
-
|
|
386
|
+
// eslint-disable-next-line camelcase
|
|
387
|
+
aztec_prv_callPrivateFunction(_foreignTargetContractAddress, _foreignFunctionSelector, _foreignArgsHash, _foreignSideEffectCounter, _foreignIsStaticCall) {
|
|
349
388
|
throw new Error('Contract calls are forbidden inside a `TestEnvironment::private_context`, use `private_call` instead');
|
|
350
389
|
}
|
|
351
|
-
|
|
390
|
+
// eslint-disable-next-line camelcase
|
|
391
|
+
async aztec_utl_getNullifierMembershipWitness(foreignBlockHash, foreignNullifier) {
|
|
352
392
|
const blockHash = new BlockHash(fromSingle(foreignBlockHash));
|
|
353
393
|
const nullifier = fromSingle(foreignNullifier);
|
|
354
|
-
const witness = await this.handlerAsUtility().
|
|
394
|
+
const witness = await this.handlerAsUtility().getNullifierMembershipWitness(blockHash, nullifier);
|
|
355
395
|
if (!witness) {
|
|
356
396
|
throw new Error(`Nullifier membership witness not found at block ${blockHash}.`);
|
|
357
397
|
}
|
|
358
398
|
return toForeignCallResult(witness.toNoirRepresentation());
|
|
359
399
|
}
|
|
360
|
-
|
|
400
|
+
// eslint-disable-next-line camelcase
|
|
401
|
+
async aztec_utl_getAuthWitness(foreignMessageHash) {
|
|
361
402
|
const messageHash = fromSingle(foreignMessageHash);
|
|
362
|
-
const authWitness = await this.handlerAsUtility().
|
|
403
|
+
const authWitness = await this.handlerAsUtility().getAuthWitness(messageHash);
|
|
363
404
|
if (!authWitness) {
|
|
364
405
|
throw new Error(`Auth witness not found for message hash ${messageHash}.`);
|
|
365
406
|
}
|
|
@@ -367,92 +408,112 @@ export class RPCTranslator {
|
|
|
367
408
|
toArray(authWitness)
|
|
368
409
|
]);
|
|
369
410
|
}
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
}
|
|
373
|
-
privateNotifySetPublicTeardownFunctionCall(_foreignTargetContractAddress, _foreignCalldataHash, _foreignSideEffectCounter, _foreignIsStaticCall) {
|
|
411
|
+
// eslint-disable-next-line camelcase
|
|
412
|
+
aztec_prv_validatePublicCalldata(_foreignCalldataHash) {
|
|
374
413
|
throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
|
|
375
414
|
}
|
|
376
|
-
|
|
415
|
+
// eslint-disable-next-line camelcase
|
|
416
|
+
aztec_prv_notifyRevertiblePhaseStart(_foreignMinRevertibleSideEffectCounter) {
|
|
377
417
|
throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
|
|
378
418
|
}
|
|
379
|
-
|
|
419
|
+
// eslint-disable-next-line camelcase
|
|
420
|
+
async aztec_prv_inRevertiblePhase(foreignSideEffectCounter) {
|
|
380
421
|
const sideEffectCounter = fromSingle(foreignSideEffectCounter).toNumber();
|
|
381
|
-
const isRevertible = await this.handlerAsPrivate().
|
|
422
|
+
const isRevertible = await this.handlerAsPrivate().inRevertiblePhase(sideEffectCounter);
|
|
382
423
|
return toForeignCallResult([
|
|
383
424
|
toSingle(new Fr(isRevertible))
|
|
384
425
|
]);
|
|
385
426
|
}
|
|
386
|
-
|
|
387
|
-
|
|
427
|
+
// eslint-disable-next-line camelcase
|
|
428
|
+
aztec_utl_getUtilityContext() {
|
|
429
|
+
const context = this.handlerAsUtility().getUtilityContext();
|
|
388
430
|
return toForeignCallResult(context.toNoirRepresentation());
|
|
389
431
|
}
|
|
390
|
-
|
|
432
|
+
// eslint-disable-next-line camelcase
|
|
433
|
+
async aztec_utl_getBlockHeader(foreignBlockNumber) {
|
|
391
434
|
const blockNumber = BlockNumber(fromSingle(foreignBlockNumber).toNumber());
|
|
392
|
-
const header = await this.handlerAsUtility().
|
|
435
|
+
const header = await this.handlerAsUtility().getBlockHeader(blockNumber);
|
|
393
436
|
if (!header) {
|
|
394
437
|
throw new Error(`Block header not found for block ${blockNumber}.`);
|
|
395
438
|
}
|
|
396
439
|
return toForeignCallResult(header.toFields().map(toSingle));
|
|
397
440
|
}
|
|
398
|
-
|
|
441
|
+
// eslint-disable-next-line camelcase
|
|
442
|
+
async aztec_utl_getNoteHashMembershipWitness(foreignAnchorBlockHash, foreignNoteHash) {
|
|
399
443
|
const blockHash = new BlockHash(fromSingle(foreignAnchorBlockHash));
|
|
400
444
|
const noteHash = fromSingle(foreignNoteHash);
|
|
401
|
-
const witness = await this.handlerAsUtility().
|
|
445
|
+
const witness = await this.handlerAsUtility().getNoteHashMembershipWitness(blockHash, noteHash);
|
|
402
446
|
if (!witness) {
|
|
403
447
|
throw new Error(`Note hash ${noteHash} not found in the note hash tree at block ${blockHash.toString()}.`);
|
|
404
448
|
}
|
|
405
449
|
return toForeignCallResult(witness.toNoirRepresentation());
|
|
406
450
|
}
|
|
407
|
-
|
|
451
|
+
// eslint-disable-next-line camelcase
|
|
452
|
+
async aztec_utl_getBlockHashMembershipWitness(foreignAnchorBlockHash, foreignBlockHash) {
|
|
408
453
|
const anchorBlockHash = new BlockHash(fromSingle(foreignAnchorBlockHash));
|
|
409
454
|
const blockHash = new BlockHash(fromSingle(foreignBlockHash));
|
|
410
|
-
const witness = await this.handlerAsUtility().
|
|
455
|
+
const witness = await this.handlerAsUtility().getBlockHashMembershipWitness(anchorBlockHash, blockHash);
|
|
411
456
|
if (!witness) {
|
|
412
457
|
throw new Error(`Block hash ${blockHash.toString()} not found in the archive tree at anchor block ${anchorBlockHash.toString()}.`);
|
|
413
458
|
}
|
|
414
459
|
return toForeignCallResult(witness.toNoirRepresentation());
|
|
415
460
|
}
|
|
416
|
-
|
|
461
|
+
// eslint-disable-next-line camelcase
|
|
462
|
+
async aztec_utl_getLowNullifierMembershipWitness(foreignBlockHash, foreignNullifier) {
|
|
417
463
|
const blockHash = new BlockHash(fromSingle(foreignBlockHash));
|
|
418
464
|
const nullifier = fromSingle(foreignNullifier);
|
|
419
|
-
const witness = await this.handlerAsUtility().
|
|
465
|
+
const witness = await this.handlerAsUtility().getLowNullifierMembershipWitness(blockHash, nullifier);
|
|
420
466
|
if (!witness) {
|
|
421
467
|
throw new Error(`Low nullifier witness not found for nullifier ${nullifier} at block ${blockHash}.`);
|
|
422
468
|
}
|
|
423
469
|
return toForeignCallResult(witness.toNoirRepresentation());
|
|
424
470
|
}
|
|
425
|
-
|
|
471
|
+
// eslint-disable-next-line camelcase
|
|
472
|
+
async aztec_utl_fetchTaggedLogs(foreignPendingTaggedLogArrayBaseSlot) {
|
|
426
473
|
const pendingTaggedLogArrayBaseSlot = fromSingle(foreignPendingTaggedLogArrayBaseSlot);
|
|
427
|
-
await this.handlerAsUtility().
|
|
474
|
+
await this.handlerAsUtility().fetchTaggedLogs(pendingTaggedLogArrayBaseSlot);
|
|
428
475
|
return toForeignCallResult([]);
|
|
429
476
|
}
|
|
430
|
-
|
|
477
|
+
// eslint-disable-next-line camelcase
|
|
478
|
+
async aztec_utl_validateAndStoreEnqueuedNotesAndEvents(foreignContractAddress, foreignNoteValidationRequestsArrayBaseSlot, foreignEventValidationRequestsArrayBaseSlot, foreignMaxNotePackedLen, foreignMaxEventSerializedLen) {
|
|
431
479
|
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
432
480
|
const noteValidationRequestsArrayBaseSlot = fromSingle(foreignNoteValidationRequestsArrayBaseSlot);
|
|
433
481
|
const eventValidationRequestsArrayBaseSlot = fromSingle(foreignEventValidationRequestsArrayBaseSlot);
|
|
434
|
-
|
|
482
|
+
const maxNotePackedLen = fromSingle(foreignMaxNotePackedLen).toNumber();
|
|
483
|
+
const maxEventSerializedLen = fromSingle(foreignMaxEventSerializedLen).toNumber();
|
|
484
|
+
await this.handlerAsUtility().validateAndStoreEnqueuedNotesAndEvents(contractAddress, noteValidationRequestsArrayBaseSlot, eventValidationRequestsArrayBaseSlot, maxNotePackedLen, maxEventSerializedLen);
|
|
435
485
|
return toForeignCallResult([]);
|
|
436
486
|
}
|
|
437
|
-
|
|
487
|
+
// eslint-disable-next-line camelcase
|
|
488
|
+
async aztec_utl_bulkRetrieveLogs(foreignContractAddress, foreignLogRetrievalRequestsArrayBaseSlot, foreignLogRetrievalResponsesArrayBaseSlot) {
|
|
438
489
|
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
439
490
|
const logRetrievalRequestsArrayBaseSlot = fromSingle(foreignLogRetrievalRequestsArrayBaseSlot);
|
|
440
491
|
const logRetrievalResponsesArrayBaseSlot = fromSingle(foreignLogRetrievalResponsesArrayBaseSlot);
|
|
441
|
-
await this.handlerAsUtility().
|
|
492
|
+
await this.handlerAsUtility().bulkRetrieveLogs(contractAddress, logRetrievalRequestsArrayBaseSlot, logRetrievalResponsesArrayBaseSlot);
|
|
493
|
+
return toForeignCallResult([]);
|
|
494
|
+
}
|
|
495
|
+
// eslint-disable-next-line camelcase
|
|
496
|
+
async aztec_utl_utilityResolveMessageContexts(foreignContractAddress, foreignMessageContextRequestsArrayBaseSlot, foreignMessageContextResponsesArrayBaseSlot) {
|
|
497
|
+
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
498
|
+
const messageContextRequestsArrayBaseSlot = fromSingle(foreignMessageContextRequestsArrayBaseSlot);
|
|
499
|
+
const messageContextResponsesArrayBaseSlot = fromSingle(foreignMessageContextResponsesArrayBaseSlot);
|
|
500
|
+
await this.handlerAsUtility().utilityResolveMessageContexts(contractAddress, messageContextRequestsArrayBaseSlot, messageContextResponsesArrayBaseSlot);
|
|
442
501
|
return toForeignCallResult([]);
|
|
443
502
|
}
|
|
444
|
-
|
|
503
|
+
// eslint-disable-next-line camelcase
|
|
504
|
+
async aztec_utl_storeCapsule(foreignContractAddress, foreignSlot, foreignCapsule) {
|
|
445
505
|
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
446
506
|
const slot = fromSingle(foreignSlot);
|
|
447
507
|
const capsule = fromArray(foreignCapsule);
|
|
448
|
-
await this.handlerAsUtility().
|
|
508
|
+
await this.handlerAsUtility().storeCapsule(contractAddress, slot, capsule);
|
|
449
509
|
return toForeignCallResult([]);
|
|
450
510
|
}
|
|
451
|
-
|
|
511
|
+
// eslint-disable-next-line camelcase
|
|
512
|
+
async aztec_utl_loadCapsule(foreignContractAddress, foreignSlot, foreignTSize) {
|
|
452
513
|
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
453
514
|
const slot = fromSingle(foreignSlot);
|
|
454
515
|
const tSize = fromSingle(foreignTSize).toNumber();
|
|
455
|
-
const values = await this.handlerAsUtility().
|
|
516
|
+
const values = await this.handlerAsUtility().loadCapsule(contractAddress, slot);
|
|
456
517
|
// We are going to return a Noir Option struct to represent the possibility of null values. Options are a struct
|
|
457
518
|
// with two fields: `some` (a boolean) and `value` (a field array in this case).
|
|
458
519
|
if (values === null) {
|
|
@@ -469,197 +530,256 @@ export class RPCTranslator {
|
|
|
469
530
|
]);
|
|
470
531
|
}
|
|
471
532
|
}
|
|
472
|
-
|
|
533
|
+
// eslint-disable-next-line camelcase
|
|
534
|
+
async aztec_utl_deleteCapsule(foreignContractAddress, foreignSlot) {
|
|
473
535
|
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
474
536
|
const slot = fromSingle(foreignSlot);
|
|
475
|
-
await this.handlerAsUtility().
|
|
537
|
+
await this.handlerAsUtility().deleteCapsule(contractAddress, slot);
|
|
476
538
|
return toForeignCallResult([]);
|
|
477
539
|
}
|
|
478
|
-
|
|
540
|
+
// eslint-disable-next-line camelcase
|
|
541
|
+
async aztec_utl_copyCapsule(foreignContractAddress, foreignSrcSlot, foreignDstSlot, foreignNumEntries) {
|
|
479
542
|
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
480
543
|
const srcSlot = fromSingle(foreignSrcSlot);
|
|
481
544
|
const dstSlot = fromSingle(foreignDstSlot);
|
|
482
545
|
const numEntries = fromSingle(foreignNumEntries).toNumber();
|
|
483
|
-
await this.handlerAsUtility().
|
|
546
|
+
await this.handlerAsUtility().copyCapsule(contractAddress, srcSlot, dstSlot, numEntries);
|
|
484
547
|
return toForeignCallResult([]);
|
|
485
548
|
}
|
|
486
549
|
// TODO: I forgot to add a corresponding function here, when I introduced an oracle method to txe_oracle.ts.
|
|
487
550
|
// 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
|
|
488
551
|
// to implement this function here. Isn't there a way to programmatically identify that this is missing, given the
|
|
489
552
|
// existence of a txe_oracle method?
|
|
490
|
-
|
|
553
|
+
// eslint-disable-next-line camelcase
|
|
554
|
+
async aztec_utl_tryAes128Decrypt(foreignCiphertextBVecStorage, foreignCiphertextLength, foreignIv, foreignSymKey) {
|
|
491
555
|
const ciphertext = fromUintBoundedVec(foreignCiphertextBVecStorage, foreignCiphertextLength, 8);
|
|
492
556
|
const iv = fromUintArray(foreignIv, 8);
|
|
493
557
|
const symKey = fromUintArray(foreignSymKey, 8);
|
|
494
|
-
|
|
495
|
-
|
|
558
|
+
// Noir Option<BoundedVec> is encoded as [is_some: Field, storage: Field[], length: Field].
|
|
559
|
+
try {
|
|
560
|
+
const plaintextBuffer = await this.handlerAsUtility().aes128Decrypt(ciphertext, iv, symKey);
|
|
561
|
+
const [storage, length] = arrayToBoundedVec(bufferToU8Array(plaintextBuffer), foreignCiphertextBVecStorage.length);
|
|
562
|
+
return toForeignCallResult([
|
|
563
|
+
toSingle(new Fr(1)),
|
|
564
|
+
storage,
|
|
565
|
+
length
|
|
566
|
+
]);
|
|
567
|
+
} catch {
|
|
568
|
+
const zeroStorage = toArray(Array(foreignCiphertextBVecStorage.length).fill(new Fr(0)));
|
|
569
|
+
return toForeignCallResult([
|
|
570
|
+
toSingle(new Fr(0)),
|
|
571
|
+
zeroStorage,
|
|
572
|
+
toSingle(new Fr(0))
|
|
573
|
+
]);
|
|
574
|
+
}
|
|
496
575
|
}
|
|
497
|
-
|
|
576
|
+
// eslint-disable-next-line camelcase
|
|
577
|
+
async aztec_utl_getSharedSecret(foreignAddress, foreignEphPKField0, foreignEphPKField1, foreignEphPKField2) {
|
|
498
578
|
const address = AztecAddress.fromField(fromSingle(foreignAddress));
|
|
499
579
|
const ephPK = Point.fromFields([
|
|
500
580
|
fromSingle(foreignEphPKField0),
|
|
501
581
|
fromSingle(foreignEphPKField1),
|
|
502
582
|
fromSingle(foreignEphPKField2)
|
|
503
583
|
]);
|
|
504
|
-
const secret = await this.handlerAsUtility().
|
|
584
|
+
const secret = await this.handlerAsUtility().getSharedSecret(address, ephPK);
|
|
505
585
|
return toForeignCallResult(secret.toFields().map(toSingle));
|
|
506
586
|
}
|
|
507
|
-
|
|
587
|
+
// eslint-disable-next-line camelcase
|
|
588
|
+
aztec_utl_invalidateContractSyncCache(foreignContractAddress, foreignScopes, foreignScopeCount) {
|
|
589
|
+
const contractAddress = addressFromSingle(foreignContractAddress);
|
|
590
|
+
const count = fromSingle(foreignScopeCount).toNumber();
|
|
591
|
+
const scopes = fromArray(foreignScopes).slice(0, count).map((f)=>new AztecAddress(f));
|
|
592
|
+
this.handlerAsUtility().invalidateContractSyncCache(contractAddress, scopes);
|
|
593
|
+
return Promise.resolve(toForeignCallResult([]));
|
|
594
|
+
}
|
|
595
|
+
// eslint-disable-next-line camelcase
|
|
596
|
+
aztec_utl_emitOffchainEffect(_foreignData) {
|
|
508
597
|
throw new Error('Offchain effects are not yet supported in the TestEnvironment');
|
|
509
598
|
}
|
|
510
599
|
// AVM opcodes
|
|
511
|
-
|
|
600
|
+
// eslint-disable-next-line camelcase
|
|
601
|
+
aztec_avm_emitPublicLog(_foreignMessage) {
|
|
512
602
|
// TODO(#8811): Implement
|
|
513
603
|
return toForeignCallResult([]);
|
|
514
604
|
}
|
|
515
|
-
|
|
605
|
+
// eslint-disable-next-line camelcase
|
|
606
|
+
async aztec_avm_storageRead(foreignSlot, foreignContractAddress) {
|
|
516
607
|
const slot = fromSingle(foreignSlot);
|
|
517
608
|
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
518
|
-
const value = (await this.handlerAsAvm().
|
|
609
|
+
const value = (await this.handlerAsAvm().storageRead(slot, contractAddress)).value;
|
|
519
610
|
return toForeignCallResult([
|
|
520
611
|
toSingle(new Fr(value))
|
|
521
612
|
]);
|
|
522
613
|
}
|
|
523
|
-
|
|
614
|
+
// eslint-disable-next-line camelcase
|
|
615
|
+
async aztec_avm_storageWrite(foreignSlot, foreignValue) {
|
|
524
616
|
const slot = fromSingle(foreignSlot);
|
|
525
617
|
const value = fromSingle(foreignValue);
|
|
526
|
-
await this.handlerAsAvm().
|
|
618
|
+
await this.handlerAsAvm().storageWrite(slot, value);
|
|
527
619
|
return toForeignCallResult([]);
|
|
528
620
|
}
|
|
529
|
-
|
|
621
|
+
// eslint-disable-next-line camelcase
|
|
622
|
+
async aztec_avm_getContractInstanceDeployer(foreignAddress) {
|
|
530
623
|
const address = addressFromSingle(foreignAddress);
|
|
531
|
-
const instance = await this.handlerAsUtility().
|
|
624
|
+
const instance = await this.handlerAsUtility().getContractInstance(address);
|
|
532
625
|
return toForeignCallResult([
|
|
533
626
|
toSingle(instance.deployer),
|
|
534
627
|
// AVM requires an extra boolean indicating the instance was found
|
|
535
628
|
toSingle(new Fr(1))
|
|
536
629
|
]);
|
|
537
630
|
}
|
|
538
|
-
|
|
631
|
+
// eslint-disable-next-line camelcase
|
|
632
|
+
async aztec_avm_getContractInstanceClassId(foreignAddress) {
|
|
539
633
|
const address = addressFromSingle(foreignAddress);
|
|
540
|
-
const instance = await this.handlerAsUtility().
|
|
634
|
+
const instance = await this.handlerAsUtility().getContractInstance(address);
|
|
541
635
|
return toForeignCallResult([
|
|
542
636
|
toSingle(instance.currentContractClassId),
|
|
543
637
|
// AVM requires an extra boolean indicating the instance was found
|
|
544
638
|
toSingle(new Fr(1))
|
|
545
639
|
]);
|
|
546
640
|
}
|
|
547
|
-
|
|
641
|
+
// eslint-disable-next-line camelcase
|
|
642
|
+
async aztec_avm_getContractInstanceInitializationHash(foreignAddress) {
|
|
548
643
|
const address = addressFromSingle(foreignAddress);
|
|
549
|
-
const instance = await this.handlerAsUtility().
|
|
644
|
+
const instance = await this.handlerAsUtility().getContractInstance(address);
|
|
550
645
|
return toForeignCallResult([
|
|
551
646
|
toSingle(instance.initializationHash),
|
|
552
647
|
// AVM requires an extra boolean indicating the instance was found
|
|
553
648
|
toSingle(new Fr(1))
|
|
554
649
|
]);
|
|
555
650
|
}
|
|
556
|
-
|
|
557
|
-
|
|
651
|
+
// eslint-disable-next-line camelcase
|
|
652
|
+
async aztec_avm_sender() {
|
|
653
|
+
const sender = await this.handlerAsAvm().sender();
|
|
558
654
|
return toForeignCallResult([
|
|
559
655
|
toSingle(sender)
|
|
560
656
|
]);
|
|
561
657
|
}
|
|
562
|
-
|
|
658
|
+
// eslint-disable-next-line camelcase
|
|
659
|
+
async aztec_avm_emitNullifier(foreignNullifier) {
|
|
563
660
|
const nullifier = fromSingle(foreignNullifier);
|
|
564
|
-
await this.handlerAsAvm().
|
|
661
|
+
await this.handlerAsAvm().emitNullifier(nullifier);
|
|
565
662
|
return toForeignCallResult([]);
|
|
566
663
|
}
|
|
567
|
-
|
|
664
|
+
// eslint-disable-next-line camelcase
|
|
665
|
+
async aztec_avm_emitNoteHash(foreignNoteHash) {
|
|
568
666
|
const noteHash = fromSingle(foreignNoteHash);
|
|
569
|
-
await this.handlerAsAvm().
|
|
667
|
+
await this.handlerAsAvm().emitNoteHash(noteHash);
|
|
570
668
|
return toForeignCallResult([]);
|
|
571
669
|
}
|
|
572
|
-
|
|
670
|
+
// eslint-disable-next-line camelcase
|
|
671
|
+
async aztec_avm_nullifierExists(foreignSiloedNullifier) {
|
|
573
672
|
const siloedNullifier = fromSingle(foreignSiloedNullifier);
|
|
574
|
-
const exists = await this.handlerAsAvm().
|
|
673
|
+
const exists = await this.handlerAsAvm().nullifierExists(siloedNullifier);
|
|
575
674
|
return toForeignCallResult([
|
|
576
675
|
toSingle(new Fr(exists))
|
|
577
676
|
]);
|
|
578
677
|
}
|
|
579
|
-
|
|
580
|
-
|
|
678
|
+
// eslint-disable-next-line camelcase
|
|
679
|
+
async aztec_avm_address() {
|
|
680
|
+
const contractAddress = await this.handlerAsAvm().address();
|
|
581
681
|
return toForeignCallResult([
|
|
582
682
|
toSingle(contractAddress.toField())
|
|
583
683
|
]);
|
|
584
684
|
}
|
|
585
|
-
|
|
586
|
-
|
|
685
|
+
// eslint-disable-next-line camelcase
|
|
686
|
+
async aztec_avm_blockNumber() {
|
|
687
|
+
const blockNumber = await this.handlerAsAvm().blockNumber();
|
|
587
688
|
return toForeignCallResult([
|
|
588
689
|
toSingle(new Fr(blockNumber))
|
|
589
690
|
]);
|
|
590
691
|
}
|
|
591
|
-
|
|
592
|
-
|
|
692
|
+
// eslint-disable-next-line camelcase
|
|
693
|
+
async aztec_avm_timestamp() {
|
|
694
|
+
const timestamp = await this.handlerAsAvm().timestamp();
|
|
593
695
|
return toForeignCallResult([
|
|
594
696
|
toSingle(new Fr(timestamp))
|
|
595
697
|
]);
|
|
596
698
|
}
|
|
597
|
-
|
|
598
|
-
|
|
699
|
+
// eslint-disable-next-line camelcase
|
|
700
|
+
async aztec_avm_isStaticCall() {
|
|
701
|
+
const isStaticCall = await this.handlerAsAvm().isStaticCall();
|
|
599
702
|
return toForeignCallResult([
|
|
600
703
|
toSingle(new Fr(isStaticCall ? 1 : 0))
|
|
601
704
|
]);
|
|
602
705
|
}
|
|
603
|
-
|
|
604
|
-
|
|
706
|
+
// eslint-disable-next-line camelcase
|
|
707
|
+
async aztec_avm_chainId() {
|
|
708
|
+
const chainId = await this.handlerAsAvm().chainId();
|
|
605
709
|
return toForeignCallResult([
|
|
606
710
|
toSingle(chainId)
|
|
607
711
|
]);
|
|
608
712
|
}
|
|
609
|
-
|
|
610
|
-
|
|
713
|
+
// eslint-disable-next-line camelcase
|
|
714
|
+
async aztec_avm_version() {
|
|
715
|
+
const version = await this.handlerAsAvm().version();
|
|
611
716
|
return toForeignCallResult([
|
|
612
717
|
toSingle(version)
|
|
613
718
|
]);
|
|
614
719
|
}
|
|
615
|
-
|
|
720
|
+
// eslint-disable-next-line camelcase
|
|
721
|
+
aztec_avm_returndataSize() {
|
|
616
722
|
throw new Error('Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead');
|
|
617
723
|
}
|
|
618
|
-
|
|
724
|
+
// eslint-disable-next-line camelcase
|
|
725
|
+
aztec_avm_returndataCopy(_foreignRdOffset, _foreignCopySize) {
|
|
619
726
|
throw new Error('Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead');
|
|
620
727
|
}
|
|
621
|
-
|
|
728
|
+
// eslint-disable-next-line camelcase
|
|
729
|
+
aztec_avm_call(_foreignL2Gas, _foreignDaGas, _foreignAddress, _foreignLength, _foreignArgs) {
|
|
622
730
|
throw new Error('Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead');
|
|
623
731
|
}
|
|
624
|
-
|
|
732
|
+
// eslint-disable-next-line camelcase
|
|
733
|
+
aztec_avm_staticCall(_foreignL2Gas, _foreignDaGas, _foreignAddress, _foreignLength, _foreignArgs) {
|
|
625
734
|
throw new Error('Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead');
|
|
626
735
|
}
|
|
627
|
-
|
|
736
|
+
// eslint-disable-next-line camelcase
|
|
737
|
+
aztec_avm_successCopy() {
|
|
628
738
|
throw new Error('Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead');
|
|
629
739
|
}
|
|
630
|
-
|
|
740
|
+
// eslint-disable-next-line camelcase
|
|
741
|
+
async aztec_txe_privateCallNewFlow(foreignFrom, foreignTargetContractAddress, foreignFunctionSelector, foreignArgs, foreignArgsHash, foreignIsStaticCall) {
|
|
631
742
|
const from = addressFromSingle(foreignFrom);
|
|
632
743
|
const targetContractAddress = addressFromSingle(foreignTargetContractAddress);
|
|
633
744
|
const functionSelector = FunctionSelector.fromField(fromSingle(foreignFunctionSelector));
|
|
634
745
|
const args = fromArray(foreignArgs);
|
|
635
746
|
const argsHash = fromSingle(foreignArgsHash);
|
|
636
747
|
const isStaticCall = fromSingle(foreignIsStaticCall).toBool();
|
|
637
|
-
const returnValues = await this.handlerAsTxe().
|
|
748
|
+
const returnValues = await this.handlerAsTxe().privateCallNewFlow(from, targetContractAddress, functionSelector, args, argsHash, isStaticCall, this.stateHandler.getCurrentJob());
|
|
749
|
+
// TODO(F-335): Avoid doing the following call here.
|
|
750
|
+
await this.stateHandler.cycleJob();
|
|
638
751
|
return toForeignCallResult([
|
|
639
752
|
toArray(returnValues)
|
|
640
753
|
]);
|
|
641
754
|
}
|
|
642
|
-
|
|
755
|
+
// eslint-disable-next-line camelcase
|
|
756
|
+
async aztec_txe_executeUtilityFunction(foreignTargetContractAddress, foreignFunctionSelector, foreignArgs) {
|
|
643
757
|
const targetContractAddress = addressFromSingle(foreignTargetContractAddress);
|
|
644
758
|
const functionSelector = FunctionSelector.fromField(fromSingle(foreignFunctionSelector));
|
|
645
759
|
const args = fromArray(foreignArgs);
|
|
646
|
-
const returnValues = await this.handlerAsTxe().
|
|
760
|
+
const returnValues = await this.handlerAsTxe().executeUtilityFunction(targetContractAddress, functionSelector, args, this.stateHandler.getCurrentJob());
|
|
761
|
+
// TODO(F-335): Avoid doing the following call here.
|
|
762
|
+
await this.stateHandler.cycleJob();
|
|
647
763
|
return toForeignCallResult([
|
|
648
764
|
toArray(returnValues)
|
|
649
765
|
]);
|
|
650
766
|
}
|
|
651
|
-
|
|
767
|
+
// eslint-disable-next-line camelcase
|
|
768
|
+
async aztec_txe_publicCallNewFlow(foreignFrom, foreignAddress, foreignCalldata, foreignIsStaticCall) {
|
|
652
769
|
const from = addressFromSingle(foreignFrom);
|
|
653
770
|
const address = addressFromSingle(foreignAddress);
|
|
654
771
|
const calldata = fromArray(foreignCalldata);
|
|
655
772
|
const isStaticCall = fromSingle(foreignIsStaticCall).toBool();
|
|
656
|
-
const returnValues = await this.handlerAsTxe().
|
|
773
|
+
const returnValues = await this.handlerAsTxe().publicCallNewFlow(from, address, calldata, isStaticCall);
|
|
774
|
+
// TODO(F-335): Avoid doing the following call here.
|
|
775
|
+
await this.stateHandler.cycleJob();
|
|
657
776
|
return toForeignCallResult([
|
|
658
777
|
toArray(returnValues)
|
|
659
778
|
]);
|
|
660
779
|
}
|
|
661
|
-
|
|
662
|
-
|
|
780
|
+
// eslint-disable-next-line camelcase
|
|
781
|
+
async aztec_prv_getSenderForTags() {
|
|
782
|
+
const sender = await this.handlerAsPrivate().getSenderForTags();
|
|
663
783
|
// Return a Noir Option struct with `some` and `value` fields
|
|
664
784
|
if (sender === undefined) {
|
|
665
785
|
// No sender found, return Option with some=0 and value=0
|
|
@@ -675,15 +795,17 @@ export class RPCTranslator {
|
|
|
675
795
|
]);
|
|
676
796
|
}
|
|
677
797
|
}
|
|
678
|
-
|
|
798
|
+
// eslint-disable-next-line camelcase
|
|
799
|
+
async aztec_prv_setSenderForTags(foreignSenderForTags) {
|
|
679
800
|
const senderForTags = AztecAddress.fromField(fromSingle(foreignSenderForTags));
|
|
680
|
-
await this.handlerAsPrivate().
|
|
801
|
+
await this.handlerAsPrivate().setSenderForTags(senderForTags);
|
|
681
802
|
return toForeignCallResult([]);
|
|
682
803
|
}
|
|
683
|
-
|
|
804
|
+
// eslint-disable-next-line camelcase
|
|
805
|
+
async aztec_prv_getNextAppTagAsSender(foreignSender, foreignRecipient) {
|
|
684
806
|
const sender = AztecAddress.fromField(fromSingle(foreignSender));
|
|
685
807
|
const recipient = AztecAddress.fromField(fromSingle(foreignRecipient));
|
|
686
|
-
const nextAppTag = await this.handlerAsPrivate().
|
|
808
|
+
const nextAppTag = await this.handlerAsPrivate().getNextAppTagAsSender(sender, recipient);
|
|
687
809
|
return toForeignCallResult([
|
|
688
810
|
toSingle(nextAppTag.value)
|
|
689
811
|
]);
|