@aztec/txe 0.0.1-commit.03f7ef2 → 0.0.1-commit.08c5969dc
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/oracle/interfaces.d.ts +3 -3
- 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 +17 -14
- package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_top_level_context.js +144 -67
- package/dest/rpc_translator.d.ts +19 -13
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +75 -50
- 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 +16 -12
- package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
- package/dest/state_machine/dummy_p2p_client.js +32 -20
- 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 +6 -6
- package/dest/state_machine/index.d.ts.map +1 -1
- package/dest/state_machine/index.js +36 -13
- 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 +17 -14
- package/dest/txe_session.d.ts.map +1 -1
- package/dest/txe_session.js +144 -49
- package/dest/util/encoding.d.ts +17 -17
- 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_contract_store.d.ts +12 -0
- package/dest/util/txe_contract_store.d.ts.map +1 -0
- package/dest/util/{txe_contract_data_provider.js → txe_contract_store.js} +3 -3
- package/dest/util/txe_public_contract_data_source.d.ts +4 -4
- package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
- package/dest/util/txe_public_contract_data_source.js +10 -10
- 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/constants.ts +3 -0
- package/src/index.ts +1 -1
- package/src/oracle/interfaces.ts +2 -2
- package/src/oracle/txe_oracle_public_context.ts +6 -8
- package/src/oracle/txe_oracle_top_level_context.ts +171 -108
- package/src/rpc_translator.ts +78 -52
- package/src/state_machine/archiver.ts +54 -220
- package/src/state_machine/dummy_p2p_client.ts +45 -26
- package/src/state_machine/global_variable_builder.ts +1 -1
- package/src/state_machine/index.ts +49 -12
- package/src/state_machine/mock_epoch_cache.ts +15 -11
- package/src/state_machine/synchronizer.ts +2 -2
- package/src/txe_session.ts +188 -109
- package/src/util/{txe_account_data_provider.ts → txe_account_store.ts} +1 -1
- package/src/util/{txe_contract_data_provider.ts → txe_contract_store.ts} +3 -3
- package/src/util/txe_public_contract_data_source.ts +9 -9
- package/src/utils/block_creation.ts +19 -16
- package/src/utils/tx_effect_creation.ts +3 -11
- 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/src/txe_session.ts
CHANGED
|
@@ -5,13 +5,16 @@ import { KeyStore } from '@aztec/key-store';
|
|
|
5
5
|
import { openTmpStore } from '@aztec/kv-store/lmdb-v2';
|
|
6
6
|
import type { ProtocolContract } from '@aztec/protocol-contracts';
|
|
7
7
|
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
AddressStore,
|
|
9
|
+
AnchorBlockStore,
|
|
10
|
+
CapsuleStore,
|
|
11
|
+
JobCoordinator,
|
|
11
12
|
NoteService,
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
NoteStore,
|
|
14
|
+
PrivateEventStore,
|
|
15
|
+
RecipientTaggingStore,
|
|
16
|
+
SenderAddressBookStore,
|
|
17
|
+
SenderTaggingStore,
|
|
15
18
|
} from '@aztec/pxe/server';
|
|
16
19
|
import {
|
|
17
20
|
ExecutionNoteCache,
|
|
@@ -19,10 +22,19 @@ import {
|
|
|
19
22
|
HashedValuesCache,
|
|
20
23
|
type IPrivateExecutionOracle,
|
|
21
24
|
type IUtilityExecutionOracle,
|
|
25
|
+
Oracle,
|
|
22
26
|
PrivateExecutionOracle,
|
|
23
27
|
UtilityExecutionOracle,
|
|
24
28
|
} from '@aztec/pxe/simulator';
|
|
25
|
-
import {
|
|
29
|
+
import {
|
|
30
|
+
ExecutionError,
|
|
31
|
+
WASMSimulator,
|
|
32
|
+
createSimulationError,
|
|
33
|
+
extractCallStack,
|
|
34
|
+
resolveAssertionMessageFromError,
|
|
35
|
+
toACVMWitness,
|
|
36
|
+
} from '@aztec/simulator/client';
|
|
37
|
+
import { FunctionCall, FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
|
|
26
38
|
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
27
39
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
28
40
|
import { GasSettings } from '@aztec/stdlib/gas';
|
|
@@ -33,14 +45,16 @@ import { CallContext, GlobalVariables, TxContext } from '@aztec/stdlib/tx';
|
|
|
33
45
|
|
|
34
46
|
import { z } from 'zod';
|
|
35
47
|
|
|
48
|
+
import { DEFAULT_ADDRESS } from './constants.js';
|
|
36
49
|
import type { IAvmExecutionOracle, ITxeExecutionOracle } from './oracle/interfaces.js';
|
|
37
50
|
import { TXEOraclePublicContext } from './oracle/txe_oracle_public_context.js';
|
|
38
51
|
import { TXEOracleTopLevelContext } from './oracle/txe_oracle_top_level_context.js';
|
|
39
52
|
import { RPCTranslator } from './rpc_translator.js';
|
|
53
|
+
import { TXEArchiver } from './state_machine/archiver.js';
|
|
40
54
|
import { TXEStateMachine } from './state_machine/index.js';
|
|
41
55
|
import type { ForeignCallArgs, ForeignCallResult } from './util/encoding.js';
|
|
42
|
-
import {
|
|
43
|
-
import {
|
|
56
|
+
import { TXEAccountStore } from './util/txe_account_store.js';
|
|
57
|
+
import { TXEContractStore } from './util/txe_contract_store.js';
|
|
44
58
|
import { getSingleTxBlockRequestHash, insertTxEffectIntoWorldTrees, makeTXEBlock } from './utils/block_creation.js';
|
|
45
59
|
import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
46
60
|
|
|
@@ -63,7 +77,6 @@ type SessionState =
|
|
|
63
77
|
| {
|
|
64
78
|
name: 'PRIVATE';
|
|
65
79
|
nextBlockGlobalVariables: GlobalVariables;
|
|
66
|
-
protocolNullifier: Fr;
|
|
67
80
|
noteCache: ExecutionNoteCache;
|
|
68
81
|
taggingIndexCache: ExecutionTaggingIndexCache;
|
|
69
82
|
}
|
|
@@ -102,8 +115,6 @@ export interface TXESessionStateHandler {
|
|
|
102
115
|
enterUtilityState(contractAddress?: AztecAddress): Promise<void>;
|
|
103
116
|
}
|
|
104
117
|
|
|
105
|
-
export const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
|
|
106
|
-
|
|
107
118
|
/**
|
|
108
119
|
* A `TXESession` corresponds to a Noir `#[test]` function, and handles all of its oracle calls, stores test-specific
|
|
109
120
|
* state, etc., independent of all other tests running in parallel.
|
|
@@ -120,15 +131,18 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
120
131
|
| IPrivateExecutionOracle
|
|
121
132
|
| IAvmExecutionOracle
|
|
122
133
|
| ITxeExecutionOracle,
|
|
123
|
-
private
|
|
124
|
-
private
|
|
134
|
+
private contractStore: TXEContractStore,
|
|
135
|
+
private noteStore: NoteStore,
|
|
125
136
|
private keyStore: KeyStore,
|
|
126
|
-
private
|
|
127
|
-
private
|
|
128
|
-
private
|
|
129
|
-
private
|
|
130
|
-
private
|
|
131
|
-
private
|
|
137
|
+
private addressStore: AddressStore,
|
|
138
|
+
private accountStore: TXEAccountStore,
|
|
139
|
+
private senderTaggingStore: SenderTaggingStore,
|
|
140
|
+
private recipientTaggingStore: RecipientTaggingStore,
|
|
141
|
+
private senderAddressBookStore: SenderAddressBookStore,
|
|
142
|
+
private capsuleStore: CapsuleStore,
|
|
143
|
+
private privateEventStore: PrivateEventStore,
|
|
144
|
+
private jobCoordinator: JobCoordinator,
|
|
145
|
+
private currentJobId: string,
|
|
132
146
|
private chainId: Fr,
|
|
133
147
|
private version: Fr,
|
|
134
148
|
private nextBlockTimestamp: bigint,
|
|
@@ -137,39 +151,56 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
137
151
|
static async init(protocolContracts: ProtocolContract[]) {
|
|
138
152
|
const store = await openTmpStore('txe-session');
|
|
139
153
|
|
|
140
|
-
const
|
|
141
|
-
const
|
|
142
|
-
const
|
|
143
|
-
const
|
|
144
|
-
const
|
|
145
|
-
const
|
|
146
|
-
const
|
|
154
|
+
const addressStore = new AddressStore(store);
|
|
155
|
+
const privateEventStore = new PrivateEventStore(store);
|
|
156
|
+
const contractStore = new TXEContractStore(store);
|
|
157
|
+
const noteStore = new NoteStore(store);
|
|
158
|
+
const senderTaggingStore = new SenderTaggingStore(store);
|
|
159
|
+
const recipientTaggingStore = new RecipientTaggingStore(store);
|
|
160
|
+
const senderAddressBookStore = new SenderAddressBookStore(store);
|
|
161
|
+
const capsuleStore = new CapsuleStore(store);
|
|
147
162
|
const keyStore = new KeyStore(store);
|
|
148
|
-
const
|
|
163
|
+
const accountStore = new TXEAccountStore(store);
|
|
164
|
+
|
|
165
|
+
// Create job coordinator and register staged stores
|
|
166
|
+
const jobCoordinator = new JobCoordinator(store);
|
|
167
|
+
jobCoordinator.registerStores([
|
|
168
|
+
capsuleStore,
|
|
169
|
+
senderTaggingStore,
|
|
170
|
+
recipientTaggingStore,
|
|
171
|
+
privateEventStore,
|
|
172
|
+
noteStore,
|
|
173
|
+
]);
|
|
149
174
|
|
|
150
175
|
// Register protocol contracts.
|
|
151
176
|
for (const { contractClass, instance, artifact } of protocolContracts) {
|
|
152
|
-
await
|
|
153
|
-
await
|
|
177
|
+
await contractStore.addContractArtifact(contractClass.id, artifact);
|
|
178
|
+
await contractStore.addContractInstance(instance);
|
|
154
179
|
}
|
|
155
180
|
|
|
156
|
-
const
|
|
181
|
+
const archiver = new TXEArchiver(store);
|
|
182
|
+
const anchorBlockStore = new AnchorBlockStore(store);
|
|
183
|
+
const stateMachine = await TXEStateMachine.create(archiver, anchorBlockStore, contractStore, noteStore);
|
|
157
184
|
|
|
158
185
|
const nextBlockTimestamp = BigInt(Math.floor(new Date().getTime() / 1000));
|
|
159
186
|
const version = new Fr(await stateMachine.node.getVersion());
|
|
160
187
|
const chainId = new Fr(await stateMachine.node.getChainId());
|
|
161
188
|
|
|
189
|
+
const initialJobId = jobCoordinator.beginJob();
|
|
190
|
+
|
|
162
191
|
const topLevelOracleHandler = new TXEOracleTopLevelContext(
|
|
163
192
|
stateMachine,
|
|
164
|
-
|
|
165
|
-
|
|
193
|
+
contractStore,
|
|
194
|
+
noteStore,
|
|
166
195
|
keyStore,
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
196
|
+
addressStore,
|
|
197
|
+
accountStore,
|
|
198
|
+
senderTaggingStore,
|
|
199
|
+
recipientTaggingStore,
|
|
200
|
+
senderAddressBookStore,
|
|
201
|
+
capsuleStore,
|
|
202
|
+
privateEventStore,
|
|
203
|
+
initialJobId,
|
|
173
204
|
nextBlockTimestamp,
|
|
174
205
|
version,
|
|
175
206
|
chainId,
|
|
@@ -181,15 +212,18 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
181
212
|
createLogger('txe:session'),
|
|
182
213
|
stateMachine,
|
|
183
214
|
topLevelOracleHandler,
|
|
184
|
-
|
|
185
|
-
|
|
215
|
+
contractStore,
|
|
216
|
+
noteStore,
|
|
186
217
|
keyStore,
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
218
|
+
addressStore,
|
|
219
|
+
accountStore,
|
|
220
|
+
senderTaggingStore,
|
|
221
|
+
recipientTaggingStore,
|
|
222
|
+
senderAddressBookStore,
|
|
223
|
+
capsuleStore,
|
|
224
|
+
privateEventStore,
|
|
225
|
+
jobCoordinator,
|
|
226
|
+
initialJobId,
|
|
193
227
|
version,
|
|
194
228
|
chainId,
|
|
195
229
|
nextBlockTimestamp,
|
|
@@ -249,17 +283,23 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
249
283
|
}
|
|
250
284
|
}
|
|
251
285
|
|
|
286
|
+
// Commit all staged stores from the job that was just completed, then begin a new job
|
|
287
|
+
await this.jobCoordinator.commitJob(this.currentJobId);
|
|
288
|
+
this.currentJobId = this.jobCoordinator.beginJob();
|
|
289
|
+
|
|
252
290
|
this.oracleHandler = new TXEOracleTopLevelContext(
|
|
253
291
|
this.stateMachine,
|
|
254
|
-
this.
|
|
255
|
-
this.
|
|
292
|
+
this.contractStore,
|
|
293
|
+
this.noteStore,
|
|
256
294
|
this.keyStore,
|
|
257
|
-
this.
|
|
258
|
-
this.
|
|
259
|
-
this.
|
|
260
|
-
this.
|
|
261
|
-
this.
|
|
262
|
-
this.
|
|
295
|
+
this.addressStore,
|
|
296
|
+
this.accountStore,
|
|
297
|
+
this.senderTaggingStore,
|
|
298
|
+
this.recipientTaggingStore,
|
|
299
|
+
this.senderAddressBookStore,
|
|
300
|
+
this.capsuleStore,
|
|
301
|
+
this.privateEventStore,
|
|
302
|
+
this.currentJobId,
|
|
263
303
|
this.nextBlockTimestamp,
|
|
264
304
|
this.version,
|
|
265
305
|
this.chainId,
|
|
@@ -276,21 +316,14 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
276
316
|
): Promise<PrivateContextInputs> {
|
|
277
317
|
this.exitTopLevelState();
|
|
278
318
|
|
|
279
|
-
// There is no automatic message discovery and contract-driven syncing process in inlined private or utility
|
|
280
|
-
// contexts, which means that known nullifiers are also not searched for, since it is during the tagging sync that
|
|
281
|
-
// we perform this. We therefore search for known nullifiers now, as otherwise notes that were nullified would not
|
|
282
|
-
// be removed from the database.
|
|
283
|
-
// TODO(#12553): make the synchronizer sync here instead and remove this
|
|
284
|
-
await new NoteService(
|
|
285
|
-
this.noteDataProvider,
|
|
286
|
-
this.stateMachine.node,
|
|
287
|
-
this.stateMachine.anchorBlockDataProvider,
|
|
288
|
-
).syncNoteNullifiers(contractAddress);
|
|
289
|
-
|
|
290
319
|
// Private execution has two associated block numbers: the anchor block (i.e. the historical block that is used to
|
|
291
320
|
// build the proof), and the *next* block, i.e. the one we'll create once the execution ends, and which will contain
|
|
292
321
|
// a single transaction with the effects of what was done in the test.
|
|
293
322
|
const anchorBlock = await this.stateMachine.node.getBlockHeader(anchorBlockNumber ?? 'latest');
|
|
323
|
+
|
|
324
|
+
await new NoteService(this.noteStore, this.stateMachine.node, anchorBlock!, this.currentJobId).syncNoteNullifiers(
|
|
325
|
+
contractAddress,
|
|
326
|
+
);
|
|
294
327
|
const latestBlock = await this.stateMachine.node.getBlockHeader('latest');
|
|
295
328
|
|
|
296
329
|
const nextBlockGlobalVariables = makeGlobalVariables(undefined, {
|
|
@@ -305,34 +338,38 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
305
338
|
const noteCache = new ExecutionNoteCache(protocolNullifier);
|
|
306
339
|
const taggingIndexCache = new ExecutionTaggingIndexCache();
|
|
307
340
|
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
new
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
341
|
+
const utilityExecutor = this.utilityExecutorForContractSync(anchorBlock);
|
|
342
|
+
this.oracleHandler = new PrivateExecutionOracle({
|
|
343
|
+
argsHash: Fr.ZERO,
|
|
344
|
+
txContext: new TxContext(this.chainId, this.version, GasSettings.empty()),
|
|
345
|
+
callContext: new CallContext(AztecAddress.ZERO, contractAddress, FunctionSelector.empty(), false),
|
|
346
|
+
anchorBlockHeader: anchorBlock!,
|
|
347
|
+
utilityExecutor,
|
|
348
|
+
authWitnesses: [],
|
|
349
|
+
capsules: [],
|
|
350
|
+
executionCache: new HashedValuesCache(),
|
|
316
351
|
noteCache,
|
|
317
352
|
taggingIndexCache,
|
|
318
|
-
this.
|
|
319
|
-
this.
|
|
320
|
-
this.keyStore,
|
|
321
|
-
this.
|
|
322
|
-
this.stateMachine.node,
|
|
323
|
-
this.
|
|
324
|
-
this.
|
|
325
|
-
this.
|
|
326
|
-
this.
|
|
327
|
-
this.
|
|
328
|
-
|
|
353
|
+
contractStore: this.contractStore,
|
|
354
|
+
noteStore: this.noteStore,
|
|
355
|
+
keyStore: this.keyStore,
|
|
356
|
+
addressStore: this.addressStore,
|
|
357
|
+
aztecNode: this.stateMachine.node,
|
|
358
|
+
senderTaggingStore: this.senderTaggingStore,
|
|
359
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
360
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
361
|
+
capsuleStore: this.capsuleStore,
|
|
362
|
+
privateEventStore: this.privateEventStore,
|
|
363
|
+
contractSyncService: this.stateMachine.contractSyncService,
|
|
364
|
+
jobId: this.currentJobId,
|
|
365
|
+
});
|
|
329
366
|
|
|
330
367
|
// We store the note and tagging index caches fed into the PrivateExecutionOracle (along with some other auxiliary
|
|
331
368
|
// data) in order to refer to it later, mimicking the way this object is used by the ContractFunctionSimulator. The
|
|
332
369
|
// difference resides in that the simulator has all information needed in order to run the simulation, while ours
|
|
333
370
|
// will be ongoing as the different oracles will be invoked from the Noir test, until eventually the private
|
|
334
371
|
// execution finishes.
|
|
335
|
-
this.state = { name: 'PRIVATE', nextBlockGlobalVariables,
|
|
372
|
+
this.state = { name: 'PRIVATE', nextBlockGlobalVariables, noteCache, taggingIndexCache };
|
|
336
373
|
this.logger.debug(`Entered state ${this.state.name}`);
|
|
337
374
|
|
|
338
375
|
return (this.oracleHandler as PrivateExecutionOracle).getPrivateContextInputs();
|
|
@@ -365,35 +402,36 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
365
402
|
async enterUtilityState(contractAddress: AztecAddress = DEFAULT_ADDRESS) {
|
|
366
403
|
this.exitTopLevelState();
|
|
367
404
|
|
|
405
|
+
const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
406
|
+
|
|
368
407
|
// There is no automatic message discovery and contract-driven syncing process in inlined private or utility
|
|
369
408
|
// contexts, which means that known nullifiers are also not searched for, since it is during the tagging sync that
|
|
370
409
|
// we perform this. We therefore search for known nullifiers now, as otherwise notes that were nullified would not
|
|
371
410
|
// be removed from the database.
|
|
372
411
|
// TODO(#12553): make the synchronizer sync here instead and remove this
|
|
373
412
|
await new NoteService(
|
|
374
|
-
this.
|
|
413
|
+
this.noteStore,
|
|
375
414
|
this.stateMachine.node,
|
|
376
|
-
|
|
415
|
+
anchorBlockHeader,
|
|
416
|
+
this.currentJobId,
|
|
377
417
|
).syncNoteNullifiers(contractAddress);
|
|
378
418
|
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
this.oracleHandler = new UtilityExecutionOracle(
|
|
419
|
+
this.oracleHandler = new UtilityExecutionOracle({
|
|
382
420
|
contractAddress,
|
|
383
|
-
[],
|
|
384
|
-
[],
|
|
421
|
+
authWitnesses: [],
|
|
422
|
+
capsules: [],
|
|
385
423
|
anchorBlockHeader,
|
|
386
|
-
this.
|
|
387
|
-
this.
|
|
388
|
-
this.keyStore,
|
|
389
|
-
this.
|
|
390
|
-
this.stateMachine.node,
|
|
391
|
-
this.
|
|
392
|
-
this.
|
|
393
|
-
this.
|
|
394
|
-
this.
|
|
395
|
-
this.
|
|
396
|
-
);
|
|
424
|
+
contractStore: this.contractStore,
|
|
425
|
+
noteStore: this.noteStore,
|
|
426
|
+
keyStore: this.keyStore,
|
|
427
|
+
addressStore: this.addressStore,
|
|
428
|
+
aztecNode: this.stateMachine.node,
|
|
429
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
430
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
431
|
+
capsuleStore: this.capsuleStore,
|
|
432
|
+
privateEventStore: this.privateEventStore,
|
|
433
|
+
jobId: this.currentJobId,
|
|
434
|
+
});
|
|
397
435
|
|
|
398
436
|
this.state = { name: 'UTILITY' };
|
|
399
437
|
this.logger.debug(`Entered state ${this.state.name}`);
|
|
@@ -428,11 +466,7 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
428
466
|
// We rely on the note cache to determine the effects of the transaction. This is incomplete as it doesn't private
|
|
429
467
|
// logs (other effects like enqueued public calls don't need to be considered since those are not allowed).
|
|
430
468
|
|
|
431
|
-
const txEffect = await makeTxEffect(
|
|
432
|
-
this.state.noteCache,
|
|
433
|
-
this.state.protocolNullifier,
|
|
434
|
-
this.state.nextBlockGlobalVariables.blockNumber,
|
|
435
|
-
);
|
|
469
|
+
const txEffect = await makeTxEffect(this.state.noteCache, this.state.nextBlockGlobalVariables.blockNumber);
|
|
436
470
|
|
|
437
471
|
// We build a block holding just this transaction
|
|
438
472
|
const forkedWorldTrees = await this.stateMachine.synchronizer.nativeWorldStateService.fork();
|
|
@@ -463,4 +497,49 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
463
497
|
throw new Error(`Expected to be in state 'UTILITY', but got '${this.state.name}' instead`);
|
|
464
498
|
}
|
|
465
499
|
}
|
|
500
|
+
|
|
501
|
+
private utilityExecutorForContractSync(anchorBlock: any) {
|
|
502
|
+
return async (call: FunctionCall, scopes: undefined | AztecAddress[]) => {
|
|
503
|
+
const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
|
|
504
|
+
if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
|
|
505
|
+
throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
try {
|
|
509
|
+
const oracle = new UtilityExecutionOracle({
|
|
510
|
+
contractAddress: call.to,
|
|
511
|
+
authWitnesses: [],
|
|
512
|
+
capsules: [],
|
|
513
|
+
anchorBlockHeader: anchorBlock!,
|
|
514
|
+
contractStore: this.contractStore,
|
|
515
|
+
noteStore: this.noteStore,
|
|
516
|
+
keyStore: this.keyStore,
|
|
517
|
+
addressStore: this.addressStore,
|
|
518
|
+
aztecNode: this.stateMachine.node,
|
|
519
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
520
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
521
|
+
capsuleStore: this.capsuleStore,
|
|
522
|
+
privateEventStore: this.privateEventStore,
|
|
523
|
+
jobId: this.currentJobId,
|
|
524
|
+
scopes,
|
|
525
|
+
});
|
|
526
|
+
await new WASMSimulator()
|
|
527
|
+
.executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, new Oracle(oracle).toACIRCallback())
|
|
528
|
+
.catch((err: Error) => {
|
|
529
|
+
err.message = resolveAssertionMessageFromError(err, entryPointArtifact);
|
|
530
|
+
throw new ExecutionError(
|
|
531
|
+
err.message,
|
|
532
|
+
{
|
|
533
|
+
contractAddress: call.to,
|
|
534
|
+
functionSelector: call.selector,
|
|
535
|
+
},
|
|
536
|
+
extractCallStack(err, entryPointArtifact.debug),
|
|
537
|
+
{ cause: err },
|
|
538
|
+
);
|
|
539
|
+
});
|
|
540
|
+
} catch (err) {
|
|
541
|
+
throw createSimulationError(err instanceof Error ? err : new Error('Unknown error contract data sync'));
|
|
542
|
+
}
|
|
543
|
+
};
|
|
544
|
+
}
|
|
466
545
|
}
|
|
@@ -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,15 +1,15 @@
|
|
|
1
1
|
import type { ContractArtifact } from '@aztec/aztec.js/abi';
|
|
2
2
|
import { Fr } from '@aztec/aztec.js/fields';
|
|
3
|
-
import {
|
|
3
|
+
import { ContractStore } from '@aztec/pxe/server';
|
|
4
4
|
|
|
5
5
|
export type ContractArtifactWithHash = ContractArtifact & { artifactHash: Fr };
|
|
6
6
|
|
|
7
7
|
/*
|
|
8
|
-
* A contract
|
|
8
|
+
* A contract store that stores contract artifacts with their hashes. Since
|
|
9
9
|
* TXE typically deploys the same contract again and again for multiple tests, caching
|
|
10
10
|
* the *very* expensive artifact hash computation improves testing speed significantly.
|
|
11
11
|
*/
|
|
12
|
-
export class
|
|
12
|
+
export class TXEContractStore extends ContractStore {
|
|
13
13
|
#artifactHashes: Map<string, Buffer> = new Map();
|
|
14
14
|
|
|
15
15
|
public override async addContractArtifact(
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
2
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
|
-
import type {
|
|
3
|
+
import type { ContractStore } from '@aztec/pxe/server';
|
|
4
4
|
import { type ContractArtifact, FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
|
|
5
5
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
6
6
|
import {
|
|
@@ -16,7 +16,7 @@ export class TXEPublicContractDataSource implements ContractDataSource {
|
|
|
16
16
|
#privateFunctionsRoot: Map<string, Buffer> = new Map();
|
|
17
17
|
constructor(
|
|
18
18
|
private blockNumber: BlockNumber,
|
|
19
|
-
private
|
|
19
|
+
private contractStore: ContractStore,
|
|
20
20
|
) {}
|
|
21
21
|
|
|
22
22
|
getBlockNumber(): Promise<BlockNumber> {
|
|
@@ -24,11 +24,11 @@ export class TXEPublicContractDataSource implements ContractDataSource {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
async getContractClass(id: Fr): Promise<ContractClassPublic | undefined> {
|
|
27
|
-
const contractClass = await this.
|
|
27
|
+
const contractClass = await this.contractStore.getContractClass(id);
|
|
28
28
|
if (!contractClass) {
|
|
29
29
|
return;
|
|
30
30
|
}
|
|
31
|
-
const artifact = await this.
|
|
31
|
+
const artifact = await this.contractStore.getContractArtifact(id);
|
|
32
32
|
if (!artifact) {
|
|
33
33
|
return;
|
|
34
34
|
}
|
|
@@ -58,12 +58,12 @@ export class TXEPublicContractDataSource implements ContractDataSource {
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
async getBytecodeCommitment(id: Fr): Promise<Fr | undefined> {
|
|
61
|
-
const contractClass = await this.
|
|
61
|
+
const contractClass = await this.contractStore.getContractClass(id);
|
|
62
62
|
return contractClass && computePublicBytecodeCommitment(contractClass.packedBytecode);
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
async getContract(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
|
|
66
|
-
const instance = await this.
|
|
66
|
+
const instance = await this.contractStore.getContractInstance(address);
|
|
67
67
|
return instance && { ...instance, address };
|
|
68
68
|
}
|
|
69
69
|
|
|
@@ -72,12 +72,12 @@ export class TXEPublicContractDataSource implements ContractDataSource {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
async getContractArtifact(address: AztecAddress): Promise<ContractArtifact | undefined> {
|
|
75
|
-
const instance = await this.
|
|
76
|
-
return instance && this.
|
|
75
|
+
const instance = await this.contractStore.getContractInstance(address);
|
|
76
|
+
return instance && this.contractStore.getContractArtifact(instance.currentContractClassId);
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
async getDebugFunctionName(address: AztecAddress, selector: FunctionSelector): Promise<string | undefined> {
|
|
80
|
-
return await this.
|
|
80
|
+
return await this.contractStore.getDebugFunctionName(address, selector);
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
registerContractFunctionSignatures(_signatures: []): Promise<void> {
|
|
@@ -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,10 +0,0 @@
|
|
|
1
|
-
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
2
|
-
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
3
|
-
import { CompleteAddress } from '@aztec/stdlib/contract';
|
|
4
|
-
export declare class TXEAccountDataProvider {
|
|
5
|
-
#private;
|
|
6
|
-
constructor(store: AztecAsyncKVStore);
|
|
7
|
-
getAccount(key: AztecAddress): Promise<CompleteAddress>;
|
|
8
|
-
setAccount(key: AztecAddress, value: CompleteAddress): Promise<void>;
|
|
9
|
-
}
|
|
10
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHhlX2FjY291bnRfZGF0YV9wcm92aWRlci5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3V0aWwvdHhlX2FjY291bnRfZGF0YV9wcm92aWRlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxpQkFBaUIsRUFBaUIsTUFBTSxpQkFBaUIsQ0FBQztBQUN4RSxPQUFPLEtBQUssRUFBRSxZQUFZLEVBQUUsTUFBTSw2QkFBNkIsQ0FBQztBQUNoRSxPQUFPLEVBQUUsZUFBZSxFQUFFLE1BQU0sd0JBQXdCLENBQUM7QUFFekQscUJBQWEsc0JBQXNCOztJQUdqQyxZQUFZLEtBQUssRUFBRSxpQkFBaUIsRUFFbkM7SUFFSyxVQUFVLENBQUMsR0FBRyxFQUFFLFlBQVksNEJBTWpDO0lBRUssVUFBVSxDQUFDLEdBQUcsRUFBRSxZQUFZLEVBQUUsS0FBSyxFQUFFLGVBQWUsaUJBRXpEO0NBQ0YifQ==
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"txe_account_data_provider.d.ts","sourceRoot":"","sources":["../../src/util/txe_account_data_provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAiB,MAAM,iBAAiB,CAAC;AACxE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,qBAAa,sBAAsB;;IAGjC,YAAY,KAAK,EAAE,iBAAiB,EAEnC;IAEK,UAAU,CAAC,GAAG,EAAE,YAAY,4BAMjC;IAEK,UAAU,CAAC,GAAG,EAAE,YAAY,EAAE,KAAK,EAAE,eAAe,iBAEzD;CACF"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { ContractArtifact } from '@aztec/aztec.js/abi';
|
|
2
|
-
import { Fr } from '@aztec/aztec.js/fields';
|
|
3
|
-
import { ContractDataProvider } from '@aztec/pxe/server';
|
|
4
|
-
export type ContractArtifactWithHash = ContractArtifact & {
|
|
5
|
-
artifactHash: Fr;
|
|
6
|
-
};
|
|
7
|
-
export declare class TXEContractDataProvider extends ContractDataProvider {
|
|
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHhlX2NvbnRyYWN0X2RhdGFfcHJvdmlkZXIuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy91dGlsL3R4ZV9jb250cmFjdF9kYXRhX3Byb3ZpZGVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxFQUFFLGdCQUFnQixFQUFFLE1BQU0scUJBQXFCLENBQUM7QUFDNUQsT0FBTyxFQUFFLEVBQUUsRUFBRSxNQUFNLHdCQUF3QixDQUFDO0FBQzVDLE9BQU8sRUFBRSxvQkFBb0IsRUFBRSxNQUFNLG1CQUFtQixDQUFDO0FBRXpELE1BQU0sTUFBTSx3QkFBd0IsR0FBRyxnQkFBZ0IsR0FBRztJQUFFLFlBQVksRUFBRSxFQUFFLENBQUE7Q0FBRSxDQUFDO0FBTy9FLHFCQUFhLHVCQUF3QixTQUFRLG9CQUFvQjs7SUFHekMsbUJBQW1CLENBQ3ZDLEVBQUUsRUFBRSxFQUFFLEVBQ04sUUFBUSxFQUFFLGdCQUFnQixHQUFHLHdCQUF3QixHQUNwRCxPQUFPLENBQUMsSUFBSSxDQUFDLENBS2Y7SUFFcUIsbUJBQW1CLENBQ3ZDLGVBQWUsRUFBRSxFQUFFLEdBQ2xCLE9BQU8sQ0FBQyxnQkFBZ0IsR0FBRyx3QkFBd0IsR0FBRyxTQUFTLENBQUMsQ0FRbEU7Q0FDRiJ9
|