@aztec/txe 0.0.1-fake-ceab37513c → 0.0.6-commit.a2d1860fe9
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.d.ts +1 -1
- package/dest/bin/index.js +1 -1
- 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 +90 -54
- package/dest/oracle/interfaces.d.ts +57 -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 +14 -14
- package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.js +36 -40
- package/dest/oracle/txe_oracle_top_level_context.d.ts +65 -0
- package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -0
- package/dest/oracle/txe_oracle_top_level_context.js +530 -0
- package/dest/rpc_translator.d.ts +252 -0
- package/dest/rpc_translator.d.ts.map +1 -0
- package/dest/{txe_service/txe_service.js → rpc_translator.js} +258 -156
- package/dest/state_machine/archiver.d.ts +21 -51
- package/dest/state_machine/archiver.d.ts.map +1 -1
- package/dest/state_machine/archiver.js +63 -94
- package/dest/state_machine/dummy_p2p_client.d.ts +20 -13
- package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
- package/dest/state_machine/dummy_p2p_client.js +41 -21
- package/dest/state_machine/global_variable_builder.d.ts +6 -17
- package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
- package/dest/state_machine/global_variable_builder.js +16 -23
- package/dest/state_machine/index.d.ts +7 -7
- package/dest/state_machine/index.d.ts.map +1 -1
- package/dest/state_machine/index.js +42 -24
- package/dest/state_machine/mock_epoch_cache.d.ts +14 -10
- package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
- package/dest/state_machine/mock_epoch_cache.js +21 -13
- package/dest/state_machine/synchronizer.d.ts +3 -2
- package/dest/state_machine/synchronizer.d.ts.map +1 -1
- package/dest/state_machine/synchronizer.js +5 -4
- package/dest/txe_session.d.ts +44 -48
- package/dest/txe_session.d.ts.map +1 -1
- package/dest/txe_session.js +314 -98
- package/dest/util/encoding.d.ts +616 -17
- package/dest/util/encoding.d.ts.map +1 -1
- package/dest/util/encoding.js +1 -1
- package/dest/util/expected_failure_error.d.ts +1 -1
- package/dest/util/expected_failure_error.d.ts.map +1 -1
- package/dest/util/txe_account_store.d.ts +10 -0
- package/dest/util/txe_account_store.d.ts.map +1 -0
- package/dest/util/{txe_account_data_provider.js → txe_account_store.js} +1 -1
- package/dest/util/txe_public_contract_data_source.d.ts +9 -8
- package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
- package/dest/util/txe_public_contract_data_source.js +15 -30
- package/dest/utils/block_creation.d.ts +28 -0
- package/dest/utils/block_creation.d.ts.map +1 -0
- package/dest/utils/block_creation.js +58 -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 +13 -0
- package/package.json +18 -17
- package/src/bin/index.ts +1 -1
- package/src/constants.ts +3 -0
- package/src/index.ts +102 -68
- package/src/oracle/interfaces.ts +86 -0
- package/src/oracle/txe_oracle_public_context.ts +40 -80
- package/src/oracle/txe_oracle_top_level_context.ts +756 -0
- package/src/{txe_service/txe_service.ts → rpc_translator.ts} +323 -161
- package/src/state_machine/archiver.ts +63 -117
- package/src/state_machine/dummy_p2p_client.ts +58 -28
- package/src/state_machine/global_variable_builder.ts +25 -42
- package/src/state_machine/index.ts +65 -24
- package/src/state_machine/mock_epoch_cache.ts +25 -20
- package/src/state_machine/synchronizer.ts +6 -5
- package/src/txe_session.ts +441 -121
- package/src/util/encoding.ts +1 -1
- package/src/util/{txe_account_data_provider.ts → txe_account_store.ts} +1 -1
- package/src/util/txe_public_contract_data_source.ts +23 -46
- package/src/utils/block_creation.ts +97 -0
- package/src/utils/tx_effect_creation.ts +30 -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 +0 -231
- package/dest/txe_service/txe_service.d.ts.map +0 -1
- 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 -11
- package/dest/util/txe_contract_data_provider.d.ts.map +0 -1
- package/dest/util/txe_contract_data_provider.js +0 -22
- package/src/oracle/txe_oracle.ts +0 -1287
- package/src/oracle/txe_typed_oracle.ts +0 -142
- package/src/txe_constants.ts +0 -9
- package/src/util/txe_contract_data_provider.ts +0 -35
|
@@ -1,11 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
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 { BlockNumber } from '@aztec/foundation/branded-types';
|
|
5
|
+
import {
|
|
6
|
+
type IMiscOracle,
|
|
7
|
+
type IPrivateExecutionOracle,
|
|
8
|
+
type IUtilityExecutionOracle,
|
|
9
|
+
packAsHintedNote,
|
|
10
|
+
} from '@aztec/pxe/simulator';
|
|
11
|
+
import { type ContractArtifact, EventSelector, FunctionSelector, NoteSelector } from '@aztec/stdlib/abi';
|
|
4
12
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
|
-
import {
|
|
13
|
+
import { BlockHash } from '@aztec/stdlib/block';
|
|
6
14
|
|
|
7
|
-
import type {
|
|
8
|
-
import type { TXESessionStateHandler } from '
|
|
15
|
+
import type { IAvmExecutionOracle, ITxeExecutionOracle } from './oracle/interfaces.js';
|
|
16
|
+
import type { TXESessionStateHandler } from './txe_session.js';
|
|
9
17
|
import {
|
|
10
18
|
type ForeignCallArray,
|
|
11
19
|
type ForeignCallSingle,
|
|
@@ -20,11 +28,20 @@ import {
|
|
|
20
28
|
toArray,
|
|
21
29
|
toForeignCallResult,
|
|
22
30
|
toSingle,
|
|
23
|
-
} from '
|
|
31
|
+
} from './util/encoding.js';
|
|
32
|
+
|
|
33
|
+
const MAX_EVENT_LEN = 12; // This is MAX_MESSAGE_CONTENT_LEN - PRIVATE_EVENT_RESERVED_FIELDS
|
|
34
|
+
const MAX_PRIVATE_EVENTS_PER_TXE_QUERY = 5;
|
|
24
35
|
|
|
25
|
-
export class
|
|
36
|
+
export class UnavailableOracleError extends Error {
|
|
37
|
+
constructor(oracleName: string) {
|
|
38
|
+
super(`${oracleName} oracles not available with the current handler`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export class RPCTranslator {
|
|
26
43
|
/**
|
|
27
|
-
* Create a new instance of `
|
|
44
|
+
* Create a new instance of `RPCTranslator` that will translate all TXE RPC calls to and from the foreign
|
|
28
45
|
* (`ForeignCallSingle`, `ForeignCallResult`, etc.) and native TS types, delegating actual execution of the oracles
|
|
29
46
|
* to the different handlers.
|
|
30
47
|
* @param stateHandler The handler that will process TXE session state transitions, such as entering a private or
|
|
@@ -34,13 +51,61 @@ export class TXEService {
|
|
|
34
51
|
*/
|
|
35
52
|
constructor(
|
|
36
53
|
private stateHandler: TXESessionStateHandler,
|
|
37
|
-
private oracleHandler:
|
|
54
|
+
private oracleHandler:
|
|
55
|
+
| IMiscOracle
|
|
56
|
+
| IUtilityExecutionOracle
|
|
57
|
+
| IPrivateExecutionOracle
|
|
58
|
+
| IAvmExecutionOracle
|
|
59
|
+
| ITxeExecutionOracle,
|
|
38
60
|
) {}
|
|
39
61
|
|
|
62
|
+
// Note: If you rename the following functions to not start with "handlerAs", you must also update the validation
|
|
63
|
+
// check in `TXESession.processFunction`.
|
|
64
|
+
|
|
65
|
+
private handlerAsMisc(): IMiscOracle {
|
|
66
|
+
if (!('isMisc' in this.oracleHandler)) {
|
|
67
|
+
throw new UnavailableOracleError('Misc');
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return this.oracleHandler;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
private handlerAsUtility(): IUtilityExecutionOracle {
|
|
74
|
+
if (!('isUtility' in this.oracleHandler)) {
|
|
75
|
+
throw new UnavailableOracleError('Utility');
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return this.oracleHandler;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
private handlerAsPrivate(): IPrivateExecutionOracle {
|
|
82
|
+
if (!('isPrivate' in this.oracleHandler)) {
|
|
83
|
+
throw new UnavailableOracleError('Private');
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return this.oracleHandler;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
private handlerAsAvm(): IAvmExecutionOracle {
|
|
90
|
+
if (!('isAvm' in this.oracleHandler)) {
|
|
91
|
+
throw new UnavailableOracleError('Avm');
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return this.oracleHandler;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
private handlerAsTxe(): ITxeExecutionOracle {
|
|
98
|
+
if (!('isTxe' in this.oracleHandler)) {
|
|
99
|
+
throw new UnavailableOracleError('Txe');
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return this.oracleHandler;
|
|
103
|
+
}
|
|
104
|
+
|
|
40
105
|
// TXE session state transition functions - these get handled by the state handler
|
|
41
106
|
|
|
42
107
|
async txeSetTopLevelTXEContext() {
|
|
43
|
-
await this.stateHandler.
|
|
108
|
+
await this.stateHandler.enterTopLevelState();
|
|
44
109
|
|
|
45
110
|
return toForeignCallResult([]);
|
|
46
111
|
}
|
|
@@ -48,18 +113,18 @@ export class TXEService {
|
|
|
48
113
|
async txeSetPrivateTXEContext(
|
|
49
114
|
foreignContractAddressIsSome: ForeignCallSingle,
|
|
50
115
|
foreignContractAddressValue: ForeignCallSingle,
|
|
51
|
-
|
|
52
|
-
|
|
116
|
+
foreignAnchorBlockNumberIsSome: ForeignCallSingle,
|
|
117
|
+
foreignAnchorBlockNumberValue: ForeignCallSingle,
|
|
53
118
|
) {
|
|
54
119
|
const contractAddress = fromSingle(foreignContractAddressIsSome).toBool()
|
|
55
120
|
? AztecAddress.fromField(fromSingle(foreignContractAddressValue))
|
|
56
121
|
: undefined;
|
|
57
122
|
|
|
58
|
-
const
|
|
59
|
-
? fromSingle(
|
|
123
|
+
const anchorBlockNumber = fromSingle(foreignAnchorBlockNumberIsSome).toBool()
|
|
124
|
+
? BlockNumber(fromSingle(foreignAnchorBlockNumberValue).toNumber())
|
|
60
125
|
: undefined;
|
|
61
126
|
|
|
62
|
-
const privateContextInputs = await this.stateHandler.
|
|
127
|
+
const privateContextInputs = await this.stateHandler.enterPrivateState(contractAddress, anchorBlockNumber);
|
|
63
128
|
|
|
64
129
|
return toForeignCallResult(privateContextInputs.toFields().map(toSingle));
|
|
65
130
|
}
|
|
@@ -72,7 +137,7 @@ export class TXEService {
|
|
|
72
137
|
? AztecAddress.fromField(fromSingle(foreignContractAddressValue))
|
|
73
138
|
: undefined;
|
|
74
139
|
|
|
75
|
-
await this.stateHandler.
|
|
140
|
+
await this.stateHandler.enterPublicState(contractAddress);
|
|
76
141
|
|
|
77
142
|
return toForeignCallResult([]);
|
|
78
143
|
}
|
|
@@ -85,7 +150,7 @@ export class TXEService {
|
|
|
85
150
|
? AztecAddress.fromField(fromSingle(foreignContractAddressValue))
|
|
86
151
|
: undefined;
|
|
87
152
|
|
|
88
|
-
await this.stateHandler.
|
|
153
|
+
await this.stateHandler.enterUtilityState(contractAddress);
|
|
89
154
|
|
|
90
155
|
return toForeignCallResult([]);
|
|
91
156
|
}
|
|
@@ -94,10 +159,28 @@ export class TXEService {
|
|
|
94
159
|
|
|
95
160
|
// TXE-specific oracles
|
|
96
161
|
|
|
162
|
+
txeGetDefaultAddress() {
|
|
163
|
+
const defaultAddress = this.handlerAsTxe().txeGetDefaultAddress();
|
|
164
|
+
|
|
165
|
+
return toForeignCallResult([toSingle(defaultAddress)]);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
async txeGetNextBlockNumber() {
|
|
169
|
+
const nextBlockNumber = await this.handlerAsTxe().txeGetNextBlockNumber();
|
|
170
|
+
|
|
171
|
+
return toForeignCallResult([toSingle(nextBlockNumber)]);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
async txeGetNextBlockTimestamp() {
|
|
175
|
+
const nextBlockTimestamp = await this.handlerAsTxe().txeGetNextBlockTimestamp();
|
|
176
|
+
|
|
177
|
+
return toForeignCallResult([toSingle(nextBlockTimestamp)]);
|
|
178
|
+
}
|
|
179
|
+
|
|
97
180
|
async txeAdvanceBlocksBy(foreignBlocks: ForeignCallSingle) {
|
|
98
181
|
const blocks = fromSingle(foreignBlocks).toNumber();
|
|
99
182
|
|
|
100
|
-
await this.
|
|
183
|
+
await this.handlerAsTxe().txeAdvanceBlocksBy(blocks);
|
|
101
184
|
|
|
102
185
|
return toForeignCallResult([]);
|
|
103
186
|
}
|
|
@@ -105,7 +188,7 @@ export class TXEService {
|
|
|
105
188
|
txeAdvanceTimestampBy(foreignDuration: ForeignCallSingle) {
|
|
106
189
|
const duration = fromSingle(foreignDuration).toBigInt();
|
|
107
190
|
|
|
108
|
-
this.
|
|
191
|
+
this.handlerAsTxe().txeAdvanceTimestampBy(duration);
|
|
109
192
|
|
|
110
193
|
return toForeignCallResult([]);
|
|
111
194
|
}
|
|
@@ -113,7 +196,7 @@ export class TXEService {
|
|
|
113
196
|
async txeDeploy(artifact: ContractArtifact, instance: ContractInstanceWithAddress, foreignSecret: ForeignCallSingle) {
|
|
114
197
|
const secret = fromSingle(foreignSecret);
|
|
115
198
|
|
|
116
|
-
await this.
|
|
199
|
+
await this.handlerAsTxe().txeDeploy(artifact, instance, secret);
|
|
117
200
|
|
|
118
201
|
return toForeignCallResult([
|
|
119
202
|
toArray([
|
|
@@ -129,7 +212,7 @@ export class TXEService {
|
|
|
129
212
|
async txeCreateAccount(foreignSecret: ForeignCallSingle) {
|
|
130
213
|
const secret = fromSingle(foreignSecret);
|
|
131
214
|
|
|
132
|
-
const completeAddress = await this.
|
|
215
|
+
const completeAddress = await this.handlerAsTxe().txeCreateAccount(secret);
|
|
133
216
|
|
|
134
217
|
return toForeignCallResult([
|
|
135
218
|
toSingle(completeAddress.address),
|
|
@@ -144,7 +227,7 @@ export class TXEService {
|
|
|
144
227
|
) {
|
|
145
228
|
const secret = fromSingle(foreignSecret);
|
|
146
229
|
|
|
147
|
-
const completeAddress = await this.
|
|
230
|
+
const completeAddress = await this.handlerAsTxe().txeAddAccount(artifact, instance, secret);
|
|
148
231
|
|
|
149
232
|
return toForeignCallResult([
|
|
150
233
|
toSingle(completeAddress.address),
|
|
@@ -156,7 +239,7 @@ export class TXEService {
|
|
|
156
239
|
const address = addressFromSingle(foreignAddress);
|
|
157
240
|
const messageHash = fromSingle(foreignMessageHash);
|
|
158
241
|
|
|
159
|
-
await this.
|
|
242
|
+
await this.handlerAsTxe().txeAddAuthWitness(address, messageHash);
|
|
160
243
|
|
|
161
244
|
return toForeignCallResult([]);
|
|
162
245
|
}
|
|
@@ -166,52 +249,71 @@ export class TXEService {
|
|
|
166
249
|
utilityAssertCompatibleOracleVersion(foreignVersion: ForeignCallSingle) {
|
|
167
250
|
const version = fromSingle(foreignVersion).toNumber();
|
|
168
251
|
|
|
169
|
-
this.
|
|
252
|
+
this.handlerAsMisc().utilityAssertCompatibleOracleVersion(version);
|
|
170
253
|
|
|
171
254
|
return toForeignCallResult([]);
|
|
172
255
|
}
|
|
173
256
|
|
|
174
257
|
utilityGetRandomField() {
|
|
175
|
-
const randomField = this.
|
|
258
|
+
const randomField = this.handlerAsMisc().utilityGetRandomField();
|
|
176
259
|
|
|
177
260
|
return toForeignCallResult([toSingle(randomField)]);
|
|
178
261
|
}
|
|
179
262
|
|
|
180
|
-
async
|
|
181
|
-
const
|
|
263
|
+
async txeGetLastBlockTimestamp() {
|
|
264
|
+
const timestamp = await this.handlerAsTxe().txeGetLastBlockTimestamp();
|
|
182
265
|
|
|
183
|
-
return toForeignCallResult([toSingle(
|
|
266
|
+
return toForeignCallResult([toSingle(new Fr(timestamp))]);
|
|
184
267
|
}
|
|
185
268
|
|
|
186
|
-
async
|
|
187
|
-
const
|
|
269
|
+
async txeGetLastTxEffects() {
|
|
270
|
+
const { txHash, noteHashes, nullifiers } = await this.handlerAsTxe().txeGetLastTxEffects();
|
|
188
271
|
|
|
189
|
-
return toForeignCallResult([
|
|
272
|
+
return toForeignCallResult([
|
|
273
|
+
toSingle(txHash.hash),
|
|
274
|
+
...arrayToBoundedVec(toArray(noteHashes), MAX_NOTE_HASHES_PER_TX),
|
|
275
|
+
...arrayToBoundedVec(toArray(nullifiers), MAX_NULLIFIERS_PER_TX),
|
|
276
|
+
]);
|
|
190
277
|
}
|
|
191
278
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
279
|
+
async txeGetPrivateEvents(
|
|
280
|
+
foreignSelector: ForeignCallSingle,
|
|
281
|
+
foreignContractAddress: ForeignCallSingle,
|
|
282
|
+
foreignScope: ForeignCallSingle,
|
|
283
|
+
) {
|
|
284
|
+
const selector = EventSelector.fromField(fromSingle(foreignSelector));
|
|
285
|
+
const contractAddress = addressFromSingle(foreignContractAddress);
|
|
286
|
+
const scope = addressFromSingle(foreignScope);
|
|
195
287
|
|
|
196
|
-
|
|
197
|
-
}
|
|
288
|
+
const events = await this.handlerAsTxe().txeGetPrivateEvents(selector, contractAddress, scope);
|
|
198
289
|
|
|
199
|
-
|
|
200
|
-
|
|
290
|
+
if (events.length > MAX_PRIVATE_EVENTS_PER_TXE_QUERY) {
|
|
291
|
+
throw new Error(`Array of length ${events.length} larger than maxLen ${MAX_PRIVATE_EVENTS_PER_TXE_QUERY}`);
|
|
292
|
+
}
|
|
201
293
|
|
|
202
|
-
|
|
294
|
+
if (events.some(e => e.length > MAX_EVENT_LEN)) {
|
|
295
|
+
throw new Error(`Some private event has length larger than maxLen ${MAX_EVENT_LEN}`);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// This is a workaround as Noir does not currently let us return nested structs with arrays. We instead return a raw
|
|
299
|
+
// multidimensional array in get_private_events_oracle and create the BoundedVecs here.
|
|
300
|
+
const rawArrayStorage = events
|
|
301
|
+
.map(e => e.concat(Array(MAX_EVENT_LEN - e.length).fill(new Fr(0))))
|
|
302
|
+
.concat(Array(MAX_PRIVATE_EVENTS_PER_TXE_QUERY - events.length).fill(Array(MAX_EVENT_LEN).fill(new Fr(0))))
|
|
303
|
+
.flat();
|
|
304
|
+
const eventLengths = events
|
|
305
|
+
.map(e => new Fr(e.length))
|
|
306
|
+
.concat(Array(MAX_PRIVATE_EVENTS_PER_TXE_QUERY - events.length).fill(new Fr(0)));
|
|
307
|
+
const queryLength = new Fr(events.length);
|
|
308
|
+
|
|
309
|
+
return toForeignCallResult([toArray(rawArrayStorage), toArray(eventLengths), toSingle(queryLength)]);
|
|
203
310
|
}
|
|
204
311
|
|
|
205
|
-
|
|
206
|
-
privateStoreInExecutionCache(
|
|
207
|
-
_foreignLength: ForeignCallSingle,
|
|
208
|
-
foreignValues: ForeignCallArray,
|
|
209
|
-
foreignHash: ForeignCallSingle,
|
|
210
|
-
) {
|
|
312
|
+
privateStoreInExecutionCache(foreignValues: ForeignCallArray, foreignHash: ForeignCallSingle) {
|
|
211
313
|
const values = fromArray(foreignValues);
|
|
212
314
|
const hash = fromSingle(foreignHash);
|
|
213
315
|
|
|
214
|
-
this.
|
|
316
|
+
this.handlerAsPrivate().privateStoreInExecutionCache(values, hash);
|
|
215
317
|
|
|
216
318
|
return toForeignCallResult([]);
|
|
217
319
|
}
|
|
@@ -219,61 +321,66 @@ export class TXEService {
|
|
|
219
321
|
async privateLoadFromExecutionCache(foreignHash: ForeignCallSingle) {
|
|
220
322
|
const hash = fromSingle(foreignHash);
|
|
221
323
|
|
|
222
|
-
const returns = await this.
|
|
324
|
+
const returns = await this.handlerAsPrivate().privateLoadFromExecutionCache(hash);
|
|
223
325
|
|
|
224
326
|
return toForeignCallResult([toArray(returns)]);
|
|
225
327
|
}
|
|
226
328
|
|
|
227
|
-
//
|
|
228
|
-
|
|
329
|
+
// When the argument is a slice, noir automatically adds a length field to oracle call.
|
|
330
|
+
// When the argument is an array, we add the field length manually to the signature.
|
|
331
|
+
async utilityLog(
|
|
332
|
+
foreignLevel: ForeignCallSingle,
|
|
229
333
|
foreignMessage: ForeignCallArray,
|
|
230
334
|
_foreignLength: ForeignCallSingle,
|
|
231
335
|
foreignFields: ForeignCallArray,
|
|
232
336
|
) {
|
|
337
|
+
const level = fromSingle(foreignLevel).toNumber();
|
|
233
338
|
const message = fromArray(foreignMessage)
|
|
234
339
|
.map(field => String.fromCharCode(field.toNumber()))
|
|
235
340
|
.join('');
|
|
236
341
|
const fields = fromArray(foreignFields);
|
|
237
342
|
|
|
238
|
-
this.
|
|
343
|
+
await this.handlerAsMisc().utilityLog(level, message, fields);
|
|
239
344
|
|
|
240
345
|
return toForeignCallResult([]);
|
|
241
346
|
}
|
|
242
347
|
|
|
243
348
|
async utilityStorageRead(
|
|
349
|
+
foreignBlockHash: ForeignCallSingle,
|
|
244
350
|
foreignContractAddress: ForeignCallSingle,
|
|
245
351
|
foreignStartStorageSlot: ForeignCallSingle,
|
|
246
|
-
foreignBlockNumber: ForeignCallSingle,
|
|
247
352
|
foreignNumberOfElements: ForeignCallSingle,
|
|
248
353
|
) {
|
|
354
|
+
const blockHash = new BlockHash(fromSingle(foreignBlockHash));
|
|
249
355
|
const contractAddress = addressFromSingle(foreignContractAddress);
|
|
250
356
|
const startStorageSlot = fromSingle(foreignStartStorageSlot);
|
|
251
|
-
const blockNumber = fromSingle(foreignBlockNumber).toNumber();
|
|
252
357
|
const numberOfElements = fromSingle(foreignNumberOfElements).toNumber();
|
|
253
358
|
|
|
254
|
-
const values = await this.
|
|
359
|
+
const values = await this.handlerAsUtility().utilityStorageRead(
|
|
360
|
+
blockHash,
|
|
255
361
|
contractAddress,
|
|
256
362
|
startStorageSlot,
|
|
257
|
-
blockNumber,
|
|
258
363
|
numberOfElements,
|
|
259
364
|
);
|
|
260
365
|
|
|
261
366
|
return toForeignCallResult([toArray(values)]);
|
|
262
367
|
}
|
|
263
368
|
|
|
264
|
-
async utilityGetPublicDataWitness(
|
|
265
|
-
const
|
|
369
|
+
async utilityGetPublicDataWitness(foreignBlockHash: ForeignCallSingle, foreignLeafSlot: ForeignCallSingle) {
|
|
370
|
+
const blockHash = new BlockHash(fromSingle(foreignBlockHash));
|
|
266
371
|
const leafSlot = fromSingle(foreignLeafSlot);
|
|
267
372
|
|
|
268
|
-
const witness = await this.
|
|
373
|
+
const witness = await this.handlerAsUtility().utilityGetPublicDataWitness(blockHash, leafSlot);
|
|
269
374
|
|
|
270
375
|
if (!witness) {
|
|
271
|
-
throw new Error(`Public data witness not found for slot ${leafSlot} at block ${
|
|
376
|
+
throw new Error(`Public data witness not found for slot ${leafSlot} at block ${blockHash.toString()}.`);
|
|
272
377
|
}
|
|
273
378
|
return toForeignCallResult(witness.toNoirRepresentation());
|
|
274
379
|
}
|
|
275
380
|
|
|
276
381
|
async utilityGetNotes(
|
|
382
|
+
foreignOwnerIsSome: ForeignCallSingle,
|
|
383
|
+
foreignOwnerValue: ForeignCallSingle,
|
|
277
384
|
foreignStorageSlot: ForeignCallSingle,
|
|
278
385
|
foreignNumSelects: ForeignCallSingle,
|
|
279
386
|
foreignSelectByIndexes: ForeignCallArray,
|
|
@@ -289,8 +396,12 @@ export class TXEService {
|
|
|
289
396
|
foreignOffset: ForeignCallSingle,
|
|
290
397
|
foreignStatus: ForeignCallSingle,
|
|
291
398
|
foreignMaxNotes: ForeignCallSingle,
|
|
292
|
-
|
|
399
|
+
foreignPackedHintedNoteLength: ForeignCallSingle,
|
|
293
400
|
) {
|
|
401
|
+
// Parse Option<AztecAddress>: ownerIsSome is 0 for None, 1 for Some
|
|
402
|
+
const owner = fromSingle(foreignOwnerIsSome).toBool()
|
|
403
|
+
? AztecAddress.fromField(fromSingle(foreignOwnerValue))
|
|
404
|
+
: undefined;
|
|
294
405
|
const storageSlot = fromSingle(foreignStorageSlot);
|
|
295
406
|
const numSelects = fromSingle(foreignNumSelects).toNumber();
|
|
296
407
|
const selectByIndexes = fromArray(foreignSelectByIndexes).map(fr => fr.toNumber());
|
|
@@ -306,9 +417,10 @@ export class TXEService {
|
|
|
306
417
|
const offset = fromSingle(foreignOffset).toNumber();
|
|
307
418
|
const status = fromSingle(foreignStatus).toNumber();
|
|
308
419
|
const maxNotes = fromSingle(foreignMaxNotes).toNumber();
|
|
309
|
-
const
|
|
420
|
+
const packedHintedNoteLength = fromSingle(foreignPackedHintedNoteLength).toNumber();
|
|
310
421
|
|
|
311
|
-
const noteDatas = await this.
|
|
422
|
+
const noteDatas = await this.handlerAsUtility().utilityGetNotes(
|
|
423
|
+
owner,
|
|
312
424
|
storageSlot,
|
|
313
425
|
numSelects,
|
|
314
426
|
selectByIndexes,
|
|
@@ -325,7 +437,17 @@ export class TXEService {
|
|
|
325
437
|
status,
|
|
326
438
|
);
|
|
327
439
|
|
|
328
|
-
const returnDataAsArrayOfArrays = noteDatas.map(
|
|
440
|
+
const returnDataAsArrayOfArrays = noteDatas.map(noteData =>
|
|
441
|
+
packAsHintedNote({
|
|
442
|
+
contractAddress: noteData.contractAddress,
|
|
443
|
+
owner: noteData.owner,
|
|
444
|
+
randomness: noteData.randomness,
|
|
445
|
+
storageSlot: noteData.storageSlot,
|
|
446
|
+
noteNonce: noteData.noteNonce,
|
|
447
|
+
isPending: noteData.isPending,
|
|
448
|
+
note: noteData.note,
|
|
449
|
+
}),
|
|
450
|
+
);
|
|
329
451
|
|
|
330
452
|
// Now we convert each sub-array to an array of ForeignCallSingles
|
|
331
453
|
const returnDataAsArrayOfForeignCallSingleArrays = returnDataAsArrayOfArrays.map(subArray =>
|
|
@@ -334,28 +456,36 @@ export class TXEService {
|
|
|
334
456
|
|
|
335
457
|
// At last we convert the array of arrays to a bounded vec of arrays
|
|
336
458
|
return toForeignCallResult(
|
|
337
|
-
arrayOfArraysToBoundedVecOfArrays(
|
|
338
|
-
returnDataAsArrayOfForeignCallSingleArrays,
|
|
339
|
-
maxNotes,
|
|
340
|
-
packedRetrievedNoteLength,
|
|
341
|
-
),
|
|
459
|
+
arrayOfArraysToBoundedVecOfArrays(returnDataAsArrayOfForeignCallSingleArrays, maxNotes, packedHintedNoteLength),
|
|
342
460
|
);
|
|
343
461
|
}
|
|
344
462
|
|
|
345
463
|
privateNotifyCreatedNote(
|
|
464
|
+
foreignOwner: ForeignCallSingle,
|
|
346
465
|
foreignStorageSlot: ForeignCallSingle,
|
|
466
|
+
foreignRandomness: ForeignCallSingle,
|
|
347
467
|
foreignNoteTypeId: ForeignCallSingle,
|
|
348
468
|
foreignNote: ForeignCallArray,
|
|
349
469
|
foreignNoteHash: ForeignCallSingle,
|
|
350
470
|
foreignCounter: ForeignCallSingle,
|
|
351
471
|
) {
|
|
472
|
+
const owner = addressFromSingle(foreignOwner);
|
|
352
473
|
const storageSlot = fromSingle(foreignStorageSlot);
|
|
474
|
+
const randomness = fromSingle(foreignRandomness);
|
|
353
475
|
const noteTypeId = NoteSelector.fromField(fromSingle(foreignNoteTypeId));
|
|
354
476
|
const note = fromArray(foreignNote);
|
|
355
477
|
const noteHash = fromSingle(foreignNoteHash);
|
|
356
478
|
const counter = fromSingle(foreignCounter).toNumber();
|
|
357
479
|
|
|
358
|
-
this.
|
|
480
|
+
this.handlerAsPrivate().privateNotifyCreatedNote(
|
|
481
|
+
owner,
|
|
482
|
+
storageSlot,
|
|
483
|
+
randomness,
|
|
484
|
+
noteTypeId,
|
|
485
|
+
note,
|
|
486
|
+
noteHash,
|
|
487
|
+
counter,
|
|
488
|
+
);
|
|
359
489
|
|
|
360
490
|
return toForeignCallResult([]);
|
|
361
491
|
}
|
|
@@ -369,7 +499,7 @@ export class TXEService {
|
|
|
369
499
|
const noteHash = fromSingle(foreignNoteHash);
|
|
370
500
|
const counter = fromSingle(foreignCounter).toNumber();
|
|
371
501
|
|
|
372
|
-
await this.
|
|
502
|
+
await this.handlerAsPrivate().privateNotifyNullifiedNote(innerNullifier, noteHash, counter);
|
|
373
503
|
|
|
374
504
|
return toForeignCallResult([]);
|
|
375
505
|
}
|
|
@@ -377,15 +507,24 @@ export class TXEService {
|
|
|
377
507
|
async privateNotifyCreatedNullifier(foreignInnerNullifier: ForeignCallSingle) {
|
|
378
508
|
const innerNullifier = fromSingle(foreignInnerNullifier);
|
|
379
509
|
|
|
380
|
-
await this.
|
|
510
|
+
await this.handlerAsPrivate().privateNotifyCreatedNullifier(innerNullifier);
|
|
381
511
|
|
|
382
512
|
return toForeignCallResult([]);
|
|
383
513
|
}
|
|
384
514
|
|
|
515
|
+
async privateIsNullifierPending(foreignInnerNullifier: ForeignCallSingle, foreignContractAddress: ForeignCallSingle) {
|
|
516
|
+
const innerNullifier = fromSingle(foreignInnerNullifier);
|
|
517
|
+
const contractAddress = addressFromSingle(foreignContractAddress);
|
|
518
|
+
|
|
519
|
+
const isPending = await this.handlerAsPrivate().privateIsNullifierPending(innerNullifier, contractAddress);
|
|
520
|
+
|
|
521
|
+
return toForeignCallResult([toSingle(new Fr(isPending))]);
|
|
522
|
+
}
|
|
523
|
+
|
|
385
524
|
async utilityCheckNullifierExists(foreignInnerNullifier: ForeignCallSingle) {
|
|
386
525
|
const innerNullifier = fromSingle(foreignInnerNullifier);
|
|
387
526
|
|
|
388
|
-
const exists = await this.
|
|
527
|
+
const exists = await this.handlerAsUtility().utilityCheckNullifierExists(innerNullifier);
|
|
389
528
|
|
|
390
529
|
return toForeignCallResult([toSingle(new Fr(exists))]);
|
|
391
530
|
}
|
|
@@ -393,7 +532,7 @@ export class TXEService {
|
|
|
393
532
|
async utilityGetContractInstance(foreignAddress: ForeignCallSingle) {
|
|
394
533
|
const address = addressFromSingle(foreignAddress);
|
|
395
534
|
|
|
396
|
-
const instance = await this.
|
|
535
|
+
const instance = await this.handlerAsUtility().utilityGetContractInstance(address);
|
|
397
536
|
|
|
398
537
|
return toForeignCallResult(
|
|
399
538
|
[
|
|
@@ -406,18 +545,29 @@ export class TXEService {
|
|
|
406
545
|
);
|
|
407
546
|
}
|
|
408
547
|
|
|
409
|
-
async
|
|
548
|
+
async utilityTryGetPublicKeysAndPartialAddress(foreignAddress: ForeignCallSingle) {
|
|
410
549
|
const address = addressFromSingle(foreignAddress);
|
|
411
550
|
|
|
412
|
-
const
|
|
551
|
+
const result = await this.handlerAsUtility().utilityTryGetPublicKeysAndPartialAddress(address);
|
|
413
552
|
|
|
414
|
-
return
|
|
553
|
+
// We are going to return a Noir Option struct to represent the possibility of null values. Options are a struct
|
|
554
|
+
// with two fields: `some` (a boolean) and `value` (a field array in this case).
|
|
555
|
+
if (result === undefined) {
|
|
556
|
+
// No data was found so we set `some` to 0 and pad `value` with zeros get the correct return size.
|
|
557
|
+
return toForeignCallResult([toSingle(new Fr(0)), toArray(Array(13).fill(new Fr(0)))]);
|
|
558
|
+
} else {
|
|
559
|
+
// Data was found so we set `some` to 1 and return it along with `value`.
|
|
560
|
+
return toForeignCallResult([
|
|
561
|
+
toSingle(new Fr(1)),
|
|
562
|
+
toArray([...result.publicKeys.toFields(), result.partialAddress]),
|
|
563
|
+
]);
|
|
564
|
+
}
|
|
415
565
|
}
|
|
416
566
|
|
|
417
567
|
async utilityGetKeyValidationRequest(foreignPkMHash: ForeignCallSingle) {
|
|
418
568
|
const pkMHash = fromSingle(foreignPkMHash);
|
|
419
569
|
|
|
420
|
-
const keyValidationRequest = await this.
|
|
570
|
+
const keyValidationRequest = await this.handlerAsUtility().utilityGetKeyValidationRequest(pkMHash);
|
|
421
571
|
|
|
422
572
|
return toForeignCallResult(keyValidationRequest.toFields().map(toSingle));
|
|
423
573
|
}
|
|
@@ -434,17 +584,14 @@ export class TXEService {
|
|
|
434
584
|
);
|
|
435
585
|
}
|
|
436
586
|
|
|
437
|
-
async utilityGetNullifierMembershipWitness(
|
|
438
|
-
|
|
439
|
-
foreignNullifier: ForeignCallSingle,
|
|
440
|
-
) {
|
|
441
|
-
const blockNumber = fromSingle(foreignBlockNumber).toNumber();
|
|
587
|
+
async utilityGetNullifierMembershipWitness(foreignBlockHash: ForeignCallSingle, foreignNullifier: ForeignCallSingle) {
|
|
588
|
+
const blockHash = new BlockHash(fromSingle(foreignBlockHash));
|
|
442
589
|
const nullifier = fromSingle(foreignNullifier);
|
|
443
590
|
|
|
444
|
-
const witness = await this.
|
|
591
|
+
const witness = await this.handlerAsUtility().utilityGetNullifierMembershipWitness(blockHash, nullifier);
|
|
445
592
|
|
|
446
593
|
if (!witness) {
|
|
447
|
-
throw new Error(`Nullifier membership witness not found at block ${
|
|
594
|
+
throw new Error(`Nullifier membership witness not found at block ${blockHash}.`);
|
|
448
595
|
}
|
|
449
596
|
return toForeignCallResult(witness.toNoirRepresentation());
|
|
450
597
|
}
|
|
@@ -452,7 +599,7 @@ export class TXEService {
|
|
|
452
599
|
async utilityGetAuthWitness(foreignMessageHash: ForeignCallSingle) {
|
|
453
600
|
const messageHash = fromSingle(foreignMessageHash);
|
|
454
601
|
|
|
455
|
-
const authWitness = await this.
|
|
602
|
+
const authWitness = await this.handlerAsUtility().utilityGetAuthWitness(messageHash);
|
|
456
603
|
|
|
457
604
|
if (!authWitness) {
|
|
458
605
|
throw new Error(`Auth witness not found for message hash ${messageHash}.`);
|
|
@@ -482,22 +629,22 @@ export class TXEService {
|
|
|
482
629
|
throw new Error('Enqueueing public calls is not supported in TestEnvironment::private_context');
|
|
483
630
|
}
|
|
484
631
|
|
|
485
|
-
async
|
|
486
|
-
const
|
|
487
|
-
|
|
488
|
-
return toForeignCallResult([toSingle(
|
|
632
|
+
public async privateIsSideEffectCounterRevertible(foreignSideEffectCounter: ForeignCallSingle) {
|
|
633
|
+
const sideEffectCounter = fromSingle(foreignSideEffectCounter).toNumber();
|
|
634
|
+
const isRevertible = await this.handlerAsPrivate().privateIsSideEffectCounterRevertible(sideEffectCounter);
|
|
635
|
+
return toForeignCallResult([toSingle(new Fr(isRevertible))]);
|
|
489
636
|
}
|
|
490
637
|
|
|
491
|
-
|
|
492
|
-
const
|
|
638
|
+
utilityGetUtilityContext() {
|
|
639
|
+
const context = this.handlerAsUtility().utilityGetUtilityContext();
|
|
493
640
|
|
|
494
|
-
return toForeignCallResult(
|
|
641
|
+
return toForeignCallResult(context.toNoirRepresentation());
|
|
495
642
|
}
|
|
496
643
|
|
|
497
644
|
async utilityGetBlockHeader(foreignBlockNumber: ForeignCallSingle) {
|
|
498
|
-
const blockNumber = fromSingle(foreignBlockNumber).toNumber();
|
|
645
|
+
const blockNumber = BlockNumber(fromSingle(foreignBlockNumber).toNumber());
|
|
499
646
|
|
|
500
|
-
const header = await this.
|
|
647
|
+
const header = await this.handlerAsUtility().utilityGetBlockHeader(blockNumber);
|
|
501
648
|
|
|
502
649
|
if (!header) {
|
|
503
650
|
throw new Error(`Block header not found for block ${blockNumber}.`);
|
|
@@ -505,58 +652,62 @@ export class TXEService {
|
|
|
505
652
|
return toForeignCallResult(header.toFields().map(toSingle));
|
|
506
653
|
}
|
|
507
654
|
|
|
508
|
-
async
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
foreignLeafValue: ForeignCallSingle,
|
|
655
|
+
async utilityGetNoteHashMembershipWitness(
|
|
656
|
+
foreignAnchorBlockHash: ForeignCallSingle,
|
|
657
|
+
foreignNoteHash: ForeignCallSingle,
|
|
512
658
|
) {
|
|
513
|
-
const
|
|
514
|
-
const
|
|
515
|
-
const leafValue = fromSingle(foreignLeafValue);
|
|
659
|
+
const blockHash = new BlockHash(fromSingle(foreignAnchorBlockHash));
|
|
660
|
+
const noteHash = fromSingle(foreignNoteHash);
|
|
516
661
|
|
|
517
|
-
const witness = await this.
|
|
662
|
+
const witness = await this.handlerAsUtility().utilityGetNoteHashMembershipWitness(blockHash, noteHash);
|
|
663
|
+
|
|
664
|
+
if (!witness) {
|
|
665
|
+
throw new Error(`Note hash ${noteHash} not found in the note hash tree at block ${blockHash.toString()}.`);
|
|
666
|
+
}
|
|
667
|
+
return toForeignCallResult(witness.toNoirRepresentation());
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
async utilityGetBlockHashMembershipWitness(
|
|
671
|
+
foreignAnchorBlockHash: ForeignCallSingle,
|
|
672
|
+
foreignBlockHash: ForeignCallSingle,
|
|
673
|
+
) {
|
|
674
|
+
const anchorBlockHash = new BlockHash(fromSingle(foreignAnchorBlockHash));
|
|
675
|
+
const blockHash = new BlockHash(fromSingle(foreignBlockHash));
|
|
676
|
+
|
|
677
|
+
const witness = await this.handlerAsUtility().utilityGetBlockHashMembershipWitness(anchorBlockHash, blockHash);
|
|
518
678
|
|
|
519
679
|
if (!witness) {
|
|
520
680
|
throw new Error(
|
|
521
|
-
`
|
|
681
|
+
`Block hash ${blockHash.toString()} not found in the archive tree at anchor block ${anchorBlockHash.toString()}.`,
|
|
522
682
|
);
|
|
523
683
|
}
|
|
524
|
-
return toForeignCallResult(
|
|
684
|
+
return toForeignCallResult(witness.toNoirRepresentation());
|
|
525
685
|
}
|
|
526
686
|
|
|
527
687
|
async utilityGetLowNullifierMembershipWitness(
|
|
528
|
-
|
|
688
|
+
foreignBlockHash: ForeignCallSingle,
|
|
529
689
|
foreignNullifier: ForeignCallSingle,
|
|
530
690
|
) {
|
|
531
|
-
const
|
|
691
|
+
const blockHash = new BlockHash(fromSingle(foreignBlockHash));
|
|
532
692
|
const nullifier = fromSingle(foreignNullifier);
|
|
533
693
|
|
|
534
|
-
const witness = await this.
|
|
694
|
+
const witness = await this.handlerAsUtility().utilityGetLowNullifierMembershipWitness(blockHash, nullifier);
|
|
535
695
|
|
|
536
696
|
if (!witness) {
|
|
537
|
-
throw new Error(`Low nullifier witness not found for nullifier ${nullifier} at block ${
|
|
697
|
+
throw new Error(`Low nullifier witness not found for nullifier ${nullifier} at block ${blockHash}.`);
|
|
538
698
|
}
|
|
539
699
|
return toForeignCallResult(witness.toNoirRepresentation());
|
|
540
700
|
}
|
|
541
701
|
|
|
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
702
|
async utilityFetchTaggedLogs(foreignPendingTaggedLogArrayBaseSlot: ForeignCallSingle) {
|
|
552
703
|
const pendingTaggedLogArrayBaseSlot = fromSingle(foreignPendingTaggedLogArrayBaseSlot);
|
|
553
704
|
|
|
554
|
-
await this.
|
|
705
|
+
await this.handlerAsUtility().utilityFetchTaggedLogs(pendingTaggedLogArrayBaseSlot);
|
|
555
706
|
|
|
556
707
|
return toForeignCallResult([]);
|
|
557
708
|
}
|
|
558
709
|
|
|
559
|
-
public async
|
|
710
|
+
public async utilityValidateAndStoreEnqueuedNotesAndEvents(
|
|
560
711
|
foreignContractAddress: ForeignCallSingle,
|
|
561
712
|
foreignNoteValidationRequestsArrayBaseSlot: ForeignCallSingle,
|
|
562
713
|
foreignEventValidationRequestsArrayBaseSlot: ForeignCallSingle,
|
|
@@ -565,7 +716,7 @@ export class TXEService {
|
|
|
565
716
|
const noteValidationRequestsArrayBaseSlot = fromSingle(foreignNoteValidationRequestsArrayBaseSlot);
|
|
566
717
|
const eventValidationRequestsArrayBaseSlot = fromSingle(foreignEventValidationRequestsArrayBaseSlot);
|
|
567
718
|
|
|
568
|
-
await this.
|
|
719
|
+
await this.handlerAsUtility().utilityValidateAndStoreEnqueuedNotesAndEvents(
|
|
569
720
|
contractAddress,
|
|
570
721
|
noteValidationRequestsArrayBaseSlot,
|
|
571
722
|
eventValidationRequestsArrayBaseSlot,
|
|
@@ -583,7 +734,7 @@ export class TXEService {
|
|
|
583
734
|
const logRetrievalRequestsArrayBaseSlot = fromSingle(foreignLogRetrievalRequestsArrayBaseSlot);
|
|
584
735
|
const logRetrievalResponsesArrayBaseSlot = fromSingle(foreignLogRetrievalResponsesArrayBaseSlot);
|
|
585
736
|
|
|
586
|
-
await this.
|
|
737
|
+
await this.handlerAsUtility().utilityBulkRetrieveLogs(
|
|
587
738
|
contractAddress,
|
|
588
739
|
logRetrievalRequestsArrayBaseSlot,
|
|
589
740
|
logRetrievalResponsesArrayBaseSlot,
|
|
@@ -601,7 +752,7 @@ export class TXEService {
|
|
|
601
752
|
const slot = fromSingle(foreignSlot);
|
|
602
753
|
const capsule = fromArray(foreignCapsule);
|
|
603
754
|
|
|
604
|
-
await this.
|
|
755
|
+
await this.handlerAsUtility().utilityStoreCapsule(contractAddress, slot, capsule);
|
|
605
756
|
|
|
606
757
|
return toForeignCallResult([]);
|
|
607
758
|
}
|
|
@@ -615,7 +766,7 @@ export class TXEService {
|
|
|
615
766
|
const slot = fromSingle(foreignSlot);
|
|
616
767
|
const tSize = fromSingle(foreignTSize).toNumber();
|
|
617
768
|
|
|
618
|
-
const values = await this.
|
|
769
|
+
const values = await this.handlerAsUtility().utilityLoadCapsule(contractAddress, slot);
|
|
619
770
|
|
|
620
771
|
// We are going to return a Noir Option struct to represent the possibility of null values. Options are a struct
|
|
621
772
|
// with two fields: `some` (a boolean) and `value` (a field array in this case).
|
|
@@ -632,7 +783,7 @@ export class TXEService {
|
|
|
632
783
|
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
633
784
|
const slot = fromSingle(foreignSlot);
|
|
634
785
|
|
|
635
|
-
await this.
|
|
786
|
+
await this.handlerAsUtility().utilityDeleteCapsule(contractAddress, slot);
|
|
636
787
|
|
|
637
788
|
return toForeignCallResult([]);
|
|
638
789
|
}
|
|
@@ -648,7 +799,7 @@ export class TXEService {
|
|
|
648
799
|
const dstSlot = fromSingle(foreignDstSlot);
|
|
649
800
|
const numEntries = fromSingle(foreignNumEntries).toNumber();
|
|
650
801
|
|
|
651
|
-
await this.
|
|
802
|
+
await this.handlerAsUtility().utilityCopyCapsule(contractAddress, srcSlot, dstSlot, numEntries);
|
|
652
803
|
|
|
653
804
|
return toForeignCallResult([]);
|
|
654
805
|
}
|
|
@@ -667,7 +818,7 @@ export class TXEService {
|
|
|
667
818
|
const iv = fromUintArray(foreignIv, 8);
|
|
668
819
|
const symKey = fromUintArray(foreignSymKey, 8);
|
|
669
820
|
|
|
670
|
-
const plaintextBuffer = await this.
|
|
821
|
+
const plaintextBuffer = await this.handlerAsUtility().utilityAes128Decrypt(ciphertext, iv, symKey);
|
|
671
822
|
|
|
672
823
|
return toForeignCallResult(
|
|
673
824
|
arrayToBoundedVec(bufferToU8Array(plaintextBuffer), foreignCiphertextBVecStorage.length),
|
|
@@ -687,7 +838,7 @@ export class TXEService {
|
|
|
687
838
|
fromSingle(foreignEphPKField2),
|
|
688
839
|
]);
|
|
689
840
|
|
|
690
|
-
const secret = await this.
|
|
841
|
+
const secret = await this.handlerAsUtility().utilityGetSharedSecret(address, ephPK);
|
|
691
842
|
|
|
692
843
|
return toForeignCallResult(secret.toFields().map(toSingle));
|
|
693
844
|
}
|
|
@@ -698,15 +849,16 @@ export class TXEService {
|
|
|
698
849
|
|
|
699
850
|
// AVM opcodes
|
|
700
851
|
|
|
701
|
-
|
|
852
|
+
avmOpcodeEmitPublicLog(_foreignMessage: ForeignCallArray) {
|
|
702
853
|
// TODO(#8811): Implement
|
|
703
854
|
return toForeignCallResult([]);
|
|
704
855
|
}
|
|
705
856
|
|
|
706
|
-
async avmOpcodeStorageRead(foreignSlot: ForeignCallSingle) {
|
|
857
|
+
async avmOpcodeStorageRead(foreignSlot: ForeignCallSingle, foreignContractAddress: ForeignCallSingle) {
|
|
707
858
|
const slot = fromSingle(foreignSlot);
|
|
859
|
+
const contractAddress = AztecAddress.fromField(fromSingle(foreignContractAddress));
|
|
708
860
|
|
|
709
|
-
const value = (await this.
|
|
861
|
+
const value = (await this.handlerAsAvm().avmOpcodeStorageRead(slot, contractAddress)).value;
|
|
710
862
|
|
|
711
863
|
return toForeignCallResult([toSingle(new Fr(value))]);
|
|
712
864
|
}
|
|
@@ -715,7 +867,7 @@ export class TXEService {
|
|
|
715
867
|
const slot = fromSingle(foreignSlot);
|
|
716
868
|
const value = fromSingle(foreignValue);
|
|
717
869
|
|
|
718
|
-
await this.
|
|
870
|
+
await this.handlerAsAvm().avmOpcodeStorageWrite(slot, value);
|
|
719
871
|
|
|
720
872
|
return toForeignCallResult([]);
|
|
721
873
|
}
|
|
@@ -723,7 +875,7 @@ export class TXEService {
|
|
|
723
875
|
async avmOpcodeGetContractInstanceDeployer(foreignAddress: ForeignCallSingle) {
|
|
724
876
|
const address = addressFromSingle(foreignAddress);
|
|
725
877
|
|
|
726
|
-
const instance = await this.
|
|
878
|
+
const instance = await this.handlerAsUtility().utilityGetContractInstance(address);
|
|
727
879
|
|
|
728
880
|
return toForeignCallResult([
|
|
729
881
|
toSingle(instance.deployer),
|
|
@@ -735,7 +887,7 @@ export class TXEService {
|
|
|
735
887
|
async avmOpcodeGetContractInstanceClassId(foreignAddress: ForeignCallSingle) {
|
|
736
888
|
const address = addressFromSingle(foreignAddress);
|
|
737
889
|
|
|
738
|
-
const instance = await this.
|
|
890
|
+
const instance = await this.handlerAsUtility().utilityGetContractInstance(address);
|
|
739
891
|
|
|
740
892
|
return toForeignCallResult([
|
|
741
893
|
toSingle(instance.currentContractClassId),
|
|
@@ -747,7 +899,7 @@ export class TXEService {
|
|
|
747
899
|
async avmOpcodeGetContractInstanceInitializationHash(foreignAddress: ForeignCallSingle) {
|
|
748
900
|
const address = addressFromSingle(foreignAddress);
|
|
749
901
|
|
|
750
|
-
const instance = await this.
|
|
902
|
+
const instance = await this.handlerAsUtility().utilityGetContractInstance(address);
|
|
751
903
|
|
|
752
904
|
return toForeignCallResult([
|
|
753
905
|
toSingle(instance.initializationHash),
|
|
@@ -756,8 +908,8 @@ export class TXEService {
|
|
|
756
908
|
]);
|
|
757
909
|
}
|
|
758
910
|
|
|
759
|
-
avmOpcodeSender() {
|
|
760
|
-
const sender = this.
|
|
911
|
+
async avmOpcodeSender() {
|
|
912
|
+
const sender = await this.handlerAsAvm().avmOpcodeSender();
|
|
761
913
|
|
|
762
914
|
return toForeignCallResult([toSingle(sender)]);
|
|
763
915
|
}
|
|
@@ -765,7 +917,7 @@ export class TXEService {
|
|
|
765
917
|
async avmOpcodeEmitNullifier(foreignNullifier: ForeignCallSingle) {
|
|
766
918
|
const nullifier = fromSingle(foreignNullifier);
|
|
767
919
|
|
|
768
|
-
await this.
|
|
920
|
+
await this.handlerAsAvm().avmOpcodeEmitNullifier(nullifier);
|
|
769
921
|
|
|
770
922
|
return toForeignCallResult([]);
|
|
771
923
|
}
|
|
@@ -773,52 +925,51 @@ export class TXEService {
|
|
|
773
925
|
async avmOpcodeEmitNoteHash(foreignNoteHash: ForeignCallSingle) {
|
|
774
926
|
const noteHash = fromSingle(foreignNoteHash);
|
|
775
927
|
|
|
776
|
-
await this.
|
|
928
|
+
await this.handlerAsAvm().avmOpcodeEmitNoteHash(noteHash);
|
|
777
929
|
|
|
778
930
|
return toForeignCallResult([]);
|
|
779
931
|
}
|
|
780
932
|
|
|
781
|
-
async avmOpcodeNullifierExists(
|
|
782
|
-
const
|
|
783
|
-
const targetAddress = AztecAddress.fromField(fromSingle(foreignTargetAddress));
|
|
933
|
+
async avmOpcodeNullifierExists(foreignSiloedNullifier: ForeignCallSingle) {
|
|
934
|
+
const siloedNullifier = fromSingle(foreignSiloedNullifier);
|
|
784
935
|
|
|
785
|
-
const exists = await this.
|
|
936
|
+
const exists = await this.handlerAsAvm().avmOpcodeNullifierExists(siloedNullifier);
|
|
786
937
|
|
|
787
938
|
return toForeignCallResult([toSingle(new Fr(exists))]);
|
|
788
939
|
}
|
|
789
940
|
|
|
790
941
|
async avmOpcodeAddress() {
|
|
791
|
-
const contractAddress = await this.
|
|
942
|
+
const contractAddress = await this.handlerAsAvm().avmOpcodeAddress();
|
|
792
943
|
|
|
793
944
|
return toForeignCallResult([toSingle(contractAddress.toField())]);
|
|
794
945
|
}
|
|
795
946
|
|
|
796
947
|
async avmOpcodeBlockNumber() {
|
|
797
|
-
const blockNumber = await this.
|
|
948
|
+
const blockNumber = await this.handlerAsAvm().avmOpcodeBlockNumber();
|
|
798
949
|
|
|
799
950
|
return toForeignCallResult([toSingle(new Fr(blockNumber))]);
|
|
800
951
|
}
|
|
801
952
|
|
|
802
953
|
async avmOpcodeTimestamp() {
|
|
803
|
-
const timestamp = await this.
|
|
954
|
+
const timestamp = await this.handlerAsAvm().avmOpcodeTimestamp();
|
|
804
955
|
|
|
805
956
|
return toForeignCallResult([toSingle(new Fr(timestamp))]);
|
|
806
957
|
}
|
|
807
958
|
|
|
808
959
|
async avmOpcodeIsStaticCall() {
|
|
809
|
-
const isStaticCall = await this.
|
|
960
|
+
const isStaticCall = await this.handlerAsAvm().avmOpcodeIsStaticCall();
|
|
810
961
|
|
|
811
962
|
return toForeignCallResult([toSingle(new Fr(isStaticCall ? 1 : 0))]);
|
|
812
963
|
}
|
|
813
964
|
|
|
814
965
|
async avmOpcodeChainId() {
|
|
815
|
-
const chainId = await this.
|
|
966
|
+
const chainId = await this.handlerAsAvm().avmOpcodeChainId();
|
|
816
967
|
|
|
817
968
|
return toForeignCallResult([toSingle(chainId)]);
|
|
818
969
|
}
|
|
819
970
|
|
|
820
971
|
async avmOpcodeVersion() {
|
|
821
|
-
const version = await this.
|
|
972
|
+
const version = await this.handlerAsAvm().avmOpcodeVersion();
|
|
822
973
|
|
|
823
974
|
return toForeignCallResult([toSingle(version)]);
|
|
824
975
|
}
|
|
@@ -869,7 +1020,6 @@ export class TXEService {
|
|
|
869
1020
|
foreignFrom: ForeignCallSingle,
|
|
870
1021
|
foreignTargetContractAddress: ForeignCallSingle,
|
|
871
1022
|
foreignFunctionSelector: ForeignCallSingle,
|
|
872
|
-
_foreignArgsLength: ForeignCallSingle,
|
|
873
1023
|
foreignArgs: ForeignCallArray,
|
|
874
1024
|
foreignArgsHash: ForeignCallSingle,
|
|
875
1025
|
foreignIsStaticCall: ForeignCallSingle,
|
|
@@ -881,7 +1031,7 @@ export class TXEService {
|
|
|
881
1031
|
const argsHash = fromSingle(foreignArgsHash);
|
|
882
1032
|
const isStaticCall = fromSingle(foreignIsStaticCall).toBool();
|
|
883
1033
|
|
|
884
|
-
const
|
|
1034
|
+
const returnValues = await this.handlerAsTxe().txePrivateCallNewFlow(
|
|
885
1035
|
from,
|
|
886
1036
|
targetContractAddress,
|
|
887
1037
|
functionSelector,
|
|
@@ -890,27 +1040,30 @@ export class TXEService {
|
|
|
890
1040
|
isStaticCall,
|
|
891
1041
|
);
|
|
892
1042
|
|
|
893
|
-
return toForeignCallResult([toArray(
|
|
1043
|
+
return toForeignCallResult([toArray(returnValues)]);
|
|
894
1044
|
}
|
|
895
1045
|
|
|
896
|
-
async
|
|
1046
|
+
async txeExecuteUtilityFunction(
|
|
897
1047
|
foreignTargetContractAddress: ForeignCallSingle,
|
|
898
1048
|
foreignFunctionSelector: ForeignCallSingle,
|
|
899
|
-
|
|
1049
|
+
foreignArgs: ForeignCallArray,
|
|
900
1050
|
) {
|
|
901
1051
|
const targetContractAddress = addressFromSingle(foreignTargetContractAddress);
|
|
902
1052
|
const functionSelector = FunctionSelector.fromField(fromSingle(foreignFunctionSelector));
|
|
903
|
-
const
|
|
1053
|
+
const args = fromArray(foreignArgs);
|
|
904
1054
|
|
|
905
|
-
const
|
|
1055
|
+
const returnValues = await this.handlerAsTxe().txeExecuteUtilityFunction(
|
|
1056
|
+
targetContractAddress,
|
|
1057
|
+
functionSelector,
|
|
1058
|
+
args,
|
|
1059
|
+
);
|
|
906
1060
|
|
|
907
|
-
return toForeignCallResult([
|
|
1061
|
+
return toForeignCallResult([toArray(returnValues)]);
|
|
908
1062
|
}
|
|
909
1063
|
|
|
910
1064
|
async txePublicCallNewFlow(
|
|
911
1065
|
foreignFrom: ForeignCallSingle,
|
|
912
1066
|
foreignAddress: ForeignCallSingle,
|
|
913
|
-
_foreignLength: ForeignCallSingle,
|
|
914
1067
|
foreignCalldata: ForeignCallArray,
|
|
915
1068
|
foreignIsStaticCall: ForeignCallSingle,
|
|
916
1069
|
) {
|
|
@@ -919,13 +1072,13 @@ export class TXEService {
|
|
|
919
1072
|
const calldata = fromArray(foreignCalldata);
|
|
920
1073
|
const isStaticCall = fromSingle(foreignIsStaticCall).toBool();
|
|
921
1074
|
|
|
922
|
-
const
|
|
1075
|
+
const returnValues = await this.handlerAsTxe().txePublicCallNewFlow(from, address, calldata, isStaticCall);
|
|
923
1076
|
|
|
924
|
-
return toForeignCallResult([toArray(
|
|
1077
|
+
return toForeignCallResult([toArray(returnValues)]);
|
|
925
1078
|
}
|
|
926
1079
|
|
|
927
1080
|
async privateGetSenderForTags() {
|
|
928
|
-
const sender = await this.
|
|
1081
|
+
const sender = await this.handlerAsPrivate().privateGetSenderForTags();
|
|
929
1082
|
|
|
930
1083
|
// Return a Noir Option struct with `some` and `value` fields
|
|
931
1084
|
if (sender === undefined) {
|
|
@@ -940,8 +1093,17 @@ export class TXEService {
|
|
|
940
1093
|
async privateSetSenderForTags(foreignSenderForTags: ForeignCallSingle) {
|
|
941
1094
|
const senderForTags = AztecAddress.fromField(fromSingle(foreignSenderForTags));
|
|
942
1095
|
|
|
943
|
-
await this.
|
|
1096
|
+
await this.handlerAsPrivate().privateSetSenderForTags(senderForTags);
|
|
944
1097
|
|
|
945
1098
|
return toForeignCallResult([]);
|
|
946
1099
|
}
|
|
1100
|
+
|
|
1101
|
+
async privateGetNextAppTagAsSender(foreignSender: ForeignCallSingle, foreignRecipient: ForeignCallSingle) {
|
|
1102
|
+
const sender = AztecAddress.fromField(fromSingle(foreignSender));
|
|
1103
|
+
const recipient = AztecAddress.fromField(fromSingle(foreignRecipient));
|
|
1104
|
+
|
|
1105
|
+
const nextAppTag = await this.handlerAsPrivate().privateGetNextAppTagAsSender(sender, recipient);
|
|
1106
|
+
|
|
1107
|
+
return toForeignCallResult([toSingle(nextAppTag.value)]);
|
|
1108
|
+
}
|
|
947
1109
|
}
|