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