@aztec/txe 0.0.1-commit.24de95ac → 0.0.1-commit.3469e52
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 +9 -6
- package/dest/oracle/interfaces.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.d.ts +6 -6
- package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.js +4 -6
- 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 +124 -78
- package/dest/rpc_translator.d.ts +22 -13
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +87 -37
- 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 +62 -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 +6 -6
- package/dest/state_machine/index.d.ts.map +1 -1
- package/dest/state_machine/index.js +22 -19
- package/dest/state_machine/mock_epoch_cache.d.ts +9 -9
- package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
- package/dest/state_machine/mock_epoch_cache.js +15 -12
- package/dest/state_machine/synchronizer.d.ts +5 -4
- 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 +96 -48
- 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 +36 -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 +8 -5
- package/src/oracle/txe_oracle_public_context.ts +7 -12
- package/src/oracle/txe_oracle_top_level_context.ts +174 -105
- package/src/rpc_translator.ts +109 -45
- package/src/state_machine/archiver.ts +65 -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 +28 -19
- package/src/state_machine/mock_epoch_cache.ts +18 -19
- package/src/state_machine/synchronizer.ts +8 -7
- package/src/txe_session.ts +187 -82
- 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 +47 -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,19 @@
|
|
|
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
|
+
CapsuleStore,
|
|
10
|
+
JobCoordinator,
|
|
11
|
+
NoteService,
|
|
12
|
+
NoteStore,
|
|
13
|
+
PrivateEventStore,
|
|
14
|
+
RecipientTaggingStore,
|
|
15
|
+
SenderAddressBookStore,
|
|
16
|
+
SenderTaggingStore,
|
|
13
17
|
} from '@aztec/pxe/server';
|
|
14
18
|
import {
|
|
15
19
|
ExecutionNoteCache,
|
|
@@ -17,34 +21,39 @@ import {
|
|
|
17
21
|
HashedValuesCache,
|
|
18
22
|
type IPrivateExecutionOracle,
|
|
19
23
|
type IUtilityExecutionOracle,
|
|
24
|
+
Oracle,
|
|
20
25
|
PrivateExecutionOracle,
|
|
21
26
|
UtilityExecutionOracle,
|
|
22
27
|
} from '@aztec/pxe/simulator';
|
|
23
|
-
import {
|
|
28
|
+
import {
|
|
29
|
+
ExecutionError,
|
|
30
|
+
WASMSimulator,
|
|
31
|
+
createSimulationError,
|
|
32
|
+
extractCallStack,
|
|
33
|
+
resolveAssertionMessageFromError,
|
|
34
|
+
toACVMWitness,
|
|
35
|
+
} from '@aztec/simulator/client';
|
|
36
|
+
import { FunctionCall, FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
|
|
24
37
|
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
25
38
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
26
|
-
import { Body, L2Block } from '@aztec/stdlib/block';
|
|
27
39
|
import { GasSettings } from '@aztec/stdlib/gas';
|
|
40
|
+
import { computeProtocolNullifier } from '@aztec/stdlib/hash';
|
|
28
41
|
import { PrivateContextInputs } from '@aztec/stdlib/kernel';
|
|
29
|
-
import {
|
|
42
|
+
import { makeGlobalVariables } from '@aztec/stdlib/testing';
|
|
30
43
|
import { CallContext, GlobalVariables, TxContext } from '@aztec/stdlib/tx';
|
|
31
|
-
import type { UInt32 } from '@aztec/stdlib/types';
|
|
32
44
|
|
|
33
45
|
import { z } from 'zod';
|
|
34
46
|
|
|
47
|
+
import { DEFAULT_ADDRESS } from './constants.js';
|
|
35
48
|
import type { IAvmExecutionOracle, ITxeExecutionOracle } from './oracle/interfaces.js';
|
|
36
49
|
import { TXEOraclePublicContext } from './oracle/txe_oracle_public_context.js';
|
|
37
50
|
import { TXEOracleTopLevelContext } from './oracle/txe_oracle_top_level_context.js';
|
|
38
51
|
import { RPCTranslator } from './rpc_translator.js';
|
|
39
52
|
import { TXEStateMachine } from './state_machine/index.js';
|
|
40
53
|
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';
|
|
54
|
+
import { TXEAccountStore } from './util/txe_account_store.js';
|
|
55
|
+
import { TXEContractStore } from './util/txe_contract_store.js';
|
|
56
|
+
import { getSingleTxBlockRequestHash, insertTxEffectIntoWorldTrees, makeTXEBlock } from './utils/block_creation.js';
|
|
48
57
|
import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
49
58
|
|
|
50
59
|
/**
|
|
@@ -66,7 +75,6 @@ type SessionState =
|
|
|
66
75
|
| {
|
|
67
76
|
name: 'PRIVATE';
|
|
68
77
|
nextBlockGlobalVariables: GlobalVariables;
|
|
69
|
-
txRequestHash: Fr;
|
|
70
78
|
noteCache: ExecutionNoteCache;
|
|
71
79
|
taggingIndexCache: ExecutionTaggingIndexCache;
|
|
72
80
|
}
|
|
@@ -101,12 +109,10 @@ export type TXEOracleFunctionName = Exclude<
|
|
|
101
109
|
export interface TXESessionStateHandler {
|
|
102
110
|
enterTopLevelState(): Promise<void>;
|
|
103
111
|
enterPublicState(contractAddress?: AztecAddress): Promise<void>;
|
|
104
|
-
enterPrivateState(contractAddress?: AztecAddress, anchorBlockNumber?:
|
|
112
|
+
enterPrivateState(contractAddress?: AztecAddress, anchorBlockNumber?: BlockNumber): Promise<PrivateContextInputs>;
|
|
105
113
|
enterUtilityState(contractAddress?: AztecAddress): Promise<void>;
|
|
106
114
|
}
|
|
107
115
|
|
|
108
|
-
const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
|
|
109
|
-
|
|
110
116
|
/**
|
|
111
117
|
* A `TXESession` corresponds to a Noir `#[test]` function, and handles all of its oracle calls, stores test-specific
|
|
112
118
|
* state, etc., independent of all other tests running in parallel.
|
|
@@ -123,32 +129,45 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
123
129
|
| IPrivateExecutionOracle
|
|
124
130
|
| IAvmExecutionOracle
|
|
125
131
|
| ITxeExecutionOracle,
|
|
126
|
-
private
|
|
132
|
+
private contractStore: TXEContractStore,
|
|
133
|
+
private noteStore: NoteStore,
|
|
127
134
|
private keyStore: KeyStore,
|
|
128
|
-
private
|
|
129
|
-
private
|
|
135
|
+
private addressStore: AddressStore,
|
|
136
|
+
private accountStore: TXEAccountStore,
|
|
137
|
+
private senderTaggingStore: SenderTaggingStore,
|
|
138
|
+
private recipientTaggingStore: RecipientTaggingStore,
|
|
139
|
+
private senderAddressBookStore: SenderAddressBookStore,
|
|
140
|
+
private capsuleStore: CapsuleStore,
|
|
141
|
+
private privateEventStore: PrivateEventStore,
|
|
142
|
+
private jobCoordinator: JobCoordinator,
|
|
143
|
+
private currentJobId: string,
|
|
130
144
|
private chainId: Fr,
|
|
131
145
|
private version: Fr,
|
|
132
146
|
private nextBlockTimestamp: bigint,
|
|
133
|
-
private pxeOracleInterface: PXEOracleInterface,
|
|
134
147
|
) {}
|
|
135
148
|
|
|
136
149
|
static async init(protocolContracts: ProtocolContract[]) {
|
|
137
150
|
const store = await openTmpStore('txe-session');
|
|
138
151
|
|
|
139
|
-
const
|
|
140
|
-
const
|
|
141
|
-
const
|
|
142
|
-
const
|
|
143
|
-
const
|
|
144
|
-
const
|
|
152
|
+
const addressStore = new AddressStore(store);
|
|
153
|
+
const privateEventStore = new PrivateEventStore(store);
|
|
154
|
+
const contractStore = new TXEContractStore(store);
|
|
155
|
+
const noteStore = await NoteStore.create(store);
|
|
156
|
+
const senderTaggingStore = new SenderTaggingStore(store);
|
|
157
|
+
const recipientTaggingStore = new RecipientTaggingStore(store);
|
|
158
|
+
const senderAddressBookStore = new SenderAddressBookStore(store);
|
|
159
|
+
const capsuleStore = new CapsuleStore(store);
|
|
145
160
|
const keyStore = new KeyStore(store);
|
|
146
|
-
const
|
|
161
|
+
const accountStore = new TXEAccountStore(store);
|
|
162
|
+
|
|
163
|
+
// Create job coordinator and register staged stores
|
|
164
|
+
const jobCoordinator = new JobCoordinator(store);
|
|
165
|
+
jobCoordinator.registerStores([capsuleStore, senderTaggingStore, recipientTaggingStore, privateEventStore]);
|
|
147
166
|
|
|
148
167
|
// Register protocol contracts.
|
|
149
168
|
for (const { contractClass, instance, artifact } of protocolContracts) {
|
|
150
|
-
await
|
|
151
|
-
await
|
|
169
|
+
await contractStore.addContractArtifact(contractClass.id, artifact);
|
|
170
|
+
await contractStore.addContractInstance(instance);
|
|
152
171
|
}
|
|
153
172
|
|
|
154
173
|
const stateMachine = await TXEStateMachine.create(store);
|
|
@@ -157,25 +176,21 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
157
176
|
const version = new Fr(await stateMachine.node.getVersion());
|
|
158
177
|
const chainId = new Fr(await stateMachine.node.getChainId());
|
|
159
178
|
|
|
160
|
-
const
|
|
161
|
-
stateMachine.node,
|
|
162
|
-
keyStore,
|
|
163
|
-
contractDataProvider,
|
|
164
|
-
noteDataProvider,
|
|
165
|
-
capsuleDataProvider,
|
|
166
|
-
stateMachine.syncDataProvider,
|
|
167
|
-
taggingDataProvider,
|
|
168
|
-
addressDataProvider,
|
|
169
|
-
privateEventDataProvider,
|
|
170
|
-
);
|
|
179
|
+
const initialJobId = jobCoordinator.beginJob();
|
|
171
180
|
|
|
172
181
|
const topLevelOracleHandler = new TXEOracleTopLevelContext(
|
|
173
182
|
stateMachine,
|
|
174
|
-
|
|
183
|
+
contractStore,
|
|
184
|
+
noteStore,
|
|
175
185
|
keyStore,
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
186
|
+
addressStore,
|
|
187
|
+
accountStore,
|
|
188
|
+
senderTaggingStore,
|
|
189
|
+
recipientTaggingStore,
|
|
190
|
+
senderAddressBookStore,
|
|
191
|
+
capsuleStore,
|
|
192
|
+
privateEventStore,
|
|
193
|
+
initialJobId,
|
|
179
194
|
nextBlockTimestamp,
|
|
180
195
|
version,
|
|
181
196
|
chainId,
|
|
@@ -187,14 +202,21 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
187
202
|
createLogger('txe:session'),
|
|
188
203
|
stateMachine,
|
|
189
204
|
topLevelOracleHandler,
|
|
190
|
-
|
|
205
|
+
contractStore,
|
|
206
|
+
noteStore,
|
|
191
207
|
keyStore,
|
|
192
|
-
|
|
193
|
-
|
|
208
|
+
addressStore,
|
|
209
|
+
accountStore,
|
|
210
|
+
senderTaggingStore,
|
|
211
|
+
recipientTaggingStore,
|
|
212
|
+
senderAddressBookStore,
|
|
213
|
+
capsuleStore,
|
|
214
|
+
privateEventStore,
|
|
215
|
+
jobCoordinator,
|
|
216
|
+
initialJobId,
|
|
194
217
|
version,
|
|
195
218
|
chainId,
|
|
196
219
|
nextBlockTimestamp,
|
|
197
|
-
pxeOracleInterface,
|
|
198
220
|
);
|
|
199
221
|
}
|
|
200
222
|
|
|
@@ -251,13 +273,23 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
251
273
|
}
|
|
252
274
|
}
|
|
253
275
|
|
|
276
|
+
// Commit all staged stores from the job that was just completed, then begin a new job
|
|
277
|
+
await this.jobCoordinator.commitJob(this.currentJobId);
|
|
278
|
+
this.currentJobId = this.jobCoordinator.beginJob();
|
|
279
|
+
|
|
254
280
|
this.oracleHandler = new TXEOracleTopLevelContext(
|
|
255
281
|
this.stateMachine,
|
|
256
|
-
this.
|
|
282
|
+
this.contractStore,
|
|
283
|
+
this.noteStore,
|
|
257
284
|
this.keyStore,
|
|
258
|
-
this.
|
|
259
|
-
this.
|
|
260
|
-
this.
|
|
285
|
+
this.addressStore,
|
|
286
|
+
this.accountStore,
|
|
287
|
+
this.senderTaggingStore,
|
|
288
|
+
this.recipientTaggingStore,
|
|
289
|
+
this.senderAddressBookStore,
|
|
290
|
+
this.capsuleStore,
|
|
291
|
+
this.privateEventStore,
|
|
292
|
+
this.currentJobId,
|
|
261
293
|
this.nextBlockTimestamp,
|
|
262
294
|
this.version,
|
|
263
295
|
this.chainId,
|
|
@@ -270,16 +302,15 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
270
302
|
|
|
271
303
|
async enterPrivateState(
|
|
272
304
|
contractAddress: AztecAddress = DEFAULT_ADDRESS,
|
|
273
|
-
anchorBlockNumber?:
|
|
305
|
+
anchorBlockNumber?: BlockNumber,
|
|
274
306
|
): Promise<PrivateContextInputs> {
|
|
275
307
|
this.exitTopLevelState();
|
|
276
308
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
await this.pxeOracleInterface.syncNoteNullifiers(contractAddress);
|
|
309
|
+
await new NoteService(
|
|
310
|
+
this.noteStore,
|
|
311
|
+
this.stateMachine.node,
|
|
312
|
+
this.stateMachine.anchorBlockStore,
|
|
313
|
+
).syncNoteNullifiers(contractAddress);
|
|
283
314
|
|
|
284
315
|
// Private execution has two associated block numbers: the anchor block (i.e. the historical block that is used to
|
|
285
316
|
// build the proof), and the *next* block, i.e. the one we'll create once the execution ends, and which will contain
|
|
@@ -288,27 +319,41 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
288
319
|
const latestBlock = await this.stateMachine.node.getBlockHeader('latest');
|
|
289
320
|
|
|
290
321
|
const nextBlockGlobalVariables = makeGlobalVariables(undefined, {
|
|
291
|
-
blockNumber: latestBlock!.globalVariables.blockNumber + 1,
|
|
322
|
+
blockNumber: BlockNumber(latestBlock!.globalVariables.blockNumber + 1),
|
|
292
323
|
timestamp: this.nextBlockTimestamp,
|
|
293
324
|
version: this.version,
|
|
294
325
|
chainId: this.chainId,
|
|
295
326
|
});
|
|
296
327
|
|
|
297
328
|
const txRequestHash = getSingleTxBlockRequestHash(nextBlockGlobalVariables.blockNumber);
|
|
298
|
-
const
|
|
329
|
+
const protocolNullifier = await computeProtocolNullifier(txRequestHash);
|
|
330
|
+
const noteCache = new ExecutionNoteCache(protocolNullifier);
|
|
299
331
|
const taggingIndexCache = new ExecutionTaggingIndexCache();
|
|
300
332
|
|
|
333
|
+
const utilityExecutor = this.utilityExecutorForContractSync(anchorBlock);
|
|
301
334
|
this.oracleHandler = new PrivateExecutionOracle(
|
|
302
335
|
Fr.ZERO,
|
|
303
336
|
new TxContext(this.chainId, this.version, GasSettings.empty()),
|
|
304
337
|
new CallContext(AztecAddress.ZERO, contractAddress, FunctionSelector.empty(), false),
|
|
305
338
|
anchorBlock!,
|
|
339
|
+
utilityExecutor,
|
|
306
340
|
[],
|
|
307
341
|
[],
|
|
308
342
|
new HashedValuesCache(),
|
|
309
343
|
noteCache,
|
|
310
344
|
taggingIndexCache,
|
|
311
|
-
this.
|
|
345
|
+
this.contractStore,
|
|
346
|
+
this.noteStore,
|
|
347
|
+
this.keyStore,
|
|
348
|
+
this.addressStore,
|
|
349
|
+
this.stateMachine.node,
|
|
350
|
+
this.stateMachine.anchorBlockStore,
|
|
351
|
+
this.senderTaggingStore,
|
|
352
|
+
this.recipientTaggingStore,
|
|
353
|
+
this.senderAddressBookStore,
|
|
354
|
+
this.capsuleStore,
|
|
355
|
+
this.privateEventStore,
|
|
356
|
+
this.currentJobId,
|
|
312
357
|
);
|
|
313
358
|
|
|
314
359
|
// We store the note and tagging index caches fed into the PrivateExecutionOracle (along with some other auxiliary
|
|
@@ -316,7 +361,7 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
316
361
|
// difference resides in that the simulator has all information needed in order to run the simulation, while ours
|
|
317
362
|
// will be ongoing as the different oracles will be invoked from the Noir test, until eventually the private
|
|
318
363
|
// execution finishes.
|
|
319
|
-
this.state = { name: 'PRIVATE', nextBlockGlobalVariables,
|
|
364
|
+
this.state = { name: 'PRIVATE', nextBlockGlobalVariables, noteCache, taggingIndexCache };
|
|
320
365
|
this.logger.debug(`Entered state ${this.state.name}`);
|
|
321
366
|
|
|
322
367
|
return (this.oracleHandler as PrivateExecutionOracle).getPrivateContextInputs();
|
|
@@ -329,7 +374,7 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
329
374
|
// the test. The block therefore gets the *next* block number and timestamp.
|
|
330
375
|
const latestBlockNumber = (await this.stateMachine.node.getBlockHeader('latest'))!.globalVariables.blockNumber;
|
|
331
376
|
const globalVariables = makeGlobalVariables(undefined, {
|
|
332
|
-
blockNumber: latestBlockNumber + 1,
|
|
377
|
+
blockNumber: BlockNumber(latestBlockNumber + 1),
|
|
333
378
|
timestamp: this.nextBlockTimestamp,
|
|
334
379
|
version: this.version,
|
|
335
380
|
chainId: this.chainId,
|
|
@@ -354,9 +399,31 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
354
399
|
// we perform this. We therefore search for known nullifiers now, as otherwise notes that were nullified would not
|
|
355
400
|
// be removed from the database.
|
|
356
401
|
// TODO(#12553): make the synchronizer sync here instead and remove this
|
|
357
|
-
await
|
|
402
|
+
await new NoteService(
|
|
403
|
+
this.noteStore,
|
|
404
|
+
this.stateMachine.node,
|
|
405
|
+
this.stateMachine.anchorBlockStore,
|
|
406
|
+
).syncNoteNullifiers(contractAddress);
|
|
407
|
+
|
|
408
|
+
const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
358
409
|
|
|
359
|
-
this.oracleHandler = new UtilityExecutionOracle(
|
|
410
|
+
this.oracleHandler = new UtilityExecutionOracle(
|
|
411
|
+
contractAddress,
|
|
412
|
+
[],
|
|
413
|
+
[],
|
|
414
|
+
anchorBlockHeader,
|
|
415
|
+
this.contractStore,
|
|
416
|
+
this.noteStore,
|
|
417
|
+
this.keyStore,
|
|
418
|
+
this.addressStore,
|
|
419
|
+
this.stateMachine.node,
|
|
420
|
+
this.stateMachine.anchorBlockStore,
|
|
421
|
+
this.recipientTaggingStore,
|
|
422
|
+
this.senderAddressBookStore,
|
|
423
|
+
this.capsuleStore,
|
|
424
|
+
this.privateEventStore,
|
|
425
|
+
this.currentJobId,
|
|
426
|
+
);
|
|
360
427
|
|
|
361
428
|
this.state = { name: 'UTILITY' };
|
|
362
429
|
this.logger.debug(`Entered state ${this.state.name}`);
|
|
@@ -390,21 +457,14 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
390
457
|
|
|
391
458
|
// We rely on the note cache to determine the effects of the transaction. This is incomplete as it doesn't private
|
|
392
459
|
// 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
|
-
);
|
|
460
|
+
|
|
461
|
+
const txEffect = await makeTxEffect(this.state.noteCache, this.state.nextBlockGlobalVariables.blockNumber);
|
|
398
462
|
|
|
399
463
|
// We build a block holding just this transaction
|
|
400
464
|
const forkedWorldTrees = await this.stateMachine.synchronizer.nativeWorldStateService.fork();
|
|
401
465
|
await insertTxEffectIntoWorldTrees(txEffect, forkedWorldTrees);
|
|
402
466
|
|
|
403
|
-
const block =
|
|
404
|
-
makeAppendOnlyTreeSnapshot(),
|
|
405
|
-
await makeTXEBlockHeader(forkedWorldTrees, this.state.nextBlockGlobalVariables),
|
|
406
|
-
new Body([txEffect]),
|
|
407
|
-
);
|
|
467
|
+
const block = await makeTXEBlock(forkedWorldTrees, this.state.nextBlockGlobalVariables, [txEffect]);
|
|
408
468
|
await this.stateMachine.handleL2Block(block);
|
|
409
469
|
|
|
410
470
|
await forkedWorldTrees.close();
|
|
@@ -429,4 +489,49 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
429
489
|
throw new Error(`Expected to be in state 'UTILITY', but got '${this.state.name}' instead`);
|
|
430
490
|
}
|
|
431
491
|
}
|
|
492
|
+
|
|
493
|
+
private utilityExecutorForContractSync(anchorBlock: any) {
|
|
494
|
+
return async (call: FunctionCall) => {
|
|
495
|
+
const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
|
|
496
|
+
if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
|
|
497
|
+
throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
try {
|
|
501
|
+
const oracle = new UtilityExecutionOracle(
|
|
502
|
+
call.to,
|
|
503
|
+
[],
|
|
504
|
+
[],
|
|
505
|
+
anchorBlock!,
|
|
506
|
+
this.contractStore,
|
|
507
|
+
this.noteStore,
|
|
508
|
+
this.keyStore,
|
|
509
|
+
this.addressStore,
|
|
510
|
+
this.stateMachine.node,
|
|
511
|
+
this.stateMachine.anchorBlockStore,
|
|
512
|
+
this.recipientTaggingStore,
|
|
513
|
+
this.senderAddressBookStore,
|
|
514
|
+
this.capsuleStore,
|
|
515
|
+
this.privateEventStore,
|
|
516
|
+
this.currentJobId,
|
|
517
|
+
);
|
|
518
|
+
await new WASMSimulator()
|
|
519
|
+
.executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, new Oracle(oracle).toACIRCallback())
|
|
520
|
+
.catch((err: Error) => {
|
|
521
|
+
err.message = resolveAssertionMessageFromError(err, entryPointArtifact);
|
|
522
|
+
throw new ExecutionError(
|
|
523
|
+
err.message,
|
|
524
|
+
{
|
|
525
|
+
contractAddress: call.to,
|
|
526
|
+
functionSelector: call.selector,
|
|
527
|
+
},
|
|
528
|
+
extractCallStack(err, entryPointArtifact.debug),
|
|
529
|
+
{ cause: err },
|
|
530
|
+
);
|
|
531
|
+
});
|
|
532
|
+
} catch (err) {
|
|
533
|
+
throw createSimulationError(err instanceof Error ? err : new Error('Unknown error contract data sync'));
|
|
534
|
+
}
|
|
535
|
+
};
|
|
536
|
+
}
|
|
432
537
|
}
|
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, L2BlockNew } 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,50 @@ 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 L2BlockNew 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 L2BlockNew with proper archive chaining
|
|
75
|
+
*/
|
|
76
|
+
export async function makeTXEBlock(
|
|
77
|
+
worldTrees: MerkleTreeWriteOperations,
|
|
78
|
+
globalVariables: GlobalVariables,
|
|
79
|
+
txEffects: TxEffect[],
|
|
80
|
+
): Promise<L2BlockNew> {
|
|
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
|
+
// L2BlockNew requires checkpointNumber and indexWithinCheckpoint
|
|
91
|
+
const checkpointNumber = CheckpointNumber.fromBlockNumber(globalVariables.blockNumber);
|
|
92
|
+
const indexWithinCheckpoint = IndexWithinCheckpoint(0);
|
|
93
|
+
|
|
94
|
+
return new L2BlockNew(newArchive, header, new Body(txEffects), checkpointNumber, indexWithinCheckpoint);
|
|
62
95
|
}
|
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
3
|
import type { ExecutionNoteCache } from '@aztec/pxe/simulator';
|
|
3
4
|
import { computeNoteHashNonce, computeUniqueNoteHash, siloNoteHash } from '@aztec/stdlib/hash';
|
|
4
5
|
import { TxEffect, TxHash } from '@aztec/stdlib/tx';
|
|
5
6
|
|
|
6
|
-
export async function makeTxEffect(
|
|
7
|
-
noteCache: ExecutionNoteCache,
|
|
8
|
-
txRequestHash: Fr,
|
|
9
|
-
txBlockNumber: number,
|
|
10
|
-
): Promise<TxEffect> {
|
|
7
|
+
export async function makeTxEffect(noteCache: ExecutionNoteCache, txBlockNumber: BlockNumber): Promise<TxEffect> {
|
|
11
8
|
const txEffect = TxEffect.empty();
|
|
12
9
|
|
|
13
|
-
|
|
14
|
-
const nonceGenerator = usedTxRequestHashForNonces ? txRequestHash : noteCache.getAllNullifiers()[0];
|
|
10
|
+
noteCache.finish();
|
|
15
11
|
|
|
12
|
+
const nonceGenerator = noteCache.getNonceGenerator();
|
|
16
13
|
txEffect.noteHashes = await Promise.all(
|
|
17
14
|
noteCache
|
|
18
15
|
.getAllNotes()
|
|
@@ -27,10 +24,6 @@ export async function makeTxEffect(
|
|
|
27
24
|
// Nullifiers are already siloed
|
|
28
25
|
txEffect.nullifiers = noteCache.getAllNullifiers();
|
|
29
26
|
|
|
30
|
-
if (usedTxRequestHashForNonces) {
|
|
31
|
-
txEffect.nullifiers.unshift(txRequestHash);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
27
|
txEffect.txHash = new TxHash(new Fr(txBlockNumber));
|
|
35
28
|
|
|
36
29
|
return txEffect;
|