@aztec/txe 0.0.1-commit.d431d1c → 0.0.1-commit.d939eb5aa
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 +15 -15
- package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.js +16 -16
- 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 +151 -63
- package/dest/rpc_translator.d.ts +125 -81
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +418 -172
- package/dest/state_machine/archiver.d.ts +4 -4
- package/dest/state_machine/archiver.d.ts.map +1 -1
- package/dest/state_machine/archiver.js +10 -10
- 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 +9 -7
- package/dest/state_machine/index.d.ts.map +1 -1
- package/dest/state_machine/index.js +36 -18
- package/dest/state_machine/mock_epoch_cache.d.ts +23 -4
- package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
- package/dest/state_machine/mock_epoch_cache.js +41 -3
- package/dest/state_machine/synchronizer.d.ts +6 -6
- 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 +100 -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 +5 -5
- package/dest/utils/block_creation.d.ts.map +1 -1
- package/dest/utils/block_creation.js +7 -5
- 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 +18 -20
- package/src/oracle/txe_oracle_top_level_context.ts +190 -114
- package/src/rpc_translator.ts +482 -187
- package/src/state_machine/archiver.ts +10 -11
- 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 +56 -20
- package/src/state_machine/mock_epoch_cache.ts +53 -4
- package/src/state_machine/synchronizer.ts +5 -5
- package/src/txe_session.ts +118 -86
- package/src/util/encoding.ts +5 -0
- package/src/util/txe_public_contract_data_source.ts +10 -38
- package/src/utils/block_creation.ts +8 -6
- 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,9 +12,12 @@ 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,
|
|
@@ -54,7 +55,13 @@ import { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
|
54
55
|
import { PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
55
56
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
56
57
|
import { type ContractInstanceWithAddress, computePartialAddress } from '@aztec/stdlib/contract';
|
|
57
|
-
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';
|
|
58
65
|
import { computeCalldataHash, computeProtocolNullifier, siloNullifier } from '@aztec/stdlib/hash';
|
|
59
66
|
import {
|
|
60
67
|
PartialPrivateTailPublicInputsForPublic,
|
|
@@ -83,7 +90,6 @@ import { ForkCheckpoint } from '@aztec/world-state';
|
|
|
83
90
|
import { DEFAULT_ADDRESS } from '../constants.js';
|
|
84
91
|
import type { TXEStateMachine } from '../state_machine/index.js';
|
|
85
92
|
import type { TXEAccountStore } from '../util/txe_account_store.js';
|
|
86
|
-
import type { TXEContractStore } from '../util/txe_contract_store.js';
|
|
87
93
|
import { TXEPublicContractDataSource } from '../util/txe_public_contract_data_source.js';
|
|
88
94
|
import { getSingleTxBlockRequestHash, insertTxEffectIntoWorldTrees, makeTXEBlock } from '../utils/block_creation.js';
|
|
89
95
|
import type { ITxeExecutionOracle } from './interfaces.js';
|
|
@@ -96,7 +102,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
96
102
|
|
|
97
103
|
constructor(
|
|
98
104
|
private stateMachine: TXEStateMachine,
|
|
99
|
-
private contractStore:
|
|
105
|
+
private contractStore: ContractStore,
|
|
100
106
|
private noteStore: NoteStore,
|
|
101
107
|
private keyStore: KeyStore,
|
|
102
108
|
private addressStore: AddressStore,
|
|
@@ -106,57 +112,70 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
106
112
|
private senderAddressBookStore: SenderAddressBookStore,
|
|
107
113
|
private capsuleStore: CapsuleStore,
|
|
108
114
|
private privateEventStore: PrivateEventStore,
|
|
109
|
-
private jobId: string,
|
|
110
115
|
private nextBlockTimestamp: bigint,
|
|
111
116
|
private version: Fr,
|
|
112
117
|
private chainId: Fr,
|
|
113
118
|
private authwits: Map<string, AuthWitness>,
|
|
119
|
+
private readonly contractSyncService: ContractSyncService,
|
|
114
120
|
) {
|
|
115
121
|
this.logger = createLogger('txe:top_level_context');
|
|
116
122
|
this.logger.debug('Entering Top Level Context');
|
|
117
123
|
}
|
|
118
124
|
|
|
119
|
-
|
|
120
|
-
|
|
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.';
|
|
121
133
|
throw new Error(
|
|
122
|
-
`Incompatible
|
|
134
|
+
`Incompatible aztec cli version: ${hint} See https://docs.aztec.network/errors/8 (expected oracle major version ${ORACLE_VERSION_MAJOR}, got ${major})`,
|
|
123
135
|
);
|
|
124
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;
|
|
125
143
|
}
|
|
126
144
|
|
|
127
145
|
// This is typically only invoked in private contexts, but it is convenient to also have it in top-level for testing
|
|
128
146
|
// setup.
|
|
129
|
-
|
|
147
|
+
getRandomField(): Fr {
|
|
130
148
|
return Fr.random();
|
|
131
149
|
}
|
|
132
150
|
|
|
133
151
|
// We instruct users to debug contracts via this oracle, so it makes sense that they'd expect it to also work in tests
|
|
134
|
-
|
|
152
|
+
log(level: number, message: string, fields: Fr[]): Promise<void> {
|
|
135
153
|
if (!LogLevels[level]) {
|
|
136
|
-
throw new Error(`Invalid
|
|
154
|
+
throw new Error(`Invalid log level: ${level}`);
|
|
137
155
|
}
|
|
138
156
|
const levelName = LogLevels[level];
|
|
139
157
|
|
|
140
158
|
this.logger[levelName](`${applyStringFormatting(message, fields)}`, { module: `${this.logger.module}:debug_log` });
|
|
159
|
+
return Promise.resolve();
|
|
141
160
|
}
|
|
142
161
|
|
|
143
|
-
|
|
162
|
+
getDefaultAddress(): AztecAddress {
|
|
144
163
|
return DEFAULT_ADDRESS;
|
|
145
164
|
}
|
|
146
165
|
|
|
147
|
-
async
|
|
166
|
+
async getNextBlockNumber(): Promise<BlockNumber> {
|
|
148
167
|
return BlockNumber((await this.getLastBlockNumber()) + 1);
|
|
149
168
|
}
|
|
150
169
|
|
|
151
|
-
|
|
170
|
+
getNextBlockTimestamp(): Promise<bigint> {
|
|
152
171
|
return Promise.resolve(this.nextBlockTimestamp);
|
|
153
172
|
}
|
|
154
173
|
|
|
155
|
-
async
|
|
174
|
+
async getLastBlockTimestamp() {
|
|
156
175
|
return (await this.stateMachine.node.getBlockHeader('latest'))!.globalVariables.timestamp;
|
|
157
176
|
}
|
|
158
177
|
|
|
159
|
-
async
|
|
178
|
+
async getLastTxEffects() {
|
|
160
179
|
const latestBlockNumber = await this.stateMachine.archiver.getBlockNumber();
|
|
161
180
|
const block = await this.stateMachine.archiver.getBlock(latestBlockNumber);
|
|
162
181
|
|
|
@@ -170,7 +189,26 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
170
189
|
return { txHash: txEffects.txHash, noteHashes: txEffects.noteHashes, nullifiers: txEffects.nullifiers };
|
|
171
190
|
}
|
|
172
191
|
|
|
173
|
-
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) {
|
|
174
212
|
return (
|
|
175
213
|
await this.privateEventStore.getPrivateEvents(selector, {
|
|
176
214
|
contractAddress,
|
|
@@ -181,7 +219,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
181
219
|
).map(e => e.packedEvent);
|
|
182
220
|
}
|
|
183
221
|
|
|
184
|
-
async
|
|
222
|
+
async advanceBlocksBy(blocks: number) {
|
|
185
223
|
this.logger.debug(`time traveling ${blocks} blocks`);
|
|
186
224
|
|
|
187
225
|
for (let i = 0; i < blocks; i++) {
|
|
@@ -189,12 +227,12 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
189
227
|
}
|
|
190
228
|
}
|
|
191
229
|
|
|
192
|
-
|
|
230
|
+
advanceTimestampBy(duration: UInt64) {
|
|
193
231
|
this.logger.debug(`time traveling ${duration} seconds`);
|
|
194
232
|
this.nextBlockTimestamp += duration;
|
|
195
233
|
}
|
|
196
234
|
|
|
197
|
-
async
|
|
235
|
+
async deploy(artifact: ContractArtifact, instance: ContractInstanceWithAddress, secret: Fr) {
|
|
198
236
|
// Emit deployment nullifier
|
|
199
237
|
await this.mineBlock({
|
|
200
238
|
nullifiers: [
|
|
@@ -206,20 +244,20 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
206
244
|
});
|
|
207
245
|
|
|
208
246
|
if (!secret.equals(Fr.ZERO)) {
|
|
209
|
-
await this.
|
|
247
|
+
await this.addAccount(artifact, instance, secret);
|
|
210
248
|
} else {
|
|
211
249
|
await this.contractStore.addContractInstance(instance);
|
|
212
|
-
await this.contractStore.addContractArtifact(
|
|
250
|
+
await this.contractStore.addContractArtifact(artifact);
|
|
213
251
|
this.logger.debug(`Deployed ${artifact.name} at ${instance.address}`);
|
|
214
252
|
}
|
|
215
253
|
}
|
|
216
254
|
|
|
217
|
-
async
|
|
255
|
+
async addAccount(artifact: ContractArtifact, instance: ContractInstanceWithAddress, secret: Fr) {
|
|
218
256
|
const partialAddress = await computePartialAddress(instance);
|
|
219
257
|
|
|
220
258
|
this.logger.debug(`Deployed ${artifact.name} at ${instance.address}`);
|
|
221
259
|
await this.contractStore.addContractInstance(instance);
|
|
222
|
-
await this.contractStore.addContractArtifact(
|
|
260
|
+
await this.contractStore.addContractArtifact(artifact);
|
|
223
261
|
|
|
224
262
|
const completeAddress = await this.keyStore.addAccount(secret, partialAddress);
|
|
225
263
|
await this.accountStore.setAccount(completeAddress.address, completeAddress);
|
|
@@ -229,7 +267,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
229
267
|
return completeAddress;
|
|
230
268
|
}
|
|
231
269
|
|
|
232
|
-
async
|
|
270
|
+
async createAccount(secret: Fr) {
|
|
233
271
|
// This is a foot gun !
|
|
234
272
|
const completeAddress = await this.keyStore.addAccount(secret, secret);
|
|
235
273
|
await this.accountStore.setAccount(completeAddress.address, completeAddress);
|
|
@@ -239,7 +277,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
239
277
|
return completeAddress;
|
|
240
278
|
}
|
|
241
279
|
|
|
242
|
-
async
|
|
280
|
+
async addAuthWitness(address: AztecAddress, messageHash: Fr) {
|
|
243
281
|
const account = await this.accountStore.getAccount(address);
|
|
244
282
|
const privateKey = await this.keyStore.getMasterSecretKey(account.publicKeys.masterIncomingViewingPublicKey);
|
|
245
283
|
|
|
@@ -252,7 +290,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
252
290
|
}
|
|
253
291
|
|
|
254
292
|
async mineBlock(options: { nullifiers?: Fr[] } = {}) {
|
|
255
|
-
const blockNumber = await this.
|
|
293
|
+
const blockNumber = await this.getNextBlockNumber();
|
|
256
294
|
|
|
257
295
|
const txEffect = TxEffect.empty();
|
|
258
296
|
txEffect.nullifiers = [getSingleTxBlockRequestHash(blockNumber), ...(options.nullifiers ?? [])];
|
|
@@ -276,13 +314,14 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
276
314
|
await this.stateMachine.handleL2Block(block);
|
|
277
315
|
}
|
|
278
316
|
|
|
279
|
-
async
|
|
317
|
+
async privateCallNewFlow(
|
|
280
318
|
from: AztecAddress,
|
|
281
319
|
targetContractAddress: AztecAddress = AztecAddress.zero(),
|
|
282
320
|
functionSelector: FunctionSelector = FunctionSelector.empty(),
|
|
283
321
|
args: Fr[],
|
|
284
322
|
argsHash: Fr = Fr.zero(),
|
|
285
323
|
isStaticCall: boolean = false,
|
|
324
|
+
jobId: string,
|
|
286
325
|
) {
|
|
287
326
|
this.logger.verbose(
|
|
288
327
|
`Executing external function ${await this.contractStore.getDebugFunctionName(targetContractAddress, functionSelector)}@${targetContractAddress} isStaticCall=${isStaticCall}`,
|
|
@@ -296,25 +335,35 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
296
335
|
throw new Error(message);
|
|
297
336
|
}
|
|
298
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
|
+
|
|
299
342
|
// Sync notes before executing private function to discover notes from previous transactions
|
|
300
|
-
const utilityExecutor = async (call: FunctionCall) => {
|
|
301
|
-
await this.executeUtilityCall(call);
|
|
343
|
+
const utilityExecutor = async (call: FunctionCall, execScopes: AztecAddress[]) => {
|
|
344
|
+
await this.executeUtilityCall(call, execScopes, jobId);
|
|
302
345
|
};
|
|
303
346
|
|
|
304
|
-
await this.
|
|
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
|
+
);
|
|
305
356
|
|
|
306
|
-
const blockNumber = await this.
|
|
357
|
+
const blockNumber = await this.getNextBlockNumber();
|
|
307
358
|
|
|
308
359
|
const callContext = new CallContext(from, targetContractAddress, functionSelector, isStaticCall);
|
|
309
360
|
|
|
310
|
-
const gasLimits = new Gas(
|
|
311
|
-
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);
|
|
312
363
|
const gasSettings = new GasSettings(gasLimits, teardownGasLimits, GasFees.empty(), GasFees.empty());
|
|
313
364
|
|
|
314
365
|
const txContext = new TxContext(this.chainId, this.version, gasSettings);
|
|
315
366
|
|
|
316
|
-
const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
317
|
-
|
|
318
367
|
const protocolNullifier = await computeProtocolNullifier(getSingleTxBlockRequestHash(blockNumber));
|
|
319
368
|
const noteCache = new ExecutionNoteCache(protocolNullifier);
|
|
320
369
|
// In production, the account contract sets the min revertible counter before calling the app function.
|
|
@@ -326,43 +375,39 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
326
375
|
|
|
327
376
|
const simulator = new WASMSimulator();
|
|
328
377
|
|
|
329
|
-
const privateExecutionOracle = new PrivateExecutionOracle(
|
|
378
|
+
const privateExecutionOracle = new PrivateExecutionOracle({
|
|
330
379
|
argsHash,
|
|
331
380
|
txContext,
|
|
332
381
|
callContext,
|
|
333
|
-
|
|
334
|
-
blockHeader,
|
|
382
|
+
anchorBlockHeader: blockHeader,
|
|
335
383
|
utilityExecutor,
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
[],
|
|
340
|
-
HashedValuesCache.create([new HashedValues(args, argsHash)]),
|
|
384
|
+
authWitnesses: Array.from(this.authwits.values()),
|
|
385
|
+
capsules: [],
|
|
386
|
+
executionCache: HashedValuesCache.create([new HashedValues(args, argsHash)]),
|
|
341
387
|
noteCache,
|
|
342
388
|
taggingIndexCache,
|
|
343
|
-
this.contractStore,
|
|
344
|
-
this.noteStore,
|
|
345
|
-
this.keyStore,
|
|
346
|
-
this.addressStore,
|
|
347
|
-
this.stateMachine.node,
|
|
348
|
-
this.
|
|
349
|
-
this.
|
|
350
|
-
this.
|
|
351
|
-
this.
|
|
352
|
-
this.
|
|
353
|
-
this.
|
|
354
|
-
|
|
355
|
-
0,
|
|
356
|
-
minRevertibleSideEffectCounter,
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
* contract would perform, including setting senderForTags.
|
|
362
|
-
*/
|
|
363
|
-
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,
|
|
364
407
|
simulator,
|
|
365
|
-
|
|
408
|
+
messageContextService: this.stateMachine.messageContextService,
|
|
409
|
+
l2TipsStore: this.stateMachine.node,
|
|
410
|
+
});
|
|
366
411
|
|
|
367
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.
|
|
368
413
|
let result: PrivateExecutionResult;
|
|
@@ -384,7 +429,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
384
429
|
);
|
|
385
430
|
const publicFunctionsCalldata = await Promise.all(
|
|
386
431
|
publicCallRequests.map(async r => {
|
|
387
|
-
const calldata = await privateExecutionOracle.
|
|
432
|
+
const calldata = await privateExecutionOracle.getHashPreimage(r.calldataHash);
|
|
388
433
|
return new HashedValues(calldata, r.calldataHash);
|
|
389
434
|
}),
|
|
390
435
|
);
|
|
@@ -401,7 +446,8 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
401
446
|
// We pass the non-zero minRevertibleSideEffectCounter to make sure the side effects are split correctly.
|
|
402
447
|
const { publicInputs } = await generateSimulatedProvingResult(
|
|
403
448
|
result,
|
|
404
|
-
this.contractStore,
|
|
449
|
+
(addr, sel) => this.contractStore.getDebugFunctionName(addr, sel),
|
|
450
|
+
this.stateMachine.node,
|
|
405
451
|
minRevertibleSideEffectCounter,
|
|
406
452
|
);
|
|
407
453
|
|
|
@@ -414,7 +460,11 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
414
460
|
|
|
415
461
|
const forkedWorldTrees = await this.stateMachine.synchronizer.nativeWorldStateService.fork();
|
|
416
462
|
|
|
417
|
-
const
|
|
463
|
+
const bindings = this.logger.getBindings();
|
|
464
|
+
const contractsDB = new PublicContractsDB(
|
|
465
|
+
new TXEPublicContractDataSource(blockNumber, this.contractStore),
|
|
466
|
+
bindings,
|
|
467
|
+
);
|
|
418
468
|
const guardedMerkleTrees = new GuardedMerkleTreeOperations(forkedWorldTrees);
|
|
419
469
|
const config = PublicSimulatorConfig.from({
|
|
420
470
|
skipFeeEnforcement: true,
|
|
@@ -427,8 +477,10 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
427
477
|
globals,
|
|
428
478
|
guardedMerkleTrees,
|
|
429
479
|
contractsDB,
|
|
430
|
-
new CppPublicTxSimulator(guardedMerkleTrees, contractsDB, globals, config),
|
|
480
|
+
new CppPublicTxSimulator(guardedMerkleTrees, contractsDB, globals, config, bindings),
|
|
431
481
|
new TestDateProvider(),
|
|
482
|
+
undefined,
|
|
483
|
+
createLogger('simulator:public-processor', bindings),
|
|
432
484
|
);
|
|
433
485
|
|
|
434
486
|
const tx = await Tx.create({
|
|
@@ -491,7 +543,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
491
543
|
return executionResult.returnValues ?? [];
|
|
492
544
|
}
|
|
493
545
|
|
|
494
|
-
async
|
|
546
|
+
async publicCallNewFlow(
|
|
495
547
|
from: AztecAddress,
|
|
496
548
|
targetContractAddress: AztecAddress,
|
|
497
549
|
calldata: Fr[],
|
|
@@ -501,11 +553,11 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
501
553
|
`Executing public function ${await this.contractStore.getDebugFunctionName(targetContractAddress, FunctionSelector.fromField(calldata[0]))}@${targetContractAddress} isStaticCall=${isStaticCall}`,
|
|
502
554
|
);
|
|
503
555
|
|
|
504
|
-
const blockNumber = await this.
|
|
556
|
+
const blockNumber = await this.getNextBlockNumber();
|
|
505
557
|
|
|
506
|
-
const gasLimits = new Gas(
|
|
558
|
+
const gasLimits = new Gas(MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT, MAX_PROCESSABLE_L2_GAS);
|
|
507
559
|
|
|
508
|
-
const teardownGasLimits = new Gas(
|
|
560
|
+
const teardownGasLimits = new Gas(FALLBACK_TEARDOWN_DA_GAS_LIMIT, FALLBACK_TEARDOWN_L2_GAS_LIMIT);
|
|
509
561
|
|
|
510
562
|
const gasSettings = new GasSettings(gasLimits, teardownGasLimits, GasFees.empty(), GasFees.empty());
|
|
511
563
|
|
|
@@ -525,7 +577,11 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
525
577
|
|
|
526
578
|
const forkedWorldTrees = await this.stateMachine.synchronizer.nativeWorldStateService.fork();
|
|
527
579
|
|
|
528
|
-
const
|
|
580
|
+
const bindings2 = this.logger.getBindings();
|
|
581
|
+
const contractsDB = new PublicContractsDB(
|
|
582
|
+
new TXEPublicContractDataSource(blockNumber, this.contractStore),
|
|
583
|
+
bindings2,
|
|
584
|
+
);
|
|
529
585
|
const guardedMerkleTrees = new GuardedMerkleTreeOperations(forkedWorldTrees);
|
|
530
586
|
const config = PublicSimulatorConfig.from({
|
|
531
587
|
skipFeeEnforcement: true,
|
|
@@ -534,8 +590,16 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
534
590
|
collectStatistics: false,
|
|
535
591
|
collectCallMetadata: true,
|
|
536
592
|
});
|
|
537
|
-
const simulator = new CppPublicTxSimulator(guardedMerkleTrees, contractsDB, globals, config);
|
|
538
|
-
const processor = new PublicProcessor(
|
|
593
|
+
const simulator = new CppPublicTxSimulator(guardedMerkleTrees, contractsDB, globals, config, bindings2);
|
|
594
|
+
const processor = new PublicProcessor(
|
|
595
|
+
globals,
|
|
596
|
+
guardedMerkleTrees,
|
|
597
|
+
contractsDB,
|
|
598
|
+
simulator,
|
|
599
|
+
new TestDateProvider(),
|
|
600
|
+
undefined,
|
|
601
|
+
createLogger('simulator:public-processor', bindings2),
|
|
602
|
+
);
|
|
539
603
|
|
|
540
604
|
// We're simulating a scenario in which private execution immediately enqueues a public call and halts. The private
|
|
541
605
|
// kernel init would in this case inject a nullifier with the transaction request hash as a non-revertible
|
|
@@ -566,7 +630,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
566
630
|
constantData,
|
|
567
631
|
/*gasUsed=*/ new Gas(0, 0),
|
|
568
632
|
/*feePayer=*/ AztecAddress.zero(),
|
|
569
|
-
/*
|
|
633
|
+
/*expirationTimestamp=*/ 0n,
|
|
570
634
|
inputsForPublic,
|
|
571
635
|
undefined,
|
|
572
636
|
);
|
|
@@ -634,10 +698,11 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
634
698
|
return returnValues ?? [];
|
|
635
699
|
}
|
|
636
700
|
|
|
637
|
-
async
|
|
701
|
+
async executeUtilityFunction(
|
|
638
702
|
targetContractAddress: AztecAddress,
|
|
639
703
|
functionSelector: FunctionSelector,
|
|
640
704
|
args: Fr[],
|
|
705
|
+
jobId: string,
|
|
641
706
|
) {
|
|
642
707
|
const artifact = await this.contractStore.getFunctionArtifact(targetContractAddress, functionSelector);
|
|
643
708
|
if (!artifact) {
|
|
@@ -645,25 +710,33 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
645
710
|
}
|
|
646
711
|
|
|
647
712
|
// Sync notes before executing utility function to discover notes from previous transactions
|
|
648
|
-
await this.
|
|
649
|
-
|
|
650
|
-
});
|
|
651
|
-
|
|
652
|
-
const call = new FunctionCall(
|
|
653
|
-
artifact.name,
|
|
713
|
+
const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
714
|
+
await this.stateMachine.contractSyncService.ensureContractSynced(
|
|
654
715
|
targetContractAddress,
|
|
655
716
|
functionSelector,
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
717
|
+
async (call, execScopes) => {
|
|
718
|
+
await this.executeUtilityCall(call, execScopes, jobId);
|
|
719
|
+
},
|
|
720
|
+
blockHeader,
|
|
721
|
+
jobId,
|
|
722
|
+
await this.keyStore.getAccounts(),
|
|
661
723
|
);
|
|
662
724
|
|
|
663
|
-
|
|
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);
|
|
664
737
|
}
|
|
665
738
|
|
|
666
|
-
private async executeUtilityCall(call: FunctionCall): Promise<Fr[]> {
|
|
739
|
+
private async executeUtilityCall(call: FunctionCall, scopes: AztecAddress[], jobId: string): Promise<Fr[]> {
|
|
667
740
|
const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
|
|
668
741
|
if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
|
|
669
742
|
throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
|
|
@@ -676,23 +749,26 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
676
749
|
|
|
677
750
|
try {
|
|
678
751
|
const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
679
|
-
const oracle = new UtilityExecutionOracle(
|
|
680
|
-
call.to,
|
|
681
|
-
[],
|
|
682
|
-
[],
|
|
752
|
+
const oracle = new UtilityExecutionOracle({
|
|
753
|
+
contractAddress: call.to,
|
|
754
|
+
authWitnesses: [],
|
|
755
|
+
capsules: [],
|
|
683
756
|
anchorBlockHeader,
|
|
684
|
-
this.contractStore,
|
|
685
|
-
this.noteStore,
|
|
686
|
-
this.keyStore,
|
|
687
|
-
this.addressStore,
|
|
688
|
-
this.stateMachine.node,
|
|
689
|
-
this.
|
|
690
|
-
this.
|
|
691
|
-
this.
|
|
692
|
-
this.
|
|
693
|
-
this.
|
|
694
|
-
this.
|
|
695
|
-
|
|
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
|
+
});
|
|
696
772
|
const acirExecutionResult = await new WASMSimulator()
|
|
697
773
|
.executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, new Oracle(oracle).toACIRCallback())
|
|
698
774
|
.catch((err: Error) => {
|
|
@@ -708,10 +784,10 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
708
784
|
);
|
|
709
785
|
});
|
|
710
786
|
|
|
711
|
-
this.logger.verbose(`Utility
|
|
787
|
+
this.logger.verbose(`Utility execution for ${call.to}.${call.selector} completed`);
|
|
712
788
|
return witnessMapToFields(acirExecutionResult.returnWitness);
|
|
713
789
|
} catch (err) {
|
|
714
|
-
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'));
|
|
715
791
|
}
|
|
716
792
|
}
|
|
717
793
|
|