@aztec/txe 0.0.1-commit.dbf9cec → 0.0.1-commit.e0f15ab9b
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 +8 -6
- package/dest/oracle/interfaces.d.ts +28 -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 -21
- package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_top_level_context.js +31 -26
- package/dest/rpc_translator.d.ts +87 -82
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +261 -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/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 +17 -3
- package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
- package/dest/state_machine/mock_epoch_cache.js +32 -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 +4 -3
- package/dest/txe_session.d.ts.map +1 -1
- package/dest/txe_session.js +18 -9
- package/dest/util/encoding.d.ts +69 -1
- package/dest/util/encoding.d.ts.map +1 -1
- package/dest/util/txe_public_contract_data_source.d.ts +1 -1
- package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
- package/dest/util/txe_public_contract_data_source.js +1 -3
- package/package.json +15 -15
- package/src/index.ts +8 -5
- package/src/oracle/interfaces.ts +27 -31
- package/src/oracle/txe_oracle_public_context.ts +12 -12
- package/src/oracle/txe_oracle_top_level_context.ts +29 -24
- package/src/rpc_translator.ts +290 -173
- package/src/state_machine/archiver.ts +5 -5
- package/src/state_machine/index.ts +6 -1
- package/src/state_machine/mock_epoch_cache.ts +42 -3
- package/src/state_machine/synchronizer.ts +4 -4
- package/src/txe_session.ts +17 -4
- package/src/util/txe_public_contract_data_source.ts +0 -2
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
AddressStore,
|
|
18
18
|
CapsuleStore,
|
|
19
19
|
type ContractStore,
|
|
20
|
+
type ContractSyncService,
|
|
20
21
|
NoteStore,
|
|
21
22
|
ORACLE_VERSION,
|
|
22
23
|
PrivateEventStore,
|
|
@@ -111,12 +112,13 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
111
112
|
private version: Fr,
|
|
112
113
|
private chainId: Fr,
|
|
113
114
|
private authwits: Map<string, AuthWitness>,
|
|
115
|
+
private readonly contractSyncService: ContractSyncService,
|
|
114
116
|
) {
|
|
115
117
|
this.logger = createLogger('txe:top_level_context');
|
|
116
118
|
this.logger.debug('Entering Top Level Context');
|
|
117
119
|
}
|
|
118
120
|
|
|
119
|
-
|
|
121
|
+
assertCompatibleOracleVersion(version: number): void {
|
|
120
122
|
if (version !== ORACLE_VERSION) {
|
|
121
123
|
throw new Error(
|
|
122
124
|
`Incompatible oracle version. TXE is using version '${ORACLE_VERSION}', but got a request for '${version}'.`,
|
|
@@ -126,12 +128,12 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
126
128
|
|
|
127
129
|
// This is typically only invoked in private contexts, but it is convenient to also have it in top-level for testing
|
|
128
130
|
// setup.
|
|
129
|
-
|
|
131
|
+
getRandomField(): Fr {
|
|
130
132
|
return Fr.random();
|
|
131
133
|
}
|
|
132
134
|
|
|
133
135
|
// We instruct users to debug contracts via this oracle, so it makes sense that they'd expect it to also work in tests
|
|
134
|
-
|
|
136
|
+
log(level: number, message: string, fields: Fr[]): Promise<void> {
|
|
135
137
|
if (!LogLevels[level]) {
|
|
136
138
|
throw new Error(`Invalid log level: ${level}`);
|
|
137
139
|
}
|
|
@@ -141,23 +143,23 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
141
143
|
return Promise.resolve();
|
|
142
144
|
}
|
|
143
145
|
|
|
144
|
-
|
|
146
|
+
getDefaultAddress(): AztecAddress {
|
|
145
147
|
return DEFAULT_ADDRESS;
|
|
146
148
|
}
|
|
147
149
|
|
|
148
|
-
async
|
|
150
|
+
async getNextBlockNumber(): Promise<BlockNumber> {
|
|
149
151
|
return BlockNumber((await this.getLastBlockNumber()) + 1);
|
|
150
152
|
}
|
|
151
153
|
|
|
152
|
-
|
|
154
|
+
getNextBlockTimestamp(): Promise<bigint> {
|
|
153
155
|
return Promise.resolve(this.nextBlockTimestamp);
|
|
154
156
|
}
|
|
155
157
|
|
|
156
|
-
async
|
|
158
|
+
async getLastBlockTimestamp() {
|
|
157
159
|
return (await this.stateMachine.node.getBlockHeader('latest'))!.globalVariables.timestamp;
|
|
158
160
|
}
|
|
159
161
|
|
|
160
|
-
async
|
|
162
|
+
async getLastTxEffects() {
|
|
161
163
|
const latestBlockNumber = await this.stateMachine.archiver.getBlockNumber();
|
|
162
164
|
const block = await this.stateMachine.archiver.getBlock(latestBlockNumber);
|
|
163
165
|
|
|
@@ -173,7 +175,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
173
175
|
|
|
174
176
|
async syncContractNonOracleMethod(contractAddress: AztecAddress, scope: AztecAddress, jobId: string) {
|
|
175
177
|
if (contractAddress.equals(DEFAULT_ADDRESS)) {
|
|
176
|
-
this.logger.debug(`Skipping sync in
|
|
178
|
+
this.logger.debug(`Skipping sync in getPrivateEvents because the events correspond to the default address.`);
|
|
177
179
|
return;
|
|
178
180
|
}
|
|
179
181
|
|
|
@@ -190,7 +192,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
190
192
|
);
|
|
191
193
|
}
|
|
192
194
|
|
|
193
|
-
async
|
|
195
|
+
async getPrivateEvents(selector: EventSelector, contractAddress: AztecAddress, scope: AztecAddress) {
|
|
194
196
|
return (
|
|
195
197
|
await this.privateEventStore.getPrivateEvents(selector, {
|
|
196
198
|
contractAddress,
|
|
@@ -201,7 +203,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
201
203
|
).map(e => e.packedEvent);
|
|
202
204
|
}
|
|
203
205
|
|
|
204
|
-
async
|
|
206
|
+
async advanceBlocksBy(blocks: number) {
|
|
205
207
|
this.logger.debug(`time traveling ${blocks} blocks`);
|
|
206
208
|
|
|
207
209
|
for (let i = 0; i < blocks; i++) {
|
|
@@ -209,12 +211,12 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
209
211
|
}
|
|
210
212
|
}
|
|
211
213
|
|
|
212
|
-
|
|
214
|
+
advanceTimestampBy(duration: UInt64) {
|
|
213
215
|
this.logger.debug(`time traveling ${duration} seconds`);
|
|
214
216
|
this.nextBlockTimestamp += duration;
|
|
215
217
|
}
|
|
216
218
|
|
|
217
|
-
async
|
|
219
|
+
async deploy(artifact: ContractArtifact, instance: ContractInstanceWithAddress, secret: Fr) {
|
|
218
220
|
// Emit deployment nullifier
|
|
219
221
|
await this.mineBlock({
|
|
220
222
|
nullifiers: [
|
|
@@ -226,7 +228,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
226
228
|
});
|
|
227
229
|
|
|
228
230
|
if (!secret.equals(Fr.ZERO)) {
|
|
229
|
-
await this.
|
|
231
|
+
await this.addAccount(artifact, instance, secret);
|
|
230
232
|
} else {
|
|
231
233
|
await this.contractStore.addContractInstance(instance);
|
|
232
234
|
await this.contractStore.addContractArtifact(artifact);
|
|
@@ -234,7 +236,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
234
236
|
}
|
|
235
237
|
}
|
|
236
238
|
|
|
237
|
-
async
|
|
239
|
+
async addAccount(artifact: ContractArtifact, instance: ContractInstanceWithAddress, secret: Fr) {
|
|
238
240
|
const partialAddress = await computePartialAddress(instance);
|
|
239
241
|
|
|
240
242
|
this.logger.debug(`Deployed ${artifact.name} at ${instance.address}`);
|
|
@@ -249,7 +251,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
249
251
|
return completeAddress;
|
|
250
252
|
}
|
|
251
253
|
|
|
252
|
-
async
|
|
254
|
+
async createAccount(secret: Fr) {
|
|
253
255
|
// This is a foot gun !
|
|
254
256
|
const completeAddress = await this.keyStore.addAccount(secret, secret);
|
|
255
257
|
await this.accountStore.setAccount(completeAddress.address, completeAddress);
|
|
@@ -259,7 +261,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
259
261
|
return completeAddress;
|
|
260
262
|
}
|
|
261
263
|
|
|
262
|
-
async
|
|
264
|
+
async addAuthWitness(address: AztecAddress, messageHash: Fr) {
|
|
263
265
|
const account = await this.accountStore.getAccount(address);
|
|
264
266
|
const privateKey = await this.keyStore.getMasterSecretKey(account.publicKeys.masterIncomingViewingPublicKey);
|
|
265
267
|
|
|
@@ -272,7 +274,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
272
274
|
}
|
|
273
275
|
|
|
274
276
|
async mineBlock(options: { nullifiers?: Fr[] } = {}) {
|
|
275
|
-
const blockNumber = await this.
|
|
277
|
+
const blockNumber = await this.getNextBlockNumber();
|
|
276
278
|
|
|
277
279
|
const txEffect = TxEffect.empty();
|
|
278
280
|
txEffect.nullifiers = [getSingleTxBlockRequestHash(blockNumber), ...(options.nullifiers ?? [])];
|
|
@@ -296,7 +298,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
296
298
|
await this.stateMachine.handleL2Block(block);
|
|
297
299
|
}
|
|
298
300
|
|
|
299
|
-
async
|
|
301
|
+
async privateCallNewFlow(
|
|
300
302
|
from: AztecAddress,
|
|
301
303
|
targetContractAddress: AztecAddress = AztecAddress.zero(),
|
|
302
304
|
functionSelector: FunctionSelector = FunctionSelector.empty(),
|
|
@@ -336,7 +338,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
336
338
|
effectiveScopes,
|
|
337
339
|
);
|
|
338
340
|
|
|
339
|
-
const blockNumber = await this.
|
|
341
|
+
const blockNumber = await this.getNextBlockNumber();
|
|
340
342
|
|
|
341
343
|
const callContext = new CallContext(from, targetContractAddress, functionSelector, isStaticCall);
|
|
342
344
|
|
|
@@ -387,6 +389,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
387
389
|
// contract would perform, including setting senderForTags.
|
|
388
390
|
senderForTags: from,
|
|
389
391
|
simulator,
|
|
392
|
+
messageContextService: this.stateMachine.messageContextService,
|
|
390
393
|
});
|
|
391
394
|
|
|
392
395
|
// 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.
|
|
@@ -409,7 +412,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
409
412
|
);
|
|
410
413
|
const publicFunctionsCalldata = await Promise.all(
|
|
411
414
|
publicCallRequests.map(async r => {
|
|
412
|
-
const calldata = await privateExecutionOracle.
|
|
415
|
+
const calldata = await privateExecutionOracle.loadFromExecutionCache(r.calldataHash);
|
|
413
416
|
return new HashedValues(calldata, r.calldataHash);
|
|
414
417
|
}),
|
|
415
418
|
);
|
|
@@ -523,7 +526,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
523
526
|
return executionResult.returnValues ?? [];
|
|
524
527
|
}
|
|
525
528
|
|
|
526
|
-
async
|
|
529
|
+
async publicCallNewFlow(
|
|
527
530
|
from: AztecAddress,
|
|
528
531
|
targetContractAddress: AztecAddress,
|
|
529
532
|
calldata: Fr[],
|
|
@@ -533,7 +536,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
533
536
|
`Executing public function ${await this.contractStore.getDebugFunctionName(targetContractAddress, FunctionSelector.fromField(calldata[0]))}@${targetContractAddress} isStaticCall=${isStaticCall}`,
|
|
534
537
|
);
|
|
535
538
|
|
|
536
|
-
const blockNumber = await this.
|
|
539
|
+
const blockNumber = await this.getNextBlockNumber();
|
|
537
540
|
|
|
538
541
|
const gasLimits = new Gas(DEFAULT_DA_GAS_LIMIT, DEFAULT_L2_GAS_LIMIT);
|
|
539
542
|
|
|
@@ -678,7 +681,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
678
681
|
return returnValues ?? [];
|
|
679
682
|
}
|
|
680
683
|
|
|
681
|
-
async
|
|
684
|
+
async executeUtilityFunction(
|
|
682
685
|
targetContractAddress: AztecAddress,
|
|
683
686
|
functionSelector: FunctionSelector,
|
|
684
687
|
args: Fr[],
|
|
@@ -743,6 +746,8 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
743
746
|
senderAddressBookStore: this.senderAddressBookStore,
|
|
744
747
|
capsuleStore: this.capsuleStore,
|
|
745
748
|
privateEventStore: this.privateEventStore,
|
|
749
|
+
messageContextService: this.stateMachine.messageContextService,
|
|
750
|
+
contractSyncService: this.contractSyncService,
|
|
746
751
|
jobId,
|
|
747
752
|
scopes,
|
|
748
753
|
});
|