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