@aztec/txe 0.0.1-commit.fce3e4f → 0.0.1-commit.ffe5b04ea
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 +91 -56
- package/dest/oracle/interfaces.d.ts +33 -29
- package/dest/oracle/interfaces.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.d.ts +16 -16
- package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.js +20 -22
- package/dest/oracle/txe_oracle_top_level_context.d.ts +36 -27
- package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_top_level_context.js +206 -98
- package/dest/rpc_translator.d.ts +91 -79
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +330 -170
- 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 +20 -15
- package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
- package/dest/state_machine/dummy_p2p_client.js +42 -25
- 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 +40 -23
- 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 +26 -15
- package/dest/txe_session.d.ts.map +1 -1
- package/dest/txe_session.js +161 -55
- 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_public_contract_data_source.d.ts +8 -8
- package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
- package/dest/util/txe_public_contract_data_source.js +12 -29
- 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 +103 -63
- package/src/oracle/interfaces.ts +36 -32
- package/src/oracle/txe_oracle_public_context.ts +21 -28
- package/src/oracle/txe_oracle_top_level_context.ts +251 -138
- package/src/rpc_translator.ts +368 -174
- package/src/state_machine/archiver.ts +59 -114
- package/src/state_machine/dummy_p2p_client.ts +58 -33
- package/src/state_machine/global_variable_builder.ts +21 -4
- package/src/state_machine/index.ts +60 -21
- package/src/state_machine/mock_epoch_cache.ts +15 -11
- package/src/state_machine/synchronizer.ts +6 -5
- package/src/txe_session.ts +222 -103
- 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_public_contract_data_source.ts +20 -45
- 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/dest/util/txe_contract_data_provider.js +0 -22
- package/src/util/txe_contract_data_provider.ts +0 -36
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
|
-
import type {
|
|
6
|
+
import type { AccessScopes } from '@aztec/pxe/client/lazy';
|
|
6
7
|
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
AddressStore,
|
|
9
|
+
AnchorBlockStore,
|
|
10
|
+
CapsuleStore,
|
|
11
|
+
ContractStore,
|
|
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,39 @@ 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 { getSingleTxBlockRequestHash, insertTxEffectIntoWorldTrees, makeTXEBlock } from './utils/block_creation.js';
|
|
49
59
|
import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
50
60
|
|
|
51
61
|
/**
|
|
@@ -67,7 +77,6 @@ type SessionState =
|
|
|
67
77
|
| {
|
|
68
78
|
name: 'PRIVATE';
|
|
69
79
|
nextBlockGlobalVariables: GlobalVariables;
|
|
70
|
-
protocolNullifier: Fr;
|
|
71
80
|
noteCache: ExecutionNoteCache;
|
|
72
81
|
taggingIndexCache: ExecutionTaggingIndexCache;
|
|
73
82
|
}
|
|
@@ -102,11 +111,13 @@ export type TXEOracleFunctionName = Exclude<
|
|
|
102
111
|
export interface TXESessionStateHandler {
|
|
103
112
|
enterTopLevelState(): Promise<void>;
|
|
104
113
|
enterPublicState(contractAddress?: AztecAddress): Promise<void>;
|
|
105
|
-
enterPrivateState(contractAddress?: AztecAddress, anchorBlockNumber?:
|
|
114
|
+
enterPrivateState(contractAddress?: AztecAddress, anchorBlockNumber?: BlockNumber): Promise<PrivateContextInputs>;
|
|
106
115
|
enterUtilityState(contractAddress?: AztecAddress): Promise<void>;
|
|
107
|
-
}
|
|
108
116
|
|
|
109
|
-
|
|
117
|
+
// TODO(F-335): Exposing the job info is abstraction breakage - drop the following 2 functions.
|
|
118
|
+
cycleJob(): Promise<string>;
|
|
119
|
+
getCurrentJob(): string;
|
|
120
|
+
}
|
|
110
121
|
|
|
111
122
|
/**
|
|
112
123
|
* A `TXESession` corresponds to a Noir `#[test]` function, and handles all of its oracle calls, stores test-specific
|
|
@@ -124,78 +135,94 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
124
135
|
| IPrivateExecutionOracle
|
|
125
136
|
| IAvmExecutionOracle
|
|
126
137
|
| ITxeExecutionOracle,
|
|
127
|
-
private
|
|
138
|
+
private contractStore: ContractStore,
|
|
139
|
+
private noteStore: NoteStore,
|
|
128
140
|
private keyStore: KeyStore,
|
|
129
|
-
private
|
|
130
|
-
private
|
|
141
|
+
private addressStore: AddressStore,
|
|
142
|
+
private accountStore: TXEAccountStore,
|
|
143
|
+
private senderTaggingStore: SenderTaggingStore,
|
|
144
|
+
private recipientTaggingStore: RecipientTaggingStore,
|
|
145
|
+
private senderAddressBookStore: SenderAddressBookStore,
|
|
146
|
+
private capsuleStore: CapsuleStore,
|
|
147
|
+
private privateEventStore: PrivateEventStore,
|
|
148
|
+
private jobCoordinator: JobCoordinator,
|
|
149
|
+
private currentJobId: string,
|
|
131
150
|
private chainId: Fr,
|
|
132
151
|
private version: Fr,
|
|
133
152
|
private nextBlockTimestamp: bigint,
|
|
134
|
-
private pxeOracleInterface: PXEOracleInterface,
|
|
135
153
|
) {}
|
|
136
154
|
|
|
137
|
-
static async init(
|
|
155
|
+
static async init(contractStore: ContractStore) {
|
|
138
156
|
const store = await openTmpStore('txe-session');
|
|
139
157
|
|
|
140
|
-
const
|
|
141
|
-
const
|
|
142
|
-
const
|
|
143
|
-
const
|
|
144
|
-
const
|
|
145
|
-
const
|
|
158
|
+
const addressStore = new AddressStore(store);
|
|
159
|
+
const privateEventStore = new PrivateEventStore(store);
|
|
160
|
+
const noteStore = new NoteStore(store);
|
|
161
|
+
const senderTaggingStore = new SenderTaggingStore(store);
|
|
162
|
+
const recipientTaggingStore = new RecipientTaggingStore(store);
|
|
163
|
+
const senderAddressBookStore = new SenderAddressBookStore(store);
|
|
164
|
+
const capsuleStore = new CapsuleStore(store);
|
|
146
165
|
const keyStore = new KeyStore(store);
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
//
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
166
|
+
const accountStore = new TXEAccountStore(store);
|
|
167
|
+
|
|
168
|
+
// Create job coordinator and register staged stores
|
|
169
|
+
const jobCoordinator = new JobCoordinator(store);
|
|
170
|
+
jobCoordinator.registerStores([
|
|
171
|
+
capsuleStore,
|
|
172
|
+
senderTaggingStore,
|
|
173
|
+
recipientTaggingStore,
|
|
174
|
+
privateEventStore,
|
|
175
|
+
noteStore,
|
|
176
|
+
]);
|
|
177
|
+
|
|
178
|
+
const archiver = new TXEArchiver(store);
|
|
179
|
+
const anchorBlockStore = new AnchorBlockStore(store);
|
|
180
|
+
const stateMachine = await TXEStateMachine.create(archiver, anchorBlockStore, contractStore, noteStore);
|
|
156
181
|
|
|
157
182
|
const nextBlockTimestamp = BigInt(Math.floor(new Date().getTime() / 1000));
|
|
158
183
|
const version = new Fr(await stateMachine.node.getVersion());
|
|
159
184
|
const chainId = new Fr(await stateMachine.node.getChainId());
|
|
160
185
|
|
|
161
|
-
const
|
|
162
|
-
stateMachine.node,
|
|
163
|
-
keyStore,
|
|
164
|
-
contractDataProvider,
|
|
165
|
-
noteDataProvider,
|
|
166
|
-
capsuleDataProvider,
|
|
167
|
-
stateMachine.syncDataProvider,
|
|
168
|
-
taggingDataProvider,
|
|
169
|
-
addressDataProvider,
|
|
170
|
-
privateEventDataProvider,
|
|
171
|
-
);
|
|
186
|
+
const initialJobId = jobCoordinator.beginJob();
|
|
172
187
|
|
|
173
188
|
const topLevelOracleHandler = new TXEOracleTopLevelContext(
|
|
174
189
|
stateMachine,
|
|
175
|
-
|
|
190
|
+
contractStore,
|
|
191
|
+
noteStore,
|
|
176
192
|
keyStore,
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
193
|
+
addressStore,
|
|
194
|
+
accountStore,
|
|
195
|
+
senderTaggingStore,
|
|
196
|
+
recipientTaggingStore,
|
|
197
|
+
senderAddressBookStore,
|
|
198
|
+
capsuleStore,
|
|
199
|
+
privateEventStore,
|
|
180
200
|
nextBlockTimestamp,
|
|
181
201
|
version,
|
|
182
202
|
chainId,
|
|
183
203
|
new Map(),
|
|
184
204
|
);
|
|
185
|
-
await topLevelOracleHandler.
|
|
205
|
+
await topLevelOracleHandler.advanceBlocksBy(1);
|
|
186
206
|
|
|
187
207
|
return new TXESession(
|
|
188
208
|
createLogger('txe:session'),
|
|
189
209
|
stateMachine,
|
|
190
210
|
topLevelOracleHandler,
|
|
191
|
-
|
|
211
|
+
contractStore,
|
|
212
|
+
noteStore,
|
|
192
213
|
keyStore,
|
|
193
|
-
|
|
194
|
-
|
|
214
|
+
addressStore,
|
|
215
|
+
accountStore,
|
|
216
|
+
senderTaggingStore,
|
|
217
|
+
recipientTaggingStore,
|
|
218
|
+
senderAddressBookStore,
|
|
219
|
+
capsuleStore,
|
|
220
|
+
privateEventStore,
|
|
221
|
+
jobCoordinator,
|
|
222
|
+
initialJobId,
|
|
195
223
|
version,
|
|
196
224
|
chainId,
|
|
197
225
|
nextBlockTimestamp,
|
|
198
|
-
pxeOracleInterface,
|
|
199
226
|
);
|
|
200
227
|
}
|
|
201
228
|
|
|
@@ -230,6 +257,17 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
230
257
|
}
|
|
231
258
|
}
|
|
232
259
|
|
|
260
|
+
getCurrentJob(): string {
|
|
261
|
+
return this.currentJobId;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/** Commits the current job and begins a new one. Returns the new job ID. */
|
|
265
|
+
async cycleJob(): Promise<string> {
|
|
266
|
+
await this.jobCoordinator.commitJob(this.currentJobId);
|
|
267
|
+
this.currentJobId = this.jobCoordinator.beginJob();
|
|
268
|
+
return this.currentJobId;
|
|
269
|
+
}
|
|
270
|
+
|
|
233
271
|
async enterTopLevelState() {
|
|
234
272
|
switch (this.state.name) {
|
|
235
273
|
case 'PRIVATE': {
|
|
@@ -252,13 +290,21 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
252
290
|
}
|
|
253
291
|
}
|
|
254
292
|
|
|
293
|
+
// Commit all staged stores from the job that was just completed, then begin a new job
|
|
294
|
+
await this.cycleJob();
|
|
295
|
+
|
|
255
296
|
this.oracleHandler = new TXEOracleTopLevelContext(
|
|
256
297
|
this.stateMachine,
|
|
257
|
-
this.
|
|
298
|
+
this.contractStore,
|
|
299
|
+
this.noteStore,
|
|
258
300
|
this.keyStore,
|
|
259
|
-
this.
|
|
260
|
-
this.
|
|
261
|
-
this.
|
|
301
|
+
this.addressStore,
|
|
302
|
+
this.accountStore,
|
|
303
|
+
this.senderTaggingStore,
|
|
304
|
+
this.recipientTaggingStore,
|
|
305
|
+
this.senderAddressBookStore,
|
|
306
|
+
this.capsuleStore,
|
|
307
|
+
this.privateEventStore,
|
|
262
308
|
this.nextBlockTimestamp,
|
|
263
309
|
this.version,
|
|
264
310
|
this.chainId,
|
|
@@ -271,25 +317,23 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
271
317
|
|
|
272
318
|
async enterPrivateState(
|
|
273
319
|
contractAddress: AztecAddress = DEFAULT_ADDRESS,
|
|
274
|
-
anchorBlockNumber?:
|
|
320
|
+
anchorBlockNumber?: BlockNumber,
|
|
275
321
|
): Promise<PrivateContextInputs> {
|
|
276
322
|
this.exitTopLevelState();
|
|
277
323
|
|
|
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
324
|
// Private execution has two associated block numbers: the anchor block (i.e. the historical block that is used to
|
|
286
325
|
// build the proof), and the *next* block, i.e. the one we'll create once the execution ends, and which will contain
|
|
287
326
|
// a single transaction with the effects of what was done in the test.
|
|
288
327
|
const anchorBlock = await this.stateMachine.node.getBlockHeader(anchorBlockNumber ?? 'latest');
|
|
328
|
+
|
|
329
|
+
await new NoteService(this.noteStore, this.stateMachine.node, anchorBlock!, this.currentJobId).syncNoteNullifiers(
|
|
330
|
+
contractAddress,
|
|
331
|
+
'ALL_SCOPES',
|
|
332
|
+
);
|
|
289
333
|
const latestBlock = await this.stateMachine.node.getBlockHeader('latest');
|
|
290
334
|
|
|
291
335
|
const nextBlockGlobalVariables = makeGlobalVariables(undefined, {
|
|
292
|
-
blockNumber: latestBlock!.globalVariables.blockNumber + 1,
|
|
336
|
+
blockNumber: BlockNumber(latestBlock!.globalVariables.blockNumber + 1),
|
|
293
337
|
timestamp: this.nextBlockTimestamp,
|
|
294
338
|
version: this.version,
|
|
295
339
|
chainId: this.chainId,
|
|
@@ -300,25 +344,39 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
300
344
|
const noteCache = new ExecutionNoteCache(protocolNullifier);
|
|
301
345
|
const taggingIndexCache = new ExecutionTaggingIndexCache();
|
|
302
346
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
new
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
347
|
+
const utilityExecutor = this.utilityExecutorForContractSync(anchorBlock);
|
|
348
|
+
this.oracleHandler = new PrivateExecutionOracle({
|
|
349
|
+
argsHash: Fr.ZERO,
|
|
350
|
+
txContext: new TxContext(this.chainId, this.version, GasSettings.empty()),
|
|
351
|
+
callContext: new CallContext(AztecAddress.ZERO, contractAddress, FunctionSelector.empty(), false),
|
|
352
|
+
anchorBlockHeader: anchorBlock!,
|
|
353
|
+
utilityExecutor,
|
|
354
|
+
authWitnesses: [],
|
|
355
|
+
capsules: [],
|
|
356
|
+
executionCache: new HashedValuesCache(),
|
|
311
357
|
noteCache,
|
|
312
358
|
taggingIndexCache,
|
|
313
|
-
this.
|
|
314
|
-
|
|
359
|
+
contractStore: this.contractStore,
|
|
360
|
+
noteStore: this.noteStore,
|
|
361
|
+
keyStore: this.keyStore,
|
|
362
|
+
addressStore: this.addressStore,
|
|
363
|
+
aztecNode: this.stateMachine.node,
|
|
364
|
+
senderTaggingStore: this.senderTaggingStore,
|
|
365
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
366
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
367
|
+
capsuleStore: this.capsuleStore,
|
|
368
|
+
privateEventStore: this.privateEventStore,
|
|
369
|
+
contractSyncService: this.stateMachine.contractSyncService,
|
|
370
|
+
jobId: this.currentJobId,
|
|
371
|
+
scopes: 'ALL_SCOPES',
|
|
372
|
+
});
|
|
315
373
|
|
|
316
374
|
// We store the note and tagging index caches fed into the PrivateExecutionOracle (along with some other auxiliary
|
|
317
375
|
// data) in order to refer to it later, mimicking the way this object is used by the ContractFunctionSimulator. The
|
|
318
376
|
// difference resides in that the simulator has all information needed in order to run the simulation, while ours
|
|
319
377
|
// will be ongoing as the different oracles will be invoked from the Noir test, until eventually the private
|
|
320
378
|
// execution finishes.
|
|
321
|
-
this.state = { name: 'PRIVATE', nextBlockGlobalVariables,
|
|
379
|
+
this.state = { name: 'PRIVATE', nextBlockGlobalVariables, noteCache, taggingIndexCache };
|
|
322
380
|
this.logger.debug(`Entered state ${this.state.name}`);
|
|
323
381
|
|
|
324
382
|
return (this.oracleHandler as PrivateExecutionOracle).getPrivateContextInputs();
|
|
@@ -331,7 +389,7 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
331
389
|
// the test. The block therefore gets the *next* block number and timestamp.
|
|
332
390
|
const latestBlockNumber = (await this.stateMachine.node.getBlockHeader('latest'))!.globalVariables.blockNumber;
|
|
333
391
|
const globalVariables = makeGlobalVariables(undefined, {
|
|
334
|
-
blockNumber: latestBlockNumber + 1,
|
|
392
|
+
blockNumber: BlockNumber(latestBlockNumber + 1),
|
|
335
393
|
timestamp: this.nextBlockTimestamp,
|
|
336
394
|
version: this.version,
|
|
337
395
|
chainId: this.chainId,
|
|
@@ -351,14 +409,37 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
351
409
|
async enterUtilityState(contractAddress: AztecAddress = DEFAULT_ADDRESS) {
|
|
352
410
|
this.exitTopLevelState();
|
|
353
411
|
|
|
412
|
+
const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
413
|
+
|
|
354
414
|
// There is no automatic message discovery and contract-driven syncing process in inlined private or utility
|
|
355
415
|
// contexts, which means that known nullifiers are also not searched for, since it is during the tagging sync that
|
|
356
416
|
// we perform this. We therefore search for known nullifiers now, as otherwise notes that were nullified would not
|
|
357
417
|
// be removed from the database.
|
|
358
418
|
// TODO(#12553): make the synchronizer sync here instead and remove this
|
|
359
|
-
await
|
|
360
|
-
|
|
361
|
-
|
|
419
|
+
await new NoteService(
|
|
420
|
+
this.noteStore,
|
|
421
|
+
this.stateMachine.node,
|
|
422
|
+
anchorBlockHeader,
|
|
423
|
+
this.currentJobId,
|
|
424
|
+
).syncNoteNullifiers(contractAddress, 'ALL_SCOPES');
|
|
425
|
+
|
|
426
|
+
this.oracleHandler = new UtilityExecutionOracle({
|
|
427
|
+
contractAddress,
|
|
428
|
+
authWitnesses: [],
|
|
429
|
+
capsules: [],
|
|
430
|
+
anchorBlockHeader,
|
|
431
|
+
contractStore: this.contractStore,
|
|
432
|
+
noteStore: this.noteStore,
|
|
433
|
+
keyStore: this.keyStore,
|
|
434
|
+
addressStore: this.addressStore,
|
|
435
|
+
aztecNode: this.stateMachine.node,
|
|
436
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
437
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
438
|
+
capsuleStore: this.capsuleStore,
|
|
439
|
+
privateEventStore: this.privateEventStore,
|
|
440
|
+
jobId: this.currentJobId,
|
|
441
|
+
scopes: 'ALL_SCOPES',
|
|
442
|
+
});
|
|
362
443
|
|
|
363
444
|
this.state = { name: 'UTILITY' };
|
|
364
445
|
this.logger.debug(`Entered state ${this.state.name}`);
|
|
@@ -371,8 +452,8 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
371
452
|
|
|
372
453
|
// Note that while all public and private contexts do is build a single block that we then process when exiting
|
|
373
454
|
// those, the top level context performs a large number of actions not captured in the following 'close' call. Among
|
|
374
|
-
// others, it will create empty blocks (via `
|
|
375
|
-
// `
|
|
455
|
+
// others, it will create empty blocks (via `advanceBlocksBy` and `deploy`), create blocks with transactions via
|
|
456
|
+
// `privateCallNewFlow` and `publicCallNewFlow`, add accounts to PXE via `addAccount`, etc. This is a
|
|
376
457
|
// slight inconsistency in the working model of this class, but is not too bad.
|
|
377
458
|
// TODO: it's quite unfortunate that we need to capture the authwits created to later pass them again when the top
|
|
378
459
|
// level context is re-created. This is because authwits create a temporary utility context that'd otherwise reset
|
|
@@ -392,21 +473,14 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
392
473
|
|
|
393
474
|
// We rely on the note cache to determine the effects of the transaction. This is incomplete as it doesn't private
|
|
394
475
|
// 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
|
-
);
|
|
476
|
+
|
|
477
|
+
const txEffect = await makeTxEffect(this.state.noteCache, this.state.nextBlockGlobalVariables.blockNumber);
|
|
400
478
|
|
|
401
479
|
// We build a block holding just this transaction
|
|
402
480
|
const forkedWorldTrees = await this.stateMachine.synchronizer.nativeWorldStateService.fork();
|
|
403
481
|
await insertTxEffectIntoWorldTrees(txEffect, forkedWorldTrees);
|
|
404
482
|
|
|
405
|
-
const block =
|
|
406
|
-
makeAppendOnlyTreeSnapshot(),
|
|
407
|
-
await makeTXEBlockHeader(forkedWorldTrees, this.state.nextBlockGlobalVariables),
|
|
408
|
-
new Body([txEffect]),
|
|
409
|
-
);
|
|
483
|
+
const block = await makeTXEBlock(forkedWorldTrees, this.state.nextBlockGlobalVariables, [txEffect]);
|
|
410
484
|
await this.stateMachine.handleL2Block(block);
|
|
411
485
|
|
|
412
486
|
await forkedWorldTrees.close();
|
|
@@ -431,4 +505,49 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
431
505
|
throw new Error(`Expected to be in state 'UTILITY', but got '${this.state.name}' instead`);
|
|
432
506
|
}
|
|
433
507
|
}
|
|
508
|
+
|
|
509
|
+
private utilityExecutorForContractSync(anchorBlock: any) {
|
|
510
|
+
return async (call: FunctionCall, scopes: AccessScopes) => {
|
|
511
|
+
const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
|
|
512
|
+
if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
|
|
513
|
+
throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
try {
|
|
517
|
+
const oracle = new UtilityExecutionOracle({
|
|
518
|
+
contractAddress: call.to,
|
|
519
|
+
authWitnesses: [],
|
|
520
|
+
capsules: [],
|
|
521
|
+
anchorBlockHeader: anchorBlock!,
|
|
522
|
+
contractStore: this.contractStore,
|
|
523
|
+
noteStore: this.noteStore,
|
|
524
|
+
keyStore: this.keyStore,
|
|
525
|
+
addressStore: this.addressStore,
|
|
526
|
+
aztecNode: this.stateMachine.node,
|
|
527
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
528
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
529
|
+
capsuleStore: this.capsuleStore,
|
|
530
|
+
privateEventStore: this.privateEventStore,
|
|
531
|
+
jobId: this.currentJobId,
|
|
532
|
+
scopes,
|
|
533
|
+
});
|
|
534
|
+
await new WASMSimulator()
|
|
535
|
+
.executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, new Oracle(oracle).toACIRCallback())
|
|
536
|
+
.catch((err: Error) => {
|
|
537
|
+
err.message = resolveAssertionMessageFromError(err, entryPointArtifact);
|
|
538
|
+
throw new ExecutionError(
|
|
539
|
+
err.message,
|
|
540
|
+
{
|
|
541
|
+
contractAddress: call.to,
|
|
542
|
+
functionSelector: call.selector,
|
|
543
|
+
},
|
|
544
|
+
extractCallStack(err, entryPointArtifact.debug),
|
|
545
|
+
{ cause: err },
|
|
546
|
+
);
|
|
547
|
+
});
|
|
548
|
+
} catch (err) {
|
|
549
|
+
throw createSimulationError(err instanceof Error ? err : new Error('Unknown error contract data sync'));
|
|
550
|
+
}
|
|
551
|
+
};
|
|
552
|
+
}
|
|
434
553
|
}
|
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,68 +1,43 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
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';
|
|
4
|
+
import { type ContractArtifact, FunctionSelector } from '@aztec/stdlib/abi';
|
|
4
5
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
|
-
import {
|
|
6
|
-
type ContractClassPublic,
|
|
7
|
-
type ContractDataSource,
|
|
8
|
-
type ContractInstanceWithAddress,
|
|
9
|
-
computePrivateFunctionsRoot,
|
|
10
|
-
computePublicBytecodeCommitment,
|
|
11
|
-
getContractClassPrivateFunctionFromArtifact,
|
|
12
|
-
} from '@aztec/stdlib/contract';
|
|
6
|
+
import type { ContractClassPublic, ContractDataSource, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
13
7
|
|
|
14
8
|
export class TXEPublicContractDataSource implements ContractDataSource {
|
|
15
|
-
#privateFunctionsRoot: Map<string, Buffer> = new Map();
|
|
16
9
|
constructor(
|
|
17
|
-
private blockNumber:
|
|
18
|
-
private
|
|
10
|
+
private blockNumber: BlockNumber,
|
|
11
|
+
private contractStore: ContractStore,
|
|
19
12
|
) {}
|
|
20
13
|
|
|
21
|
-
getBlockNumber(): Promise<
|
|
14
|
+
getBlockNumber(): Promise<BlockNumber> {
|
|
22
15
|
return Promise.resolve(this.blockNumber);
|
|
23
16
|
}
|
|
24
17
|
|
|
25
18
|
async getContractClass(id: Fr): Promise<ContractClassPublic | undefined> {
|
|
26
|
-
const contractClass = await this.
|
|
19
|
+
const contractClass = await this.contractStore.getContractClassWithPreimage(id);
|
|
27
20
|
if (!contractClass) {
|
|
28
21
|
return;
|
|
29
22
|
}
|
|
30
|
-
const artifact = await this.contractDataProvider.getContractArtifact(id);
|
|
31
|
-
if (!artifact) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
let privateFunctionsRoot;
|
|
36
|
-
if (!this.#privateFunctionsRoot.has(id.toString())) {
|
|
37
|
-
const privateFunctions = await Promise.all(
|
|
38
|
-
artifact.functions
|
|
39
|
-
.filter(fn => fn.functionType === FunctionType.PRIVATE)
|
|
40
|
-
.map(fn => getContractClassPrivateFunctionFromArtifact(fn)),
|
|
41
|
-
);
|
|
42
|
-
privateFunctionsRoot = await computePrivateFunctionsRoot(privateFunctions);
|
|
43
|
-
this.#privateFunctionsRoot.set(id.toString(), privateFunctionsRoot.toBuffer());
|
|
44
|
-
} else {
|
|
45
|
-
privateFunctionsRoot = Fr.fromBuffer(this.#privateFunctionsRoot.get(id.toString())!);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
23
|
return {
|
|
49
|
-
id,
|
|
50
|
-
artifactHash: contractClass
|
|
51
|
-
packedBytecode: contractClass
|
|
52
|
-
privateFunctionsRoot,
|
|
53
|
-
version: contractClass
|
|
24
|
+
id: contractClass.id,
|
|
25
|
+
artifactHash: contractClass.artifactHash,
|
|
26
|
+
packedBytecode: contractClass.packedBytecode,
|
|
27
|
+
privateFunctionsRoot: contractClass.privateFunctionsRoot,
|
|
28
|
+
version: contractClass.version,
|
|
54
29
|
privateFunctions: [],
|
|
55
30
|
utilityFunctions: [],
|
|
56
31
|
};
|
|
57
32
|
}
|
|
58
33
|
|
|
59
34
|
async getBytecodeCommitment(id: Fr): Promise<Fr | undefined> {
|
|
60
|
-
const contractClass = await this.
|
|
61
|
-
return contractClass
|
|
35
|
+
const contractClass = await this.contractStore.getContractClassWithPreimage(id);
|
|
36
|
+
return contractClass?.publicBytecodeCommitment;
|
|
62
37
|
}
|
|
63
38
|
|
|
64
39
|
async getContract(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
|
|
65
|
-
const instance = await this.
|
|
40
|
+
const instance = await this.contractStore.getContractInstance(address);
|
|
66
41
|
return instance && { ...instance, address };
|
|
67
42
|
}
|
|
68
43
|
|
|
@@ -71,12 +46,12 @@ export class TXEPublicContractDataSource implements ContractDataSource {
|
|
|
71
46
|
}
|
|
72
47
|
|
|
73
48
|
async getContractArtifact(address: AztecAddress): Promise<ContractArtifact | undefined> {
|
|
74
|
-
const instance = await this.
|
|
75
|
-
return instance && this.
|
|
49
|
+
const instance = await this.contractStore.getContractInstance(address);
|
|
50
|
+
return instance && this.contractStore.getContractArtifact(instance.currentContractClassId);
|
|
76
51
|
}
|
|
77
52
|
|
|
78
53
|
async getDebugFunctionName(address: AztecAddress, selector: FunctionSelector): Promise<string | undefined> {
|
|
79
|
-
return await this.
|
|
54
|
+
return await this.contractStore.getDebugFunctionName(address, selector);
|
|
80
55
|
}
|
|
81
56
|
|
|
82
57
|
registerContractFunctionSignatures(_signatures: []): Promise<void> {
|