@aztec/txe 2.1.0-rc.9 → 3.0.0-devnet.2
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/bin/index.js +1 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +5 -2
- package/dest/oracle/interfaces.d.ts +54 -0
- package/dest/oracle/interfaces.d.ts.map +1 -0
- package/dest/oracle/interfaces.js +3 -0
- package/dest/oracle/txe_oracle_public_context.d.ts +7 -7
- package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.js +29 -31
- package/dest/oracle/txe_oracle_top_level_context.d.ts +56 -0
- package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -0
- package/dest/oracle/txe_oracle_top_level_context.js +423 -0
- package/dest/{txe_service/txe_service.d.ts → rpc_translator.d.ts} +34 -28
- package/dest/rpc_translator.d.ts.map +1 -0
- package/dest/{txe_service/txe_service.js → rpc_translator.js} +143 -115
- package/dest/state_machine/archiver.d.ts +5 -1
- package/dest/state_machine/archiver.d.ts.map +1 -1
- package/dest/state_machine/archiver.js +8 -1
- package/dest/state_machine/dummy_p2p_client.d.ts +1 -0
- package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
- package/dest/state_machine/dummy_p2p_client.js +3 -0
- package/dest/state_machine/global_variable_builder.d.ts +1 -14
- package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
- package/dest/state_machine/global_variable_builder.js +3 -22
- package/dest/state_machine/index.d.ts.map +1 -1
- package/dest/state_machine/index.js +4 -3
- package/dest/txe_session.d.ts +34 -44
- package/dest/txe_session.d.ts.map +1 -1
- package/dest/txe_session.js +197 -82
- package/dest/util/encoding.d.ts +1 -1
- package/dest/util/txe_contract_data_provider.d.ts +2 -1
- package/dest/util/txe_contract_data_provider.d.ts.map +1 -1
- package/dest/util/txe_contract_data_provider.js +1 -1
- package/dest/util/txe_public_contract_data_source.d.ts +4 -3
- package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
- package/dest/util/txe_public_contract_data_source.js +13 -11
- package/dest/utils/block_creation.d.ts +13 -0
- package/dest/utils/block_creation.d.ts.map +1 -0
- package/dest/utils/block_creation.js +24 -0
- package/dest/utils/tx_effect_creation.d.ts +5 -0
- package/dest/utils/tx_effect_creation.d.ts.map +1 -0
- package/dest/utils/tx_effect_creation.js +16 -0
- package/package.json +15 -15
- package/src/bin/index.ts +1 -1
- package/src/index.ts +5 -8
- package/src/oracle/interfaces.ts +83 -0
- package/src/oracle/txe_oracle_public_context.ts +36 -69
- package/src/oracle/txe_oracle_top_level_context.ts +658 -0
- package/src/{txe_service/txe_service.ts → rpc_translator.ts} +181 -115
- package/src/state_machine/archiver.ts +8 -2
- package/src/state_machine/dummy_p2p_client.ts +4 -0
- package/src/state_machine/global_variable_builder.ts +6 -41
- package/src/state_machine/index.ts +6 -4
- package/src/txe_session.ts +301 -90
- package/src/util/txe_contract_data_provider.ts +2 -1
- package/src/util/txe_public_contract_data_source.ts +13 -11
- package/src/utils/block_creation.ts +62 -0
- package/src/utils/tx_effect_creation.ts +37 -0
- package/dest/oracle/txe_oracle.d.ts +0 -124
- package/dest/oracle/txe_oracle.d.ts.map +0 -1
- package/dest/oracle/txe_oracle.js +0 -770
- package/dest/oracle/txe_typed_oracle.d.ts +0 -42
- package/dest/oracle/txe_typed_oracle.d.ts.map +0 -1
- package/dest/oracle/txe_typed_oracle.js +0 -83
- package/dest/txe_constants.d.ts +0 -2
- package/dest/txe_constants.d.ts.map +0 -1
- package/dest/txe_constants.js +0 -7
- package/dest/txe_service/txe_service.d.ts.map +0 -1
- package/src/oracle/txe_oracle.ts +0 -1287
- package/src/oracle/txe_typed_oracle.ts +0 -142
- package/src/txe_constants.ts +0 -9
|
@@ -1,11 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { ContractInstanceWithAddress } from '@aztec/aztec.js/contracts';
|
|
2
|
+
import { Fr, Point } from '@aztec/aztec.js/fields';
|
|
3
|
+
import { MAX_NOTE_HASHES_PER_TX, MAX_NULLIFIERS_PER_TX } from '@aztec/constants';
|
|
4
|
+
import {
|
|
5
|
+
type IMiscOracle,
|
|
6
|
+
type IPrivateExecutionOracle,
|
|
7
|
+
type IUtilityExecutionOracle,
|
|
8
|
+
packAsRetrievedNote,
|
|
9
|
+
} from '@aztec/pxe/simulator';
|
|
3
10
|
import { type ContractArtifact, FunctionSelector, NoteSelector } from '@aztec/stdlib/abi';
|
|
4
11
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
12
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
6
13
|
|
|
7
|
-
import type {
|
|
8
|
-
import type { TXESessionStateHandler } from '
|
|
14
|
+
import type { IAvmExecutionOracle, ITxeExecutionOracle } from './oracle/interfaces.js';
|
|
15
|
+
import type { TXESessionStateHandler } from './txe_session.js';
|
|
9
16
|
import {
|
|
10
17
|
type ForeignCallArray,
|
|
11
18
|
type ForeignCallSingle,
|
|
@@ -20,11 +27,17 @@ import {
|
|
|
20
27
|
toArray,
|
|
21
28
|
toForeignCallResult,
|
|
22
29
|
toSingle,
|
|
23
|
-
} from '
|
|
30
|
+
} from './util/encoding.js';
|
|
24
31
|
|
|
25
|
-
export class
|
|
32
|
+
export class UnavailableOracleError extends Error {
|
|
33
|
+
constructor(oracleName: string) {
|
|
34
|
+
super(`${oracleName} oracles not available with the current handler`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export class RPCTranslator {
|
|
26
39
|
/**
|
|
27
|
-
* Create a new instance of `
|
|
40
|
+
* Create a new instance of `RPCTranslator` that will translate all TXE RPC calls to and from the foreign
|
|
28
41
|
* (`ForeignCallSingle`, `ForeignCallResult`, etc.) and native TS types, delegating actual execution of the oracles
|
|
29
42
|
* to the different handlers.
|
|
30
43
|
* @param stateHandler The handler that will process TXE session state transitions, such as entering a private or
|
|
@@ -34,13 +47,61 @@ export class TXEService {
|
|
|
34
47
|
*/
|
|
35
48
|
constructor(
|
|
36
49
|
private stateHandler: TXESessionStateHandler,
|
|
37
|
-
private oracleHandler:
|
|
50
|
+
private oracleHandler:
|
|
51
|
+
| IMiscOracle
|
|
52
|
+
| IUtilityExecutionOracle
|
|
53
|
+
| IPrivateExecutionOracle
|
|
54
|
+
| IAvmExecutionOracle
|
|
55
|
+
| ITxeExecutionOracle,
|
|
38
56
|
) {}
|
|
39
57
|
|
|
58
|
+
// Note: If you rename the following functions to not start with "handlerAs", you must also update the validation
|
|
59
|
+
// check in `TXESession.processFunction`.
|
|
60
|
+
|
|
61
|
+
private handlerAsMisc(): IMiscOracle {
|
|
62
|
+
if (!('isMisc' in this.oracleHandler)) {
|
|
63
|
+
throw new UnavailableOracleError('Misc');
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return this.oracleHandler;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
private handlerAsUtility(): IUtilityExecutionOracle {
|
|
70
|
+
if (!('isUtility' in this.oracleHandler)) {
|
|
71
|
+
throw new UnavailableOracleError('Utility');
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return this.oracleHandler;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
private handlerAsPrivate(): IPrivateExecutionOracle {
|
|
78
|
+
if (!('isPrivate' in this.oracleHandler)) {
|
|
79
|
+
throw new UnavailableOracleError('Private');
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return this.oracleHandler;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
private handlerAsAvm(): IAvmExecutionOracle {
|
|
86
|
+
if (!('isAvm' in this.oracleHandler)) {
|
|
87
|
+
throw new UnavailableOracleError('Avm');
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return this.oracleHandler;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
private handlerAsTxe(): ITxeExecutionOracle {
|
|
94
|
+
if (!('isTxe' in this.oracleHandler)) {
|
|
95
|
+
throw new UnavailableOracleError('Txe');
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return this.oracleHandler;
|
|
99
|
+
}
|
|
100
|
+
|
|
40
101
|
// TXE session state transition functions - these get handled by the state handler
|
|
41
102
|
|
|
42
103
|
async txeSetTopLevelTXEContext() {
|
|
43
|
-
await this.stateHandler.
|
|
104
|
+
await this.stateHandler.enterTopLevelState();
|
|
44
105
|
|
|
45
106
|
return toForeignCallResult([]);
|
|
46
107
|
}
|
|
@@ -48,18 +109,18 @@ export class TXEService {
|
|
|
48
109
|
async txeSetPrivateTXEContext(
|
|
49
110
|
foreignContractAddressIsSome: ForeignCallSingle,
|
|
50
111
|
foreignContractAddressValue: ForeignCallSingle,
|
|
51
|
-
|
|
52
|
-
|
|
112
|
+
foreignAnchorBlockNumberIsSome: ForeignCallSingle,
|
|
113
|
+
foreignAnchorBlockNumberValue: ForeignCallSingle,
|
|
53
114
|
) {
|
|
54
115
|
const contractAddress = fromSingle(foreignContractAddressIsSome).toBool()
|
|
55
116
|
? AztecAddress.fromField(fromSingle(foreignContractAddressValue))
|
|
56
117
|
: undefined;
|
|
57
118
|
|
|
58
|
-
const
|
|
59
|
-
? fromSingle(
|
|
119
|
+
const anchorBlockNumber = fromSingle(foreignAnchorBlockNumberIsSome).toBool()
|
|
120
|
+
? fromSingle(foreignAnchorBlockNumberValue).toNumber()
|
|
60
121
|
: undefined;
|
|
61
122
|
|
|
62
|
-
const privateContextInputs = await this.stateHandler.
|
|
123
|
+
const privateContextInputs = await this.stateHandler.enterPrivateState(contractAddress, anchorBlockNumber);
|
|
63
124
|
|
|
64
125
|
return toForeignCallResult(privateContextInputs.toFields().map(toSingle));
|
|
65
126
|
}
|
|
@@ -72,7 +133,7 @@ export class TXEService {
|
|
|
72
133
|
? AztecAddress.fromField(fromSingle(foreignContractAddressValue))
|
|
73
134
|
: undefined;
|
|
74
135
|
|
|
75
|
-
await this.stateHandler.
|
|
136
|
+
await this.stateHandler.enterPublicState(contractAddress);
|
|
76
137
|
|
|
77
138
|
return toForeignCallResult([]);
|
|
78
139
|
}
|
|
@@ -85,7 +146,7 @@ export class TXEService {
|
|
|
85
146
|
? AztecAddress.fromField(fromSingle(foreignContractAddressValue))
|
|
86
147
|
: undefined;
|
|
87
148
|
|
|
88
|
-
await this.stateHandler.
|
|
149
|
+
await this.stateHandler.enterUtilityState(contractAddress);
|
|
89
150
|
|
|
90
151
|
return toForeignCallResult([]);
|
|
91
152
|
}
|
|
@@ -94,10 +155,22 @@ export class TXEService {
|
|
|
94
155
|
|
|
95
156
|
// TXE-specific oracles
|
|
96
157
|
|
|
158
|
+
async txeGetNextBlockNumber() {
|
|
159
|
+
const nextBlockNumber = await this.handlerAsTxe().txeGetNextBlockNumber();
|
|
160
|
+
|
|
161
|
+
return toForeignCallResult([toSingle(nextBlockNumber)]);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
async txeGetNextBlockTimestamp() {
|
|
165
|
+
const nextBlockTimestamp = await this.handlerAsTxe().txeGetNextBlockTimestamp();
|
|
166
|
+
|
|
167
|
+
return toForeignCallResult([toSingle(nextBlockTimestamp)]);
|
|
168
|
+
}
|
|
169
|
+
|
|
97
170
|
async txeAdvanceBlocksBy(foreignBlocks: ForeignCallSingle) {
|
|
98
171
|
const blocks = fromSingle(foreignBlocks).toNumber();
|
|
99
172
|
|
|
100
|
-
await this.
|
|
173
|
+
await this.handlerAsTxe().txeAdvanceBlocksBy(blocks);
|
|
101
174
|
|
|
102
175
|
return toForeignCallResult([]);
|
|
103
176
|
}
|
|
@@ -105,7 +178,7 @@ export class TXEService {
|
|
|
105
178
|
txeAdvanceTimestampBy(foreignDuration: ForeignCallSingle) {
|
|
106
179
|
const duration = fromSingle(foreignDuration).toBigInt();
|
|
107
180
|
|
|
108
|
-
this.
|
|
181
|
+
this.handlerAsTxe().txeAdvanceTimestampBy(duration);
|
|
109
182
|
|
|
110
183
|
return toForeignCallResult([]);
|
|
111
184
|
}
|
|
@@ -113,7 +186,7 @@ export class TXEService {
|
|
|
113
186
|
async txeDeploy(artifact: ContractArtifact, instance: ContractInstanceWithAddress, foreignSecret: ForeignCallSingle) {
|
|
114
187
|
const secret = fromSingle(foreignSecret);
|
|
115
188
|
|
|
116
|
-
await this.
|
|
189
|
+
await this.handlerAsTxe().txeDeploy(artifact, instance, secret);
|
|
117
190
|
|
|
118
191
|
return toForeignCallResult([
|
|
119
192
|
toArray([
|
|
@@ -129,7 +202,7 @@ export class TXEService {
|
|
|
129
202
|
async txeCreateAccount(foreignSecret: ForeignCallSingle) {
|
|
130
203
|
const secret = fromSingle(foreignSecret);
|
|
131
204
|
|
|
132
|
-
const completeAddress = await this.
|
|
205
|
+
const completeAddress = await this.handlerAsTxe().txeCreateAccount(secret);
|
|
133
206
|
|
|
134
207
|
return toForeignCallResult([
|
|
135
208
|
toSingle(completeAddress.address),
|
|
@@ -144,7 +217,7 @@ export class TXEService {
|
|
|
144
217
|
) {
|
|
145
218
|
const secret = fromSingle(foreignSecret);
|
|
146
219
|
|
|
147
|
-
const completeAddress = await this.
|
|
220
|
+
const completeAddress = await this.handlerAsTxe().txeAddAccount(artifact, instance, secret);
|
|
148
221
|
|
|
149
222
|
return toForeignCallResult([
|
|
150
223
|
toSingle(completeAddress.address),
|
|
@@ -156,7 +229,7 @@ export class TXEService {
|
|
|
156
229
|
const address = addressFromSingle(foreignAddress);
|
|
157
230
|
const messageHash = fromSingle(foreignMessageHash);
|
|
158
231
|
|
|
159
|
-
await this.
|
|
232
|
+
await this.handlerAsTxe().txeAddAuthWitness(address, messageHash);
|
|
160
233
|
|
|
161
234
|
return toForeignCallResult([]);
|
|
162
235
|
}
|
|
@@ -166,40 +239,31 @@ export class TXEService {
|
|
|
166
239
|
utilityAssertCompatibleOracleVersion(foreignVersion: ForeignCallSingle) {
|
|
167
240
|
const version = fromSingle(foreignVersion).toNumber();
|
|
168
241
|
|
|
169
|
-
this.
|
|
242
|
+
this.handlerAsMisc().utilityAssertCompatibleOracleVersion(version);
|
|
170
243
|
|
|
171
244
|
return toForeignCallResult([]);
|
|
172
245
|
}
|
|
173
246
|
|
|
174
247
|
utilityGetRandomField() {
|
|
175
|
-
const randomField = this.
|
|
248
|
+
const randomField = this.handlerAsMisc().utilityGetRandomField();
|
|
176
249
|
|
|
177
250
|
return toForeignCallResult([toSingle(randomField)]);
|
|
178
251
|
}
|
|
179
252
|
|
|
180
|
-
async
|
|
181
|
-
const
|
|
182
|
-
|
|
183
|
-
return toForeignCallResult([toSingle(contractAddress.toField())]);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
async utilityGetBlockNumber() {
|
|
187
|
-
const blockNumber = await this.oracleHandler.utilityGetBlockNumber();
|
|
188
|
-
|
|
189
|
-
return toForeignCallResult([toSingle(new Fr(blockNumber))]);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
// seems to be used to mean the timestamp of the last mined block in txe (but that's not what is done here)
|
|
193
|
-
async utilityGetTimestamp() {
|
|
194
|
-
const timestamp = await this.oracleHandler.utilityGetTimestamp();
|
|
253
|
+
async txeGetLastBlockTimestamp() {
|
|
254
|
+
const timestamp = await this.handlerAsTxe().txeGetLastBlockTimestamp();
|
|
195
255
|
|
|
196
256
|
return toForeignCallResult([toSingle(new Fr(timestamp))]);
|
|
197
257
|
}
|
|
198
258
|
|
|
199
|
-
async
|
|
200
|
-
const
|
|
259
|
+
async txeGetLastTxEffects() {
|
|
260
|
+
const { txHash, noteHashes, nullifiers } = await this.handlerAsTxe().txeGetLastTxEffects();
|
|
201
261
|
|
|
202
|
-
return toForeignCallResult([
|
|
262
|
+
return toForeignCallResult([
|
|
263
|
+
toSingle(txHash.hash),
|
|
264
|
+
...arrayToBoundedVec(toArray(noteHashes), MAX_NOTE_HASHES_PER_TX),
|
|
265
|
+
...arrayToBoundedVec(toArray(nullifiers), MAX_NULLIFIERS_PER_TX),
|
|
266
|
+
]);
|
|
203
267
|
}
|
|
204
268
|
|
|
205
269
|
// Since the argument is a slice, noir automatically adds a length field to oracle call.
|
|
@@ -211,7 +275,7 @@ export class TXEService {
|
|
|
211
275
|
const values = fromArray(foreignValues);
|
|
212
276
|
const hash = fromSingle(foreignHash);
|
|
213
277
|
|
|
214
|
-
this.
|
|
278
|
+
this.handlerAsPrivate().privateStoreInExecutionCache(values, hash);
|
|
215
279
|
|
|
216
280
|
return toForeignCallResult([]);
|
|
217
281
|
}
|
|
@@ -219,23 +283,26 @@ export class TXEService {
|
|
|
219
283
|
async privateLoadFromExecutionCache(foreignHash: ForeignCallSingle) {
|
|
220
284
|
const hash = fromSingle(foreignHash);
|
|
221
285
|
|
|
222
|
-
const returns = await this.
|
|
286
|
+
const returns = await this.handlerAsPrivate().privateLoadFromExecutionCache(hash);
|
|
223
287
|
|
|
224
288
|
return toForeignCallResult([toArray(returns)]);
|
|
225
289
|
}
|
|
226
290
|
|
|
227
|
-
//
|
|
291
|
+
// When the argument is a slice, noir automatically adds a length field to oracle call.
|
|
292
|
+
// When the argument is an array, we add the field length manually to the signature.
|
|
228
293
|
utilityDebugLog(
|
|
294
|
+
foreignLevel: ForeignCallSingle,
|
|
229
295
|
foreignMessage: ForeignCallArray,
|
|
230
296
|
_foreignLength: ForeignCallSingle,
|
|
231
297
|
foreignFields: ForeignCallArray,
|
|
232
298
|
) {
|
|
299
|
+
const level = fromSingle(foreignLevel).toNumber();
|
|
233
300
|
const message = fromArray(foreignMessage)
|
|
234
301
|
.map(field => String.fromCharCode(field.toNumber()))
|
|
235
302
|
.join('');
|
|
236
303
|
const fields = fromArray(foreignFields);
|
|
237
304
|
|
|
238
|
-
this.
|
|
305
|
+
this.handlerAsMisc().utilityDebugLog(level, message, fields);
|
|
239
306
|
|
|
240
307
|
return toForeignCallResult([]);
|
|
241
308
|
}
|
|
@@ -251,7 +318,7 @@ export class TXEService {
|
|
|
251
318
|
const blockNumber = fromSingle(foreignBlockNumber).toNumber();
|
|
252
319
|
const numberOfElements = fromSingle(foreignNumberOfElements).toNumber();
|
|
253
320
|
|
|
254
|
-
const values = await this.
|
|
321
|
+
const values = await this.handlerAsUtility().utilityStorageRead(
|
|
255
322
|
contractAddress,
|
|
256
323
|
startStorageSlot,
|
|
257
324
|
blockNumber,
|
|
@@ -265,7 +332,7 @@ export class TXEService {
|
|
|
265
332
|
const blockNumber = fromSingle(foreignBlockNumber).toNumber();
|
|
266
333
|
const leafSlot = fromSingle(foreignLeafSlot);
|
|
267
334
|
|
|
268
|
-
const witness = await this.
|
|
335
|
+
const witness = await this.handlerAsUtility().utilityGetPublicDataWitness(blockNumber, leafSlot);
|
|
269
336
|
|
|
270
337
|
if (!witness) {
|
|
271
338
|
throw new Error(`Public data witness not found for slot ${leafSlot} at block ${blockNumber}.`);
|
|
@@ -308,7 +375,7 @@ export class TXEService {
|
|
|
308
375
|
const maxNotes = fromSingle(foreignMaxNotes).toNumber();
|
|
309
376
|
const packedRetrievedNoteLength = fromSingle(foreignPackedRetrievedNoteLength).toNumber();
|
|
310
377
|
|
|
311
|
-
const noteDatas = await this.
|
|
378
|
+
const noteDatas = await this.handlerAsUtility().utilityGetNotes(
|
|
312
379
|
storageSlot,
|
|
313
380
|
numSelects,
|
|
314
381
|
selectByIndexes,
|
|
@@ -355,7 +422,7 @@ export class TXEService {
|
|
|
355
422
|
const noteHash = fromSingle(foreignNoteHash);
|
|
356
423
|
const counter = fromSingle(foreignCounter).toNumber();
|
|
357
424
|
|
|
358
|
-
this.
|
|
425
|
+
this.handlerAsPrivate().privateNotifyCreatedNote(storageSlot, noteTypeId, note, noteHash, counter);
|
|
359
426
|
|
|
360
427
|
return toForeignCallResult([]);
|
|
361
428
|
}
|
|
@@ -369,7 +436,7 @@ export class TXEService {
|
|
|
369
436
|
const noteHash = fromSingle(foreignNoteHash);
|
|
370
437
|
const counter = fromSingle(foreignCounter).toNumber();
|
|
371
438
|
|
|
372
|
-
await this.
|
|
439
|
+
await this.handlerAsPrivate().privateNotifyNullifiedNote(innerNullifier, noteHash, counter);
|
|
373
440
|
|
|
374
441
|
return toForeignCallResult([]);
|
|
375
442
|
}
|
|
@@ -377,7 +444,7 @@ export class TXEService {
|
|
|
377
444
|
async privateNotifyCreatedNullifier(foreignInnerNullifier: ForeignCallSingle) {
|
|
378
445
|
const innerNullifier = fromSingle(foreignInnerNullifier);
|
|
379
446
|
|
|
380
|
-
await this.
|
|
447
|
+
await this.handlerAsPrivate().privateNotifyCreatedNullifier(innerNullifier);
|
|
381
448
|
|
|
382
449
|
return toForeignCallResult([]);
|
|
383
450
|
}
|
|
@@ -385,7 +452,7 @@ export class TXEService {
|
|
|
385
452
|
async utilityCheckNullifierExists(foreignInnerNullifier: ForeignCallSingle) {
|
|
386
453
|
const innerNullifier = fromSingle(foreignInnerNullifier);
|
|
387
454
|
|
|
388
|
-
const exists = await this.
|
|
455
|
+
const exists = await this.handlerAsUtility().utilityCheckNullifierExists(innerNullifier);
|
|
389
456
|
|
|
390
457
|
return toForeignCallResult([toSingle(new Fr(exists))]);
|
|
391
458
|
}
|
|
@@ -393,7 +460,7 @@ export class TXEService {
|
|
|
393
460
|
async utilityGetContractInstance(foreignAddress: ForeignCallSingle) {
|
|
394
461
|
const address = addressFromSingle(foreignAddress);
|
|
395
462
|
|
|
396
|
-
const instance = await this.
|
|
463
|
+
const instance = await this.handlerAsUtility().utilityGetContractInstance(address);
|
|
397
464
|
|
|
398
465
|
return toForeignCallResult(
|
|
399
466
|
[
|
|
@@ -409,7 +476,7 @@ export class TXEService {
|
|
|
409
476
|
async utilityGetPublicKeysAndPartialAddress(foreignAddress: ForeignCallSingle) {
|
|
410
477
|
const address = addressFromSingle(foreignAddress);
|
|
411
478
|
|
|
412
|
-
const { publicKeys, partialAddress } = await this.
|
|
479
|
+
const { publicKeys, partialAddress } = await this.handlerAsUtility().utilityGetPublicKeysAndPartialAddress(address);
|
|
413
480
|
|
|
414
481
|
return toForeignCallResult([toArray([...publicKeys.toFields(), partialAddress])]);
|
|
415
482
|
}
|
|
@@ -417,7 +484,7 @@ export class TXEService {
|
|
|
417
484
|
async utilityGetKeyValidationRequest(foreignPkMHash: ForeignCallSingle) {
|
|
418
485
|
const pkMHash = fromSingle(foreignPkMHash);
|
|
419
486
|
|
|
420
|
-
const keyValidationRequest = await this.
|
|
487
|
+
const keyValidationRequest = await this.handlerAsUtility().utilityGetKeyValidationRequest(pkMHash);
|
|
421
488
|
|
|
422
489
|
return toForeignCallResult(keyValidationRequest.toFields().map(toSingle));
|
|
423
490
|
}
|
|
@@ -441,7 +508,7 @@ export class TXEService {
|
|
|
441
508
|
const blockNumber = fromSingle(foreignBlockNumber).toNumber();
|
|
442
509
|
const nullifier = fromSingle(foreignNullifier);
|
|
443
510
|
|
|
444
|
-
const witness = await this.
|
|
511
|
+
const witness = await this.handlerAsUtility().utilityGetNullifierMembershipWitness(blockNumber, nullifier);
|
|
445
512
|
|
|
446
513
|
if (!witness) {
|
|
447
514
|
throw new Error(`Nullifier membership witness not found at block ${blockNumber}.`);
|
|
@@ -452,7 +519,7 @@ export class TXEService {
|
|
|
452
519
|
async utilityGetAuthWitness(foreignMessageHash: ForeignCallSingle) {
|
|
453
520
|
const messageHash = fromSingle(foreignMessageHash);
|
|
454
521
|
|
|
455
|
-
const authWitness = await this.
|
|
522
|
+
const authWitness = await this.handlerAsUtility().utilityGetAuthWitness(messageHash);
|
|
456
523
|
|
|
457
524
|
if (!authWitness) {
|
|
458
525
|
throw new Error(`Auth witness not found for message hash ${messageHash}.`);
|
|
@@ -482,22 +549,16 @@ export class TXEService {
|
|
|
482
549
|
throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
|
|
483
550
|
}
|
|
484
551
|
|
|
485
|
-
async
|
|
486
|
-
const
|
|
552
|
+
async utilityGetUtilityContext() {
|
|
553
|
+
const context = await this.handlerAsUtility().utilityGetUtilityContext();
|
|
487
554
|
|
|
488
|
-
return toForeignCallResult(
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
async utilityGetVersion() {
|
|
492
|
-
const version = await this.oracleHandler.utilityGetVersion();
|
|
493
|
-
|
|
494
|
-
return toForeignCallResult([toSingle(version)]);
|
|
555
|
+
return toForeignCallResult(context.toNoirRepresentation());
|
|
495
556
|
}
|
|
496
557
|
|
|
497
558
|
async utilityGetBlockHeader(foreignBlockNumber: ForeignCallSingle) {
|
|
498
559
|
const blockNumber = fromSingle(foreignBlockNumber).toNumber();
|
|
499
560
|
|
|
500
|
-
const header = await this.
|
|
561
|
+
const header = await this.handlerAsUtility().utilityGetBlockHeader(blockNumber);
|
|
501
562
|
|
|
502
563
|
if (!header) {
|
|
503
564
|
throw new Error(`Block header not found for block ${blockNumber}.`);
|
|
@@ -514,7 +575,7 @@ export class TXEService {
|
|
|
514
575
|
const treeId = fromSingle(foreignTreeId).toNumber();
|
|
515
576
|
const leafValue = fromSingle(foreignLeafValue);
|
|
516
577
|
|
|
517
|
-
const witness = await this.
|
|
578
|
+
const witness = await this.handlerAsUtility().utilityGetMembershipWitness(blockNumber, treeId, leafValue);
|
|
518
579
|
|
|
519
580
|
if (!witness) {
|
|
520
581
|
throw new Error(
|
|
@@ -531,7 +592,7 @@ export class TXEService {
|
|
|
531
592
|
const blockNumber = fromSingle(foreignBlockNumber).toNumber();
|
|
532
593
|
const nullifier = fromSingle(foreignNullifier);
|
|
533
594
|
|
|
534
|
-
const witness = await this.
|
|
595
|
+
const witness = await this.handlerAsUtility().utilityGetLowNullifierMembershipWitness(blockNumber, nullifier);
|
|
535
596
|
|
|
536
597
|
if (!witness) {
|
|
537
598
|
throw new Error(`Low nullifier witness not found for nullifier ${nullifier} at block ${blockNumber}.`);
|
|
@@ -539,19 +600,10 @@ export class TXEService {
|
|
|
539
600
|
return toForeignCallResult(witness.toNoirRepresentation());
|
|
540
601
|
}
|
|
541
602
|
|
|
542
|
-
async utilityGetIndexedTaggingSecretAsSender(foreignSender: ForeignCallSingle, foreignRecipient: ForeignCallSingle) {
|
|
543
|
-
const sender = AztecAddress.fromField(fromSingle(foreignSender));
|
|
544
|
-
const recipient = AztecAddress.fromField(fromSingle(foreignRecipient));
|
|
545
|
-
|
|
546
|
-
const secret = await this.oracleHandler.utilityGetIndexedTaggingSecretAsSender(sender, recipient);
|
|
547
|
-
|
|
548
|
-
return toForeignCallResult(secret.toFields().map(toSingle));
|
|
549
|
-
}
|
|
550
|
-
|
|
551
603
|
async utilityFetchTaggedLogs(foreignPendingTaggedLogArrayBaseSlot: ForeignCallSingle) {
|
|
552
604
|
const pendingTaggedLogArrayBaseSlot = fromSingle(foreignPendingTaggedLogArrayBaseSlot);
|
|
553
605
|
|
|
554
|
-
await this.
|
|
606
|
+
await this.handlerAsUtility().utilityFetchTaggedLogs(pendingTaggedLogArrayBaseSlot);
|
|
555
607
|
|
|
556
608
|
return toForeignCallResult([]);
|
|
557
609
|
}
|
|
@@ -565,7 +617,7 @@ export class TXEService {
|
|
|
565
617
|
const noteValidationRequestsArrayBaseSlot = fromSingle(foreignNoteValidationRequestsArrayBaseSlot);
|
|
566
618
|
const eventValidationRequestsArrayBaseSlot = fromSingle(foreignEventValidationRequestsArrayBaseSlot);
|
|
567
619
|
|
|
568
|
-
await this.
|
|
620
|
+
await this.handlerAsUtility().utilityValidateEnqueuedNotesAndEvents(
|
|
569
621
|
contractAddress,
|
|
570
622
|
noteValidationRequestsArrayBaseSlot,
|
|
571
623
|
eventValidationRequestsArrayBaseSlot,
|
|
@@ -583,7 +635,7 @@ export class TXEService {
|
|
|
583
635
|
const logRetrievalRequestsArrayBaseSlot = fromSingle(foreignLogRetrievalRequestsArrayBaseSlot);
|
|
584
636
|
const logRetrievalResponsesArrayBaseSlot = fromSingle(foreignLogRetrievalResponsesArrayBaseSlot);
|
|
585
637
|
|
|
586
|
-
await this.
|
|
638
|
+
await this.handlerAsUtility().utilityBulkRetrieveLogs(
|
|
587
639
|
contractAddress,
|
|
588
640
|
logRetrievalRequestsArrayBaseSlot,
|
|
589
641
|
logRetrievalResponsesArrayBaseSlot,
|
|
@@ -601,7 +653,7 @@ export class TXEService {
|
|
|
601
653
|
const slot = fromSingle(foreignSlot);
|
|
602
654
|
const capsule = fromArray(foreignCapsule);
|
|
603
655
|
|
|
604
|
-
await this.
|
|
656
|
+
await this.handlerAsUtility().utilityStoreCapsule(contractAddress, slot, capsule);
|
|
605
657
|
|
|
606
658
|
return toForeignCallResult([]);
|
|
607
659
|
}
|
|
@@ -615,7 +667,7 @@ export class TXEService {
|
|
|
615
667
|
const slot = fromSingle(foreignSlot);
|
|
616
668
|
const tSize = fromSingle(foreignTSize).toNumber();
|
|
617
669
|
|
|
618
|
-
const values = await this.
|
|
670
|
+
const values = await this.handlerAsUtility().utilityLoadCapsule(contractAddress, slot);
|
|
619
671
|
|
|
620
672
|
// We are going to return a Noir Option struct to represent the possibility of null values. Options are a struct
|
|
621
673
|
// with two fields: `some` (a boolean) and `value` (a field array in this case).
|
|
@@ -632,7 +684,7 @@ export class TXEService {
|
|
|
632
684
|
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
633
685
|
const slot = fromSingle(foreignSlot);
|
|
634
686
|
|
|
635
|
-
await this.
|
|
687
|
+
await this.handlerAsUtility().utilityDeleteCapsule(contractAddress, slot);
|
|
636
688
|
|
|
637
689
|
return toForeignCallResult([]);
|
|
638
690
|
}
|
|
@@ -648,7 +700,7 @@ export class TXEService {
|
|
|
648
700
|
const dstSlot = fromSingle(foreignDstSlot);
|
|
649
701
|
const numEntries = fromSingle(foreignNumEntries).toNumber();
|
|
650
702
|
|
|
651
|
-
await this.
|
|
703
|
+
await this.handlerAsUtility().utilityCopyCapsule(contractAddress, srcSlot, dstSlot, numEntries);
|
|
652
704
|
|
|
653
705
|
return toForeignCallResult([]);
|
|
654
706
|
}
|
|
@@ -667,7 +719,7 @@ export class TXEService {
|
|
|
667
719
|
const iv = fromUintArray(foreignIv, 8);
|
|
668
720
|
const symKey = fromUintArray(foreignSymKey, 8);
|
|
669
721
|
|
|
670
|
-
const plaintextBuffer = await this.
|
|
722
|
+
const plaintextBuffer = await this.handlerAsUtility().utilityAes128Decrypt(ciphertext, iv, symKey);
|
|
671
723
|
|
|
672
724
|
return toForeignCallResult(
|
|
673
725
|
arrayToBoundedVec(bufferToU8Array(plaintextBuffer), foreignCiphertextBVecStorage.length),
|
|
@@ -687,7 +739,7 @@ export class TXEService {
|
|
|
687
739
|
fromSingle(foreignEphPKField2),
|
|
688
740
|
]);
|
|
689
741
|
|
|
690
|
-
const secret = await this.
|
|
742
|
+
const secret = await this.handlerAsUtility().utilityGetSharedSecret(address, ephPK);
|
|
691
743
|
|
|
692
744
|
return toForeignCallResult(secret.toFields().map(toSingle));
|
|
693
745
|
}
|
|
@@ -706,7 +758,7 @@ export class TXEService {
|
|
|
706
758
|
async avmOpcodeStorageRead(foreignSlot: ForeignCallSingle) {
|
|
707
759
|
const slot = fromSingle(foreignSlot);
|
|
708
760
|
|
|
709
|
-
const value = (await this.
|
|
761
|
+
const value = (await this.handlerAsAvm().avmOpcodeStorageRead(slot)).value;
|
|
710
762
|
|
|
711
763
|
return toForeignCallResult([toSingle(new Fr(value))]);
|
|
712
764
|
}
|
|
@@ -715,7 +767,7 @@ export class TXEService {
|
|
|
715
767
|
const slot = fromSingle(foreignSlot);
|
|
716
768
|
const value = fromSingle(foreignValue);
|
|
717
769
|
|
|
718
|
-
await this.
|
|
770
|
+
await this.handlerAsAvm().avmOpcodeStorageWrite(slot, value);
|
|
719
771
|
|
|
720
772
|
return toForeignCallResult([]);
|
|
721
773
|
}
|
|
@@ -723,7 +775,7 @@ export class TXEService {
|
|
|
723
775
|
async avmOpcodeGetContractInstanceDeployer(foreignAddress: ForeignCallSingle) {
|
|
724
776
|
const address = addressFromSingle(foreignAddress);
|
|
725
777
|
|
|
726
|
-
const instance = await this.
|
|
778
|
+
const instance = await this.handlerAsUtility().utilityGetContractInstance(address);
|
|
727
779
|
|
|
728
780
|
return toForeignCallResult([
|
|
729
781
|
toSingle(instance.deployer),
|
|
@@ -735,7 +787,7 @@ export class TXEService {
|
|
|
735
787
|
async avmOpcodeGetContractInstanceClassId(foreignAddress: ForeignCallSingle) {
|
|
736
788
|
const address = addressFromSingle(foreignAddress);
|
|
737
789
|
|
|
738
|
-
const instance = await this.
|
|
790
|
+
const instance = await this.handlerAsUtility().utilityGetContractInstance(address);
|
|
739
791
|
|
|
740
792
|
return toForeignCallResult([
|
|
741
793
|
toSingle(instance.currentContractClassId),
|
|
@@ -747,7 +799,7 @@ export class TXEService {
|
|
|
747
799
|
async avmOpcodeGetContractInstanceInitializationHash(foreignAddress: ForeignCallSingle) {
|
|
748
800
|
const address = addressFromSingle(foreignAddress);
|
|
749
801
|
|
|
750
|
-
const instance = await this.
|
|
802
|
+
const instance = await this.handlerAsUtility().utilityGetContractInstance(address);
|
|
751
803
|
|
|
752
804
|
return toForeignCallResult([
|
|
753
805
|
toSingle(instance.initializationHash),
|
|
@@ -756,8 +808,8 @@ export class TXEService {
|
|
|
756
808
|
]);
|
|
757
809
|
}
|
|
758
810
|
|
|
759
|
-
avmOpcodeSender() {
|
|
760
|
-
const sender = this.
|
|
811
|
+
async avmOpcodeSender() {
|
|
812
|
+
const sender = await this.handlerAsAvm().avmOpcodeSender();
|
|
761
813
|
|
|
762
814
|
return toForeignCallResult([toSingle(sender)]);
|
|
763
815
|
}
|
|
@@ -765,7 +817,7 @@ export class TXEService {
|
|
|
765
817
|
async avmOpcodeEmitNullifier(foreignNullifier: ForeignCallSingle) {
|
|
766
818
|
const nullifier = fromSingle(foreignNullifier);
|
|
767
819
|
|
|
768
|
-
await this.
|
|
820
|
+
await this.handlerAsAvm().avmOpcodeEmitNullifier(nullifier);
|
|
769
821
|
|
|
770
822
|
return toForeignCallResult([]);
|
|
771
823
|
}
|
|
@@ -773,7 +825,7 @@ export class TXEService {
|
|
|
773
825
|
async avmOpcodeEmitNoteHash(foreignNoteHash: ForeignCallSingle) {
|
|
774
826
|
const noteHash = fromSingle(foreignNoteHash);
|
|
775
827
|
|
|
776
|
-
await this.
|
|
828
|
+
await this.handlerAsAvm().avmOpcodeEmitNoteHash(noteHash);
|
|
777
829
|
|
|
778
830
|
return toForeignCallResult([]);
|
|
779
831
|
}
|
|
@@ -782,43 +834,43 @@ export class TXEService {
|
|
|
782
834
|
const innerNullifier = fromSingle(foreignInnerNullifier);
|
|
783
835
|
const targetAddress = AztecAddress.fromField(fromSingle(foreignTargetAddress));
|
|
784
836
|
|
|
785
|
-
const exists = await this.
|
|
837
|
+
const exists = await this.handlerAsAvm().avmOpcodeNullifierExists(innerNullifier, targetAddress);
|
|
786
838
|
|
|
787
839
|
return toForeignCallResult([toSingle(new Fr(exists))]);
|
|
788
840
|
}
|
|
789
841
|
|
|
790
842
|
async avmOpcodeAddress() {
|
|
791
|
-
const contractAddress = await this.
|
|
843
|
+
const contractAddress = await this.handlerAsAvm().avmOpcodeAddress();
|
|
792
844
|
|
|
793
845
|
return toForeignCallResult([toSingle(contractAddress.toField())]);
|
|
794
846
|
}
|
|
795
847
|
|
|
796
848
|
async avmOpcodeBlockNumber() {
|
|
797
|
-
const blockNumber = await this.
|
|
849
|
+
const blockNumber = await this.handlerAsAvm().avmOpcodeBlockNumber();
|
|
798
850
|
|
|
799
851
|
return toForeignCallResult([toSingle(new Fr(blockNumber))]);
|
|
800
852
|
}
|
|
801
853
|
|
|
802
854
|
async avmOpcodeTimestamp() {
|
|
803
|
-
const timestamp = await this.
|
|
855
|
+
const timestamp = await this.handlerAsAvm().avmOpcodeTimestamp();
|
|
804
856
|
|
|
805
857
|
return toForeignCallResult([toSingle(new Fr(timestamp))]);
|
|
806
858
|
}
|
|
807
859
|
|
|
808
860
|
async avmOpcodeIsStaticCall() {
|
|
809
|
-
const isStaticCall = await this.
|
|
861
|
+
const isStaticCall = await this.handlerAsAvm().avmOpcodeIsStaticCall();
|
|
810
862
|
|
|
811
863
|
return toForeignCallResult([toSingle(new Fr(isStaticCall ? 1 : 0))]);
|
|
812
864
|
}
|
|
813
865
|
|
|
814
866
|
async avmOpcodeChainId() {
|
|
815
|
-
const chainId = await this.
|
|
867
|
+
const chainId = await this.handlerAsAvm().avmOpcodeChainId();
|
|
816
868
|
|
|
817
869
|
return toForeignCallResult([toSingle(chainId)]);
|
|
818
870
|
}
|
|
819
871
|
|
|
820
872
|
async avmOpcodeVersion() {
|
|
821
|
-
const version = await this.
|
|
873
|
+
const version = await this.handlerAsAvm().avmOpcodeVersion();
|
|
822
874
|
|
|
823
875
|
return toForeignCallResult([toSingle(version)]);
|
|
824
876
|
}
|
|
@@ -881,7 +933,7 @@ export class TXEService {
|
|
|
881
933
|
const argsHash = fromSingle(foreignArgsHash);
|
|
882
934
|
const isStaticCall = fromSingle(foreignIsStaticCall).toBool();
|
|
883
935
|
|
|
884
|
-
const
|
|
936
|
+
const returnValues = await this.handlerAsTxe().txePrivateCallNewFlow(
|
|
885
937
|
from,
|
|
886
938
|
targetContractAddress,
|
|
887
939
|
functionSelector,
|
|
@@ -890,21 +942,26 @@ export class TXEService {
|
|
|
890
942
|
isStaticCall,
|
|
891
943
|
);
|
|
892
944
|
|
|
893
|
-
return toForeignCallResult([toArray(
|
|
945
|
+
return toForeignCallResult([toArray(returnValues)]);
|
|
894
946
|
}
|
|
895
947
|
|
|
896
|
-
async
|
|
948
|
+
async txeSimulateUtilityFunction(
|
|
897
949
|
foreignTargetContractAddress: ForeignCallSingle,
|
|
898
950
|
foreignFunctionSelector: ForeignCallSingle,
|
|
899
|
-
|
|
951
|
+
_foreignArgsLength: ForeignCallSingle,
|
|
952
|
+
foreignArgs: ForeignCallArray,
|
|
900
953
|
) {
|
|
901
954
|
const targetContractAddress = addressFromSingle(foreignTargetContractAddress);
|
|
902
955
|
const functionSelector = FunctionSelector.fromField(fromSingle(foreignFunctionSelector));
|
|
903
|
-
const
|
|
956
|
+
const args = fromArray(foreignArgs);
|
|
904
957
|
|
|
905
|
-
const
|
|
958
|
+
const returnValues = await this.handlerAsTxe().txeSimulateUtilityFunction(
|
|
959
|
+
targetContractAddress,
|
|
960
|
+
functionSelector,
|
|
961
|
+
args,
|
|
962
|
+
);
|
|
906
963
|
|
|
907
|
-
return toForeignCallResult([
|
|
964
|
+
return toForeignCallResult([toArray(returnValues)]);
|
|
908
965
|
}
|
|
909
966
|
|
|
910
967
|
async txePublicCallNewFlow(
|
|
@@ -919,13 +976,13 @@ export class TXEService {
|
|
|
919
976
|
const calldata = fromArray(foreignCalldata);
|
|
920
977
|
const isStaticCall = fromSingle(foreignIsStaticCall).toBool();
|
|
921
978
|
|
|
922
|
-
const
|
|
979
|
+
const returnValues = await this.handlerAsTxe().txePublicCallNewFlow(from, address, calldata, isStaticCall);
|
|
923
980
|
|
|
924
|
-
return toForeignCallResult([toArray(
|
|
981
|
+
return toForeignCallResult([toArray(returnValues)]);
|
|
925
982
|
}
|
|
926
983
|
|
|
927
984
|
async privateGetSenderForTags() {
|
|
928
|
-
const sender = await this.
|
|
985
|
+
const sender = await this.handlerAsPrivate().privateGetSenderForTags();
|
|
929
986
|
|
|
930
987
|
// Return a Noir Option struct with `some` and `value` fields
|
|
931
988
|
if (sender === undefined) {
|
|
@@ -940,8 +997,17 @@ export class TXEService {
|
|
|
940
997
|
async privateSetSenderForTags(foreignSenderForTags: ForeignCallSingle) {
|
|
941
998
|
const senderForTags = AztecAddress.fromField(fromSingle(foreignSenderForTags));
|
|
942
999
|
|
|
943
|
-
await this.
|
|
1000
|
+
await this.handlerAsPrivate().privateSetSenderForTags(senderForTags);
|
|
944
1001
|
|
|
945
1002
|
return toForeignCallResult([]);
|
|
946
1003
|
}
|
|
1004
|
+
|
|
1005
|
+
async privateGetNextAppTagAsSender(foreignSender: ForeignCallSingle, foreignRecipient: ForeignCallSingle) {
|
|
1006
|
+
const sender = AztecAddress.fromField(fromSingle(foreignSender));
|
|
1007
|
+
const recipient = AztecAddress.fromField(fromSingle(foreignRecipient));
|
|
1008
|
+
|
|
1009
|
+
const nextAppTag = await this.handlerAsPrivate().privateGetNextAppTagAsSender(sender, recipient);
|
|
1010
|
+
|
|
1011
|
+
return toForeignCallResult([toSingle(nextAppTag.value)]);
|
|
1012
|
+
}
|
|
947
1013
|
}
|