@aztec/txe 0.0.1-commit.9593d84 → 0.0.1-commit.96bb3f7
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/constants.d.ts +4 -0
- package/dest/constants.d.ts.map +1 -0
- package/dest/constants.js +3 -0
- package/dest/index.d.ts +1 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +3 -2
- package/dest/oracle/interfaces.d.ts +9 -6
- package/dest/oracle/interfaces.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.d.ts +5 -5
- package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.js +4 -6
- package/dest/oracle/txe_oracle_top_level_context.d.ts +21 -12
- package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_top_level_context.js +93 -62
- package/dest/rpc_translator.d.ts +11 -5
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +57 -15
- package/dest/state_machine/archiver.d.ts +29 -11
- package/dest/state_machine/archiver.d.ts.map +1 -1
- package/dest/state_machine/archiver.js +128 -17
- package/dest/state_machine/dummy_p2p_client.d.ts +8 -7
- package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
- package/dest/state_machine/dummy_p2p_client.js +16 -11
- package/dest/state_machine/global_variable_builder.d.ts +6 -5
- package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
- package/dest/state_machine/global_variable_builder.js +13 -1
- package/dest/state_machine/index.d.ts +5 -5
- package/dest/state_machine/index.d.ts.map +1 -1
- package/dest/state_machine/index.js +14 -20
- package/dest/state_machine/mock_epoch_cache.d.ts +2 -1
- package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
- package/dest/state_machine/mock_epoch_cache.js +3 -0
- package/dest/state_machine/synchronizer.d.ts +5 -4
- package/dest/state_machine/synchronizer.d.ts.map +1 -1
- package/dest/state_machine/synchronizer.js +5 -4
- package/dest/txe_session.d.ts +19 -13
- package/dest/txe_session.d.ts.map +1 -1
- package/dest/txe_session.js +76 -45
- package/dest/util/encoding.d.ts +610 -11
- package/dest/util/encoding.d.ts.map +1 -1
- package/dest/util/encoding.js +1 -1
- package/dest/util/txe_account_store.d.ts +10 -0
- package/dest/util/txe_account_store.d.ts.map +1 -0
- package/dest/util/{txe_account_data_provider.js → txe_account_store.js} +1 -1
- package/dest/util/txe_contract_store.d.ts +12 -0
- package/dest/util/txe_contract_store.d.ts.map +1 -0
- package/dest/util/{txe_contract_data_provider.js → txe_contract_store.js} +3 -3
- package/dest/util/txe_public_contract_data_source.d.ts +7 -6
- package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
- package/dest/util/txe_public_contract_data_source.js +11 -11
- package/dest/utils/block_creation.d.ts +19 -4
- package/dest/utils/block_creation.d.ts.map +1 -1
- package/dest/utils/block_creation.js +24 -4
- package/dest/utils/tx_effect_creation.d.ts +4 -3
- package/dest/utils/tx_effect_creation.d.ts.map +1 -1
- package/dest/utils/tx_effect_creation.js +1 -1
- package/package.json +17 -17
- package/src/constants.ts +4 -0
- package/src/index.ts +15 -12
- package/src/oracle/interfaces.ts +8 -5
- package/src/oracle/txe_oracle_public_context.ts +6 -11
- package/src/oracle/txe_oracle_top_level_context.ts +139 -88
- package/src/rpc_translator.ts +82 -12
- package/src/state_machine/archiver.ts +168 -26
- package/src/state_machine/dummy_p2p_client.ts +21 -14
- package/src/state_machine/global_variable_builder.ts +21 -4
- package/src/state_machine/index.ts +19 -18
- package/src/state_machine/mock_epoch_cache.ts +4 -0
- package/src/state_machine/synchronizer.ts +8 -7
- package/src/txe_session.ts +166 -75
- package/src/util/encoding.ts +1 -1
- package/src/util/{txe_account_data_provider.ts → txe_account_store.ts} +1 -1
- package/src/util/{txe_contract_data_provider.ts → txe_contract_store.ts} +3 -3
- package/src/util/txe_public_contract_data_source.ts +13 -12
- package/src/utils/block_creation.ts +36 -5
- package/src/utils/tx_effect_creation.ts +3 -2
- package/dest/util/txe_account_data_provider.d.ts +0 -10
- package/dest/util/txe_account_data_provider.d.ts.map +0 -1
- package/dest/util/txe_contract_data_provider.d.ts +0 -12
- package/dest/util/txe_contract_data_provider.d.ts.map +0 -1
|
@@ -6,15 +6,21 @@ import {
|
|
|
6
6
|
DEFAULT_TEARDOWN_L2_GAS_LIMIT,
|
|
7
7
|
NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP,
|
|
8
8
|
} from '@aztec/constants';
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
9
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
10
|
+
import { Schnorr } from '@aztec/foundation/crypto/schnorr';
|
|
11
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
11
12
|
import { LogLevels, type Logger, applyStringFormatting, createLogger } from '@aztec/foundation/log';
|
|
12
13
|
import { TestDateProvider } from '@aztec/foundation/timer';
|
|
13
14
|
import type { KeyStore } from '@aztec/key-store';
|
|
14
15
|
import {
|
|
15
|
-
|
|
16
|
+
AddressStore,
|
|
17
|
+
CapsuleStore,
|
|
18
|
+
NoteStore,
|
|
16
19
|
ORACLE_VERSION,
|
|
17
|
-
|
|
20
|
+
PrivateEventStore,
|
|
21
|
+
RecipientTaggingStore,
|
|
22
|
+
SenderAddressBookStore,
|
|
23
|
+
SenderTaggingStore,
|
|
18
24
|
enrichPublicSimulationError,
|
|
19
25
|
} from '@aztec/pxe/server';
|
|
20
26
|
import {
|
|
@@ -38,16 +44,15 @@ import {
|
|
|
38
44
|
witnessMapToFields,
|
|
39
45
|
} from '@aztec/simulator/client';
|
|
40
46
|
import {
|
|
47
|
+
CppPublicTxSimulator,
|
|
41
48
|
GuardedMerkleTreeOperations,
|
|
42
49
|
PublicContractsDB,
|
|
43
50
|
PublicProcessor,
|
|
44
|
-
PublicTxSimulator,
|
|
45
51
|
} from '@aztec/simulator/server';
|
|
46
|
-
import { type ContractArtifact, FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
|
|
52
|
+
import { type ContractArtifact, EventSelector, FunctionCall, FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
|
|
47
53
|
import { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
48
54
|
import { PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
49
55
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
50
|
-
import { Body, L2Block } from '@aztec/stdlib/block';
|
|
51
56
|
import { type ContractInstanceWithAddress, computePartialAddress } from '@aztec/stdlib/contract';
|
|
52
57
|
import { Gas, GasFees, GasSettings } from '@aztec/stdlib/gas';
|
|
53
58
|
import { computeCalldataHash, computeProtocolNullifier, siloNullifier } from '@aztec/stdlib/hash';
|
|
@@ -58,7 +63,7 @@ import {
|
|
|
58
63
|
PublicCallRequest,
|
|
59
64
|
} from '@aztec/stdlib/kernel';
|
|
60
65
|
import { ChonkProof } from '@aztec/stdlib/proofs';
|
|
61
|
-
import {
|
|
66
|
+
import { makeGlobalVariables } from '@aztec/stdlib/testing';
|
|
62
67
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
63
68
|
import {
|
|
64
69
|
CallContext,
|
|
@@ -75,15 +80,12 @@ import {
|
|
|
75
80
|
import type { UInt64 } from '@aztec/stdlib/types';
|
|
76
81
|
import { ForkCheckpoint } from '@aztec/world-state';
|
|
77
82
|
|
|
83
|
+
import { DEFAULT_ADDRESS, TXE_JOB_ID } from '../constants.js';
|
|
78
84
|
import type { TXEStateMachine } from '../state_machine/index.js';
|
|
79
|
-
import type {
|
|
80
|
-
import type {
|
|
85
|
+
import type { TXEAccountStore } from '../util/txe_account_store.js';
|
|
86
|
+
import type { TXEContractStore } from '../util/txe_contract_store.js';
|
|
81
87
|
import { TXEPublicContractDataSource } from '../util/txe_public_contract_data_source.js';
|
|
82
|
-
import {
|
|
83
|
-
getSingleTxBlockRequestHash,
|
|
84
|
-
insertTxEffectIntoWorldTrees,
|
|
85
|
-
makeTXEBlockHeader,
|
|
86
|
-
} from '../utils/block_creation.js';
|
|
88
|
+
import { getSingleTxBlockRequestHash, insertTxEffectIntoWorldTrees, makeTXEBlock } from '../utils/block_creation.js';
|
|
87
89
|
import type { ITxeExecutionOracle } from './interfaces.js';
|
|
88
90
|
|
|
89
91
|
export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracle {
|
|
@@ -94,11 +96,16 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
94
96
|
|
|
95
97
|
constructor(
|
|
96
98
|
private stateMachine: TXEStateMachine,
|
|
97
|
-
private
|
|
99
|
+
private contractStore: TXEContractStore,
|
|
100
|
+
private noteStore: NoteStore,
|
|
98
101
|
private keyStore: KeyStore,
|
|
99
|
-
private
|
|
100
|
-
private
|
|
101
|
-
private
|
|
102
|
+
private addressStore: AddressStore,
|
|
103
|
+
private accountStore: TXEAccountStore,
|
|
104
|
+
private senderTaggingStore: SenderTaggingStore,
|
|
105
|
+
private recipientTaggingStore: RecipientTaggingStore,
|
|
106
|
+
private senderAddressBookStore: SenderAddressBookStore,
|
|
107
|
+
private capsuleStore: CapsuleStore,
|
|
108
|
+
private privateEventStore: PrivateEventStore,
|
|
102
109
|
private nextBlockTimestamp: bigint,
|
|
103
110
|
private version: Fr,
|
|
104
111
|
private chainId: Fr,
|
|
@@ -132,8 +139,12 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
132
139
|
this.logger[levelName](`${applyStringFormatting(message, fields)}`, { module: `${this.logger.module}:debug_log` });
|
|
133
140
|
}
|
|
134
141
|
|
|
135
|
-
|
|
136
|
-
return
|
|
142
|
+
txeGetDefaultAddress(): AztecAddress {
|
|
143
|
+
return DEFAULT_ADDRESS;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
async txeGetNextBlockNumber(): Promise<BlockNumber> {
|
|
147
|
+
return BlockNumber((await this.getLastBlockNumber()) + 1);
|
|
137
148
|
}
|
|
138
149
|
|
|
139
150
|
txeGetNextBlockTimestamp(): Promise<bigint> {
|
|
@@ -145,7 +156,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
145
156
|
}
|
|
146
157
|
|
|
147
158
|
async txeGetLastTxEffects() {
|
|
148
|
-
const block = await this.stateMachine.archiver.
|
|
159
|
+
const block = await this.stateMachine.archiver.getL2Block('latest');
|
|
149
160
|
|
|
150
161
|
if (block!.body.txEffects.length != 1) {
|
|
151
162
|
// Note that calls like env.mine() will result in blocks with no transactions, hitting this
|
|
@@ -157,6 +168,17 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
157
168
|
return { txHash: txEffects.txHash, noteHashes: txEffects.noteHashes, nullifiers: txEffects.nullifiers };
|
|
158
169
|
}
|
|
159
170
|
|
|
171
|
+
async txeGetPrivateEvents(selector: EventSelector, contractAddress: AztecAddress, scope: AztecAddress) {
|
|
172
|
+
return (
|
|
173
|
+
await this.privateEventStore.getPrivateEvents(selector, {
|
|
174
|
+
contractAddress,
|
|
175
|
+
scopes: [scope],
|
|
176
|
+
fromBlock: 0,
|
|
177
|
+
toBlock: (await this.getLastBlockNumber()) + 1,
|
|
178
|
+
})
|
|
179
|
+
).map(e => e.packedEvent);
|
|
180
|
+
}
|
|
181
|
+
|
|
160
182
|
async txeAdvanceBlocksBy(blocks: number) {
|
|
161
183
|
this.logger.debug(`time traveling ${blocks} blocks`);
|
|
162
184
|
|
|
@@ -184,8 +206,8 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
184
206
|
if (!secret.equals(Fr.ZERO)) {
|
|
185
207
|
await this.txeAddAccount(artifact, instance, secret);
|
|
186
208
|
} else {
|
|
187
|
-
await this.
|
|
188
|
-
await this.
|
|
209
|
+
await this.contractStore.addContractInstance(instance);
|
|
210
|
+
await this.contractStore.addContractArtifact(instance.currentContractClassId, artifact);
|
|
189
211
|
this.logger.debug(`Deployed ${artifact.name} at ${instance.address}`);
|
|
190
212
|
}
|
|
191
213
|
}
|
|
@@ -194,29 +216,29 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
194
216
|
const partialAddress = await computePartialAddress(instance);
|
|
195
217
|
|
|
196
218
|
this.logger.debug(`Deployed ${artifact.name} at ${instance.address}`);
|
|
197
|
-
await this.
|
|
198
|
-
await this.
|
|
219
|
+
await this.contractStore.addContractInstance(instance);
|
|
220
|
+
await this.contractStore.addContractArtifact(instance.currentContractClassId, artifact);
|
|
199
221
|
|
|
200
222
|
const completeAddress = await this.keyStore.addAccount(secret, partialAddress);
|
|
201
|
-
await this.
|
|
202
|
-
await this.
|
|
223
|
+
await this.accountStore.setAccount(completeAddress.address, completeAddress);
|
|
224
|
+
await this.addressStore.addCompleteAddress(completeAddress);
|
|
203
225
|
this.logger.debug(`Created account ${completeAddress.address}`);
|
|
204
226
|
|
|
205
227
|
return completeAddress;
|
|
206
228
|
}
|
|
207
229
|
|
|
208
230
|
async txeCreateAccount(secret: Fr) {
|
|
209
|
-
// This is a
|
|
231
|
+
// This is a foot gun !
|
|
210
232
|
const completeAddress = await this.keyStore.addAccount(secret, secret);
|
|
211
|
-
await this.
|
|
212
|
-
await this.
|
|
233
|
+
await this.accountStore.setAccount(completeAddress.address, completeAddress);
|
|
234
|
+
await this.addressStore.addCompleteAddress(completeAddress);
|
|
213
235
|
this.logger.debug(`Created account ${completeAddress.address}`);
|
|
214
236
|
|
|
215
237
|
return completeAddress;
|
|
216
238
|
}
|
|
217
239
|
|
|
218
240
|
async txeAddAuthWitness(address: AztecAddress, messageHash: Fr) {
|
|
219
|
-
const account = await this.
|
|
241
|
+
const account = await this.accountStore.getAccount(address);
|
|
220
242
|
const privateKey = await this.keyStore.getMasterSecretKey(account.publicKeys.masterIncomingViewingPublicKey);
|
|
221
243
|
|
|
222
244
|
const schnorr = new Schnorr();
|
|
@@ -237,19 +259,13 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
237
259
|
const forkedWorldTrees = await this.stateMachine.synchronizer.nativeWorldStateService.fork();
|
|
238
260
|
await insertTxEffectIntoWorldTrees(txEffect, forkedWorldTrees);
|
|
239
261
|
|
|
240
|
-
const
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
version: this.version,
|
|
248
|
-
chainId: this.chainId,
|
|
249
|
-
}),
|
|
250
|
-
),
|
|
251
|
-
new Body([txEffect]),
|
|
252
|
-
);
|
|
262
|
+
const globals = makeGlobalVariables(undefined, {
|
|
263
|
+
blockNumber,
|
|
264
|
+
timestamp: this.nextBlockTimestamp,
|
|
265
|
+
version: this.version,
|
|
266
|
+
chainId: this.chainId,
|
|
267
|
+
});
|
|
268
|
+
const block = await makeTXEBlock(forkedWorldTrees, globals, [txEffect]);
|
|
253
269
|
|
|
254
270
|
await forkedWorldTrees.close();
|
|
255
271
|
|
|
@@ -267,10 +283,10 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
267
283
|
isStaticCall: boolean = false,
|
|
268
284
|
) {
|
|
269
285
|
this.logger.verbose(
|
|
270
|
-
`Executing external function ${await this.
|
|
286
|
+
`Executing external function ${await this.contractStore.getDebugFunctionName(targetContractAddress, functionSelector)}@${targetContractAddress} isStaticCall=${isStaticCall}`,
|
|
271
287
|
);
|
|
272
288
|
|
|
273
|
-
const artifact = await this.
|
|
289
|
+
const artifact = await this.contractStore.getFunctionArtifact(targetContractAddress, functionSelector);
|
|
274
290
|
if (!artifact) {
|
|
275
291
|
const message = functionSelector.equals(await FunctionSelector.fromSignature('verify_private_authwit(Field)'))
|
|
276
292
|
? 'Found no account contract artifact for a private authwit check - use `create_contract_account` instead of `create_light_account` for authwit support.'
|
|
@@ -278,19 +294,24 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
278
294
|
throw new Error(message);
|
|
279
295
|
}
|
|
280
296
|
|
|
297
|
+
// Sync notes before executing private function to discover notes from previous transactions
|
|
298
|
+
const utilityExecutor = async (call: FunctionCall) => {
|
|
299
|
+
await this.executeUtilityCall(call);
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
await this.contractStore.syncPrivateState(targetContractAddress, functionSelector, utilityExecutor);
|
|
303
|
+
|
|
281
304
|
const blockNumber = await this.txeGetNextBlockNumber();
|
|
282
305
|
|
|
283
306
|
const callContext = new CallContext(from, targetContractAddress, functionSelector, isStaticCall);
|
|
284
307
|
|
|
285
308
|
const gasLimits = new Gas(DEFAULT_DA_GAS_LIMIT, DEFAULT_L2_GAS_LIMIT);
|
|
286
|
-
|
|
287
309
|
const teardownGasLimits = new Gas(DEFAULT_TEARDOWN_DA_GAS_LIMIT, DEFAULT_TEARDOWN_L2_GAS_LIMIT);
|
|
288
|
-
|
|
289
310
|
const gasSettings = new GasSettings(gasLimits, teardownGasLimits, GasFees.empty(), GasFees.empty());
|
|
290
311
|
|
|
291
312
|
const txContext = new TxContext(this.chainId, this.version, gasSettings);
|
|
292
313
|
|
|
293
|
-
const blockHeader = await this.
|
|
314
|
+
const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
294
315
|
|
|
295
316
|
const protocolNullifier = await computeProtocolNullifier(getSingleTxBlockRequestHash(blockNumber));
|
|
296
317
|
const noteCache = new ExecutionNoteCache(protocolNullifier);
|
|
@@ -304,6 +325,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
304
325
|
callContext,
|
|
305
326
|
/** Header of a block whose state is used during private execution (not the block the transaction is included in). */
|
|
306
327
|
blockHeader,
|
|
328
|
+
utilityExecutor,
|
|
307
329
|
/** List of transient auth witnesses to be used during this simulation */
|
|
308
330
|
Array.from(this.authwits.values()),
|
|
309
331
|
/** List of transient auth witnesses to be used during this simulation */
|
|
@@ -311,7 +333,18 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
311
333
|
HashedValuesCache.create([new HashedValues(args, argsHash)]),
|
|
312
334
|
noteCache,
|
|
313
335
|
taggingIndexCache,
|
|
314
|
-
this.
|
|
336
|
+
this.contractStore,
|
|
337
|
+
this.noteStore,
|
|
338
|
+
this.keyStore,
|
|
339
|
+
this.addressStore,
|
|
340
|
+
this.stateMachine.node,
|
|
341
|
+
this.stateMachine.anchorBlockStore,
|
|
342
|
+
this.senderTaggingStore,
|
|
343
|
+
this.recipientTaggingStore,
|
|
344
|
+
this.senderAddressBookStore,
|
|
345
|
+
this.capsuleStore,
|
|
346
|
+
this.privateEventStore,
|
|
347
|
+
TXE_JOB_ID,
|
|
315
348
|
0,
|
|
316
349
|
1,
|
|
317
350
|
undefined, // log
|
|
@@ -361,7 +394,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
361
394
|
// can either be the first nullifier in the tx or the hash of the initial tx request
|
|
362
395
|
// if there are none.
|
|
363
396
|
const nonceGenerator = result.firstNullifier.equals(Fr.ZERO) ? protocolNullifier : result.firstNullifier;
|
|
364
|
-
const { publicInputs } = await generateSimulatedProvingResult(result, nonceGenerator, this.
|
|
397
|
+
const { publicInputs } = await generateSimulatedProvingResult(result, nonceGenerator, this.contractStore);
|
|
365
398
|
|
|
366
399
|
const globals = makeGlobalVariables();
|
|
367
400
|
globals.blockNumber = blockNumber;
|
|
@@ -372,7 +405,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
372
405
|
|
|
373
406
|
const forkedWorldTrees = await this.stateMachine.synchronizer.nativeWorldStateService.fork();
|
|
374
407
|
|
|
375
|
-
const contractsDB = new PublicContractsDB(new TXEPublicContractDataSource(blockNumber, this.
|
|
408
|
+
const contractsDB = new PublicContractsDB(new TXEPublicContractDataSource(blockNumber, this.contractStore));
|
|
376
409
|
const guardedMerkleTrees = new GuardedMerkleTreeOperations(forkedWorldTrees);
|
|
377
410
|
const config = PublicSimulatorConfig.from({
|
|
378
411
|
skipFeeEnforcement: true,
|
|
@@ -385,7 +418,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
385
418
|
globals,
|
|
386
419
|
guardedMerkleTrees,
|
|
387
420
|
contractsDB,
|
|
388
|
-
new
|
|
421
|
+
new CppPublicTxSimulator(guardedMerkleTrees, contractsDB, globals, config),
|
|
389
422
|
new TestDateProvider(),
|
|
390
423
|
);
|
|
391
424
|
|
|
@@ -411,7 +444,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
411
444
|
} else if (!processedTx.revertCode.isOK()) {
|
|
412
445
|
if (processedTx.revertReason) {
|
|
413
446
|
try {
|
|
414
|
-
await enrichPublicSimulationError(processedTx.revertReason, this.
|
|
447
|
+
await enrichPublicSimulationError(processedTx.revertReason, this.contractStore, this.logger);
|
|
415
448
|
// eslint-disable-next-line no-empty
|
|
416
449
|
} catch {}
|
|
417
450
|
throw new Error(`Contract execution has reverted: ${processedTx.revertReason.getMessage()}`);
|
|
@@ -440,13 +473,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
440
473
|
const l1ToL2Messages = Array(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP).fill(0).map(Fr.zero);
|
|
441
474
|
await forkedWorldTrees.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, l1ToL2Messages);
|
|
442
475
|
|
|
443
|
-
const
|
|
444
|
-
|
|
445
|
-
const l2Block = new L2Block(
|
|
446
|
-
makeAppendOnlyTreeSnapshot(),
|
|
447
|
-
await makeTXEBlockHeader(forkedWorldTrees, globals),
|
|
448
|
-
body,
|
|
449
|
-
);
|
|
476
|
+
const l2Block = await makeTXEBlock(forkedWorldTrees, globals, [txEffect]);
|
|
450
477
|
|
|
451
478
|
await this.stateMachine.handleL2Block(l2Block);
|
|
452
479
|
|
|
@@ -462,7 +489,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
462
489
|
isStaticCall: boolean,
|
|
463
490
|
) {
|
|
464
491
|
this.logger.verbose(
|
|
465
|
-
`Executing public function ${await this.
|
|
492
|
+
`Executing public function ${await this.contractStore.getDebugFunctionName(targetContractAddress, FunctionSelector.fromField(calldata[0]))}@${targetContractAddress} isStaticCall=${isStaticCall}`,
|
|
466
493
|
);
|
|
467
494
|
|
|
468
495
|
const blockNumber = await this.txeGetNextBlockNumber();
|
|
@@ -475,7 +502,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
475
502
|
|
|
476
503
|
const txContext = new TxContext(this.chainId, this.version, gasSettings);
|
|
477
504
|
|
|
478
|
-
const anchorBlockHeader = await this.
|
|
505
|
+
const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
479
506
|
|
|
480
507
|
const calldataHash = await computeCalldataHash(calldata);
|
|
481
508
|
const calldataHashedValues = new HashedValues(calldata, calldataHash);
|
|
@@ -489,7 +516,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
489
516
|
|
|
490
517
|
const forkedWorldTrees = await this.stateMachine.synchronizer.nativeWorldStateService.fork();
|
|
491
518
|
|
|
492
|
-
const contractsDB = new PublicContractsDB(new TXEPublicContractDataSource(blockNumber, this.
|
|
519
|
+
const contractsDB = new PublicContractsDB(new TXEPublicContractDataSource(blockNumber, this.contractStore));
|
|
493
520
|
const guardedMerkleTrees = new GuardedMerkleTreeOperations(forkedWorldTrees);
|
|
494
521
|
const config = PublicSimulatorConfig.from({
|
|
495
522
|
skipFeeEnforcement: true,
|
|
@@ -498,7 +525,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
498
525
|
collectStatistics: false,
|
|
499
526
|
collectCallMetadata: true,
|
|
500
527
|
});
|
|
501
|
-
const simulator = new
|
|
528
|
+
const simulator = new CppPublicTxSimulator(guardedMerkleTrees, contractsDB, globals, config);
|
|
502
529
|
const processor = new PublicProcessor(globals, guardedMerkleTrees, contractsDB, simulator, new TestDateProvider());
|
|
503
530
|
|
|
504
531
|
// We're simulating a scenario in which private execution immediately enqueues a public call and halts. The private
|
|
@@ -506,9 +533,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
506
533
|
// side-effect, which the AVM then expects to exist in order to use it as the nonce generator when siloing notes as
|
|
507
534
|
// unique.
|
|
508
535
|
const nonRevertibleAccumulatedData = PrivateToPublicAccumulatedData.empty();
|
|
509
|
-
|
|
510
|
-
nonRevertibleAccumulatedData.nullifiers[0] = getSingleTxBlockRequestHash(blockNumber);
|
|
511
|
-
}
|
|
536
|
+
nonRevertibleAccumulatedData.nullifiers[0] = getSingleTxBlockRequestHash(blockNumber);
|
|
512
537
|
|
|
513
538
|
// The enqueued public call itself we make be revertible so that the public execution is itself revertible, as tests
|
|
514
539
|
// may require producing reverts.
|
|
@@ -559,7 +584,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
559
584
|
} else if (!processedTx.revertCode.isOK()) {
|
|
560
585
|
if (processedTx.revertReason) {
|
|
561
586
|
try {
|
|
562
|
-
await enrichPublicSimulationError(processedTx.revertReason, this.
|
|
587
|
+
await enrichPublicSimulationError(processedTx.revertReason, this.contractStore, this.logger);
|
|
563
588
|
// eslint-disable-next-line no-empty
|
|
564
589
|
} catch {}
|
|
565
590
|
throw new Error(`Contract execution has reverted: ${processedTx.revertReason.getMessage()}`);
|
|
@@ -591,13 +616,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
591
616
|
const l1ToL2Messages = Array(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP).fill(0).map(Fr.zero);
|
|
592
617
|
await forkedWorldTrees.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, l1ToL2Messages);
|
|
593
618
|
|
|
594
|
-
const
|
|
595
|
-
|
|
596
|
-
const l2Block = new L2Block(
|
|
597
|
-
makeAppendOnlyTreeSnapshot(),
|
|
598
|
-
await makeTXEBlockHeader(forkedWorldTrees, globals),
|
|
599
|
-
body,
|
|
600
|
-
);
|
|
619
|
+
const l2Block = await makeTXEBlock(forkedWorldTrees, globals, [txEffect]);
|
|
601
620
|
|
|
602
621
|
await this.stateMachine.handleL2Block(l2Block);
|
|
603
622
|
|
|
@@ -611,18 +630,32 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
611
630
|
functionSelector: FunctionSelector,
|
|
612
631
|
args: Fr[],
|
|
613
632
|
) {
|
|
614
|
-
const artifact = await this.
|
|
633
|
+
const artifact = await this.contractStore.getFunctionArtifact(targetContractAddress, functionSelector);
|
|
615
634
|
if (!artifact) {
|
|
616
635
|
throw new Error(`Cannot call ${functionSelector} as there is no artifact found at ${targetContractAddress}.`);
|
|
617
636
|
}
|
|
618
637
|
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
};
|
|
638
|
+
// Sync notes before executing utility function to discover notes from previous transactions
|
|
639
|
+
await this.contractStore.syncPrivateState(targetContractAddress, functionSelector, async call => {
|
|
640
|
+
await this.executeUtilityCall(call);
|
|
641
|
+
});
|
|
624
642
|
|
|
625
|
-
const
|
|
643
|
+
const call = new FunctionCall(
|
|
644
|
+
artifact.name,
|
|
645
|
+
targetContractAddress,
|
|
646
|
+
functionSelector,
|
|
647
|
+
FunctionType.UTILITY,
|
|
648
|
+
false,
|
|
649
|
+
false,
|
|
650
|
+
args,
|
|
651
|
+
[],
|
|
652
|
+
);
|
|
653
|
+
|
|
654
|
+
return this.executeUtilityCall(call);
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
private async executeUtilityCall(call: FunctionCall): Promise<Fr[]> {
|
|
658
|
+
const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
|
|
626
659
|
if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
|
|
627
660
|
throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
|
|
628
661
|
}
|
|
@@ -633,9 +666,26 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
633
666
|
});
|
|
634
667
|
|
|
635
668
|
try {
|
|
636
|
-
const
|
|
669
|
+
const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
670
|
+
const oracle = new UtilityExecutionOracle(
|
|
671
|
+
call.to,
|
|
672
|
+
[],
|
|
673
|
+
[],
|
|
674
|
+
anchorBlockHeader,
|
|
675
|
+
this.contractStore,
|
|
676
|
+
this.noteStore,
|
|
677
|
+
this.keyStore,
|
|
678
|
+
this.addressStore,
|
|
679
|
+
this.stateMachine.node,
|
|
680
|
+
this.stateMachine.anchorBlockStore,
|
|
681
|
+
this.recipientTaggingStore,
|
|
682
|
+
this.senderAddressBookStore,
|
|
683
|
+
this.capsuleStore,
|
|
684
|
+
this.privateEventStore,
|
|
685
|
+
TXE_JOB_ID,
|
|
686
|
+
);
|
|
637
687
|
const acirExecutionResult = await new WASMSimulator()
|
|
638
|
-
.executeUserCircuit(toACVMWitness(0, args), entryPointArtifact, new Oracle(oracle).toACIRCallback())
|
|
688
|
+
.executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, new Oracle(oracle).toACIRCallback())
|
|
639
689
|
.catch((err: Error) => {
|
|
640
690
|
err.message = resolveAssertionMessageFromError(err, entryPointArtifact);
|
|
641
691
|
throw new ExecutionError(
|
|
@@ -661,7 +711,8 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
661
711
|
return [this.nextBlockTimestamp, this.authwits];
|
|
662
712
|
}
|
|
663
713
|
|
|
664
|
-
private async getLastBlockNumber(): Promise<
|
|
665
|
-
|
|
714
|
+
private async getLastBlockNumber(): Promise<BlockNumber> {
|
|
715
|
+
const header = await this.stateMachine.node.getBlockHeader('latest');
|
|
716
|
+
return header ? header.globalVariables.blockNumber : BlockNumber.ZERO;
|
|
666
717
|
}
|
|
667
718
|
}
|