@aztec/txe 0.0.1-commit.5daedc8 → 0.0.1-commit.6201a7b05
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 +36 -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 +44 -27
- package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_top_level_context.js +245 -109
- package/dest/rpc_translator.d.ts +136 -78
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +545 -178
- 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 +67 -99
- package/dest/state_machine/dummy_p2p_client.d.ts +21 -15
- package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
- package/dest/state_machine/dummy_p2p_client.js +45 -25
- package/dest/state_machine/global_variable_builder.d.ts +11 -5
- package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
- package/dest/state_machine/global_variable_builder.js +21 -3
- 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 +45 -24
- package/dest/state_machine/mock_epoch_cache.d.ts +26 -8
- package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
- package/dest/state_machine/mock_epoch_cache.js +49 -9
- 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 +71 -15
- package/dest/txe_session.d.ts.map +1 -1
- package/dest/txe_session.js +228 -57
- package/dest/util/encoding.d.ts +688 -19
- package/dest/util/encoding.d.ts.map +1 -1
- package/dest/util/encoding.js +5 -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 +13 -32
- 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 +37 -33
- package/src/oracle/txe_oracle_public_context.ts +21 -28
- package/src/oracle/txe_oracle_top_level_context.ts +291 -151
- package/src/rpc_translator.ts +645 -206
- package/src/state_machine/archiver.ts +63 -117
- package/src/state_machine/dummy_p2p_client.ts +62 -33
- package/src/state_machine/global_variable_builder.ts +38 -6
- package/src/state_machine/index.ts +68 -22
- package/src/state_machine/mock_epoch_cache.ts +61 -14
- package/src/state_machine/synchronizer.ts +9 -8
- package/src/txe_session.ts +351 -105
- package/src/util/encoding.ts +6 -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 -47
- 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,35 @@
|
|
|
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, 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 { CallContext, TxContext } from '@aztec/stdlib/tx';
|
|
13
|
+
import { makeGlobalVariables } from '@aztec/stdlib/testing';
|
|
14
|
+
import { CallContext, OFFCHAIN_MESSAGE_IDENTIFIER, 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
|
-
|
|
25
|
+
function emptyLastCallState() {
|
|
26
|
+
return {
|
|
27
|
+
offchainEffects: [],
|
|
28
|
+
queried: false,
|
|
29
|
+
txHash: Fr.ZERO,
|
|
30
|
+
anchorBlockTimestamp: 0n
|
|
31
|
+
};
|
|
32
|
+
}
|
|
24
33
|
/**
|
|
25
34
|
* A `TXESession` corresponds to a Noir `#[test]` function, and handles all of its oracle calls, stores test-specific
|
|
26
35
|
* state, etc., independent of all other tests running in parallel.
|
|
@@ -28,56 +37,80 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
|
|
|
28
37
|
logger;
|
|
29
38
|
stateMachine;
|
|
30
39
|
oracleHandler;
|
|
31
|
-
|
|
40
|
+
contractStore;
|
|
41
|
+
noteStore;
|
|
32
42
|
keyStore;
|
|
33
|
-
|
|
34
|
-
|
|
43
|
+
addressStore;
|
|
44
|
+
accountStore;
|
|
45
|
+
senderTaggingStore;
|
|
46
|
+
recipientTaggingStore;
|
|
47
|
+
senderAddressBookStore;
|
|
48
|
+
capsuleStore;
|
|
49
|
+
privateEventStore;
|
|
50
|
+
jobCoordinator;
|
|
51
|
+
currentJobId;
|
|
35
52
|
chainId;
|
|
36
53
|
version;
|
|
37
54
|
nextBlockTimestamp;
|
|
38
|
-
pxeOracleInterface;
|
|
39
55
|
state;
|
|
40
56
|
authwits;
|
|
41
|
-
|
|
57
|
+
lastCallInfo;
|
|
58
|
+
constructor(logger, stateMachine, oracleHandler, contractStore, noteStore, keyStore, addressStore, accountStore, senderTaggingStore, recipientTaggingStore, senderAddressBookStore, capsuleStore, privateEventStore, jobCoordinator, currentJobId, chainId, version, nextBlockTimestamp){
|
|
42
59
|
this.logger = logger;
|
|
43
60
|
this.stateMachine = stateMachine;
|
|
44
61
|
this.oracleHandler = oracleHandler;
|
|
45
|
-
this.
|
|
62
|
+
this.contractStore = contractStore;
|
|
63
|
+
this.noteStore = noteStore;
|
|
46
64
|
this.keyStore = keyStore;
|
|
47
|
-
this.
|
|
48
|
-
this.
|
|
65
|
+
this.addressStore = addressStore;
|
|
66
|
+
this.accountStore = accountStore;
|
|
67
|
+
this.senderTaggingStore = senderTaggingStore;
|
|
68
|
+
this.recipientTaggingStore = recipientTaggingStore;
|
|
69
|
+
this.senderAddressBookStore = senderAddressBookStore;
|
|
70
|
+
this.capsuleStore = capsuleStore;
|
|
71
|
+
this.privateEventStore = privateEventStore;
|
|
72
|
+
this.jobCoordinator = jobCoordinator;
|
|
73
|
+
this.currentJobId = currentJobId;
|
|
49
74
|
this.chainId = chainId;
|
|
50
75
|
this.version = version;
|
|
51
76
|
this.nextBlockTimestamp = nextBlockTimestamp;
|
|
52
|
-
this.pxeOracleInterface = pxeOracleInterface;
|
|
53
77
|
this.state = {
|
|
54
78
|
name: 'TOP_LEVEL'
|
|
55
79
|
};
|
|
56
80
|
this.authwits = new Map();
|
|
81
|
+
this.lastCallInfo = emptyLastCallState();
|
|
57
82
|
}
|
|
58
|
-
static async init(
|
|
83
|
+
static async init(contractStore) {
|
|
59
84
|
const store = await openTmpStore('txe-session');
|
|
60
|
-
const
|
|
61
|
-
const
|
|
62
|
-
const
|
|
63
|
-
const
|
|
64
|
-
const
|
|
65
|
-
const
|
|
85
|
+
const addressStore = new AddressStore(store);
|
|
86
|
+
const privateEventStore = new PrivateEventStore(store);
|
|
87
|
+
const noteStore = new NoteStore(store);
|
|
88
|
+
const senderTaggingStore = new SenderTaggingStore(store);
|
|
89
|
+
const recipientTaggingStore = new RecipientTaggingStore(store);
|
|
90
|
+
const senderAddressBookStore = new SenderAddressBookStore(store);
|
|
91
|
+
const capsuleStore = new CapsuleStore(store);
|
|
66
92
|
const keyStore = new KeyStore(store);
|
|
67
|
-
const
|
|
68
|
-
//
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
93
|
+
const accountStore = new TXEAccountStore(store);
|
|
94
|
+
// Create job coordinator and register staged stores
|
|
95
|
+
const jobCoordinator = new JobCoordinator(store);
|
|
96
|
+
jobCoordinator.registerStores([
|
|
97
|
+
capsuleStore,
|
|
98
|
+
senderTaggingStore,
|
|
99
|
+
recipientTaggingStore,
|
|
100
|
+
privateEventStore,
|
|
101
|
+
noteStore
|
|
102
|
+
]);
|
|
103
|
+
const archiver = new TXEArchiver(store);
|
|
104
|
+
const anchorBlockStore = new AnchorBlockStore(store);
|
|
105
|
+
const stateMachine = await TXEStateMachine.create(archiver, anchorBlockStore, contractStore, noteStore);
|
|
74
106
|
const nextBlockTimestamp = BigInt(Math.floor(new Date().getTime() / 1000));
|
|
75
107
|
const version = new Fr(await stateMachine.node.getVersion());
|
|
76
108
|
const chainId = new Fr(await stateMachine.node.getChainId());
|
|
77
|
-
const
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
109
|
+
const initialJobId = jobCoordinator.beginJob();
|
|
110
|
+
const logger = createLogger('txe:session');
|
|
111
|
+
const topLevelOracleHandler = new TXEOracleTopLevelContext(stateMachine, contractStore, noteStore, keyStore, addressStore, accountStore, senderTaggingStore, recipientTaggingStore, senderAddressBookStore, capsuleStore, privateEventStore, nextBlockTimestamp, version, chainId, new Map());
|
|
112
|
+
await topLevelOracleHandler.advanceBlocksBy(1);
|
|
113
|
+
return new TXESession(logger, stateMachine, topLevelOracleHandler, contractStore, noteStore, keyStore, addressStore, accountStore, senderTaggingStore, recipientTaggingStore, senderAddressBookStore, capsuleStore, privateEventStore, jobCoordinator, initialJobId, version, chainId, nextBlockTimestamp);
|
|
81
114
|
}
|
|
82
115
|
/**
|
|
83
116
|
* Processes an oracle function invoked by the Noir test associated to this session.
|
|
@@ -100,6 +133,50 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
|
|
|
100
133
|
}
|
|
101
134
|
}
|
|
102
135
|
}
|
|
136
|
+
getCurrentJob() {
|
|
137
|
+
return this.currentJobId;
|
|
138
|
+
}
|
|
139
|
+
/** Commits the current job and begins a new one. Returns the new job ID. */ async cycleJob() {
|
|
140
|
+
await this.jobCoordinator.commitJob(this.currentJobId);
|
|
141
|
+
this.currentJobId = this.jobCoordinator.beginJob();
|
|
142
|
+
return this.currentJobId;
|
|
143
|
+
}
|
|
144
|
+
resetLastCall() {
|
|
145
|
+
const notQueriedMessageCount = this.lastCallInfo.queried ? 0 : this.lastCallInfo.offchainEffects.filter((payload)=>payload[0]?.equals(OFFCHAIN_MESSAGE_IDENTIFIER)).length;
|
|
146
|
+
if (notQueriedMessageCount > 0) {
|
|
147
|
+
this.logger.warn(`Dropping ${notQueriedMessageCount} unqueried offchain message(s) from the previous top-level call. ` + `To deliver them, call \`env.offchain_messages()\` and forward the result to the recipient contract's ` + `\`offchain_receive\` utility before issuing another top-level call. To intentionally discard, assign ` + `to \`let _ = env.offchain_messages()\` to silence this warning.`);
|
|
148
|
+
}
|
|
149
|
+
this.lastCallInfo = emptyLastCallState();
|
|
150
|
+
}
|
|
151
|
+
recordOffchainEffect(data) {
|
|
152
|
+
this.lastCallInfo.offchainEffects.push(data);
|
|
153
|
+
}
|
|
154
|
+
setLastCallContext(txHash, anchorBlockTimestamp) {
|
|
155
|
+
this.lastCallInfo.txHash = txHash;
|
|
156
|
+
this.lastCallInfo.anchorBlockTimestamp = anchorBlockTimestamp;
|
|
157
|
+
}
|
|
158
|
+
async withTopLevelCallTracking(work) {
|
|
159
|
+
this.resetLastCall();
|
|
160
|
+
// Capture the anchor *before* `work` runs: private/public executor calls mine a new block as a
|
|
161
|
+
// side effect, and that block's timestamp should not be attributed to this call's anchor.
|
|
162
|
+
const anchorBlockTimestamp = (await this.stateMachine.node.getBlockHeader('latest')).globalVariables.timestamp;
|
|
163
|
+
const { result, txHash } = await work();
|
|
164
|
+
this.setLastCallContext(txHash ?? Fr.ZERO, anchorBlockTimestamp);
|
|
165
|
+
return result;
|
|
166
|
+
}
|
|
167
|
+
getLastCallOffchainEffects() {
|
|
168
|
+
this.lastCallInfo.queried = true;
|
|
169
|
+
return {
|
|
170
|
+
effects: this.lastCallInfo.offchainEffects
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
getLastCallContext() {
|
|
174
|
+
const { txHash, anchorBlockTimestamp } = this.lastCallInfo;
|
|
175
|
+
return {
|
|
176
|
+
txHash,
|
|
177
|
+
anchorBlockTimestamp
|
|
178
|
+
};
|
|
179
|
+
}
|
|
103
180
|
async enterTopLevelState() {
|
|
104
181
|
switch(this.state.name){
|
|
105
182
|
case 'PRIVATE':
|
|
@@ -126,7 +203,9 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
|
|
|
126
203
|
this.state;
|
|
127
204
|
}
|
|
128
205
|
}
|
|
129
|
-
|
|
206
|
+
// Commit all staged stores from the job that was just completed, then begin a new job
|
|
207
|
+
await this.cycleJob();
|
|
208
|
+
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);
|
|
130
209
|
this.state = {
|
|
131
210
|
name: 'TOP_LEVEL'
|
|
132
211
|
};
|
|
@@ -134,19 +213,15 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
|
|
|
134
213
|
}
|
|
135
214
|
async enterPrivateState(contractAddress = DEFAULT_ADDRESS, anchorBlockNumber) {
|
|
136
215
|
this.exitTopLevelState();
|
|
137
|
-
|
|
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);
|
|
216
|
+
this.resetLastCall();
|
|
143
217
|
// Private execution has two associated block numbers: the anchor block (i.e. the historical block that is used to
|
|
144
218
|
// build the proof), and the *next* block, i.e. the one we'll create once the execution ends, and which will contain
|
|
145
219
|
// a single transaction with the effects of what was done in the test.
|
|
146
220
|
const anchorBlock = await this.stateMachine.node.getBlockHeader(anchorBlockNumber ?? 'latest');
|
|
221
|
+
await new NoteService(this.noteStore, this.stateMachine.node, anchorBlock, this.currentJobId).syncNoteNullifiers(contractAddress, await this.keyStore.getAccounts());
|
|
147
222
|
const latestBlock = await this.stateMachine.node.getBlockHeader('latest');
|
|
148
223
|
const nextBlockGlobalVariables = makeGlobalVariables(undefined, {
|
|
149
|
-
blockNumber: latestBlock.globalVariables.blockNumber + 1,
|
|
224
|
+
blockNumber: BlockNumber(latestBlock.globalVariables.blockNumber + 1),
|
|
150
225
|
timestamp: this.nextBlockTimestamp,
|
|
151
226
|
version: this.version,
|
|
152
227
|
chainId: this.chainId
|
|
@@ -155,7 +230,34 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
|
|
|
155
230
|
const protocolNullifier = await computeProtocolNullifier(txRequestHash);
|
|
156
231
|
const noteCache = new ExecutionNoteCache(protocolNullifier);
|
|
157
232
|
const taggingIndexCache = new ExecutionTaggingIndexCache();
|
|
158
|
-
|
|
233
|
+
const utilityExecutor = this.utilityExecutorForContractSync(anchorBlock);
|
|
234
|
+
this.oracleHandler = new PrivateExecutionOracle({
|
|
235
|
+
argsHash: Fr.ZERO,
|
|
236
|
+
txContext: new TxContext(this.chainId, this.version, GasSettings.empty()),
|
|
237
|
+
callContext: new CallContext(AztecAddress.ZERO, contractAddress, FunctionSelector.empty(), false),
|
|
238
|
+
anchorBlockHeader: anchorBlock,
|
|
239
|
+
utilityExecutor,
|
|
240
|
+
authWitnesses: [],
|
|
241
|
+
capsules: [],
|
|
242
|
+
executionCache: new HashedValuesCache(),
|
|
243
|
+
noteCache,
|
|
244
|
+
taggingIndexCache,
|
|
245
|
+
contractStore: this.contractStore,
|
|
246
|
+
noteStore: this.noteStore,
|
|
247
|
+
keyStore: this.keyStore,
|
|
248
|
+
addressStore: this.addressStore,
|
|
249
|
+
aztecNode: this.stateMachine.node,
|
|
250
|
+
senderTaggingStore: this.senderTaggingStore,
|
|
251
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
252
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
253
|
+
capsuleService: new CapsuleService(this.capsuleStore, await this.keyStore.getAccounts()),
|
|
254
|
+
privateEventStore: this.privateEventStore,
|
|
255
|
+
contractSyncService: this.stateMachine.contractSyncService,
|
|
256
|
+
l2TipsStore: this.stateMachine.node,
|
|
257
|
+
jobId: this.currentJobId,
|
|
258
|
+
scopes: await this.keyStore.getAccounts(),
|
|
259
|
+
messageContextService: this.stateMachine.messageContextService
|
|
260
|
+
});
|
|
159
261
|
// We store the note and tagging index caches fed into the PrivateExecutionOracle (along with some other auxiliary
|
|
160
262
|
// data) in order to refer to it later, mimicking the way this object is used by the ContractFunctionSimulator. The
|
|
161
263
|
// difference resides in that the simulator has all information needed in order to run the simulation, while ours
|
|
@@ -164,20 +266,23 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
|
|
|
164
266
|
this.state = {
|
|
165
267
|
name: 'PRIVATE',
|
|
166
268
|
nextBlockGlobalVariables,
|
|
167
|
-
protocolNullifier,
|
|
168
269
|
noteCache,
|
|
169
270
|
taggingIndexCache
|
|
170
271
|
};
|
|
171
272
|
this.logger.debug(`Entered state ${this.state.name}`);
|
|
273
|
+
// Record the *resolved* anchor's timestamp — if the caller pinned the anchor to a past block
|
|
274
|
+
// via `anchorBlockNumber`, "latest" would be the wrong anchor for offchain-message semantics.
|
|
275
|
+
this.setLastCallContext(Fr.ZERO, anchorBlock.globalVariables.timestamp);
|
|
172
276
|
return this.oracleHandler.getPrivateContextInputs();
|
|
173
277
|
}
|
|
174
278
|
async enterPublicState(contractAddress) {
|
|
175
279
|
this.exitTopLevelState();
|
|
280
|
+
this.resetLastCall();
|
|
176
281
|
// The PublicContext will create a block with a single transaction in it, containing the effects of what was done in
|
|
177
282
|
// the test. The block therefore gets the *next* block number and timestamp.
|
|
178
|
-
const
|
|
283
|
+
const latestHeader = await this.stateMachine.node.getBlockHeader('latest');
|
|
179
284
|
const globalVariables = makeGlobalVariables(undefined, {
|
|
180
|
-
blockNumber:
|
|
285
|
+
blockNumber: BlockNumber(latestHeader.globalVariables.blockNumber + 1),
|
|
181
286
|
timestamp: this.nextBlockTimestamp,
|
|
182
287
|
version: this.version,
|
|
183
288
|
chainId: this.chainId
|
|
@@ -187,20 +292,45 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
|
|
|
187
292
|
name: 'PUBLIC'
|
|
188
293
|
};
|
|
189
294
|
this.logger.debug(`Entered state ${this.state.name}`);
|
|
295
|
+
// Public state is anchored at the latest block.
|
|
296
|
+
this.setLastCallContext(Fr.ZERO, latestHeader.globalVariables.timestamp);
|
|
190
297
|
}
|
|
191
298
|
async enterUtilityState(contractAddress = DEFAULT_ADDRESS) {
|
|
192
299
|
this.exitTopLevelState();
|
|
300
|
+
this.resetLastCall();
|
|
301
|
+
const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
193
302
|
// There is no automatic message discovery and contract-driven syncing process in inlined private or utility
|
|
194
303
|
// contexts, which means that known nullifiers are also not searched for, since it is during the tagging sync that
|
|
195
304
|
// we perform this. We therefore search for known nullifiers now, as otherwise notes that were nullified would not
|
|
196
305
|
// be removed from the database.
|
|
197
306
|
// TODO(#12553): make the synchronizer sync here instead and remove this
|
|
198
|
-
await this.
|
|
199
|
-
this.oracleHandler = new UtilityExecutionOracle(
|
|
307
|
+
await new NoteService(this.noteStore, this.stateMachine.node, anchorBlockHeader, this.currentJobId).syncNoteNullifiers(contractAddress, await this.keyStore.getAccounts());
|
|
308
|
+
this.oracleHandler = new UtilityExecutionOracle({
|
|
309
|
+
contractAddress,
|
|
310
|
+
authWitnesses: [],
|
|
311
|
+
capsules: [],
|
|
312
|
+
anchorBlockHeader,
|
|
313
|
+
contractStore: this.contractStore,
|
|
314
|
+
noteStore: this.noteStore,
|
|
315
|
+
keyStore: this.keyStore,
|
|
316
|
+
addressStore: this.addressStore,
|
|
317
|
+
aztecNode: this.stateMachine.node,
|
|
318
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
319
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
320
|
+
capsuleService: new CapsuleService(this.capsuleStore, await this.keyStore.getAccounts()),
|
|
321
|
+
privateEventStore: this.privateEventStore,
|
|
322
|
+
messageContextService: this.stateMachine.messageContextService,
|
|
323
|
+
contractSyncService: this.stateMachine.contractSyncService,
|
|
324
|
+
l2TipsStore: this.stateMachine.node,
|
|
325
|
+
jobId: this.currentJobId,
|
|
326
|
+
scopes: await this.keyStore.getAccounts()
|
|
327
|
+
});
|
|
200
328
|
this.state = {
|
|
201
329
|
name: 'UTILITY'
|
|
202
330
|
};
|
|
203
331
|
this.logger.debug(`Entered state ${this.state.name}`);
|
|
332
|
+
// Utility state anchors at whatever the anchor block store is pointing to (tracked as latest).
|
|
333
|
+
this.setLastCallContext(Fr.ZERO, anchorBlockHeader.globalVariables.timestamp);
|
|
204
334
|
}
|
|
205
335
|
exitTopLevelState() {
|
|
206
336
|
if (this.state.name != 'TOP_LEVEL') {
|
|
@@ -208,8 +338,8 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
|
|
|
208
338
|
}
|
|
209
339
|
// Note that while all public and private contexts do is build a single block that we then process when exiting
|
|
210
340
|
// 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
|
-
// `
|
|
341
|
+
// others, it will create empty blocks (via `advanceBlocksBy` and `deploy`), create blocks with transactions via
|
|
342
|
+
// `privateCallNewFlow` and `publicCallNewFlow`, add accounts to PXE via `addAccount`, etc. This is a
|
|
213
343
|
// slight inconsistency in the working model of this class, but is not too bad.
|
|
214
344
|
// TODO: it's quite unfortunate that we need to capture the authwits created to later pass them again when the top
|
|
215
345
|
// level context is re-created. This is because authwits create a temporary utility context that'd otherwise reset
|
|
@@ -226,13 +356,13 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
|
|
|
226
356
|
});
|
|
227
357
|
// We rely on the note cache to determine the effects of the transaction. This is incomplete as it doesn't private
|
|
228
358
|
// 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.
|
|
359
|
+
const txEffect = await makeTxEffect(this.state.noteCache, this.state.nextBlockGlobalVariables.blockNumber);
|
|
230
360
|
// We build a block holding just this transaction
|
|
231
361
|
const forkedWorldTrees = await this.stateMachine.synchronizer.nativeWorldStateService.fork();
|
|
232
362
|
await insertTxEffectIntoWorldTrees(txEffect, forkedWorldTrees);
|
|
233
|
-
const block =
|
|
363
|
+
const block = await makeTXEBlock(forkedWorldTrees, this.state.nextBlockGlobalVariables, [
|
|
234
364
|
txEffect
|
|
235
|
-
])
|
|
365
|
+
]);
|
|
236
366
|
await this.stateMachine.handleL2Block(block);
|
|
237
367
|
await forkedWorldTrees.close();
|
|
238
368
|
this.logger.debug('Exited PublicContext with built block', {
|
|
@@ -252,4 +382,45 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
|
|
|
252
382
|
throw new Error(`Expected to be in state 'UTILITY', but got '${this.state.name}' instead`);
|
|
253
383
|
}
|
|
254
384
|
}
|
|
385
|
+
utilityExecutorForContractSync(anchorBlock) {
|
|
386
|
+
return async (call, scopes)=>{
|
|
387
|
+
const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
|
|
388
|
+
if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
|
|
389
|
+
throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
|
|
390
|
+
}
|
|
391
|
+
try {
|
|
392
|
+
const oracle = new UtilityExecutionOracle({
|
|
393
|
+
contractAddress: call.to,
|
|
394
|
+
authWitnesses: [],
|
|
395
|
+
capsules: [],
|
|
396
|
+
anchorBlockHeader: anchorBlock,
|
|
397
|
+
contractStore: this.contractStore,
|
|
398
|
+
noteStore: this.noteStore,
|
|
399
|
+
keyStore: this.keyStore,
|
|
400
|
+
addressStore: this.addressStore,
|
|
401
|
+
aztecNode: this.stateMachine.node,
|
|
402
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
403
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
404
|
+
capsuleService: new CapsuleService(this.capsuleStore, scopes),
|
|
405
|
+
privateEventStore: this.privateEventStore,
|
|
406
|
+
messageContextService: this.stateMachine.messageContextService,
|
|
407
|
+
contractSyncService: this.stateMachine.contractSyncService,
|
|
408
|
+
l2TipsStore: this.stateMachine.node,
|
|
409
|
+
jobId: this.currentJobId,
|
|
410
|
+
scopes
|
|
411
|
+
});
|
|
412
|
+
await new WASMSimulator().executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, new Oracle(oracle).toACIRCallback()).catch((err)=>{
|
|
413
|
+
err.message = resolveAssertionMessageFromError(err, entryPointArtifact);
|
|
414
|
+
throw new ExecutionError(err.message, {
|
|
415
|
+
contractAddress: call.to,
|
|
416
|
+
functionSelector: call.selector
|
|
417
|
+
}, extractCallStack(err, entryPointArtifact.debug), {
|
|
418
|
+
cause: err
|
|
419
|
+
});
|
|
420
|
+
});
|
|
421
|
+
} catch (err) {
|
|
422
|
+
throw createSimulationError(err instanceof Error ? err : new Error('Unknown error contract data sync'));
|
|
423
|
+
}
|
|
424
|
+
};
|
|
425
|
+
}
|
|
255
426
|
}
|