@aztec/txe 0.0.1-commit.6d63667d → 0.0.1-commit.7035c9bd6
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/index.d.ts +1 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +88 -54
- package/dest/oracle/interfaces.d.ts +29 -28
- package/dest/oracle/interfaces.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.d.ts +13 -13
- package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.js +12 -12
- package/dest/oracle/txe_oracle_top_level_context.d.ts +23 -23
- package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_top_level_context.js +120 -53
- package/dest/rpc_translator.d.ts +88 -83
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +273 -151
- package/dest/state_machine/archiver.d.ts +3 -3
- package/dest/state_machine/archiver.d.ts.map +1 -1
- package/dest/state_machine/archiver.js +5 -7
- package/dest/state_machine/dummy_p2p_client.d.ts +16 -12
- package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
- package/dest/state_machine/dummy_p2p_client.js +28 -16
- package/dest/state_machine/index.d.ts +4 -2
- package/dest/state_machine/index.d.ts.map +1 -1
- package/dest/state_machine/index.js +7 -3
- package/dest/state_machine/mock_epoch_cache.d.ts +19 -3
- package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
- package/dest/state_machine/mock_epoch_cache.js +36 -2
- package/dest/state_machine/synchronizer.d.ts +5 -5
- package/dest/state_machine/synchronizer.d.ts.map +1 -1
- package/dest/state_machine/synchronizer.js +3 -3
- package/dest/txe_session.d.ts +10 -6
- package/dest/txe_session.d.ts.map +1 -1
- package/dest/txe_session.js +89 -24
- package/dest/util/txe_public_contract_data_source.d.ts +2 -3
- package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
- package/dest/util/txe_public_contract_data_source.js +5 -22
- package/package.json +15 -15
- package/src/index.ts +89 -52
- package/src/oracle/interfaces.ts +32 -31
- package/src/oracle/txe_oracle_public_context.ts +12 -12
- package/src/oracle/txe_oracle_top_level_context.ts +123 -101
- package/src/rpc_translator.ts +305 -173
- package/src/state_machine/archiver.ts +5 -5
- package/src/state_machine/dummy_p2p_client.ts +40 -22
- package/src/state_machine/index.ts +6 -1
- package/src/state_machine/mock_epoch_cache.ts +47 -3
- package/src/state_machine/synchronizer.ts +4 -4
- package/src/txe_session.ts +94 -72
- package/src/util/txe_public_contract_data_source.ts +10 -36
- package/dest/util/txe_contract_store.d.ts +0 -12
- package/dest/util/txe_contract_store.d.ts.map +0 -1
- package/dest/util/txe_contract_store.js +0 -22
- package/src/util/txe_contract_store.ts +0 -36
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"txe_session.d.ts","sourceRoot":"","sources":["../src/txe_session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AACpD,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;AAClE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"txe_session.d.ts","sourceRoot":"","sources":["../src/txe_session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AACpD,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,uBAAuB,CAAC;AAClE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAG5C,OAAO,EACL,YAAY,EAEZ,YAAY,EACZ,aAAa,EACb,mBAAmB,EACnB,cAAc,EAEd,SAAS,EACT,iBAAiB,EACjB,qBAAqB,EACrB,sBAAsB,EACtB,kBAAkB,EACnB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mBAAmB,EAC9C;IAEJ,OAAa,IAAI,CAAC,aAAa,EAAE,aAAa,uBA6E7C;IAED;;;;;OAKG;IACH,eAAe,CAAC,YAAY,EAAE,qBAAqB,EAAE,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAuBxG;IAED,aAAa,IAAI,MAAM,CAEtB;IAED,4EAA4E;IACtE,QAAQ,IAAI,OAAO,CAAC,MAAM,CAAC,CAIhC;IAEK,kBAAkB,kBA8CvB;IAEK,iBAAiB,CACrB,eAAe,GAAE,YAA8B,EAC/C,iBAAiB,CAAC,EAAE,WAAW,GAC9B,OAAO,CAAC,oBAAoB,CAAC,CA+D/B;IAEK,gBAAgB,CAAC,eAAe,CAAC,EAAE,YAAY,iBAsBpD;IAEK,iBAAiB,CAAC,eAAe,GAAE,YAA8B,iBAuCtE;IAED,OAAO,CAAC,iBAAiB;YAiBX,gBAAgB;YA6BhB,eAAe;IAS7B,OAAO,CAAC,kBAAkB;IAM1B,OAAO,CAAC,8BAA8B;CA8CvC"}
|
package/dest/txe_session.js
CHANGED
|
@@ -3,7 +3,7 @@ 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 { AddressStore, AnchorBlockStore, CapsuleStore, JobCoordinator, NoteService, NoteStore, PrivateEventStore, RecipientTaggingStore, SenderAddressBookStore, SenderTaggingStore } from '@aztec/pxe/server';
|
|
6
|
+
import { AddressStore, AnchorBlockStore, CapsuleStore, ContractSyncService, JobCoordinator, NoteService, NoteStore, PrivateEventStore, RecipientTaggingStore, SenderAddressBookStore, SenderTaggingStore } from '@aztec/pxe/server';
|
|
7
7
|
import { ExecutionNoteCache, ExecutionTaggingIndexCache, HashedValuesCache, Oracle, PrivateExecutionOracle, UtilityExecutionOracle } from '@aztec/pxe/simulator';
|
|
8
8
|
import { ExecutionError, WASMSimulator, createSimulationError, extractCallStack, resolveAssertionMessageFromError, toACVMWitness } from '@aztec/simulator/client';
|
|
9
9
|
import { FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
|
|
@@ -20,7 +20,6 @@ import { RPCTranslator } from './rpc_translator.js';
|
|
|
20
20
|
import { TXEArchiver } from './state_machine/archiver.js';
|
|
21
21
|
import { TXEStateMachine } from './state_machine/index.js';
|
|
22
22
|
import { TXEAccountStore } from './util/txe_account_store.js';
|
|
23
|
-
import { TXEContractStore } from './util/txe_contract_store.js';
|
|
24
23
|
import { getSingleTxBlockRequestHash, insertTxEffectIntoWorldTrees, makeTXEBlock } from './utils/block_creation.js';
|
|
25
24
|
import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
26
25
|
/**
|
|
@@ -45,9 +44,10 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
|
45
44
|
chainId;
|
|
46
45
|
version;
|
|
47
46
|
nextBlockTimestamp;
|
|
47
|
+
contractSyncService;
|
|
48
48
|
state;
|
|
49
49
|
authwits;
|
|
50
|
-
constructor(logger, stateMachine, oracleHandler, contractStore, noteStore, keyStore, addressStore, accountStore, senderTaggingStore, recipientTaggingStore, senderAddressBookStore, capsuleStore, privateEventStore, jobCoordinator, currentJobId, chainId, version, nextBlockTimestamp){
|
|
50
|
+
constructor(logger, stateMachine, oracleHandler, contractStore, noteStore, keyStore, addressStore, accountStore, senderTaggingStore, recipientTaggingStore, senderAddressBookStore, capsuleStore, privateEventStore, jobCoordinator, currentJobId, chainId, version, nextBlockTimestamp, contractSyncService){
|
|
51
51
|
this.logger = logger;
|
|
52
52
|
this.stateMachine = stateMachine;
|
|
53
53
|
this.oracleHandler = oracleHandler;
|
|
@@ -66,16 +66,16 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
|
66
66
|
this.chainId = chainId;
|
|
67
67
|
this.version = version;
|
|
68
68
|
this.nextBlockTimestamp = nextBlockTimestamp;
|
|
69
|
+
this.contractSyncService = contractSyncService;
|
|
69
70
|
this.state = {
|
|
70
71
|
name: 'TOP_LEVEL'
|
|
71
72
|
};
|
|
72
73
|
this.authwits = new Map();
|
|
73
74
|
}
|
|
74
|
-
static async init(
|
|
75
|
+
static async init(contractStore) {
|
|
75
76
|
const store = await openTmpStore('txe-session');
|
|
76
77
|
const addressStore = new AddressStore(store);
|
|
77
78
|
const privateEventStore = new PrivateEventStore(store);
|
|
78
|
-
const contractStore = new TXEContractStore(store);
|
|
79
79
|
const noteStore = new NoteStore(store);
|
|
80
80
|
const senderTaggingStore = new SenderTaggingStore(store);
|
|
81
81
|
const recipientTaggingStore = new RecipientTaggingStore(store);
|
|
@@ -92,11 +92,6 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
|
92
92
|
privateEventStore,
|
|
93
93
|
noteStore
|
|
94
94
|
]);
|
|
95
|
-
// Register protocol contracts.
|
|
96
|
-
for (const { contractClass, instance, artifact } of protocolContracts){
|
|
97
|
-
await contractStore.addContractArtifact(contractClass.id, artifact);
|
|
98
|
-
await contractStore.addContractInstance(instance);
|
|
99
|
-
}
|
|
100
95
|
const archiver = new TXEArchiver(store);
|
|
101
96
|
const anchorBlockStore = new AnchorBlockStore(store);
|
|
102
97
|
const stateMachine = await TXEStateMachine.create(archiver, anchorBlockStore, contractStore, noteStore);
|
|
@@ -104,9 +99,11 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
|
104
99
|
const version = new Fr(await stateMachine.node.getVersion());
|
|
105
100
|
const chainId = new Fr(await stateMachine.node.getChainId());
|
|
106
101
|
const initialJobId = jobCoordinator.beginJob();
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
|
|
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);
|
|
110
107
|
}
|
|
111
108
|
/**
|
|
112
109
|
* Processes an oracle function invoked by the Noir test associated to this session.
|
|
@@ -129,6 +126,14 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
|
129
126
|
}
|
|
130
127
|
}
|
|
131
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
|
+
}
|
|
132
137
|
async enterTopLevelState() {
|
|
133
138
|
switch(this.state.name){
|
|
134
139
|
case 'PRIVATE':
|
|
@@ -156,9 +161,8 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
|
156
161
|
}
|
|
157
162
|
}
|
|
158
163
|
// Commit all staged stores from the job that was just completed, then begin a new job
|
|
159
|
-
await this.
|
|
160
|
-
this.
|
|
161
|
-
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);
|
|
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);
|
|
162
166
|
this.state = {
|
|
163
167
|
name: 'TOP_LEVEL'
|
|
164
168
|
};
|
|
@@ -170,7 +174,7 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
|
170
174
|
// build the proof), and the *next* block, i.e. the one we'll create once the execution ends, and which will contain
|
|
171
175
|
// a single transaction with the effects of what was done in the test.
|
|
172
176
|
const anchorBlock = await this.stateMachine.node.getBlockHeader(anchorBlockNumber ?? 'latest');
|
|
173
|
-
await new NoteService(this.noteStore, this.stateMachine.node, anchorBlock, this.currentJobId).syncNoteNullifiers(contractAddress);
|
|
177
|
+
await new NoteService(this.noteStore, this.stateMachine.node, anchorBlock, this.currentJobId).syncNoteNullifiers(contractAddress, 'ALL_SCOPES');
|
|
174
178
|
const latestBlock = await this.stateMachine.node.getBlockHeader('latest');
|
|
175
179
|
const nextBlockGlobalVariables = makeGlobalVariables(undefined, {
|
|
176
180
|
blockNumber: BlockNumber(latestBlock.globalVariables.blockNumber + 1),
|
|
@@ -183,7 +187,32 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
|
183
187
|
const noteCache = new ExecutionNoteCache(protocolNullifier);
|
|
184
188
|
const taggingIndexCache = new ExecutionTaggingIndexCache();
|
|
185
189
|
const utilityExecutor = this.utilityExecutorForContractSync(anchorBlock);
|
|
186
|
-
this.oracleHandler = new PrivateExecutionOracle(
|
|
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
|
+
capsuleStore: this.capsuleStore,
|
|
210
|
+
privateEventStore: this.privateEventStore,
|
|
211
|
+
contractSyncService: this.stateMachine.contractSyncService,
|
|
212
|
+
jobId: this.currentJobId,
|
|
213
|
+
scopes: 'ALL_SCOPES',
|
|
214
|
+
messageContextService: this.stateMachine.messageContextService
|
|
215
|
+
});
|
|
187
216
|
// We store the note and tagging index caches fed into the PrivateExecutionOracle (along with some other auxiliary
|
|
188
217
|
// data) in order to refer to it later, mimicking the way this object is used by the ContractFunctionSimulator. The
|
|
189
218
|
// difference resides in that the simulator has all information needed in order to run the simulation, while ours
|
|
@@ -223,8 +252,26 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
|
223
252
|
// we perform this. We therefore search for known nullifiers now, as otherwise notes that were nullified would not
|
|
224
253
|
// be removed from the database.
|
|
225
254
|
// TODO(#12553): make the synchronizer sync here instead and remove this
|
|
226
|
-
await new NoteService(this.noteStore, this.stateMachine.node, anchorBlockHeader, this.currentJobId).syncNoteNullifiers(contractAddress);
|
|
227
|
-
this.oracleHandler = new UtilityExecutionOracle(
|
|
255
|
+
await new NoteService(this.noteStore, this.stateMachine.node, anchorBlockHeader, this.currentJobId).syncNoteNullifiers(contractAddress, 'ALL_SCOPES');
|
|
256
|
+
this.oracleHandler = new UtilityExecutionOracle({
|
|
257
|
+
contractAddress,
|
|
258
|
+
authWitnesses: [],
|
|
259
|
+
capsules: [],
|
|
260
|
+
anchorBlockHeader,
|
|
261
|
+
contractStore: this.contractStore,
|
|
262
|
+
noteStore: this.noteStore,
|
|
263
|
+
keyStore: this.keyStore,
|
|
264
|
+
addressStore: this.addressStore,
|
|
265
|
+
aztecNode: this.stateMachine.node,
|
|
266
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
267
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
268
|
+
capsuleStore: this.capsuleStore,
|
|
269
|
+
privateEventStore: this.privateEventStore,
|
|
270
|
+
messageContextService: this.stateMachine.messageContextService,
|
|
271
|
+
contractSyncService: this.contractSyncService,
|
|
272
|
+
jobId: this.currentJobId,
|
|
273
|
+
scopes: 'ALL_SCOPES'
|
|
274
|
+
});
|
|
228
275
|
this.state = {
|
|
229
276
|
name: 'UTILITY'
|
|
230
277
|
};
|
|
@@ -236,8 +283,8 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
|
236
283
|
}
|
|
237
284
|
// Note that while all public and private contexts do is build a single block that we then process when exiting
|
|
238
285
|
// those, the top level context performs a large number of actions not captured in the following 'close' call. Among
|
|
239
|
-
// others, it will create empty blocks (via `
|
|
240
|
-
// `
|
|
286
|
+
// others, it will create empty blocks (via `advanceBlocksBy` and `deploy`), create blocks with transactions via
|
|
287
|
+
// `privateCallNewFlow` and `publicCallNewFlow`, add accounts to PXE via `addAccount`, etc. This is a
|
|
241
288
|
// slight inconsistency in the working model of this class, but is not too bad.
|
|
242
289
|
// TODO: it's quite unfortunate that we need to capture the authwits created to later pass them again when the top
|
|
243
290
|
// level context is re-created. This is because authwits create a temporary utility context that'd otherwise reset
|
|
@@ -281,13 +328,31 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
|
281
328
|
}
|
|
282
329
|
}
|
|
283
330
|
utilityExecutorForContractSync(anchorBlock) {
|
|
284
|
-
return async (call)=>{
|
|
331
|
+
return async (call, scopes)=>{
|
|
285
332
|
const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
|
|
286
333
|
if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
|
|
287
334
|
throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
|
|
288
335
|
}
|
|
289
336
|
try {
|
|
290
|
-
const oracle = new UtilityExecutionOracle(
|
|
337
|
+
const oracle = new UtilityExecutionOracle({
|
|
338
|
+
contractAddress: call.to,
|
|
339
|
+
authWitnesses: [],
|
|
340
|
+
capsules: [],
|
|
341
|
+
anchorBlockHeader: anchorBlock,
|
|
342
|
+
contractStore: this.contractStore,
|
|
343
|
+
noteStore: this.noteStore,
|
|
344
|
+
keyStore: this.keyStore,
|
|
345
|
+
addressStore: this.addressStore,
|
|
346
|
+
aztecNode: this.stateMachine.node,
|
|
347
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
348
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
349
|
+
capsuleStore: this.capsuleStore,
|
|
350
|
+
privateEventStore: this.privateEventStore,
|
|
351
|
+
messageContextService: this.stateMachine.messageContextService,
|
|
352
|
+
contractSyncService: this.contractSyncService,
|
|
353
|
+
jobId: this.currentJobId,
|
|
354
|
+
scopes
|
|
355
|
+
});
|
|
291
356
|
await new WASMSimulator().executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, new Oracle(oracle).toACIRCallback()).catch((err)=>{
|
|
292
357
|
err.message = resolveAssertionMessageFromError(err, entryPointArtifact);
|
|
293
358
|
throw new ExecutionError(err.message, {
|
|
@@ -3,9 +3,8 @@ import { Fr } from '@aztec/foundation/curves/bn254';
|
|
|
3
3
|
import type { ContractStore } from '@aztec/pxe/server';
|
|
4
4
|
import { type ContractArtifact, FunctionSelector } from '@aztec/stdlib/abi';
|
|
5
5
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
6
|
-
import {
|
|
6
|
+
import type { ContractClassPublic, ContractDataSource, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
|
|
7
7
|
export declare class TXEPublicContractDataSource implements ContractDataSource {
|
|
8
|
-
#private;
|
|
9
8
|
private blockNumber;
|
|
10
9
|
private contractStore;
|
|
11
10
|
constructor(blockNumber: BlockNumber, contractStore: ContractStore);
|
|
@@ -18,4 +17,4 @@ export declare class TXEPublicContractDataSource implements ContractDataSource {
|
|
|
18
17
|
getDebugFunctionName(address: AztecAddress, selector: FunctionSelector): Promise<string | undefined>;
|
|
19
18
|
registerContractFunctionSignatures(_signatures: []): Promise<void>;
|
|
20
19
|
}
|
|
21
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
20
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHhlX3B1YmxpY19jb250cmFjdF9kYXRhX3NvdXJjZS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3V0aWwvdHhlX3B1YmxpY19jb250cmFjdF9kYXRhX3NvdXJjZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsV0FBVyxFQUFFLE1BQU0saUNBQWlDLENBQUM7QUFDOUQsT0FBTyxFQUFFLEVBQUUsRUFBRSxNQUFNLGdDQUFnQyxDQUFDO0FBQ3BELE9BQU8sS0FBSyxFQUFFLGFBQWEsRUFBRSxNQUFNLG1CQUFtQixDQUFDO0FBQ3ZELE9BQU8sRUFBRSxLQUFLLGdCQUFnQixFQUFFLGdCQUFnQixFQUFFLE1BQU0sbUJBQW1CLENBQUM7QUFDNUUsT0FBTyxLQUFLLEVBQUUsWUFBWSxFQUFFLE1BQU0sNkJBQTZCLENBQUM7QUFDaEUsT0FBTyxLQUFLLEVBQUUsbUJBQW1CLEVBQUUsa0JBQWtCLEVBQUUsMkJBQTJCLEVBQUUsTUFBTSx3QkFBd0IsQ0FBQztBQUVuSCxxQkFBYSwyQkFBNEIsWUFBVyxrQkFBa0I7SUFFbEUsT0FBTyxDQUFDLFdBQVc7SUFDbk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,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAEzG;IAED,kCAAkC,CAAC,WAAW,EAAE,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAEjE;CACF"}
|
|
@@ -1,48 +1,31 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
|
-
import { FunctionType } from '@aztec/stdlib/abi';
|
|
3
|
-
import { computePrivateFunctionsRoot, computePublicBytecodeCommitment, getContractClassPrivateFunctionFromArtifact } from '@aztec/stdlib/contract';
|
|
4
1
|
export class TXEPublicContractDataSource {
|
|
5
2
|
blockNumber;
|
|
6
3
|
contractStore;
|
|
7
|
-
#privateFunctionsRoot;
|
|
8
4
|
constructor(blockNumber, contractStore){
|
|
9
5
|
this.blockNumber = blockNumber;
|
|
10
6
|
this.contractStore = contractStore;
|
|
11
|
-
this.#privateFunctionsRoot = new Map();
|
|
12
7
|
}
|
|
13
8
|
getBlockNumber() {
|
|
14
9
|
return Promise.resolve(this.blockNumber);
|
|
15
10
|
}
|
|
16
11
|
async getContractClass(id) {
|
|
17
|
-
const contractClass = await this.contractStore.
|
|
12
|
+
const contractClass = await this.contractStore.getContractClassWithPreimage(id);
|
|
18
13
|
if (!contractClass) {
|
|
19
14
|
return;
|
|
20
15
|
}
|
|
21
|
-
const artifact = await this.contractStore.getContractArtifact(id);
|
|
22
|
-
if (!artifact) {
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
let privateFunctionsRoot;
|
|
26
|
-
if (!this.#privateFunctionsRoot.has(id.toString())) {
|
|
27
|
-
const privateFunctions = await Promise.all(artifact.functions.filter((fn)=>fn.functionType === FunctionType.PRIVATE).map((fn)=>getContractClassPrivateFunctionFromArtifact(fn)));
|
|
28
|
-
privateFunctionsRoot = await computePrivateFunctionsRoot(privateFunctions);
|
|
29
|
-
this.#privateFunctionsRoot.set(id.toString(), privateFunctionsRoot.toBuffer());
|
|
30
|
-
} else {
|
|
31
|
-
privateFunctionsRoot = Fr.fromBuffer(this.#privateFunctionsRoot.get(id.toString()));
|
|
32
|
-
}
|
|
33
16
|
return {
|
|
34
|
-
id,
|
|
17
|
+
id: contractClass.id,
|
|
35
18
|
artifactHash: contractClass.artifactHash,
|
|
36
19
|
packedBytecode: contractClass.packedBytecode,
|
|
37
|
-
privateFunctionsRoot,
|
|
20
|
+
privateFunctionsRoot: contractClass.privateFunctionsRoot,
|
|
38
21
|
version: contractClass.version,
|
|
39
22
|
privateFunctions: [],
|
|
40
23
|
utilityFunctions: []
|
|
41
24
|
};
|
|
42
25
|
}
|
|
43
26
|
async getBytecodeCommitment(id) {
|
|
44
|
-
const contractClass = await this.contractStore.
|
|
45
|
-
return contractClass
|
|
27
|
+
const contractClass = await this.contractStore.getContractClassWithPreimage(id);
|
|
28
|
+
return contractClass?.publicBytecodeCommitment;
|
|
46
29
|
}
|
|
47
30
|
async getContract(address) {
|
|
48
31
|
const instance = await this.contractStore.getContractInstance(address);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/txe",
|
|
3
|
-
"version": "0.0.1-commit.
|
|
3
|
+
"version": "0.0.1-commit.7035c9bd6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": "./dest/index.js",
|
|
6
6
|
"bin": "./dest/bin/index.js",
|
|
@@ -61,20 +61,20 @@
|
|
|
61
61
|
]
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
|
-
"@aztec/accounts": "0.0.1-commit.
|
|
65
|
-
"@aztec/archiver": "0.0.1-commit.
|
|
66
|
-
"@aztec/aztec-node": "0.0.1-commit.
|
|
67
|
-
"@aztec/aztec.js": "0.0.1-commit.
|
|
68
|
-
"@aztec/bb-prover": "0.0.1-commit.
|
|
69
|
-
"@aztec/constants": "0.0.1-commit.
|
|
70
|
-
"@aztec/foundation": "0.0.1-commit.
|
|
71
|
-
"@aztec/key-store": "0.0.1-commit.
|
|
72
|
-
"@aztec/kv-store": "0.0.1-commit.
|
|
73
|
-
"@aztec/protocol-contracts": "0.0.1-commit.
|
|
74
|
-
"@aztec/pxe": "0.0.1-commit.
|
|
75
|
-
"@aztec/simulator": "0.0.1-commit.
|
|
76
|
-
"@aztec/stdlib": "0.0.1-commit.
|
|
77
|
-
"@aztec/world-state": "0.0.1-commit.
|
|
64
|
+
"@aztec/accounts": "0.0.1-commit.7035c9bd6",
|
|
65
|
+
"@aztec/archiver": "0.0.1-commit.7035c9bd6",
|
|
66
|
+
"@aztec/aztec-node": "0.0.1-commit.7035c9bd6",
|
|
67
|
+
"@aztec/aztec.js": "0.0.1-commit.7035c9bd6",
|
|
68
|
+
"@aztec/bb-prover": "0.0.1-commit.7035c9bd6",
|
|
69
|
+
"@aztec/constants": "0.0.1-commit.7035c9bd6",
|
|
70
|
+
"@aztec/foundation": "0.0.1-commit.7035c9bd6",
|
|
71
|
+
"@aztec/key-store": "0.0.1-commit.7035c9bd6",
|
|
72
|
+
"@aztec/kv-store": "0.0.1-commit.7035c9bd6",
|
|
73
|
+
"@aztec/protocol-contracts": "0.0.1-commit.7035c9bd6",
|
|
74
|
+
"@aztec/pxe": "0.0.1-commit.7035c9bd6",
|
|
75
|
+
"@aztec/simulator": "0.0.1-commit.7035c9bd6",
|
|
76
|
+
"@aztec/stdlib": "0.0.1-commit.7035c9bd6",
|
|
77
|
+
"@aztec/world-state": "0.0.1-commit.7035c9bd6",
|
|
78
78
|
"zod": "^3.23.8"
|
|
79
79
|
},
|
|
80
80
|
"devDependencies": {
|
package/src/index.ts
CHANGED
|
@@ -9,9 +9,12 @@ import { Fr } from '@aztec/aztec.js/fields';
|
|
|
9
9
|
import { PublicKeys, deriveKeys } from '@aztec/aztec.js/keys';
|
|
10
10
|
import { createSafeJsonRpcServer } from '@aztec/foundation/json-rpc/server';
|
|
11
11
|
import type { Logger } from '@aztec/foundation/log';
|
|
12
|
-
import {
|
|
12
|
+
import { openTmpStore } from '@aztec/kv-store/lmdb-v2';
|
|
13
|
+
import { protocolContractNames } from '@aztec/protocol-contracts';
|
|
13
14
|
import { BundledProtocolContractsProvider } from '@aztec/protocol-contracts/providers/bundle';
|
|
15
|
+
import { ContractStore } from '@aztec/pxe/server';
|
|
14
16
|
import { computeArtifactHash } from '@aztec/stdlib/contract';
|
|
17
|
+
import type { ContractArtifactWithHash } from '@aztec/stdlib/contract';
|
|
15
18
|
import type { ApiSchemaFor } from '@aztec/stdlib/schemas';
|
|
16
19
|
import { zodFor } from '@aztec/stdlib/schemas';
|
|
17
20
|
|
|
@@ -29,22 +32,29 @@ import {
|
|
|
29
32
|
type ForeignCallResult,
|
|
30
33
|
ForeignCallResultSchema,
|
|
31
34
|
type ForeignCallSingle,
|
|
35
|
+
addressFromSingle,
|
|
32
36
|
fromArray,
|
|
33
37
|
fromSingle,
|
|
34
38
|
toSingle,
|
|
35
39
|
} from './util/encoding.js';
|
|
36
|
-
import type { ContractArtifactWithHash } from './util/txe_contract_store.js';
|
|
37
40
|
|
|
38
41
|
const sessions = new Map<number, TXESession>();
|
|
39
42
|
|
|
40
43
|
/*
|
|
41
44
|
* TXE typically has to load the same contract artifacts over and over again for multiple tests,
|
|
42
|
-
* so we cache them here to avoid
|
|
45
|
+
* so we cache them here to avoid loading from disk repeatedly.
|
|
46
|
+
*
|
|
47
|
+
* The in-flight map coalesces concurrent requests for the same cache key so that
|
|
48
|
+
* computeArtifactHash (very expensive) is only run once even under parallelism.
|
|
43
49
|
*/
|
|
44
50
|
const TXEArtifactsCache = new Map<
|
|
45
51
|
string,
|
|
46
52
|
{ artifact: ContractArtifactWithHash; instance: ContractInstanceWithAddress }
|
|
47
53
|
>();
|
|
54
|
+
const TXEArtifactsCacheInFlight = new Map<
|
|
55
|
+
string,
|
|
56
|
+
Promise<{ artifact: ContractArtifactWithHash; instance: ContractInstanceWithAddress }>
|
|
57
|
+
>();
|
|
48
58
|
|
|
49
59
|
type TXEForeignCallInput = {
|
|
50
60
|
session_id: number;
|
|
@@ -68,7 +78,7 @@ const TXEForeignCallInputSchema = zodFor<TXEForeignCallInput>()(
|
|
|
68
78
|
);
|
|
69
79
|
|
|
70
80
|
class TXEDispatcher {
|
|
71
|
-
private
|
|
81
|
+
private contractStore!: ContractStore;
|
|
72
82
|
|
|
73
83
|
constructor(private logger: Logger) {}
|
|
74
84
|
|
|
@@ -96,6 +106,8 @@ class TXEDispatcher {
|
|
|
96
106
|
|
|
97
107
|
const decodedArgs = fromArray(inputs[3] as ForeignCallArray);
|
|
98
108
|
const secret = fromSingle(inputs[4] as ForeignCallSingle);
|
|
109
|
+
const salt = fromSingle(inputs[5] as ForeignCallSingle);
|
|
110
|
+
const deployer = addressFromSingle(inputs[6] as ForeignCallSingle);
|
|
99
111
|
const publicKeys = secret.equals(Fr.ZERO) ? PublicKeys.default() : (await deriveKeys(secret)).publicKeys;
|
|
100
112
|
const publicKeysHash = await publicKeys.hash();
|
|
101
113
|
|
|
@@ -126,7 +138,7 @@ class TXEDispatcher {
|
|
|
126
138
|
|
|
127
139
|
const cacheKey = `${contractDirectory ?? ''}-${contractFilename}-${initializer}-${decodedArgs
|
|
128
140
|
.map(arg => arg.toString())
|
|
129
|
-
.join('-')}-${publicKeysHash}-${fileHash}`;
|
|
141
|
+
.join('-')}-${publicKeysHash}-${salt}-${deployer}-${fileHash}`;
|
|
130
142
|
|
|
131
143
|
let instance;
|
|
132
144
|
let artifact: ContractArtifactWithHash;
|
|
@@ -135,29 +147,36 @@ class TXEDispatcher {
|
|
|
135
147
|
this.logger.debug(`Using cached artifact for ${cacheKey}`);
|
|
136
148
|
({ artifact, instance } = TXEArtifactsCache.get(cacheKey)!);
|
|
137
149
|
} else {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
150
|
+
if (!TXEArtifactsCacheInFlight.has(cacheKey)) {
|
|
151
|
+
this.logger.debug(`Loading compiled artifact ${artifactPath}`);
|
|
152
|
+
const compute = async () => {
|
|
153
|
+
const artifactJSON = JSON.parse(await readFile(artifactPath, 'utf-8')) as NoirCompiledContract;
|
|
154
|
+
const artifactWithoutHash = loadContractArtifact(artifactJSON);
|
|
155
|
+
const computedArtifact: ContractArtifactWithHash = {
|
|
156
|
+
...artifactWithoutHash,
|
|
157
|
+
// Artifact hash is *very* expensive to compute, so we do it here once
|
|
158
|
+
// and the TXE contract data provider can cache it
|
|
159
|
+
artifactHash: await computeArtifactHash(artifactWithoutHash),
|
|
160
|
+
};
|
|
161
|
+
this.logger.debug(
|
|
162
|
+
`Deploy ${computedArtifact.name} with initializer ${initializer}(${decodedArgs}) and public keys hash ${publicKeysHash.toString()}`,
|
|
163
|
+
);
|
|
164
|
+
const computedInstance = await getContractInstanceFromInstantiationParams(computedArtifact, {
|
|
165
|
+
constructorArgs: decodedArgs,
|
|
166
|
+
skipArgsDecoding: true,
|
|
167
|
+
salt,
|
|
168
|
+
publicKeys,
|
|
169
|
+
constructorArtifact: initializer ? initializer : undefined,
|
|
170
|
+
deployer,
|
|
171
|
+
});
|
|
172
|
+
const result = { artifact: computedArtifact, instance: computedInstance };
|
|
173
|
+
TXEArtifactsCache.set(cacheKey, result);
|
|
174
|
+
TXEArtifactsCacheInFlight.delete(cacheKey);
|
|
175
|
+
return result;
|
|
176
|
+
};
|
|
177
|
+
TXEArtifactsCacheInFlight.set(cacheKey, compute());
|
|
178
|
+
}
|
|
179
|
+
({ artifact, instance } = await TXEArtifactsCacheInFlight.get(cacheKey)!);
|
|
161
180
|
}
|
|
162
181
|
|
|
163
182
|
inputs.splice(0, 1, artifact, instance, toSingle(secret));
|
|
@@ -175,23 +194,35 @@ class TXEDispatcher {
|
|
|
175
194
|
this.logger.debug(`Using cached artifact for ${cacheKey}`);
|
|
176
195
|
({ artifact, instance } = TXEArtifactsCache.get(cacheKey)!);
|
|
177
196
|
} else {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
197
|
+
if (!TXEArtifactsCacheInFlight.has(cacheKey)) {
|
|
198
|
+
const compute = async () => {
|
|
199
|
+
const keys = await deriveKeys(secret);
|
|
200
|
+
const args = [
|
|
201
|
+
keys.publicKeys.masterIncomingViewingPublicKey.x,
|
|
202
|
+
keys.publicKeys.masterIncomingViewingPublicKey.y,
|
|
203
|
+
];
|
|
204
|
+
const computedArtifact: ContractArtifactWithHash = {
|
|
205
|
+
...SchnorrAccountContractArtifact,
|
|
206
|
+
// Artifact hash is *very* expensive to compute, so we do it here once
|
|
207
|
+
// and the TXE contract data provider can cache it
|
|
208
|
+
artifactHash: await computeArtifactHash(SchnorrAccountContractArtifact),
|
|
209
|
+
};
|
|
210
|
+
const computedInstance = await getContractInstanceFromInstantiationParams(computedArtifact, {
|
|
211
|
+
constructorArgs: args,
|
|
212
|
+
skipArgsDecoding: true,
|
|
213
|
+
salt: Fr.ONE,
|
|
214
|
+
publicKeys: keys.publicKeys,
|
|
215
|
+
constructorArtifact: 'constructor',
|
|
216
|
+
deployer: AztecAddress.ZERO,
|
|
217
|
+
});
|
|
218
|
+
const result = { artifact: computedArtifact, instance: computedInstance };
|
|
219
|
+
TXEArtifactsCache.set(cacheKey, result);
|
|
220
|
+
TXEArtifactsCacheInFlight.delete(cacheKey);
|
|
221
|
+
return result;
|
|
222
|
+
};
|
|
223
|
+
TXEArtifactsCacheInFlight.set(cacheKey, compute());
|
|
224
|
+
}
|
|
225
|
+
({ artifact, instance } = await TXEArtifactsCacheInFlight.get(cacheKey)!);
|
|
195
226
|
}
|
|
196
227
|
|
|
197
228
|
inputs.splice(0, 0, artifact, instance);
|
|
@@ -204,20 +235,26 @@ class TXEDispatcher {
|
|
|
204
235
|
|
|
205
236
|
if (!sessions.has(sessionId)) {
|
|
206
237
|
this.logger.debug(`Creating new session ${sessionId}`);
|
|
207
|
-
if (!this.
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
);
|
|
238
|
+
if (!this.contractStore) {
|
|
239
|
+
const kvStore = await openTmpStore('txe-contracts');
|
|
240
|
+
this.contractStore = new ContractStore(kvStore);
|
|
241
|
+
const provider = new BundledProtocolContractsProvider();
|
|
242
|
+
for (const name of protocolContractNames) {
|
|
243
|
+
const { instance, artifact } = await provider.getProtocolContractArtifact(name);
|
|
244
|
+
await this.contractStore.addContractArtifact(artifact);
|
|
245
|
+
await this.contractStore.addContractInstance(instance);
|
|
246
|
+
}
|
|
247
|
+
this.logger.debug('Registered protocol contracts in shared contract store');
|
|
211
248
|
}
|
|
212
|
-
sessions.set(sessionId, await TXESession.init(this.
|
|
249
|
+
sessions.set(sessionId, await TXESession.init(this.contractStore));
|
|
213
250
|
}
|
|
214
251
|
|
|
215
252
|
switch (functionName) {
|
|
216
|
-
case '
|
|
253
|
+
case 'aztec_txe_deploy': {
|
|
217
254
|
await this.#processDeployInputs(callData);
|
|
218
255
|
break;
|
|
219
256
|
}
|
|
220
|
-
case '
|
|
257
|
+
case 'aztec_txe_addAccount': {
|
|
221
258
|
await this.#processAddAccountInputs(callData);
|
|
222
259
|
break;
|
|
223
260
|
}
|