@aztec/txe 0.0.1-commit.d3ec352c → 0.0.1-commit.e61ad554
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 +3 -2
- package/dest/oracle/interfaces.d.ts +6 -4
- package/dest/oracle/interfaces.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.d.ts +4 -4
- package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.js +7 -8
- package/dest/oracle/txe_oracle_top_level_context.d.ts +20 -11
- package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_top_level_context.js +100 -63
- package/dest/rpc_translator.d.ts +23 -11
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +91 -38
- package/dest/state_machine/archiver.d.ts +21 -57
- package/dest/state_machine/archiver.d.ts.map +1 -1
- package/dest/state_machine/archiver.js +61 -107
- 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 +16 -11
- package/dest/state_machine/global_variable_builder.d.ts +4 -3
- 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 +5 -5
- package/dest/state_machine/index.d.ts.map +1 -1
- package/dest/state_machine/index.js +32 -20
- 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/state_machine/synchronizer.js +2 -2
- package/dest/txe_session.d.ts +18 -10
- package/dest/txe_session.d.ts.map +1 -1
- package/dest/txe_session.js +91 -45
- package/dest/util/encoding.d.ts +618 -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_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 +5 -5
- 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 -5
- package/dest/utils/block_creation.d.ts.map +1 -1
- package/dest/utils/block_creation.js +36 -4
- 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 +4 -7
- package/package.json +16 -16
- package/src/constants.ts +3 -0
- package/src/index.ts +15 -12
- package/src/oracle/interfaces.ts +5 -3
- package/src/oracle/txe_oracle_public_context.ts +7 -12
- package/src/oracle/txe_oracle_top_level_context.ts +149 -88
- package/src/rpc_translator.ts +113 -49
- package/src/state_machine/archiver.ts +57 -131
- package/src/state_machine/dummy_p2p_client.ts +21 -14
- package/src/state_machine/global_variable_builder.ts +19 -2
- package/src/state_machine/index.ts +41 -18
- package/src/state_machine/mock_epoch_cache.ts +10 -11
- package/src/state_machine/synchronizer.ts +3 -4
- package/src/txe_session.ts +187 -76
- 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 +10 -10
- package/src/utils/block_creation.ts +46 -15
- package/src/utils/tx_effect_creation.ts +4 -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/txe_session.js
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
-
import { Fr } from '@aztec/foundation/
|
|
2
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
3
|
import { createLogger } from '@aztec/foundation/log';
|
|
4
4
|
import { KeyStore } from '@aztec/key-store';
|
|
5
5
|
import { openTmpStore } from '@aztec/kv-store/lmdb-v2';
|
|
6
|
-
import {
|
|
7
|
-
import { ExecutionNoteCache, ExecutionTaggingIndexCache, HashedValuesCache, PrivateExecutionOracle, UtilityExecutionOracle } from '@aztec/pxe/simulator';
|
|
8
|
-
import {
|
|
6
|
+
import { AddressStore, 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';
|
|
9
10
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
10
|
-
import { Body, L2Block } from '@aztec/stdlib/block';
|
|
11
11
|
import { GasSettings } from '@aztec/stdlib/gas';
|
|
12
12
|
import { computeProtocolNullifier } from '@aztec/stdlib/hash';
|
|
13
|
-
import {
|
|
13
|
+
import { makeGlobalVariables } from '@aztec/stdlib/testing';
|
|
14
14
|
import { CallContext, TxContext } from '@aztec/stdlib/tx';
|
|
15
15
|
import { z } from 'zod';
|
|
16
|
+
import { DEFAULT_ADDRESS } from './constants.js';
|
|
16
17
|
import { TXEOraclePublicContext } from './oracle/txe_oracle_public_context.js';
|
|
17
18
|
import { TXEOracleTopLevelContext } from './oracle/txe_oracle_top_level_context.js';
|
|
18
19
|
import { RPCTranslator } from './rpc_translator.js';
|
|
19
20
|
import { TXEStateMachine } from './state_machine/index.js';
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import { getSingleTxBlockRequestHash, insertTxEffectIntoWorldTrees,
|
|
21
|
+
import { TXEAccountStore } from './util/txe_account_store.js';
|
|
22
|
+
import { TXEContractStore } from './util/txe_contract_store.js';
|
|
23
|
+
import { getSingleTxBlockRequestHash, insertTxEffectIntoWorldTrees, makeTXEBlock } from './utils/block_creation.js';
|
|
23
24
|
import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
24
|
-
const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
|
|
25
25
|
/**
|
|
26
26
|
* A `TXESession` corresponds to a Noir `#[test]` function, and handles all of its oracle calls, stores test-specific
|
|
27
27
|
* state, etc., independent of all other tests running in parallel.
|
|
@@ -29,28 +29,42 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
|
|
|
29
29
|
logger;
|
|
30
30
|
stateMachine;
|
|
31
31
|
oracleHandler;
|
|
32
|
-
|
|
32
|
+
contractStore;
|
|
33
|
+
noteStore;
|
|
33
34
|
keyStore;
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
addressStore;
|
|
36
|
+
accountStore;
|
|
37
|
+
senderTaggingStore;
|
|
38
|
+
recipientTaggingStore;
|
|
39
|
+
senderAddressBookStore;
|
|
40
|
+
capsuleStore;
|
|
41
|
+
privateEventStore;
|
|
42
|
+
jobCoordinator;
|
|
43
|
+
currentJobId;
|
|
36
44
|
chainId;
|
|
37
45
|
version;
|
|
38
46
|
nextBlockTimestamp;
|
|
39
|
-
pxeOracleInterface;
|
|
40
47
|
state;
|
|
41
48
|
authwits;
|
|
42
|
-
constructor(logger, stateMachine, oracleHandler,
|
|
49
|
+
constructor(logger, stateMachine, oracleHandler, contractStore, noteStore, keyStore, addressStore, accountStore, senderTaggingStore, recipientTaggingStore, senderAddressBookStore, capsuleStore, privateEventStore, jobCoordinator, currentJobId, chainId, version, nextBlockTimestamp){
|
|
43
50
|
this.logger = logger;
|
|
44
51
|
this.stateMachine = stateMachine;
|
|
45
52
|
this.oracleHandler = oracleHandler;
|
|
46
|
-
this.
|
|
53
|
+
this.contractStore = contractStore;
|
|
54
|
+
this.noteStore = noteStore;
|
|
47
55
|
this.keyStore = keyStore;
|
|
48
|
-
this.
|
|
49
|
-
this.
|
|
56
|
+
this.addressStore = addressStore;
|
|
57
|
+
this.accountStore = accountStore;
|
|
58
|
+
this.senderTaggingStore = senderTaggingStore;
|
|
59
|
+
this.recipientTaggingStore = recipientTaggingStore;
|
|
60
|
+
this.senderAddressBookStore = senderAddressBookStore;
|
|
61
|
+
this.capsuleStore = capsuleStore;
|
|
62
|
+
this.privateEventStore = privateEventStore;
|
|
63
|
+
this.jobCoordinator = jobCoordinator;
|
|
64
|
+
this.currentJobId = currentJobId;
|
|
50
65
|
this.chainId = chainId;
|
|
51
66
|
this.version = version;
|
|
52
67
|
this.nextBlockTimestamp = nextBlockTimestamp;
|
|
53
|
-
this.pxeOracleInterface = pxeOracleInterface;
|
|
54
68
|
this.state = {
|
|
55
69
|
name: 'TOP_LEVEL'
|
|
56
70
|
};
|
|
@@ -58,27 +72,38 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
|
|
|
58
72
|
}
|
|
59
73
|
static async init(protocolContracts) {
|
|
60
74
|
const store = await openTmpStore('txe-session');
|
|
61
|
-
const
|
|
62
|
-
const
|
|
63
|
-
const
|
|
64
|
-
const
|
|
65
|
-
const
|
|
66
|
-
const
|
|
75
|
+
const addressStore = new AddressStore(store);
|
|
76
|
+
const privateEventStore = new PrivateEventStore(store);
|
|
77
|
+
const contractStore = new TXEContractStore(store);
|
|
78
|
+
const noteStore = new NoteStore(store);
|
|
79
|
+
const senderTaggingStore = new SenderTaggingStore(store);
|
|
80
|
+
const recipientTaggingStore = new RecipientTaggingStore(store);
|
|
81
|
+
const senderAddressBookStore = new SenderAddressBookStore(store);
|
|
82
|
+
const capsuleStore = new CapsuleStore(store);
|
|
67
83
|
const keyStore = new KeyStore(store);
|
|
68
|
-
const
|
|
84
|
+
const accountStore = new TXEAccountStore(store);
|
|
85
|
+
// Create job coordinator and register staged stores
|
|
86
|
+
const jobCoordinator = new JobCoordinator(store);
|
|
87
|
+
jobCoordinator.registerStores([
|
|
88
|
+
capsuleStore,
|
|
89
|
+
senderTaggingStore,
|
|
90
|
+
recipientTaggingStore,
|
|
91
|
+
privateEventStore,
|
|
92
|
+
noteStore
|
|
93
|
+
]);
|
|
69
94
|
// Register protocol contracts.
|
|
70
95
|
for (const { contractClass, instance, artifact } of protocolContracts){
|
|
71
|
-
await
|
|
72
|
-
await
|
|
96
|
+
await contractStore.addContractArtifact(contractClass.id, artifact);
|
|
97
|
+
await contractStore.addContractInstance(instance);
|
|
73
98
|
}
|
|
74
99
|
const stateMachine = await TXEStateMachine.create(store);
|
|
75
100
|
const nextBlockTimestamp = BigInt(Math.floor(new Date().getTime() / 1000));
|
|
76
101
|
const version = new Fr(await stateMachine.node.getVersion());
|
|
77
102
|
const chainId = new Fr(await stateMachine.node.getChainId());
|
|
78
|
-
const
|
|
79
|
-
const topLevelOracleHandler = new TXEOracleTopLevelContext(stateMachine,
|
|
103
|
+
const initialJobId = jobCoordinator.beginJob();
|
|
104
|
+
const topLevelOracleHandler = new TXEOracleTopLevelContext(stateMachine, contractStore, noteStore, keyStore, addressStore, accountStore, senderTaggingStore, recipientTaggingStore, senderAddressBookStore, capsuleStore, privateEventStore, initialJobId, nextBlockTimestamp, version, chainId, new Map());
|
|
80
105
|
await topLevelOracleHandler.txeAdvanceBlocksBy(1);
|
|
81
|
-
return new TXESession(createLogger('txe:session'), stateMachine, topLevelOracleHandler,
|
|
106
|
+
return new TXESession(createLogger('txe:session'), stateMachine, topLevelOracleHandler, contractStore, noteStore, keyStore, addressStore, accountStore, senderTaggingStore, recipientTaggingStore, senderAddressBookStore, capsuleStore, privateEventStore, jobCoordinator, initialJobId, version, chainId, nextBlockTimestamp);
|
|
82
107
|
}
|
|
83
108
|
/**
|
|
84
109
|
* Processes an oracle function invoked by the Noir test associated to this session.
|
|
@@ -127,7 +152,10 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
|
|
|
127
152
|
this.state;
|
|
128
153
|
}
|
|
129
154
|
}
|
|
130
|
-
|
|
155
|
+
// Commit all staged stores from the job that was just completed, then begin a new job
|
|
156
|
+
await this.jobCoordinator.commitJob(this.currentJobId);
|
|
157
|
+
this.currentJobId = this.jobCoordinator.beginJob();
|
|
158
|
+
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.currentJobId, this.nextBlockTimestamp, this.version, this.chainId, this.authwits);
|
|
131
159
|
this.state = {
|
|
132
160
|
name: 'TOP_LEVEL'
|
|
133
161
|
};
|
|
@@ -135,12 +163,7 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
|
|
|
135
163
|
}
|
|
136
164
|
async enterPrivateState(contractAddress = DEFAULT_ADDRESS, anchorBlockNumber) {
|
|
137
165
|
this.exitTopLevelState();
|
|
138
|
-
|
|
139
|
-
// contexts, which means that known nullifiers are also not searched for, since it is during the tagging sync that
|
|
140
|
-
// we perform this. We therefore search for known nullifiers now, as otherwise notes that were nullified would not
|
|
141
|
-
// be removed from the database.
|
|
142
|
-
// TODO(#12553): make the synchronizer sync here instead and remove this
|
|
143
|
-
await this.pxeOracleInterface.syncNoteNullifiers(contractAddress);
|
|
166
|
+
await new NoteService(this.noteStore, this.stateMachine.node, this.stateMachine.anchorBlockStore, this.currentJobId).syncNoteNullifiers(contractAddress);
|
|
144
167
|
// Private execution has two associated block numbers: the anchor block (i.e. the historical block that is used to
|
|
145
168
|
// build the proof), and the *next* block, i.e. the one we'll create once the execution ends, and which will contain
|
|
146
169
|
// a single transaction with the effects of what was done in the test.
|
|
@@ -156,7 +179,8 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
|
|
|
156
179
|
const protocolNullifier = await computeProtocolNullifier(txRequestHash);
|
|
157
180
|
const noteCache = new ExecutionNoteCache(protocolNullifier);
|
|
158
181
|
const taggingIndexCache = new ExecutionTaggingIndexCache();
|
|
159
|
-
|
|
182
|
+
const utilityExecutor = this.utilityExecutorForContractSync(anchorBlock);
|
|
183
|
+
this.oracleHandler = new PrivateExecutionOracle(Fr.ZERO, new TxContext(this.chainId, this.version, GasSettings.empty()), new CallContext(AztecAddress.ZERO, contractAddress, FunctionSelector.empty(), false), anchorBlock, utilityExecutor, [], [], new HashedValuesCache(), noteCache, taggingIndexCache, this.contractStore, this.noteStore, this.keyStore, this.addressStore, this.stateMachine.node, this.stateMachine.anchorBlockStore, this.senderTaggingStore, this.recipientTaggingStore, this.senderAddressBookStore, this.capsuleStore, this.privateEventStore, this.currentJobId);
|
|
160
184
|
// We store the note and tagging index caches fed into the PrivateExecutionOracle (along with some other auxiliary
|
|
161
185
|
// data) in order to refer to it later, mimicking the way this object is used by the ContractFunctionSimulator. The
|
|
162
186
|
// difference resides in that the simulator has all information needed in order to run the simulation, while ours
|
|
@@ -165,7 +189,6 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
|
|
|
165
189
|
this.state = {
|
|
166
190
|
name: 'PRIVATE',
|
|
167
191
|
nextBlockGlobalVariables,
|
|
168
|
-
protocolNullifier,
|
|
169
192
|
noteCache,
|
|
170
193
|
taggingIndexCache
|
|
171
194
|
};
|
|
@@ -196,8 +219,9 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
|
|
|
196
219
|
// we perform this. We therefore search for known nullifiers now, as otherwise notes that were nullified would not
|
|
197
220
|
// be removed from the database.
|
|
198
221
|
// TODO(#12553): make the synchronizer sync here instead and remove this
|
|
199
|
-
await this.
|
|
200
|
-
|
|
222
|
+
await new NoteService(this.noteStore, this.stateMachine.node, this.stateMachine.anchorBlockStore, this.currentJobId).syncNoteNullifiers(contractAddress);
|
|
223
|
+
const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
224
|
+
this.oracleHandler = new UtilityExecutionOracle(contractAddress, [], [], anchorBlockHeader, this.contractStore, this.noteStore, this.keyStore, this.addressStore, this.stateMachine.node, this.stateMachine.anchorBlockStore, this.recipientTaggingStore, this.senderAddressBookStore, this.capsuleStore, this.privateEventStore, this.currentJobId);
|
|
201
225
|
this.state = {
|
|
202
226
|
name: 'UTILITY'
|
|
203
227
|
};
|
|
@@ -227,13 +251,13 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
|
|
|
227
251
|
});
|
|
228
252
|
// We rely on the note cache to determine the effects of the transaction. This is incomplete as it doesn't private
|
|
229
253
|
// logs (other effects like enqueued public calls don't need to be considered since those are not allowed).
|
|
230
|
-
const txEffect = await makeTxEffect(this.state.noteCache, this.state.
|
|
254
|
+
const txEffect = await makeTxEffect(this.state.noteCache, this.state.nextBlockGlobalVariables.blockNumber);
|
|
231
255
|
// We build a block holding just this transaction
|
|
232
256
|
const forkedWorldTrees = await this.stateMachine.synchronizer.nativeWorldStateService.fork();
|
|
233
257
|
await insertTxEffectIntoWorldTrees(txEffect, forkedWorldTrees);
|
|
234
|
-
const block =
|
|
258
|
+
const block = await makeTXEBlock(forkedWorldTrees, this.state.nextBlockGlobalVariables, [
|
|
235
259
|
txEffect
|
|
236
|
-
])
|
|
260
|
+
]);
|
|
237
261
|
await this.stateMachine.handleL2Block(block);
|
|
238
262
|
await forkedWorldTrees.close();
|
|
239
263
|
this.logger.debug('Exited PublicContext with built block', {
|
|
@@ -253,4 +277,26 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
|
|
|
253
277
|
throw new Error(`Expected to be in state 'UTILITY', but got '${this.state.name}' instead`);
|
|
254
278
|
}
|
|
255
279
|
}
|
|
280
|
+
utilityExecutorForContractSync(anchorBlock) {
|
|
281
|
+
return async (call)=>{
|
|
282
|
+
const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
|
|
283
|
+
if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
|
|
284
|
+
throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
|
|
285
|
+
}
|
|
286
|
+
try {
|
|
287
|
+
const oracle = new UtilityExecutionOracle(call.to, [], [], anchorBlock, this.contractStore, this.noteStore, this.keyStore, this.addressStore, this.stateMachine.node, this.stateMachine.anchorBlockStore, this.recipientTaggingStore, this.senderAddressBookStore, this.capsuleStore, this.privateEventStore, this.currentJobId);
|
|
288
|
+
await new WASMSimulator().executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, new Oracle(oracle).toACIRCallback()).catch((err)=>{
|
|
289
|
+
err.message = resolveAssertionMessageFromError(err, entryPointArtifact);
|
|
290
|
+
throw new ExecutionError(err.message, {
|
|
291
|
+
contractAddress: call.to,
|
|
292
|
+
functionSelector: call.selector
|
|
293
|
+
}, extractCallStack(err, entryPointArtifact.debug), {
|
|
294
|
+
cause: err
|
|
295
|
+
});
|
|
296
|
+
});
|
|
297
|
+
} catch (err) {
|
|
298
|
+
throw createSimulationError(err instanceof Error ? err : new Error('Unknown error contract data sync'));
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
}
|
|
256
302
|
}
|