@aztec/txe 0.0.1-commit.03f7ef2 → 0.0.1-commit.0b941701
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/oracle/interfaces.d.ts +2 -2
- package/dest/oracle/interfaces.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.d.ts +2 -2
- package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.js +3 -2
- package/dest/oracle/txe_oracle_top_level_context.d.ts +16 -13
- package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_top_level_context.js +77 -61
- package/dest/rpc_translator.d.ts +15 -9
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +49 -35
- package/dest/state_machine/archiver.d.ts +20 -67
- package/dest/state_machine/archiver.d.ts.map +1 -1
- package/dest/state_machine/archiver.js +57 -178
- package/dest/state_machine/dummy_p2p_client.d.ts +8 -7
- package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
- package/dest/state_machine/dummy_p2p_client.js +13 -10
- package/dest/state_machine/global_variable_builder.d.ts +2 -2
- package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
- package/dest/state_machine/global_variable_builder.js +1 -1
- package/dest/state_machine/index.d.ts +4 -4
- package/dest/state_machine/index.d.ts.map +1 -1
- package/dest/state_machine/index.js +28 -10
- package/dest/state_machine/mock_epoch_cache.d.ts +7 -6
- package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
- package/dest/state_machine/mock_epoch_cache.js +10 -7
- package/dest/state_machine/synchronizer.d.ts +3 -3
- package/dest/state_machine/synchronizer.d.ts.map +1 -1
- package/dest/txe_session.d.ts +17 -14
- package/dest/txe_session.d.ts.map +1 -1
- package/dest/txe_session.js +86 -48
- package/dest/util/encoding.d.ts +17 -17
- 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 +4 -4
- package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
- package/dest/util/txe_public_contract_data_source.js +10 -10
- package/dest/utils/block_creation.d.ts +4 -4
- package/dest/utils/block_creation.d.ts.map +1 -1
- package/dest/utils/block_creation.js +16 -5
- package/dest/utils/tx_effect_creation.d.ts +2 -3
- package/dest/utils/tx_effect_creation.d.ts.map +1 -1
- package/dest/utils/tx_effect_creation.js +3 -6
- package/package.json +16 -16
- package/src/constants.ts +3 -0
- package/src/index.ts +1 -1
- package/src/oracle/interfaces.ts +1 -1
- package/src/oracle/txe_oracle_public_context.ts +3 -3
- package/src/oracle/txe_oracle_top_level_context.ts +110 -78
- package/src/rpc_translator.ts +53 -45
- package/src/state_machine/archiver.ts +52 -220
- package/src/state_machine/dummy_p2p_client.ts +18 -13
- package/src/state_machine/global_variable_builder.ts +1 -1
- package/src/state_machine/index.ts +30 -8
- package/src/state_machine/mock_epoch_cache.ts +10 -11
- package/src/state_machine/synchronizer.ts +2 -2
- package/src/txe_session.ts +165 -86
- 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 +9 -9
- package/src/utils/block_creation.ts +17 -16
- package/src/utils/tx_effect_creation.ts +3 -11
- 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
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { type AztecNodeConfig, AztecNodeService } from '@aztec/aztec-node';
|
|
2
2
|
import { TestCircuitVerifier } from '@aztec/bb-prover/test';
|
|
3
|
+
import { CheckpointNumber } from '@aztec/foundation/branded-types';
|
|
4
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
5
|
import { createLogger } from '@aztec/foundation/log';
|
|
4
6
|
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
5
|
-
import {
|
|
7
|
+
import { AnchorBlockStore } from '@aztec/pxe/server';
|
|
6
8
|
import { L2Block } from '@aztec/stdlib/block';
|
|
7
|
-
import { L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
9
|
+
import { Checkpoint, L1PublishedData, PublishedCheckpoint } from '@aztec/stdlib/checkpoint';
|
|
8
10
|
import type { AztecNode } from '@aztec/stdlib/interfaces/client';
|
|
11
|
+
import { CheckpointHeader } from '@aztec/stdlib/rollup';
|
|
9
12
|
import { getPackageVersion } from '@aztec/stdlib/update-checker';
|
|
10
13
|
|
|
11
14
|
import { TXEArchiver } from './archiver.js';
|
|
@@ -22,13 +25,13 @@ export class TXEStateMachine {
|
|
|
22
25
|
public node: AztecNode,
|
|
23
26
|
public synchronizer: TXESynchronizer,
|
|
24
27
|
public archiver: TXEArchiver,
|
|
25
|
-
public
|
|
28
|
+
public anchorBlockStore: AnchorBlockStore,
|
|
26
29
|
) {}
|
|
27
30
|
|
|
28
31
|
public static async create(db: AztecAsyncKVStore) {
|
|
29
32
|
const archiver = new TXEArchiver(db);
|
|
30
33
|
const synchronizer = await TXESynchronizer.create();
|
|
31
|
-
const
|
|
34
|
+
const anchorBlockStore = new AnchorBlockStore(db);
|
|
32
35
|
|
|
33
36
|
const aztecNodeConfig = {} as AztecNodeConfig;
|
|
34
37
|
|
|
@@ -55,11 +58,30 @@ export class TXEStateMachine {
|
|
|
55
58
|
log,
|
|
56
59
|
);
|
|
57
60
|
|
|
58
|
-
return new this(node, synchronizer, archiver,
|
|
61
|
+
return new this(node, synchronizer, archiver, anchorBlockStore);
|
|
59
62
|
}
|
|
60
63
|
|
|
61
64
|
public async handleL2Block(block: L2Block) {
|
|
62
|
-
|
|
65
|
+
// Create a checkpoint from the block manually
|
|
66
|
+
const checkpoint = new Checkpoint(
|
|
67
|
+
block.archive,
|
|
68
|
+
CheckpointHeader.from({
|
|
69
|
+
lastArchiveRoot: block.header.lastArchive.root,
|
|
70
|
+
inHash: Fr.ZERO,
|
|
71
|
+
blobsHash: Fr.ZERO,
|
|
72
|
+
blockHeadersHash: Fr.ZERO,
|
|
73
|
+
epochOutHash: Fr.ZERO,
|
|
74
|
+
slotNumber: block.header.globalVariables.slotNumber,
|
|
75
|
+
timestamp: block.header.globalVariables.timestamp,
|
|
76
|
+
coinbase: block.header.globalVariables.coinbase,
|
|
77
|
+
feeRecipient: block.header.globalVariables.feeRecipient,
|
|
78
|
+
gasFees: block.header.globalVariables.gasFees,
|
|
79
|
+
totalManaUsed: block.header.totalManaUsed,
|
|
80
|
+
}),
|
|
81
|
+
[block],
|
|
82
|
+
CheckpointNumber.fromBlockNumber(block.number),
|
|
83
|
+
);
|
|
84
|
+
|
|
63
85
|
const publishedCheckpoint = new PublishedCheckpoint(
|
|
64
86
|
checkpoint,
|
|
65
87
|
new L1PublishedData(
|
|
@@ -70,9 +92,9 @@ export class TXEStateMachine {
|
|
|
70
92
|
[],
|
|
71
93
|
);
|
|
72
94
|
await Promise.all([
|
|
73
|
-
this.synchronizer.handleL2Block(block
|
|
95
|
+
this.synchronizer.handleL2Block(block),
|
|
74
96
|
this.archiver.addCheckpoints([publishedCheckpoint], undefined),
|
|
75
|
-
this.
|
|
97
|
+
this.anchorBlockStore.setHeader(block.header),
|
|
76
98
|
]);
|
|
77
99
|
}
|
|
78
100
|
}
|
|
@@ -12,14 +12,16 @@ export class MockEpochCache implements EpochCacheInterface {
|
|
|
12
12
|
committee: undefined,
|
|
13
13
|
seed: 0n,
|
|
14
14
|
epoch: EpochNumber.ZERO,
|
|
15
|
+
isEscapeHatchOpen: false,
|
|
15
16
|
});
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
getEpochAndSlotNow(): EpochAndSlot {
|
|
19
|
+
getEpochAndSlotNow(): EpochAndSlot & { nowMs: bigint } {
|
|
19
20
|
return {
|
|
20
21
|
epoch: EpochNumber.ZERO,
|
|
21
22
|
slot: SlotNumber(0),
|
|
22
23
|
ts: 0n,
|
|
24
|
+
nowMs: 0n,
|
|
23
25
|
};
|
|
24
26
|
}
|
|
25
27
|
|
|
@@ -40,18 +42,15 @@ export class MockEpochCache implements EpochCacheInterface {
|
|
|
40
42
|
return 0n;
|
|
41
43
|
}
|
|
42
44
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
nextProposer: EthAddress | undefined;
|
|
46
|
-
currentSlot: SlotNumber;
|
|
47
|
-
nextSlot: SlotNumber;
|
|
48
|
-
}> {
|
|
49
|
-
return Promise.resolve({
|
|
50
|
-
currentProposer: undefined,
|
|
51
|
-
nextProposer: undefined,
|
|
45
|
+
getCurrentAndNextSlot(): { currentSlot: SlotNumber; nextSlot: SlotNumber } {
|
|
46
|
+
return {
|
|
52
47
|
currentSlot: SlotNumber(0),
|
|
53
48
|
nextSlot: SlotNumber(0),
|
|
54
|
-
}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
getProposerAttesterAddressInSlot(_slot: SlotNumber): Promise<EthAddress | undefined> {
|
|
53
|
+
return Promise.resolve(undefined);
|
|
55
54
|
}
|
|
56
55
|
|
|
57
56
|
isInCommittee(_slot: SlotTag, _validator: EthAddress): Promise<boolean> {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/constants';
|
|
2
2
|
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
3
3
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
|
-
import type {
|
|
4
|
+
import type { L2Block } from '@aztec/stdlib/block';
|
|
5
5
|
import type {
|
|
6
6
|
MerkleTreeReadOperations,
|
|
7
7
|
MerkleTreeWriteOperations,
|
|
@@ -23,7 +23,7 @@ export class TXESynchronizer implements WorldStateSynchronizer {
|
|
|
23
23
|
return new this(nativeWorldStateService);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
public async handleL2Block(block:
|
|
26
|
+
public async handleL2Block(block: L2Block) {
|
|
27
27
|
await this.nativeWorldStateService.handleL2BlockAndMessages(
|
|
28
28
|
block,
|
|
29
29
|
Array(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP).fill(0).map(Fr.zero),
|
package/src/txe_session.ts
CHANGED
|
@@ -5,13 +5,15 @@ import { KeyStore } from '@aztec/key-store';
|
|
|
5
5
|
import { openTmpStore } from '@aztec/kv-store/lmdb-v2';
|
|
6
6
|
import type { ProtocolContract } from '@aztec/protocol-contracts';
|
|
7
7
|
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
AddressStore,
|
|
9
|
+
CapsuleStore,
|
|
10
|
+
JobCoordinator,
|
|
11
11
|
NoteService,
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
NoteStore,
|
|
13
|
+
PrivateEventStore,
|
|
14
|
+
RecipientTaggingStore,
|
|
15
|
+
SenderAddressBookStore,
|
|
16
|
+
SenderTaggingStore,
|
|
15
17
|
} from '@aztec/pxe/server';
|
|
16
18
|
import {
|
|
17
19
|
ExecutionNoteCache,
|
|
@@ -19,10 +21,19 @@ import {
|
|
|
19
21
|
HashedValuesCache,
|
|
20
22
|
type IPrivateExecutionOracle,
|
|
21
23
|
type IUtilityExecutionOracle,
|
|
24
|
+
Oracle,
|
|
22
25
|
PrivateExecutionOracle,
|
|
23
26
|
UtilityExecutionOracle,
|
|
24
27
|
} from '@aztec/pxe/simulator';
|
|
25
|
-
import {
|
|
28
|
+
import {
|
|
29
|
+
ExecutionError,
|
|
30
|
+
WASMSimulator,
|
|
31
|
+
createSimulationError,
|
|
32
|
+
extractCallStack,
|
|
33
|
+
resolveAssertionMessageFromError,
|
|
34
|
+
toACVMWitness,
|
|
35
|
+
} from '@aztec/simulator/client';
|
|
36
|
+
import { FunctionCall, FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
|
|
26
37
|
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
27
38
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
28
39
|
import { GasSettings } from '@aztec/stdlib/gas';
|
|
@@ -33,14 +44,15 @@ import { CallContext, GlobalVariables, TxContext } from '@aztec/stdlib/tx';
|
|
|
33
44
|
|
|
34
45
|
import { z } from 'zod';
|
|
35
46
|
|
|
47
|
+
import { DEFAULT_ADDRESS } from './constants.js';
|
|
36
48
|
import type { IAvmExecutionOracle, ITxeExecutionOracle } from './oracle/interfaces.js';
|
|
37
49
|
import { TXEOraclePublicContext } from './oracle/txe_oracle_public_context.js';
|
|
38
50
|
import { TXEOracleTopLevelContext } from './oracle/txe_oracle_top_level_context.js';
|
|
39
51
|
import { RPCTranslator } from './rpc_translator.js';
|
|
40
52
|
import { TXEStateMachine } from './state_machine/index.js';
|
|
41
53
|
import type { ForeignCallArgs, ForeignCallResult } from './util/encoding.js';
|
|
42
|
-
import {
|
|
43
|
-
import {
|
|
54
|
+
import { TXEAccountStore } from './util/txe_account_store.js';
|
|
55
|
+
import { TXEContractStore } from './util/txe_contract_store.js';
|
|
44
56
|
import { getSingleTxBlockRequestHash, insertTxEffectIntoWorldTrees, makeTXEBlock } from './utils/block_creation.js';
|
|
45
57
|
import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
46
58
|
|
|
@@ -63,7 +75,6 @@ type SessionState =
|
|
|
63
75
|
| {
|
|
64
76
|
name: 'PRIVATE';
|
|
65
77
|
nextBlockGlobalVariables: GlobalVariables;
|
|
66
|
-
protocolNullifier: Fr;
|
|
67
78
|
noteCache: ExecutionNoteCache;
|
|
68
79
|
taggingIndexCache: ExecutionTaggingIndexCache;
|
|
69
80
|
}
|
|
@@ -102,8 +113,6 @@ export interface TXESessionStateHandler {
|
|
|
102
113
|
enterUtilityState(contractAddress?: AztecAddress): Promise<void>;
|
|
103
114
|
}
|
|
104
115
|
|
|
105
|
-
export const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
|
|
106
|
-
|
|
107
116
|
/**
|
|
108
117
|
* A `TXESession` corresponds to a Noir `#[test]` function, and handles all of its oracle calls, stores test-specific
|
|
109
118
|
* state, etc., independent of all other tests running in parallel.
|
|
@@ -120,15 +129,18 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
120
129
|
| IPrivateExecutionOracle
|
|
121
130
|
| IAvmExecutionOracle
|
|
122
131
|
| ITxeExecutionOracle,
|
|
123
|
-
private
|
|
124
|
-
private
|
|
132
|
+
private contractStore: TXEContractStore,
|
|
133
|
+
private noteStore: NoteStore,
|
|
125
134
|
private keyStore: KeyStore,
|
|
126
|
-
private
|
|
127
|
-
private
|
|
128
|
-
private
|
|
129
|
-
private
|
|
130
|
-
private
|
|
131
|
-
private
|
|
135
|
+
private addressStore: AddressStore,
|
|
136
|
+
private accountStore: TXEAccountStore,
|
|
137
|
+
private senderTaggingStore: SenderTaggingStore,
|
|
138
|
+
private recipientTaggingStore: RecipientTaggingStore,
|
|
139
|
+
private senderAddressBookStore: SenderAddressBookStore,
|
|
140
|
+
private capsuleStore: CapsuleStore,
|
|
141
|
+
private privateEventStore: PrivateEventStore,
|
|
142
|
+
private jobCoordinator: JobCoordinator,
|
|
143
|
+
private currentJobId: string,
|
|
132
144
|
private chainId: Fr,
|
|
133
145
|
private version: Fr,
|
|
134
146
|
private nextBlockTimestamp: bigint,
|
|
@@ -137,20 +149,31 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
137
149
|
static async init(protocolContracts: ProtocolContract[]) {
|
|
138
150
|
const store = await openTmpStore('txe-session');
|
|
139
151
|
|
|
140
|
-
const
|
|
141
|
-
const
|
|
142
|
-
const
|
|
143
|
-
const
|
|
144
|
-
const
|
|
145
|
-
const
|
|
146
|
-
const
|
|
152
|
+
const addressStore = new AddressStore(store);
|
|
153
|
+
const privateEventStore = new PrivateEventStore(store);
|
|
154
|
+
const contractStore = new TXEContractStore(store);
|
|
155
|
+
const noteStore = new NoteStore(store);
|
|
156
|
+
const senderTaggingStore = new SenderTaggingStore(store);
|
|
157
|
+
const recipientTaggingStore = new RecipientTaggingStore(store);
|
|
158
|
+
const senderAddressBookStore = new SenderAddressBookStore(store);
|
|
159
|
+
const capsuleStore = new CapsuleStore(store);
|
|
147
160
|
const keyStore = new KeyStore(store);
|
|
148
|
-
const
|
|
161
|
+
const accountStore = new TXEAccountStore(store);
|
|
162
|
+
|
|
163
|
+
// Create job coordinator and register staged stores
|
|
164
|
+
const jobCoordinator = new JobCoordinator(store);
|
|
165
|
+
jobCoordinator.registerStores([
|
|
166
|
+
capsuleStore,
|
|
167
|
+
senderTaggingStore,
|
|
168
|
+
recipientTaggingStore,
|
|
169
|
+
privateEventStore,
|
|
170
|
+
noteStore,
|
|
171
|
+
]);
|
|
149
172
|
|
|
150
173
|
// Register protocol contracts.
|
|
151
174
|
for (const { contractClass, instance, artifact } of protocolContracts) {
|
|
152
|
-
await
|
|
153
|
-
await
|
|
175
|
+
await contractStore.addContractArtifact(contractClass.id, artifact);
|
|
176
|
+
await contractStore.addContractInstance(instance);
|
|
154
177
|
}
|
|
155
178
|
|
|
156
179
|
const stateMachine = await TXEStateMachine.create(store);
|
|
@@ -159,17 +182,21 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
159
182
|
const version = new Fr(await stateMachine.node.getVersion());
|
|
160
183
|
const chainId = new Fr(await stateMachine.node.getChainId());
|
|
161
184
|
|
|
185
|
+
const initialJobId = jobCoordinator.beginJob();
|
|
186
|
+
|
|
162
187
|
const topLevelOracleHandler = new TXEOracleTopLevelContext(
|
|
163
188
|
stateMachine,
|
|
164
|
-
|
|
165
|
-
|
|
189
|
+
contractStore,
|
|
190
|
+
noteStore,
|
|
166
191
|
keyStore,
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
192
|
+
addressStore,
|
|
193
|
+
accountStore,
|
|
194
|
+
senderTaggingStore,
|
|
195
|
+
recipientTaggingStore,
|
|
196
|
+
senderAddressBookStore,
|
|
197
|
+
capsuleStore,
|
|
198
|
+
privateEventStore,
|
|
199
|
+
initialJobId,
|
|
173
200
|
nextBlockTimestamp,
|
|
174
201
|
version,
|
|
175
202
|
chainId,
|
|
@@ -181,15 +208,18 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
181
208
|
createLogger('txe:session'),
|
|
182
209
|
stateMachine,
|
|
183
210
|
topLevelOracleHandler,
|
|
184
|
-
|
|
185
|
-
|
|
211
|
+
contractStore,
|
|
212
|
+
noteStore,
|
|
186
213
|
keyStore,
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
214
|
+
addressStore,
|
|
215
|
+
accountStore,
|
|
216
|
+
senderTaggingStore,
|
|
217
|
+
recipientTaggingStore,
|
|
218
|
+
senderAddressBookStore,
|
|
219
|
+
capsuleStore,
|
|
220
|
+
privateEventStore,
|
|
221
|
+
jobCoordinator,
|
|
222
|
+
initialJobId,
|
|
193
223
|
version,
|
|
194
224
|
chainId,
|
|
195
225
|
nextBlockTimestamp,
|
|
@@ -249,17 +279,23 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
249
279
|
}
|
|
250
280
|
}
|
|
251
281
|
|
|
282
|
+
// Commit all staged stores from the job that was just completed, then begin a new job
|
|
283
|
+
await this.jobCoordinator.commitJob(this.currentJobId);
|
|
284
|
+
this.currentJobId = this.jobCoordinator.beginJob();
|
|
285
|
+
|
|
252
286
|
this.oracleHandler = new TXEOracleTopLevelContext(
|
|
253
287
|
this.stateMachine,
|
|
254
|
-
this.
|
|
255
|
-
this.
|
|
288
|
+
this.contractStore,
|
|
289
|
+
this.noteStore,
|
|
256
290
|
this.keyStore,
|
|
257
|
-
this.
|
|
258
|
-
this.
|
|
259
|
-
this.
|
|
260
|
-
this.
|
|
261
|
-
this.
|
|
262
|
-
this.
|
|
291
|
+
this.addressStore,
|
|
292
|
+
this.accountStore,
|
|
293
|
+
this.senderTaggingStore,
|
|
294
|
+
this.recipientTaggingStore,
|
|
295
|
+
this.senderAddressBookStore,
|
|
296
|
+
this.capsuleStore,
|
|
297
|
+
this.privateEventStore,
|
|
298
|
+
this.currentJobId,
|
|
263
299
|
this.nextBlockTimestamp,
|
|
264
300
|
this.version,
|
|
265
301
|
this.chainId,
|
|
@@ -276,15 +312,11 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
276
312
|
): Promise<PrivateContextInputs> {
|
|
277
313
|
this.exitTopLevelState();
|
|
278
314
|
|
|
279
|
-
// There is no automatic message discovery and contract-driven syncing process in inlined private or utility
|
|
280
|
-
// contexts, which means that known nullifiers are also not searched for, since it is during the tagging sync that
|
|
281
|
-
// we perform this. We therefore search for known nullifiers now, as otherwise notes that were nullified would not
|
|
282
|
-
// be removed from the database.
|
|
283
|
-
// TODO(#12553): make the synchronizer sync here instead and remove this
|
|
284
315
|
await new NoteService(
|
|
285
|
-
this.
|
|
316
|
+
this.noteStore,
|
|
286
317
|
this.stateMachine.node,
|
|
287
|
-
this.stateMachine.
|
|
318
|
+
this.stateMachine.anchorBlockStore,
|
|
319
|
+
this.currentJobId,
|
|
288
320
|
).syncNoteNullifiers(contractAddress);
|
|
289
321
|
|
|
290
322
|
// Private execution has two associated block numbers: the anchor block (i.e. the historical block that is used to
|
|
@@ -305,26 +337,30 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
305
337
|
const noteCache = new ExecutionNoteCache(protocolNullifier);
|
|
306
338
|
const taggingIndexCache = new ExecutionTaggingIndexCache();
|
|
307
339
|
|
|
340
|
+
const utilityExecutor = this.utilityExecutorForContractSync(anchorBlock);
|
|
308
341
|
this.oracleHandler = new PrivateExecutionOracle(
|
|
309
342
|
Fr.ZERO,
|
|
310
343
|
new TxContext(this.chainId, this.version, GasSettings.empty()),
|
|
311
344
|
new CallContext(AztecAddress.ZERO, contractAddress, FunctionSelector.empty(), false),
|
|
312
345
|
anchorBlock!,
|
|
346
|
+
utilityExecutor,
|
|
313
347
|
[],
|
|
314
348
|
[],
|
|
315
349
|
new HashedValuesCache(),
|
|
316
350
|
noteCache,
|
|
317
351
|
taggingIndexCache,
|
|
318
|
-
this.
|
|
319
|
-
this.
|
|
352
|
+
this.contractStore,
|
|
353
|
+
this.noteStore,
|
|
320
354
|
this.keyStore,
|
|
321
|
-
this.
|
|
355
|
+
this.addressStore,
|
|
322
356
|
this.stateMachine.node,
|
|
323
|
-
this.stateMachine.
|
|
324
|
-
this.
|
|
325
|
-
this.
|
|
326
|
-
this.
|
|
327
|
-
this.
|
|
357
|
+
this.stateMachine.anchorBlockStore,
|
|
358
|
+
this.senderTaggingStore,
|
|
359
|
+
this.recipientTaggingStore,
|
|
360
|
+
this.senderAddressBookStore,
|
|
361
|
+
this.capsuleStore,
|
|
362
|
+
this.privateEventStore,
|
|
363
|
+
this.currentJobId,
|
|
328
364
|
);
|
|
329
365
|
|
|
330
366
|
// We store the note and tagging index caches fed into the PrivateExecutionOracle (along with some other auxiliary
|
|
@@ -332,7 +368,7 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
332
368
|
// difference resides in that the simulator has all information needed in order to run the simulation, while ours
|
|
333
369
|
// will be ongoing as the different oracles will be invoked from the Noir test, until eventually the private
|
|
334
370
|
// execution finishes.
|
|
335
|
-
this.state = { name: 'PRIVATE', nextBlockGlobalVariables,
|
|
371
|
+
this.state = { name: 'PRIVATE', nextBlockGlobalVariables, noteCache, taggingIndexCache };
|
|
336
372
|
this.logger.debug(`Entered state ${this.state.name}`);
|
|
337
373
|
|
|
338
374
|
return (this.oracleHandler as PrivateExecutionOracle).getPrivateContextInputs();
|
|
@@ -371,28 +407,30 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
371
407
|
// be removed from the database.
|
|
372
408
|
// TODO(#12553): make the synchronizer sync here instead and remove this
|
|
373
409
|
await new NoteService(
|
|
374
|
-
this.
|
|
410
|
+
this.noteStore,
|
|
375
411
|
this.stateMachine.node,
|
|
376
|
-
this.stateMachine.
|
|
412
|
+
this.stateMachine.anchorBlockStore,
|
|
413
|
+
this.currentJobId,
|
|
377
414
|
).syncNoteNullifiers(contractAddress);
|
|
378
415
|
|
|
379
|
-
const anchorBlockHeader = await this.stateMachine.
|
|
416
|
+
const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
380
417
|
|
|
381
418
|
this.oracleHandler = new UtilityExecutionOracle(
|
|
382
419
|
contractAddress,
|
|
383
420
|
[],
|
|
384
421
|
[],
|
|
385
422
|
anchorBlockHeader,
|
|
386
|
-
this.
|
|
387
|
-
this.
|
|
423
|
+
this.contractStore,
|
|
424
|
+
this.noteStore,
|
|
388
425
|
this.keyStore,
|
|
389
|
-
this.
|
|
426
|
+
this.addressStore,
|
|
390
427
|
this.stateMachine.node,
|
|
391
|
-
this.stateMachine.
|
|
392
|
-
this.
|
|
393
|
-
this.
|
|
394
|
-
this.
|
|
395
|
-
this.
|
|
428
|
+
this.stateMachine.anchorBlockStore,
|
|
429
|
+
this.recipientTaggingStore,
|
|
430
|
+
this.senderAddressBookStore,
|
|
431
|
+
this.capsuleStore,
|
|
432
|
+
this.privateEventStore,
|
|
433
|
+
this.currentJobId,
|
|
396
434
|
);
|
|
397
435
|
|
|
398
436
|
this.state = { name: 'UTILITY' };
|
|
@@ -428,11 +466,7 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
428
466
|
// We rely on the note cache to determine the effects of the transaction. This is incomplete as it doesn't private
|
|
429
467
|
// logs (other effects like enqueued public calls don't need to be considered since those are not allowed).
|
|
430
468
|
|
|
431
|
-
const txEffect = await makeTxEffect(
|
|
432
|
-
this.state.noteCache,
|
|
433
|
-
this.state.protocolNullifier,
|
|
434
|
-
this.state.nextBlockGlobalVariables.blockNumber,
|
|
435
|
-
);
|
|
469
|
+
const txEffect = await makeTxEffect(this.state.noteCache, this.state.nextBlockGlobalVariables.blockNumber);
|
|
436
470
|
|
|
437
471
|
// We build a block holding just this transaction
|
|
438
472
|
const forkedWorldTrees = await this.stateMachine.synchronizer.nativeWorldStateService.fork();
|
|
@@ -463,4 +497,49 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
463
497
|
throw new Error(`Expected to be in state 'UTILITY', but got '${this.state.name}' instead`);
|
|
464
498
|
}
|
|
465
499
|
}
|
|
500
|
+
|
|
501
|
+
private utilityExecutorForContractSync(anchorBlock: any) {
|
|
502
|
+
return async (call: FunctionCall) => {
|
|
503
|
+
const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
|
|
504
|
+
if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
|
|
505
|
+
throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
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.stateMachine.anchorBlockStore,
|
|
520
|
+
this.recipientTaggingStore,
|
|
521
|
+
this.senderAddressBookStore,
|
|
522
|
+
this.capsuleStore,
|
|
523
|
+
this.privateEventStore,
|
|
524
|
+
this.currentJobId,
|
|
525
|
+
);
|
|
526
|
+
await new WASMSimulator()
|
|
527
|
+
.executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, new Oracle(oracle).toACIRCallback())
|
|
528
|
+
.catch((err: Error) => {
|
|
529
|
+
err.message = resolveAssertionMessageFromError(err, entryPointArtifact);
|
|
530
|
+
throw new ExecutionError(
|
|
531
|
+
err.message,
|
|
532
|
+
{
|
|
533
|
+
contractAddress: call.to,
|
|
534
|
+
functionSelector: call.selector,
|
|
535
|
+
},
|
|
536
|
+
extractCallStack(err, entryPointArtifact.debug),
|
|
537
|
+
{ cause: err },
|
|
538
|
+
);
|
|
539
|
+
});
|
|
540
|
+
} catch (err) {
|
|
541
|
+
throw createSimulationError(err instanceof Error ? err : new Error('Unknown error contract data sync'));
|
|
542
|
+
}
|
|
543
|
+
};
|
|
544
|
+
}
|
|
466
545
|
}
|
|
@@ -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,6 +1,6 @@
|
|
|
1
1
|
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
2
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
|
-
import type {
|
|
3
|
+
import type { ContractStore } from '@aztec/pxe/server';
|
|
4
4
|
import { type ContractArtifact, FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
|
|
5
5
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
6
6
|
import {
|
|
@@ -16,7 +16,7 @@ export class TXEPublicContractDataSource implements ContractDataSource {
|
|
|
16
16
|
#privateFunctionsRoot: Map<string, Buffer> = new Map();
|
|
17
17
|
constructor(
|
|
18
18
|
private blockNumber: BlockNumber,
|
|
19
|
-
private
|
|
19
|
+
private contractStore: ContractStore,
|
|
20
20
|
) {}
|
|
21
21
|
|
|
22
22
|
getBlockNumber(): Promise<BlockNumber> {
|
|
@@ -24,11 +24,11 @@ export class TXEPublicContractDataSource implements ContractDataSource {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
async getContractClass(id: Fr): Promise<ContractClassPublic | undefined> {
|
|
27
|
-
const contractClass = await this.
|
|
27
|
+
const contractClass = await this.contractStore.getContractClass(id);
|
|
28
28
|
if (!contractClass) {
|
|
29
29
|
return;
|
|
30
30
|
}
|
|
31
|
-
const artifact = await this.
|
|
31
|
+
const artifact = await this.contractStore.getContractArtifact(id);
|
|
32
32
|
if (!artifact) {
|
|
33
33
|
return;
|
|
34
34
|
}
|
|
@@ -58,12 +58,12 @@ export class TXEPublicContractDataSource implements ContractDataSource {
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
async getBytecodeCommitment(id: Fr): Promise<Fr | undefined> {
|
|
61
|
-
const contractClass = await this.
|
|
61
|
+
const contractClass = await this.contractStore.getContractClass(id);
|
|
62
62
|
return contractClass && computePublicBytecodeCommitment(contractClass.packedBytecode);
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
async getContract(address: AztecAddress): Promise<ContractInstanceWithAddress | undefined> {
|
|
66
|
-
const instance = await this.
|
|
66
|
+
const instance = await this.contractStore.getContractInstance(address);
|
|
67
67
|
return instance && { ...instance, address };
|
|
68
68
|
}
|
|
69
69
|
|
|
@@ -72,12 +72,12 @@ export class TXEPublicContractDataSource implements ContractDataSource {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
async getContractArtifact(address: AztecAddress): Promise<ContractArtifact | undefined> {
|
|
75
|
-
const instance = await this.
|
|
76
|
-
return instance && this.
|
|
75
|
+
const instance = await this.contractStore.getContractInstance(address);
|
|
76
|
+
return instance && this.contractStore.getContractArtifact(instance.currentContractClassId);
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
async getDebugFunctionName(address: AztecAddress, selector: FunctionSelector): Promise<string | undefined> {
|
|
80
|
-
return await this.
|
|
80
|
+
return await this.contractStore.getDebugFunctionName(address, selector);
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
registerContractFunctionSignatures(_signatures: []): Promise<void> {
|