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