@aztec/txe 0.0.1-commit.5476d83 → 0.0.1-commit.5914bae
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/constants.d.ts +3 -0
- package/dest/constants.d.ts.map +1 -0
- package/dest/constants.js +2 -0
- package/dest/index.d.ts +1 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +91 -56
- package/dest/oracle/interfaces.d.ts +33 -29
- package/dest/oracle/interfaces.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.d.ts +16 -16
- package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.js +20 -22
- package/dest/oracle/txe_oracle_top_level_context.d.ts +42 -27
- package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_top_level_context.js +232 -107
- package/dest/rpc_translator.d.ts +129 -79
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +465 -175
- 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 +66 -99
- package/dest/state_machine/dummy_p2p_client.d.ts +20 -15
- package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
- package/dest/state_machine/dummy_p2p_client.js +42 -25
- package/dest/state_machine/global_variable_builder.d.ts +6 -5
- package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
- package/dest/state_machine/global_variable_builder.js +13 -1
- package/dest/state_machine/index.d.ts +9 -7
- package/dest/state_machine/index.d.ts.map +1 -1
- package/dest/state_machine/index.js +44 -23
- package/dest/state_machine/mock_epoch_cache.d.ts +9 -6
- package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
- package/dest/state_machine/mock_epoch_cache.js +14 -7
- package/dest/state_machine/synchronizer.d.ts +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 +27 -15
- package/dest/txe_session.d.ts.map +1 -1
- package/dest/txe_session.js +173 -55
- package/dest/util/encoding.d.ts +617 -19
- package/dest/util/encoding.d.ts.map +1 -1
- package/dest/util/encoding.js +1 -1
- package/dest/util/txe_account_store.d.ts +10 -0
- package/dest/util/txe_account_store.d.ts.map +1 -0
- package/dest/util/{txe_account_data_provider.js → txe_account_store.js} +1 -1
- package/dest/util/txe_public_contract_data_source.d.ts +8 -8
- package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
- package/dest/util/txe_public_contract_data_source.js +12 -29
- package/dest/utils/block_creation.d.ts +21 -6
- package/dest/utils/block_creation.d.ts.map +1 -1
- package/dest/utils/block_creation.js +38 -4
- package/dest/utils/tx_effect_creation.d.ts +3 -3
- package/dest/utils/tx_effect_creation.d.ts.map +1 -1
- package/dest/utils/tx_effect_creation.js +4 -7
- package/package.json +18 -18
- package/src/constants.ts +3 -0
- package/src/index.ts +103 -63
- package/src/oracle/interfaces.ts +36 -32
- package/src/oracle/txe_oracle_public_context.ts +21 -28
- package/src/oracle/txe_oracle_top_level_context.ts +285 -149
- package/src/rpc_translator.ts +552 -193
- package/src/state_machine/archiver.ts +62 -117
- package/src/state_machine/dummy_p2p_client.ts +58 -33
- package/src/state_machine/global_variable_builder.ts +21 -4
- package/src/state_machine/index.ts +64 -21
- package/src/state_machine/mock_epoch_cache.ts +15 -11
- package/src/state_machine/synchronizer.ts +9 -8
- package/src/txe_session.ts +239 -104
- package/src/util/encoding.ts +1 -1
- package/src/util/{txe_account_data_provider.ts → txe_account_store.ts} +1 -1
- package/src/util/txe_public_contract_data_source.ts +20 -45
- package/src/utils/block_creation.ts +49 -15
- package/src/utils/tx_effect_creation.ts +5 -12
- package/dest/util/txe_account_data_provider.d.ts +0 -10
- package/dest/util/txe_account_data_provider.d.ts.map +0 -1
- package/dest/util/txe_contract_data_provider.d.ts +0 -12
- package/dest/util/txe_contract_data_provider.d.ts.map +0 -1
- package/dest/util/txe_contract_data_provider.js +0 -22
- package/src/util/txe_contract_data_provider.ts +0 -36
package/src/txe_session.ts
CHANGED
|
@@ -1,15 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
3
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
3
4
|
import { KeyStore } from '@aztec/key-store';
|
|
4
5
|
import { openTmpStore } from '@aztec/kv-store/lmdb-v2';
|
|
5
|
-
import type { ProtocolContract } from '@aztec/protocol-contracts';
|
|
6
6
|
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
AddressStore,
|
|
8
|
+
AnchorBlockStore,
|
|
9
|
+
CapsuleService,
|
|
10
|
+
CapsuleStore,
|
|
11
|
+
ContractStore,
|
|
12
|
+
ContractSyncService,
|
|
13
|
+
JobCoordinator,
|
|
14
|
+
NoteService,
|
|
15
|
+
NoteStore,
|
|
16
|
+
PrivateEventStore,
|
|
17
|
+
RecipientTaggingStore,
|
|
18
|
+
SenderAddressBookStore,
|
|
19
|
+
SenderTaggingStore,
|
|
13
20
|
} from '@aztec/pxe/server';
|
|
14
21
|
import {
|
|
15
22
|
ExecutionNoteCache,
|
|
@@ -17,35 +24,39 @@ import {
|
|
|
17
24
|
HashedValuesCache,
|
|
18
25
|
type IPrivateExecutionOracle,
|
|
19
26
|
type IUtilityExecutionOracle,
|
|
27
|
+
Oracle,
|
|
20
28
|
PrivateExecutionOracle,
|
|
21
29
|
UtilityExecutionOracle,
|
|
22
30
|
} from '@aztec/pxe/simulator';
|
|
23
|
-
import {
|
|
31
|
+
import {
|
|
32
|
+
ExecutionError,
|
|
33
|
+
WASMSimulator,
|
|
34
|
+
createSimulationError,
|
|
35
|
+
extractCallStack,
|
|
36
|
+
resolveAssertionMessageFromError,
|
|
37
|
+
toACVMWitness,
|
|
38
|
+
} from '@aztec/simulator/client';
|
|
39
|
+
import { FunctionCall, FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
|
|
24
40
|
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
25
41
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
26
|
-
import { Body, L2Block } from '@aztec/stdlib/block';
|
|
27
42
|
import { GasSettings } from '@aztec/stdlib/gas';
|
|
28
43
|
import { computeProtocolNullifier } from '@aztec/stdlib/hash';
|
|
29
44
|
import { PrivateContextInputs } from '@aztec/stdlib/kernel';
|
|
30
|
-
import {
|
|
45
|
+
import { makeGlobalVariables } from '@aztec/stdlib/testing';
|
|
31
46
|
import { CallContext, GlobalVariables, TxContext } from '@aztec/stdlib/tx';
|
|
32
|
-
import type { UInt32 } from '@aztec/stdlib/types';
|
|
33
47
|
|
|
34
48
|
import { z } from 'zod';
|
|
35
49
|
|
|
50
|
+
import { DEFAULT_ADDRESS } from './constants.js';
|
|
36
51
|
import type { IAvmExecutionOracle, ITxeExecutionOracle } from './oracle/interfaces.js';
|
|
37
52
|
import { TXEOraclePublicContext } from './oracle/txe_oracle_public_context.js';
|
|
38
53
|
import { TXEOracleTopLevelContext } from './oracle/txe_oracle_top_level_context.js';
|
|
39
54
|
import { RPCTranslator } from './rpc_translator.js';
|
|
55
|
+
import { TXEArchiver } from './state_machine/archiver.js';
|
|
40
56
|
import { TXEStateMachine } from './state_machine/index.js';
|
|
41
57
|
import type { ForeignCallArgs, ForeignCallResult } from './util/encoding.js';
|
|
42
|
-
import {
|
|
43
|
-
import {
|
|
44
|
-
import {
|
|
45
|
-
getSingleTxBlockRequestHash,
|
|
46
|
-
insertTxEffectIntoWorldTrees,
|
|
47
|
-
makeTXEBlockHeader,
|
|
48
|
-
} from './utils/block_creation.js';
|
|
58
|
+
import { TXEAccountStore } from './util/txe_account_store.js';
|
|
59
|
+
import { getSingleTxBlockRequestHash, insertTxEffectIntoWorldTrees, makeTXEBlock } from './utils/block_creation.js';
|
|
49
60
|
import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
50
61
|
|
|
51
62
|
/**
|
|
@@ -67,7 +78,6 @@ type SessionState =
|
|
|
67
78
|
| {
|
|
68
79
|
name: 'PRIVATE';
|
|
69
80
|
nextBlockGlobalVariables: GlobalVariables;
|
|
70
|
-
protocolNullifier: Fr;
|
|
71
81
|
noteCache: ExecutionNoteCache;
|
|
72
82
|
taggingIndexCache: ExecutionTaggingIndexCache;
|
|
73
83
|
}
|
|
@@ -102,11 +112,13 @@ export type TXEOracleFunctionName = Exclude<
|
|
|
102
112
|
export interface TXESessionStateHandler {
|
|
103
113
|
enterTopLevelState(): Promise<void>;
|
|
104
114
|
enterPublicState(contractAddress?: AztecAddress): Promise<void>;
|
|
105
|
-
enterPrivateState(contractAddress?: AztecAddress, anchorBlockNumber?:
|
|
115
|
+
enterPrivateState(contractAddress?: AztecAddress, anchorBlockNumber?: BlockNumber): Promise<PrivateContextInputs>;
|
|
106
116
|
enterUtilityState(contractAddress?: AztecAddress): Promise<void>;
|
|
107
|
-
}
|
|
108
117
|
|
|
109
|
-
|
|
118
|
+
// TODO(F-335): Exposing the job info is abstraction breakage - drop the following 2 functions.
|
|
119
|
+
cycleJob(): Promise<string>;
|
|
120
|
+
getCurrentJob(): string;
|
|
121
|
+
}
|
|
110
122
|
|
|
111
123
|
/**
|
|
112
124
|
* A `TXESession` corresponds to a Noir `#[test]` function, and handles all of its oracle calls, stores test-specific
|
|
@@ -124,78 +136,100 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
124
136
|
| IPrivateExecutionOracle
|
|
125
137
|
| IAvmExecutionOracle
|
|
126
138
|
| ITxeExecutionOracle,
|
|
127
|
-
private
|
|
139
|
+
private contractStore: ContractStore,
|
|
140
|
+
private noteStore: NoteStore,
|
|
128
141
|
private keyStore: KeyStore,
|
|
129
|
-
private
|
|
130
|
-
private
|
|
142
|
+
private addressStore: AddressStore,
|
|
143
|
+
private accountStore: TXEAccountStore,
|
|
144
|
+
private senderTaggingStore: SenderTaggingStore,
|
|
145
|
+
private recipientTaggingStore: RecipientTaggingStore,
|
|
146
|
+
private senderAddressBookStore: SenderAddressBookStore,
|
|
147
|
+
private capsuleStore: CapsuleStore,
|
|
148
|
+
private privateEventStore: PrivateEventStore,
|
|
149
|
+
private jobCoordinator: JobCoordinator,
|
|
150
|
+
private currentJobId: string,
|
|
131
151
|
private chainId: Fr,
|
|
132
152
|
private version: Fr,
|
|
133
153
|
private nextBlockTimestamp: bigint,
|
|
134
|
-
private
|
|
154
|
+
private contractSyncService: ContractSyncService,
|
|
135
155
|
) {}
|
|
136
156
|
|
|
137
|
-
static async init(
|
|
157
|
+
static async init(contractStore: ContractStore) {
|
|
138
158
|
const store = await openTmpStore('txe-session');
|
|
139
159
|
|
|
140
|
-
const
|
|
141
|
-
const
|
|
142
|
-
const
|
|
143
|
-
const
|
|
144
|
-
const
|
|
145
|
-
const
|
|
160
|
+
const addressStore = new AddressStore(store);
|
|
161
|
+
const privateEventStore = new PrivateEventStore(store);
|
|
162
|
+
const noteStore = new NoteStore(store);
|
|
163
|
+
const senderTaggingStore = new SenderTaggingStore(store);
|
|
164
|
+
const recipientTaggingStore = new RecipientTaggingStore(store);
|
|
165
|
+
const senderAddressBookStore = new SenderAddressBookStore(store);
|
|
166
|
+
const capsuleStore = new CapsuleStore(store);
|
|
146
167
|
const keyStore = new KeyStore(store);
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
//
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
168
|
+
const accountStore = new TXEAccountStore(store);
|
|
169
|
+
|
|
170
|
+
// Create job coordinator and register staged stores
|
|
171
|
+
const jobCoordinator = new JobCoordinator(store);
|
|
172
|
+
jobCoordinator.registerStores([
|
|
173
|
+
capsuleStore,
|
|
174
|
+
senderTaggingStore,
|
|
175
|
+
recipientTaggingStore,
|
|
176
|
+
privateEventStore,
|
|
177
|
+
noteStore,
|
|
178
|
+
]);
|
|
179
|
+
|
|
180
|
+
const archiver = new TXEArchiver(store);
|
|
181
|
+
const anchorBlockStore = new AnchorBlockStore(store);
|
|
182
|
+
const stateMachine = await TXEStateMachine.create(archiver, anchorBlockStore, contractStore, noteStore);
|
|
156
183
|
|
|
157
184
|
const nextBlockTimestamp = BigInt(Math.floor(new Date().getTime() / 1000));
|
|
158
185
|
const version = new Fr(await stateMachine.node.getVersion());
|
|
159
186
|
const chainId = new Fr(await stateMachine.node.getChainId());
|
|
160
187
|
|
|
161
|
-
const
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
noteDataProvider,
|
|
166
|
-
capsuleDataProvider,
|
|
167
|
-
stateMachine.syncDataProvider,
|
|
168
|
-
taggingDataProvider,
|
|
169
|
-
addressDataProvider,
|
|
170
|
-
privateEventDataProvider,
|
|
171
|
-
);
|
|
188
|
+
const initialJobId = jobCoordinator.beginJob();
|
|
189
|
+
|
|
190
|
+
const logger = createLogger('txe:session');
|
|
191
|
+
const contractSyncService = new ContractSyncService(stateMachine.node, contractStore, noteStore, logger);
|
|
172
192
|
|
|
173
193
|
const topLevelOracleHandler = new TXEOracleTopLevelContext(
|
|
174
194
|
stateMachine,
|
|
175
|
-
|
|
195
|
+
contractStore,
|
|
196
|
+
noteStore,
|
|
176
197
|
keyStore,
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
198
|
+
addressStore,
|
|
199
|
+
accountStore,
|
|
200
|
+
senderTaggingStore,
|
|
201
|
+
recipientTaggingStore,
|
|
202
|
+
senderAddressBookStore,
|
|
203
|
+
capsuleStore,
|
|
204
|
+
privateEventStore,
|
|
180
205
|
nextBlockTimestamp,
|
|
181
206
|
version,
|
|
182
207
|
chainId,
|
|
183
208
|
new Map(),
|
|
209
|
+
contractSyncService,
|
|
184
210
|
);
|
|
185
|
-
await topLevelOracleHandler.
|
|
211
|
+
await topLevelOracleHandler.advanceBlocksBy(1);
|
|
186
212
|
|
|
187
213
|
return new TXESession(
|
|
188
|
-
|
|
214
|
+
logger,
|
|
189
215
|
stateMachine,
|
|
190
216
|
topLevelOracleHandler,
|
|
191
|
-
|
|
217
|
+
contractStore,
|
|
218
|
+
noteStore,
|
|
192
219
|
keyStore,
|
|
193
|
-
|
|
194
|
-
|
|
220
|
+
addressStore,
|
|
221
|
+
accountStore,
|
|
222
|
+
senderTaggingStore,
|
|
223
|
+
recipientTaggingStore,
|
|
224
|
+
senderAddressBookStore,
|
|
225
|
+
capsuleStore,
|
|
226
|
+
privateEventStore,
|
|
227
|
+
jobCoordinator,
|
|
228
|
+
initialJobId,
|
|
195
229
|
version,
|
|
196
230
|
chainId,
|
|
197
231
|
nextBlockTimestamp,
|
|
198
|
-
|
|
232
|
+
contractSyncService,
|
|
199
233
|
);
|
|
200
234
|
}
|
|
201
235
|
|
|
@@ -230,6 +264,17 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
230
264
|
}
|
|
231
265
|
}
|
|
232
266
|
|
|
267
|
+
getCurrentJob(): string {
|
|
268
|
+
return this.currentJobId;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/** Commits the current job and begins a new one. Returns the new job ID. */
|
|
272
|
+
async cycleJob(): Promise<string> {
|
|
273
|
+
await this.jobCoordinator.commitJob(this.currentJobId);
|
|
274
|
+
this.currentJobId = this.jobCoordinator.beginJob();
|
|
275
|
+
return this.currentJobId;
|
|
276
|
+
}
|
|
277
|
+
|
|
233
278
|
async enterTopLevelState() {
|
|
234
279
|
switch (this.state.name) {
|
|
235
280
|
case 'PRIVATE': {
|
|
@@ -252,17 +297,26 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
252
297
|
}
|
|
253
298
|
}
|
|
254
299
|
|
|
300
|
+
// Commit all staged stores from the job that was just completed, then begin a new job
|
|
301
|
+
await this.cycleJob();
|
|
302
|
+
|
|
255
303
|
this.oracleHandler = new TXEOracleTopLevelContext(
|
|
256
304
|
this.stateMachine,
|
|
257
|
-
this.
|
|
305
|
+
this.contractStore,
|
|
306
|
+
this.noteStore,
|
|
258
307
|
this.keyStore,
|
|
259
|
-
this.
|
|
260
|
-
this.
|
|
261
|
-
this.
|
|
308
|
+
this.addressStore,
|
|
309
|
+
this.accountStore,
|
|
310
|
+
this.senderTaggingStore,
|
|
311
|
+
this.recipientTaggingStore,
|
|
312
|
+
this.senderAddressBookStore,
|
|
313
|
+
this.capsuleStore,
|
|
314
|
+
this.privateEventStore,
|
|
262
315
|
this.nextBlockTimestamp,
|
|
263
316
|
this.version,
|
|
264
317
|
this.chainId,
|
|
265
318
|
this.authwits,
|
|
319
|
+
this.contractSyncService,
|
|
266
320
|
);
|
|
267
321
|
|
|
268
322
|
this.state = { name: 'TOP_LEVEL' };
|
|
@@ -271,25 +325,23 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
271
325
|
|
|
272
326
|
async enterPrivateState(
|
|
273
327
|
contractAddress: AztecAddress = DEFAULT_ADDRESS,
|
|
274
|
-
anchorBlockNumber?:
|
|
328
|
+
anchorBlockNumber?: BlockNumber,
|
|
275
329
|
): Promise<PrivateContextInputs> {
|
|
276
330
|
this.exitTopLevelState();
|
|
277
331
|
|
|
278
|
-
// There is no automatic message discovery and contract-driven syncing process in inlined private or utility
|
|
279
|
-
// contexts, which means that known nullifiers are also not searched for, since it is during the tagging sync that
|
|
280
|
-
// we perform this. We therefore search for known nullifiers now, as otherwise notes that were nullified would not
|
|
281
|
-
// be removed from the database.
|
|
282
|
-
// TODO(#12553): make the synchronizer sync here instead and remove this
|
|
283
|
-
await this.pxeOracleInterface.syncNoteNullifiers(contractAddress);
|
|
284
|
-
|
|
285
332
|
// Private execution has two associated block numbers: the anchor block (i.e. the historical block that is used to
|
|
286
333
|
// build the proof), and the *next* block, i.e. the one we'll create once the execution ends, and which will contain
|
|
287
334
|
// a single transaction with the effects of what was done in the test.
|
|
288
335
|
const anchorBlock = await this.stateMachine.node.getBlockHeader(anchorBlockNumber ?? 'latest');
|
|
336
|
+
|
|
337
|
+
await new NoteService(this.noteStore, this.stateMachine.node, anchorBlock!, this.currentJobId).syncNoteNullifiers(
|
|
338
|
+
contractAddress,
|
|
339
|
+
await this.keyStore.getAccounts(),
|
|
340
|
+
);
|
|
289
341
|
const latestBlock = await this.stateMachine.node.getBlockHeader('latest');
|
|
290
342
|
|
|
291
343
|
const nextBlockGlobalVariables = makeGlobalVariables(undefined, {
|
|
292
|
-
blockNumber: latestBlock!.globalVariables.blockNumber + 1,
|
|
344
|
+
blockNumber: BlockNumber(latestBlock!.globalVariables.blockNumber + 1),
|
|
293
345
|
timestamp: this.nextBlockTimestamp,
|
|
294
346
|
version: this.version,
|
|
295
347
|
chainId: this.chainId,
|
|
@@ -300,25 +352,41 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
300
352
|
const noteCache = new ExecutionNoteCache(protocolNullifier);
|
|
301
353
|
const taggingIndexCache = new ExecutionTaggingIndexCache();
|
|
302
354
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
new
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
355
|
+
const utilityExecutor = this.utilityExecutorForContractSync(anchorBlock);
|
|
356
|
+
this.oracleHandler = new PrivateExecutionOracle({
|
|
357
|
+
argsHash: Fr.ZERO,
|
|
358
|
+
txContext: new TxContext(this.chainId, this.version, GasSettings.empty()),
|
|
359
|
+
callContext: new CallContext(AztecAddress.ZERO, contractAddress, FunctionSelector.empty(), false),
|
|
360
|
+
anchorBlockHeader: anchorBlock!,
|
|
361
|
+
utilityExecutor,
|
|
362
|
+
authWitnesses: [],
|
|
363
|
+
capsules: [],
|
|
364
|
+
executionCache: new HashedValuesCache(),
|
|
311
365
|
noteCache,
|
|
312
366
|
taggingIndexCache,
|
|
313
|
-
this.
|
|
314
|
-
|
|
367
|
+
contractStore: this.contractStore,
|
|
368
|
+
noteStore: this.noteStore,
|
|
369
|
+
keyStore: this.keyStore,
|
|
370
|
+
addressStore: this.addressStore,
|
|
371
|
+
aztecNode: this.stateMachine.node,
|
|
372
|
+
senderTaggingStore: this.senderTaggingStore,
|
|
373
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
374
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
375
|
+
capsuleService: new CapsuleService(this.capsuleStore, await this.keyStore.getAccounts()),
|
|
376
|
+
privateEventStore: this.privateEventStore,
|
|
377
|
+
contractSyncService: this.stateMachine.contractSyncService,
|
|
378
|
+
l2TipsStore: this.stateMachine.node,
|
|
379
|
+
jobId: this.currentJobId,
|
|
380
|
+
scopes: await this.keyStore.getAccounts(),
|
|
381
|
+
messageContextService: this.stateMachine.messageContextService,
|
|
382
|
+
});
|
|
315
383
|
|
|
316
384
|
// We store the note and tagging index caches fed into the PrivateExecutionOracle (along with some other auxiliary
|
|
317
385
|
// data) in order to refer to it later, mimicking the way this object is used by the ContractFunctionSimulator. The
|
|
318
386
|
// difference resides in that the simulator has all information needed in order to run the simulation, while ours
|
|
319
387
|
// will be ongoing as the different oracles will be invoked from the Noir test, until eventually the private
|
|
320
388
|
// execution finishes.
|
|
321
|
-
this.state = { name: 'PRIVATE', nextBlockGlobalVariables,
|
|
389
|
+
this.state = { name: 'PRIVATE', nextBlockGlobalVariables, noteCache, taggingIndexCache };
|
|
322
390
|
this.logger.debug(`Entered state ${this.state.name}`);
|
|
323
391
|
|
|
324
392
|
return (this.oracleHandler as PrivateExecutionOracle).getPrivateContextInputs();
|
|
@@ -331,7 +399,7 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
331
399
|
// the test. The block therefore gets the *next* block number and timestamp.
|
|
332
400
|
const latestBlockNumber = (await this.stateMachine.node.getBlockHeader('latest'))!.globalVariables.blockNumber;
|
|
333
401
|
const globalVariables = makeGlobalVariables(undefined, {
|
|
334
|
-
blockNumber: latestBlockNumber + 1,
|
|
402
|
+
blockNumber: BlockNumber(latestBlockNumber + 1),
|
|
335
403
|
timestamp: this.nextBlockTimestamp,
|
|
336
404
|
version: this.version,
|
|
337
405
|
chainId: this.chainId,
|
|
@@ -351,14 +419,40 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
351
419
|
async enterUtilityState(contractAddress: AztecAddress = DEFAULT_ADDRESS) {
|
|
352
420
|
this.exitTopLevelState();
|
|
353
421
|
|
|
422
|
+
const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
423
|
+
|
|
354
424
|
// There is no automatic message discovery and contract-driven syncing process in inlined private or utility
|
|
355
425
|
// contexts, which means that known nullifiers are also not searched for, since it is during the tagging sync that
|
|
356
426
|
// we perform this. We therefore search for known nullifiers now, as otherwise notes that were nullified would not
|
|
357
427
|
// be removed from the database.
|
|
358
428
|
// TODO(#12553): make the synchronizer sync here instead and remove this
|
|
359
|
-
await
|
|
360
|
-
|
|
361
|
-
|
|
429
|
+
await new NoteService(
|
|
430
|
+
this.noteStore,
|
|
431
|
+
this.stateMachine.node,
|
|
432
|
+
anchorBlockHeader,
|
|
433
|
+
this.currentJobId,
|
|
434
|
+
).syncNoteNullifiers(contractAddress, await this.keyStore.getAccounts());
|
|
435
|
+
|
|
436
|
+
this.oracleHandler = new UtilityExecutionOracle({
|
|
437
|
+
contractAddress,
|
|
438
|
+
authWitnesses: [],
|
|
439
|
+
capsules: [],
|
|
440
|
+
anchorBlockHeader,
|
|
441
|
+
contractStore: this.contractStore,
|
|
442
|
+
noteStore: this.noteStore,
|
|
443
|
+
keyStore: this.keyStore,
|
|
444
|
+
addressStore: this.addressStore,
|
|
445
|
+
aztecNode: this.stateMachine.node,
|
|
446
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
447
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
448
|
+
capsuleService: new CapsuleService(this.capsuleStore, await this.keyStore.getAccounts()),
|
|
449
|
+
privateEventStore: this.privateEventStore,
|
|
450
|
+
messageContextService: this.stateMachine.messageContextService,
|
|
451
|
+
contractSyncService: this.contractSyncService,
|
|
452
|
+
l2TipsStore: this.stateMachine.node,
|
|
453
|
+
jobId: this.currentJobId,
|
|
454
|
+
scopes: await this.keyStore.getAccounts(),
|
|
455
|
+
});
|
|
362
456
|
|
|
363
457
|
this.state = { name: 'UTILITY' };
|
|
364
458
|
this.logger.debug(`Entered state ${this.state.name}`);
|
|
@@ -371,8 +465,8 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
371
465
|
|
|
372
466
|
// Note that while all public and private contexts do is build a single block that we then process when exiting
|
|
373
467
|
// those, the top level context performs a large number of actions not captured in the following 'close' call. Among
|
|
374
|
-
// others, it will create empty blocks (via `
|
|
375
|
-
// `
|
|
468
|
+
// others, it will create empty blocks (via `advanceBlocksBy` and `deploy`), create blocks with transactions via
|
|
469
|
+
// `privateCallNewFlow` and `publicCallNewFlow`, add accounts to PXE via `addAccount`, etc. This is a
|
|
376
470
|
// slight inconsistency in the working model of this class, but is not too bad.
|
|
377
471
|
// TODO: it's quite unfortunate that we need to capture the authwits created to later pass them again when the top
|
|
378
472
|
// level context is re-created. This is because authwits create a temporary utility context that'd otherwise reset
|
|
@@ -392,21 +486,14 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
392
486
|
|
|
393
487
|
// We rely on the note cache to determine the effects of the transaction. This is incomplete as it doesn't private
|
|
394
488
|
// logs (other effects like enqueued public calls don't need to be considered since those are not allowed).
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
this.state.protocolNullifier,
|
|
398
|
-
this.state.nextBlockGlobalVariables.blockNumber,
|
|
399
|
-
);
|
|
489
|
+
|
|
490
|
+
const txEffect = await makeTxEffect(this.state.noteCache, this.state.nextBlockGlobalVariables.blockNumber);
|
|
400
491
|
|
|
401
492
|
// We build a block holding just this transaction
|
|
402
493
|
const forkedWorldTrees = await this.stateMachine.synchronizer.nativeWorldStateService.fork();
|
|
403
494
|
await insertTxEffectIntoWorldTrees(txEffect, forkedWorldTrees);
|
|
404
495
|
|
|
405
|
-
const block =
|
|
406
|
-
makeAppendOnlyTreeSnapshot(),
|
|
407
|
-
await makeTXEBlockHeader(forkedWorldTrees, this.state.nextBlockGlobalVariables),
|
|
408
|
-
new Body([txEffect]),
|
|
409
|
-
);
|
|
496
|
+
const block = await makeTXEBlock(forkedWorldTrees, this.state.nextBlockGlobalVariables, [txEffect]);
|
|
410
497
|
await this.stateMachine.handleL2Block(block);
|
|
411
498
|
|
|
412
499
|
await forkedWorldTrees.close();
|
|
@@ -431,4 +518,52 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
431
518
|
throw new Error(`Expected to be in state 'UTILITY', but got '${this.state.name}' instead`);
|
|
432
519
|
}
|
|
433
520
|
}
|
|
521
|
+
|
|
522
|
+
private utilityExecutorForContractSync(anchorBlock: any) {
|
|
523
|
+
return async (call: FunctionCall, scopes: AztecAddress[]) => {
|
|
524
|
+
const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
|
|
525
|
+
if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
|
|
526
|
+
throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
try {
|
|
530
|
+
const oracle = new UtilityExecutionOracle({
|
|
531
|
+
contractAddress: call.to,
|
|
532
|
+
authWitnesses: [],
|
|
533
|
+
capsules: [],
|
|
534
|
+
anchorBlockHeader: anchorBlock!,
|
|
535
|
+
contractStore: this.contractStore,
|
|
536
|
+
noteStore: this.noteStore,
|
|
537
|
+
keyStore: this.keyStore,
|
|
538
|
+
addressStore: this.addressStore,
|
|
539
|
+
aztecNode: this.stateMachine.node,
|
|
540
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
541
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
542
|
+
capsuleService: new CapsuleService(this.capsuleStore, scopes),
|
|
543
|
+
privateEventStore: this.privateEventStore,
|
|
544
|
+
messageContextService: this.stateMachine.messageContextService,
|
|
545
|
+
contractSyncService: this.contractSyncService,
|
|
546
|
+
l2TipsStore: this.stateMachine.node,
|
|
547
|
+
jobId: this.currentJobId,
|
|
548
|
+
scopes,
|
|
549
|
+
});
|
|
550
|
+
await new WASMSimulator()
|
|
551
|
+
.executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, new Oracle(oracle).toACIRCallback())
|
|
552
|
+
.catch((err: Error) => {
|
|
553
|
+
err.message = resolveAssertionMessageFromError(err, entryPointArtifact);
|
|
554
|
+
throw new ExecutionError(
|
|
555
|
+
err.message,
|
|
556
|
+
{
|
|
557
|
+
contractAddress: call.to,
|
|
558
|
+
functionSelector: call.selector,
|
|
559
|
+
},
|
|
560
|
+
extractCallStack(err, entryPointArtifact.debug),
|
|
561
|
+
{ cause: err },
|
|
562
|
+
);
|
|
563
|
+
});
|
|
564
|
+
} catch (err) {
|
|
565
|
+
throw createSimulationError(err instanceof Error ? err : new Error('Unknown error contract data sync'));
|
|
566
|
+
}
|
|
567
|
+
};
|
|
568
|
+
}
|
|
434
569
|
}
|
package/src/util/encoding.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
1
2
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
2
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
3
3
|
import { hexToBuffer } from '@aztec/foundation/string';
|
|
4
4
|
import { type ContractArtifact, ContractArtifactSchema } from '@aztec/stdlib/abi';
|
|
5
5
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
@@ -2,7 +2,7 @@ import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
|
|
|
2
2
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
3
3
|
import { CompleteAddress } from '@aztec/stdlib/contract';
|
|
4
4
|
|
|
5
|
-
export class
|
|
5
|
+
export class TXEAccountStore {
|
|
6
6
|
#accounts: AztecAsyncMap<string, Buffer>;
|
|
7
7
|
|
|
8
8
|
constructor(store: AztecAsyncKVStore) {
|
|
@@ -1,68 +1,43 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
|
+
import type { ContractStore } from '@aztec/pxe/server';
|
|
4
|
+
import { type ContractArtifact, FunctionSelector } from '@aztec/stdlib/abi';
|
|
4
5
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
|
-
import {
|
|
6
|
-
type ContractClassPublic,
|
|
7
|
-
type ContractDataSource,
|
|
8
|
-
type ContractInstanceWithAddress,
|
|
9
|
-
computePrivateFunctionsRoot,
|
|
10
|
-
computePublicBytecodeCommitment,
|
|
11
|
-
getContractClassPrivateFunctionFromArtifact,
|
|
12
|
-
} from '@aztec/stdlib/contract';
|
|
6
|
+
import type { ContractClassPublic, ContractDataSource, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
13
7
|
|
|
14
8
|
export class TXEPublicContractDataSource implements ContractDataSource {
|
|
15
|
-
#privateFunctionsRoot: Map<string, Buffer> = new Map();
|
|
16
9
|
constructor(
|
|
17
|
-
private blockNumber:
|
|
18
|
-
private
|
|
10
|
+
private blockNumber: BlockNumber,
|
|
11
|
+
private contractStore: ContractStore,
|
|
19
12
|
) {}
|
|
20
13
|
|
|
21
|
-
getBlockNumber(): Promise<
|
|
14
|
+
getBlockNumber(): Promise<BlockNumber> {
|
|
22
15
|
return Promise.resolve(this.blockNumber);
|
|
23
16
|
}
|
|
24
17
|
|
|
25
18
|
async getContractClass(id: Fr): Promise<ContractClassPublic | undefined> {
|
|
26
|
-
const contractClass = await this.
|
|
19
|
+
const contractClass = await this.contractStore.getContractClassWithPreimage(id);
|
|
27
20
|
if (!contractClass) {
|
|
28
21
|
return;
|
|
29
22
|
}
|
|
30
|
-
const artifact = await this.contractDataProvider.getContractArtifact(id);
|
|
31
|
-
if (!artifact) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
let privateFunctionsRoot;
|
|
36
|
-
if (!this.#privateFunctionsRoot.has(id.toString())) {
|
|
37
|
-
const privateFunctions = await Promise.all(
|
|
38
|
-
artifact.functions
|
|
39
|
-
.filter(fn => fn.functionType === FunctionType.PRIVATE)
|
|
40
|
-
.map(fn => getContractClassPrivateFunctionFromArtifact(fn)),
|
|
41
|
-
);
|
|
42
|
-
privateFunctionsRoot = await computePrivateFunctionsRoot(privateFunctions);
|
|
43
|
-
this.#privateFunctionsRoot.set(id.toString(), privateFunctionsRoot.toBuffer());
|
|
44
|
-
} else {
|
|
45
|
-
privateFunctionsRoot = Fr.fromBuffer(this.#privateFunctionsRoot.get(id.toString())!);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
23
|
return {
|
|
49
|
-
id,
|
|
50
|
-
artifactHash: contractClass
|
|
51
|
-
packedBytecode: contractClass
|
|
52
|
-
privateFunctionsRoot,
|
|
53
|
-
version: contractClass
|
|
24
|
+
id: contractClass.id,
|
|
25
|
+
artifactHash: contractClass.artifactHash,
|
|
26
|
+
packedBytecode: contractClass.packedBytecode,
|
|
27
|
+
privateFunctionsRoot: contractClass.privateFunctionsRoot,
|
|
28
|
+
version: contractClass.version,
|
|
54
29
|
privateFunctions: [],
|
|
55
30
|
utilityFunctions: [],
|
|
56
31
|
};
|
|
57
32
|
}
|
|
58
33
|
|
|
59
34
|
async getBytecodeCommitment(id: Fr): Promise<Fr | undefined> {
|
|
60
|
-
const contractClass = await this.
|
|
61
|
-
return contractClass
|
|
35
|
+
const contractClass = await this.contractStore.getContractClassWithPreimage(id);
|
|
36
|
+
return contractClass?.publicBytecodeCommitment;
|
|
62
37
|
}
|
|
63
38
|
|
|
64
39
|
async getContract(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
|
|
65
|
-
const instance = await this.
|
|
40
|
+
const instance = await this.contractStore.getContractInstance(address);
|
|
66
41
|
return instance && { ...instance, address };
|
|
67
42
|
}
|
|
68
43
|
|
|
@@ -71,12 +46,12 @@ export class TXEPublicContractDataSource implements ContractDataSource {
|
|
|
71
46
|
}
|
|
72
47
|
|
|
73
48
|
async getContractArtifact(address: AztecAddress): Promise<ContractArtifact | undefined> {
|
|
74
|
-
const instance = await this.
|
|
75
|
-
return instance && this.
|
|
49
|
+
const instance = await this.contractStore.getContractInstance(address);
|
|
50
|
+
return instance && this.contractStore.getContractArtifact(instance.currentContractClassId);
|
|
76
51
|
}
|
|
77
52
|
|
|
78
53
|
async getDebugFunctionName(address: AztecAddress, selector: FunctionSelector): Promise<string | undefined> {
|
|
79
|
-
return await this.
|
|
54
|
+
return await this.contractStore.getDebugFunctionName(address, selector);
|
|
80
55
|
}
|
|
81
56
|
|
|
82
57
|
registerContractFunctionSignatures(_signatures: []): Promise<void> {
|