@aztec/txe 0.0.1-commit.9593d84 → 0.0.1-commit.96bb3f7
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 +4 -0
- package/dest/constants.d.ts.map +1 -0
- package/dest/constants.js +3 -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 +9 -6
- package/dest/oracle/interfaces.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.d.ts +5 -5
- package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.js +4 -6
- package/dest/oracle/txe_oracle_top_level_context.d.ts +21 -12
- package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_top_level_context.js +93 -62
- package/dest/rpc_translator.d.ts +11 -5
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +57 -15
- package/dest/state_machine/archiver.d.ts +29 -11
- package/dest/state_machine/archiver.d.ts.map +1 -1
- package/dest/state_machine/archiver.js +128 -17
- 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 +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 +5 -5
- package/dest/state_machine/index.d.ts.map +1 -1
- package/dest/state_machine/index.js +14 -20
- package/dest/state_machine/mock_epoch_cache.d.ts +2 -1
- package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
- package/dest/state_machine/mock_epoch_cache.js +3 -0
- package/dest/state_machine/synchronizer.d.ts +5 -4
- package/dest/state_machine/synchronizer.d.ts.map +1 -1
- package/dest/state_machine/synchronizer.js +5 -4
- package/dest/txe_session.d.ts +19 -13
- package/dest/txe_session.d.ts.map +1 -1
- package/dest/txe_session.js +76 -45
- package/dest/util/encoding.d.ts +610 -11
- package/dest/util/encoding.d.ts.map +1 -1
- package/dest/util/encoding.js +1 -1
- package/dest/util/txe_account_store.d.ts +10 -0
- package/dest/util/txe_account_store.d.ts.map +1 -0
- package/dest/util/{txe_account_data_provider.js → txe_account_store.js} +1 -1
- package/dest/util/txe_contract_store.d.ts +12 -0
- package/dest/util/txe_contract_store.d.ts.map +1 -0
- package/dest/util/{txe_contract_data_provider.js → txe_contract_store.js} +3 -3
- package/dest/util/txe_public_contract_data_source.d.ts +7 -6
- package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
- package/dest/util/txe_public_contract_data_source.js +11 -11
- package/dest/utils/block_creation.d.ts +19 -4
- package/dest/utils/block_creation.d.ts.map +1 -1
- package/dest/utils/block_creation.js +24 -4
- package/dest/utils/tx_effect_creation.d.ts +4 -3
- package/dest/utils/tx_effect_creation.d.ts.map +1 -1
- package/dest/utils/tx_effect_creation.js +1 -1
- package/package.json +17 -17
- package/src/constants.ts +4 -0
- package/src/index.ts +15 -12
- package/src/oracle/interfaces.ts +8 -5
- package/src/oracle/txe_oracle_public_context.ts +6 -11
- package/src/oracle/txe_oracle_top_level_context.ts +139 -88
- package/src/rpc_translator.ts +82 -12
- package/src/state_machine/archiver.ts +168 -26
- package/src/state_machine/dummy_p2p_client.ts +21 -14
- package/src/state_machine/global_variable_builder.ts +21 -4
- package/src/state_machine/index.ts +19 -18
- package/src/state_machine/mock_epoch_cache.ts +4 -0
- package/src/state_machine/synchronizer.ts +8 -7
- package/src/txe_session.ts +166 -75
- package/src/util/encoding.ts +1 -1
- package/src/util/{txe_account_data_provider.ts → txe_account_store.ts} +1 -1
- package/src/util/{txe_contract_data_provider.ts → txe_contract_store.ts} +3 -3
- package/src/util/txe_public_contract_data_source.ts +13 -12
- package/src/utils/block_creation.ts +36 -5
- package/src/utils/tx_effect_creation.ts +3 -2
- package/dest/util/txe_account_data_provider.d.ts +0 -10
- package/dest/util/txe_account_data_provider.d.ts.map +0 -1
- package/dest/util/txe_contract_data_provider.d.ts +0 -12
- package/dest/util/txe_contract_data_provider.d.ts.map +0 -1
package/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, CapsuleStore, 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, TXE_JOB_ID } 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';
|
|
18
20
|
import { TXEStateMachine } from './state_machine/index.js';
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
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';
|
|
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,28 +29,38 @@ 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;
|
|
35
42
|
chainId;
|
|
36
43
|
version;
|
|
37
44
|
nextBlockTimestamp;
|
|
38
|
-
pxeOracleInterface;
|
|
39
45
|
state;
|
|
40
46
|
authwits;
|
|
41
|
-
constructor(logger, stateMachine, oracleHandler,
|
|
47
|
+
constructor(logger, stateMachine, oracleHandler, contractStore, noteStore, keyStore, addressStore, accountStore, senderTaggingStore, recipientTaggingStore, senderAddressBookStore, capsuleStore, privateEventStore, chainId, version, nextBlockTimestamp){
|
|
42
48
|
this.logger = logger;
|
|
43
49
|
this.stateMachine = stateMachine;
|
|
44
50
|
this.oracleHandler = oracleHandler;
|
|
45
|
-
this.
|
|
51
|
+
this.contractStore = contractStore;
|
|
52
|
+
this.noteStore = noteStore;
|
|
46
53
|
this.keyStore = keyStore;
|
|
47
|
-
this.
|
|
48
|
-
this.
|
|
54
|
+
this.addressStore = addressStore;
|
|
55
|
+
this.accountStore = accountStore;
|
|
56
|
+
this.senderTaggingStore = senderTaggingStore;
|
|
57
|
+
this.recipientTaggingStore = recipientTaggingStore;
|
|
58
|
+
this.senderAddressBookStore = senderAddressBookStore;
|
|
59
|
+
this.capsuleStore = capsuleStore;
|
|
60
|
+
this.privateEventStore = privateEventStore;
|
|
49
61
|
this.chainId = chainId;
|
|
50
62
|
this.version = version;
|
|
51
63
|
this.nextBlockTimestamp = nextBlockTimestamp;
|
|
52
|
-
this.pxeOracleInterface = pxeOracleInterface;
|
|
53
64
|
this.state = {
|
|
54
65
|
name: 'TOP_LEVEL'
|
|
55
66
|
};
|
|
@@ -57,27 +68,28 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
|
|
|
57
68
|
}
|
|
58
69
|
static async init(protocolContracts) {
|
|
59
70
|
const store = await openTmpStore('txe-session');
|
|
60
|
-
const
|
|
61
|
-
const
|
|
62
|
-
const
|
|
63
|
-
const
|
|
64
|
-
const
|
|
65
|
-
const
|
|
71
|
+
const addressStore = new AddressStore(store);
|
|
72
|
+
const privateEventStore = new PrivateEventStore(store);
|
|
73
|
+
const contractStore = new TXEContractStore(store);
|
|
74
|
+
const noteStore = await NoteStore.create(store);
|
|
75
|
+
const senderTaggingStore = new SenderTaggingStore(store);
|
|
76
|
+
const recipientTaggingStore = new RecipientTaggingStore(store);
|
|
77
|
+
const senderAddressBookStore = new SenderAddressBookStore(store);
|
|
78
|
+
const capsuleStore = new CapsuleStore(store);
|
|
66
79
|
const keyStore = new KeyStore(store);
|
|
67
|
-
const
|
|
80
|
+
const accountStore = new TXEAccountStore(store);
|
|
68
81
|
// Register protocol contracts.
|
|
69
82
|
for (const { contractClass, instance, artifact } of protocolContracts){
|
|
70
|
-
await
|
|
71
|
-
await
|
|
83
|
+
await contractStore.addContractArtifact(contractClass.id, artifact);
|
|
84
|
+
await contractStore.addContractInstance(instance);
|
|
72
85
|
}
|
|
73
86
|
const stateMachine = await TXEStateMachine.create(store);
|
|
74
87
|
const nextBlockTimestamp = BigInt(Math.floor(new Date().getTime() / 1000));
|
|
75
88
|
const version = new Fr(await stateMachine.node.getVersion());
|
|
76
89
|
const chainId = new Fr(await stateMachine.node.getChainId());
|
|
77
|
-
const
|
|
78
|
-
const topLevelOracleHandler = new TXEOracleTopLevelContext(stateMachine, contractDataProvider, keyStore, addressDataProvider, accountDataProvider, pxeOracleInterface, nextBlockTimestamp, version, chainId, new Map());
|
|
90
|
+
const topLevelOracleHandler = new TXEOracleTopLevelContext(stateMachine, contractStore, noteStore, keyStore, addressStore, accountStore, senderTaggingStore, recipientTaggingStore, senderAddressBookStore, capsuleStore, privateEventStore, nextBlockTimestamp, version, chainId, new Map());
|
|
79
91
|
await topLevelOracleHandler.txeAdvanceBlocksBy(1);
|
|
80
|
-
return new TXESession(createLogger('txe:session'), stateMachine, topLevelOracleHandler,
|
|
92
|
+
return new TXESession(createLogger('txe:session'), stateMachine, topLevelOracleHandler, contractStore, noteStore, keyStore, addressStore, accountStore, senderTaggingStore, recipientTaggingStore, senderAddressBookStore, capsuleStore, privateEventStore, version, chainId, nextBlockTimestamp);
|
|
81
93
|
}
|
|
82
94
|
/**
|
|
83
95
|
* Processes an oracle function invoked by the Noir test associated to this session.
|
|
@@ -126,7 +138,7 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
|
|
|
126
138
|
this.state;
|
|
127
139
|
}
|
|
128
140
|
}
|
|
129
|
-
this.oracleHandler = new TXEOracleTopLevelContext(this.stateMachine, this.
|
|
141
|
+
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
142
|
this.state = {
|
|
131
143
|
name: 'TOP_LEVEL'
|
|
132
144
|
};
|
|
@@ -134,19 +146,14 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
|
|
|
134
146
|
}
|
|
135
147
|
async enterPrivateState(contractAddress = DEFAULT_ADDRESS, anchorBlockNumber) {
|
|
136
148
|
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);
|
|
149
|
+
await new NoteService(this.noteStore, this.stateMachine.node, this.stateMachine.anchorBlockStore).syncNoteNullifiers(contractAddress);
|
|
143
150
|
// Private execution has two associated block numbers: the anchor block (i.e. the historical block that is used to
|
|
144
151
|
// build the proof), and the *next* block, i.e. the one we'll create once the execution ends, and which will contain
|
|
145
152
|
// a single transaction with the effects of what was done in the test.
|
|
146
153
|
const anchorBlock = await this.stateMachine.node.getBlockHeader(anchorBlockNumber ?? 'latest');
|
|
147
154
|
const latestBlock = await this.stateMachine.node.getBlockHeader('latest');
|
|
148
155
|
const nextBlockGlobalVariables = makeGlobalVariables(undefined, {
|
|
149
|
-
blockNumber: latestBlock.globalVariables.blockNumber + 1,
|
|
156
|
+
blockNumber: BlockNumber(latestBlock.globalVariables.blockNumber + 1),
|
|
150
157
|
timestamp: this.nextBlockTimestamp,
|
|
151
158
|
version: this.version,
|
|
152
159
|
chainId: this.chainId
|
|
@@ -155,7 +162,8 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
|
|
|
155
162
|
const protocolNullifier = await computeProtocolNullifier(txRequestHash);
|
|
156
163
|
const noteCache = new ExecutionNoteCache(protocolNullifier);
|
|
157
164
|
const taggingIndexCache = new ExecutionTaggingIndexCache();
|
|
158
|
-
|
|
165
|
+
const utilityExecutor = this.utilityExecutorForContractSync(anchorBlock);
|
|
166
|
+
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, TXE_JOB_ID);
|
|
159
167
|
// We store the note and tagging index caches fed into the PrivateExecutionOracle (along with some other auxiliary
|
|
160
168
|
// data) in order to refer to it later, mimicking the way this object is used by the ContractFunctionSimulator. The
|
|
161
169
|
// difference resides in that the simulator has all information needed in order to run the simulation, while ours
|
|
@@ -177,7 +185,7 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
|
|
|
177
185
|
// the test. The block therefore gets the *next* block number and timestamp.
|
|
178
186
|
const latestBlockNumber = (await this.stateMachine.node.getBlockHeader('latest')).globalVariables.blockNumber;
|
|
179
187
|
const globalVariables = makeGlobalVariables(undefined, {
|
|
180
|
-
blockNumber: latestBlockNumber + 1,
|
|
188
|
+
blockNumber: BlockNumber(latestBlockNumber + 1),
|
|
181
189
|
timestamp: this.nextBlockTimestamp,
|
|
182
190
|
version: this.version,
|
|
183
191
|
chainId: this.chainId
|
|
@@ -195,8 +203,9 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
|
|
|
195
203
|
// we perform this. We therefore search for known nullifiers now, as otherwise notes that were nullified would not
|
|
196
204
|
// be removed from the database.
|
|
197
205
|
// TODO(#12553): make the synchronizer sync here instead and remove this
|
|
198
|
-
await this.
|
|
199
|
-
|
|
206
|
+
await new NoteService(this.noteStore, this.stateMachine.node, this.stateMachine.anchorBlockStore).syncNoteNullifiers(contractAddress);
|
|
207
|
+
const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
208
|
+
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, TXE_JOB_ID);
|
|
200
209
|
this.state = {
|
|
201
210
|
name: 'UTILITY'
|
|
202
211
|
};
|
|
@@ -230,9 +239,9 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
|
|
|
230
239
|
// We build a block holding just this transaction
|
|
231
240
|
const forkedWorldTrees = await this.stateMachine.synchronizer.nativeWorldStateService.fork();
|
|
232
241
|
await insertTxEffectIntoWorldTrees(txEffect, forkedWorldTrees);
|
|
233
|
-
const block =
|
|
242
|
+
const block = await makeTXEBlock(forkedWorldTrees, this.state.nextBlockGlobalVariables, [
|
|
234
243
|
txEffect
|
|
235
|
-
])
|
|
244
|
+
]);
|
|
236
245
|
await this.stateMachine.handleL2Block(block);
|
|
237
246
|
await forkedWorldTrees.close();
|
|
238
247
|
this.logger.debug('Exited PublicContext with built block', {
|
|
@@ -252,4 +261,26 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
|
|
|
252
261
|
throw new Error(`Expected to be in state 'UTILITY', but got '${this.state.name}' instead`);
|
|
253
262
|
}
|
|
254
263
|
}
|
|
264
|
+
utilityExecutorForContractSync(anchorBlock) {
|
|
265
|
+
return async (call)=>{
|
|
266
|
+
const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
|
|
267
|
+
if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
|
|
268
|
+
throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
|
|
269
|
+
}
|
|
270
|
+
try {
|
|
271
|
+
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, TXE_JOB_ID);
|
|
272
|
+
await new WASMSimulator().executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, new Oracle(oracle).toACIRCallback()).catch((err)=>{
|
|
273
|
+
err.message = resolveAssertionMessageFromError(err, entryPointArtifact);
|
|
274
|
+
throw new ExecutionError(err.message, {
|
|
275
|
+
contractAddress: call.to,
|
|
276
|
+
functionSelector: call.selector
|
|
277
|
+
}, extractCallStack(err, entryPointArtifact.debug), {
|
|
278
|
+
cause: err
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
} catch (err) {
|
|
282
|
+
throw createSimulationError(err instanceof Error ? err : new Error('Unknown error contract data sync'));
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
}
|
|
255
286
|
}
|