@aztec/txe 0.0.1-commit.5476d83 → 0.0.1-commit.6230efd
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 +3 -0
- package/dest/constants.d.ts.map +1 -0
- package/dest/constants.js +2 -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 +26 -10
- package/dest/state_machine/archiver.d.ts.map +1 -1
- package/dest/state_machine/archiver.js +105 -17
- package/dest/state_machine/dummy_p2p_client.d.ts +1 -1
- package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
- package/dest/state_machine/dummy_p2p_client.js +3 -1
- package/dest/state_machine/global_variable_builder.d.ts +5 -4
- package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
- package/dest/state_machine/global_variable_builder.js +12 -0
- 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/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 +23 -2
- 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 +3 -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 +137 -88
- package/src/rpc_translator.ts +82 -12
- package/src/state_machine/archiver.ts +136 -25
- package/src/state_machine/dummy_p2p_client.ts +3 -1
- package/src/state_machine/global_variable_builder.ts +20 -3
- package/src/state_machine/index.ts +19 -18
- package/src/state_machine/synchronizer.ts +8 -7
- package/src/txe_session.ts +163 -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 +34 -3
- 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 } 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,17 @@ 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,
|
|
315
347
|
0,
|
|
316
348
|
1,
|
|
317
349
|
undefined, // log
|
|
@@ -361,7 +393,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
361
393
|
// can either be the first nullifier in the tx or the hash of the initial tx request
|
|
362
394
|
// if there are none.
|
|
363
395
|
const nonceGenerator = result.firstNullifier.equals(Fr.ZERO) ? protocolNullifier : result.firstNullifier;
|
|
364
|
-
const { publicInputs } = await generateSimulatedProvingResult(result, nonceGenerator, this.
|
|
396
|
+
const { publicInputs } = await generateSimulatedProvingResult(result, nonceGenerator, this.contractStore);
|
|
365
397
|
|
|
366
398
|
const globals = makeGlobalVariables();
|
|
367
399
|
globals.blockNumber = blockNumber;
|
|
@@ -372,7 +404,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
372
404
|
|
|
373
405
|
const forkedWorldTrees = await this.stateMachine.synchronizer.nativeWorldStateService.fork();
|
|
374
406
|
|
|
375
|
-
const contractsDB = new PublicContractsDB(new TXEPublicContractDataSource(blockNumber, this.
|
|
407
|
+
const contractsDB = new PublicContractsDB(new TXEPublicContractDataSource(blockNumber, this.contractStore));
|
|
376
408
|
const guardedMerkleTrees = new GuardedMerkleTreeOperations(forkedWorldTrees);
|
|
377
409
|
const config = PublicSimulatorConfig.from({
|
|
378
410
|
skipFeeEnforcement: true,
|
|
@@ -385,7 +417,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
385
417
|
globals,
|
|
386
418
|
guardedMerkleTrees,
|
|
387
419
|
contractsDB,
|
|
388
|
-
new
|
|
420
|
+
new CppPublicTxSimulator(guardedMerkleTrees, contractsDB, globals, config),
|
|
389
421
|
new TestDateProvider(),
|
|
390
422
|
);
|
|
391
423
|
|
|
@@ -411,7 +443,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
411
443
|
} else if (!processedTx.revertCode.isOK()) {
|
|
412
444
|
if (processedTx.revertReason) {
|
|
413
445
|
try {
|
|
414
|
-
await enrichPublicSimulationError(processedTx.revertReason, this.
|
|
446
|
+
await enrichPublicSimulationError(processedTx.revertReason, this.contractStore, this.logger);
|
|
415
447
|
// eslint-disable-next-line no-empty
|
|
416
448
|
} catch {}
|
|
417
449
|
throw new Error(`Contract execution has reverted: ${processedTx.revertReason.getMessage()}`);
|
|
@@ -440,13 +472,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
440
472
|
const l1ToL2Messages = Array(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP).fill(0).map(Fr.zero);
|
|
441
473
|
await forkedWorldTrees.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, l1ToL2Messages);
|
|
442
474
|
|
|
443
|
-
const
|
|
444
|
-
|
|
445
|
-
const l2Block = new L2Block(
|
|
446
|
-
makeAppendOnlyTreeSnapshot(),
|
|
447
|
-
await makeTXEBlockHeader(forkedWorldTrees, globals),
|
|
448
|
-
body,
|
|
449
|
-
);
|
|
475
|
+
const l2Block = await makeTXEBlock(forkedWorldTrees, globals, [txEffect]);
|
|
450
476
|
|
|
451
477
|
await this.stateMachine.handleL2Block(l2Block);
|
|
452
478
|
|
|
@@ -462,7 +488,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
462
488
|
isStaticCall: boolean,
|
|
463
489
|
) {
|
|
464
490
|
this.logger.verbose(
|
|
465
|
-
`Executing public function ${await this.
|
|
491
|
+
`Executing public function ${await this.contractStore.getDebugFunctionName(targetContractAddress, FunctionSelector.fromField(calldata[0]))}@${targetContractAddress} isStaticCall=${isStaticCall}`,
|
|
466
492
|
);
|
|
467
493
|
|
|
468
494
|
const blockNumber = await this.txeGetNextBlockNumber();
|
|
@@ -475,7 +501,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
475
501
|
|
|
476
502
|
const txContext = new TxContext(this.chainId, this.version, gasSettings);
|
|
477
503
|
|
|
478
|
-
const anchorBlockHeader = await this.
|
|
504
|
+
const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
479
505
|
|
|
480
506
|
const calldataHash = await computeCalldataHash(calldata);
|
|
481
507
|
const calldataHashedValues = new HashedValues(calldata, calldataHash);
|
|
@@ -489,7 +515,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
489
515
|
|
|
490
516
|
const forkedWorldTrees = await this.stateMachine.synchronizer.nativeWorldStateService.fork();
|
|
491
517
|
|
|
492
|
-
const contractsDB = new PublicContractsDB(new TXEPublicContractDataSource(blockNumber, this.
|
|
518
|
+
const contractsDB = new PublicContractsDB(new TXEPublicContractDataSource(blockNumber, this.contractStore));
|
|
493
519
|
const guardedMerkleTrees = new GuardedMerkleTreeOperations(forkedWorldTrees);
|
|
494
520
|
const config = PublicSimulatorConfig.from({
|
|
495
521
|
skipFeeEnforcement: true,
|
|
@@ -498,7 +524,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
498
524
|
collectStatistics: false,
|
|
499
525
|
collectCallMetadata: true,
|
|
500
526
|
});
|
|
501
|
-
const simulator = new
|
|
527
|
+
const simulator = new CppPublicTxSimulator(guardedMerkleTrees, contractsDB, globals, config);
|
|
502
528
|
const processor = new PublicProcessor(globals, guardedMerkleTrees, contractsDB, simulator, new TestDateProvider());
|
|
503
529
|
|
|
504
530
|
// We're simulating a scenario in which private execution immediately enqueues a public call and halts. The private
|
|
@@ -506,9 +532,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
506
532
|
// side-effect, which the AVM then expects to exist in order to use it as the nonce generator when siloing notes as
|
|
507
533
|
// unique.
|
|
508
534
|
const nonRevertibleAccumulatedData = PrivateToPublicAccumulatedData.empty();
|
|
509
|
-
|
|
510
|
-
nonRevertibleAccumulatedData.nullifiers[0] = getSingleTxBlockRequestHash(blockNumber);
|
|
511
|
-
}
|
|
535
|
+
nonRevertibleAccumulatedData.nullifiers[0] = getSingleTxBlockRequestHash(blockNumber);
|
|
512
536
|
|
|
513
537
|
// The enqueued public call itself we make be revertible so that the public execution is itself revertible, as tests
|
|
514
538
|
// may require producing reverts.
|
|
@@ -559,7 +583,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
559
583
|
} else if (!processedTx.revertCode.isOK()) {
|
|
560
584
|
if (processedTx.revertReason) {
|
|
561
585
|
try {
|
|
562
|
-
await enrichPublicSimulationError(processedTx.revertReason, this.
|
|
586
|
+
await enrichPublicSimulationError(processedTx.revertReason, this.contractStore, this.logger);
|
|
563
587
|
// eslint-disable-next-line no-empty
|
|
564
588
|
} catch {}
|
|
565
589
|
throw new Error(`Contract execution has reverted: ${processedTx.revertReason.getMessage()}`);
|
|
@@ -591,13 +615,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
591
615
|
const l1ToL2Messages = Array(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP).fill(0).map(Fr.zero);
|
|
592
616
|
await forkedWorldTrees.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, l1ToL2Messages);
|
|
593
617
|
|
|
594
|
-
const
|
|
595
|
-
|
|
596
|
-
const l2Block = new L2Block(
|
|
597
|
-
makeAppendOnlyTreeSnapshot(),
|
|
598
|
-
await makeTXEBlockHeader(forkedWorldTrees, globals),
|
|
599
|
-
body,
|
|
600
|
-
);
|
|
618
|
+
const l2Block = await makeTXEBlock(forkedWorldTrees, globals, [txEffect]);
|
|
601
619
|
|
|
602
620
|
await this.stateMachine.handleL2Block(l2Block);
|
|
603
621
|
|
|
@@ -611,18 +629,32 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
611
629
|
functionSelector: FunctionSelector,
|
|
612
630
|
args: Fr[],
|
|
613
631
|
) {
|
|
614
|
-
const artifact = await this.
|
|
632
|
+
const artifact = await this.contractStore.getFunctionArtifact(targetContractAddress, functionSelector);
|
|
615
633
|
if (!artifact) {
|
|
616
634
|
throw new Error(`Cannot call ${functionSelector} as there is no artifact found at ${targetContractAddress}.`);
|
|
617
635
|
}
|
|
618
636
|
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
};
|
|
637
|
+
// Sync notes before executing utility function to discover notes from previous transactions
|
|
638
|
+
await this.contractStore.syncPrivateState(targetContractAddress, functionSelector, async call => {
|
|
639
|
+
await this.executeUtilityCall(call);
|
|
640
|
+
});
|
|
624
641
|
|
|
625
|
-
const
|
|
642
|
+
const call = new FunctionCall(
|
|
643
|
+
artifact.name,
|
|
644
|
+
targetContractAddress,
|
|
645
|
+
functionSelector,
|
|
646
|
+
FunctionType.UTILITY,
|
|
647
|
+
false,
|
|
648
|
+
false,
|
|
649
|
+
args,
|
|
650
|
+
[],
|
|
651
|
+
);
|
|
652
|
+
|
|
653
|
+
return this.executeUtilityCall(call);
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
private async executeUtilityCall(call: FunctionCall): Promise<Fr[]> {
|
|
657
|
+
const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
|
|
626
658
|
if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
|
|
627
659
|
throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
|
|
628
660
|
}
|
|
@@ -633,9 +665,25 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
633
665
|
});
|
|
634
666
|
|
|
635
667
|
try {
|
|
636
|
-
const
|
|
668
|
+
const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
669
|
+
const oracle = new UtilityExecutionOracle(
|
|
670
|
+
call.to,
|
|
671
|
+
[],
|
|
672
|
+
[],
|
|
673
|
+
anchorBlockHeader,
|
|
674
|
+
this.contractStore,
|
|
675
|
+
this.noteStore,
|
|
676
|
+
this.keyStore,
|
|
677
|
+
this.addressStore,
|
|
678
|
+
this.stateMachine.node,
|
|
679
|
+
this.stateMachine.anchorBlockStore,
|
|
680
|
+
this.recipientTaggingStore,
|
|
681
|
+
this.senderAddressBookStore,
|
|
682
|
+
this.capsuleStore,
|
|
683
|
+
this.privateEventStore,
|
|
684
|
+
);
|
|
637
685
|
const acirExecutionResult = await new WASMSimulator()
|
|
638
|
-
.executeUserCircuit(toACVMWitness(0, args), entryPointArtifact, new Oracle(oracle).toACIRCallback())
|
|
686
|
+
.executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, new Oracle(oracle).toACIRCallback())
|
|
639
687
|
.catch((err: Error) => {
|
|
640
688
|
err.message = resolveAssertionMessageFromError(err, entryPointArtifact);
|
|
641
689
|
throw new ExecutionError(
|
|
@@ -661,7 +709,8 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
661
709
|
return [this.nextBlockTimestamp, this.authwits];
|
|
662
710
|
}
|
|
663
711
|
|
|
664
|
-
private async getLastBlockNumber(): Promise<
|
|
665
|
-
|
|
712
|
+
private async getLastBlockNumber(): Promise<BlockNumber> {
|
|
713
|
+
const header = await this.stateMachine.node.getBlockHeader('latest');
|
|
714
|
+
return header ? header.globalVariables.blockNumber : BlockNumber.ZERO;
|
|
666
715
|
}
|
|
667
716
|
}
|