@aztec/txe 0.0.1-commit.3469e52 → 0.0.1-commit.35158ae7e
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/index.d.ts +1 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +88 -54
- package/dest/oracle/interfaces.d.ts +29 -28
- package/dest/oracle/interfaces.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.d.ts +15 -15
- package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.js +16 -16
- package/dest/oracle/txe_oracle_top_level_context.d.ts +23 -23
- package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_top_level_context.js +130 -54
- package/dest/rpc_translator.d.ts +92 -81
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +315 -169
- package/dest/state_machine/archiver.d.ts +4 -4
- package/dest/state_machine/archiver.d.ts.map +1 -1
- package/dest/state_machine/archiver.js +8 -9
- package/dest/state_machine/dummy_p2p_client.d.ts +16 -12
- package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
- package/dest/state_machine/dummy_p2p_client.js +28 -16
- package/dest/state_machine/index.d.ts +9 -7
- package/dest/state_machine/index.d.ts.map +1 -1
- package/dest/state_machine/index.js +35 -17
- package/dest/state_machine/mock_epoch_cache.d.ts +22 -4
- package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
- package/dest/state_machine/mock_epoch_cache.js +38 -3
- package/dest/state_machine/synchronizer.d.ts +6 -6
- package/dest/state_machine/synchronizer.d.ts.map +1 -1
- package/dest/state_machine/synchronizer.js +3 -3
- package/dest/txe_session.d.ts +10 -6
- package/dest/txe_session.d.ts.map +1 -1
- package/dest/txe_session.js +97 -28
- package/dest/util/encoding.d.ts +69 -1
- package/dest/util/encoding.d.ts.map +1 -1
- package/dest/util/txe_public_contract_data_source.d.ts +2 -3
- package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
- package/dest/util/txe_public_contract_data_source.js +6 -25
- package/dest/utils/block_creation.d.ts +5 -5
- package/dest/utils/block_creation.d.ts.map +1 -1
- package/dest/utils/block_creation.js +7 -5
- package/package.json +15 -15
- package/src/index.ts +89 -52
- package/src/oracle/interfaces.ts +32 -31
- package/src/oracle/txe_oracle_public_context.ts +18 -20
- package/src/oracle/txe_oracle_top_level_context.ts +160 -102
- package/src/rpc_translator.ts +349 -185
- package/src/state_machine/archiver.ts +9 -11
- package/src/state_machine/dummy_p2p_client.ts +40 -22
- package/src/state_machine/index.ts +54 -19
- package/src/state_machine/mock_epoch_cache.ts +49 -4
- package/src/state_machine/synchronizer.ts +5 -5
- package/src/txe_session.ts +115 -86
- package/src/util/txe_public_contract_data_source.ts +10 -38
- package/src/utils/block_creation.ts +8 -6
- package/dest/util/txe_contract_store.d.ts +0 -12
- package/dest/util/txe_contract_store.d.ts.map +0 -1
- package/dest/util/txe_contract_store.js +0 -22
- package/src/util/txe_contract_store.ts +0 -36
package/src/txe_session.ts
CHANGED
|
@@ -3,10 +3,13 @@ import { Fr } from '@aztec/foundation/curves/bn254';
|
|
|
3
3
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
4
4
|
import { KeyStore } from '@aztec/key-store';
|
|
5
5
|
import { openTmpStore } from '@aztec/kv-store/lmdb-v2';
|
|
6
|
-
import type {
|
|
6
|
+
import type { AccessScopes } from '@aztec/pxe/client/lazy';
|
|
7
7
|
import {
|
|
8
8
|
AddressStore,
|
|
9
|
+
AnchorBlockStore,
|
|
9
10
|
CapsuleStore,
|
|
11
|
+
ContractStore,
|
|
12
|
+
ContractSyncService,
|
|
10
13
|
JobCoordinator,
|
|
11
14
|
NoteService,
|
|
12
15
|
NoteStore,
|
|
@@ -49,10 +52,10 @@ import type { IAvmExecutionOracle, ITxeExecutionOracle } from './oracle/interfac
|
|
|
49
52
|
import { TXEOraclePublicContext } from './oracle/txe_oracle_public_context.js';
|
|
50
53
|
import { TXEOracleTopLevelContext } from './oracle/txe_oracle_top_level_context.js';
|
|
51
54
|
import { RPCTranslator } from './rpc_translator.js';
|
|
55
|
+
import { TXEArchiver } from './state_machine/archiver.js';
|
|
52
56
|
import { TXEStateMachine } from './state_machine/index.js';
|
|
53
57
|
import type { ForeignCallArgs, ForeignCallResult } from './util/encoding.js';
|
|
54
58
|
import { TXEAccountStore } from './util/txe_account_store.js';
|
|
55
|
-
import { TXEContractStore } from './util/txe_contract_store.js';
|
|
56
59
|
import { getSingleTxBlockRequestHash, insertTxEffectIntoWorldTrees, makeTXEBlock } from './utils/block_creation.js';
|
|
57
60
|
import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
58
61
|
|
|
@@ -111,6 +114,10 @@ export interface TXESessionStateHandler {
|
|
|
111
114
|
enterPublicState(contractAddress?: AztecAddress): Promise<void>;
|
|
112
115
|
enterPrivateState(contractAddress?: AztecAddress, anchorBlockNumber?: BlockNumber): Promise<PrivateContextInputs>;
|
|
113
116
|
enterUtilityState(contractAddress?: AztecAddress): Promise<void>;
|
|
117
|
+
|
|
118
|
+
// TODO(F-335): Exposing the job info is abstraction breakage - drop the following 2 functions.
|
|
119
|
+
cycleJob(): Promise<string>;
|
|
120
|
+
getCurrentJob(): string;
|
|
114
121
|
}
|
|
115
122
|
|
|
116
123
|
/**
|
|
@@ -129,7 +136,7 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
129
136
|
| IPrivateExecutionOracle
|
|
130
137
|
| IAvmExecutionOracle
|
|
131
138
|
| ITxeExecutionOracle,
|
|
132
|
-
private contractStore:
|
|
139
|
+
private contractStore: ContractStore,
|
|
133
140
|
private noteStore: NoteStore,
|
|
134
141
|
private keyStore: KeyStore,
|
|
135
142
|
private addressStore: AddressStore,
|
|
@@ -144,15 +151,15 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
144
151
|
private chainId: Fr,
|
|
145
152
|
private version: Fr,
|
|
146
153
|
private nextBlockTimestamp: bigint,
|
|
154
|
+
private contractSyncService: ContractSyncService,
|
|
147
155
|
) {}
|
|
148
156
|
|
|
149
|
-
static async init(
|
|
157
|
+
static async init(contractStore: ContractStore) {
|
|
150
158
|
const store = await openTmpStore('txe-session');
|
|
151
159
|
|
|
152
160
|
const addressStore = new AddressStore(store);
|
|
153
161
|
const privateEventStore = new PrivateEventStore(store);
|
|
154
|
-
const
|
|
155
|
-
const noteStore = await NoteStore.create(store);
|
|
162
|
+
const noteStore = new NoteStore(store);
|
|
156
163
|
const senderTaggingStore = new SenderTaggingStore(store);
|
|
157
164
|
const recipientTaggingStore = new RecipientTaggingStore(store);
|
|
158
165
|
const senderAddressBookStore = new SenderAddressBookStore(store);
|
|
@@ -162,15 +169,17 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
162
169
|
|
|
163
170
|
// Create job coordinator and register staged stores
|
|
164
171
|
const jobCoordinator = new JobCoordinator(store);
|
|
165
|
-
jobCoordinator.registerStores([
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
+
jobCoordinator.registerStores([
|
|
173
|
+
capsuleStore,
|
|
174
|
+
senderTaggingStore,
|
|
175
|
+
recipientTaggingStore,
|
|
176
|
+
privateEventStore,
|
|
177
|
+
noteStore,
|
|
178
|
+
]);
|
|
172
179
|
|
|
173
|
-
const
|
|
180
|
+
const archiver = new TXEArchiver(store);
|
|
181
|
+
const anchorBlockStore = new AnchorBlockStore(store);
|
|
182
|
+
const stateMachine = await TXEStateMachine.create(archiver, anchorBlockStore, contractStore, noteStore);
|
|
174
183
|
|
|
175
184
|
const nextBlockTimestamp = BigInt(Math.floor(new Date().getTime() / 1000));
|
|
176
185
|
const version = new Fr(await stateMachine.node.getVersion());
|
|
@@ -178,6 +187,9 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
178
187
|
|
|
179
188
|
const initialJobId = jobCoordinator.beginJob();
|
|
180
189
|
|
|
190
|
+
const logger = createLogger('txe:session');
|
|
191
|
+
const contractSyncService = new ContractSyncService(stateMachine.node, contractStore, noteStore, logger);
|
|
192
|
+
|
|
181
193
|
const topLevelOracleHandler = new TXEOracleTopLevelContext(
|
|
182
194
|
stateMachine,
|
|
183
195
|
contractStore,
|
|
@@ -190,16 +202,16 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
190
202
|
senderAddressBookStore,
|
|
191
203
|
capsuleStore,
|
|
192
204
|
privateEventStore,
|
|
193
|
-
initialJobId,
|
|
194
205
|
nextBlockTimestamp,
|
|
195
206
|
version,
|
|
196
207
|
chainId,
|
|
197
208
|
new Map(),
|
|
209
|
+
contractSyncService,
|
|
198
210
|
);
|
|
199
|
-
await topLevelOracleHandler.
|
|
211
|
+
await topLevelOracleHandler.advanceBlocksBy(1);
|
|
200
212
|
|
|
201
213
|
return new TXESession(
|
|
202
|
-
|
|
214
|
+
logger,
|
|
203
215
|
stateMachine,
|
|
204
216
|
topLevelOracleHandler,
|
|
205
217
|
contractStore,
|
|
@@ -217,6 +229,7 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
217
229
|
version,
|
|
218
230
|
chainId,
|
|
219
231
|
nextBlockTimestamp,
|
|
232
|
+
contractSyncService,
|
|
220
233
|
);
|
|
221
234
|
}
|
|
222
235
|
|
|
@@ -251,6 +264,17 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
251
264
|
}
|
|
252
265
|
}
|
|
253
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
|
+
|
|
254
278
|
async enterTopLevelState() {
|
|
255
279
|
switch (this.state.name) {
|
|
256
280
|
case 'PRIVATE': {
|
|
@@ -274,8 +298,7 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
274
298
|
}
|
|
275
299
|
|
|
276
300
|
// Commit all staged stores from the job that was just completed, then begin a new job
|
|
277
|
-
await this.
|
|
278
|
-
this.currentJobId = this.jobCoordinator.beginJob();
|
|
301
|
+
await this.cycleJob();
|
|
279
302
|
|
|
280
303
|
this.oracleHandler = new TXEOracleTopLevelContext(
|
|
281
304
|
this.stateMachine,
|
|
@@ -289,11 +312,11 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
289
312
|
this.senderAddressBookStore,
|
|
290
313
|
this.capsuleStore,
|
|
291
314
|
this.privateEventStore,
|
|
292
|
-
this.currentJobId,
|
|
293
315
|
this.nextBlockTimestamp,
|
|
294
316
|
this.version,
|
|
295
317
|
this.chainId,
|
|
296
318
|
this.authwits,
|
|
319
|
+
this.contractSyncService,
|
|
297
320
|
);
|
|
298
321
|
|
|
299
322
|
this.state = { name: 'TOP_LEVEL' };
|
|
@@ -306,16 +329,15 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
306
329
|
): Promise<PrivateContextInputs> {
|
|
307
330
|
this.exitTopLevelState();
|
|
308
331
|
|
|
309
|
-
await new NoteService(
|
|
310
|
-
this.noteStore,
|
|
311
|
-
this.stateMachine.node,
|
|
312
|
-
this.stateMachine.anchorBlockStore,
|
|
313
|
-
).syncNoteNullifiers(contractAddress);
|
|
314
|
-
|
|
315
332
|
// Private execution has two associated block numbers: the anchor block (i.e. the historical block that is used to
|
|
316
333
|
// build the proof), and the *next* block, i.e. the one we'll create once the execution ends, and which will contain
|
|
317
334
|
// a single transaction with the effects of what was done in the test.
|
|
318
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
|
+
'ALL_SCOPES',
|
|
340
|
+
);
|
|
319
341
|
const latestBlock = await this.stateMachine.node.getBlockHeader('latest');
|
|
320
342
|
|
|
321
343
|
const nextBlockGlobalVariables = makeGlobalVariables(undefined, {
|
|
@@ -331,30 +353,32 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
331
353
|
const taggingIndexCache = new ExecutionTaggingIndexCache();
|
|
332
354
|
|
|
333
355
|
const utilityExecutor = this.utilityExecutorForContractSync(anchorBlock);
|
|
334
|
-
this.oracleHandler = new PrivateExecutionOracle(
|
|
335
|
-
Fr.ZERO,
|
|
336
|
-
new TxContext(this.chainId, this.version, GasSettings.empty()),
|
|
337
|
-
new CallContext(AztecAddress.ZERO, contractAddress, FunctionSelector.empty(), false),
|
|
338
|
-
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!,
|
|
339
361
|
utilityExecutor,
|
|
340
|
-
[],
|
|
341
|
-
[],
|
|
342
|
-
new HashedValuesCache(),
|
|
362
|
+
authWitnesses: [],
|
|
363
|
+
capsules: [],
|
|
364
|
+
executionCache: new HashedValuesCache(),
|
|
343
365
|
noteCache,
|
|
344
366
|
taggingIndexCache,
|
|
345
|
-
this.contractStore,
|
|
346
|
-
this.noteStore,
|
|
347
|
-
this.keyStore,
|
|
348
|
-
this.addressStore,
|
|
349
|
-
this.stateMachine.node,
|
|
350
|
-
this.
|
|
351
|
-
this.
|
|
352
|
-
this.
|
|
353
|
-
this.
|
|
354
|
-
this.
|
|
355
|
-
this.
|
|
356
|
-
this.currentJobId,
|
|
357
|
-
|
|
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
|
+
capsuleStore: this.capsuleStore,
|
|
376
|
+
privateEventStore: this.privateEventStore,
|
|
377
|
+
contractSyncService: this.stateMachine.contractSyncService,
|
|
378
|
+
jobId: this.currentJobId,
|
|
379
|
+
scopes: 'ALL_SCOPES',
|
|
380
|
+
messageContextService: this.stateMachine.messageContextService,
|
|
381
|
+
});
|
|
358
382
|
|
|
359
383
|
// We store the note and tagging index caches fed into the PrivateExecutionOracle (along with some other auxiliary
|
|
360
384
|
// data) in order to refer to it later, mimicking the way this object is used by the ContractFunctionSimulator. The
|
|
@@ -394,6 +418,8 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
394
418
|
async enterUtilityState(contractAddress: AztecAddress = DEFAULT_ADDRESS) {
|
|
395
419
|
this.exitTopLevelState();
|
|
396
420
|
|
|
421
|
+
const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
422
|
+
|
|
397
423
|
// There is no automatic message discovery and contract-driven syncing process in inlined private or utility
|
|
398
424
|
// contexts, which means that known nullifiers are also not searched for, since it is during the tagging sync that
|
|
399
425
|
// we perform this. We therefore search for known nullifiers now, as otherwise notes that were nullified would not
|
|
@@ -402,28 +428,29 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
402
428
|
await new NoteService(
|
|
403
429
|
this.noteStore,
|
|
404
430
|
this.stateMachine.node,
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
431
|
+
anchorBlockHeader,
|
|
432
|
+
this.currentJobId,
|
|
433
|
+
).syncNoteNullifiers(contractAddress, 'ALL_SCOPES');
|
|
409
434
|
|
|
410
|
-
this.oracleHandler = new UtilityExecutionOracle(
|
|
435
|
+
this.oracleHandler = new UtilityExecutionOracle({
|
|
411
436
|
contractAddress,
|
|
412
|
-
[],
|
|
413
|
-
[],
|
|
437
|
+
authWitnesses: [],
|
|
438
|
+
capsules: [],
|
|
414
439
|
anchorBlockHeader,
|
|
415
|
-
this.contractStore,
|
|
416
|
-
this.noteStore,
|
|
417
|
-
this.keyStore,
|
|
418
|
-
this.addressStore,
|
|
419
|
-
this.stateMachine.node,
|
|
420
|
-
this.
|
|
421
|
-
this.
|
|
422
|
-
this.
|
|
423
|
-
this.
|
|
424
|
-
this.
|
|
425
|
-
this.
|
|
426
|
-
|
|
440
|
+
contractStore: this.contractStore,
|
|
441
|
+
noteStore: this.noteStore,
|
|
442
|
+
keyStore: this.keyStore,
|
|
443
|
+
addressStore: this.addressStore,
|
|
444
|
+
aztecNode: this.stateMachine.node,
|
|
445
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
446
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
447
|
+
capsuleStore: this.capsuleStore,
|
|
448
|
+
privateEventStore: this.privateEventStore,
|
|
449
|
+
messageContextService: this.stateMachine.messageContextService,
|
|
450
|
+
contractSyncService: this.contractSyncService,
|
|
451
|
+
jobId: this.currentJobId,
|
|
452
|
+
scopes: 'ALL_SCOPES',
|
|
453
|
+
});
|
|
427
454
|
|
|
428
455
|
this.state = { name: 'UTILITY' };
|
|
429
456
|
this.logger.debug(`Entered state ${this.state.name}`);
|
|
@@ -436,8 +463,8 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
436
463
|
|
|
437
464
|
// Note that while all public and private contexts do is build a single block that we then process when exiting
|
|
438
465
|
// those, the top level context performs a large number of actions not captured in the following 'close' call. Among
|
|
439
|
-
// others, it will create empty blocks (via `
|
|
440
|
-
// `
|
|
466
|
+
// others, it will create empty blocks (via `advanceBlocksBy` and `deploy`), create blocks with transactions via
|
|
467
|
+
// `privateCallNewFlow` and `publicCallNewFlow`, add accounts to PXE via `addAccount`, etc. This is a
|
|
441
468
|
// slight inconsistency in the working model of this class, but is not too bad.
|
|
442
469
|
// TODO: it's quite unfortunate that we need to capture the authwits created to later pass them again when the top
|
|
443
470
|
// level context is re-created. This is because authwits create a temporary utility context that'd otherwise reset
|
|
@@ -491,30 +518,32 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
491
518
|
}
|
|
492
519
|
|
|
493
520
|
private utilityExecutorForContractSync(anchorBlock: any) {
|
|
494
|
-
return async (call: FunctionCall) => {
|
|
521
|
+
return async (call: FunctionCall, scopes: AccessScopes) => {
|
|
495
522
|
const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
|
|
496
523
|
if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
|
|
497
524
|
throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
|
|
498
525
|
}
|
|
499
526
|
|
|
500
527
|
try {
|
|
501
|
-
const oracle = new UtilityExecutionOracle(
|
|
502
|
-
call.to,
|
|
503
|
-
[],
|
|
504
|
-
[],
|
|
505
|
-
anchorBlock!,
|
|
506
|
-
this.contractStore,
|
|
507
|
-
this.noteStore,
|
|
508
|
-
this.keyStore,
|
|
509
|
-
this.addressStore,
|
|
510
|
-
this.stateMachine.node,
|
|
511
|
-
this.
|
|
512
|
-
this.
|
|
513
|
-
this.
|
|
514
|
-
this.
|
|
515
|
-
this.
|
|
516
|
-
this.
|
|
517
|
-
|
|
528
|
+
const oracle = new UtilityExecutionOracle({
|
|
529
|
+
contractAddress: call.to,
|
|
530
|
+
authWitnesses: [],
|
|
531
|
+
capsules: [],
|
|
532
|
+
anchorBlockHeader: anchorBlock!,
|
|
533
|
+
contractStore: this.contractStore,
|
|
534
|
+
noteStore: this.noteStore,
|
|
535
|
+
keyStore: this.keyStore,
|
|
536
|
+
addressStore: this.addressStore,
|
|
537
|
+
aztecNode: this.stateMachine.node,
|
|
538
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
539
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
540
|
+
capsuleStore: this.capsuleStore,
|
|
541
|
+
privateEventStore: this.privateEventStore,
|
|
542
|
+
messageContextService: this.stateMachine.messageContextService,
|
|
543
|
+
contractSyncService: this.contractSyncService,
|
|
544
|
+
jobId: this.currentJobId,
|
|
545
|
+
scopes,
|
|
546
|
+
});
|
|
518
547
|
await new WASMSimulator()
|
|
519
548
|
.executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, new Oracle(oracle).toACIRCallback())
|
|
520
549
|
.catch((err: Error) => {
|
|
@@ -1,19 +1,11 @@
|
|
|
1
1
|
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
2
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
3
|
import type { ContractStore } from '@aztec/pxe/server';
|
|
4
|
-
import { type ContractArtifact, FunctionSelector
|
|
4
|
+
import { type ContractArtifact, FunctionSelector } from '@aztec/stdlib/abi';
|
|
5
5
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
6
|
-
import {
|
|
7
|
-
type ContractClassPublic,
|
|
8
|
-
type ContractDataSource,
|
|
9
|
-
type ContractInstanceWithAddress,
|
|
10
|
-
computePrivateFunctionsRoot,
|
|
11
|
-
computePublicBytecodeCommitment,
|
|
12
|
-
getContractClassPrivateFunctionFromArtifact,
|
|
13
|
-
} from '@aztec/stdlib/contract';
|
|
6
|
+
import type { ContractClassPublic, ContractDataSource, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
14
7
|
|
|
15
8
|
export class TXEPublicContractDataSource implements ContractDataSource {
|
|
16
|
-
#privateFunctionsRoot: Map<string, Buffer> = new Map();
|
|
17
9
|
constructor(
|
|
18
10
|
private blockNumber: BlockNumber,
|
|
19
11
|
private contractStore: ContractStore,
|
|
@@ -24,42 +16,22 @@ export class TXEPublicContractDataSource implements ContractDataSource {
|
|
|
24
16
|
}
|
|
25
17
|
|
|
26
18
|
async getContractClass(id: Fr): Promise<ContractClassPublic | undefined> {
|
|
27
|
-
const contractClass = await this.contractStore.
|
|
19
|
+
const contractClass = await this.contractStore.getContractClassWithPreimage(id);
|
|
28
20
|
if (!contractClass) {
|
|
29
21
|
return;
|
|
30
22
|
}
|
|
31
|
-
const artifact = await this.contractStore.getContractArtifact(id);
|
|
32
|
-
if (!artifact) {
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
let privateFunctionsRoot;
|
|
37
|
-
if (!this.#privateFunctionsRoot.has(id.toString())) {
|
|
38
|
-
const privateFunctions = await Promise.all(
|
|
39
|
-
artifact.functions
|
|
40
|
-
.filter(fn => fn.functionType === FunctionType.PRIVATE)
|
|
41
|
-
.map(fn => getContractClassPrivateFunctionFromArtifact(fn)),
|
|
42
|
-
);
|
|
43
|
-
privateFunctionsRoot = await computePrivateFunctionsRoot(privateFunctions);
|
|
44
|
-
this.#privateFunctionsRoot.set(id.toString(), privateFunctionsRoot.toBuffer());
|
|
45
|
-
} else {
|
|
46
|
-
privateFunctionsRoot = Fr.fromBuffer(this.#privateFunctionsRoot.get(id.toString())!);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
23
|
return {
|
|
50
|
-
id,
|
|
51
|
-
artifactHash: contractClass
|
|
52
|
-
packedBytecode: contractClass
|
|
53
|
-
privateFunctionsRoot,
|
|
54
|
-
version: contractClass
|
|
55
|
-
privateFunctions: [],
|
|
56
|
-
utilityFunctions: [],
|
|
24
|
+
id: contractClass.id,
|
|
25
|
+
artifactHash: contractClass.artifactHash,
|
|
26
|
+
packedBytecode: contractClass.packedBytecode,
|
|
27
|
+
privateFunctionsRoot: contractClass.privateFunctionsRoot,
|
|
28
|
+
version: contractClass.version,
|
|
57
29
|
};
|
|
58
30
|
}
|
|
59
31
|
|
|
60
32
|
async getBytecodeCommitment(id: Fr): Promise<Fr | undefined> {
|
|
61
|
-
const contractClass = await this.contractStore.
|
|
62
|
-
return contractClass
|
|
33
|
+
const contractClass = await this.contractStore.getContractClassWithPreimage(id);
|
|
34
|
+
return contractClass?.publicBytecodeCommitment;
|
|
63
35
|
}
|
|
64
36
|
|
|
65
37
|
async getContract(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
import { BlockNumber, CheckpointNumber, IndexWithinCheckpoint } from '@aztec/foundation/branded-types';
|
|
8
8
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
9
9
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
10
|
-
import { Body,
|
|
10
|
+
import { Body, L2Block } from '@aztec/stdlib/block';
|
|
11
11
|
import { AppendOnlyTreeSnapshot, MerkleTreeId, type MerkleTreeWriteOperations } from '@aztec/stdlib/trees';
|
|
12
12
|
import { BlockHeader, GlobalVariables, TxEffect } from '@aztec/stdlib/tx';
|
|
13
13
|
|
|
@@ -61,7 +61,7 @@ export async function makeTXEBlockHeader(
|
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
/**
|
|
64
|
-
* Creates an
|
|
64
|
+
* Creates an L2Block with proper archive chaining.
|
|
65
65
|
* This function:
|
|
66
66
|
* 1. Gets the current archive state as lastArchive for the header
|
|
67
67
|
* 2. Creates the block header
|
|
@@ -71,13 +71,13 @@ export async function makeTXEBlockHeader(
|
|
|
71
71
|
* @param worldTrees - The world trees to read/write from
|
|
72
72
|
* @param globalVariables - Global variables for the block
|
|
73
73
|
* @param txEffects - Transaction effects to include in the block
|
|
74
|
-
* @returns The created
|
|
74
|
+
* @returns The created L2Block with proper archive chaining
|
|
75
75
|
*/
|
|
76
76
|
export async function makeTXEBlock(
|
|
77
77
|
worldTrees: MerkleTreeWriteOperations,
|
|
78
78
|
globalVariables: GlobalVariables,
|
|
79
79
|
txEffects: TxEffect[],
|
|
80
|
-
): Promise<
|
|
80
|
+
): Promise<L2Block> {
|
|
81
81
|
const header = await makeTXEBlockHeader(worldTrees, globalVariables);
|
|
82
82
|
|
|
83
83
|
// Update the archive tree with this block's header hash
|
|
@@ -87,9 +87,11 @@ export async function makeTXEBlock(
|
|
|
87
87
|
const newArchiveInfo = await worldTrees.getTreeInfo(MerkleTreeId.ARCHIVE);
|
|
88
88
|
const newArchive = new AppendOnlyTreeSnapshot(new Fr(newArchiveInfo.root), Number(newArchiveInfo.size));
|
|
89
89
|
|
|
90
|
-
//
|
|
90
|
+
// L2Block requires checkpointNumber and indexWithinCheckpoint.
|
|
91
|
+
// TXE uses 1-block-per-checkpoint for testing simplicity, so we can use block number as checkpoint number.
|
|
92
|
+
// This uses the deprecated fromBlockNumber method intentionally for the TXE testing environment.
|
|
91
93
|
const checkpointNumber = CheckpointNumber.fromBlockNumber(globalVariables.blockNumber);
|
|
92
94
|
const indexWithinCheckpoint = IndexWithinCheckpoint(0);
|
|
93
95
|
|
|
94
|
-
return new
|
|
96
|
+
return new L2Block(newArchive, header, new Body(txEffects), checkpointNumber, indexWithinCheckpoint);
|
|
95
97
|
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { ContractArtifact } from '@aztec/aztec.js/abi';
|
|
2
|
-
import { Fr } from '@aztec/aztec.js/fields';
|
|
3
|
-
import { ContractStore } from '@aztec/pxe/server';
|
|
4
|
-
export type ContractArtifactWithHash = ContractArtifact & {
|
|
5
|
-
artifactHash: Fr;
|
|
6
|
-
};
|
|
7
|
-
export declare class TXEContractStore extends ContractStore {
|
|
8
|
-
#private;
|
|
9
|
-
addContractArtifact(id: Fr, artifact: ContractArtifact | ContractArtifactWithHash): Promise<void>;
|
|
10
|
-
getContractArtifact(contractClassId: Fr): Promise<ContractArtifact | ContractArtifactWithHash | undefined>;
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHhlX2NvbnRyYWN0X3N0b3JlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdXRpbC90eGVfY29udHJhY3Rfc3RvcmUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLEVBQUUsZ0JBQWdCLEVBQUUsTUFBTSxxQkFBcUIsQ0FBQztBQUM1RCxPQUFPLEVBQUUsRUFBRSxFQUFFLE1BQU0sd0JBQXdCLENBQUM7QUFDNUMsT0FBTyxFQUFFLGFBQWEsRUFBRSxNQUFNLG1CQUFtQixDQUFDO0FBRWxELE1BQU0sTUFBTSx3QkFBd0IsR0FBRyxnQkFBZ0IsR0FBRztJQUFFLFlBQVksRUFBRSxFQUFFLENBQUE7Q0FBRSxDQUFDO0FBTy9FLHFCQUFhLGdCQUFpQixTQUFRLGFBQWE7O0lBRzNCLG1CQUFtQixDQUN2QyxFQUFFLEVBQUUsRUFBRSxFQUNOLFFBQVEsRUFBRSxnQkFBZ0IsR0FBRyx3QkFBd0IsR0FDcEQsT0FBTyxDQUFDLElBQUksQ0FBQyxDQUtmO0lBRXFCLG1CQUFtQixDQUN2QyxlQUFlLEVBQUUsRUFBRSxHQUNsQixPQUFPLENBQUMsZ0JBQWdCLEdBQUcsd0JBQXdCLEdBQUcsU0FBUyxDQUFDLENBUWxFO0NBQ0YifQ==
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"txe_contract_store.d.ts","sourceRoot":"","sources":["../../src/util/txe_contract_store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,EAAE,EAAE,MAAM,wBAAwB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,MAAM,MAAM,wBAAwB,GAAG,gBAAgB,GAAG;IAAE,YAAY,EAAE,EAAE,CAAA;CAAE,CAAC;AAO/E,qBAAa,gBAAiB,SAAQ,aAAa;;IAG3B,mBAAmB,CACvC,EAAE,EAAE,EAAE,EACN,QAAQ,EAAE,gBAAgB,GAAG,wBAAwB,GACpD,OAAO,CAAC,IAAI,CAAC,CAKf;IAEqB,mBAAmB,CACvC,eAAe,EAAE,EAAE,GAClB,OAAO,CAAC,gBAAgB,GAAG,wBAAwB,GAAG,SAAS,CAAC,CAQlE;CACF"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Fr } from '@aztec/aztec.js/fields';
|
|
2
|
-
import { ContractStore } from '@aztec/pxe/server';
|
|
3
|
-
/*
|
|
4
|
-
* A contract store that stores contract artifacts with their hashes. Since
|
|
5
|
-
* TXE typically deploys the same contract again and again for multiple tests, caching
|
|
6
|
-
* the *very* expensive artifact hash computation improves testing speed significantly.
|
|
7
|
-
*/ export class TXEContractStore extends ContractStore {
|
|
8
|
-
#artifactHashes = new Map();
|
|
9
|
-
async addContractArtifact(id, artifact) {
|
|
10
|
-
if ('artifactHash' in artifact) {
|
|
11
|
-
this.#artifactHashes.set(id.toString(), artifact.artifactHash.toBuffer());
|
|
12
|
-
}
|
|
13
|
-
await super.addContractArtifact(id, artifact);
|
|
14
|
-
}
|
|
15
|
-
async getContractArtifact(contractClassId) {
|
|
16
|
-
const artifact = await super.getContractArtifact(contractClassId);
|
|
17
|
-
if (artifact && this.#artifactHashes.has(contractClassId.toString())) {
|
|
18
|
-
artifact.artifactHash = Fr.fromBuffer(this.#artifactHashes.get(contractClassId.toString()));
|
|
19
|
-
}
|
|
20
|
-
return artifact;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import type { ContractArtifact } from '@aztec/aztec.js/abi';
|
|
2
|
-
import { Fr } from '@aztec/aztec.js/fields';
|
|
3
|
-
import { ContractStore } from '@aztec/pxe/server';
|
|
4
|
-
|
|
5
|
-
export type ContractArtifactWithHash = ContractArtifact & { artifactHash: Fr };
|
|
6
|
-
|
|
7
|
-
/*
|
|
8
|
-
* A contract store that stores contract artifacts with their hashes. Since
|
|
9
|
-
* TXE typically deploys the same contract again and again for multiple tests, caching
|
|
10
|
-
* the *very* expensive artifact hash computation improves testing speed significantly.
|
|
11
|
-
*/
|
|
12
|
-
export class TXEContractStore extends ContractStore {
|
|
13
|
-
#artifactHashes: Map<string, Buffer> = new Map();
|
|
14
|
-
|
|
15
|
-
public override async addContractArtifact(
|
|
16
|
-
id: Fr,
|
|
17
|
-
artifact: ContractArtifact | ContractArtifactWithHash,
|
|
18
|
-
): Promise<void> {
|
|
19
|
-
if ('artifactHash' in artifact) {
|
|
20
|
-
this.#artifactHashes.set(id.toString(), artifact.artifactHash.toBuffer());
|
|
21
|
-
}
|
|
22
|
-
await super.addContractArtifact(id, artifact);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
public override async getContractArtifact(
|
|
26
|
-
contractClassId: Fr,
|
|
27
|
-
): Promise<ContractArtifact | ContractArtifactWithHash | undefined> {
|
|
28
|
-
const artifact = await super.getContractArtifact(contractClassId);
|
|
29
|
-
if (artifact && this.#artifactHashes.has(contractClassId.toString())) {
|
|
30
|
-
(artifact as ContractArtifactWithHash).artifactHash = Fr.fromBuffer(
|
|
31
|
-
this.#artifactHashes.get(contractClassId.toString())!,
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
return artifact;
|
|
35
|
-
}
|
|
36
|
-
}
|