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