@aztec/txe 0.0.1-commit.21caa21 → 0.0.1-commit.21ecf947b
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/constants.d.ts +3 -0
- package/dest/constants.d.ts.map +1 -0
- package/dest/constants.js +2 -0
- package/dest/index.d.ts +1 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +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 +23 -13
- package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_top_level_context.js +174 -76
- package/dest/rpc_translator.d.ts +29 -17
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +125 -58
- package/dest/state_machine/archiver.d.ts +21 -52
- package/dest/state_machine/archiver.d.ts.map +1 -1
- package/dest/state_machine/archiver.js +63 -94
- 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 +35 -21
- package/dest/state_machine/global_variable_builder.d.ts +6 -5
- package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
- package/dest/state_machine/global_variable_builder.js +13 -1
- package/dest/state_machine/index.d.ts +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 +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 -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 +154 -48
- package/dest/util/encoding.d.ts +618 -19
- package/dest/util/encoding.d.ts.map +1 -1
- package/dest/util/encoding.js +1 -1
- package/dest/util/txe_account_store.d.ts +10 -0
- package/dest/util/txe_account_store.d.ts.map +1 -0
- package/dest/util/{txe_account_data_provider.js → txe_account_store.js} +1 -1
- package/dest/util/txe_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 -18
- 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 +210 -117
- package/src/rpc_translator.ts +154 -58
- package/src/state_machine/archiver.ts +59 -114
- package/src/state_machine/dummy_p2p_client.ts +48 -27
- package/src/state_machine/global_variable_builder.ts +21 -4
- package/src/state_machine/index.ts +59 -21
- package/src/state_machine/mock_epoch_cache.ts +15 -11
- package/src/state_machine/synchronizer.ts +6 -5
- package/src/txe_session.ts +208 -93
- 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 -15
- package/src/utils/tx_effect_creation.ts +5 -12
- package/dest/util/txe_account_data_provider.d.ts +0 -10
- package/dest/util/txe_account_data_provider.d.ts.map +0 -1
- package/dest/util/txe_contract_data_provider.d.ts +0 -12
- package/dest/util/txe_contract_data_provider.d.ts.map +0 -1
package/src/txe_session.ts
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
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';
|
|
7
|
+
import type { AccessScopes } from '@aztec/pxe/client/lazy';
|
|
6
8
|
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
AddressStore,
|
|
10
|
+
AnchorBlockStore,
|
|
11
|
+
CapsuleStore,
|
|
12
|
+
JobCoordinator,
|
|
13
|
+
NoteService,
|
|
14
|
+
NoteStore,
|
|
15
|
+
PrivateEventStore,
|
|
16
|
+
RecipientTaggingStore,
|
|
17
|
+
SenderAddressBookStore,
|
|
18
|
+
SenderTaggingStore,
|
|
13
19
|
} from '@aztec/pxe/server';
|
|
14
20
|
import {
|
|
15
21
|
ExecutionNoteCache,
|
|
@@ -17,35 +23,40 @@ import {
|
|
|
17
23
|
HashedValuesCache,
|
|
18
24
|
type IPrivateExecutionOracle,
|
|
19
25
|
type IUtilityExecutionOracle,
|
|
26
|
+
Oracle,
|
|
20
27
|
PrivateExecutionOracle,
|
|
21
28
|
UtilityExecutionOracle,
|
|
22
29
|
} from '@aztec/pxe/simulator';
|
|
23
|
-
import {
|
|
30
|
+
import {
|
|
31
|
+
ExecutionError,
|
|
32
|
+
WASMSimulator,
|
|
33
|
+
createSimulationError,
|
|
34
|
+
extractCallStack,
|
|
35
|
+
resolveAssertionMessageFromError,
|
|
36
|
+
toACVMWitness,
|
|
37
|
+
} from '@aztec/simulator/client';
|
|
38
|
+
import { FunctionCall, FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
|
|
24
39
|
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
25
40
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
26
|
-
import { Body, L2Block } from '@aztec/stdlib/block';
|
|
27
41
|
import { GasSettings } from '@aztec/stdlib/gas';
|
|
28
42
|
import { computeProtocolNullifier } from '@aztec/stdlib/hash';
|
|
29
43
|
import { PrivateContextInputs } from '@aztec/stdlib/kernel';
|
|
30
|
-
import {
|
|
44
|
+
import { makeGlobalVariables } from '@aztec/stdlib/testing';
|
|
31
45
|
import { CallContext, GlobalVariables, TxContext } from '@aztec/stdlib/tx';
|
|
32
|
-
import type { UInt32 } from '@aztec/stdlib/types';
|
|
33
46
|
|
|
34
47
|
import { z } from 'zod';
|
|
35
48
|
|
|
49
|
+
import { DEFAULT_ADDRESS } from './constants.js';
|
|
36
50
|
import type { IAvmExecutionOracle, ITxeExecutionOracle } from './oracle/interfaces.js';
|
|
37
51
|
import { TXEOraclePublicContext } from './oracle/txe_oracle_public_context.js';
|
|
38
52
|
import { TXEOracleTopLevelContext } from './oracle/txe_oracle_top_level_context.js';
|
|
39
53
|
import { RPCTranslator } from './rpc_translator.js';
|
|
54
|
+
import { TXEArchiver } from './state_machine/archiver.js';
|
|
40
55
|
import { TXEStateMachine } from './state_machine/index.js';
|
|
41
56
|
import type { ForeignCallArgs, ForeignCallResult } from './util/encoding.js';
|
|
42
|
-
import {
|
|
43
|
-
import {
|
|
44
|
-
import {
|
|
45
|
-
getSingleTxBlockRequestHash,
|
|
46
|
-
insertTxEffectIntoWorldTrees,
|
|
47
|
-
makeTXEBlockHeader,
|
|
48
|
-
} from './utils/block_creation.js';
|
|
57
|
+
import { TXEAccountStore } from './util/txe_account_store.js';
|
|
58
|
+
import { TXEContractStore } from './util/txe_contract_store.js';
|
|
59
|
+
import { getSingleTxBlockRequestHash, insertTxEffectIntoWorldTrees, makeTXEBlock } from './utils/block_creation.js';
|
|
49
60
|
import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
50
61
|
|
|
51
62
|
/**
|
|
@@ -67,7 +78,6 @@ type SessionState =
|
|
|
67
78
|
| {
|
|
68
79
|
name: 'PRIVATE';
|
|
69
80
|
nextBlockGlobalVariables: GlobalVariables;
|
|
70
|
-
protocolNullifier: Fr;
|
|
71
81
|
noteCache: ExecutionNoteCache;
|
|
72
82
|
taggingIndexCache: ExecutionTaggingIndexCache;
|
|
73
83
|
}
|
|
@@ -102,12 +112,10 @@ export type TXEOracleFunctionName = Exclude<
|
|
|
102
112
|
export interface TXESessionStateHandler {
|
|
103
113
|
enterTopLevelState(): Promise<void>;
|
|
104
114
|
enterPublicState(contractAddress?: AztecAddress): Promise<void>;
|
|
105
|
-
enterPrivateState(contractAddress?: AztecAddress, anchorBlockNumber?:
|
|
115
|
+
enterPrivateState(contractAddress?: AztecAddress, anchorBlockNumber?: BlockNumber): Promise<PrivateContextInputs>;
|
|
106
116
|
enterUtilityState(contractAddress?: AztecAddress): Promise<void>;
|
|
107
117
|
}
|
|
108
118
|
|
|
109
|
-
const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
|
|
110
|
-
|
|
111
119
|
/**
|
|
112
120
|
* A `TXESession` corresponds to a Noir `#[test]` function, and handles all of its oracle calls, stores test-specific
|
|
113
121
|
* state, etc., independent of all other tests running in parallel.
|
|
@@ -124,59 +132,76 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
124
132
|
| IPrivateExecutionOracle
|
|
125
133
|
| IAvmExecutionOracle
|
|
126
134
|
| ITxeExecutionOracle,
|
|
127
|
-
private
|
|
135
|
+
private contractStore: TXEContractStore,
|
|
136
|
+
private noteStore: NoteStore,
|
|
128
137
|
private keyStore: KeyStore,
|
|
129
|
-
private
|
|
130
|
-
private
|
|
138
|
+
private addressStore: AddressStore,
|
|
139
|
+
private accountStore: TXEAccountStore,
|
|
140
|
+
private senderTaggingStore: SenderTaggingStore,
|
|
141
|
+
private recipientTaggingStore: RecipientTaggingStore,
|
|
142
|
+
private senderAddressBookStore: SenderAddressBookStore,
|
|
143
|
+
private capsuleStore: CapsuleStore,
|
|
144
|
+
private privateEventStore: PrivateEventStore,
|
|
145
|
+
private jobCoordinator: JobCoordinator,
|
|
146
|
+
private currentJobId: string,
|
|
131
147
|
private chainId: Fr,
|
|
132
148
|
private version: Fr,
|
|
133
149
|
private nextBlockTimestamp: bigint,
|
|
134
|
-
private pxeOracleInterface: PXEOracleInterface,
|
|
135
150
|
) {}
|
|
136
151
|
|
|
137
152
|
static async init(protocolContracts: ProtocolContract[]) {
|
|
138
153
|
const store = await openTmpStore('txe-session');
|
|
139
154
|
|
|
140
|
-
const
|
|
141
|
-
const
|
|
142
|
-
const
|
|
143
|
-
const
|
|
144
|
-
const
|
|
145
|
-
const
|
|
155
|
+
const addressStore = new AddressStore(store);
|
|
156
|
+
const privateEventStore = new PrivateEventStore(store);
|
|
157
|
+
const contractStore = new TXEContractStore(store);
|
|
158
|
+
const noteStore = new NoteStore(store);
|
|
159
|
+
const senderTaggingStore = new SenderTaggingStore(store);
|
|
160
|
+
const recipientTaggingStore = new RecipientTaggingStore(store);
|
|
161
|
+
const senderAddressBookStore = new SenderAddressBookStore(store);
|
|
162
|
+
const capsuleStore = new CapsuleStore(store);
|
|
146
163
|
const keyStore = new KeyStore(store);
|
|
147
|
-
const
|
|
164
|
+
const accountStore = new TXEAccountStore(store);
|
|
165
|
+
|
|
166
|
+
// Create job coordinator and register staged stores
|
|
167
|
+
const jobCoordinator = new JobCoordinator(store);
|
|
168
|
+
jobCoordinator.registerStores([
|
|
169
|
+
capsuleStore,
|
|
170
|
+
senderTaggingStore,
|
|
171
|
+
recipientTaggingStore,
|
|
172
|
+
privateEventStore,
|
|
173
|
+
noteStore,
|
|
174
|
+
]);
|
|
148
175
|
|
|
149
176
|
// Register protocol contracts.
|
|
150
177
|
for (const { contractClass, instance, artifact } of protocolContracts) {
|
|
151
|
-
await
|
|
152
|
-
await
|
|
178
|
+
await contractStore.addContractArtifact(contractClass.id, artifact);
|
|
179
|
+
await contractStore.addContractInstance(instance);
|
|
153
180
|
}
|
|
154
181
|
|
|
155
|
-
const
|
|
182
|
+
const archiver = new TXEArchiver(store);
|
|
183
|
+
const anchorBlockStore = new AnchorBlockStore(store);
|
|
184
|
+
const stateMachine = await TXEStateMachine.create(archiver, anchorBlockStore, contractStore, noteStore);
|
|
156
185
|
|
|
157
186
|
const nextBlockTimestamp = BigInt(Math.floor(new Date().getTime() / 1000));
|
|
158
187
|
const version = new Fr(await stateMachine.node.getVersion());
|
|
159
188
|
const chainId = new Fr(await stateMachine.node.getChainId());
|
|
160
189
|
|
|
161
|
-
const
|
|
162
|
-
stateMachine.node,
|
|
163
|
-
keyStore,
|
|
164
|
-
contractDataProvider,
|
|
165
|
-
noteDataProvider,
|
|
166
|
-
capsuleDataProvider,
|
|
167
|
-
stateMachine.syncDataProvider,
|
|
168
|
-
taggingDataProvider,
|
|
169
|
-
addressDataProvider,
|
|
170
|
-
privateEventDataProvider,
|
|
171
|
-
);
|
|
190
|
+
const initialJobId = jobCoordinator.beginJob();
|
|
172
191
|
|
|
173
192
|
const topLevelOracleHandler = new TXEOracleTopLevelContext(
|
|
174
193
|
stateMachine,
|
|
175
|
-
|
|
194
|
+
contractStore,
|
|
195
|
+
noteStore,
|
|
176
196
|
keyStore,
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
197
|
+
addressStore,
|
|
198
|
+
accountStore,
|
|
199
|
+
senderTaggingStore,
|
|
200
|
+
recipientTaggingStore,
|
|
201
|
+
senderAddressBookStore,
|
|
202
|
+
capsuleStore,
|
|
203
|
+
privateEventStore,
|
|
204
|
+
initialJobId,
|
|
180
205
|
nextBlockTimestamp,
|
|
181
206
|
version,
|
|
182
207
|
chainId,
|
|
@@ -188,14 +213,21 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
188
213
|
createLogger('txe:session'),
|
|
189
214
|
stateMachine,
|
|
190
215
|
topLevelOracleHandler,
|
|
191
|
-
|
|
216
|
+
contractStore,
|
|
217
|
+
noteStore,
|
|
192
218
|
keyStore,
|
|
193
|
-
|
|
194
|
-
|
|
219
|
+
addressStore,
|
|
220
|
+
accountStore,
|
|
221
|
+
senderTaggingStore,
|
|
222
|
+
recipientTaggingStore,
|
|
223
|
+
senderAddressBookStore,
|
|
224
|
+
capsuleStore,
|
|
225
|
+
privateEventStore,
|
|
226
|
+
jobCoordinator,
|
|
227
|
+
initialJobId,
|
|
195
228
|
version,
|
|
196
229
|
chainId,
|
|
197
230
|
nextBlockTimestamp,
|
|
198
|
-
pxeOracleInterface,
|
|
199
231
|
);
|
|
200
232
|
}
|
|
201
233
|
|
|
@@ -252,13 +284,23 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
252
284
|
}
|
|
253
285
|
}
|
|
254
286
|
|
|
287
|
+
// Commit all staged stores from the job that was just completed, then begin a new job
|
|
288
|
+
await this.jobCoordinator.commitJob(this.currentJobId);
|
|
289
|
+
this.currentJobId = this.jobCoordinator.beginJob();
|
|
290
|
+
|
|
255
291
|
this.oracleHandler = new TXEOracleTopLevelContext(
|
|
256
292
|
this.stateMachine,
|
|
257
|
-
this.
|
|
293
|
+
this.contractStore,
|
|
294
|
+
this.noteStore,
|
|
258
295
|
this.keyStore,
|
|
259
|
-
this.
|
|
260
|
-
this.
|
|
261
|
-
this.
|
|
296
|
+
this.addressStore,
|
|
297
|
+
this.accountStore,
|
|
298
|
+
this.senderTaggingStore,
|
|
299
|
+
this.recipientTaggingStore,
|
|
300
|
+
this.senderAddressBookStore,
|
|
301
|
+
this.capsuleStore,
|
|
302
|
+
this.privateEventStore,
|
|
303
|
+
this.currentJobId,
|
|
262
304
|
this.nextBlockTimestamp,
|
|
263
305
|
this.version,
|
|
264
306
|
this.chainId,
|
|
@@ -271,25 +313,23 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
271
313
|
|
|
272
314
|
async enterPrivateState(
|
|
273
315
|
contractAddress: AztecAddress = DEFAULT_ADDRESS,
|
|
274
|
-
anchorBlockNumber?:
|
|
316
|
+
anchorBlockNumber?: BlockNumber,
|
|
275
317
|
): Promise<PrivateContextInputs> {
|
|
276
318
|
this.exitTopLevelState();
|
|
277
319
|
|
|
278
|
-
// There is no automatic message discovery and contract-driven syncing process in inlined private or utility
|
|
279
|
-
// contexts, which means that known nullifiers are also not searched for, since it is during the tagging sync that
|
|
280
|
-
// we perform this. We therefore search for known nullifiers now, as otherwise notes that were nullified would not
|
|
281
|
-
// be removed from the database.
|
|
282
|
-
// TODO(#12553): make the synchronizer sync here instead and remove this
|
|
283
|
-
await this.pxeOracleInterface.syncNoteNullifiers(contractAddress);
|
|
284
|
-
|
|
285
320
|
// Private execution has two associated block numbers: the anchor block (i.e. the historical block that is used to
|
|
286
321
|
// build the proof), and the *next* block, i.e. the one we'll create once the execution ends, and which will contain
|
|
287
322
|
// a single transaction with the effects of what was done in the test.
|
|
288
323
|
const anchorBlock = await this.stateMachine.node.getBlockHeader(anchorBlockNumber ?? 'latest');
|
|
324
|
+
|
|
325
|
+
await new NoteService(this.noteStore, this.stateMachine.node, anchorBlock!, this.currentJobId).syncNoteNullifiers(
|
|
326
|
+
contractAddress,
|
|
327
|
+
'ALL_SCOPES',
|
|
328
|
+
);
|
|
289
329
|
const latestBlock = await this.stateMachine.node.getBlockHeader('latest');
|
|
290
330
|
|
|
291
331
|
const nextBlockGlobalVariables = makeGlobalVariables(undefined, {
|
|
292
|
-
blockNumber: latestBlock!.globalVariables.blockNumber + 1,
|
|
332
|
+
blockNumber: BlockNumber(latestBlock!.globalVariables.blockNumber + 1),
|
|
293
333
|
timestamp: this.nextBlockTimestamp,
|
|
294
334
|
version: this.version,
|
|
295
335
|
chainId: this.chainId,
|
|
@@ -300,25 +340,39 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
300
340
|
const noteCache = new ExecutionNoteCache(protocolNullifier);
|
|
301
341
|
const taggingIndexCache = new ExecutionTaggingIndexCache();
|
|
302
342
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
new
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
343
|
+
const utilityExecutor = this.utilityExecutorForContractSync(anchorBlock);
|
|
344
|
+
this.oracleHandler = new PrivateExecutionOracle({
|
|
345
|
+
argsHash: Fr.ZERO,
|
|
346
|
+
txContext: new TxContext(this.chainId, this.version, GasSettings.empty()),
|
|
347
|
+
callContext: new CallContext(AztecAddress.ZERO, contractAddress, FunctionSelector.empty(), false),
|
|
348
|
+
anchorBlockHeader: anchorBlock!,
|
|
349
|
+
utilityExecutor,
|
|
350
|
+
authWitnesses: [],
|
|
351
|
+
capsules: [],
|
|
352
|
+
executionCache: new HashedValuesCache(),
|
|
311
353
|
noteCache,
|
|
312
354
|
taggingIndexCache,
|
|
313
|
-
this.
|
|
314
|
-
|
|
355
|
+
contractStore: this.contractStore,
|
|
356
|
+
noteStore: this.noteStore,
|
|
357
|
+
keyStore: this.keyStore,
|
|
358
|
+
addressStore: this.addressStore,
|
|
359
|
+
aztecNode: this.stateMachine.node,
|
|
360
|
+
senderTaggingStore: this.senderTaggingStore,
|
|
361
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
362
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
363
|
+
capsuleStore: this.capsuleStore,
|
|
364
|
+
privateEventStore: this.privateEventStore,
|
|
365
|
+
contractSyncService: this.stateMachine.contractSyncService,
|
|
366
|
+
jobId: this.currentJobId,
|
|
367
|
+
scopes: 'ALL_SCOPES',
|
|
368
|
+
});
|
|
315
369
|
|
|
316
370
|
// We store the note and tagging index caches fed into the PrivateExecutionOracle (along with some other auxiliary
|
|
317
371
|
// data) in order to refer to it later, mimicking the way this object is used by the ContractFunctionSimulator. The
|
|
318
372
|
// difference resides in that the simulator has all information needed in order to run the simulation, while ours
|
|
319
373
|
// will be ongoing as the different oracles will be invoked from the Noir test, until eventually the private
|
|
320
374
|
// execution finishes.
|
|
321
|
-
this.state = { name: 'PRIVATE', nextBlockGlobalVariables,
|
|
375
|
+
this.state = { name: 'PRIVATE', nextBlockGlobalVariables, noteCache, taggingIndexCache };
|
|
322
376
|
this.logger.debug(`Entered state ${this.state.name}`);
|
|
323
377
|
|
|
324
378
|
return (this.oracleHandler as PrivateExecutionOracle).getPrivateContextInputs();
|
|
@@ -331,7 +385,7 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
331
385
|
// the test. The block therefore gets the *next* block number and timestamp.
|
|
332
386
|
const latestBlockNumber = (await this.stateMachine.node.getBlockHeader('latest'))!.globalVariables.blockNumber;
|
|
333
387
|
const globalVariables = makeGlobalVariables(undefined, {
|
|
334
|
-
blockNumber: latestBlockNumber + 1,
|
|
388
|
+
blockNumber: BlockNumber(latestBlockNumber + 1),
|
|
335
389
|
timestamp: this.nextBlockTimestamp,
|
|
336
390
|
version: this.version,
|
|
337
391
|
chainId: this.chainId,
|
|
@@ -351,14 +405,37 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
351
405
|
async enterUtilityState(contractAddress: AztecAddress = DEFAULT_ADDRESS) {
|
|
352
406
|
this.exitTopLevelState();
|
|
353
407
|
|
|
408
|
+
const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
409
|
+
|
|
354
410
|
// There is no automatic message discovery and contract-driven syncing process in inlined private or utility
|
|
355
411
|
// contexts, which means that known nullifiers are also not searched for, since it is during the tagging sync that
|
|
356
412
|
// we perform this. We therefore search for known nullifiers now, as otherwise notes that were nullified would not
|
|
357
413
|
// be removed from the database.
|
|
358
414
|
// TODO(#12553): make the synchronizer sync here instead and remove this
|
|
359
|
-
await
|
|
360
|
-
|
|
361
|
-
|
|
415
|
+
await new NoteService(
|
|
416
|
+
this.noteStore,
|
|
417
|
+
this.stateMachine.node,
|
|
418
|
+
anchorBlockHeader,
|
|
419
|
+
this.currentJobId,
|
|
420
|
+
).syncNoteNullifiers(contractAddress, 'ALL_SCOPES');
|
|
421
|
+
|
|
422
|
+
this.oracleHandler = new UtilityExecutionOracle({
|
|
423
|
+
contractAddress,
|
|
424
|
+
authWitnesses: [],
|
|
425
|
+
capsules: [],
|
|
426
|
+
anchorBlockHeader,
|
|
427
|
+
contractStore: this.contractStore,
|
|
428
|
+
noteStore: this.noteStore,
|
|
429
|
+
keyStore: this.keyStore,
|
|
430
|
+
addressStore: this.addressStore,
|
|
431
|
+
aztecNode: this.stateMachine.node,
|
|
432
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
433
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
434
|
+
capsuleStore: this.capsuleStore,
|
|
435
|
+
privateEventStore: this.privateEventStore,
|
|
436
|
+
jobId: this.currentJobId,
|
|
437
|
+
scopes: 'ALL_SCOPES',
|
|
438
|
+
});
|
|
362
439
|
|
|
363
440
|
this.state = { name: 'UTILITY' };
|
|
364
441
|
this.logger.debug(`Entered state ${this.state.name}`);
|
|
@@ -392,21 +469,14 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
392
469
|
|
|
393
470
|
// We rely on the note cache to determine the effects of the transaction. This is incomplete as it doesn't private
|
|
394
471
|
// logs (other effects like enqueued public calls don't need to be considered since those are not allowed).
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
this.state.protocolNullifier,
|
|
398
|
-
this.state.nextBlockGlobalVariables.blockNumber,
|
|
399
|
-
);
|
|
472
|
+
|
|
473
|
+
const txEffect = await makeTxEffect(this.state.noteCache, this.state.nextBlockGlobalVariables.blockNumber);
|
|
400
474
|
|
|
401
475
|
// We build a block holding just this transaction
|
|
402
476
|
const forkedWorldTrees = await this.stateMachine.synchronizer.nativeWorldStateService.fork();
|
|
403
477
|
await insertTxEffectIntoWorldTrees(txEffect, forkedWorldTrees);
|
|
404
478
|
|
|
405
|
-
const block =
|
|
406
|
-
makeAppendOnlyTreeSnapshot(),
|
|
407
|
-
await makeTXEBlockHeader(forkedWorldTrees, this.state.nextBlockGlobalVariables),
|
|
408
|
-
new Body([txEffect]),
|
|
409
|
-
);
|
|
479
|
+
const block = await makeTXEBlock(forkedWorldTrees, this.state.nextBlockGlobalVariables, [txEffect]);
|
|
410
480
|
await this.stateMachine.handleL2Block(block);
|
|
411
481
|
|
|
412
482
|
await forkedWorldTrees.close();
|
|
@@ -431,4 +501,49 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
431
501
|
throw new Error(`Expected to be in state 'UTILITY', but got '${this.state.name}' instead`);
|
|
432
502
|
}
|
|
433
503
|
}
|
|
504
|
+
|
|
505
|
+
private utilityExecutorForContractSync(anchorBlock: any) {
|
|
506
|
+
return async (call: FunctionCall, scopes: AccessScopes) => {
|
|
507
|
+
const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
|
|
508
|
+
if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
|
|
509
|
+
throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
try {
|
|
513
|
+
const oracle = new UtilityExecutionOracle({
|
|
514
|
+
contractAddress: call.to,
|
|
515
|
+
authWitnesses: [],
|
|
516
|
+
capsules: [],
|
|
517
|
+
anchorBlockHeader: anchorBlock!,
|
|
518
|
+
contractStore: this.contractStore,
|
|
519
|
+
noteStore: this.noteStore,
|
|
520
|
+
keyStore: this.keyStore,
|
|
521
|
+
addressStore: this.addressStore,
|
|
522
|
+
aztecNode: this.stateMachine.node,
|
|
523
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
524
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
525
|
+
capsuleStore: this.capsuleStore,
|
|
526
|
+
privateEventStore: this.privateEventStore,
|
|
527
|
+
jobId: this.currentJobId,
|
|
528
|
+
scopes,
|
|
529
|
+
});
|
|
530
|
+
await new WASMSimulator()
|
|
531
|
+
.executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, new Oracle(oracle).toACIRCallback())
|
|
532
|
+
.catch((err: Error) => {
|
|
533
|
+
err.message = resolveAssertionMessageFromError(err, entryPointArtifact);
|
|
534
|
+
throw new ExecutionError(
|
|
535
|
+
err.message,
|
|
536
|
+
{
|
|
537
|
+
contractAddress: call.to,
|
|
538
|
+
functionSelector: call.selector,
|
|
539
|
+
},
|
|
540
|
+
extractCallStack(err, entryPointArtifact.debug),
|
|
541
|
+
{ cause: err },
|
|
542
|
+
);
|
|
543
|
+
});
|
|
544
|
+
} catch (err) {
|
|
545
|
+
throw createSimulationError(err instanceof Error ? err : new Error('Unknown error contract data sync'));
|
|
546
|
+
}
|
|
547
|
+
};
|
|
548
|
+
}
|
|
434
549
|
}
|
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,18 +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
|
-
|
|
62
|
-
|
|
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);
|
|
63
97
|
}
|