@aztec/txe 0.0.1-commit.9b94fc1 → 0.0.1-commit.c7c42ec
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 +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 +5 -5
- 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 +20 -12
- package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_top_level_context.js +77 -54
- package/dest/rpc_translator.d.ts +11 -5
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +57 -15
- package/dest/state_machine/archiver.d.ts +26 -10
- package/dest/state_machine/archiver.d.ts.map +1 -1
- package/dest/state_machine/archiver.js +105 -17
- package/dest/state_machine/dummy_p2p_client.d.ts +1 -1
- package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
- package/dest/state_machine/dummy_p2p_client.js +3 -1
- package/dest/state_machine/global_variable_builder.d.ts +5 -4
- package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
- package/dest/state_machine/global_variable_builder.js +12 -0
- package/dest/state_machine/index.d.ts +5 -5
- package/dest/state_machine/index.d.ts.map +1 -1
- package/dest/state_machine/index.js +14 -20
- 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 +19 -13
- package/dest/txe_session.d.ts.map +1 -1
- package/dest/txe_session.js +50 -38
- package/dest/util/encoding.d.ts +610 -11
- package/dest/util/encoding.d.ts.map +1 -1
- package/dest/util/encoding.js +1 -1
- package/dest/util/txe_account_store.d.ts +10 -0
- package/dest/util/txe_account_store.d.ts.map +1 -0
- package/dest/util/{txe_account_data_provider.js → txe_account_store.js} +1 -1
- package/dest/util/txe_contract_store.d.ts +12 -0
- package/dest/util/txe_contract_store.d.ts.map +1 -0
- package/dest/util/{txe_contract_data_provider.js → txe_contract_store.js} +3 -3
- package/dest/util/txe_public_contract_data_source.d.ts +7 -6
- package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
- package/dest/util/txe_public_contract_data_source.js +11 -11
- package/dest/utils/block_creation.d.ts +19 -4
- package/dest/utils/block_creation.d.ts.map +1 -1
- package/dest/utils/block_creation.js +23 -2
- package/dest/utils/tx_effect_creation.d.ts +4 -3
- package/dest/utils/tx_effect_creation.d.ts.map +1 -1
- package/dest/utils/tx_effect_creation.js +1 -1
- package/package.json +17 -17
- package/src/index.ts +15 -12
- package/src/oracle/interfaces.ts +8 -5
- package/src/oracle/txe_oracle_public_context.ts +6 -11
- package/src/oracle/txe_oracle_top_level_context.ts +109 -80
- package/src/rpc_translator.ts +82 -12
- package/src/state_machine/archiver.ts +136 -25
- package/src/state_machine/dummy_p2p_client.ts +3 -1
- package/src/state_machine/global_variable_builder.ts +20 -3
- package/src/state_machine/index.ts +19 -18
- package/src/state_machine/synchronizer.ts +8 -7
- package/src/txe_session.ts +107 -68
- 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 +34 -3
- package/src/utils/tx_effect_creation.ts +3 -2
- 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,18 @@
|
|
|
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
|
+
NoteService,
|
|
11
|
+
NoteStore,
|
|
12
|
+
PrivateEventStore,
|
|
13
|
+
RecipientTaggingStore,
|
|
14
|
+
SenderAddressBookStore,
|
|
15
|
+
SenderTaggingStore,
|
|
13
16
|
} from '@aztec/pxe/server';
|
|
14
17
|
import {
|
|
15
18
|
ExecutionNoteCache,
|
|
@@ -23,13 +26,11 @@ import {
|
|
|
23
26
|
import { FunctionSelector } from '@aztec/stdlib/abi';
|
|
24
27
|
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
25
28
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
26
|
-
import { Body, L2Block } from '@aztec/stdlib/block';
|
|
27
29
|
import { GasSettings } from '@aztec/stdlib/gas';
|
|
28
30
|
import { computeProtocolNullifier } from '@aztec/stdlib/hash';
|
|
29
31
|
import { PrivateContextInputs } from '@aztec/stdlib/kernel';
|
|
30
|
-
import {
|
|
32
|
+
import { makeGlobalVariables } from '@aztec/stdlib/testing';
|
|
31
33
|
import { CallContext, GlobalVariables, TxContext } from '@aztec/stdlib/tx';
|
|
32
|
-
import type { UInt32 } from '@aztec/stdlib/types';
|
|
33
34
|
|
|
34
35
|
import { z } from 'zod';
|
|
35
36
|
|
|
@@ -39,13 +40,9 @@ import { TXEOracleTopLevelContext } from './oracle/txe_oracle_top_level_context.
|
|
|
39
40
|
import { RPCTranslator } from './rpc_translator.js';
|
|
40
41
|
import { TXEStateMachine } from './state_machine/index.js';
|
|
41
42
|
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';
|
|
43
|
+
import { TXEAccountStore } from './util/txe_account_store.js';
|
|
44
|
+
import { TXEContractStore } from './util/txe_contract_store.js';
|
|
45
|
+
import { getSingleTxBlockRequestHash, insertTxEffectIntoWorldTrees, makeTXEBlock } from './utils/block_creation.js';
|
|
49
46
|
import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
50
47
|
|
|
51
48
|
/**
|
|
@@ -102,11 +99,11 @@ export type TXEOracleFunctionName = Exclude<
|
|
|
102
99
|
export interface TXESessionStateHandler {
|
|
103
100
|
enterTopLevelState(): Promise<void>;
|
|
104
101
|
enterPublicState(contractAddress?: AztecAddress): Promise<void>;
|
|
105
|
-
enterPrivateState(contractAddress?: AztecAddress, anchorBlockNumber?:
|
|
102
|
+
enterPrivateState(contractAddress?: AztecAddress, anchorBlockNumber?: BlockNumber): Promise<PrivateContextInputs>;
|
|
106
103
|
enterUtilityState(contractAddress?: AztecAddress): Promise<void>;
|
|
107
104
|
}
|
|
108
105
|
|
|
109
|
-
const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
|
|
106
|
+
export const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
|
|
110
107
|
|
|
111
108
|
/**
|
|
112
109
|
* A `TXESession` corresponds to a Noir `#[test]` function, and handles all of its oracle calls, stores test-specific
|
|
@@ -124,32 +121,39 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
124
121
|
| IPrivateExecutionOracle
|
|
125
122
|
| IAvmExecutionOracle
|
|
126
123
|
| ITxeExecutionOracle,
|
|
127
|
-
private
|
|
124
|
+
private contractStore: TXEContractStore,
|
|
125
|
+
private noteStore: NoteStore,
|
|
128
126
|
private keyStore: KeyStore,
|
|
129
|
-
private
|
|
130
|
-
private
|
|
127
|
+
private addressStore: AddressStore,
|
|
128
|
+
private accountStore: TXEAccountStore,
|
|
129
|
+
private senderTaggingStore: SenderTaggingStore,
|
|
130
|
+
private recipientTaggingStore: RecipientTaggingStore,
|
|
131
|
+
private senderAddressBookStore: SenderAddressBookStore,
|
|
132
|
+
private capsuleStore: CapsuleStore,
|
|
133
|
+
private privateEventStore: PrivateEventStore,
|
|
131
134
|
private chainId: Fr,
|
|
132
135
|
private version: Fr,
|
|
133
136
|
private nextBlockTimestamp: bigint,
|
|
134
|
-
private pxeOracleInterface: PXEOracleInterface,
|
|
135
137
|
) {}
|
|
136
138
|
|
|
137
139
|
static async init(protocolContracts: ProtocolContract[]) {
|
|
138
140
|
const store = await openTmpStore('txe-session');
|
|
139
141
|
|
|
140
|
-
const
|
|
141
|
-
const
|
|
142
|
-
const
|
|
143
|
-
const
|
|
144
|
-
const
|
|
145
|
-
const
|
|
142
|
+
const addressStore = new AddressStore(store);
|
|
143
|
+
const privateEventStore = new PrivateEventStore(store);
|
|
144
|
+
const contractStore = new TXEContractStore(store);
|
|
145
|
+
const noteStore = await NoteStore.create(store);
|
|
146
|
+
const senderTaggingStore = new SenderTaggingStore(store);
|
|
147
|
+
const recipientTaggingStore = new RecipientTaggingStore(store);
|
|
148
|
+
const senderAddressBookStore = new SenderAddressBookStore(store);
|
|
149
|
+
const capsuleStore = new CapsuleStore(store);
|
|
146
150
|
const keyStore = new KeyStore(store);
|
|
147
|
-
const
|
|
151
|
+
const accountStore = new TXEAccountStore(store);
|
|
148
152
|
|
|
149
153
|
// Register protocol contracts.
|
|
150
154
|
for (const { contractClass, instance, artifact } of protocolContracts) {
|
|
151
|
-
await
|
|
152
|
-
await
|
|
155
|
+
await contractStore.addContractArtifact(contractClass.id, artifact);
|
|
156
|
+
await contractStore.addContractInstance(instance);
|
|
153
157
|
}
|
|
154
158
|
|
|
155
159
|
const stateMachine = await TXEStateMachine.create(store);
|
|
@@ -158,25 +162,18 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
158
162
|
const version = new Fr(await stateMachine.node.getVersion());
|
|
159
163
|
const chainId = new Fr(await stateMachine.node.getChainId());
|
|
160
164
|
|
|
161
|
-
const pxeOracleInterface = new PXEOracleInterface(
|
|
162
|
-
stateMachine.node,
|
|
163
|
-
keyStore,
|
|
164
|
-
contractDataProvider,
|
|
165
|
-
noteDataProvider,
|
|
166
|
-
capsuleDataProvider,
|
|
167
|
-
stateMachine.syncDataProvider,
|
|
168
|
-
taggingDataProvider,
|
|
169
|
-
addressDataProvider,
|
|
170
|
-
privateEventDataProvider,
|
|
171
|
-
);
|
|
172
|
-
|
|
173
165
|
const topLevelOracleHandler = new TXEOracleTopLevelContext(
|
|
174
166
|
stateMachine,
|
|
175
|
-
|
|
167
|
+
contractStore,
|
|
168
|
+
noteStore,
|
|
176
169
|
keyStore,
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
170
|
+
addressStore,
|
|
171
|
+
accountStore,
|
|
172
|
+
senderTaggingStore,
|
|
173
|
+
recipientTaggingStore,
|
|
174
|
+
senderAddressBookStore,
|
|
175
|
+
capsuleStore,
|
|
176
|
+
privateEventStore,
|
|
180
177
|
nextBlockTimestamp,
|
|
181
178
|
version,
|
|
182
179
|
chainId,
|
|
@@ -188,14 +185,19 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
188
185
|
createLogger('txe:session'),
|
|
189
186
|
stateMachine,
|
|
190
187
|
topLevelOracleHandler,
|
|
191
|
-
|
|
188
|
+
contractStore,
|
|
189
|
+
noteStore,
|
|
192
190
|
keyStore,
|
|
193
|
-
|
|
194
|
-
|
|
191
|
+
addressStore,
|
|
192
|
+
accountStore,
|
|
193
|
+
senderTaggingStore,
|
|
194
|
+
recipientTaggingStore,
|
|
195
|
+
senderAddressBookStore,
|
|
196
|
+
capsuleStore,
|
|
197
|
+
privateEventStore,
|
|
195
198
|
version,
|
|
196
199
|
chainId,
|
|
197
200
|
nextBlockTimestamp,
|
|
198
|
-
pxeOracleInterface,
|
|
199
201
|
);
|
|
200
202
|
}
|
|
201
203
|
|
|
@@ -254,11 +256,16 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
254
256
|
|
|
255
257
|
this.oracleHandler = new TXEOracleTopLevelContext(
|
|
256
258
|
this.stateMachine,
|
|
257
|
-
this.
|
|
259
|
+
this.contractStore,
|
|
260
|
+
this.noteStore,
|
|
258
261
|
this.keyStore,
|
|
259
|
-
this.
|
|
260
|
-
this.
|
|
261
|
-
this.
|
|
262
|
+
this.addressStore,
|
|
263
|
+
this.accountStore,
|
|
264
|
+
this.senderTaggingStore,
|
|
265
|
+
this.recipientTaggingStore,
|
|
266
|
+
this.senderAddressBookStore,
|
|
267
|
+
this.capsuleStore,
|
|
268
|
+
this.privateEventStore,
|
|
262
269
|
this.nextBlockTimestamp,
|
|
263
270
|
this.version,
|
|
264
271
|
this.chainId,
|
|
@@ -271,7 +278,7 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
271
278
|
|
|
272
279
|
async enterPrivateState(
|
|
273
280
|
contractAddress: AztecAddress = DEFAULT_ADDRESS,
|
|
274
|
-
anchorBlockNumber?:
|
|
281
|
+
anchorBlockNumber?: BlockNumber,
|
|
275
282
|
): Promise<PrivateContextInputs> {
|
|
276
283
|
this.exitTopLevelState();
|
|
277
284
|
|
|
@@ -280,7 +287,11 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
280
287
|
// we perform this. We therefore search for known nullifiers now, as otherwise notes that were nullified would not
|
|
281
288
|
// be removed from the database.
|
|
282
289
|
// TODO(#12553): make the synchronizer sync here instead and remove this
|
|
283
|
-
await
|
|
290
|
+
await new NoteService(
|
|
291
|
+
this.noteStore,
|
|
292
|
+
this.stateMachine.node,
|
|
293
|
+
this.stateMachine.anchorBlockStore,
|
|
294
|
+
).syncNoteNullifiers(contractAddress);
|
|
284
295
|
|
|
285
296
|
// Private execution has two associated block numbers: the anchor block (i.e. the historical block that is used to
|
|
286
297
|
// build the proof), and the *next* block, i.e. the one we'll create once the execution ends, and which will contain
|
|
@@ -289,7 +300,7 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
289
300
|
const latestBlock = await this.stateMachine.node.getBlockHeader('latest');
|
|
290
301
|
|
|
291
302
|
const nextBlockGlobalVariables = makeGlobalVariables(undefined, {
|
|
292
|
-
blockNumber: latestBlock!.globalVariables.blockNumber + 1,
|
|
303
|
+
blockNumber: BlockNumber(latestBlock!.globalVariables.blockNumber + 1),
|
|
293
304
|
timestamp: this.nextBlockTimestamp,
|
|
294
305
|
version: this.version,
|
|
295
306
|
chainId: this.chainId,
|
|
@@ -310,7 +321,17 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
310
321
|
new HashedValuesCache(),
|
|
311
322
|
noteCache,
|
|
312
323
|
taggingIndexCache,
|
|
313
|
-
this.
|
|
324
|
+
this.contractStore,
|
|
325
|
+
this.noteStore,
|
|
326
|
+
this.keyStore,
|
|
327
|
+
this.addressStore,
|
|
328
|
+
this.stateMachine.node,
|
|
329
|
+
this.stateMachine.anchorBlockStore,
|
|
330
|
+
this.senderTaggingStore,
|
|
331
|
+
this.recipientTaggingStore,
|
|
332
|
+
this.senderAddressBookStore,
|
|
333
|
+
this.capsuleStore,
|
|
334
|
+
this.privateEventStore,
|
|
314
335
|
);
|
|
315
336
|
|
|
316
337
|
// We store the note and tagging index caches fed into the PrivateExecutionOracle (along with some other auxiliary
|
|
@@ -331,7 +352,7 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
331
352
|
// the test. The block therefore gets the *next* block number and timestamp.
|
|
332
353
|
const latestBlockNumber = (await this.stateMachine.node.getBlockHeader('latest'))!.globalVariables.blockNumber;
|
|
333
354
|
const globalVariables = makeGlobalVariables(undefined, {
|
|
334
|
-
blockNumber: latestBlockNumber + 1,
|
|
355
|
+
blockNumber: BlockNumber(latestBlockNumber + 1),
|
|
335
356
|
timestamp: this.nextBlockTimestamp,
|
|
336
357
|
version: this.version,
|
|
337
358
|
chainId: this.chainId,
|
|
@@ -356,9 +377,30 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
356
377
|
// we perform this. We therefore search for known nullifiers now, as otherwise notes that were nullified would not
|
|
357
378
|
// be removed from the database.
|
|
358
379
|
// TODO(#12553): make the synchronizer sync here instead and remove this
|
|
359
|
-
await
|
|
380
|
+
await new NoteService(
|
|
381
|
+
this.noteStore,
|
|
382
|
+
this.stateMachine.node,
|
|
383
|
+
this.stateMachine.anchorBlockStore,
|
|
384
|
+
).syncNoteNullifiers(contractAddress);
|
|
385
|
+
|
|
386
|
+
const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
360
387
|
|
|
361
|
-
this.oracleHandler = new UtilityExecutionOracle(
|
|
388
|
+
this.oracleHandler = new UtilityExecutionOracle(
|
|
389
|
+
contractAddress,
|
|
390
|
+
[],
|
|
391
|
+
[],
|
|
392
|
+
anchorBlockHeader,
|
|
393
|
+
this.contractStore,
|
|
394
|
+
this.noteStore,
|
|
395
|
+
this.keyStore,
|
|
396
|
+
this.addressStore,
|
|
397
|
+
this.stateMachine.node,
|
|
398
|
+
this.stateMachine.anchorBlockStore,
|
|
399
|
+
this.recipientTaggingStore,
|
|
400
|
+
this.senderAddressBookStore,
|
|
401
|
+
this.capsuleStore,
|
|
402
|
+
this.privateEventStore,
|
|
403
|
+
);
|
|
362
404
|
|
|
363
405
|
this.state = { name: 'UTILITY' };
|
|
364
406
|
this.logger.debug(`Entered state ${this.state.name}`);
|
|
@@ -392,6 +434,7 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
392
434
|
|
|
393
435
|
// We rely on the note cache to determine the effects of the transaction. This is incomplete as it doesn't private
|
|
394
436
|
// logs (other effects like enqueued public calls don't need to be considered since those are not allowed).
|
|
437
|
+
|
|
395
438
|
const txEffect = await makeTxEffect(
|
|
396
439
|
this.state.noteCache,
|
|
397
440
|
this.state.protocolNullifier,
|
|
@@ -402,11 +445,7 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
402
445
|
const forkedWorldTrees = await this.stateMachine.synchronizer.nativeWorldStateService.fork();
|
|
403
446
|
await insertTxEffectIntoWorldTrees(txEffect, forkedWorldTrees);
|
|
404
447
|
|
|
405
|
-
const block =
|
|
406
|
-
makeAppendOnlyTreeSnapshot(),
|
|
407
|
-
await makeTXEBlockHeader(forkedWorldTrees, this.state.nextBlockGlobalVariables),
|
|
408
|
-
new Body([txEffect]),
|
|
409
|
-
);
|
|
448
|
+
const block = await makeTXEBlock(forkedWorldTrees, this.state.nextBlockGlobalVariables, [txEffect]);
|
|
410
449
|
await this.stateMachine.handleL2Block(block);
|
|
411
450
|
|
|
412
451
|
await forkedWorldTrees.close();
|
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,9 +4,10 @@ import {
|
|
|
4
4
|
NULLIFIER_SUBTREE_HEIGHT,
|
|
5
5
|
NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP,
|
|
6
6
|
} from '@aztec/constants';
|
|
7
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
7
8
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
8
|
-
import { Fr } from '@aztec/foundation/
|
|
9
|
-
import { L2BlockHeader } from '@aztec/stdlib/block';
|
|
9
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
10
|
+
import { Body, L2Block, L2BlockHeader } from '@aztec/stdlib/block';
|
|
10
11
|
import { makeContentCommitment } from '@aztec/stdlib/testing';
|
|
11
12
|
import { AppendOnlyTreeSnapshot, MerkleTreeId, type MerkleTreeWriteOperations } from '@aztec/stdlib/trees';
|
|
12
13
|
import { GlobalVariables, TxEffect } from '@aztec/stdlib/tx';
|
|
@@ -16,7 +17,7 @@ import { GlobalVariables, TxEffect } from '@aztec/stdlib/tx';
|
|
|
16
17
|
* @param blockNumber The number for the block in which there is a single transaction.
|
|
17
18
|
* @returns The transaction request hash.
|
|
18
19
|
*/
|
|
19
|
-
export function getSingleTxBlockRequestHash(blockNumber:
|
|
20
|
+
export function getSingleTxBlockRequestHash(blockNumber: BlockNumber): Fr {
|
|
20
21
|
return new Fr(blockNumber + 9999); // Why does this need to be a high number? Why do small numbered nullifiers already exist?
|
|
21
22
|
}
|
|
22
23
|
|
|
@@ -61,3 +62,33 @@ export async function makeTXEBlockHeader(
|
|
|
61
62
|
Fr.ZERO,
|
|
62
63
|
);
|
|
63
64
|
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Creates an L2Block with proper archive chaining.
|
|
68
|
+
* This function:
|
|
69
|
+
* 1. Gets the current archive state as lastArchive for the header
|
|
70
|
+
* 2. Creates the block header
|
|
71
|
+
* 3. Updates the archive tree with the header hash
|
|
72
|
+
* 4. Gets the new archive state for the block's archive
|
|
73
|
+
*
|
|
74
|
+
* @param worldTrees - The world trees to read/write from
|
|
75
|
+
* @param globalVariables - Global variables for the block
|
|
76
|
+
* @param txEffects - Transaction effects to include in the block
|
|
77
|
+
* @returns The created L2Block with proper archive chaining
|
|
78
|
+
*/
|
|
79
|
+
export async function makeTXEBlock(
|
|
80
|
+
worldTrees: MerkleTreeWriteOperations,
|
|
81
|
+
globalVariables: GlobalVariables,
|
|
82
|
+
txEffects: TxEffect[],
|
|
83
|
+
): Promise<L2Block> {
|
|
84
|
+
const header = await makeTXEBlockHeader(worldTrees, globalVariables);
|
|
85
|
+
|
|
86
|
+
// Update the archive tree with this block's header hash
|
|
87
|
+
await worldTrees.updateArchive(header.toBlockHeader());
|
|
88
|
+
|
|
89
|
+
// Get the new archive state after updating
|
|
90
|
+
const newArchiveInfo = await worldTrees.getTreeInfo(MerkleTreeId.ARCHIVE);
|
|
91
|
+
const newArchive = new AppendOnlyTreeSnapshot(new Fr(newArchiveInfo.root), Number(newArchiveInfo.size));
|
|
92
|
+
|
|
93
|
+
return new L2Block(newArchive, header, new Body(txEffects));
|
|
94
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
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';
|
|
@@ -6,7 +7,7 @@ import { TxEffect, TxHash } from '@aztec/stdlib/tx';
|
|
|
6
7
|
export async function makeTxEffect(
|
|
7
8
|
noteCache: ExecutionNoteCache,
|
|
8
9
|
protocolNullifier: Fr,
|
|
9
|
-
txBlockNumber:
|
|
10
|
+
txBlockNumber: BlockNumber,
|
|
10
11
|
): Promise<TxEffect> {
|
|
11
12
|
const txEffect = TxEffect.empty();
|
|
12
13
|
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
2
|
-
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
3
|
-
import { CompleteAddress } from '@aztec/stdlib/contract';
|
|
4
|
-
export declare class TXEAccountDataProvider {
|
|
5
|
-
#private;
|
|
6
|
-
constructor(store: AztecAsyncKVStore);
|
|
7
|
-
getAccount(key: AztecAddress): Promise<CompleteAddress>;
|
|
8
|
-
setAccount(key: AztecAddress, value: CompleteAddress): Promise<void>;
|
|
9
|
-
}
|
|
10
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHhlX2FjY291bnRfZGF0YV9wcm92aWRlci5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3V0aWwvdHhlX2FjY291bnRfZGF0YV9wcm92aWRlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxpQkFBaUIsRUFBaUIsTUFBTSxpQkFBaUIsQ0FBQztBQUN4RSxPQUFPLEtBQUssRUFBRSxZQUFZLEVBQUUsTUFBTSw2QkFBNkIsQ0FBQztBQUNoRSxPQUFPLEVBQUUsZUFBZSxFQUFFLE1BQU0sd0JBQXdCLENBQUM7QUFFekQscUJBQWEsc0JBQXNCOztJQUdqQyxZQUFZLEtBQUssRUFBRSxpQkFBaUIsRUFFbkM7SUFFSyxVQUFVLENBQUMsR0FBRyxFQUFFLFlBQVksNEJBTWpDO0lBRUssVUFBVSxDQUFDLEdBQUcsRUFBRSxZQUFZLEVBQUUsS0FBSyxFQUFFLGVBQWUsaUJBRXpEO0NBQ0YifQ==
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"txe_account_data_provider.d.ts","sourceRoot":"","sources":["../../src/util/txe_account_data_provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAiB,MAAM,iBAAiB,CAAC;AACxE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,qBAAa,sBAAsB;;IAGjC,YAAY,KAAK,EAAE,iBAAiB,EAEnC;IAEK,UAAU,CAAC,GAAG,EAAE,YAAY,4BAMjC;IAEK,UAAU,CAAC,GAAG,EAAE,YAAY,EAAE,KAAK,EAAE,eAAe,iBAEzD;CACF"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { ContractArtifact } from '@aztec/aztec.js/abi';
|
|
2
|
-
import { Fr } from '@aztec/aztec.js/fields';
|
|
3
|
-
import { ContractDataProvider } from '@aztec/pxe/server';
|
|
4
|
-
export type ContractArtifactWithHash = ContractArtifact & {
|
|
5
|
-
artifactHash: Fr;
|
|
6
|
-
};
|
|
7
|
-
export declare class TXEContractDataProvider extends ContractDataProvider {
|
|
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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHhlX2NvbnRyYWN0X2RhdGFfcHJvdmlkZXIuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy91dGlsL3R4ZV9jb250cmFjdF9kYXRhX3Byb3ZpZGVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxFQUFFLGdCQUFnQixFQUFFLE1BQU0scUJBQXFCLENBQUM7QUFDNUQsT0FBTyxFQUFFLEVBQUUsRUFBRSxNQUFNLHdCQUF3QixDQUFDO0FBQzVDLE9BQU8sRUFBRSxvQkFBb0IsRUFBRSxNQUFNLG1CQUFtQixDQUFDO0FBRXpELE1BQU0sTUFBTSx3QkFBd0IsR0FBRyxnQkFBZ0IsR0FBRztJQUFFLFlBQVksRUFBRSxFQUFFLENBQUE7Q0FBRSxDQUFDO0FBTy9FLHFCQUFhLHVCQUF3QixTQUFRLG9CQUFvQjs7SUFHekMsbUJBQW1CLENBQ3ZDLEVBQUUsRUFBRSxFQUFFLEVBQ04sUUFBUSxFQUFFLGdCQUFnQixHQUFHLHdCQUF3QixHQUNwRCxPQUFPLENBQUMsSUFBSSxDQUFDLENBS2Y7SUFFcUIsbUJBQW1CLENBQ3ZDLGVBQWUsRUFBRSxFQUFFLEdBQ2xCLE9BQU8sQ0FBQyxnQkFBZ0IsR0FBRyx3QkFBd0IsR0FBRyxTQUFTLENBQUMsQ0FRbEU7Q0FDRiJ9
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"txe_contract_data_provider.d.ts","sourceRoot":"","sources":["../../src/util/txe_contract_data_provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,EAAE,EAAE,MAAM,wBAAwB,CAAC;AAC5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAEzD,MAAM,MAAM,wBAAwB,GAAG,gBAAgB,GAAG;IAAE,YAAY,EAAE,EAAE,CAAA;CAAE,CAAC;AAO/E,qBAAa,uBAAwB,SAAQ,oBAAoB;;IAGzC,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"}
|