@aztec/txe 0.0.1-commit.fcb71a6 → 0.0.1-commit.ff7989d6c
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 +82 -50
- package/dest/oracle/interfaces.d.ts +4 -4
- package/dest/oracle/interfaces.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.d.ts +3 -3
- package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.js +6 -6
- package/dest/oracle/txe_oracle_top_level_context.d.ts +6 -6
- package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_top_level_context.js +107 -40
- package/dest/rpc_translator.d.ts +21 -15
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +78 -53
- package/dest/state_machine/archiver.d.ts +20 -67
- package/dest/state_machine/archiver.d.ts.map +1 -1
- package/dest/state_machine/archiver.js +59 -178
- package/dest/state_machine/dummy_p2p_client.d.ts +19 -14
- package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
- package/dest/state_machine/dummy_p2p_client.js +38 -23
- package/dest/state_machine/global_variable_builder.d.ts +2 -2
- package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
- package/dest/state_machine/global_variable_builder.js +1 -1
- package/dest/state_machine/index.d.ts +5 -5
- package/dest/state_machine/index.d.ts.map +1 -1
- package/dest/state_machine/index.js +35 -12
- 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 +3 -3
- package/dest/state_machine/synchronizer.d.ts.map +1 -1
- package/dest/txe_session.d.ts +6 -6
- package/dest/txe_session.d.ts.map +1 -1
- package/dest/txe_session.js +92 -24
- package/dest/util/encoding.d.ts +17 -17
- 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 +5 -22
- package/dest/utils/block_creation.d.ts +4 -4
- package/dest/utils/block_creation.d.ts.map +1 -1
- package/dest/utils/block_creation.js +18 -5
- package/dest/utils/tx_effect_creation.d.ts +2 -3
- package/dest/utils/tx_effect_creation.d.ts.map +1 -1
- package/dest/utils/tx_effect_creation.js +3 -6
- package/package.json +16 -16
- package/src/index.ts +83 -49
- package/src/oracle/interfaces.ts +3 -3
- package/src/oracle/txe_oracle_public_context.ts +6 -8
- package/src/oracle/txe_oracle_top_level_context.ts +131 -91
- package/src/rpc_translator.ts +81 -55
- package/src/state_machine/archiver.ts +54 -220
- package/src/state_machine/dummy_p2p_client.ts +54 -31
- package/src/state_machine/global_variable_builder.ts +1 -1
- package/src/state_machine/index.ts +49 -11
- package/src/state_machine/mock_epoch_cache.ts +15 -11
- package/src/state_machine/synchronizer.ts +2 -2
- package/src/txe_session.ts +99 -80
- package/src/util/txe_public_contract_data_source.ts +10 -36
- package/src/utils/block_creation.ts +19 -16
- package/src/utils/tx_effect_creation.ts +3 -11
- 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
|
+
JobCoordinator,
|
|
10
13
|
NoteService,
|
|
11
14
|
NoteStore,
|
|
12
15
|
PrivateEventStore,
|
|
@@ -48,10 +51,10 @@ import type { IAvmExecutionOracle, ITxeExecutionOracle } from './oracle/interfac
|
|
|
48
51
|
import { TXEOraclePublicContext } from './oracle/txe_oracle_public_context.js';
|
|
49
52
|
import { TXEOracleTopLevelContext } from './oracle/txe_oracle_top_level_context.js';
|
|
50
53
|
import { RPCTranslator } from './rpc_translator.js';
|
|
54
|
+
import { TXEArchiver } from './state_machine/archiver.js';
|
|
51
55
|
import { TXEStateMachine } from './state_machine/index.js';
|
|
52
56
|
import type { ForeignCallArgs, ForeignCallResult } from './util/encoding.js';
|
|
53
57
|
import { TXEAccountStore } from './util/txe_account_store.js';
|
|
54
|
-
import { TXEContractStore } from './util/txe_contract_store.js';
|
|
55
58
|
import { getSingleTxBlockRequestHash, insertTxEffectIntoWorldTrees, makeTXEBlock } from './utils/block_creation.js';
|
|
56
59
|
import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
57
60
|
|
|
@@ -74,7 +77,6 @@ type SessionState =
|
|
|
74
77
|
| {
|
|
75
78
|
name: 'PRIVATE';
|
|
76
79
|
nextBlockGlobalVariables: GlobalVariables;
|
|
77
|
-
protocolNullifier: Fr;
|
|
78
80
|
noteCache: ExecutionNoteCache;
|
|
79
81
|
taggingIndexCache: ExecutionTaggingIndexCache;
|
|
80
82
|
}
|
|
@@ -129,7 +131,7 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
129
131
|
| IPrivateExecutionOracle
|
|
130
132
|
| IAvmExecutionOracle
|
|
131
133
|
| ITxeExecutionOracle,
|
|
132
|
-
private contractStore:
|
|
134
|
+
private contractStore: ContractStore,
|
|
133
135
|
private noteStore: NoteStore,
|
|
134
136
|
private keyStore: KeyStore,
|
|
135
137
|
private addressStore: AddressStore,
|
|
@@ -139,18 +141,19 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
139
141
|
private senderAddressBookStore: SenderAddressBookStore,
|
|
140
142
|
private capsuleStore: CapsuleStore,
|
|
141
143
|
private privateEventStore: PrivateEventStore,
|
|
144
|
+
private jobCoordinator: JobCoordinator,
|
|
145
|
+
private currentJobId: string,
|
|
142
146
|
private chainId: Fr,
|
|
143
147
|
private version: Fr,
|
|
144
148
|
private nextBlockTimestamp: bigint,
|
|
145
149
|
) {}
|
|
146
150
|
|
|
147
|
-
static async init(
|
|
151
|
+
static async init(contractStore: ContractStore) {
|
|
148
152
|
const store = await openTmpStore('txe-session');
|
|
149
153
|
|
|
150
154
|
const addressStore = new AddressStore(store);
|
|
151
155
|
const privateEventStore = new PrivateEventStore(store);
|
|
152
|
-
const
|
|
153
|
-
const noteStore = await NoteStore.create(store);
|
|
156
|
+
const noteStore = new NoteStore(store);
|
|
154
157
|
const senderTaggingStore = new SenderTaggingStore(store);
|
|
155
158
|
const recipientTaggingStore = new RecipientTaggingStore(store);
|
|
156
159
|
const senderAddressBookStore = new SenderAddressBookStore(store);
|
|
@@ -158,18 +161,26 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
158
161
|
const keyStore = new KeyStore(store);
|
|
159
162
|
const accountStore = new TXEAccountStore(store);
|
|
160
163
|
|
|
161
|
-
//
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
164
|
+
// Create job coordinator and register staged stores
|
|
165
|
+
const jobCoordinator = new JobCoordinator(store);
|
|
166
|
+
jobCoordinator.registerStores([
|
|
167
|
+
capsuleStore,
|
|
168
|
+
senderTaggingStore,
|
|
169
|
+
recipientTaggingStore,
|
|
170
|
+
privateEventStore,
|
|
171
|
+
noteStore,
|
|
172
|
+
]);
|
|
166
173
|
|
|
167
|
-
const
|
|
174
|
+
const archiver = new TXEArchiver(store);
|
|
175
|
+
const anchorBlockStore = new AnchorBlockStore(store);
|
|
176
|
+
const stateMachine = await TXEStateMachine.create(archiver, anchorBlockStore, contractStore, noteStore);
|
|
168
177
|
|
|
169
178
|
const nextBlockTimestamp = BigInt(Math.floor(new Date().getTime() / 1000));
|
|
170
179
|
const version = new Fr(await stateMachine.node.getVersion());
|
|
171
180
|
const chainId = new Fr(await stateMachine.node.getChainId());
|
|
172
181
|
|
|
182
|
+
const initialJobId = jobCoordinator.beginJob();
|
|
183
|
+
|
|
173
184
|
const topLevelOracleHandler = new TXEOracleTopLevelContext(
|
|
174
185
|
stateMachine,
|
|
175
186
|
contractStore,
|
|
@@ -182,6 +193,7 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
182
193
|
senderAddressBookStore,
|
|
183
194
|
capsuleStore,
|
|
184
195
|
privateEventStore,
|
|
196
|
+
initialJobId,
|
|
185
197
|
nextBlockTimestamp,
|
|
186
198
|
version,
|
|
187
199
|
chainId,
|
|
@@ -203,6 +215,8 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
203
215
|
senderAddressBookStore,
|
|
204
216
|
capsuleStore,
|
|
205
217
|
privateEventStore,
|
|
218
|
+
jobCoordinator,
|
|
219
|
+
initialJobId,
|
|
206
220
|
version,
|
|
207
221
|
chainId,
|
|
208
222
|
nextBlockTimestamp,
|
|
@@ -262,6 +276,10 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
262
276
|
}
|
|
263
277
|
}
|
|
264
278
|
|
|
279
|
+
// Commit all staged stores from the job that was just completed, then begin a new job
|
|
280
|
+
await this.jobCoordinator.commitJob(this.currentJobId);
|
|
281
|
+
this.currentJobId = this.jobCoordinator.beginJob();
|
|
282
|
+
|
|
265
283
|
this.oracleHandler = new TXEOracleTopLevelContext(
|
|
266
284
|
this.stateMachine,
|
|
267
285
|
this.contractStore,
|
|
@@ -274,6 +292,7 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
274
292
|
this.senderAddressBookStore,
|
|
275
293
|
this.capsuleStore,
|
|
276
294
|
this.privateEventStore,
|
|
295
|
+
this.currentJobId,
|
|
277
296
|
this.nextBlockTimestamp,
|
|
278
297
|
this.version,
|
|
279
298
|
this.chainId,
|
|
@@ -290,16 +309,15 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
290
309
|
): Promise<PrivateContextInputs> {
|
|
291
310
|
this.exitTopLevelState();
|
|
292
311
|
|
|
293
|
-
await new NoteService(
|
|
294
|
-
this.noteStore,
|
|
295
|
-
this.stateMachine.node,
|
|
296
|
-
this.stateMachine.anchorBlockStore,
|
|
297
|
-
).syncNoteNullifiers(contractAddress);
|
|
298
|
-
|
|
299
312
|
// Private execution has two associated block numbers: the anchor block (i.e. the historical block that is used to
|
|
300
313
|
// build the proof), and the *next* block, i.e. the one we'll create once the execution ends, and which will contain
|
|
301
314
|
// a single transaction with the effects of what was done in the test.
|
|
302
315
|
const anchorBlock = await this.stateMachine.node.getBlockHeader(anchorBlockNumber ?? 'latest');
|
|
316
|
+
|
|
317
|
+
await new NoteService(this.noteStore, this.stateMachine.node, anchorBlock!, this.currentJobId).syncNoteNullifiers(
|
|
318
|
+
contractAddress,
|
|
319
|
+
'ALL_SCOPES',
|
|
320
|
+
);
|
|
303
321
|
const latestBlock = await this.stateMachine.node.getBlockHeader('latest');
|
|
304
322
|
|
|
305
323
|
const nextBlockGlobalVariables = makeGlobalVariables(undefined, {
|
|
@@ -315,36 +333,38 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
315
333
|
const taggingIndexCache = new ExecutionTaggingIndexCache();
|
|
316
334
|
|
|
317
335
|
const utilityExecutor = this.utilityExecutorForContractSync(anchorBlock);
|
|
318
|
-
this.oracleHandler = new PrivateExecutionOracle(
|
|
319
|
-
Fr.ZERO,
|
|
320
|
-
new TxContext(this.chainId, this.version, GasSettings.empty()),
|
|
321
|
-
new CallContext(AztecAddress.ZERO, contractAddress, FunctionSelector.empty(), false),
|
|
322
|
-
anchorBlock!,
|
|
336
|
+
this.oracleHandler = new PrivateExecutionOracle({
|
|
337
|
+
argsHash: Fr.ZERO,
|
|
338
|
+
txContext: new TxContext(this.chainId, this.version, GasSettings.empty()),
|
|
339
|
+
callContext: new CallContext(AztecAddress.ZERO, contractAddress, FunctionSelector.empty(), false),
|
|
340
|
+
anchorBlockHeader: anchorBlock!,
|
|
323
341
|
utilityExecutor,
|
|
324
|
-
[],
|
|
325
|
-
[],
|
|
326
|
-
new HashedValuesCache(),
|
|
342
|
+
authWitnesses: [],
|
|
343
|
+
capsules: [],
|
|
344
|
+
executionCache: new HashedValuesCache(),
|
|
327
345
|
noteCache,
|
|
328
346
|
taggingIndexCache,
|
|
329
|
-
this.contractStore,
|
|
330
|
-
this.noteStore,
|
|
331
|
-
this.keyStore,
|
|
332
|
-
this.addressStore,
|
|
333
|
-
this.stateMachine.node,
|
|
334
|
-
this.
|
|
335
|
-
this.
|
|
336
|
-
this.
|
|
337
|
-
this.
|
|
338
|
-
this.
|
|
339
|
-
this.
|
|
340
|
-
|
|
347
|
+
contractStore: this.contractStore,
|
|
348
|
+
noteStore: this.noteStore,
|
|
349
|
+
keyStore: this.keyStore,
|
|
350
|
+
addressStore: this.addressStore,
|
|
351
|
+
aztecNode: this.stateMachine.node,
|
|
352
|
+
senderTaggingStore: this.senderTaggingStore,
|
|
353
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
354
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
355
|
+
capsuleStore: this.capsuleStore,
|
|
356
|
+
privateEventStore: this.privateEventStore,
|
|
357
|
+
contractSyncService: this.stateMachine.contractSyncService,
|
|
358
|
+
jobId: this.currentJobId,
|
|
359
|
+
scopes: 'ALL_SCOPES',
|
|
360
|
+
});
|
|
341
361
|
|
|
342
362
|
// We store the note and tagging index caches fed into the PrivateExecutionOracle (along with some other auxiliary
|
|
343
363
|
// data) in order to refer to it later, mimicking the way this object is used by the ContractFunctionSimulator. The
|
|
344
364
|
// difference resides in that the simulator has all information needed in order to run the simulation, while ours
|
|
345
365
|
// will be ongoing as the different oracles will be invoked from the Noir test, until eventually the private
|
|
346
366
|
// execution finishes.
|
|
347
|
-
this.state = { name: 'PRIVATE', nextBlockGlobalVariables,
|
|
367
|
+
this.state = { name: 'PRIVATE', nextBlockGlobalVariables, noteCache, taggingIndexCache };
|
|
348
368
|
this.logger.debug(`Entered state ${this.state.name}`);
|
|
349
369
|
|
|
350
370
|
return (this.oracleHandler as PrivateExecutionOracle).getPrivateContextInputs();
|
|
@@ -377,6 +397,8 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
377
397
|
async enterUtilityState(contractAddress: AztecAddress = DEFAULT_ADDRESS) {
|
|
378
398
|
this.exitTopLevelState();
|
|
379
399
|
|
|
400
|
+
const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
401
|
+
|
|
380
402
|
// There is no automatic message discovery and contract-driven syncing process in inlined private or utility
|
|
381
403
|
// contexts, which means that known nullifiers are also not searched for, since it is during the tagging sync that
|
|
382
404
|
// we perform this. We therefore search for known nullifiers now, as otherwise notes that were nullified would not
|
|
@@ -385,27 +407,27 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
385
407
|
await new NoteService(
|
|
386
408
|
this.noteStore,
|
|
387
409
|
this.stateMachine.node,
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
410
|
+
anchorBlockHeader,
|
|
411
|
+
this.currentJobId,
|
|
412
|
+
).syncNoteNullifiers(contractAddress, 'ALL_SCOPES');
|
|
392
413
|
|
|
393
|
-
this.oracleHandler = new UtilityExecutionOracle(
|
|
414
|
+
this.oracleHandler = new UtilityExecutionOracle({
|
|
394
415
|
contractAddress,
|
|
395
|
-
[],
|
|
396
|
-
[],
|
|
416
|
+
authWitnesses: [],
|
|
417
|
+
capsules: [],
|
|
397
418
|
anchorBlockHeader,
|
|
398
|
-
this.contractStore,
|
|
399
|
-
this.noteStore,
|
|
400
|
-
this.keyStore,
|
|
401
|
-
this.addressStore,
|
|
402
|
-
this.stateMachine.node,
|
|
403
|
-
this.
|
|
404
|
-
this.
|
|
405
|
-
this.
|
|
406
|
-
this.
|
|
407
|
-
this.
|
|
408
|
-
|
|
419
|
+
contractStore: this.contractStore,
|
|
420
|
+
noteStore: this.noteStore,
|
|
421
|
+
keyStore: this.keyStore,
|
|
422
|
+
addressStore: this.addressStore,
|
|
423
|
+
aztecNode: this.stateMachine.node,
|
|
424
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
425
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
426
|
+
capsuleStore: this.capsuleStore,
|
|
427
|
+
privateEventStore: this.privateEventStore,
|
|
428
|
+
jobId: this.currentJobId,
|
|
429
|
+
scopes: 'ALL_SCOPES',
|
|
430
|
+
});
|
|
409
431
|
|
|
410
432
|
this.state = { name: 'UTILITY' };
|
|
411
433
|
this.logger.debug(`Entered state ${this.state.name}`);
|
|
@@ -440,11 +462,7 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
440
462
|
// We rely on the note cache to determine the effects of the transaction. This is incomplete as it doesn't private
|
|
441
463
|
// logs (other effects like enqueued public calls don't need to be considered since those are not allowed).
|
|
442
464
|
|
|
443
|
-
const txEffect = await makeTxEffect(
|
|
444
|
-
this.state.noteCache,
|
|
445
|
-
this.state.protocolNullifier,
|
|
446
|
-
this.state.nextBlockGlobalVariables.blockNumber,
|
|
447
|
-
);
|
|
465
|
+
const txEffect = await makeTxEffect(this.state.noteCache, this.state.nextBlockGlobalVariables.blockNumber);
|
|
448
466
|
|
|
449
467
|
// We build a block holding just this transaction
|
|
450
468
|
const forkedWorldTrees = await this.stateMachine.synchronizer.nativeWorldStateService.fork();
|
|
@@ -477,29 +495,30 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
477
495
|
}
|
|
478
496
|
|
|
479
497
|
private utilityExecutorForContractSync(anchorBlock: any) {
|
|
480
|
-
return async (call: FunctionCall) => {
|
|
498
|
+
return async (call: FunctionCall, scopes: AccessScopes) => {
|
|
481
499
|
const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
|
|
482
500
|
if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
|
|
483
501
|
throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
|
|
484
502
|
}
|
|
485
503
|
|
|
486
504
|
try {
|
|
487
|
-
const oracle = new UtilityExecutionOracle(
|
|
488
|
-
call.to,
|
|
489
|
-
[],
|
|
490
|
-
[],
|
|
491
|
-
anchorBlock!,
|
|
492
|
-
this.contractStore,
|
|
493
|
-
this.noteStore,
|
|
494
|
-
this.keyStore,
|
|
495
|
-
this.addressStore,
|
|
496
|
-
this.stateMachine.node,
|
|
497
|
-
this.
|
|
498
|
-
this.
|
|
499
|
-
this.
|
|
500
|
-
this.
|
|
501
|
-
this.
|
|
502
|
-
|
|
505
|
+
const oracle = new UtilityExecutionOracle({
|
|
506
|
+
contractAddress: call.to,
|
|
507
|
+
authWitnesses: [],
|
|
508
|
+
capsules: [],
|
|
509
|
+
anchorBlockHeader: anchorBlock!,
|
|
510
|
+
contractStore: this.contractStore,
|
|
511
|
+
noteStore: this.noteStore,
|
|
512
|
+
keyStore: this.keyStore,
|
|
513
|
+
addressStore: this.addressStore,
|
|
514
|
+
aztecNode: this.stateMachine.node,
|
|
515
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
516
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
517
|
+
capsuleStore: this.capsuleStore,
|
|
518
|
+
privateEventStore: this.privateEventStore,
|
|
519
|
+
jobId: this.currentJobId,
|
|
520
|
+
scopes,
|
|
521
|
+
});
|
|
503
522
|
await new WASMSimulator()
|
|
504
523
|
.executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, new Oracle(oracle).toACIRCallback())
|
|
505
524
|
.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,24 @@ 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
|
|
24
|
+
id: contractClass.id,
|
|
25
|
+
artifactHash: contractClass.artifactHash,
|
|
26
|
+
packedBytecode: contractClass.packedBytecode,
|
|
27
|
+
privateFunctionsRoot: contractClass.privateFunctionsRoot,
|
|
28
|
+
version: contractClass.version,
|
|
55
29
|
privateFunctions: [],
|
|
56
30
|
utilityFunctions: [],
|
|
57
31
|
};
|
|
58
32
|
}
|
|
59
33
|
|
|
60
34
|
async getBytecodeCommitment(id: Fr): Promise<Fr | undefined> {
|
|
61
|
-
const contractClass = await this.contractStore.
|
|
62
|
-
return contractClass
|
|
35
|
+
const contractClass = await this.contractStore.getContractClassWithPreimage(id);
|
|
36
|
+
return contractClass?.publicBytecodeCommitment;
|
|
63
37
|
}
|
|
64
38
|
|
|
65
39
|
async getContract(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
|
|
@@ -4,13 +4,12 @@ import {
|
|
|
4
4
|
NULLIFIER_SUBTREE_HEIGHT,
|
|
5
5
|
NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP,
|
|
6
6
|
} from '@aztec/constants';
|
|
7
|
-
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
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, L2Block
|
|
11
|
-
import { makeContentCommitment } from '@aztec/stdlib/testing';
|
|
10
|
+
import { Body, L2Block } from '@aztec/stdlib/block';
|
|
12
11
|
import { AppendOnlyTreeSnapshot, MerkleTreeId, type MerkleTreeWriteOperations } from '@aztec/stdlib/trees';
|
|
13
|
-
import { GlobalVariables, TxEffect } from '@aztec/stdlib/tx';
|
|
12
|
+
import { BlockHeader, GlobalVariables, TxEffect } from '@aztec/stdlib/tx';
|
|
14
13
|
|
|
15
14
|
/**
|
|
16
15
|
* Returns a transaction request hash that is valid for transactions that are the only ones in a block.
|
|
@@ -47,20 +46,18 @@ export async function insertTxEffectIntoWorldTrees(
|
|
|
47
46
|
export async function makeTXEBlockHeader(
|
|
48
47
|
worldTrees: MerkleTreeWriteOperations,
|
|
49
48
|
globalVariables: GlobalVariables,
|
|
50
|
-
): Promise<
|
|
49
|
+
): Promise<BlockHeader> {
|
|
51
50
|
const stateReference = await worldTrees.getStateReference();
|
|
52
51
|
const archiveInfo = await worldTrees.getTreeInfo(MerkleTreeId.ARCHIVE);
|
|
53
52
|
|
|
54
|
-
return
|
|
55
|
-
new AppendOnlyTreeSnapshot(new Fr(archiveInfo.root), Number(archiveInfo.size)),
|
|
56
|
-
|
|
57
|
-
stateReference,
|
|
53
|
+
return BlockHeader.from({
|
|
54
|
+
lastArchive: new AppendOnlyTreeSnapshot(new Fr(archiveInfo.root), Number(archiveInfo.size)),
|
|
55
|
+
spongeBlobHash: Fr.ZERO,
|
|
56
|
+
state: stateReference,
|
|
58
57
|
globalVariables,
|
|
59
|
-
Fr.ZERO,
|
|
60
|
-
Fr.ZERO,
|
|
61
|
-
|
|
62
|
-
Fr.ZERO,
|
|
63
|
-
);
|
|
58
|
+
totalFees: Fr.ZERO,
|
|
59
|
+
totalManaUsed: Fr.ZERO,
|
|
60
|
+
});
|
|
64
61
|
}
|
|
65
62
|
|
|
66
63
|
/**
|
|
@@ -84,11 +81,17 @@ export async function makeTXEBlock(
|
|
|
84
81
|
const header = await makeTXEBlockHeader(worldTrees, globalVariables);
|
|
85
82
|
|
|
86
83
|
// Update the archive tree with this block's header hash
|
|
87
|
-
await worldTrees.updateArchive(header
|
|
84
|
+
await worldTrees.updateArchive(header);
|
|
88
85
|
|
|
89
86
|
// Get the new archive state after updating
|
|
90
87
|
const newArchiveInfo = await worldTrees.getTreeInfo(MerkleTreeId.ARCHIVE);
|
|
91
88
|
const newArchive = new AppendOnlyTreeSnapshot(new Fr(newArchiveInfo.root), Number(newArchiveInfo.size));
|
|
92
89
|
|
|
93
|
-
|
|
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.
|
|
93
|
+
const checkpointNumber = CheckpointNumber.fromBlockNumber(globalVariables.blockNumber);
|
|
94
|
+
const indexWithinCheckpoint = IndexWithinCheckpoint(0);
|
|
95
|
+
|
|
96
|
+
return new L2Block(newArchive, header, new Body(txEffects), checkpointNumber, indexWithinCheckpoint);
|
|
94
97
|
}
|
|
@@ -4,16 +4,12 @@ import type { ExecutionNoteCache } from '@aztec/pxe/simulator';
|
|
|
4
4
|
import { computeNoteHashNonce, computeUniqueNoteHash, siloNoteHash } from '@aztec/stdlib/hash';
|
|
5
5
|
import { TxEffect, TxHash } from '@aztec/stdlib/tx';
|
|
6
6
|
|
|
7
|
-
export async function makeTxEffect(
|
|
8
|
-
noteCache: ExecutionNoteCache,
|
|
9
|
-
protocolNullifier: Fr,
|
|
10
|
-
txBlockNumber: BlockNumber,
|
|
11
|
-
): Promise<TxEffect> {
|
|
7
|
+
export async function makeTxEffect(noteCache: ExecutionNoteCache, txBlockNumber: BlockNumber): Promise<TxEffect> {
|
|
12
8
|
const txEffect = TxEffect.empty();
|
|
13
9
|
|
|
14
|
-
|
|
15
|
-
const nonceGenerator = usedProtocolNullifierForNonces ? protocolNullifier : noteCache.getAllNullifiers()[0];
|
|
10
|
+
noteCache.finish();
|
|
16
11
|
|
|
12
|
+
const nonceGenerator = noteCache.getNonceGenerator();
|
|
17
13
|
txEffect.noteHashes = await Promise.all(
|
|
18
14
|
noteCache
|
|
19
15
|
.getAllNotes()
|
|
@@ -28,10 +24,6 @@ export async function makeTxEffect(
|
|
|
28
24
|
// Nullifiers are already siloed
|
|
29
25
|
txEffect.nullifiers = noteCache.getAllNullifiers();
|
|
30
26
|
|
|
31
|
-
if (usedProtocolNullifierForNonces) {
|
|
32
|
-
txEffect.nullifiers.unshift(protocolNullifier);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
27
|
txEffect.txHash = new TxHash(new Fr(txBlockNumber));
|
|
36
28
|
|
|
37
29
|
return txEffect;
|
|
@@ -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
|
-
}
|