@aztec/txe 0.0.1-commit.24de95ac → 0.0.1-commit.2e2504e2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/bin/index.d.ts +1 -1
- package/dest/constants.d.ts +3 -0
- package/dest/constants.d.ts.map +1 -0
- package/dest/constants.js +2 -0
- package/dest/index.d.ts +1 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +3 -2
- package/dest/oracle/interfaces.d.ts +11 -8
- package/dest/oracle/interfaces.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.d.ts +7 -7
- package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.js +10 -12
- package/dest/oracle/txe_oracle_top_level_context.d.ts +22 -12
- package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_top_level_context.js +128 -79
- package/dest/rpc_translator.d.ts +32 -17
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +134 -60
- package/dest/state_machine/archiver.d.ts +21 -51
- package/dest/state_machine/archiver.d.ts.map +1 -1
- package/dest/state_machine/archiver.js +63 -94
- package/dest/state_machine/dummy_p2p_client.d.ts +9 -6
- package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
- package/dest/state_machine/dummy_p2p_client.js +16 -8
- package/dest/state_machine/global_variable_builder.d.ts +6 -4
- package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
- package/dest/state_machine/global_variable_builder.js +13 -1
- package/dest/state_machine/index.d.ts +7 -7
- package/dest/state_machine/index.d.ts.map +1 -1
- package/dest/state_machine/index.js +39 -22
- package/dest/state_machine/mock_epoch_cache.d.ts +12 -10
- package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
- package/dest/state_machine/mock_epoch_cache.js +17 -13
- package/dest/state_machine/synchronizer.d.ts +3 -2
- package/dest/state_machine/synchronizer.d.ts.map +1 -1
- package/dest/state_machine/synchronizer.js +5 -4
- package/dest/txe_session.d.ts +21 -13
- package/dest/txe_session.d.ts.map +1 -1
- package/dest/txe_session.js +101 -49
- package/dest/util/encoding.d.ts +615 -16
- package/dest/util/encoding.d.ts.map +1 -1
- package/dest/util/encoding.js +1 -1
- package/dest/util/expected_failure_error.d.ts +1 -1
- package/dest/util/expected_failure_error.d.ts.map +1 -1
- package/dest/util/txe_account_store.d.ts +10 -0
- package/dest/util/txe_account_store.d.ts.map +1 -0
- package/dest/util/{txe_account_data_provider.js → txe_account_store.js} +1 -1
- package/dest/util/txe_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 +7 -6
- package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
- package/dest/util/txe_public_contract_data_source.js +11 -11
- package/dest/utils/block_creation.d.ts +21 -6
- package/dest/utils/block_creation.d.ts.map +1 -1
- package/dest/utils/block_creation.js +38 -4
- package/dest/utils/tx_effect_creation.d.ts +3 -3
- package/dest/utils/tx_effect_creation.d.ts.map +1 -1
- package/dest/utils/tx_effect_creation.js +4 -7
- package/package.json +18 -17
- package/src/constants.ts +3 -0
- package/src/index.ts +15 -12
- package/src/oracle/interfaces.ts +10 -7
- package/src/oracle/txe_oracle_public_context.ts +12 -19
- package/src/oracle/txe_oracle_top_level_context.ts +205 -107
- package/src/rpc_translator.ts +159 -63
- package/src/state_machine/archiver.ts +63 -117
- package/src/state_machine/dummy_p2p_client.ts +22 -10
- package/src/state_machine/global_variable_builder.ts +22 -4
- package/src/state_machine/index.ts +59 -21
- package/src/state_machine/mock_epoch_cache.ts +20 -20
- package/src/state_machine/synchronizer.ts +6 -5
- package/src/txe_session.ts +197 -85
- package/src/util/encoding.ts +1 -1
- package/src/util/{txe_account_data_provider.ts → txe_account_store.ts} +1 -1
- package/src/util/{txe_contract_data_provider.ts → txe_contract_store.ts} +3 -3
- package/src/util/txe_public_contract_data_source.ts +13 -12
- package/src/utils/block_creation.ts +49 -14
- package/src/utils/tx_effect_creation.ts +5 -12
- package/dest/util/txe_account_data_provider.d.ts +0 -10
- package/dest/util/txe_account_data_provider.d.ts.map +0 -1
- package/dest/util/txe_contract_data_provider.d.ts +0 -12
- package/dest/util/txe_contract_data_provider.d.ts.map +0 -1
package/src/txe_session.ts
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
3
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
3
4
|
import { KeyStore } from '@aztec/key-store';
|
|
4
5
|
import { openTmpStore } from '@aztec/kv-store/lmdb-v2';
|
|
5
6
|
import type { ProtocolContract } from '@aztec/protocol-contracts';
|
|
6
7
|
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
AddressStore,
|
|
9
|
+
AnchorBlockStore,
|
|
10
|
+
CapsuleStore,
|
|
11
|
+
JobCoordinator,
|
|
12
|
+
NoteService,
|
|
13
|
+
NoteStore,
|
|
14
|
+
PrivateEventStore,
|
|
15
|
+
RecipientTaggingStore,
|
|
16
|
+
SenderAddressBookStore,
|
|
17
|
+
SenderTaggingStore,
|
|
13
18
|
} from '@aztec/pxe/server';
|
|
14
19
|
import {
|
|
15
20
|
ExecutionNoteCache,
|
|
@@ -17,34 +22,40 @@ import {
|
|
|
17
22
|
HashedValuesCache,
|
|
18
23
|
type IPrivateExecutionOracle,
|
|
19
24
|
type IUtilityExecutionOracle,
|
|
25
|
+
Oracle,
|
|
20
26
|
PrivateExecutionOracle,
|
|
21
27
|
UtilityExecutionOracle,
|
|
22
28
|
} from '@aztec/pxe/simulator';
|
|
23
|
-
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';
|
|
24
38
|
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
25
39
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
26
|
-
import { Body, L2Block } from '@aztec/stdlib/block';
|
|
27
40
|
import { GasSettings } from '@aztec/stdlib/gas';
|
|
41
|
+
import { computeProtocolNullifier } from '@aztec/stdlib/hash';
|
|
28
42
|
import { PrivateContextInputs } from '@aztec/stdlib/kernel';
|
|
29
|
-
import {
|
|
43
|
+
import { makeGlobalVariables } from '@aztec/stdlib/testing';
|
|
30
44
|
import { CallContext, GlobalVariables, TxContext } from '@aztec/stdlib/tx';
|
|
31
|
-
import type { UInt32 } from '@aztec/stdlib/types';
|
|
32
45
|
|
|
33
46
|
import { z } from 'zod';
|
|
34
47
|
|
|
48
|
+
import { DEFAULT_ADDRESS } from './constants.js';
|
|
35
49
|
import type { IAvmExecutionOracle, ITxeExecutionOracle } from './oracle/interfaces.js';
|
|
36
50
|
import { TXEOraclePublicContext } from './oracle/txe_oracle_public_context.js';
|
|
37
51
|
import { TXEOracleTopLevelContext } from './oracle/txe_oracle_top_level_context.js';
|
|
38
52
|
import { RPCTranslator } from './rpc_translator.js';
|
|
53
|
+
import { TXEArchiver } from './state_machine/archiver.js';
|
|
39
54
|
import { TXEStateMachine } from './state_machine/index.js';
|
|
40
55
|
import type { ForeignCallArgs, ForeignCallResult } from './util/encoding.js';
|
|
41
|
-
import {
|
|
42
|
-
import {
|
|
43
|
-
import {
|
|
44
|
-
getSingleTxBlockRequestHash,
|
|
45
|
-
insertTxEffectIntoWorldTrees,
|
|
46
|
-
makeTXEBlockHeader,
|
|
47
|
-
} from './utils/block_creation.js';
|
|
56
|
+
import { TXEAccountStore } from './util/txe_account_store.js';
|
|
57
|
+
import { TXEContractStore } from './util/txe_contract_store.js';
|
|
58
|
+
import { getSingleTxBlockRequestHash, insertTxEffectIntoWorldTrees, makeTXEBlock } from './utils/block_creation.js';
|
|
48
59
|
import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
49
60
|
|
|
50
61
|
/**
|
|
@@ -66,7 +77,6 @@ type SessionState =
|
|
|
66
77
|
| {
|
|
67
78
|
name: 'PRIVATE';
|
|
68
79
|
nextBlockGlobalVariables: GlobalVariables;
|
|
69
|
-
txRequestHash: Fr;
|
|
70
80
|
noteCache: ExecutionNoteCache;
|
|
71
81
|
taggingIndexCache: ExecutionTaggingIndexCache;
|
|
72
82
|
}
|
|
@@ -101,12 +111,10 @@ export type TXEOracleFunctionName = Exclude<
|
|
|
101
111
|
export interface TXESessionStateHandler {
|
|
102
112
|
enterTopLevelState(): Promise<void>;
|
|
103
113
|
enterPublicState(contractAddress?: AztecAddress): Promise<void>;
|
|
104
|
-
enterPrivateState(contractAddress?: AztecAddress, anchorBlockNumber?:
|
|
114
|
+
enterPrivateState(contractAddress?: AztecAddress, anchorBlockNumber?: BlockNumber): Promise<PrivateContextInputs>;
|
|
105
115
|
enterUtilityState(contractAddress?: AztecAddress): Promise<void>;
|
|
106
116
|
}
|
|
107
117
|
|
|
108
|
-
const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
|
|
109
|
-
|
|
110
118
|
/**
|
|
111
119
|
* A `TXESession` corresponds to a Noir `#[test]` function, and handles all of its oracle calls, stores test-specific
|
|
112
120
|
* state, etc., independent of all other tests running in parallel.
|
|
@@ -123,59 +131,76 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
123
131
|
| IPrivateExecutionOracle
|
|
124
132
|
| IAvmExecutionOracle
|
|
125
133
|
| ITxeExecutionOracle,
|
|
126
|
-
private
|
|
134
|
+
private contractStore: TXEContractStore,
|
|
135
|
+
private noteStore: NoteStore,
|
|
127
136
|
private keyStore: KeyStore,
|
|
128
|
-
private
|
|
129
|
-
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,
|
|
130
146
|
private chainId: Fr,
|
|
131
147
|
private version: Fr,
|
|
132
148
|
private nextBlockTimestamp: bigint,
|
|
133
|
-
private pxeOracleInterface: PXEOracleInterface,
|
|
134
149
|
) {}
|
|
135
150
|
|
|
136
151
|
static async init(protocolContracts: ProtocolContract[]) {
|
|
137
152
|
const store = await openTmpStore('txe-session');
|
|
138
153
|
|
|
139
|
-
const
|
|
140
|
-
const
|
|
141
|
-
const
|
|
142
|
-
const
|
|
143
|
-
const
|
|
144
|
-
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);
|
|
145
162
|
const keyStore = new KeyStore(store);
|
|
146
|
-
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
|
+
]);
|
|
147
174
|
|
|
148
175
|
// Register protocol contracts.
|
|
149
176
|
for (const { contractClass, instance, artifact } of protocolContracts) {
|
|
150
|
-
await
|
|
151
|
-
await
|
|
177
|
+
await contractStore.addContractArtifact(contractClass.id, artifact);
|
|
178
|
+
await contractStore.addContractInstance(instance);
|
|
152
179
|
}
|
|
153
180
|
|
|
154
|
-
const
|
|
181
|
+
const archiver = new TXEArchiver(store);
|
|
182
|
+
const anchorBlockStore = new AnchorBlockStore(store);
|
|
183
|
+
const stateMachine = await TXEStateMachine.create(archiver, anchorBlockStore, contractStore, noteStore);
|
|
155
184
|
|
|
156
185
|
const nextBlockTimestamp = BigInt(Math.floor(new Date().getTime() / 1000));
|
|
157
186
|
const version = new Fr(await stateMachine.node.getVersion());
|
|
158
187
|
const chainId = new Fr(await stateMachine.node.getChainId());
|
|
159
188
|
|
|
160
|
-
const
|
|
161
|
-
stateMachine.node,
|
|
162
|
-
keyStore,
|
|
163
|
-
contractDataProvider,
|
|
164
|
-
noteDataProvider,
|
|
165
|
-
capsuleDataProvider,
|
|
166
|
-
stateMachine.syncDataProvider,
|
|
167
|
-
taggingDataProvider,
|
|
168
|
-
addressDataProvider,
|
|
169
|
-
privateEventDataProvider,
|
|
170
|
-
);
|
|
189
|
+
const initialJobId = jobCoordinator.beginJob();
|
|
171
190
|
|
|
172
191
|
const topLevelOracleHandler = new TXEOracleTopLevelContext(
|
|
173
192
|
stateMachine,
|
|
174
|
-
|
|
193
|
+
contractStore,
|
|
194
|
+
noteStore,
|
|
175
195
|
keyStore,
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
196
|
+
addressStore,
|
|
197
|
+
accountStore,
|
|
198
|
+
senderTaggingStore,
|
|
199
|
+
recipientTaggingStore,
|
|
200
|
+
senderAddressBookStore,
|
|
201
|
+
capsuleStore,
|
|
202
|
+
privateEventStore,
|
|
203
|
+
initialJobId,
|
|
179
204
|
nextBlockTimestamp,
|
|
180
205
|
version,
|
|
181
206
|
chainId,
|
|
@@ -187,14 +212,21 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
187
212
|
createLogger('txe:session'),
|
|
188
213
|
stateMachine,
|
|
189
214
|
topLevelOracleHandler,
|
|
190
|
-
|
|
215
|
+
contractStore,
|
|
216
|
+
noteStore,
|
|
191
217
|
keyStore,
|
|
192
|
-
|
|
193
|
-
|
|
218
|
+
addressStore,
|
|
219
|
+
accountStore,
|
|
220
|
+
senderTaggingStore,
|
|
221
|
+
recipientTaggingStore,
|
|
222
|
+
senderAddressBookStore,
|
|
223
|
+
capsuleStore,
|
|
224
|
+
privateEventStore,
|
|
225
|
+
jobCoordinator,
|
|
226
|
+
initialJobId,
|
|
194
227
|
version,
|
|
195
228
|
chainId,
|
|
196
229
|
nextBlockTimestamp,
|
|
197
|
-
pxeOracleInterface,
|
|
198
230
|
);
|
|
199
231
|
}
|
|
200
232
|
|
|
@@ -251,13 +283,23 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
251
283
|
}
|
|
252
284
|
}
|
|
253
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
|
+
|
|
254
290
|
this.oracleHandler = new TXEOracleTopLevelContext(
|
|
255
291
|
this.stateMachine,
|
|
256
|
-
this.
|
|
292
|
+
this.contractStore,
|
|
293
|
+
this.noteStore,
|
|
257
294
|
this.keyStore,
|
|
258
|
-
this.
|
|
259
|
-
this.
|
|
260
|
-
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,
|
|
261
303
|
this.nextBlockTimestamp,
|
|
262
304
|
this.version,
|
|
263
305
|
this.chainId,
|
|
@@ -270,45 +312,56 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
270
312
|
|
|
271
313
|
async enterPrivateState(
|
|
272
314
|
contractAddress: AztecAddress = DEFAULT_ADDRESS,
|
|
273
|
-
anchorBlockNumber?:
|
|
315
|
+
anchorBlockNumber?: BlockNumber,
|
|
274
316
|
): Promise<PrivateContextInputs> {
|
|
275
317
|
this.exitTopLevelState();
|
|
276
318
|
|
|
277
|
-
// There is no automatic message discovery and contract-driven syncing process in inlined private or utility
|
|
278
|
-
// contexts, which means that known nullifiers are also not searched for, since it is during the tagging sync that
|
|
279
|
-
// we perform this. We therefore search for known nullifiers now, as otherwise notes that were nullified would not
|
|
280
|
-
// be removed from the database.
|
|
281
|
-
// TODO(#12553): make the synchronizer sync here instead and remove this
|
|
282
|
-
await this.pxeOracleInterface.syncNoteNullifiers(contractAddress);
|
|
283
|
-
|
|
284
319
|
// Private execution has two associated block numbers: the anchor block (i.e. the historical block that is used to
|
|
285
320
|
// build the proof), and the *next* block, i.e. the one we'll create once the execution ends, and which will contain
|
|
286
321
|
// a single transaction with the effects of what was done in the test.
|
|
287
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
|
+
);
|
|
288
327
|
const latestBlock = await this.stateMachine.node.getBlockHeader('latest');
|
|
289
328
|
|
|
290
329
|
const nextBlockGlobalVariables = makeGlobalVariables(undefined, {
|
|
291
|
-
blockNumber: latestBlock!.globalVariables.blockNumber + 1,
|
|
330
|
+
blockNumber: BlockNumber(latestBlock!.globalVariables.blockNumber + 1),
|
|
292
331
|
timestamp: this.nextBlockTimestamp,
|
|
293
332
|
version: this.version,
|
|
294
333
|
chainId: this.chainId,
|
|
295
334
|
});
|
|
296
335
|
|
|
297
336
|
const txRequestHash = getSingleTxBlockRequestHash(nextBlockGlobalVariables.blockNumber);
|
|
298
|
-
const
|
|
337
|
+
const protocolNullifier = await computeProtocolNullifier(txRequestHash);
|
|
338
|
+
const noteCache = new ExecutionNoteCache(protocolNullifier);
|
|
299
339
|
const taggingIndexCache = new ExecutionTaggingIndexCache();
|
|
300
340
|
|
|
341
|
+
const utilityExecutor = this.utilityExecutorForContractSync(anchorBlock);
|
|
301
342
|
this.oracleHandler = new PrivateExecutionOracle(
|
|
302
343
|
Fr.ZERO,
|
|
303
344
|
new TxContext(this.chainId, this.version, GasSettings.empty()),
|
|
304
345
|
new CallContext(AztecAddress.ZERO, contractAddress, FunctionSelector.empty(), false),
|
|
305
346
|
anchorBlock!,
|
|
347
|
+
utilityExecutor,
|
|
306
348
|
[],
|
|
307
349
|
[],
|
|
308
350
|
new HashedValuesCache(),
|
|
309
351
|
noteCache,
|
|
310
352
|
taggingIndexCache,
|
|
311
|
-
this.
|
|
353
|
+
this.contractStore,
|
|
354
|
+
this.noteStore,
|
|
355
|
+
this.keyStore,
|
|
356
|
+
this.addressStore,
|
|
357
|
+
this.stateMachine.node,
|
|
358
|
+
this.senderTaggingStore,
|
|
359
|
+
this.recipientTaggingStore,
|
|
360
|
+
this.senderAddressBookStore,
|
|
361
|
+
this.capsuleStore,
|
|
362
|
+
this.privateEventStore,
|
|
363
|
+
this.stateMachine.contractSyncService,
|
|
364
|
+
this.currentJobId,
|
|
312
365
|
);
|
|
313
366
|
|
|
314
367
|
// We store the note and tagging index caches fed into the PrivateExecutionOracle (along with some other auxiliary
|
|
@@ -316,7 +369,7 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
316
369
|
// difference resides in that the simulator has all information needed in order to run the simulation, while ours
|
|
317
370
|
// will be ongoing as the different oracles will be invoked from the Noir test, until eventually the private
|
|
318
371
|
// execution finishes.
|
|
319
|
-
this.state = { name: 'PRIVATE', nextBlockGlobalVariables,
|
|
372
|
+
this.state = { name: 'PRIVATE', nextBlockGlobalVariables, noteCache, taggingIndexCache };
|
|
320
373
|
this.logger.debug(`Entered state ${this.state.name}`);
|
|
321
374
|
|
|
322
375
|
return (this.oracleHandler as PrivateExecutionOracle).getPrivateContextInputs();
|
|
@@ -329,7 +382,7 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
329
382
|
// the test. The block therefore gets the *next* block number and timestamp.
|
|
330
383
|
const latestBlockNumber = (await this.stateMachine.node.getBlockHeader('latest'))!.globalVariables.blockNumber;
|
|
331
384
|
const globalVariables = makeGlobalVariables(undefined, {
|
|
332
|
-
blockNumber: latestBlockNumber + 1,
|
|
385
|
+
blockNumber: BlockNumber(latestBlockNumber + 1),
|
|
333
386
|
timestamp: this.nextBlockTimestamp,
|
|
334
387
|
version: this.version,
|
|
335
388
|
chainId: this.chainId,
|
|
@@ -349,14 +402,36 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
349
402
|
async enterUtilityState(contractAddress: AztecAddress = DEFAULT_ADDRESS) {
|
|
350
403
|
this.exitTopLevelState();
|
|
351
404
|
|
|
405
|
+
const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
406
|
+
|
|
352
407
|
// There is no automatic message discovery and contract-driven syncing process in inlined private or utility
|
|
353
408
|
// contexts, which means that known nullifiers are also not searched for, since it is during the tagging sync that
|
|
354
409
|
// we perform this. We therefore search for known nullifiers now, as otherwise notes that were nullified would not
|
|
355
410
|
// be removed from the database.
|
|
356
411
|
// TODO(#12553): make the synchronizer sync here instead and remove this
|
|
357
|
-
await
|
|
358
|
-
|
|
359
|
-
|
|
412
|
+
await new NoteService(
|
|
413
|
+
this.noteStore,
|
|
414
|
+
this.stateMachine.node,
|
|
415
|
+
anchorBlockHeader,
|
|
416
|
+
this.currentJobId,
|
|
417
|
+
).syncNoteNullifiers(contractAddress);
|
|
418
|
+
|
|
419
|
+
this.oracleHandler = new UtilityExecutionOracle(
|
|
420
|
+
contractAddress,
|
|
421
|
+
[],
|
|
422
|
+
[],
|
|
423
|
+
anchorBlockHeader,
|
|
424
|
+
this.contractStore,
|
|
425
|
+
this.noteStore,
|
|
426
|
+
this.keyStore,
|
|
427
|
+
this.addressStore,
|
|
428
|
+
this.stateMachine.node,
|
|
429
|
+
this.recipientTaggingStore,
|
|
430
|
+
this.senderAddressBookStore,
|
|
431
|
+
this.capsuleStore,
|
|
432
|
+
this.privateEventStore,
|
|
433
|
+
this.currentJobId,
|
|
434
|
+
);
|
|
360
435
|
|
|
361
436
|
this.state = { name: 'UTILITY' };
|
|
362
437
|
this.logger.debug(`Entered state ${this.state.name}`);
|
|
@@ -390,21 +465,14 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
390
465
|
|
|
391
466
|
// We rely on the note cache to determine the effects of the transaction. This is incomplete as it doesn't private
|
|
392
467
|
// logs (other effects like enqueued public calls don't need to be considered since those are not allowed).
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
this.state.txRequestHash,
|
|
396
|
-
this.state.nextBlockGlobalVariables.blockNumber,
|
|
397
|
-
);
|
|
468
|
+
|
|
469
|
+
const txEffect = await makeTxEffect(this.state.noteCache, this.state.nextBlockGlobalVariables.blockNumber);
|
|
398
470
|
|
|
399
471
|
// We build a block holding just this transaction
|
|
400
472
|
const forkedWorldTrees = await this.stateMachine.synchronizer.nativeWorldStateService.fork();
|
|
401
473
|
await insertTxEffectIntoWorldTrees(txEffect, forkedWorldTrees);
|
|
402
474
|
|
|
403
|
-
const block =
|
|
404
|
-
makeAppendOnlyTreeSnapshot(),
|
|
405
|
-
await makeTXEBlockHeader(forkedWorldTrees, this.state.nextBlockGlobalVariables),
|
|
406
|
-
new Body([txEffect]),
|
|
407
|
-
);
|
|
475
|
+
const block = await makeTXEBlock(forkedWorldTrees, this.state.nextBlockGlobalVariables, [txEffect]);
|
|
408
476
|
await this.stateMachine.handleL2Block(block);
|
|
409
477
|
|
|
410
478
|
await forkedWorldTrees.close();
|
|
@@ -429,4 +497,48 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
429
497
|
throw new Error(`Expected to be in state 'UTILITY', but got '${this.state.name}' instead`);
|
|
430
498
|
}
|
|
431
499
|
}
|
|
500
|
+
|
|
501
|
+
private utilityExecutorForContractSync(anchorBlock: any) {
|
|
502
|
+
return async (call: FunctionCall) => {
|
|
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
|
+
call.to,
|
|
511
|
+
[],
|
|
512
|
+
[],
|
|
513
|
+
anchorBlock!,
|
|
514
|
+
this.contractStore,
|
|
515
|
+
this.noteStore,
|
|
516
|
+
this.keyStore,
|
|
517
|
+
this.addressStore,
|
|
518
|
+
this.stateMachine.node,
|
|
519
|
+
this.recipientTaggingStore,
|
|
520
|
+
this.senderAddressBookStore,
|
|
521
|
+
this.capsuleStore,
|
|
522
|
+
this.privateEventStore,
|
|
523
|
+
this.currentJobId,
|
|
524
|
+
);
|
|
525
|
+
await new WASMSimulator()
|
|
526
|
+
.executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, new Oracle(oracle).toACIRCallback())
|
|
527
|
+
.catch((err: Error) => {
|
|
528
|
+
err.message = resolveAssertionMessageFromError(err, entryPointArtifact);
|
|
529
|
+
throw new ExecutionError(
|
|
530
|
+
err.message,
|
|
531
|
+
{
|
|
532
|
+
contractAddress: call.to,
|
|
533
|
+
functionSelector: call.selector,
|
|
534
|
+
},
|
|
535
|
+
extractCallStack(err, entryPointArtifact.debug),
|
|
536
|
+
{ cause: err },
|
|
537
|
+
);
|
|
538
|
+
});
|
|
539
|
+
} catch (err) {
|
|
540
|
+
throw createSimulationError(err instanceof Error ? err : new Error('Unknown error contract data sync'));
|
|
541
|
+
}
|
|
542
|
+
};
|
|
543
|
+
}
|
|
432
544
|
}
|
package/src/util/encoding.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
1
2
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
2
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
3
3
|
import { hexToBuffer } from '@aztec/foundation/string';
|
|
4
4
|
import { type ContractArtifact, ContractArtifactSchema } from '@aztec/stdlib/abi';
|
|
5
5
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
@@ -2,7 +2,7 @@ import type { AztecAsyncKVStore, AztecAsyncMap } from '@aztec/kv-store';
|
|
|
2
2
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
3
3
|
import { CompleteAddress } from '@aztec/stdlib/contract';
|
|
4
4
|
|
|
5
|
-
export class
|
|
5
|
+
export class TXEAccountStore {
|
|
6
6
|
#accounts: AztecAsyncMap<string, Buffer>;
|
|
7
7
|
|
|
8
8
|
constructor(store: AztecAsyncKVStore) {
|
|
@@ -1,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,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
|
+
import type { ContractStore } from '@aztec/pxe/server';
|
|
3
4
|
import { type ContractArtifact, FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
|
|
4
5
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
6
|
import {
|
|
@@ -14,20 +15,20 @@ import {
|
|
|
14
15
|
export class TXEPublicContractDataSource implements ContractDataSource {
|
|
15
16
|
#privateFunctionsRoot: Map<string, Buffer> = new Map();
|
|
16
17
|
constructor(
|
|
17
|
-
private blockNumber:
|
|
18
|
-
private
|
|
18
|
+
private blockNumber: BlockNumber,
|
|
19
|
+
private contractStore: ContractStore,
|
|
19
20
|
) {}
|
|
20
21
|
|
|
21
|
-
getBlockNumber(): Promise<
|
|
22
|
+
getBlockNumber(): Promise<BlockNumber> {
|
|
22
23
|
return Promise.resolve(this.blockNumber);
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
async getContractClass(id: Fr): Promise<ContractClassPublic | undefined> {
|
|
26
|
-
const contractClass = await this.
|
|
27
|
+
const contractClass = await this.contractStore.getContractClass(id);
|
|
27
28
|
if (!contractClass) {
|
|
28
29
|
return;
|
|
29
30
|
}
|
|
30
|
-
const artifact = await this.
|
|
31
|
+
const artifact = await this.contractStore.getContractArtifact(id);
|
|
31
32
|
if (!artifact) {
|
|
32
33
|
return;
|
|
33
34
|
}
|
|
@@ -57,12 +58,12 @@ export class TXEPublicContractDataSource implements ContractDataSource {
|
|
|
57
58
|
}
|
|
58
59
|
|
|
59
60
|
async getBytecodeCommitment(id: Fr): Promise<Fr | undefined> {
|
|
60
|
-
const contractClass = await this.
|
|
61
|
+
const contractClass = await this.contractStore.getContractClass(id);
|
|
61
62
|
return contractClass && computePublicBytecodeCommitment(contractClass.packedBytecode);
|
|
62
63
|
}
|
|
63
64
|
|
|
64
65
|
async getContract(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
|
|
65
|
-
const instance = await this.
|
|
66
|
+
const instance = await this.contractStore.getContractInstance(address);
|
|
66
67
|
return instance && { ...instance, address };
|
|
67
68
|
}
|
|
68
69
|
|
|
@@ -71,12 +72,12 @@ export class TXEPublicContractDataSource implements ContractDataSource {
|
|
|
71
72
|
}
|
|
72
73
|
|
|
73
74
|
async getContractArtifact(address: AztecAddress): Promise<ContractArtifact | undefined> {
|
|
74
|
-
const instance = await this.
|
|
75
|
-
return instance && this.
|
|
75
|
+
const instance = await this.contractStore.getContractInstance(address);
|
|
76
|
+
return instance && this.contractStore.getContractArtifact(instance.currentContractClassId);
|
|
76
77
|
}
|
|
77
78
|
|
|
78
79
|
async getDebugFunctionName(address: AztecAddress, selector: FunctionSelector): Promise<string | undefined> {
|
|
79
|
-
return await this.
|
|
80
|
+
return await this.contractStore.getDebugFunctionName(address, selector);
|
|
80
81
|
}
|
|
81
82
|
|
|
82
83
|
registerContractFunctionSignatures(_signatures: []): Promise<void> {
|
|
@@ -4,19 +4,19 @@ import {
|
|
|
4
4
|
NULLIFIER_SUBTREE_HEIGHT,
|
|
5
5
|
NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP,
|
|
6
6
|
} from '@aztec/constants';
|
|
7
|
+
import { BlockNumber, CheckpointNumber, IndexWithinCheckpoint } from '@aztec/foundation/branded-types';
|
|
7
8
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
8
|
-
import { Fr } from '@aztec/foundation/
|
|
9
|
-
import {
|
|
10
|
-
import { makeContentCommitment } from '@aztec/stdlib/testing';
|
|
9
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
10
|
+
import { Body, L2Block } from '@aztec/stdlib/block';
|
|
11
11
|
import { AppendOnlyTreeSnapshot, MerkleTreeId, type MerkleTreeWriteOperations } from '@aztec/stdlib/trees';
|
|
12
|
-
import { GlobalVariables, TxEffect } from '@aztec/stdlib/tx';
|
|
12
|
+
import { BlockHeader, GlobalVariables, TxEffect } from '@aztec/stdlib/tx';
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Returns a transaction request hash that is valid for transactions that are the only ones in a block.
|
|
16
16
|
* @param blockNumber The number for the block in which there is a single transaction.
|
|
17
17
|
* @returns The transaction request hash.
|
|
18
18
|
*/
|
|
19
|
-
export function getSingleTxBlockRequestHash(blockNumber:
|
|
19
|
+
export function getSingleTxBlockRequestHash(blockNumber: BlockNumber): Fr {
|
|
20
20
|
return new Fr(blockNumber + 9999); // Why does this need to be a high number? Why do small numbered nullifiers already exist?
|
|
21
21
|
}
|
|
22
22
|
|
|
@@ -46,17 +46,52 @@ export async function insertTxEffectIntoWorldTrees(
|
|
|
46
46
|
export async function makeTXEBlockHeader(
|
|
47
47
|
worldTrees: MerkleTreeWriteOperations,
|
|
48
48
|
globalVariables: GlobalVariables,
|
|
49
|
-
): Promise<
|
|
49
|
+
): Promise<BlockHeader> {
|
|
50
50
|
const stateReference = await worldTrees.getStateReference();
|
|
51
51
|
const archiveInfo = await worldTrees.getTreeInfo(MerkleTreeId.ARCHIVE);
|
|
52
52
|
|
|
53
|
-
return
|
|
54
|
-
new AppendOnlyTreeSnapshot(new Fr(archiveInfo.root), Number(archiveInfo.size)),
|
|
55
|
-
|
|
56
|
-
stateReference,
|
|
53
|
+
return BlockHeader.from({
|
|
54
|
+
lastArchive: new AppendOnlyTreeSnapshot(new Fr(archiveInfo.root), Number(archiveInfo.size)),
|
|
55
|
+
spongeBlobHash: Fr.ZERO,
|
|
56
|
+
state: stateReference,
|
|
57
57
|
globalVariables,
|
|
58
|
-
Fr.ZERO,
|
|
59
|
-
Fr.ZERO,
|
|
60
|
-
|
|
61
|
-
|
|
58
|
+
totalFees: Fr.ZERO,
|
|
59
|
+
totalManaUsed: Fr.ZERO,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Creates an L2Block with proper archive chaining.
|
|
65
|
+
* This function:
|
|
66
|
+
* 1. Gets the current archive state as lastArchive for the header
|
|
67
|
+
* 2. Creates the block header
|
|
68
|
+
* 3. Updates the archive tree with the header hash
|
|
69
|
+
* 4. Gets the new archive state for the block's archive
|
|
70
|
+
*
|
|
71
|
+
* @param worldTrees - The world trees to read/write from
|
|
72
|
+
* @param globalVariables - Global variables for the block
|
|
73
|
+
* @param txEffects - Transaction effects to include in the block
|
|
74
|
+
* @returns The created L2Block with proper archive chaining
|
|
75
|
+
*/
|
|
76
|
+
export async function makeTXEBlock(
|
|
77
|
+
worldTrees: MerkleTreeWriteOperations,
|
|
78
|
+
globalVariables: GlobalVariables,
|
|
79
|
+
txEffects: TxEffect[],
|
|
80
|
+
): Promise<L2Block> {
|
|
81
|
+
const header = await makeTXEBlockHeader(worldTrees, globalVariables);
|
|
82
|
+
|
|
83
|
+
// Update the archive tree with this block's header hash
|
|
84
|
+
await worldTrees.updateArchive(header);
|
|
85
|
+
|
|
86
|
+
// Get the new archive state after updating
|
|
87
|
+
const newArchiveInfo = await worldTrees.getTreeInfo(MerkleTreeId.ARCHIVE);
|
|
88
|
+
const newArchive = new AppendOnlyTreeSnapshot(new Fr(newArchiveInfo.root), Number(newArchiveInfo.size));
|
|
89
|
+
|
|
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);
|
|
62
97
|
}
|