@aztec/txe 0.0.1-commit.e3c1de76 → 0.0.1-commit.e588bc7e5
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 +126 -51
- package/dest/rpc_translator.d.ts +88 -83
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +308 -163
- 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 +9 -8
- package/dest/state_machine/dummy_p2p_client.d.ts +18 -13
- package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
- package/dest/state_machine/dummy_p2p_client.js +33 -18
- package/dest/state_machine/global_variable_builder.d.ts +3 -3
- package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
- package/dest/state_machine/global_variable_builder.js +1 -1
- package/dest/state_machine/index.d.ts +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 +19 -3
- package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
- package/dest/state_machine/mock_epoch_cache.js +36 -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 +93 -25
- 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/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 +142 -97
- package/src/rpc_translator.ts +357 -180
- package/src/state_machine/archiver.ts +8 -5
- package/src/state_machine/dummy_p2p_client.ts +46 -24
- package/src/state_machine/global_variable_builder.ts +7 -1
- package/src/state_machine/index.ts +30 -9
- package/src/state_machine/mock_epoch_cache.ts +47 -3
- package/src/state_machine/synchronizer.ts +4 -4
- package/src/txe_session.ts +99 -72
- package/src/util/txe_public_contract_data_source.ts +10 -38
- package/src/utils/block_creation.ts +3 -1
- package/dest/util/txe_contract_store.d.ts +0 -12
- package/dest/util/txe_contract_store.d.ts.map +0 -1
- package/dest/util/txe_contract_store.js +0 -22
- package/src/util/txe_contract_store.ts +0 -36
package/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_setHashPreimage(foreignValues, foreignHash) {
|
|
198
223
|
const values = fromArray(foreignValues);
|
|
199
224
|
const hash = fromSingle(foreignHash);
|
|
200
|
-
this.handlerAsPrivate().
|
|
225
|
+
this.handlerAsPrivate().setHashPreimage(values, hash);
|
|
201
226
|
return toForeignCallResult([]);
|
|
202
227
|
}
|
|
203
|
-
|
|
228
|
+
// eslint-disable-next-line camelcase
|
|
229
|
+
async aztec_prv_getHashPreimage(foreignHash) {
|
|
204
230
|
const hash = fromSingle(foreignHash);
|
|
205
|
-
const returns = await this.handlerAsPrivate().
|
|
231
|
+
const returns = await this.handlerAsPrivate().getHashPreimage(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
|
-
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_getFromPublicStorage(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().getFromPublicStorage(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_doesNullifierExist(foreignInnerNullifier) {
|
|
304
339
|
const innerNullifier = fromSingle(foreignInnerNullifier);
|
|
305
|
-
const exists = await this.handlerAsUtility().
|
|
340
|
+
const exists = await this.handlerAsUtility().doesNullifierExist(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,36 +354,53 @@ 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_getPublicKeysAndPartialAddress(foreignAddress) {
|
|
322
359
|
const address = addressFromSingle(foreignAddress);
|
|
323
|
-
const
|
|
324
|
-
return
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
360
|
+
const result = await this.handlerAsUtility().getPublicKeysAndPartialAddress(address);
|
|
361
|
+
// We are going to return a Noir Option struct to represent the possibility of null values. Options are a struct
|
|
362
|
+
// with two fields: `some` (a boolean) and `value` (a field array in this case).
|
|
363
|
+
if (result === undefined) {
|
|
364
|
+
// No data was found so we set `some` to 0 and pad `value` with zeros get the correct return size.
|
|
365
|
+
return toForeignCallResult([
|
|
366
|
+
toSingle(new Fr(0)),
|
|
367
|
+
toArray(Array(13).fill(new Fr(0)))
|
|
368
|
+
]);
|
|
369
|
+
} else {
|
|
370
|
+
// Data was found so we set `some` to 1 and return it along with `value`.
|
|
371
|
+
return toForeignCallResult([
|
|
372
|
+
toSingle(new Fr(1)),
|
|
373
|
+
toArray([
|
|
374
|
+
...result.publicKeys.toFields(),
|
|
375
|
+
result.partialAddress
|
|
376
|
+
])
|
|
377
|
+
]);
|
|
378
|
+
}
|
|
330
379
|
}
|
|
331
|
-
|
|
380
|
+
// eslint-disable-next-line camelcase
|
|
381
|
+
async aztec_utl_getKeyValidationRequest(foreignPkMHash) {
|
|
332
382
|
const pkMHash = fromSingle(foreignPkMHash);
|
|
333
|
-
const keyValidationRequest = await this.handlerAsUtility().
|
|
383
|
+
const keyValidationRequest = await this.handlerAsUtility().getKeyValidationRequest(pkMHash);
|
|
334
384
|
return toForeignCallResult(keyValidationRequest.toFields().map(toSingle));
|
|
335
385
|
}
|
|
336
|
-
|
|
386
|
+
// eslint-disable-next-line camelcase
|
|
387
|
+
aztec_prv_callPrivateFunction(_foreignTargetContractAddress, _foreignFunctionSelector, _foreignArgsHash, _foreignSideEffectCounter, _foreignIsStaticCall) {
|
|
337
388
|
throw new Error('Contract calls are forbidden inside a `TestEnvironment::private_context`, use `private_call` instead');
|
|
338
389
|
}
|
|
339
|
-
|
|
390
|
+
// eslint-disable-next-line camelcase
|
|
391
|
+
async aztec_utl_getNullifierMembershipWitness(foreignBlockHash, foreignNullifier) {
|
|
340
392
|
const blockHash = new BlockHash(fromSingle(foreignBlockHash));
|
|
341
393
|
const nullifier = fromSingle(foreignNullifier);
|
|
342
|
-
const witness = await this.handlerAsUtility().
|
|
394
|
+
const witness = await this.handlerAsUtility().getNullifierMembershipWitness(blockHash, nullifier);
|
|
343
395
|
if (!witness) {
|
|
344
396
|
throw new Error(`Nullifier membership witness not found at block ${blockHash}.`);
|
|
345
397
|
}
|
|
346
398
|
return toForeignCallResult(witness.toNoirRepresentation());
|
|
347
399
|
}
|
|
348
|
-
|
|
400
|
+
// eslint-disable-next-line camelcase
|
|
401
|
+
async aztec_utl_getAuthWitness(foreignMessageHash) {
|
|
349
402
|
const messageHash = fromSingle(foreignMessageHash);
|
|
350
|
-
const authWitness = await this.handlerAsUtility().
|
|
403
|
+
const authWitness = await this.handlerAsUtility().getAuthWitness(messageHash);
|
|
351
404
|
if (!authWitness) {
|
|
352
405
|
throw new Error(`Auth witness not found for message hash ${messageHash}.`);
|
|
353
406
|
}
|
|
@@ -355,92 +408,118 @@ export class RPCTranslator {
|
|
|
355
408
|
toArray(authWitness)
|
|
356
409
|
]);
|
|
357
410
|
}
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
}
|
|
361
|
-
privateNotifySetPublicTeardownFunctionCall(_foreignTargetContractAddress, _foreignCalldataHash, _foreignSideEffectCounter, _foreignIsStaticCall) {
|
|
411
|
+
// eslint-disable-next-line camelcase
|
|
412
|
+
aztec_prv_assertValidPublicCalldata(_foreignCalldataHash) {
|
|
362
413
|
throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
|
|
363
414
|
}
|
|
364
|
-
|
|
415
|
+
// eslint-disable-next-line camelcase
|
|
416
|
+
aztec_prv_notifyRevertiblePhaseStart(_foreignMinRevertibleSideEffectCounter) {
|
|
365
417
|
throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
|
|
366
418
|
}
|
|
367
|
-
|
|
419
|
+
// eslint-disable-next-line camelcase
|
|
420
|
+
async aztec_prv_isExecutionInRevertiblePhase(foreignSideEffectCounter) {
|
|
368
421
|
const sideEffectCounter = fromSingle(foreignSideEffectCounter).toNumber();
|
|
369
|
-
const isRevertible = await this.handlerAsPrivate().
|
|
422
|
+
const isRevertible = await this.handlerAsPrivate().isExecutionInRevertiblePhase(sideEffectCounter);
|
|
370
423
|
return toForeignCallResult([
|
|
371
424
|
toSingle(new Fr(isRevertible))
|
|
372
425
|
]);
|
|
373
426
|
}
|
|
374
|
-
|
|
375
|
-
|
|
427
|
+
// eslint-disable-next-line camelcase
|
|
428
|
+
aztec_utl_getUtilityContext() {
|
|
429
|
+
const context = this.handlerAsUtility().getUtilityContext();
|
|
376
430
|
return toForeignCallResult(context.toNoirRepresentation());
|
|
377
431
|
}
|
|
378
|
-
|
|
432
|
+
// eslint-disable-next-line camelcase
|
|
433
|
+
async aztec_utl_getBlockHeader(foreignBlockNumber) {
|
|
379
434
|
const blockNumber = BlockNumber(fromSingle(foreignBlockNumber).toNumber());
|
|
380
|
-
const header = await this.handlerAsUtility().
|
|
435
|
+
const header = await this.handlerAsUtility().getBlockHeader(blockNumber);
|
|
381
436
|
if (!header) {
|
|
382
437
|
throw new Error(`Block header not found for block ${blockNumber}.`);
|
|
383
438
|
}
|
|
384
439
|
return toForeignCallResult(header.toFields().map(toSingle));
|
|
385
440
|
}
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
const
|
|
389
|
-
const
|
|
441
|
+
// eslint-disable-next-line camelcase
|
|
442
|
+
async aztec_utl_getNoteHashMembershipWitness(foreignAnchorBlockHash, foreignNoteHash) {
|
|
443
|
+
const blockHash = new BlockHash(fromSingle(foreignAnchorBlockHash));
|
|
444
|
+
const noteHash = fromSingle(foreignNoteHash);
|
|
445
|
+
const witness = await this.handlerAsUtility().getNoteHashMembershipWitness(blockHash, noteHash);
|
|
390
446
|
if (!witness) {
|
|
391
|
-
throw new Error(`Note hash ${
|
|
447
|
+
throw new Error(`Note hash ${noteHash} not found in the note hash tree at block ${blockHash.toString()}.`);
|
|
392
448
|
}
|
|
393
449
|
return toForeignCallResult(witness.toNoirRepresentation());
|
|
394
450
|
}
|
|
395
|
-
|
|
451
|
+
// eslint-disable-next-line camelcase
|
|
452
|
+
async aztec_utl_getBlockHashMembershipWitness(foreignAnchorBlockHash, foreignBlockHash) {
|
|
453
|
+
const anchorBlockHash = new BlockHash(fromSingle(foreignAnchorBlockHash));
|
|
396
454
|
const blockHash = new BlockHash(fromSingle(foreignBlockHash));
|
|
397
|
-
const
|
|
398
|
-
const witness = await this.handlerAsUtility().utilityGetArchiveMembershipWitness(blockHash, leafValue);
|
|
455
|
+
const witness = await this.handlerAsUtility().getBlockHashMembershipWitness(anchorBlockHash, blockHash);
|
|
399
456
|
if (!witness) {
|
|
400
|
-
throw new Error(`Block hash ${
|
|
457
|
+
throw new Error(`Block hash ${blockHash.toString()} not found in the archive tree at anchor block ${anchorBlockHash.toString()}.`);
|
|
401
458
|
}
|
|
402
459
|
return toForeignCallResult(witness.toNoirRepresentation());
|
|
403
460
|
}
|
|
404
|
-
|
|
461
|
+
// eslint-disable-next-line camelcase
|
|
462
|
+
async aztec_utl_getLowNullifierMembershipWitness(foreignBlockHash, foreignNullifier) {
|
|
405
463
|
const blockHash = new BlockHash(fromSingle(foreignBlockHash));
|
|
406
464
|
const nullifier = fromSingle(foreignNullifier);
|
|
407
|
-
const witness = await this.handlerAsUtility().
|
|
465
|
+
const witness = await this.handlerAsUtility().getLowNullifierMembershipWitness(blockHash, nullifier);
|
|
408
466
|
if (!witness) {
|
|
409
467
|
throw new Error(`Low nullifier witness not found for nullifier ${nullifier} at block ${blockHash}.`);
|
|
410
468
|
}
|
|
411
469
|
return toForeignCallResult(witness.toNoirRepresentation());
|
|
412
470
|
}
|
|
413
|
-
|
|
471
|
+
// eslint-disable-next-line camelcase
|
|
472
|
+
async aztec_utl_getPendingTaggedLogs(foreignPendingTaggedLogArrayBaseSlot, foreignScope) {
|
|
414
473
|
const pendingTaggedLogArrayBaseSlot = fromSingle(foreignPendingTaggedLogArrayBaseSlot);
|
|
415
|
-
|
|
474
|
+
const scope = AztecAddress.fromField(fromSingle(foreignScope));
|
|
475
|
+
await this.handlerAsUtility().getPendingTaggedLogs(pendingTaggedLogArrayBaseSlot, scope);
|
|
416
476
|
return toForeignCallResult([]);
|
|
417
477
|
}
|
|
418
|
-
|
|
478
|
+
// eslint-disable-next-line camelcase
|
|
479
|
+
async aztec_utl_validateAndStoreEnqueuedNotesAndEvents(foreignContractAddress, foreignNoteValidationRequestsArrayBaseSlot, foreignEventValidationRequestsArrayBaseSlot, foreignMaxNotePackedLen, foreignMaxEventSerializedLen, foreignScope) {
|
|
419
480
|
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
420
481
|
const noteValidationRequestsArrayBaseSlot = fromSingle(foreignNoteValidationRequestsArrayBaseSlot);
|
|
421
482
|
const eventValidationRequestsArrayBaseSlot = fromSingle(foreignEventValidationRequestsArrayBaseSlot);
|
|
422
|
-
|
|
483
|
+
const maxNotePackedLen = fromSingle(foreignMaxNotePackedLen).toNumber();
|
|
484
|
+
const maxEventSerializedLen = fromSingle(foreignMaxEventSerializedLen).toNumber();
|
|
485
|
+
const scope = AztecAddress.fromField(fromSingle(foreignScope));
|
|
486
|
+
await this.handlerAsUtility().validateAndStoreEnqueuedNotesAndEvents(contractAddress, noteValidationRequestsArrayBaseSlot, eventValidationRequestsArrayBaseSlot, maxNotePackedLen, maxEventSerializedLen, scope);
|
|
423
487
|
return toForeignCallResult([]);
|
|
424
488
|
}
|
|
425
|
-
|
|
489
|
+
// eslint-disable-next-line camelcase
|
|
490
|
+
async aztec_utl_getLogsByTag(foreignContractAddress, foreignLogRetrievalRequestsArrayBaseSlot, foreignLogRetrievalResponsesArrayBaseSlot, foreignScope) {
|
|
426
491
|
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
427
492
|
const logRetrievalRequestsArrayBaseSlot = fromSingle(foreignLogRetrievalRequestsArrayBaseSlot);
|
|
428
493
|
const logRetrievalResponsesArrayBaseSlot = fromSingle(foreignLogRetrievalResponsesArrayBaseSlot);
|
|
429
|
-
|
|
494
|
+
const scope = AztecAddress.fromField(fromSingle(foreignScope));
|
|
495
|
+
await this.handlerAsUtility().getLogsByTag(contractAddress, logRetrievalRequestsArrayBaseSlot, logRetrievalResponsesArrayBaseSlot, scope);
|
|
430
496
|
return toForeignCallResult([]);
|
|
431
497
|
}
|
|
432
|
-
|
|
498
|
+
// eslint-disable-next-line camelcase
|
|
499
|
+
async aztec_utl_getMessageContextsByTxHash(foreignContractAddress, foreignMessageContextRequestsArrayBaseSlot, foreignMessageContextResponsesArrayBaseSlot, foreignScope) {
|
|
500
|
+
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
501
|
+
const messageContextRequestsArrayBaseSlot = fromSingle(foreignMessageContextRequestsArrayBaseSlot);
|
|
502
|
+
const messageContextResponsesArrayBaseSlot = fromSingle(foreignMessageContextResponsesArrayBaseSlot);
|
|
503
|
+
const scope = AztecAddress.fromField(fromSingle(foreignScope));
|
|
504
|
+
await this.handlerAsUtility().getMessageContextsByTxHash(contractAddress, messageContextRequestsArrayBaseSlot, messageContextResponsesArrayBaseSlot, scope);
|
|
505
|
+
return toForeignCallResult([]);
|
|
506
|
+
}
|
|
507
|
+
// eslint-disable-next-line camelcase
|
|
508
|
+
aztec_utl_setCapsule(foreignContractAddress, foreignSlot, foreignCapsule, foreignScope) {
|
|
433
509
|
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
434
510
|
const slot = fromSingle(foreignSlot);
|
|
435
511
|
const capsule = fromArray(foreignCapsule);
|
|
436
|
-
|
|
512
|
+
const scope = AztecAddress.fromField(fromSingle(foreignScope));
|
|
513
|
+
this.handlerAsUtility().setCapsule(contractAddress, slot, capsule, scope);
|
|
437
514
|
return toForeignCallResult([]);
|
|
438
515
|
}
|
|
439
|
-
|
|
516
|
+
// eslint-disable-next-line camelcase
|
|
517
|
+
async aztec_utl_getCapsule(foreignContractAddress, foreignSlot, foreignTSize, foreignScope) {
|
|
440
518
|
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
441
519
|
const slot = fromSingle(foreignSlot);
|
|
442
520
|
const tSize = fromSingle(foreignTSize).toNumber();
|
|
443
|
-
const
|
|
521
|
+
const scope = AztecAddress.fromField(fromSingle(foreignScope));
|
|
522
|
+
const values = await this.handlerAsUtility().getCapsule(contractAddress, slot, scope);
|
|
444
523
|
// We are going to return a Noir Option struct to represent the possibility of null values. Options are a struct
|
|
445
524
|
// with two fields: `some` (a boolean) and `value` (a field array in this case).
|
|
446
525
|
if (values === null) {
|
|
@@ -457,197 +536,261 @@ export class RPCTranslator {
|
|
|
457
536
|
]);
|
|
458
537
|
}
|
|
459
538
|
}
|
|
460
|
-
|
|
539
|
+
// eslint-disable-next-line camelcase
|
|
540
|
+
aztec_utl_deleteCapsule(foreignContractAddress, foreignSlot, foreignScope) {
|
|
461
541
|
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
462
542
|
const slot = fromSingle(foreignSlot);
|
|
463
|
-
|
|
543
|
+
const scope = AztecAddress.fromField(fromSingle(foreignScope));
|
|
544
|
+
this.handlerAsUtility().deleteCapsule(contractAddress, slot, scope);
|
|
464
545
|
return toForeignCallResult([]);
|
|
465
546
|
}
|
|
466
|
-
|
|
547
|
+
// eslint-disable-next-line camelcase
|
|
548
|
+
async aztec_utl_copyCapsule(foreignContractAddress, foreignSrcSlot, foreignDstSlot, foreignNumEntries, foreignScope) {
|
|
467
549
|
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
468
550
|
const srcSlot = fromSingle(foreignSrcSlot);
|
|
469
551
|
const dstSlot = fromSingle(foreignDstSlot);
|
|
470
552
|
const numEntries = fromSingle(foreignNumEntries).toNumber();
|
|
471
|
-
|
|
553
|
+
const scope = AztecAddress.fromField(fromSingle(foreignScope));
|
|
554
|
+
await this.handlerAsUtility().copyCapsule(contractAddress, srcSlot, dstSlot, numEntries, scope);
|
|
472
555
|
return toForeignCallResult([]);
|
|
473
556
|
}
|
|
474
557
|
// TODO: I forgot to add a corresponding function here, when I introduced an oracle method to txe_oracle.ts.
|
|
475
558
|
// 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
559
|
// to implement this function here. Isn't there a way to programmatically identify that this is missing, given the
|
|
477
560
|
// existence of a txe_oracle method?
|
|
478
|
-
|
|
561
|
+
// eslint-disable-next-line camelcase
|
|
562
|
+
async aztec_utl_decryptAes128(foreignCiphertextBVecStorage, foreignCiphertextLength, foreignIv, foreignSymKey) {
|
|
479
563
|
const ciphertext = fromUintBoundedVec(foreignCiphertextBVecStorage, foreignCiphertextLength, 8);
|
|
480
564
|
const iv = fromUintArray(foreignIv, 8);
|
|
481
565
|
const symKey = fromUintArray(foreignSymKey, 8);
|
|
482
|
-
|
|
483
|
-
|
|
566
|
+
// Noir Option<BoundedVec> is encoded as [is_some: Field, storage: Field[], length: Field].
|
|
567
|
+
try {
|
|
568
|
+
const plaintextBuffer = await this.handlerAsUtility().decryptAes128(ciphertext, iv, symKey);
|
|
569
|
+
const [storage, length] = arrayToBoundedVec(bufferToU8Array(plaintextBuffer), foreignCiphertextBVecStorage.length);
|
|
570
|
+
return toForeignCallResult([
|
|
571
|
+
toSingle(new Fr(1)),
|
|
572
|
+
storage,
|
|
573
|
+
length
|
|
574
|
+
]);
|
|
575
|
+
} catch {
|
|
576
|
+
const zeroStorage = toArray(Array(foreignCiphertextBVecStorage.length).fill(new Fr(0)));
|
|
577
|
+
return toForeignCallResult([
|
|
578
|
+
toSingle(new Fr(0)),
|
|
579
|
+
zeroStorage,
|
|
580
|
+
toSingle(new Fr(0))
|
|
581
|
+
]);
|
|
582
|
+
}
|
|
484
583
|
}
|
|
485
|
-
|
|
584
|
+
// eslint-disable-next-line camelcase
|
|
585
|
+
async aztec_utl_getSharedSecret(foreignAddress, foreignEphPKField0, foreignEphPKField1, foreignEphPKField2, foreignContractAddress) {
|
|
486
586
|
const address = AztecAddress.fromField(fromSingle(foreignAddress));
|
|
487
587
|
const ephPK = Point.fromFields([
|
|
488
588
|
fromSingle(foreignEphPKField0),
|
|
489
589
|
fromSingle(foreignEphPKField1),
|
|
490
590
|
fromSingle(foreignEphPKField2)
|
|
491
591
|
]);
|
|
492
|
-
const
|
|
493
|
-
|
|
592
|
+
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
593
|
+
const secret = await this.handlerAsUtility().getSharedSecret(address, ephPK, contractAddress);
|
|
594
|
+
return toForeignCallResult([
|
|
595
|
+
toSingle(secret)
|
|
596
|
+
]);
|
|
597
|
+
}
|
|
598
|
+
// eslint-disable-next-line camelcase
|
|
599
|
+
aztec_utl_setContractSyncCacheInvalid(foreignContractAddress, foreignScopes, foreignScopeCount) {
|
|
600
|
+
const contractAddress = addressFromSingle(foreignContractAddress);
|
|
601
|
+
const count = fromSingle(foreignScopeCount).toNumber();
|
|
602
|
+
const scopes = fromArray(foreignScopes).slice(0, count).map((f)=>new AztecAddress(f));
|
|
603
|
+
this.handlerAsUtility().setContractSyncCacheInvalid(contractAddress, scopes);
|
|
604
|
+
return Promise.resolve(toForeignCallResult([]));
|
|
494
605
|
}
|
|
495
|
-
|
|
606
|
+
// eslint-disable-next-line camelcase
|
|
607
|
+
aztec_utl_emitOffchainEffect(_foreignData) {
|
|
496
608
|
throw new Error('Offchain effects are not yet supported in the TestEnvironment');
|
|
497
609
|
}
|
|
498
610
|
// AVM opcodes
|
|
499
|
-
|
|
611
|
+
// eslint-disable-next-line camelcase
|
|
612
|
+
aztec_avm_emitPublicLog(_foreignMessage) {
|
|
500
613
|
// TODO(#8811): Implement
|
|
501
614
|
return toForeignCallResult([]);
|
|
502
615
|
}
|
|
503
|
-
|
|
616
|
+
// eslint-disable-next-line camelcase
|
|
617
|
+
async aztec_avm_storageRead(foreignSlot, foreignContractAddress) {
|
|
504
618
|
const slot = fromSingle(foreignSlot);
|
|
505
619
|
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
506
|
-
const value = (await this.handlerAsAvm().
|
|
620
|
+
const value = (await this.handlerAsAvm().storageRead(slot, contractAddress)).value;
|
|
507
621
|
return toForeignCallResult([
|
|
508
622
|
toSingle(new Fr(value))
|
|
509
623
|
]);
|
|
510
624
|
}
|
|
511
|
-
|
|
625
|
+
// eslint-disable-next-line camelcase
|
|
626
|
+
async aztec_avm_storageWrite(foreignSlot, foreignValue) {
|
|
512
627
|
const slot = fromSingle(foreignSlot);
|
|
513
628
|
const value = fromSingle(foreignValue);
|
|
514
|
-
await this.handlerAsAvm().
|
|
629
|
+
await this.handlerAsAvm().storageWrite(slot, value);
|
|
515
630
|
return toForeignCallResult([]);
|
|
516
631
|
}
|
|
517
|
-
|
|
632
|
+
// eslint-disable-next-line camelcase
|
|
633
|
+
async aztec_avm_getContractInstanceDeployer(foreignAddress) {
|
|
518
634
|
const address = addressFromSingle(foreignAddress);
|
|
519
|
-
const instance = await this.handlerAsUtility().
|
|
635
|
+
const instance = await this.handlerAsUtility().getContractInstance(address);
|
|
520
636
|
return toForeignCallResult([
|
|
521
637
|
toSingle(instance.deployer),
|
|
522
638
|
// AVM requires an extra boolean indicating the instance was found
|
|
523
639
|
toSingle(new Fr(1))
|
|
524
640
|
]);
|
|
525
641
|
}
|
|
526
|
-
|
|
642
|
+
// eslint-disable-next-line camelcase
|
|
643
|
+
async aztec_avm_getContractInstanceClassId(foreignAddress) {
|
|
527
644
|
const address = addressFromSingle(foreignAddress);
|
|
528
|
-
const instance = await this.handlerAsUtility().
|
|
645
|
+
const instance = await this.handlerAsUtility().getContractInstance(address);
|
|
529
646
|
return toForeignCallResult([
|
|
530
647
|
toSingle(instance.currentContractClassId),
|
|
531
648
|
// AVM requires an extra boolean indicating the instance was found
|
|
532
649
|
toSingle(new Fr(1))
|
|
533
650
|
]);
|
|
534
651
|
}
|
|
535
|
-
|
|
652
|
+
// eslint-disable-next-line camelcase
|
|
653
|
+
async aztec_avm_getContractInstanceInitializationHash(foreignAddress) {
|
|
536
654
|
const address = addressFromSingle(foreignAddress);
|
|
537
|
-
const instance = await this.handlerAsUtility().
|
|
655
|
+
const instance = await this.handlerAsUtility().getContractInstance(address);
|
|
538
656
|
return toForeignCallResult([
|
|
539
657
|
toSingle(instance.initializationHash),
|
|
540
658
|
// AVM requires an extra boolean indicating the instance was found
|
|
541
659
|
toSingle(new Fr(1))
|
|
542
660
|
]);
|
|
543
661
|
}
|
|
544
|
-
|
|
545
|
-
|
|
662
|
+
// eslint-disable-next-line camelcase
|
|
663
|
+
async aztec_avm_sender() {
|
|
664
|
+
const sender = await this.handlerAsAvm().sender();
|
|
546
665
|
return toForeignCallResult([
|
|
547
666
|
toSingle(sender)
|
|
548
667
|
]);
|
|
549
668
|
}
|
|
550
|
-
|
|
669
|
+
// eslint-disable-next-line camelcase
|
|
670
|
+
async aztec_avm_emitNullifier(foreignNullifier) {
|
|
551
671
|
const nullifier = fromSingle(foreignNullifier);
|
|
552
|
-
await this.handlerAsAvm().
|
|
672
|
+
await this.handlerAsAvm().emitNullifier(nullifier);
|
|
553
673
|
return toForeignCallResult([]);
|
|
554
674
|
}
|
|
555
|
-
|
|
675
|
+
// eslint-disable-next-line camelcase
|
|
676
|
+
async aztec_avm_emitNoteHash(foreignNoteHash) {
|
|
556
677
|
const noteHash = fromSingle(foreignNoteHash);
|
|
557
|
-
await this.handlerAsAvm().
|
|
678
|
+
await this.handlerAsAvm().emitNoteHash(noteHash);
|
|
558
679
|
return toForeignCallResult([]);
|
|
559
680
|
}
|
|
560
|
-
|
|
681
|
+
// eslint-disable-next-line camelcase
|
|
682
|
+
async aztec_avm_nullifierExists(foreignSiloedNullifier) {
|
|
561
683
|
const siloedNullifier = fromSingle(foreignSiloedNullifier);
|
|
562
|
-
const exists = await this.handlerAsAvm().
|
|
684
|
+
const exists = await this.handlerAsAvm().nullifierExists(siloedNullifier);
|
|
563
685
|
return toForeignCallResult([
|
|
564
686
|
toSingle(new Fr(exists))
|
|
565
687
|
]);
|
|
566
688
|
}
|
|
567
|
-
|
|
568
|
-
|
|
689
|
+
// eslint-disable-next-line camelcase
|
|
690
|
+
async aztec_avm_address() {
|
|
691
|
+
const contractAddress = await this.handlerAsAvm().address();
|
|
569
692
|
return toForeignCallResult([
|
|
570
693
|
toSingle(contractAddress.toField())
|
|
571
694
|
]);
|
|
572
695
|
}
|
|
573
|
-
|
|
574
|
-
|
|
696
|
+
// eslint-disable-next-line camelcase
|
|
697
|
+
async aztec_avm_blockNumber() {
|
|
698
|
+
const blockNumber = await this.handlerAsAvm().blockNumber();
|
|
575
699
|
return toForeignCallResult([
|
|
576
700
|
toSingle(new Fr(blockNumber))
|
|
577
701
|
]);
|
|
578
702
|
}
|
|
579
|
-
|
|
580
|
-
|
|
703
|
+
// eslint-disable-next-line camelcase
|
|
704
|
+
async aztec_avm_timestamp() {
|
|
705
|
+
const timestamp = await this.handlerAsAvm().timestamp();
|
|
581
706
|
return toForeignCallResult([
|
|
582
707
|
toSingle(new Fr(timestamp))
|
|
583
708
|
]);
|
|
584
709
|
}
|
|
585
|
-
|
|
586
|
-
|
|
710
|
+
// eslint-disable-next-line camelcase
|
|
711
|
+
async aztec_avm_isStaticCall() {
|
|
712
|
+
const isStaticCall = await this.handlerAsAvm().isStaticCall();
|
|
587
713
|
return toForeignCallResult([
|
|
588
714
|
toSingle(new Fr(isStaticCall ? 1 : 0))
|
|
589
715
|
]);
|
|
590
716
|
}
|
|
591
|
-
|
|
592
|
-
|
|
717
|
+
// eslint-disable-next-line camelcase
|
|
718
|
+
async aztec_avm_chainId() {
|
|
719
|
+
const chainId = await this.handlerAsAvm().chainId();
|
|
593
720
|
return toForeignCallResult([
|
|
594
721
|
toSingle(chainId)
|
|
595
722
|
]);
|
|
596
723
|
}
|
|
597
|
-
|
|
598
|
-
|
|
724
|
+
// eslint-disable-next-line camelcase
|
|
725
|
+
async aztec_avm_version() {
|
|
726
|
+
const version = await this.handlerAsAvm().version();
|
|
599
727
|
return toForeignCallResult([
|
|
600
728
|
toSingle(version)
|
|
601
729
|
]);
|
|
602
730
|
}
|
|
603
|
-
|
|
731
|
+
// eslint-disable-next-line camelcase
|
|
732
|
+
aztec_avm_returndataSize() {
|
|
604
733
|
throw new Error('Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead');
|
|
605
734
|
}
|
|
606
|
-
|
|
735
|
+
// eslint-disable-next-line camelcase
|
|
736
|
+
aztec_avm_returndataCopy(_foreignRdOffset, _foreignCopySize) {
|
|
607
737
|
throw new Error('Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead');
|
|
608
738
|
}
|
|
609
|
-
|
|
739
|
+
// eslint-disable-next-line camelcase
|
|
740
|
+
aztec_avm_call(_foreignL2Gas, _foreignDaGas, _foreignAddress, _foreignLength, _foreignArgs) {
|
|
610
741
|
throw new Error('Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead');
|
|
611
742
|
}
|
|
612
|
-
|
|
743
|
+
// eslint-disable-next-line camelcase
|
|
744
|
+
aztec_avm_staticCall(_foreignL2Gas, _foreignDaGas, _foreignAddress, _foreignLength, _foreignArgs) {
|
|
613
745
|
throw new Error('Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead');
|
|
614
746
|
}
|
|
615
|
-
|
|
747
|
+
// eslint-disable-next-line camelcase
|
|
748
|
+
aztec_avm_successCopy() {
|
|
616
749
|
throw new Error('Contract calls are forbidden inside a `TestEnvironment::public_context`, use `public_call` instead');
|
|
617
750
|
}
|
|
618
|
-
|
|
751
|
+
// eslint-disable-next-line camelcase
|
|
752
|
+
async aztec_txe_privateCallNewFlow(foreignFrom, foreignTargetContractAddress, foreignFunctionSelector, foreignArgs, foreignArgsHash, foreignIsStaticCall) {
|
|
619
753
|
const from = addressFromSingle(foreignFrom);
|
|
620
754
|
const targetContractAddress = addressFromSingle(foreignTargetContractAddress);
|
|
621
755
|
const functionSelector = FunctionSelector.fromField(fromSingle(foreignFunctionSelector));
|
|
622
756
|
const args = fromArray(foreignArgs);
|
|
623
757
|
const argsHash = fromSingle(foreignArgsHash);
|
|
624
758
|
const isStaticCall = fromSingle(foreignIsStaticCall).toBool();
|
|
625
|
-
const returnValues = await this.handlerAsTxe().
|
|
759
|
+
const returnValues = await this.handlerAsTxe().privateCallNewFlow(from, targetContractAddress, functionSelector, args, argsHash, isStaticCall, this.stateHandler.getCurrentJob());
|
|
760
|
+
// TODO(F-335): Avoid doing the following call here.
|
|
761
|
+
await this.stateHandler.cycleJob();
|
|
626
762
|
return toForeignCallResult([
|
|
627
763
|
toArray(returnValues)
|
|
628
764
|
]);
|
|
629
765
|
}
|
|
630
|
-
|
|
766
|
+
// eslint-disable-next-line camelcase
|
|
767
|
+
async aztec_txe_executeUtilityFunction(foreignTargetContractAddress, foreignFunctionSelector, foreignArgs) {
|
|
631
768
|
const targetContractAddress = addressFromSingle(foreignTargetContractAddress);
|
|
632
769
|
const functionSelector = FunctionSelector.fromField(fromSingle(foreignFunctionSelector));
|
|
633
770
|
const args = fromArray(foreignArgs);
|
|
634
|
-
const returnValues = await this.handlerAsTxe().
|
|
771
|
+
const returnValues = await this.handlerAsTxe().executeUtilityFunction(targetContractAddress, functionSelector, args, this.stateHandler.getCurrentJob());
|
|
772
|
+
// TODO(F-335): Avoid doing the following call here.
|
|
773
|
+
await this.stateHandler.cycleJob();
|
|
635
774
|
return toForeignCallResult([
|
|
636
775
|
toArray(returnValues)
|
|
637
776
|
]);
|
|
638
777
|
}
|
|
639
|
-
|
|
778
|
+
// eslint-disable-next-line camelcase
|
|
779
|
+
async aztec_txe_publicCallNewFlow(foreignFrom, foreignAddress, foreignCalldata, foreignIsStaticCall) {
|
|
640
780
|
const from = addressFromSingle(foreignFrom);
|
|
641
781
|
const address = addressFromSingle(foreignAddress);
|
|
642
782
|
const calldata = fromArray(foreignCalldata);
|
|
643
783
|
const isStaticCall = fromSingle(foreignIsStaticCall).toBool();
|
|
644
|
-
const returnValues = await this.handlerAsTxe().
|
|
784
|
+
const returnValues = await this.handlerAsTxe().publicCallNewFlow(from, address, calldata, isStaticCall);
|
|
785
|
+
// TODO(F-335): Avoid doing the following call here.
|
|
786
|
+
await this.stateHandler.cycleJob();
|
|
645
787
|
return toForeignCallResult([
|
|
646
788
|
toArray(returnValues)
|
|
647
789
|
]);
|
|
648
790
|
}
|
|
649
|
-
|
|
650
|
-
|
|
791
|
+
// eslint-disable-next-line camelcase
|
|
792
|
+
async aztec_prv_getSenderForTags() {
|
|
793
|
+
const sender = await this.handlerAsPrivate().getSenderForTags();
|
|
651
794
|
// Return a Noir Option struct with `some` and `value` fields
|
|
652
795
|
if (sender === undefined) {
|
|
653
796
|
// No sender found, return Option with some=0 and value=0
|
|
@@ -663,15 +806,17 @@ export class RPCTranslator {
|
|
|
663
806
|
]);
|
|
664
807
|
}
|
|
665
808
|
}
|
|
666
|
-
|
|
809
|
+
// eslint-disable-next-line camelcase
|
|
810
|
+
async aztec_prv_setSenderForTags(foreignSenderForTags) {
|
|
667
811
|
const senderForTags = AztecAddress.fromField(fromSingle(foreignSenderForTags));
|
|
668
|
-
await this.handlerAsPrivate().
|
|
812
|
+
await this.handlerAsPrivate().setSenderForTags(senderForTags);
|
|
669
813
|
return toForeignCallResult([]);
|
|
670
814
|
}
|
|
671
|
-
|
|
815
|
+
// eslint-disable-next-line camelcase
|
|
816
|
+
async aztec_prv_getNextAppTagAsSender(foreignSender, foreignRecipient) {
|
|
672
817
|
const sender = AztecAddress.fromField(fromSingle(foreignSender));
|
|
673
818
|
const recipient = AztecAddress.fromField(fromSingle(foreignRecipient));
|
|
674
|
-
const nextAppTag = await this.handlerAsPrivate().
|
|
819
|
+
const nextAppTag = await this.handlerAsPrivate().getNextAppTagAsSender(sender, recipient);
|
|
675
820
|
return toForeignCallResult([
|
|
676
821
|
toSingle(nextAppTag.value)
|
|
677
822
|
]);
|