@aztec/txe 0.0.1-commit.5476d83 → 0.0.1-commit.5914bae
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/constants.d.ts +3 -0
- package/dest/constants.d.ts.map +1 -0
- package/dest/constants.js +2 -0
- package/dest/index.d.ts +1 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +91 -56
- package/dest/oracle/interfaces.d.ts +33 -29
- package/dest/oracle/interfaces.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.d.ts +16 -16
- package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.js +20 -22
- package/dest/oracle/txe_oracle_top_level_context.d.ts +42 -27
- package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_top_level_context.js +232 -107
- package/dest/rpc_translator.d.ts +129 -79
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +465 -175
- package/dest/state_machine/archiver.d.ts +21 -52
- package/dest/state_machine/archiver.d.ts.map +1 -1
- package/dest/state_machine/archiver.js +66 -99
- package/dest/state_machine/dummy_p2p_client.d.ts +20 -15
- package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
- package/dest/state_machine/dummy_p2p_client.js +42 -25
- package/dest/state_machine/global_variable_builder.d.ts +6 -5
- package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
- package/dest/state_machine/global_variable_builder.js +13 -1
- package/dest/state_machine/index.d.ts +9 -7
- package/dest/state_machine/index.d.ts.map +1 -1
- package/dest/state_machine/index.js +44 -23
- package/dest/state_machine/mock_epoch_cache.d.ts +9 -6
- package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
- package/dest/state_machine/mock_epoch_cache.js +14 -7
- package/dest/state_machine/synchronizer.d.ts +6 -5
- package/dest/state_machine/synchronizer.d.ts.map +1 -1
- package/dest/state_machine/synchronizer.js +8 -7
- package/dest/txe_session.d.ts +27 -15
- package/dest/txe_session.d.ts.map +1 -1
- package/dest/txe_session.js +173 -55
- package/dest/util/encoding.d.ts +617 -19
- package/dest/util/encoding.d.ts.map +1 -1
- package/dest/util/encoding.js +1 -1
- package/dest/util/txe_account_store.d.ts +10 -0
- package/dest/util/txe_account_store.d.ts.map +1 -0
- package/dest/util/{txe_account_data_provider.js → txe_account_store.js} +1 -1
- package/dest/util/txe_public_contract_data_source.d.ts +8 -8
- package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
- package/dest/util/txe_public_contract_data_source.js +12 -29
- package/dest/utils/block_creation.d.ts +21 -6
- package/dest/utils/block_creation.d.ts.map +1 -1
- package/dest/utils/block_creation.js +38 -4
- package/dest/utils/tx_effect_creation.d.ts +3 -3
- package/dest/utils/tx_effect_creation.d.ts.map +1 -1
- package/dest/utils/tx_effect_creation.js +4 -7
- package/package.json +18 -18
- package/src/constants.ts +3 -0
- package/src/index.ts +103 -63
- package/src/oracle/interfaces.ts +36 -32
- package/src/oracle/txe_oracle_public_context.ts +21 -28
- package/src/oracle/txe_oracle_top_level_context.ts +285 -149
- package/src/rpc_translator.ts +552 -193
- package/src/state_machine/archiver.ts +62 -117
- package/src/state_machine/dummy_p2p_client.ts +58 -33
- package/src/state_machine/global_variable_builder.ts +21 -4
- package/src/state_machine/index.ts +64 -21
- package/src/state_machine/mock_epoch_cache.ts +15 -11
- package/src/state_machine/synchronizer.ts +9 -8
- package/src/txe_session.ts +239 -104
- package/src/util/encoding.ts +1 -1
- package/src/util/{txe_account_data_provider.ts → txe_account_store.ts} +1 -1
- package/src/util/txe_public_contract_data_source.ts +20 -45
- package/src/utils/block_creation.ts +49 -15
- package/src/utils/tx_effect_creation.ts +5 -12
- package/dest/util/txe_account_data_provider.d.ts +0 -10
- package/dest/util/txe_account_data_provider.d.ts.map +0 -1
- package/dest/util/txe_contract_data_provider.d.ts +0 -12
- package/dest/util/txe_contract_data_provider.d.ts.map +0 -1
- package/dest/util/txe_contract_data_provider.js +0 -22
- package/src/util/txe_contract_data_provider.ts +0 -36
package/dest/txe_session.js
CHANGED
|
@@ -1,26 +1,27 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
3
|
import { createLogger } from '@aztec/foundation/log';
|
|
3
4
|
import { KeyStore } from '@aztec/key-store';
|
|
4
5
|
import { openTmpStore } from '@aztec/kv-store/lmdb-v2';
|
|
5
|
-
import {
|
|
6
|
-
import { ExecutionNoteCache, ExecutionTaggingIndexCache, HashedValuesCache, PrivateExecutionOracle, UtilityExecutionOracle } from '@aztec/pxe/simulator';
|
|
7
|
-
import {
|
|
6
|
+
import { AddressStore, AnchorBlockStore, CapsuleService, CapsuleStore, ContractSyncService, JobCoordinator, NoteService, NoteStore, PrivateEventStore, RecipientTaggingStore, SenderAddressBookStore, SenderTaggingStore } from '@aztec/pxe/server';
|
|
7
|
+
import { ExecutionNoteCache, ExecutionTaggingIndexCache, HashedValuesCache, Oracle, PrivateExecutionOracle, UtilityExecutionOracle } from '@aztec/pxe/simulator';
|
|
8
|
+
import { ExecutionError, WASMSimulator, createSimulationError, extractCallStack, resolveAssertionMessageFromError, toACVMWitness } from '@aztec/simulator/client';
|
|
9
|
+
import { FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
|
|
8
10
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
9
|
-
import { Body, L2Block } from '@aztec/stdlib/block';
|
|
10
11
|
import { GasSettings } from '@aztec/stdlib/gas';
|
|
11
12
|
import { computeProtocolNullifier } from '@aztec/stdlib/hash';
|
|
12
|
-
import {
|
|
13
|
+
import { makeGlobalVariables } from '@aztec/stdlib/testing';
|
|
13
14
|
import { CallContext, TxContext } from '@aztec/stdlib/tx';
|
|
14
15
|
import { z } from 'zod';
|
|
16
|
+
import { DEFAULT_ADDRESS } from './constants.js';
|
|
15
17
|
import { TXEOraclePublicContext } from './oracle/txe_oracle_public_context.js';
|
|
16
18
|
import { TXEOracleTopLevelContext } from './oracle/txe_oracle_top_level_context.js';
|
|
17
19
|
import { RPCTranslator } from './rpc_translator.js';
|
|
20
|
+
import { TXEArchiver } from './state_machine/archiver.js';
|
|
18
21
|
import { TXEStateMachine } from './state_machine/index.js';
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import { getSingleTxBlockRequestHash, insertTxEffectIntoWorldTrees, makeTXEBlockHeader } from './utils/block_creation.js';
|
|
22
|
+
import { TXEAccountStore } from './util/txe_account_store.js';
|
|
23
|
+
import { getSingleTxBlockRequestHash, insertTxEffectIntoWorldTrees, makeTXEBlock } from './utils/block_creation.js';
|
|
22
24
|
import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
23
|
-
const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
|
|
24
25
|
/**
|
|
25
26
|
* A `TXESession` corresponds to a Noir `#[test]` function, and handles all of its oracle calls, stores test-specific
|
|
26
27
|
* state, etc., independent of all other tests running in parallel.
|
|
@@ -28,56 +29,81 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
|
|
|
28
29
|
logger;
|
|
29
30
|
stateMachine;
|
|
30
31
|
oracleHandler;
|
|
31
|
-
|
|
32
|
+
contractStore;
|
|
33
|
+
noteStore;
|
|
32
34
|
keyStore;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
+
addressStore;
|
|
36
|
+
accountStore;
|
|
37
|
+
senderTaggingStore;
|
|
38
|
+
recipientTaggingStore;
|
|
39
|
+
senderAddressBookStore;
|
|
40
|
+
capsuleStore;
|
|
41
|
+
privateEventStore;
|
|
42
|
+
jobCoordinator;
|
|
43
|
+
currentJobId;
|
|
35
44
|
chainId;
|
|
36
45
|
version;
|
|
37
46
|
nextBlockTimestamp;
|
|
38
|
-
|
|
47
|
+
contractSyncService;
|
|
39
48
|
state;
|
|
40
49
|
authwits;
|
|
41
|
-
constructor(logger, stateMachine, oracleHandler,
|
|
50
|
+
constructor(logger, stateMachine, oracleHandler, contractStore, noteStore, keyStore, addressStore, accountStore, senderTaggingStore, recipientTaggingStore, senderAddressBookStore, capsuleStore, privateEventStore, jobCoordinator, currentJobId, chainId, version, nextBlockTimestamp, contractSyncService){
|
|
42
51
|
this.logger = logger;
|
|
43
52
|
this.stateMachine = stateMachine;
|
|
44
53
|
this.oracleHandler = oracleHandler;
|
|
45
|
-
this.
|
|
54
|
+
this.contractStore = contractStore;
|
|
55
|
+
this.noteStore = noteStore;
|
|
46
56
|
this.keyStore = keyStore;
|
|
47
|
-
this.
|
|
48
|
-
this.
|
|
57
|
+
this.addressStore = addressStore;
|
|
58
|
+
this.accountStore = accountStore;
|
|
59
|
+
this.senderTaggingStore = senderTaggingStore;
|
|
60
|
+
this.recipientTaggingStore = recipientTaggingStore;
|
|
61
|
+
this.senderAddressBookStore = senderAddressBookStore;
|
|
62
|
+
this.capsuleStore = capsuleStore;
|
|
63
|
+
this.privateEventStore = privateEventStore;
|
|
64
|
+
this.jobCoordinator = jobCoordinator;
|
|
65
|
+
this.currentJobId = currentJobId;
|
|
49
66
|
this.chainId = chainId;
|
|
50
67
|
this.version = version;
|
|
51
68
|
this.nextBlockTimestamp = nextBlockTimestamp;
|
|
52
|
-
this.
|
|
69
|
+
this.contractSyncService = contractSyncService;
|
|
53
70
|
this.state = {
|
|
54
71
|
name: 'TOP_LEVEL'
|
|
55
72
|
};
|
|
56
73
|
this.authwits = new Map();
|
|
57
74
|
}
|
|
58
|
-
static async init(
|
|
75
|
+
static async init(contractStore) {
|
|
59
76
|
const store = await openTmpStore('txe-session');
|
|
60
|
-
const
|
|
61
|
-
const
|
|
62
|
-
const
|
|
63
|
-
const
|
|
64
|
-
const
|
|
65
|
-
const
|
|
77
|
+
const addressStore = new AddressStore(store);
|
|
78
|
+
const privateEventStore = new PrivateEventStore(store);
|
|
79
|
+
const noteStore = new NoteStore(store);
|
|
80
|
+
const senderTaggingStore = new SenderTaggingStore(store);
|
|
81
|
+
const recipientTaggingStore = new RecipientTaggingStore(store);
|
|
82
|
+
const senderAddressBookStore = new SenderAddressBookStore(store);
|
|
83
|
+
const capsuleStore = new CapsuleStore(store);
|
|
66
84
|
const keyStore = new KeyStore(store);
|
|
67
|
-
const
|
|
68
|
-
//
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
85
|
+
const accountStore = new TXEAccountStore(store);
|
|
86
|
+
// Create job coordinator and register staged stores
|
|
87
|
+
const jobCoordinator = new JobCoordinator(store);
|
|
88
|
+
jobCoordinator.registerStores([
|
|
89
|
+
capsuleStore,
|
|
90
|
+
senderTaggingStore,
|
|
91
|
+
recipientTaggingStore,
|
|
92
|
+
privateEventStore,
|
|
93
|
+
noteStore
|
|
94
|
+
]);
|
|
95
|
+
const archiver = new TXEArchiver(store);
|
|
96
|
+
const anchorBlockStore = new AnchorBlockStore(store);
|
|
97
|
+
const stateMachine = await TXEStateMachine.create(archiver, anchorBlockStore, contractStore, noteStore);
|
|
74
98
|
const nextBlockTimestamp = BigInt(Math.floor(new Date().getTime() / 1000));
|
|
75
99
|
const version = new Fr(await stateMachine.node.getVersion());
|
|
76
100
|
const chainId = new Fr(await stateMachine.node.getChainId());
|
|
77
|
-
const
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
101
|
+
const initialJobId = jobCoordinator.beginJob();
|
|
102
|
+
const logger = createLogger('txe:session');
|
|
103
|
+
const contractSyncService = new ContractSyncService(stateMachine.node, contractStore, noteStore, logger);
|
|
104
|
+
const topLevelOracleHandler = new TXEOracleTopLevelContext(stateMachine, contractStore, noteStore, keyStore, addressStore, accountStore, senderTaggingStore, recipientTaggingStore, senderAddressBookStore, capsuleStore, privateEventStore, nextBlockTimestamp, version, chainId, new Map(), contractSyncService);
|
|
105
|
+
await topLevelOracleHandler.advanceBlocksBy(1);
|
|
106
|
+
return new TXESession(logger, stateMachine, topLevelOracleHandler, contractStore, noteStore, keyStore, addressStore, accountStore, senderTaggingStore, recipientTaggingStore, senderAddressBookStore, capsuleStore, privateEventStore, jobCoordinator, initialJobId, version, chainId, nextBlockTimestamp, contractSyncService);
|
|
81
107
|
}
|
|
82
108
|
/**
|
|
83
109
|
* Processes an oracle function invoked by the Noir test associated to this session.
|
|
@@ -100,6 +126,14 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
|
|
|
100
126
|
}
|
|
101
127
|
}
|
|
102
128
|
}
|
|
129
|
+
getCurrentJob() {
|
|
130
|
+
return this.currentJobId;
|
|
131
|
+
}
|
|
132
|
+
/** Commits the current job and begins a new one. Returns the new job ID. */ async cycleJob() {
|
|
133
|
+
await this.jobCoordinator.commitJob(this.currentJobId);
|
|
134
|
+
this.currentJobId = this.jobCoordinator.beginJob();
|
|
135
|
+
return this.currentJobId;
|
|
136
|
+
}
|
|
103
137
|
async enterTopLevelState() {
|
|
104
138
|
switch(this.state.name){
|
|
105
139
|
case 'PRIVATE':
|
|
@@ -126,7 +160,9 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
|
|
|
126
160
|
this.state;
|
|
127
161
|
}
|
|
128
162
|
}
|
|
129
|
-
|
|
163
|
+
// Commit all staged stores from the job that was just completed, then begin a new job
|
|
164
|
+
await this.cycleJob();
|
|
165
|
+
this.oracleHandler = new TXEOracleTopLevelContext(this.stateMachine, this.contractStore, this.noteStore, this.keyStore, this.addressStore, this.accountStore, this.senderTaggingStore, this.recipientTaggingStore, this.senderAddressBookStore, this.capsuleStore, this.privateEventStore, this.nextBlockTimestamp, this.version, this.chainId, this.authwits, this.contractSyncService);
|
|
130
166
|
this.state = {
|
|
131
167
|
name: 'TOP_LEVEL'
|
|
132
168
|
};
|
|
@@ -134,19 +170,14 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
|
|
|
134
170
|
}
|
|
135
171
|
async enterPrivateState(contractAddress = DEFAULT_ADDRESS, anchorBlockNumber) {
|
|
136
172
|
this.exitTopLevelState();
|
|
137
|
-
// There is no automatic message discovery and contract-driven syncing process in inlined private or utility
|
|
138
|
-
// contexts, which means that known nullifiers are also not searched for, since it is during the tagging sync that
|
|
139
|
-
// we perform this. We therefore search for known nullifiers now, as otherwise notes that were nullified would not
|
|
140
|
-
// be removed from the database.
|
|
141
|
-
// TODO(#12553): make the synchronizer sync here instead and remove this
|
|
142
|
-
await this.pxeOracleInterface.syncNoteNullifiers(contractAddress);
|
|
143
173
|
// Private execution has two associated block numbers: the anchor block (i.e. the historical block that is used to
|
|
144
174
|
// build the proof), and the *next* block, i.e. the one we'll create once the execution ends, and which will contain
|
|
145
175
|
// a single transaction with the effects of what was done in the test.
|
|
146
176
|
const anchorBlock = await this.stateMachine.node.getBlockHeader(anchorBlockNumber ?? 'latest');
|
|
177
|
+
await new NoteService(this.noteStore, this.stateMachine.node, anchorBlock, this.currentJobId).syncNoteNullifiers(contractAddress, await this.keyStore.getAccounts());
|
|
147
178
|
const latestBlock = await this.stateMachine.node.getBlockHeader('latest');
|
|
148
179
|
const nextBlockGlobalVariables = makeGlobalVariables(undefined, {
|
|
149
|
-
blockNumber: latestBlock.globalVariables.blockNumber + 1,
|
|
180
|
+
blockNumber: BlockNumber(latestBlock.globalVariables.blockNumber + 1),
|
|
150
181
|
timestamp: this.nextBlockTimestamp,
|
|
151
182
|
version: this.version,
|
|
152
183
|
chainId: this.chainId
|
|
@@ -155,7 +186,34 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
|
|
|
155
186
|
const protocolNullifier = await computeProtocolNullifier(txRequestHash);
|
|
156
187
|
const noteCache = new ExecutionNoteCache(protocolNullifier);
|
|
157
188
|
const taggingIndexCache = new ExecutionTaggingIndexCache();
|
|
158
|
-
|
|
189
|
+
const utilityExecutor = this.utilityExecutorForContractSync(anchorBlock);
|
|
190
|
+
this.oracleHandler = new PrivateExecutionOracle({
|
|
191
|
+
argsHash: Fr.ZERO,
|
|
192
|
+
txContext: new TxContext(this.chainId, this.version, GasSettings.empty()),
|
|
193
|
+
callContext: new CallContext(AztecAddress.ZERO, contractAddress, FunctionSelector.empty(), false),
|
|
194
|
+
anchorBlockHeader: anchorBlock,
|
|
195
|
+
utilityExecutor,
|
|
196
|
+
authWitnesses: [],
|
|
197
|
+
capsules: [],
|
|
198
|
+
executionCache: new HashedValuesCache(),
|
|
199
|
+
noteCache,
|
|
200
|
+
taggingIndexCache,
|
|
201
|
+
contractStore: this.contractStore,
|
|
202
|
+
noteStore: this.noteStore,
|
|
203
|
+
keyStore: this.keyStore,
|
|
204
|
+
addressStore: this.addressStore,
|
|
205
|
+
aztecNode: this.stateMachine.node,
|
|
206
|
+
senderTaggingStore: this.senderTaggingStore,
|
|
207
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
208
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
209
|
+
capsuleService: new CapsuleService(this.capsuleStore, await this.keyStore.getAccounts()),
|
|
210
|
+
privateEventStore: this.privateEventStore,
|
|
211
|
+
contractSyncService: this.stateMachine.contractSyncService,
|
|
212
|
+
l2TipsStore: this.stateMachine.node,
|
|
213
|
+
jobId: this.currentJobId,
|
|
214
|
+
scopes: await this.keyStore.getAccounts(),
|
|
215
|
+
messageContextService: this.stateMachine.messageContextService
|
|
216
|
+
});
|
|
159
217
|
// We store the note and tagging index caches fed into the PrivateExecutionOracle (along with some other auxiliary
|
|
160
218
|
// data) in order to refer to it later, mimicking the way this object is used by the ContractFunctionSimulator. The
|
|
161
219
|
// difference resides in that the simulator has all information needed in order to run the simulation, while ours
|
|
@@ -164,7 +222,6 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
|
|
|
164
222
|
this.state = {
|
|
165
223
|
name: 'PRIVATE',
|
|
166
224
|
nextBlockGlobalVariables,
|
|
167
|
-
protocolNullifier,
|
|
168
225
|
noteCache,
|
|
169
226
|
taggingIndexCache
|
|
170
227
|
};
|
|
@@ -177,7 +234,7 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
|
|
|
177
234
|
// the test. The block therefore gets the *next* block number and timestamp.
|
|
178
235
|
const latestBlockNumber = (await this.stateMachine.node.getBlockHeader('latest')).globalVariables.blockNumber;
|
|
179
236
|
const globalVariables = makeGlobalVariables(undefined, {
|
|
180
|
-
blockNumber: latestBlockNumber + 1,
|
|
237
|
+
blockNumber: BlockNumber(latestBlockNumber + 1),
|
|
181
238
|
timestamp: this.nextBlockTimestamp,
|
|
182
239
|
version: this.version,
|
|
183
240
|
chainId: this.chainId
|
|
@@ -190,13 +247,33 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
|
|
|
190
247
|
}
|
|
191
248
|
async enterUtilityState(contractAddress = DEFAULT_ADDRESS) {
|
|
192
249
|
this.exitTopLevelState();
|
|
250
|
+
const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
193
251
|
// There is no automatic message discovery and contract-driven syncing process in inlined private or utility
|
|
194
252
|
// contexts, which means that known nullifiers are also not searched for, since it is during the tagging sync that
|
|
195
253
|
// we perform this. We therefore search for known nullifiers now, as otherwise notes that were nullified would not
|
|
196
254
|
// be removed from the database.
|
|
197
255
|
// TODO(#12553): make the synchronizer sync here instead and remove this
|
|
198
|
-
await this.
|
|
199
|
-
this.oracleHandler = new UtilityExecutionOracle(
|
|
256
|
+
await new NoteService(this.noteStore, this.stateMachine.node, anchorBlockHeader, this.currentJobId).syncNoteNullifiers(contractAddress, await this.keyStore.getAccounts());
|
|
257
|
+
this.oracleHandler = new UtilityExecutionOracle({
|
|
258
|
+
contractAddress,
|
|
259
|
+
authWitnesses: [],
|
|
260
|
+
capsules: [],
|
|
261
|
+
anchorBlockHeader,
|
|
262
|
+
contractStore: this.contractStore,
|
|
263
|
+
noteStore: this.noteStore,
|
|
264
|
+
keyStore: this.keyStore,
|
|
265
|
+
addressStore: this.addressStore,
|
|
266
|
+
aztecNode: this.stateMachine.node,
|
|
267
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
268
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
269
|
+
capsuleService: new CapsuleService(this.capsuleStore, await this.keyStore.getAccounts()),
|
|
270
|
+
privateEventStore: this.privateEventStore,
|
|
271
|
+
messageContextService: this.stateMachine.messageContextService,
|
|
272
|
+
contractSyncService: this.contractSyncService,
|
|
273
|
+
l2TipsStore: this.stateMachine.node,
|
|
274
|
+
jobId: this.currentJobId,
|
|
275
|
+
scopes: await this.keyStore.getAccounts()
|
|
276
|
+
});
|
|
200
277
|
this.state = {
|
|
201
278
|
name: 'UTILITY'
|
|
202
279
|
};
|
|
@@ -208,8 +285,8 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
|
|
|
208
285
|
}
|
|
209
286
|
// Note that while all public and private contexts do is build a single block that we then process when exiting
|
|
210
287
|
// those, the top level context performs a large number of actions not captured in the following 'close' call. Among
|
|
211
|
-
// others, it will create empty blocks (via `
|
|
212
|
-
// `
|
|
288
|
+
// others, it will create empty blocks (via `advanceBlocksBy` and `deploy`), create blocks with transactions via
|
|
289
|
+
// `privateCallNewFlow` and `publicCallNewFlow`, add accounts to PXE via `addAccount`, etc. This is a
|
|
213
290
|
// slight inconsistency in the working model of this class, but is not too bad.
|
|
214
291
|
// TODO: it's quite unfortunate that we need to capture the authwits created to later pass them again when the top
|
|
215
292
|
// level context is re-created. This is because authwits create a temporary utility context that'd otherwise reset
|
|
@@ -226,13 +303,13 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
|
|
|
226
303
|
});
|
|
227
304
|
// We rely on the note cache to determine the effects of the transaction. This is incomplete as it doesn't private
|
|
228
305
|
// logs (other effects like enqueued public calls don't need to be considered since those are not allowed).
|
|
229
|
-
const txEffect = await makeTxEffect(this.state.noteCache, this.state.
|
|
306
|
+
const txEffect = await makeTxEffect(this.state.noteCache, this.state.nextBlockGlobalVariables.blockNumber);
|
|
230
307
|
// We build a block holding just this transaction
|
|
231
308
|
const forkedWorldTrees = await this.stateMachine.synchronizer.nativeWorldStateService.fork();
|
|
232
309
|
await insertTxEffectIntoWorldTrees(txEffect, forkedWorldTrees);
|
|
233
|
-
const block =
|
|
310
|
+
const block = await makeTXEBlock(forkedWorldTrees, this.state.nextBlockGlobalVariables, [
|
|
234
311
|
txEffect
|
|
235
|
-
])
|
|
312
|
+
]);
|
|
236
313
|
await this.stateMachine.handleL2Block(block);
|
|
237
314
|
await forkedWorldTrees.close();
|
|
238
315
|
this.logger.debug('Exited PublicContext with built block', {
|
|
@@ -252,4 +329,45 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
|
|
|
252
329
|
throw new Error(`Expected to be in state 'UTILITY', but got '${this.state.name}' instead`);
|
|
253
330
|
}
|
|
254
331
|
}
|
|
332
|
+
utilityExecutorForContractSync(anchorBlock) {
|
|
333
|
+
return async (call, scopes)=>{
|
|
334
|
+
const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
|
|
335
|
+
if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
|
|
336
|
+
throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
|
|
337
|
+
}
|
|
338
|
+
try {
|
|
339
|
+
const oracle = new UtilityExecutionOracle({
|
|
340
|
+
contractAddress: call.to,
|
|
341
|
+
authWitnesses: [],
|
|
342
|
+
capsules: [],
|
|
343
|
+
anchorBlockHeader: anchorBlock,
|
|
344
|
+
contractStore: this.contractStore,
|
|
345
|
+
noteStore: this.noteStore,
|
|
346
|
+
keyStore: this.keyStore,
|
|
347
|
+
addressStore: this.addressStore,
|
|
348
|
+
aztecNode: this.stateMachine.node,
|
|
349
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
350
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
351
|
+
capsuleService: new CapsuleService(this.capsuleStore, scopes),
|
|
352
|
+
privateEventStore: this.privateEventStore,
|
|
353
|
+
messageContextService: this.stateMachine.messageContextService,
|
|
354
|
+
contractSyncService: this.contractSyncService,
|
|
355
|
+
l2TipsStore: this.stateMachine.node,
|
|
356
|
+
jobId: this.currentJobId,
|
|
357
|
+
scopes
|
|
358
|
+
});
|
|
359
|
+
await new WASMSimulator().executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, new Oracle(oracle).toACIRCallback()).catch((err)=>{
|
|
360
|
+
err.message = resolveAssertionMessageFromError(err, entryPointArtifact);
|
|
361
|
+
throw new ExecutionError(err.message, {
|
|
362
|
+
contractAddress: call.to,
|
|
363
|
+
functionSelector: call.selector
|
|
364
|
+
}, extractCallStack(err, entryPointArtifact.debug), {
|
|
365
|
+
cause: err
|
|
366
|
+
});
|
|
367
|
+
});
|
|
368
|
+
} catch (err) {
|
|
369
|
+
throw createSimulationError(err instanceof Error ? err : new Error('Unknown error contract data sync'));
|
|
370
|
+
}
|
|
371
|
+
};
|
|
372
|
+
}
|
|
255
373
|
}
|