@aztec/txe 0.0.1-commit.d1f2d6c → 0.0.1-commit.d20b825a7
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/index.d.ts +1 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +88 -54
- package/dest/oracle/interfaces.d.ts +32 -28
- package/dest/oracle/interfaces.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.d.ts +13 -13
- package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.js +14 -15
- package/dest/oracle/txe_oracle_top_level_context.d.ts +30 -23
- package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_top_level_context.js +164 -65
- package/dest/rpc_translator.d.ts +129 -83
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +486 -175
- package/dest/state_machine/archiver.d.ts +4 -4
- package/dest/state_machine/archiver.d.ts.map +1 -1
- package/dest/state_machine/archiver.js +10 -12
- package/dest/state_machine/dummy_p2p_client.d.ts +18 -13
- package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
- package/dest/state_machine/dummy_p2p_client.js +33 -18
- package/dest/state_machine/global_variable_builder.d.ts +9 -4
- package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
- package/dest/state_machine/global_variable_builder.js +9 -3
- package/dest/state_machine/index.d.ts +7 -5
- package/dest/state_machine/index.d.ts.map +1 -1
- package/dest/state_machine/index.js +36 -18
- package/dest/state_machine/mock_epoch_cache.d.ts +20 -3
- package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
- package/dest/state_machine/mock_epoch_cache.js +39 -2
- package/dest/state_machine/synchronizer.d.ts +5 -5
- package/dest/state_machine/synchronizer.d.ts.map +1 -1
- package/dest/state_machine/synchronizer.js +3 -3
- package/dest/txe_session.d.ts +54 -6
- package/dest/txe_session.d.ts.map +1 -1
- package/dest/txe_session.js +152 -28
- package/dest/util/encoding.d.ts +71 -1
- package/dest/util/encoding.d.ts.map +1 -1
- package/dest/util/encoding.js +4 -0
- package/dest/util/txe_public_contract_data_source.d.ts +2 -3
- package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
- package/dest/util/txe_public_contract_data_source.js +6 -25
- package/dest/utils/block_creation.d.ts +1 -1
- package/dest/utils/block_creation.d.ts.map +1 -1
- package/dest/utils/block_creation.js +3 -1
- package/package.json +15 -15
- package/src/index.ts +89 -52
- package/src/oracle/interfaces.ts +33 -32
- package/src/oracle/txe_oracle_public_context.ts +14 -16
- package/src/oracle/txe_oracle_top_level_context.ts +196 -116
- package/src/rpc_translator.ts +563 -202
- package/src/state_machine/archiver.ts +10 -11
- package/src/state_machine/dummy_p2p_client.ts +46 -24
- package/src/state_machine/global_variable_builder.ts +18 -3
- package/src/state_machine/index.ts +54 -18
- package/src/state_machine/mock_epoch_cache.ts +51 -3
- package/src/state_machine/synchronizer.ts +4 -4
- package/src/txe_session.ts +223 -88
- package/src/util/encoding.ts +5 -0
- package/src/util/txe_public_contract_data_source.ts +10 -38
- package/src/utils/block_creation.ts +3 -1
- package/dest/util/txe_contract_store.d.ts +0 -12
- package/dest/util/txe_contract_store.d.ts.map +0 -1
- package/dest/util/txe_contract_store.js +0 -22
- package/src/util/txe_contract_store.ts +0 -36
package/src/txe_session.ts
CHANGED
|
@@ -3,10 +3,12 @@ import { Fr } from '@aztec/foundation/curves/bn254';
|
|
|
3
3
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
4
4
|
import { KeyStore } from '@aztec/key-store';
|
|
5
5
|
import { openTmpStore } from '@aztec/kv-store/lmdb-v2';
|
|
6
|
-
import type { ProtocolContract } from '@aztec/protocol-contracts';
|
|
7
6
|
import {
|
|
8
7
|
AddressStore,
|
|
8
|
+
AnchorBlockStore,
|
|
9
|
+
CapsuleService,
|
|
9
10
|
CapsuleStore,
|
|
11
|
+
ContractStore,
|
|
10
12
|
JobCoordinator,
|
|
11
13
|
NoteService,
|
|
12
14
|
NoteStore,
|
|
@@ -40,7 +42,7 @@ import { GasSettings } from '@aztec/stdlib/gas';
|
|
|
40
42
|
import { computeProtocolNullifier } from '@aztec/stdlib/hash';
|
|
41
43
|
import { PrivateContextInputs } from '@aztec/stdlib/kernel';
|
|
42
44
|
import { makeGlobalVariables } from '@aztec/stdlib/testing';
|
|
43
|
-
import { CallContext, GlobalVariables, TxContext } from '@aztec/stdlib/tx';
|
|
45
|
+
import { CallContext, GlobalVariables, OFFCHAIN_MESSAGE_IDENTIFIER, TxContext } from '@aztec/stdlib/tx';
|
|
44
46
|
|
|
45
47
|
import { z } from 'zod';
|
|
46
48
|
|
|
@@ -49,10 +51,10 @@ import type { IAvmExecutionOracle, ITxeExecutionOracle } from './oracle/interfac
|
|
|
49
51
|
import { TXEOraclePublicContext } from './oracle/txe_oracle_public_context.js';
|
|
50
52
|
import { TXEOracleTopLevelContext } from './oracle/txe_oracle_top_level_context.js';
|
|
51
53
|
import { RPCTranslator } from './rpc_translator.js';
|
|
54
|
+
import { TXEArchiver } from './state_machine/archiver.js';
|
|
52
55
|
import { TXEStateMachine } from './state_machine/index.js';
|
|
53
56
|
import type { ForeignCallArgs, ForeignCallResult } from './util/encoding.js';
|
|
54
57
|
import { TXEAccountStore } from './util/txe_account_store.js';
|
|
55
|
-
import { TXEContractStore } from './util/txe_contract_store.js';
|
|
56
58
|
import { getSingleTxBlockRequestHash, insertTxEffectIntoWorldTrees, makeTXEBlock } from './utils/block_creation.js';
|
|
57
59
|
import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
58
60
|
|
|
@@ -111,6 +113,69 @@ export interface TXESessionStateHandler {
|
|
|
111
113
|
enterPublicState(contractAddress?: AztecAddress): Promise<void>;
|
|
112
114
|
enterPrivateState(contractAddress?: AztecAddress, anchorBlockNumber?: BlockNumber): Promise<PrivateContextInputs>;
|
|
113
115
|
enterUtilityState(contractAddress?: AztecAddress): Promise<void>;
|
|
116
|
+
|
|
117
|
+
// TODO(F-335): Exposing the job info is abstraction breakage - drop the following 2 functions.
|
|
118
|
+
cycleJob(): Promise<string>;
|
|
119
|
+
getCurrentJob(): string;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Runs an executor-style top-level call (private/public call, utility execution) with last-call tracking.
|
|
123
|
+
*/
|
|
124
|
+
withTopLevelCallTracking<T>(work: () => Promise<{ result: T; txHash?: Fr }>): Promise<T>;
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Captures a raw offchain effect payload for consumption from test environment. Called by the `emit_offchain_effect`
|
|
128
|
+
* oracle handler whenever a contract function emits an offchain message, at any call depth.
|
|
129
|
+
*/
|
|
130
|
+
recordOffchainEffect(data: Fr[]): void;
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Returns the raw offchain effect payloads emitted by the last top-level call. Each payload follows the protocol
|
|
134
|
+
* convention documented on `OFFCHAIN_MESSAGE_IDENTIFIER`, i.e. `[identifier, recipient, ...ciphertext]`. Decoding into
|
|
135
|
+
* `OffchainMessage` structs happens on the Noir side of the test helper. Marks the buffer as queried so the
|
|
136
|
+
* unqueried-messages warning doesn't fire on the next reset.
|
|
137
|
+
*/
|
|
138
|
+
getLastCallOffchainEffects(): { effects: Fr[][] };
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Returns the context of the last top-level call: its tx hash (`Fr.ZERO` if the call was tx-less) and the anchor
|
|
142
|
+
* block timestamp captured at the start of the call. Does *not* mark the buffer as queried — context reads are
|
|
143
|
+
* metadata, not effect consumption.
|
|
144
|
+
*/
|
|
145
|
+
getLastCallContext(): { txHash: Fr; anchorBlockTimestamp: bigint };
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Session state tracking the most recently completed top-level call: the offchain effect buffer it produced, and the
|
|
150
|
+
* call's context (tx hash + anchor block timestamp). The context is refreshed on every top-level call, independently
|
|
151
|
+
* of whether the call produced offchain effects.
|
|
152
|
+
*/
|
|
153
|
+
interface LastCallState {
|
|
154
|
+
/**
|
|
155
|
+
* Raw offchain effect payloads emitted by the currently-executing (or most recently completed) top-level call. Wiped
|
|
156
|
+
* at the start of every top-level entry point, appended to on every `emit_offchain_effect` oracle invocation.
|
|
157
|
+
*/
|
|
158
|
+
offchainEffects: Fr[][];
|
|
159
|
+
/**
|
|
160
|
+
* Tracks whether the test has queried `effects` since the last reset. If a new top-level call clobbers the buffer
|
|
161
|
+
* without it being queried first, any accumulated messages are lost and we emit a warning so tests don't silently
|
|
162
|
+
* drop delivery.
|
|
163
|
+
*/
|
|
164
|
+
queried: boolean;
|
|
165
|
+
/**
|
|
166
|
+
* Tx hash of the most recently completed top-level call, or `Fr.ZERO` if the call was tx-less (context setters,
|
|
167
|
+
* utility execution). Populated by call executor handlers after execution completes.
|
|
168
|
+
*/
|
|
169
|
+
txHash: Fr;
|
|
170
|
+
/**
|
|
171
|
+
* Anchor block timestamp of the most recently completed top-level call, captured from the anchor block header that
|
|
172
|
+
* was active when the call started. Populated by call executor handlers after execution completes.
|
|
173
|
+
*/
|
|
174
|
+
anchorBlockTimestamp: bigint;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function emptyLastCallState(): LastCallState {
|
|
178
|
+
return { offchainEffects: [], queried: false, txHash: Fr.ZERO, anchorBlockTimestamp: 0n };
|
|
114
179
|
}
|
|
115
180
|
|
|
116
181
|
/**
|
|
@@ -120,6 +185,7 @@ export interface TXESessionStateHandler {
|
|
|
120
185
|
export class TXESession implements TXESessionStateHandler {
|
|
121
186
|
private state: SessionState = { name: 'TOP_LEVEL' };
|
|
122
187
|
private authwits: Map<string, AuthWitness> = new Map();
|
|
188
|
+
private lastCallInfo: LastCallState = emptyLastCallState();
|
|
123
189
|
|
|
124
190
|
constructor(
|
|
125
191
|
private logger: Logger,
|
|
@@ -129,7 +195,7 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
129
195
|
| IPrivateExecutionOracle
|
|
130
196
|
| IAvmExecutionOracle
|
|
131
197
|
| ITxeExecutionOracle,
|
|
132
|
-
private contractStore:
|
|
198
|
+
private contractStore: ContractStore,
|
|
133
199
|
private noteStore: NoteStore,
|
|
134
200
|
private keyStore: KeyStore,
|
|
135
201
|
private addressStore: AddressStore,
|
|
@@ -146,12 +212,11 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
146
212
|
private nextBlockTimestamp: bigint,
|
|
147
213
|
) {}
|
|
148
214
|
|
|
149
|
-
static async init(
|
|
215
|
+
static async init(contractStore: ContractStore) {
|
|
150
216
|
const store = await openTmpStore('txe-session');
|
|
151
217
|
|
|
152
218
|
const addressStore = new AddressStore(store);
|
|
153
219
|
const privateEventStore = new PrivateEventStore(store);
|
|
154
|
-
const contractStore = new TXEContractStore(store);
|
|
155
220
|
const noteStore = new NoteStore(store);
|
|
156
221
|
const senderTaggingStore = new SenderTaggingStore(store);
|
|
157
222
|
const recipientTaggingStore = new RecipientTaggingStore(store);
|
|
@@ -170,13 +235,9 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
170
235
|
noteStore,
|
|
171
236
|
]);
|
|
172
237
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
await contractStore.addContractInstance(instance);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
const stateMachine = await TXEStateMachine.create(store);
|
|
238
|
+
const archiver = new TXEArchiver(store);
|
|
239
|
+
const anchorBlockStore = new AnchorBlockStore(store);
|
|
240
|
+
const stateMachine = await TXEStateMachine.create(archiver, anchorBlockStore, contractStore, noteStore);
|
|
180
241
|
|
|
181
242
|
const nextBlockTimestamp = BigInt(Math.floor(new Date().getTime() / 1000));
|
|
182
243
|
const version = new Fr(await stateMachine.node.getVersion());
|
|
@@ -184,6 +245,8 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
184
245
|
|
|
185
246
|
const initialJobId = jobCoordinator.beginJob();
|
|
186
247
|
|
|
248
|
+
const logger = createLogger('txe:session');
|
|
249
|
+
|
|
187
250
|
const topLevelOracleHandler = new TXEOracleTopLevelContext(
|
|
188
251
|
stateMachine,
|
|
189
252
|
contractStore,
|
|
@@ -196,16 +259,15 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
196
259
|
senderAddressBookStore,
|
|
197
260
|
capsuleStore,
|
|
198
261
|
privateEventStore,
|
|
199
|
-
initialJobId,
|
|
200
262
|
nextBlockTimestamp,
|
|
201
263
|
version,
|
|
202
264
|
chainId,
|
|
203
265
|
new Map(),
|
|
204
266
|
);
|
|
205
|
-
await topLevelOracleHandler.
|
|
267
|
+
await topLevelOracleHandler.advanceBlocksBy(1);
|
|
206
268
|
|
|
207
269
|
return new TXESession(
|
|
208
|
-
|
|
270
|
+
logger,
|
|
209
271
|
stateMachine,
|
|
210
272
|
topLevelOracleHandler,
|
|
211
273
|
contractStore,
|
|
@@ -257,6 +319,61 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
257
319
|
}
|
|
258
320
|
}
|
|
259
321
|
|
|
322
|
+
getCurrentJob(): string {
|
|
323
|
+
return this.currentJobId;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/** Commits the current job and begins a new one. Returns the new job ID. */
|
|
327
|
+
async cycleJob(): Promise<string> {
|
|
328
|
+
await this.jobCoordinator.commitJob(this.currentJobId);
|
|
329
|
+
this.currentJobId = this.jobCoordinator.beginJob();
|
|
330
|
+
return this.currentJobId;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
private resetLastCall(): void {
|
|
334
|
+
const notQueriedMessageCount = this.lastCallInfo.queried
|
|
335
|
+
? 0
|
|
336
|
+
: this.lastCallInfo.offchainEffects.filter(payload => payload[0]?.equals(OFFCHAIN_MESSAGE_IDENTIFIER)).length;
|
|
337
|
+
if (notQueriedMessageCount > 0) {
|
|
338
|
+
this.logger.warn(
|
|
339
|
+
`Dropping ${notQueriedMessageCount} unqueried offchain message(s) from the previous top-level call. ` +
|
|
340
|
+
`To deliver them, call \`env.offchain_messages()\` and forward the result to the recipient contract's ` +
|
|
341
|
+
`\`offchain_receive\` utility before issuing another top-level call. To intentionally discard, assign ` +
|
|
342
|
+
`to \`let _ = env.offchain_messages()\` to silence this warning.`,
|
|
343
|
+
);
|
|
344
|
+
}
|
|
345
|
+
this.lastCallInfo = emptyLastCallState();
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
recordOffchainEffect(data: Fr[]): void {
|
|
349
|
+
this.lastCallInfo.offchainEffects.push(data);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
private setLastCallContext(txHash: Fr, anchorBlockTimestamp: bigint): void {
|
|
353
|
+
this.lastCallInfo.txHash = txHash;
|
|
354
|
+
this.lastCallInfo.anchorBlockTimestamp = anchorBlockTimestamp;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
async withTopLevelCallTracking<T>(work: () => Promise<{ result: T; txHash?: Fr }>): Promise<T> {
|
|
358
|
+
this.resetLastCall();
|
|
359
|
+
// Capture the anchor *before* `work` runs: private/public executor calls mine a new block as a
|
|
360
|
+
// side effect, and that block's timestamp should not be attributed to this call's anchor.
|
|
361
|
+
const anchorBlockTimestamp = (await this.stateMachine.node.getBlockHeader('latest'))!.globalVariables.timestamp;
|
|
362
|
+
const { result, txHash } = await work();
|
|
363
|
+
this.setLastCallContext(txHash ?? Fr.ZERO, anchorBlockTimestamp);
|
|
364
|
+
return result;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
getLastCallOffchainEffects(): { effects: Fr[][] } {
|
|
368
|
+
this.lastCallInfo.queried = true;
|
|
369
|
+
return { effects: this.lastCallInfo.offchainEffects };
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
getLastCallContext(): { txHash: Fr; anchorBlockTimestamp: bigint } {
|
|
373
|
+
const { txHash, anchorBlockTimestamp } = this.lastCallInfo;
|
|
374
|
+
return { txHash, anchorBlockTimestamp };
|
|
375
|
+
}
|
|
376
|
+
|
|
260
377
|
async enterTopLevelState() {
|
|
261
378
|
switch (this.state.name) {
|
|
262
379
|
case 'PRIVATE': {
|
|
@@ -280,8 +397,7 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
280
397
|
}
|
|
281
398
|
|
|
282
399
|
// Commit all staged stores from the job that was just completed, then begin a new job
|
|
283
|
-
await this.
|
|
284
|
-
this.currentJobId = this.jobCoordinator.beginJob();
|
|
400
|
+
await this.cycleJob();
|
|
285
401
|
|
|
286
402
|
this.oracleHandler = new TXEOracleTopLevelContext(
|
|
287
403
|
this.stateMachine,
|
|
@@ -295,7 +411,6 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
295
411
|
this.senderAddressBookStore,
|
|
296
412
|
this.capsuleStore,
|
|
297
413
|
this.privateEventStore,
|
|
298
|
-
this.currentJobId,
|
|
299
414
|
this.nextBlockTimestamp,
|
|
300
415
|
this.version,
|
|
301
416
|
this.chainId,
|
|
@@ -311,18 +426,17 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
311
426
|
anchorBlockNumber?: BlockNumber,
|
|
312
427
|
): Promise<PrivateContextInputs> {
|
|
313
428
|
this.exitTopLevelState();
|
|
314
|
-
|
|
315
|
-
await new NoteService(
|
|
316
|
-
this.noteStore,
|
|
317
|
-
this.stateMachine.node,
|
|
318
|
-
this.stateMachine.anchorBlockStore,
|
|
319
|
-
this.currentJobId,
|
|
320
|
-
).syncNoteNullifiers(contractAddress);
|
|
429
|
+
this.resetLastCall();
|
|
321
430
|
|
|
322
431
|
// Private execution has two associated block numbers: the anchor block (i.e. the historical block that is used to
|
|
323
432
|
// build the proof), and the *next* block, i.e. the one we'll create once the execution ends, and which will contain
|
|
324
433
|
// a single transaction with the effects of what was done in the test.
|
|
325
434
|
const anchorBlock = await this.stateMachine.node.getBlockHeader(anchorBlockNumber ?? 'latest');
|
|
435
|
+
|
|
436
|
+
await new NoteService(this.noteStore, this.stateMachine.node, anchorBlock!, this.currentJobId).syncNoteNullifiers(
|
|
437
|
+
contractAddress,
|
|
438
|
+
await this.keyStore.getAccounts(),
|
|
439
|
+
);
|
|
326
440
|
const latestBlock = await this.stateMachine.node.getBlockHeader('latest');
|
|
327
441
|
|
|
328
442
|
const nextBlockGlobalVariables = makeGlobalVariables(undefined, {
|
|
@@ -338,30 +452,33 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
338
452
|
const taggingIndexCache = new ExecutionTaggingIndexCache();
|
|
339
453
|
|
|
340
454
|
const utilityExecutor = this.utilityExecutorForContractSync(anchorBlock);
|
|
341
|
-
this.oracleHandler = new PrivateExecutionOracle(
|
|
342
|
-
Fr.ZERO,
|
|
343
|
-
new TxContext(this.chainId, this.version, GasSettings.empty()),
|
|
344
|
-
new CallContext(AztecAddress.ZERO, contractAddress, FunctionSelector.empty(), false),
|
|
345
|
-
anchorBlock!,
|
|
455
|
+
this.oracleHandler = new PrivateExecutionOracle({
|
|
456
|
+
argsHash: Fr.ZERO,
|
|
457
|
+
txContext: new TxContext(this.chainId, this.version, GasSettings.empty()),
|
|
458
|
+
callContext: new CallContext(AztecAddress.ZERO, contractAddress, FunctionSelector.empty(), false),
|
|
459
|
+
anchorBlockHeader: anchorBlock!,
|
|
346
460
|
utilityExecutor,
|
|
347
|
-
[],
|
|
348
|
-
[],
|
|
349
|
-
new HashedValuesCache(),
|
|
461
|
+
authWitnesses: [],
|
|
462
|
+
capsules: [],
|
|
463
|
+
executionCache: new HashedValuesCache(),
|
|
350
464
|
noteCache,
|
|
351
465
|
taggingIndexCache,
|
|
352
|
-
this.contractStore,
|
|
353
|
-
this.noteStore,
|
|
354
|
-
this.keyStore,
|
|
355
|
-
this.addressStore,
|
|
356
|
-
this.stateMachine.node,
|
|
357
|
-
this.
|
|
358
|
-
this.
|
|
359
|
-
this.
|
|
360
|
-
this.
|
|
361
|
-
this.
|
|
362
|
-
this.
|
|
363
|
-
this.
|
|
364
|
-
|
|
466
|
+
contractStore: this.contractStore,
|
|
467
|
+
noteStore: this.noteStore,
|
|
468
|
+
keyStore: this.keyStore,
|
|
469
|
+
addressStore: this.addressStore,
|
|
470
|
+
aztecNode: this.stateMachine.node,
|
|
471
|
+
senderTaggingStore: this.senderTaggingStore,
|
|
472
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
473
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
474
|
+
capsuleService: new CapsuleService(this.capsuleStore, await this.keyStore.getAccounts()),
|
|
475
|
+
privateEventStore: this.privateEventStore,
|
|
476
|
+
contractSyncService: this.stateMachine.contractSyncService,
|
|
477
|
+
l2TipsStore: this.stateMachine.node,
|
|
478
|
+
jobId: this.currentJobId,
|
|
479
|
+
scopes: await this.keyStore.getAccounts(),
|
|
480
|
+
messageContextService: this.stateMachine.messageContextService,
|
|
481
|
+
});
|
|
365
482
|
|
|
366
483
|
// We store the note and tagging index caches fed into the PrivateExecutionOracle (along with some other auxiliary
|
|
367
484
|
// data) in order to refer to it later, mimicking the way this object is used by the ContractFunctionSimulator. The
|
|
@@ -371,17 +488,22 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
371
488
|
this.state = { name: 'PRIVATE', nextBlockGlobalVariables, noteCache, taggingIndexCache };
|
|
372
489
|
this.logger.debug(`Entered state ${this.state.name}`);
|
|
373
490
|
|
|
491
|
+
// Record the *resolved* anchor's timestamp — if the caller pinned the anchor to a past block
|
|
492
|
+
// via `anchorBlockNumber`, "latest" would be the wrong anchor for offchain-message semantics.
|
|
493
|
+
this.setLastCallContext(Fr.ZERO, anchorBlock!.globalVariables.timestamp);
|
|
494
|
+
|
|
374
495
|
return (this.oracleHandler as PrivateExecutionOracle).getPrivateContextInputs();
|
|
375
496
|
}
|
|
376
497
|
|
|
377
498
|
async enterPublicState(contractAddress?: AztecAddress) {
|
|
378
499
|
this.exitTopLevelState();
|
|
500
|
+
this.resetLastCall();
|
|
379
501
|
|
|
380
502
|
// The PublicContext will create a block with a single transaction in it, containing the effects of what was done in
|
|
381
503
|
// the test. The block therefore gets the *next* block number and timestamp.
|
|
382
|
-
const
|
|
504
|
+
const latestHeader = (await this.stateMachine.node.getBlockHeader('latest'))!;
|
|
383
505
|
const globalVariables = makeGlobalVariables(undefined, {
|
|
384
|
-
blockNumber: BlockNumber(
|
|
506
|
+
blockNumber: BlockNumber(latestHeader.globalVariables.blockNumber + 1),
|
|
385
507
|
timestamp: this.nextBlockTimestamp,
|
|
386
508
|
version: this.version,
|
|
387
509
|
chainId: this.chainId,
|
|
@@ -396,10 +518,16 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
396
518
|
|
|
397
519
|
this.state = { name: 'PUBLIC' };
|
|
398
520
|
this.logger.debug(`Entered state ${this.state.name}`);
|
|
521
|
+
|
|
522
|
+
// Public state is anchored at the latest block.
|
|
523
|
+
this.setLastCallContext(Fr.ZERO, latestHeader.globalVariables.timestamp);
|
|
399
524
|
}
|
|
400
525
|
|
|
401
526
|
async enterUtilityState(contractAddress: AztecAddress = DEFAULT_ADDRESS) {
|
|
402
527
|
this.exitTopLevelState();
|
|
528
|
+
this.resetLastCall();
|
|
529
|
+
|
|
530
|
+
const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
403
531
|
|
|
404
532
|
// There is no automatic message discovery and contract-driven syncing process in inlined private or utility
|
|
405
533
|
// contexts, which means that known nullifiers are also not searched for, since it is during the tagging sync that
|
|
@@ -409,32 +537,36 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
409
537
|
await new NoteService(
|
|
410
538
|
this.noteStore,
|
|
411
539
|
this.stateMachine.node,
|
|
412
|
-
|
|
540
|
+
anchorBlockHeader,
|
|
413
541
|
this.currentJobId,
|
|
414
|
-
).syncNoteNullifiers(contractAddress);
|
|
415
|
-
|
|
416
|
-
const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
542
|
+
).syncNoteNullifiers(contractAddress, await this.keyStore.getAccounts());
|
|
417
543
|
|
|
418
|
-
this.oracleHandler = new UtilityExecutionOracle(
|
|
544
|
+
this.oracleHandler = new UtilityExecutionOracle({
|
|
419
545
|
contractAddress,
|
|
420
|
-
[],
|
|
421
|
-
[],
|
|
546
|
+
authWitnesses: [],
|
|
547
|
+
capsules: [],
|
|
422
548
|
anchorBlockHeader,
|
|
423
|
-
this.contractStore,
|
|
424
|
-
this.noteStore,
|
|
425
|
-
this.keyStore,
|
|
426
|
-
this.addressStore,
|
|
427
|
-
this.stateMachine.node,
|
|
428
|
-
this.
|
|
429
|
-
this.
|
|
430
|
-
this.
|
|
431
|
-
this.
|
|
432
|
-
this.
|
|
433
|
-
this.
|
|
434
|
-
|
|
549
|
+
contractStore: this.contractStore,
|
|
550
|
+
noteStore: this.noteStore,
|
|
551
|
+
keyStore: this.keyStore,
|
|
552
|
+
addressStore: this.addressStore,
|
|
553
|
+
aztecNode: this.stateMachine.node,
|
|
554
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
555
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
556
|
+
capsuleService: new CapsuleService(this.capsuleStore, await this.keyStore.getAccounts()),
|
|
557
|
+
privateEventStore: this.privateEventStore,
|
|
558
|
+
messageContextService: this.stateMachine.messageContextService,
|
|
559
|
+
contractSyncService: this.stateMachine.contractSyncService,
|
|
560
|
+
l2TipsStore: this.stateMachine.node,
|
|
561
|
+
jobId: this.currentJobId,
|
|
562
|
+
scopes: await this.keyStore.getAccounts(),
|
|
563
|
+
});
|
|
435
564
|
|
|
436
565
|
this.state = { name: 'UTILITY' };
|
|
437
566
|
this.logger.debug(`Entered state ${this.state.name}`);
|
|
567
|
+
|
|
568
|
+
// Utility state anchors at whatever the anchor block store is pointing to (tracked as latest).
|
|
569
|
+
this.setLastCallContext(Fr.ZERO, anchorBlockHeader.globalVariables.timestamp);
|
|
438
570
|
}
|
|
439
571
|
|
|
440
572
|
private exitTopLevelState() {
|
|
@@ -444,8 +576,8 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
444
576
|
|
|
445
577
|
// Note that while all public and private contexts do is build a single block that we then process when exiting
|
|
446
578
|
// those, the top level context performs a large number of actions not captured in the following 'close' call. Among
|
|
447
|
-
// others, it will create empty blocks (via `
|
|
448
|
-
// `
|
|
579
|
+
// others, it will create empty blocks (via `advanceBlocksBy` and `deploy`), create blocks with transactions via
|
|
580
|
+
// `privateCallNewFlow` and `publicCallNewFlow`, add accounts to PXE via `addAccount`, etc. This is a
|
|
449
581
|
// slight inconsistency in the working model of this class, but is not too bad.
|
|
450
582
|
// TODO: it's quite unfortunate that we need to capture the authwits created to later pass them again when the top
|
|
451
583
|
// level context is re-created. This is because authwits create a temporary utility context that'd otherwise reset
|
|
@@ -499,30 +631,33 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
499
631
|
}
|
|
500
632
|
|
|
501
633
|
private utilityExecutorForContractSync(anchorBlock: any) {
|
|
502
|
-
return async (call: FunctionCall) => {
|
|
634
|
+
return async (call: FunctionCall, scopes: AztecAddress[]) => {
|
|
503
635
|
const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
|
|
504
636
|
if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
|
|
505
637
|
throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
|
|
506
638
|
}
|
|
507
639
|
|
|
508
640
|
try {
|
|
509
|
-
const oracle = new UtilityExecutionOracle(
|
|
510
|
-
call.to,
|
|
511
|
-
[],
|
|
512
|
-
[],
|
|
513
|
-
anchorBlock!,
|
|
514
|
-
this.contractStore,
|
|
515
|
-
this.noteStore,
|
|
516
|
-
this.keyStore,
|
|
517
|
-
this.addressStore,
|
|
518
|
-
this.stateMachine.node,
|
|
519
|
-
this.
|
|
520
|
-
this.
|
|
521
|
-
this.
|
|
522
|
-
this.
|
|
523
|
-
this.
|
|
524
|
-
this.
|
|
525
|
-
|
|
641
|
+
const oracle = new UtilityExecutionOracle({
|
|
642
|
+
contractAddress: call.to,
|
|
643
|
+
authWitnesses: [],
|
|
644
|
+
capsules: [],
|
|
645
|
+
anchorBlockHeader: anchorBlock!,
|
|
646
|
+
contractStore: this.contractStore,
|
|
647
|
+
noteStore: this.noteStore,
|
|
648
|
+
keyStore: this.keyStore,
|
|
649
|
+
addressStore: this.addressStore,
|
|
650
|
+
aztecNode: this.stateMachine.node,
|
|
651
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
652
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
653
|
+
capsuleService: new CapsuleService(this.capsuleStore, scopes),
|
|
654
|
+
privateEventStore: this.privateEventStore,
|
|
655
|
+
messageContextService: this.stateMachine.messageContextService,
|
|
656
|
+
contractSyncService: this.stateMachine.contractSyncService,
|
|
657
|
+
l2TipsStore: this.stateMachine.node,
|
|
658
|
+
jobId: this.currentJobId,
|
|
659
|
+
scopes,
|
|
660
|
+
});
|
|
526
661
|
await new WASMSimulator()
|
|
527
662
|
.executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, new Oracle(oracle).toACIRCallback())
|
|
528
663
|
.catch((err: Error) => {
|
package/src/util/encoding.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
|
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';
|
|
6
|
+
import { BlockHash } from '@aztec/stdlib/block';
|
|
6
7
|
import { type ContractInstanceWithAddress, ContractInstanceWithAddressSchema } from '@aztec/stdlib/contract';
|
|
7
8
|
|
|
8
9
|
import { z } from 'zod';
|
|
@@ -25,6 +26,10 @@ export function addressFromSingle(obj: ForeignCallSingle) {
|
|
|
25
26
|
return new AztecAddress(fromSingle(obj));
|
|
26
27
|
}
|
|
27
28
|
|
|
29
|
+
export function blockHashFromSingle(obj: ForeignCallSingle) {
|
|
30
|
+
return new BlockHash(fromSingle(obj));
|
|
31
|
+
}
|
|
32
|
+
|
|
28
33
|
export function fromArray(obj: ForeignCallArray) {
|
|
29
34
|
return obj.map(str => Fr.fromBuffer(hexToBuffer(str)));
|
|
30
35
|
}
|
|
@@ -1,19 +1,11 @@
|
|
|
1
1
|
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
2
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
3
|
import type { ContractStore } from '@aztec/pxe/server';
|
|
4
|
-
import { type ContractArtifact, FunctionSelector
|
|
4
|
+
import { type ContractArtifact, FunctionSelector } from '@aztec/stdlib/abi';
|
|
5
5
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
6
|
-
import {
|
|
7
|
-
type ContractClassPublic,
|
|
8
|
-
type ContractDataSource,
|
|
9
|
-
type ContractInstanceWithAddress,
|
|
10
|
-
computePrivateFunctionsRoot,
|
|
11
|
-
computePublicBytecodeCommitment,
|
|
12
|
-
getContractClassPrivateFunctionFromArtifact,
|
|
13
|
-
} from '@aztec/stdlib/contract';
|
|
6
|
+
import type { ContractClassPublic, ContractDataSource, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
14
7
|
|
|
15
8
|
export class TXEPublicContractDataSource implements ContractDataSource {
|
|
16
|
-
#privateFunctionsRoot: Map<string, Buffer> = new Map();
|
|
17
9
|
constructor(
|
|
18
10
|
private blockNumber: BlockNumber,
|
|
19
11
|
private contractStore: ContractStore,
|
|
@@ -24,42 +16,22 @@ export class TXEPublicContractDataSource implements ContractDataSource {
|
|
|
24
16
|
}
|
|
25
17
|
|
|
26
18
|
async getContractClass(id: Fr): Promise<ContractClassPublic | undefined> {
|
|
27
|
-
const contractClass = await this.contractStore.
|
|
19
|
+
const contractClass = await this.contractStore.getContractClassWithPreimage(id);
|
|
28
20
|
if (!contractClass) {
|
|
29
21
|
return;
|
|
30
22
|
}
|
|
31
|
-
const artifact = await this.contractStore.getContractArtifact(id);
|
|
32
|
-
if (!artifact) {
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
let privateFunctionsRoot;
|
|
37
|
-
if (!this.#privateFunctionsRoot.has(id.toString())) {
|
|
38
|
-
const privateFunctions = await Promise.all(
|
|
39
|
-
artifact.functions
|
|
40
|
-
.filter(fn => fn.functionType === FunctionType.PRIVATE)
|
|
41
|
-
.map(fn => getContractClassPrivateFunctionFromArtifact(fn)),
|
|
42
|
-
);
|
|
43
|
-
privateFunctionsRoot = await computePrivateFunctionsRoot(privateFunctions);
|
|
44
|
-
this.#privateFunctionsRoot.set(id.toString(), privateFunctionsRoot.toBuffer());
|
|
45
|
-
} else {
|
|
46
|
-
privateFunctionsRoot = Fr.fromBuffer(this.#privateFunctionsRoot.get(id.toString())!);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
23
|
return {
|
|
50
|
-
id,
|
|
51
|
-
artifactHash: contractClass
|
|
52
|
-
packedBytecode: contractClass
|
|
53
|
-
privateFunctionsRoot,
|
|
54
|
-
version: contractClass
|
|
55
|
-
privateFunctions: [],
|
|
56
|
-
utilityFunctions: [],
|
|
24
|
+
id: contractClass.id,
|
|
25
|
+
artifactHash: contractClass.artifactHash,
|
|
26
|
+
packedBytecode: contractClass.packedBytecode,
|
|
27
|
+
privateFunctionsRoot: contractClass.privateFunctionsRoot,
|
|
28
|
+
version: contractClass.version,
|
|
57
29
|
};
|
|
58
30
|
}
|
|
59
31
|
|
|
60
32
|
async getBytecodeCommitment(id: Fr): Promise<Fr | undefined> {
|
|
61
|
-
const contractClass = await this.contractStore.
|
|
62
|
-
return contractClass
|
|
33
|
+
const contractClass = await this.contractStore.getContractClassWithPreimage(id);
|
|
34
|
+
return contractClass?.publicBytecodeCommitment;
|
|
63
35
|
}
|
|
64
36
|
|
|
65
37
|
async getContract(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
|
|
@@ -87,7 +87,9 @@ export async function makeTXEBlock(
|
|
|
87
87
|
const newArchiveInfo = await worldTrees.getTreeInfo(MerkleTreeId.ARCHIVE);
|
|
88
88
|
const newArchive = new AppendOnlyTreeSnapshot(new Fr(newArchiveInfo.root), Number(newArchiveInfo.size));
|
|
89
89
|
|
|
90
|
-
// L2Block requires checkpointNumber and indexWithinCheckpoint
|
|
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.
|
|
91
93
|
const checkpointNumber = CheckpointNumber.fromBlockNumber(globalVariables.blockNumber);
|
|
92
94
|
const indexWithinCheckpoint = IndexWithinCheckpoint(0);
|
|
93
95
|
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { ContractArtifact } from '@aztec/aztec.js/abi';
|
|
2
|
-
import { Fr } from '@aztec/aztec.js/fields';
|
|
3
|
-
import { ContractStore } from '@aztec/pxe/server';
|
|
4
|
-
export type ContractArtifactWithHash = ContractArtifact & {
|
|
5
|
-
artifactHash: Fr;
|
|
6
|
-
};
|
|
7
|
-
export declare class TXEContractStore extends ContractStore {
|
|
8
|
-
#private;
|
|
9
|
-
addContractArtifact(id: Fr, artifact: ContractArtifact | ContractArtifactWithHash): Promise<void>;
|
|
10
|
-
getContractArtifact(contractClassId: Fr): Promise<ContractArtifact | ContractArtifactWithHash | undefined>;
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHhlX2NvbnRyYWN0X3N0b3JlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdXRpbC90eGVfY29udHJhY3Rfc3RvcmUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLEVBQUUsZ0JBQWdCLEVBQUUsTUFBTSxxQkFBcUIsQ0FBQztBQUM1RCxPQUFPLEVBQUUsRUFBRSxFQUFFLE1BQU0sd0JBQXdCLENBQUM7QUFDNUMsT0FBTyxFQUFFLGFBQWEsRUFBRSxNQUFNLG1CQUFtQixDQUFDO0FBRWxELE1BQU0sTUFBTSx3QkFBd0IsR0FBRyxnQkFBZ0IsR0FBRztJQUFFLFlBQVksRUFBRSxFQUFFLENBQUE7Q0FBRSxDQUFDO0FBTy9FLHFCQUFhLGdCQUFpQixTQUFRLGFBQWE7O0lBRzNCLG1CQUFtQixDQUN2QyxFQUFFLEVBQUUsRUFBRSxFQUNOLFFBQVEsRUFBRSxnQkFBZ0IsR0FBRyx3QkFBd0IsR0FDcEQsT0FBTyxDQUFDLElBQUksQ0FBQyxDQUtmO0lBRXFCLG1CQUFtQixDQUN2QyxlQUFlLEVBQUUsRUFBRSxHQUNsQixPQUFPLENBQUMsZ0JBQWdCLEdBQUcsd0JBQXdCLEdBQUcsU0FBUyxDQUFDLENBUWxFO0NBQ0YifQ==
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"txe_contract_store.d.ts","sourceRoot":"","sources":["../../src/util/txe_contract_store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,EAAE,EAAE,MAAM,wBAAwB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,MAAM,MAAM,wBAAwB,GAAG,gBAAgB,GAAG;IAAE,YAAY,EAAE,EAAE,CAAA;CAAE,CAAC;AAO/E,qBAAa,gBAAiB,SAAQ,aAAa;;IAG3B,mBAAmB,CACvC,EAAE,EAAE,EAAE,EACN,QAAQ,EAAE,gBAAgB,GAAG,wBAAwB,GACpD,OAAO,CAAC,IAAI,CAAC,CAKf;IAEqB,mBAAmB,CACvC,eAAe,EAAE,EAAE,GAClB,OAAO,CAAC,gBAAgB,GAAG,wBAAwB,GAAG,SAAS,CAAC,CAQlE;CACF"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Fr } from '@aztec/aztec.js/fields';
|
|
2
|
-
import { ContractStore } from '@aztec/pxe/server';
|
|
3
|
-
/*
|
|
4
|
-
* A contract store that stores contract artifacts with their hashes. Since
|
|
5
|
-
* TXE typically deploys the same contract again and again for multiple tests, caching
|
|
6
|
-
* the *very* expensive artifact hash computation improves testing speed significantly.
|
|
7
|
-
*/ export class TXEContractStore extends ContractStore {
|
|
8
|
-
#artifactHashes = new Map();
|
|
9
|
-
async addContractArtifact(id, artifact) {
|
|
10
|
-
if ('artifactHash' in artifact) {
|
|
11
|
-
this.#artifactHashes.set(id.toString(), artifact.artifactHash.toBuffer());
|
|
12
|
-
}
|
|
13
|
-
await super.addContractArtifact(id, artifact);
|
|
14
|
-
}
|
|
15
|
-
async getContractArtifact(contractClassId) {
|
|
16
|
-
const artifact = await super.getContractArtifact(contractClassId);
|
|
17
|
-
if (artifact && this.#artifactHashes.has(contractClassId.toString())) {
|
|
18
|
-
artifact.artifactHash = Fr.fromBuffer(this.#artifactHashes.get(contractClassId.toString()));
|
|
19
|
-
}
|
|
20
|
-
return artifact;
|
|
21
|
-
}
|
|
22
|
-
}
|