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