@aztec/txe 0.0.1-commit.54489865 → 0.0.1-commit.5914bae
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 +28 -23
- package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_top_level_context.js +144 -58
- package/dest/rpc_translator.d.ts +121 -83
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +399 -164
- 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 +7 -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 +7 -5
- package/dest/state_machine/index.d.ts.map +1 -1
- package/dest/state_machine/index.js +19 -10
- package/dest/state_machine/mock_epoch_cache.d.ts +3 -1
- package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
- package/dest/state_machine/mock_epoch_cache.js +4 -0
- 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 +97 -26
- package/dest/util/encoding.d.ts +40 -41
- package/dest/util/encoding.d.ts.map +1 -1
- 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/dest/utils/block_creation.d.ts +1 -1
- package/dest/utils/block_creation.d.ts.map +1 -1
- package/dest/utils/block_creation.js +3 -1
- 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 +167 -110
- package/src/rpc_translator.ts +463 -181
- package/src/state_machine/archiver.ts +7 -5
- package/src/state_machine/dummy_p2p_client.ts +40 -22
- package/src/state_machine/index.ts +29 -9
- package/src/state_machine/mock_epoch_cache.ts +5 -0
- package/src/state_machine/synchronizer.ts +4 -4
- package/src/txe_session.ts +109 -85
- package/src/util/txe_public_contract_data_source.ts +10 -36
- package/src/utils/block_creation.ts +3 -1
- 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,9 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS,
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
DEFAULT_TEARDOWN_DA_GAS_LIMIT,
|
|
6
|
-
DEFAULT_TEARDOWN_L2_GAS_LIMIT,
|
|
3
|
+
MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT,
|
|
4
|
+
MAX_PROCESSABLE_L2_GAS,
|
|
7
5
|
NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP,
|
|
8
6
|
} from '@aztec/constants';
|
|
9
7
|
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
@@ -14,15 +12,17 @@ import { TestDateProvider } from '@aztec/foundation/timer';
|
|
|
14
12
|
import type { KeyStore } from '@aztec/key-store';
|
|
15
13
|
import {
|
|
16
14
|
AddressStore,
|
|
15
|
+
CapsuleService,
|
|
17
16
|
CapsuleStore,
|
|
17
|
+
type ContractStore,
|
|
18
|
+
type ContractSyncService,
|
|
18
19
|
NoteStore,
|
|
19
|
-
|
|
20
|
+
ORACLE_VERSION_MAJOR,
|
|
20
21
|
PrivateEventStore,
|
|
21
22
|
RecipientTaggingStore,
|
|
22
23
|
SenderAddressBookStore,
|
|
23
24
|
SenderTaggingStore,
|
|
24
25
|
enrichPublicSimulationError,
|
|
25
|
-
syncState,
|
|
26
26
|
} from '@aztec/pxe/server';
|
|
27
27
|
import {
|
|
28
28
|
ExecutionNoteCache,
|
|
@@ -55,7 +55,13 @@ import { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
|
55
55
|
import { PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
56
56
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
57
57
|
import { type ContractInstanceWithAddress, computePartialAddress } from '@aztec/stdlib/contract';
|
|
58
|
-
import {
|
|
58
|
+
import {
|
|
59
|
+
FALLBACK_TEARDOWN_DA_GAS_LIMIT,
|
|
60
|
+
FALLBACK_TEARDOWN_L2_GAS_LIMIT,
|
|
61
|
+
Gas,
|
|
62
|
+
GasFees,
|
|
63
|
+
GasSettings,
|
|
64
|
+
} from '@aztec/stdlib/gas';
|
|
59
65
|
import { computeCalldataHash, computeProtocolNullifier, siloNullifier } from '@aztec/stdlib/hash';
|
|
60
66
|
import {
|
|
61
67
|
PartialPrivateTailPublicInputsForPublic,
|
|
@@ -84,7 +90,6 @@ import { ForkCheckpoint } from '@aztec/world-state';
|
|
|
84
90
|
import { DEFAULT_ADDRESS } from '../constants.js';
|
|
85
91
|
import type { TXEStateMachine } from '../state_machine/index.js';
|
|
86
92
|
import type { TXEAccountStore } from '../util/txe_account_store.js';
|
|
87
|
-
import type { TXEContractStore } from '../util/txe_contract_store.js';
|
|
88
93
|
import { TXEPublicContractDataSource } from '../util/txe_public_contract_data_source.js';
|
|
89
94
|
import { getSingleTxBlockRequestHash, insertTxEffectIntoWorldTrees, makeTXEBlock } from '../utils/block_creation.js';
|
|
90
95
|
import type { ITxeExecutionOracle } from './interfaces.js';
|
|
@@ -97,7 +102,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
97
102
|
|
|
98
103
|
constructor(
|
|
99
104
|
private stateMachine: TXEStateMachine,
|
|
100
|
-
private contractStore:
|
|
105
|
+
private contractStore: ContractStore,
|
|
101
106
|
private noteStore: NoteStore,
|
|
102
107
|
private keyStore: KeyStore,
|
|
103
108
|
private addressStore: AddressStore,
|
|
@@ -107,57 +112,70 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
107
112
|
private senderAddressBookStore: SenderAddressBookStore,
|
|
108
113
|
private capsuleStore: CapsuleStore,
|
|
109
114
|
private privateEventStore: PrivateEventStore,
|
|
110
|
-
private jobId: string,
|
|
111
115
|
private nextBlockTimestamp: bigint,
|
|
112
116
|
private version: Fr,
|
|
113
117
|
private chainId: Fr,
|
|
114
118
|
private authwits: Map<string, AuthWitness>,
|
|
119
|
+
private readonly contractSyncService: ContractSyncService,
|
|
115
120
|
) {
|
|
116
121
|
this.logger = createLogger('txe:top_level_context');
|
|
117
122
|
this.logger.debug('Entering Top Level Context');
|
|
118
123
|
}
|
|
119
124
|
|
|
120
|
-
|
|
121
|
-
|
|
125
|
+
private contractOracleVersion: { major: number; minor: number } | undefined;
|
|
126
|
+
|
|
127
|
+
assertCompatibleOracleVersion(major: number, minor: number): void {
|
|
128
|
+
if (major !== ORACLE_VERSION_MAJOR) {
|
|
129
|
+
const hint =
|
|
130
|
+
major > ORACLE_VERSION_MAJOR
|
|
131
|
+
? 'The contract was compiled with a newer version of Aztec.nr than this aztec cli version supports. Upgrade your aztec cli version to a compatible version.'
|
|
132
|
+
: 'The contract was compiled with an older version of Aztec.nr than this aztec cli version supports. Recompile the contract with a compatible version of Aztec.nr.';
|
|
122
133
|
throw new Error(
|
|
123
|
-
`Incompatible
|
|
134
|
+
`Incompatible aztec cli version: ${hint} See https://docs.aztec.network/errors/8 (expected oracle major version ${ORACLE_VERSION_MAJOR}, got ${major})`,
|
|
124
135
|
);
|
|
125
136
|
}
|
|
137
|
+
this.contractOracleVersion = { major, minor };
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Prefixed with "nonOracleFunction" as it is not used as an oracle handler.
|
|
141
|
+
nonOracleFunctionGetContractOracleVersion(): { major: number; minor: number } | undefined {
|
|
142
|
+
return this.contractOracleVersion;
|
|
126
143
|
}
|
|
127
144
|
|
|
128
145
|
// This is typically only invoked in private contexts, but it is convenient to also have it in top-level for testing
|
|
129
146
|
// setup.
|
|
130
|
-
|
|
147
|
+
getRandomField(): Fr {
|
|
131
148
|
return Fr.random();
|
|
132
149
|
}
|
|
133
150
|
|
|
134
151
|
// We instruct users to debug contracts via this oracle, so it makes sense that they'd expect it to also work in tests
|
|
135
|
-
|
|
152
|
+
log(level: number, message: string, fields: Fr[]): Promise<void> {
|
|
136
153
|
if (!LogLevels[level]) {
|
|
137
|
-
throw new Error(`Invalid
|
|
154
|
+
throw new Error(`Invalid log level: ${level}`);
|
|
138
155
|
}
|
|
139
156
|
const levelName = LogLevels[level];
|
|
140
157
|
|
|
141
158
|
this.logger[levelName](`${applyStringFormatting(message, fields)}`, { module: `${this.logger.module}:debug_log` });
|
|
159
|
+
return Promise.resolve();
|
|
142
160
|
}
|
|
143
161
|
|
|
144
|
-
|
|
162
|
+
getDefaultAddress(): AztecAddress {
|
|
145
163
|
return DEFAULT_ADDRESS;
|
|
146
164
|
}
|
|
147
165
|
|
|
148
|
-
async
|
|
166
|
+
async getNextBlockNumber(): Promise<BlockNumber> {
|
|
149
167
|
return BlockNumber((await this.getLastBlockNumber()) + 1);
|
|
150
168
|
}
|
|
151
169
|
|
|
152
|
-
|
|
170
|
+
getNextBlockTimestamp(): Promise<bigint> {
|
|
153
171
|
return Promise.resolve(this.nextBlockTimestamp);
|
|
154
172
|
}
|
|
155
173
|
|
|
156
|
-
async
|
|
174
|
+
async getLastBlockTimestamp() {
|
|
157
175
|
return (await this.stateMachine.node.getBlockHeader('latest'))!.globalVariables.timestamp;
|
|
158
176
|
}
|
|
159
177
|
|
|
160
|
-
async
|
|
178
|
+
async getLastTxEffects() {
|
|
161
179
|
const latestBlockNumber = await this.stateMachine.archiver.getBlockNumber();
|
|
162
180
|
const block = await this.stateMachine.archiver.getBlock(latestBlockNumber);
|
|
163
181
|
|
|
@@ -171,7 +189,26 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
171
189
|
return { txHash: txEffects.txHash, noteHashes: txEffects.noteHashes, nullifiers: txEffects.nullifiers };
|
|
172
190
|
}
|
|
173
191
|
|
|
174
|
-
async
|
|
192
|
+
async syncContractNonOracleMethod(contractAddress: AztecAddress, scope: AztecAddress, jobId: string) {
|
|
193
|
+
if (contractAddress.equals(DEFAULT_ADDRESS)) {
|
|
194
|
+
this.logger.debug(`Skipping sync in getPrivateEvents because the events correspond to the default address.`);
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
199
|
+
await this.stateMachine.contractSyncService.ensureContractSynced(
|
|
200
|
+
contractAddress,
|
|
201
|
+
null,
|
|
202
|
+
async (call, execScopes) => {
|
|
203
|
+
await this.executeUtilityCall(call, execScopes, jobId);
|
|
204
|
+
},
|
|
205
|
+
blockHeader,
|
|
206
|
+
jobId,
|
|
207
|
+
[scope],
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
async getPrivateEvents(selector: EventSelector, contractAddress: AztecAddress, scope: AztecAddress) {
|
|
175
212
|
return (
|
|
176
213
|
await this.privateEventStore.getPrivateEvents(selector, {
|
|
177
214
|
contractAddress,
|
|
@@ -182,7 +219,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
182
219
|
).map(e => e.packedEvent);
|
|
183
220
|
}
|
|
184
221
|
|
|
185
|
-
async
|
|
222
|
+
async advanceBlocksBy(blocks: number) {
|
|
186
223
|
this.logger.debug(`time traveling ${blocks} blocks`);
|
|
187
224
|
|
|
188
225
|
for (let i = 0; i < blocks; i++) {
|
|
@@ -190,12 +227,12 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
190
227
|
}
|
|
191
228
|
}
|
|
192
229
|
|
|
193
|
-
|
|
230
|
+
advanceTimestampBy(duration: UInt64) {
|
|
194
231
|
this.logger.debug(`time traveling ${duration} seconds`);
|
|
195
232
|
this.nextBlockTimestamp += duration;
|
|
196
233
|
}
|
|
197
234
|
|
|
198
|
-
async
|
|
235
|
+
async deploy(artifact: ContractArtifact, instance: ContractInstanceWithAddress, secret: Fr) {
|
|
199
236
|
// Emit deployment nullifier
|
|
200
237
|
await this.mineBlock({
|
|
201
238
|
nullifiers: [
|
|
@@ -207,20 +244,20 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
207
244
|
});
|
|
208
245
|
|
|
209
246
|
if (!secret.equals(Fr.ZERO)) {
|
|
210
|
-
await this.
|
|
247
|
+
await this.addAccount(artifact, instance, secret);
|
|
211
248
|
} else {
|
|
212
249
|
await this.contractStore.addContractInstance(instance);
|
|
213
|
-
await this.contractStore.addContractArtifact(
|
|
250
|
+
await this.contractStore.addContractArtifact(artifact);
|
|
214
251
|
this.logger.debug(`Deployed ${artifact.name} at ${instance.address}`);
|
|
215
252
|
}
|
|
216
253
|
}
|
|
217
254
|
|
|
218
|
-
async
|
|
255
|
+
async addAccount(artifact: ContractArtifact, instance: ContractInstanceWithAddress, secret: Fr) {
|
|
219
256
|
const partialAddress = await computePartialAddress(instance);
|
|
220
257
|
|
|
221
258
|
this.logger.debug(`Deployed ${artifact.name} at ${instance.address}`);
|
|
222
259
|
await this.contractStore.addContractInstance(instance);
|
|
223
|
-
await this.contractStore.addContractArtifact(
|
|
260
|
+
await this.contractStore.addContractArtifact(artifact);
|
|
224
261
|
|
|
225
262
|
const completeAddress = await this.keyStore.addAccount(secret, partialAddress);
|
|
226
263
|
await this.accountStore.setAccount(completeAddress.address, completeAddress);
|
|
@@ -230,7 +267,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
230
267
|
return completeAddress;
|
|
231
268
|
}
|
|
232
269
|
|
|
233
|
-
async
|
|
270
|
+
async createAccount(secret: Fr) {
|
|
234
271
|
// This is a foot gun !
|
|
235
272
|
const completeAddress = await this.keyStore.addAccount(secret, secret);
|
|
236
273
|
await this.accountStore.setAccount(completeAddress.address, completeAddress);
|
|
@@ -240,7 +277,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
240
277
|
return completeAddress;
|
|
241
278
|
}
|
|
242
279
|
|
|
243
|
-
async
|
|
280
|
+
async addAuthWitness(address: AztecAddress, messageHash: Fr) {
|
|
244
281
|
const account = await this.accountStore.getAccount(address);
|
|
245
282
|
const privateKey = await this.keyStore.getMasterSecretKey(account.publicKeys.masterIncomingViewingPublicKey);
|
|
246
283
|
|
|
@@ -253,7 +290,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
253
290
|
}
|
|
254
291
|
|
|
255
292
|
async mineBlock(options: { nullifiers?: Fr[] } = {}) {
|
|
256
|
-
const blockNumber = await this.
|
|
293
|
+
const blockNumber = await this.getNextBlockNumber();
|
|
257
294
|
|
|
258
295
|
const txEffect = TxEffect.empty();
|
|
259
296
|
txEffect.nullifiers = [getSingleTxBlockRequestHash(blockNumber), ...(options.nullifiers ?? [])];
|
|
@@ -277,13 +314,14 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
277
314
|
await this.stateMachine.handleL2Block(block);
|
|
278
315
|
}
|
|
279
316
|
|
|
280
|
-
async
|
|
317
|
+
async privateCallNewFlow(
|
|
281
318
|
from: AztecAddress,
|
|
282
319
|
targetContractAddress: AztecAddress = AztecAddress.zero(),
|
|
283
320
|
functionSelector: FunctionSelector = FunctionSelector.empty(),
|
|
284
321
|
args: Fr[],
|
|
285
322
|
argsHash: Fr = Fr.zero(),
|
|
286
323
|
isStaticCall: boolean = false,
|
|
324
|
+
jobId: string,
|
|
287
325
|
) {
|
|
288
326
|
this.logger.verbose(
|
|
289
327
|
`Executing external function ${await this.contractStore.getDebugFunctionName(targetContractAddress, functionSelector)}@${targetContractAddress} isStaticCall=${isStaticCall}`,
|
|
@@ -297,25 +335,35 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
297
335
|
throw new Error(message);
|
|
298
336
|
}
|
|
299
337
|
|
|
338
|
+
// When `from` is the zero address (e.g. when deploying a new account contract), we return an
|
|
339
|
+
// empty scope list which acts as deny-all: no notes are visible and no keys are accessible.
|
|
340
|
+
const effectiveScopes = from.isZero() ? [] : [from];
|
|
341
|
+
|
|
300
342
|
// Sync notes before executing private function to discover notes from previous transactions
|
|
301
|
-
const utilityExecutor = async (call: FunctionCall) => {
|
|
302
|
-
await this.executeUtilityCall(call);
|
|
343
|
+
const utilityExecutor = async (call: FunctionCall, execScopes: AztecAddress[]) => {
|
|
344
|
+
await this.executeUtilityCall(call, execScopes, jobId);
|
|
303
345
|
};
|
|
304
346
|
|
|
305
|
-
await
|
|
347
|
+
const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
348
|
+
await this.stateMachine.contractSyncService.ensureContractSynced(
|
|
349
|
+
targetContractAddress,
|
|
350
|
+
functionSelector,
|
|
351
|
+
utilityExecutor,
|
|
352
|
+
blockHeader,
|
|
353
|
+
jobId,
|
|
354
|
+
effectiveScopes,
|
|
355
|
+
);
|
|
306
356
|
|
|
307
|
-
const blockNumber = await this.
|
|
357
|
+
const blockNumber = await this.getNextBlockNumber();
|
|
308
358
|
|
|
309
359
|
const callContext = new CallContext(from, targetContractAddress, functionSelector, isStaticCall);
|
|
310
360
|
|
|
311
|
-
const gasLimits = new Gas(
|
|
312
|
-
const teardownGasLimits = new Gas(
|
|
361
|
+
const gasLimits = new Gas(MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT, MAX_PROCESSABLE_L2_GAS);
|
|
362
|
+
const teardownGasLimits = new Gas(FALLBACK_TEARDOWN_DA_GAS_LIMIT, FALLBACK_TEARDOWN_L2_GAS_LIMIT);
|
|
313
363
|
const gasSettings = new GasSettings(gasLimits, teardownGasLimits, GasFees.empty(), GasFees.empty());
|
|
314
364
|
|
|
315
365
|
const txContext = new TxContext(this.chainId, this.version, gasSettings);
|
|
316
366
|
|
|
317
|
-
const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
318
|
-
|
|
319
367
|
const protocolNullifier = await computeProtocolNullifier(getSingleTxBlockRequestHash(blockNumber));
|
|
320
368
|
const noteCache = new ExecutionNoteCache(protocolNullifier);
|
|
321
369
|
// In production, the account contract sets the min revertible counter before calling the app function.
|
|
@@ -327,43 +375,39 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
327
375
|
|
|
328
376
|
const simulator = new WASMSimulator();
|
|
329
377
|
|
|
330
|
-
const privateExecutionOracle = new PrivateExecutionOracle(
|
|
378
|
+
const privateExecutionOracle = new PrivateExecutionOracle({
|
|
331
379
|
argsHash,
|
|
332
380
|
txContext,
|
|
333
381
|
callContext,
|
|
334
|
-
|
|
335
|
-
blockHeader,
|
|
382
|
+
anchorBlockHeader: blockHeader,
|
|
336
383
|
utilityExecutor,
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
[],
|
|
341
|
-
HashedValuesCache.create([new HashedValues(args, argsHash)]),
|
|
384
|
+
authWitnesses: Array.from(this.authwits.values()),
|
|
385
|
+
capsules: [],
|
|
386
|
+
executionCache: HashedValuesCache.create([new HashedValues(args, argsHash)]),
|
|
342
387
|
noteCache,
|
|
343
388
|
taggingIndexCache,
|
|
344
|
-
this.contractStore,
|
|
345
|
-
this.noteStore,
|
|
346
|
-
this.keyStore,
|
|
347
|
-
this.addressStore,
|
|
348
|
-
this.stateMachine.node,
|
|
349
|
-
this.
|
|
350
|
-
this.
|
|
351
|
-
this.
|
|
352
|
-
this.
|
|
353
|
-
this.
|
|
354
|
-
this.
|
|
355
|
-
|
|
356
|
-
0,
|
|
357
|
-
minRevertibleSideEffectCounter,
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
* contract would perform, including setting senderForTags.
|
|
363
|
-
*/
|
|
364
|
-
from,
|
|
389
|
+
contractStore: this.contractStore,
|
|
390
|
+
noteStore: this.noteStore,
|
|
391
|
+
keyStore: this.keyStore,
|
|
392
|
+
addressStore: this.addressStore,
|
|
393
|
+
aztecNode: this.stateMachine.node,
|
|
394
|
+
senderTaggingStore: this.senderTaggingStore,
|
|
395
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
396
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
397
|
+
capsuleService: new CapsuleService(this.capsuleStore, effectiveScopes),
|
|
398
|
+
privateEventStore: this.privateEventStore,
|
|
399
|
+
contractSyncService: this.stateMachine.contractSyncService,
|
|
400
|
+
jobId,
|
|
401
|
+
totalPublicCalldataCount: 0,
|
|
402
|
+
sideEffectCounter: minRevertibleSideEffectCounter,
|
|
403
|
+
scopes: effectiveScopes,
|
|
404
|
+
// In TXE, the typical transaction entrypoint is skipped, so we need to simulate the actions that such a
|
|
405
|
+
// contract would perform, including setting senderForTags.
|
|
406
|
+
senderForTags: from,
|
|
365
407
|
simulator,
|
|
366
|
-
|
|
408
|
+
messageContextService: this.stateMachine.messageContextService,
|
|
409
|
+
l2TipsStore: this.stateMachine.node,
|
|
410
|
+
});
|
|
367
411
|
|
|
368
412
|
// 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.
|
|
369
413
|
let result: PrivateExecutionResult;
|
|
@@ -385,7 +429,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
385
429
|
);
|
|
386
430
|
const publicFunctionsCalldata = await Promise.all(
|
|
387
431
|
publicCallRequests.map(async r => {
|
|
388
|
-
const calldata = await privateExecutionOracle.
|
|
432
|
+
const calldata = await privateExecutionOracle.getHashPreimage(r.calldataHash);
|
|
389
433
|
return new HashedValues(calldata, r.calldataHash);
|
|
390
434
|
}),
|
|
391
435
|
);
|
|
@@ -402,7 +446,8 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
402
446
|
// We pass the non-zero minRevertibleSideEffectCounter to make sure the side effects are split correctly.
|
|
403
447
|
const { publicInputs } = await generateSimulatedProvingResult(
|
|
404
448
|
result,
|
|
405
|
-
this.contractStore,
|
|
449
|
+
(addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
|
|
450
|
+
this.stateMachine.node,
|
|
406
451
|
minRevertibleSideEffectCounter,
|
|
407
452
|
);
|
|
408
453
|
|
|
@@ -498,7 +543,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
498
543
|
return executionResult.returnValues ?? [];
|
|
499
544
|
}
|
|
500
545
|
|
|
501
|
-
async
|
|
546
|
+
async publicCallNewFlow(
|
|
502
547
|
from: AztecAddress,
|
|
503
548
|
targetContractAddress: AztecAddress,
|
|
504
549
|
calldata: Fr[],
|
|
@@ -508,11 +553,11 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
508
553
|
`Executing public function ${await this.contractStore.getDebugFunctionName(targetContractAddress, FunctionSelector.fromField(calldata[0]))}@${targetContractAddress} isStaticCall=${isStaticCall}`,
|
|
509
554
|
);
|
|
510
555
|
|
|
511
|
-
const blockNumber = await this.
|
|
556
|
+
const blockNumber = await this.getNextBlockNumber();
|
|
512
557
|
|
|
513
|
-
const gasLimits = new Gas(
|
|
558
|
+
const gasLimits = new Gas(MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT, MAX_PROCESSABLE_L2_GAS);
|
|
514
559
|
|
|
515
|
-
const teardownGasLimits = new Gas(
|
|
560
|
+
const teardownGasLimits = new Gas(FALLBACK_TEARDOWN_DA_GAS_LIMIT, FALLBACK_TEARDOWN_L2_GAS_LIMIT);
|
|
516
561
|
|
|
517
562
|
const gasSettings = new GasSettings(gasLimits, teardownGasLimits, GasFees.empty(), GasFees.empty());
|
|
518
563
|
|
|
@@ -585,7 +630,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
585
630
|
constantData,
|
|
586
631
|
/*gasUsed=*/ new Gas(0, 0),
|
|
587
632
|
/*feePayer=*/ AztecAddress.zero(),
|
|
588
|
-
/*
|
|
633
|
+
/*expirationTimestamp=*/ 0n,
|
|
589
634
|
inputsForPublic,
|
|
590
635
|
undefined,
|
|
591
636
|
);
|
|
@@ -653,10 +698,11 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
653
698
|
return returnValues ?? [];
|
|
654
699
|
}
|
|
655
700
|
|
|
656
|
-
async
|
|
701
|
+
async executeUtilityFunction(
|
|
657
702
|
targetContractAddress: AztecAddress,
|
|
658
703
|
functionSelector: FunctionSelector,
|
|
659
704
|
args: Fr[],
|
|
705
|
+
jobId: string,
|
|
660
706
|
) {
|
|
661
707
|
const artifact = await this.contractStore.getFunctionArtifact(targetContractAddress, functionSelector);
|
|
662
708
|
if (!artifact) {
|
|
@@ -664,25 +710,33 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
664
710
|
}
|
|
665
711
|
|
|
666
712
|
// Sync notes before executing utility function to discover notes from previous transactions
|
|
667
|
-
await
|
|
668
|
-
|
|
669
|
-
});
|
|
670
|
-
|
|
671
|
-
const call = new FunctionCall(
|
|
672
|
-
artifact.name,
|
|
713
|
+
const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
714
|
+
await this.stateMachine.contractSyncService.ensureContractSynced(
|
|
673
715
|
targetContractAddress,
|
|
674
716
|
functionSelector,
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
717
|
+
async (call, execScopes) => {
|
|
718
|
+
await this.executeUtilityCall(call, execScopes, jobId);
|
|
719
|
+
},
|
|
720
|
+
blockHeader,
|
|
721
|
+
jobId,
|
|
722
|
+
await this.keyStore.getAccounts(),
|
|
680
723
|
);
|
|
681
724
|
|
|
682
|
-
|
|
725
|
+
const call = FunctionCall.from({
|
|
726
|
+
name: artifact.name,
|
|
727
|
+
to: targetContractAddress,
|
|
728
|
+
selector: functionSelector,
|
|
729
|
+
type: FunctionType.UTILITY,
|
|
730
|
+
hideMsgSender: false,
|
|
731
|
+
isStatic: false,
|
|
732
|
+
args,
|
|
733
|
+
returnTypes: [],
|
|
734
|
+
});
|
|
735
|
+
|
|
736
|
+
return this.executeUtilityCall(call, await this.keyStore.getAccounts(), jobId);
|
|
683
737
|
}
|
|
684
738
|
|
|
685
|
-
private async executeUtilityCall(call: FunctionCall): Promise<Fr[]> {
|
|
739
|
+
private async executeUtilityCall(call: FunctionCall, scopes: AztecAddress[], jobId: string): Promise<Fr[]> {
|
|
686
740
|
const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
|
|
687
741
|
if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
|
|
688
742
|
throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
|
|
@@ -695,23 +749,26 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
695
749
|
|
|
696
750
|
try {
|
|
697
751
|
const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
698
|
-
const oracle = new UtilityExecutionOracle(
|
|
699
|
-
call.to,
|
|
700
|
-
[],
|
|
701
|
-
[],
|
|
752
|
+
const oracle = new UtilityExecutionOracle({
|
|
753
|
+
contractAddress: call.to,
|
|
754
|
+
authWitnesses: [],
|
|
755
|
+
capsules: [],
|
|
702
756
|
anchorBlockHeader,
|
|
703
|
-
this.contractStore,
|
|
704
|
-
this.noteStore,
|
|
705
|
-
this.keyStore,
|
|
706
|
-
this.addressStore,
|
|
707
|
-
this.stateMachine.node,
|
|
708
|
-
this.
|
|
709
|
-
this.
|
|
710
|
-
this.
|
|
711
|
-
this.
|
|
712
|
-
this.
|
|
713
|
-
this.
|
|
714
|
-
|
|
757
|
+
contractStore: this.contractStore,
|
|
758
|
+
noteStore: this.noteStore,
|
|
759
|
+
keyStore: this.keyStore,
|
|
760
|
+
addressStore: this.addressStore,
|
|
761
|
+
aztecNode: this.stateMachine.node,
|
|
762
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
763
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
764
|
+
capsuleService: new CapsuleService(this.capsuleStore, scopes),
|
|
765
|
+
privateEventStore: this.privateEventStore,
|
|
766
|
+
messageContextService: this.stateMachine.messageContextService,
|
|
767
|
+
contractSyncService: this.contractSyncService,
|
|
768
|
+
l2TipsStore: this.stateMachine.node,
|
|
769
|
+
jobId,
|
|
770
|
+
scopes,
|
|
771
|
+
});
|
|
715
772
|
const acirExecutionResult = await new WASMSimulator()
|
|
716
773
|
.executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, new Oracle(oracle).toACIRCallback())
|
|
717
774
|
.catch((err: Error) => {
|
|
@@ -727,10 +784,10 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
727
784
|
);
|
|
728
785
|
});
|
|
729
786
|
|
|
730
|
-
this.logger.verbose(`Utility
|
|
787
|
+
this.logger.verbose(`Utility execution for ${call.to}.${call.selector} completed`);
|
|
731
788
|
return witnessMapToFields(acirExecutionResult.returnWitness);
|
|
732
789
|
} catch (err) {
|
|
733
|
-
throw createSimulationError(err instanceof Error ? err : new Error('Unknown error during utility
|
|
790
|
+
throw createSimulationError(err instanceof Error ? err : new Error('Unknown error during utility execution'));
|
|
734
791
|
}
|
|
735
792
|
}
|
|
736
793
|
|