@aztec/txe 0.0.1-commit.0c875d939 → 0.0.1-commit.10bd49492
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 +22 -23
- package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_top_level_context.js +52 -40
- package/dest/rpc_translator.d.ts +84 -82
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +249 -150
- 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 +6 -5
- package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
- package/dest/state_machine/dummy_p2p_client.js +7 -4
- 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/txe_session.d.ts +9 -6
- package/dest/txe_session.d.ts.map +1 -1
- package/dest/txe_session.js +19 -16
- 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 +61 -39
- package/src/rpc_translator.ts +277 -169
- package/src/state_machine/archiver.ts +5 -5
- package/src/state_machine/dummy_p2p_client.ts +11 -7
- package/src/state_machine/index.ts +6 -1
- package/src/txe_session.ts +25 -18
- 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
|
@@ -16,6 +16,7 @@ import type { AccessScopes } from '@aztec/pxe/client/lazy';
|
|
|
16
16
|
import {
|
|
17
17
|
AddressStore,
|
|
18
18
|
CapsuleStore,
|
|
19
|
+
type ContractStore,
|
|
19
20
|
NoteStore,
|
|
20
21
|
ORACLE_VERSION,
|
|
21
22
|
PrivateEventStore,
|
|
@@ -84,7 +85,6 @@ import { ForkCheckpoint } from '@aztec/world-state';
|
|
|
84
85
|
import { DEFAULT_ADDRESS } from '../constants.js';
|
|
85
86
|
import type { TXEStateMachine } from '../state_machine/index.js';
|
|
86
87
|
import type { TXEAccountStore } from '../util/txe_account_store.js';
|
|
87
|
-
import type { TXEContractStore } from '../util/txe_contract_store.js';
|
|
88
88
|
import { TXEPublicContractDataSource } from '../util/txe_public_contract_data_source.js';
|
|
89
89
|
import { getSingleTxBlockRequestHash, insertTxEffectIntoWorldTrees, makeTXEBlock } from '../utils/block_creation.js';
|
|
90
90
|
import type { ITxeExecutionOracle } from './interfaces.js';
|
|
@@ -97,7 +97,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
97
97
|
|
|
98
98
|
constructor(
|
|
99
99
|
private stateMachine: TXEStateMachine,
|
|
100
|
-
private contractStore:
|
|
100
|
+
private contractStore: ContractStore,
|
|
101
101
|
private noteStore: NoteStore,
|
|
102
102
|
private keyStore: KeyStore,
|
|
103
103
|
private addressStore: AddressStore,
|
|
@@ -107,7 +107,6 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
107
107
|
private senderAddressBookStore: SenderAddressBookStore,
|
|
108
108
|
private capsuleStore: CapsuleStore,
|
|
109
109
|
private privateEventStore: PrivateEventStore,
|
|
110
|
-
private jobId: string,
|
|
111
110
|
private nextBlockTimestamp: bigint,
|
|
112
111
|
private version: Fr,
|
|
113
112
|
private chainId: Fr,
|
|
@@ -117,7 +116,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
117
116
|
this.logger.debug('Entering Top Level Context');
|
|
118
117
|
}
|
|
119
118
|
|
|
120
|
-
|
|
119
|
+
assertCompatibleOracleVersion(version: number): void {
|
|
121
120
|
if (version !== ORACLE_VERSION) {
|
|
122
121
|
throw new Error(
|
|
123
122
|
`Incompatible oracle version. TXE is using version '${ORACLE_VERSION}', but got a request for '${version}'.`,
|
|
@@ -127,12 +126,12 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
127
126
|
|
|
128
127
|
// This is typically only invoked in private contexts, but it is convenient to also have it in top-level for testing
|
|
129
128
|
// setup.
|
|
130
|
-
|
|
129
|
+
getRandomField(): Fr {
|
|
131
130
|
return Fr.random();
|
|
132
131
|
}
|
|
133
132
|
|
|
134
133
|
// We instruct users to debug contracts via this oracle, so it makes sense that they'd expect it to also work in tests
|
|
135
|
-
|
|
134
|
+
log(level: number, message: string, fields: Fr[]): Promise<void> {
|
|
136
135
|
if (!LogLevels[level]) {
|
|
137
136
|
throw new Error(`Invalid log level: ${level}`);
|
|
138
137
|
}
|
|
@@ -142,23 +141,23 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
142
141
|
return Promise.resolve();
|
|
143
142
|
}
|
|
144
143
|
|
|
145
|
-
|
|
144
|
+
getDefaultAddress(): AztecAddress {
|
|
146
145
|
return DEFAULT_ADDRESS;
|
|
147
146
|
}
|
|
148
147
|
|
|
149
|
-
async
|
|
148
|
+
async getNextBlockNumber(): Promise<BlockNumber> {
|
|
150
149
|
return BlockNumber((await this.getLastBlockNumber()) + 1);
|
|
151
150
|
}
|
|
152
151
|
|
|
153
|
-
|
|
152
|
+
getNextBlockTimestamp(): Promise<bigint> {
|
|
154
153
|
return Promise.resolve(this.nextBlockTimestamp);
|
|
155
154
|
}
|
|
156
155
|
|
|
157
|
-
async
|
|
156
|
+
async getLastBlockTimestamp() {
|
|
158
157
|
return (await this.stateMachine.node.getBlockHeader('latest'))!.globalVariables.timestamp;
|
|
159
158
|
}
|
|
160
159
|
|
|
161
|
-
async
|
|
160
|
+
async getLastTxEffects() {
|
|
162
161
|
const latestBlockNumber = await this.stateMachine.archiver.getBlockNumber();
|
|
163
162
|
const block = await this.stateMachine.archiver.getBlock(latestBlockNumber);
|
|
164
163
|
|
|
@@ -172,7 +171,26 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
172
171
|
return { txHash: txEffects.txHash, noteHashes: txEffects.noteHashes, nullifiers: txEffects.nullifiers };
|
|
173
172
|
}
|
|
174
173
|
|
|
175
|
-
async
|
|
174
|
+
async syncContractNonOracleMethod(contractAddress: AztecAddress, scope: AztecAddress, jobId: string) {
|
|
175
|
+
if (contractAddress.equals(DEFAULT_ADDRESS)) {
|
|
176
|
+
this.logger.debug(`Skipping sync in getPrivateEvents because the events correspond to the default address.`);
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
181
|
+
await this.stateMachine.contractSyncService.ensureContractSynced(
|
|
182
|
+
contractAddress,
|
|
183
|
+
null,
|
|
184
|
+
async (call, execScopes) => {
|
|
185
|
+
await this.executeUtilityCall(call, execScopes, jobId);
|
|
186
|
+
},
|
|
187
|
+
blockHeader,
|
|
188
|
+
jobId,
|
|
189
|
+
[scope],
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
async getPrivateEvents(selector: EventSelector, contractAddress: AztecAddress, scope: AztecAddress) {
|
|
176
194
|
return (
|
|
177
195
|
await this.privateEventStore.getPrivateEvents(selector, {
|
|
178
196
|
contractAddress,
|
|
@@ -183,7 +201,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
183
201
|
).map(e => e.packedEvent);
|
|
184
202
|
}
|
|
185
203
|
|
|
186
|
-
async
|
|
204
|
+
async advanceBlocksBy(blocks: number) {
|
|
187
205
|
this.logger.debug(`time traveling ${blocks} blocks`);
|
|
188
206
|
|
|
189
207
|
for (let i = 0; i < blocks; i++) {
|
|
@@ -191,12 +209,12 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
191
209
|
}
|
|
192
210
|
}
|
|
193
211
|
|
|
194
|
-
|
|
212
|
+
advanceTimestampBy(duration: UInt64) {
|
|
195
213
|
this.logger.debug(`time traveling ${duration} seconds`);
|
|
196
214
|
this.nextBlockTimestamp += duration;
|
|
197
215
|
}
|
|
198
216
|
|
|
199
|
-
async
|
|
217
|
+
async deploy(artifact: ContractArtifact, instance: ContractInstanceWithAddress, secret: Fr) {
|
|
200
218
|
// Emit deployment nullifier
|
|
201
219
|
await this.mineBlock({
|
|
202
220
|
nullifiers: [
|
|
@@ -208,20 +226,20 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
208
226
|
});
|
|
209
227
|
|
|
210
228
|
if (!secret.equals(Fr.ZERO)) {
|
|
211
|
-
await this.
|
|
229
|
+
await this.addAccount(artifact, instance, secret);
|
|
212
230
|
} else {
|
|
213
231
|
await this.contractStore.addContractInstance(instance);
|
|
214
|
-
await this.contractStore.addContractArtifact(
|
|
232
|
+
await this.contractStore.addContractArtifact(artifact);
|
|
215
233
|
this.logger.debug(`Deployed ${artifact.name} at ${instance.address}`);
|
|
216
234
|
}
|
|
217
235
|
}
|
|
218
236
|
|
|
219
|
-
async
|
|
237
|
+
async addAccount(artifact: ContractArtifact, instance: ContractInstanceWithAddress, secret: Fr) {
|
|
220
238
|
const partialAddress = await computePartialAddress(instance);
|
|
221
239
|
|
|
222
240
|
this.logger.debug(`Deployed ${artifact.name} at ${instance.address}`);
|
|
223
241
|
await this.contractStore.addContractInstance(instance);
|
|
224
|
-
await this.contractStore.addContractArtifact(
|
|
242
|
+
await this.contractStore.addContractArtifact(artifact);
|
|
225
243
|
|
|
226
244
|
const completeAddress = await this.keyStore.addAccount(secret, partialAddress);
|
|
227
245
|
await this.accountStore.setAccount(completeAddress.address, completeAddress);
|
|
@@ -231,7 +249,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
231
249
|
return completeAddress;
|
|
232
250
|
}
|
|
233
251
|
|
|
234
|
-
async
|
|
252
|
+
async createAccount(secret: Fr) {
|
|
235
253
|
// This is a foot gun !
|
|
236
254
|
const completeAddress = await this.keyStore.addAccount(secret, secret);
|
|
237
255
|
await this.accountStore.setAccount(completeAddress.address, completeAddress);
|
|
@@ -241,7 +259,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
241
259
|
return completeAddress;
|
|
242
260
|
}
|
|
243
261
|
|
|
244
|
-
async
|
|
262
|
+
async addAuthWitness(address: AztecAddress, messageHash: Fr) {
|
|
245
263
|
const account = await this.accountStore.getAccount(address);
|
|
246
264
|
const privateKey = await this.keyStore.getMasterSecretKey(account.publicKeys.masterIncomingViewingPublicKey);
|
|
247
265
|
|
|
@@ -254,7 +272,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
254
272
|
}
|
|
255
273
|
|
|
256
274
|
async mineBlock(options: { nullifiers?: Fr[] } = {}) {
|
|
257
|
-
const blockNumber = await this.
|
|
275
|
+
const blockNumber = await this.getNextBlockNumber();
|
|
258
276
|
|
|
259
277
|
const txEffect = TxEffect.empty();
|
|
260
278
|
txEffect.nullifiers = [getSingleTxBlockRequestHash(blockNumber), ...(options.nullifiers ?? [])];
|
|
@@ -278,13 +296,14 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
278
296
|
await this.stateMachine.handleL2Block(block);
|
|
279
297
|
}
|
|
280
298
|
|
|
281
|
-
async
|
|
299
|
+
async privateCallNewFlow(
|
|
282
300
|
from: AztecAddress,
|
|
283
301
|
targetContractAddress: AztecAddress = AztecAddress.zero(),
|
|
284
302
|
functionSelector: FunctionSelector = FunctionSelector.empty(),
|
|
285
303
|
args: Fr[],
|
|
286
304
|
argsHash: Fr = Fr.zero(),
|
|
287
305
|
isStaticCall: boolean = false,
|
|
306
|
+
jobId: string,
|
|
288
307
|
) {
|
|
289
308
|
this.logger.verbose(
|
|
290
309
|
`Executing external function ${await this.contractStore.getDebugFunctionName(targetContractAddress, functionSelector)}@${targetContractAddress} isStaticCall=${isStaticCall}`,
|
|
@@ -304,7 +323,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
304
323
|
|
|
305
324
|
// Sync notes before executing private function to discover notes from previous transactions
|
|
306
325
|
const utilityExecutor = async (call: FunctionCall, execScopes: AccessScopes) => {
|
|
307
|
-
await this.executeUtilityCall(call, execScopes);
|
|
326
|
+
await this.executeUtilityCall(call, execScopes, jobId);
|
|
308
327
|
};
|
|
309
328
|
|
|
310
329
|
const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
@@ -313,11 +332,11 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
313
332
|
functionSelector,
|
|
314
333
|
utilityExecutor,
|
|
315
334
|
blockHeader,
|
|
316
|
-
|
|
335
|
+
jobId,
|
|
317
336
|
effectiveScopes,
|
|
318
337
|
);
|
|
319
338
|
|
|
320
|
-
const blockNumber = await this.
|
|
339
|
+
const blockNumber = await this.getNextBlockNumber();
|
|
321
340
|
|
|
322
341
|
const callContext = new CallContext(from, targetContractAddress, functionSelector, isStaticCall);
|
|
323
342
|
|
|
@@ -360,7 +379,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
360
379
|
capsuleStore: this.capsuleStore,
|
|
361
380
|
privateEventStore: this.privateEventStore,
|
|
362
381
|
contractSyncService: this.stateMachine.contractSyncService,
|
|
363
|
-
jobId
|
|
382
|
+
jobId,
|
|
364
383
|
totalPublicCalldataCount: 0,
|
|
365
384
|
sideEffectCounter: minRevertibleSideEffectCounter,
|
|
366
385
|
scopes: effectiveScopes,
|
|
@@ -368,6 +387,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
368
387
|
// contract would perform, including setting senderForTags.
|
|
369
388
|
senderForTags: from,
|
|
370
389
|
simulator,
|
|
390
|
+
messageContextService: this.stateMachine.messageContextService,
|
|
371
391
|
});
|
|
372
392
|
|
|
373
393
|
// Note: This is a slight modification of simulator.run without any of the checks. Maybe we should modify simulator.run with a boolean value to skip checks.
|
|
@@ -390,7 +410,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
390
410
|
);
|
|
391
411
|
const publicFunctionsCalldata = await Promise.all(
|
|
392
412
|
publicCallRequests.map(async r => {
|
|
393
|
-
const calldata = await privateExecutionOracle.
|
|
413
|
+
const calldata = await privateExecutionOracle.loadFromExecutionCache(r.calldataHash);
|
|
394
414
|
return new HashedValues(calldata, r.calldataHash);
|
|
395
415
|
}),
|
|
396
416
|
);
|
|
@@ -504,7 +524,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
504
524
|
return executionResult.returnValues ?? [];
|
|
505
525
|
}
|
|
506
526
|
|
|
507
|
-
async
|
|
527
|
+
async publicCallNewFlow(
|
|
508
528
|
from: AztecAddress,
|
|
509
529
|
targetContractAddress: AztecAddress,
|
|
510
530
|
calldata: Fr[],
|
|
@@ -514,7 +534,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
514
534
|
`Executing public function ${await this.contractStore.getDebugFunctionName(targetContractAddress, FunctionSelector.fromField(calldata[0]))}@${targetContractAddress} isStaticCall=${isStaticCall}`,
|
|
515
535
|
);
|
|
516
536
|
|
|
517
|
-
const blockNumber = await this.
|
|
537
|
+
const blockNumber = await this.getNextBlockNumber();
|
|
518
538
|
|
|
519
539
|
const gasLimits = new Gas(DEFAULT_DA_GAS_LIMIT, DEFAULT_L2_GAS_LIMIT);
|
|
520
540
|
|
|
@@ -591,7 +611,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
591
611
|
constantData,
|
|
592
612
|
/*gasUsed=*/ new Gas(0, 0),
|
|
593
613
|
/*feePayer=*/ AztecAddress.zero(),
|
|
594
|
-
/*
|
|
614
|
+
/*expirationTimestamp=*/ 0n,
|
|
595
615
|
inputsForPublic,
|
|
596
616
|
undefined,
|
|
597
617
|
);
|
|
@@ -659,10 +679,11 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
659
679
|
return returnValues ?? [];
|
|
660
680
|
}
|
|
661
681
|
|
|
662
|
-
async
|
|
682
|
+
async executeUtilityFunction(
|
|
663
683
|
targetContractAddress: AztecAddress,
|
|
664
684
|
functionSelector: FunctionSelector,
|
|
665
685
|
args: Fr[],
|
|
686
|
+
jobId: string,
|
|
666
687
|
) {
|
|
667
688
|
const artifact = await this.contractStore.getFunctionArtifact(targetContractAddress, functionSelector);
|
|
668
689
|
if (!artifact) {
|
|
@@ -675,10 +696,10 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
675
696
|
targetContractAddress,
|
|
676
697
|
functionSelector,
|
|
677
698
|
async (call, execScopes) => {
|
|
678
|
-
await this.executeUtilityCall(call, execScopes);
|
|
699
|
+
await this.executeUtilityCall(call, execScopes, jobId);
|
|
679
700
|
},
|
|
680
701
|
blockHeader,
|
|
681
|
-
|
|
702
|
+
jobId,
|
|
682
703
|
'ALL_SCOPES',
|
|
683
704
|
);
|
|
684
705
|
|
|
@@ -693,10 +714,10 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
693
714
|
returnTypes: [],
|
|
694
715
|
});
|
|
695
716
|
|
|
696
|
-
return this.executeUtilityCall(call, 'ALL_SCOPES');
|
|
717
|
+
return this.executeUtilityCall(call, 'ALL_SCOPES', jobId);
|
|
697
718
|
}
|
|
698
719
|
|
|
699
|
-
private async executeUtilityCall(call: FunctionCall, scopes: AccessScopes): Promise<Fr[]> {
|
|
720
|
+
private async executeUtilityCall(call: FunctionCall, scopes: AccessScopes, jobId: string): Promise<Fr[]> {
|
|
700
721
|
const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
|
|
701
722
|
if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
|
|
702
723
|
throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
|
|
@@ -723,7 +744,8 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
723
744
|
senderAddressBookStore: this.senderAddressBookStore,
|
|
724
745
|
capsuleStore: this.capsuleStore,
|
|
725
746
|
privateEventStore: this.privateEventStore,
|
|
726
|
-
|
|
747
|
+
messageContextService: this.stateMachine.messageContextService,
|
|
748
|
+
jobId,
|
|
727
749
|
scopes,
|
|
728
750
|
});
|
|
729
751
|
const acirExecutionResult = await new WASMSimulator()
|
|
@@ -741,10 +763,10 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
741
763
|
);
|
|
742
764
|
});
|
|
743
765
|
|
|
744
|
-
this.logger.verbose(`Utility
|
|
766
|
+
this.logger.verbose(`Utility execution for ${call.to}.${call.selector} completed`);
|
|
745
767
|
return witnessMapToFields(acirExecutionResult.returnWitness);
|
|
746
768
|
} catch (err) {
|
|
747
|
-
throw createSimulationError(err instanceof Error ? err : new Error('Unknown error during utility
|
|
769
|
+
throw createSimulationError(err instanceof Error ? err : new Error('Unknown error during utility execution'));
|
|
748
770
|
}
|
|
749
771
|
}
|
|
750
772
|
|