@aztec/txe 0.0.1-commit.d3ec352c → 0.0.1-commit.e6bd8901
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 +6 -4
- package/dest/oracle/interfaces.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.d.ts +4 -4
- package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.js +7 -8
- package/dest/oracle/txe_oracle_top_level_context.d.ts +20 -11
- package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_top_level_context.js +100 -63
- package/dest/rpc_translator.d.ts +23 -11
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +91 -38
- package/dest/state_machine/archiver.d.ts +21 -57
- package/dest/state_machine/archiver.d.ts.map +1 -1
- package/dest/state_machine/archiver.js +61 -107
- 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 +4 -3
- 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 +32 -20
- package/dest/state_machine/mock_epoch_cache.d.ts +7 -6
- package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
- package/dest/state_machine/mock_epoch_cache.js +10 -7
- package/dest/state_machine/synchronizer.d.ts +3 -3
- package/dest/state_machine/synchronizer.d.ts.map +1 -1
- package/dest/state_machine/synchronizer.js +2 -2
- package/dest/txe_session.d.ts +18 -10
- package/dest/txe_session.d.ts.map +1 -1
- package/dest/txe_session.js +91 -45
- package/dest/util/encoding.d.ts +618 -19
- 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 +5 -5
- 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 -5
- package/dest/utils/block_creation.d.ts.map +1 -1
- package/dest/utils/block_creation.js +36 -4
- package/dest/utils/tx_effect_creation.d.ts +2 -3
- package/dest/utils/tx_effect_creation.d.ts.map +1 -1
- package/dest/utils/tx_effect_creation.js +4 -7
- package/package.json +16 -16
- package/src/constants.ts +3 -0
- package/src/index.ts +15 -12
- package/src/oracle/interfaces.ts +5 -3
- package/src/oracle/txe_oracle_public_context.ts +7 -12
- package/src/oracle/txe_oracle_top_level_context.ts +149 -88
- package/src/rpc_translator.ts +113 -49
- package/src/state_machine/archiver.ts +57 -131
- package/src/state_machine/dummy_p2p_client.ts +21 -14
- package/src/state_machine/global_variable_builder.ts +19 -2
- package/src/state_machine/index.ts +41 -18
- package/src/state_machine/mock_epoch_cache.ts +10 -11
- package/src/state_machine/synchronizer.ts +3 -4
- package/src/txe_session.ts +187 -76
- 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 +10 -10
- package/src/utils/block_creation.ts +46 -15
- package/src/utils/tx_effect_creation.ts +4 -12
- 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
|
@@ -7,16 +7,22 @@ import {
|
|
|
7
7
|
NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP,
|
|
8
8
|
} from '@aztec/constants';
|
|
9
9
|
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
10
|
-
import { Schnorr } from '@aztec/foundation/crypto';
|
|
11
|
-
import { Fr } from '@aztec/foundation/
|
|
10
|
+
import { Schnorr } from '@aztec/foundation/crypto/schnorr';
|
|
11
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
12
12
|
import { LogLevels, type Logger, applyStringFormatting, createLogger } from '@aztec/foundation/log';
|
|
13
13
|
import { TestDateProvider } from '@aztec/foundation/timer';
|
|
14
14
|
import type { KeyStore } from '@aztec/key-store';
|
|
15
15
|
import {
|
|
16
|
-
|
|
16
|
+
AddressStore,
|
|
17
|
+
CapsuleStore,
|
|
18
|
+
NoteStore,
|
|
17
19
|
ORACLE_VERSION,
|
|
18
|
-
|
|
20
|
+
PrivateEventStore,
|
|
21
|
+
RecipientTaggingStore,
|
|
22
|
+
SenderAddressBookStore,
|
|
23
|
+
SenderTaggingStore,
|
|
19
24
|
enrichPublicSimulationError,
|
|
25
|
+
syncState,
|
|
20
26
|
} from '@aztec/pxe/server';
|
|
21
27
|
import {
|
|
22
28
|
ExecutionNoteCache,
|
|
@@ -44,11 +50,10 @@ import {
|
|
|
44
50
|
PublicContractsDB,
|
|
45
51
|
PublicProcessor,
|
|
46
52
|
} from '@aztec/simulator/server';
|
|
47
|
-
import { type ContractArtifact, FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
|
|
53
|
+
import { type ContractArtifact, EventSelector, FunctionCall, FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
|
|
48
54
|
import { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
49
55
|
import { PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
50
56
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
51
|
-
import { Body, L2Block } from '@aztec/stdlib/block';
|
|
52
57
|
import { type ContractInstanceWithAddress, computePartialAddress } from '@aztec/stdlib/contract';
|
|
53
58
|
import { Gas, GasFees, GasSettings } from '@aztec/stdlib/gas';
|
|
54
59
|
import { computeCalldataHash, computeProtocolNullifier, siloNullifier } from '@aztec/stdlib/hash';
|
|
@@ -59,7 +64,7 @@ import {
|
|
|
59
64
|
PublicCallRequest,
|
|
60
65
|
} from '@aztec/stdlib/kernel';
|
|
61
66
|
import { ChonkProof } from '@aztec/stdlib/proofs';
|
|
62
|
-
import {
|
|
67
|
+
import { makeGlobalVariables } from '@aztec/stdlib/testing';
|
|
63
68
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
64
69
|
import {
|
|
65
70
|
CallContext,
|
|
@@ -76,15 +81,12 @@ import {
|
|
|
76
81
|
import type { UInt64 } from '@aztec/stdlib/types';
|
|
77
82
|
import { ForkCheckpoint } from '@aztec/world-state';
|
|
78
83
|
|
|
84
|
+
import { DEFAULT_ADDRESS } from '../constants.js';
|
|
79
85
|
import type { TXEStateMachine } from '../state_machine/index.js';
|
|
80
|
-
import type {
|
|
81
|
-
import type {
|
|
86
|
+
import type { TXEAccountStore } from '../util/txe_account_store.js';
|
|
87
|
+
import type { TXEContractStore } from '../util/txe_contract_store.js';
|
|
82
88
|
import { TXEPublicContractDataSource } from '../util/txe_public_contract_data_source.js';
|
|
83
|
-
import {
|
|
84
|
-
getSingleTxBlockRequestHash,
|
|
85
|
-
insertTxEffectIntoWorldTrees,
|
|
86
|
-
makeTXEBlockHeader,
|
|
87
|
-
} from '../utils/block_creation.js';
|
|
89
|
+
import { getSingleTxBlockRequestHash, insertTxEffectIntoWorldTrees, makeTXEBlock } from '../utils/block_creation.js';
|
|
88
90
|
import type { ITxeExecutionOracle } from './interfaces.js';
|
|
89
91
|
|
|
90
92
|
export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracle {
|
|
@@ -95,11 +97,17 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
95
97
|
|
|
96
98
|
constructor(
|
|
97
99
|
private stateMachine: TXEStateMachine,
|
|
98
|
-
private
|
|
100
|
+
private contractStore: TXEContractStore,
|
|
101
|
+
private noteStore: NoteStore,
|
|
99
102
|
private keyStore: KeyStore,
|
|
100
|
-
private
|
|
101
|
-
private
|
|
102
|
-
private
|
|
103
|
+
private addressStore: AddressStore,
|
|
104
|
+
private accountStore: TXEAccountStore,
|
|
105
|
+
private senderTaggingStore: SenderTaggingStore,
|
|
106
|
+
private recipientTaggingStore: RecipientTaggingStore,
|
|
107
|
+
private senderAddressBookStore: SenderAddressBookStore,
|
|
108
|
+
private capsuleStore: CapsuleStore,
|
|
109
|
+
private privateEventStore: PrivateEventStore,
|
|
110
|
+
private jobId: string,
|
|
103
111
|
private nextBlockTimestamp: bigint,
|
|
104
112
|
private version: Fr,
|
|
105
113
|
private chainId: Fr,
|
|
@@ -133,6 +141,10 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
133
141
|
this.logger[levelName](`${applyStringFormatting(message, fields)}`, { module: `${this.logger.module}:debug_log` });
|
|
134
142
|
}
|
|
135
143
|
|
|
144
|
+
txeGetDefaultAddress(): AztecAddress {
|
|
145
|
+
return DEFAULT_ADDRESS;
|
|
146
|
+
}
|
|
147
|
+
|
|
136
148
|
async txeGetNextBlockNumber(): Promise<BlockNumber> {
|
|
137
149
|
return BlockNumber((await this.getLastBlockNumber()) + 1);
|
|
138
150
|
}
|
|
@@ -146,7 +158,8 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
146
158
|
}
|
|
147
159
|
|
|
148
160
|
async txeGetLastTxEffects() {
|
|
149
|
-
const
|
|
161
|
+
const latestBlockNumber = await this.stateMachine.archiver.getBlockNumber();
|
|
162
|
+
const block = await this.stateMachine.archiver.getBlock(latestBlockNumber);
|
|
150
163
|
|
|
151
164
|
if (block!.body.txEffects.length != 1) {
|
|
152
165
|
// Note that calls like env.mine() will result in blocks with no transactions, hitting this
|
|
@@ -158,6 +171,17 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
158
171
|
return { txHash: txEffects.txHash, noteHashes: txEffects.noteHashes, nullifiers: txEffects.nullifiers };
|
|
159
172
|
}
|
|
160
173
|
|
|
174
|
+
async txeGetPrivateEvents(selector: EventSelector, contractAddress: AztecAddress, scope: AztecAddress) {
|
|
175
|
+
return (
|
|
176
|
+
await this.privateEventStore.getPrivateEvents(selector, {
|
|
177
|
+
contractAddress,
|
|
178
|
+
scopes: [scope],
|
|
179
|
+
fromBlock: 0,
|
|
180
|
+
toBlock: (await this.getLastBlockNumber()) + 1,
|
|
181
|
+
})
|
|
182
|
+
).map(e => e.packedEvent);
|
|
183
|
+
}
|
|
184
|
+
|
|
161
185
|
async txeAdvanceBlocksBy(blocks: number) {
|
|
162
186
|
this.logger.debug(`time traveling ${blocks} blocks`);
|
|
163
187
|
|
|
@@ -185,8 +209,8 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
185
209
|
if (!secret.equals(Fr.ZERO)) {
|
|
186
210
|
await this.txeAddAccount(artifact, instance, secret);
|
|
187
211
|
} else {
|
|
188
|
-
await this.
|
|
189
|
-
await this.
|
|
212
|
+
await this.contractStore.addContractInstance(instance);
|
|
213
|
+
await this.contractStore.addContractArtifact(instance.currentContractClassId, artifact);
|
|
190
214
|
this.logger.debug(`Deployed ${artifact.name} at ${instance.address}`);
|
|
191
215
|
}
|
|
192
216
|
}
|
|
@@ -195,29 +219,29 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
195
219
|
const partialAddress = await computePartialAddress(instance);
|
|
196
220
|
|
|
197
221
|
this.logger.debug(`Deployed ${artifact.name} at ${instance.address}`);
|
|
198
|
-
await this.
|
|
199
|
-
await this.
|
|
222
|
+
await this.contractStore.addContractInstance(instance);
|
|
223
|
+
await this.contractStore.addContractArtifact(instance.currentContractClassId, artifact);
|
|
200
224
|
|
|
201
225
|
const completeAddress = await this.keyStore.addAccount(secret, partialAddress);
|
|
202
|
-
await this.
|
|
203
|
-
await this.
|
|
226
|
+
await this.accountStore.setAccount(completeAddress.address, completeAddress);
|
|
227
|
+
await this.addressStore.addCompleteAddress(completeAddress);
|
|
204
228
|
this.logger.debug(`Created account ${completeAddress.address}`);
|
|
205
229
|
|
|
206
230
|
return completeAddress;
|
|
207
231
|
}
|
|
208
232
|
|
|
209
233
|
async txeCreateAccount(secret: Fr) {
|
|
210
|
-
// This is a
|
|
234
|
+
// This is a foot gun !
|
|
211
235
|
const completeAddress = await this.keyStore.addAccount(secret, secret);
|
|
212
|
-
await this.
|
|
213
|
-
await this.
|
|
236
|
+
await this.accountStore.setAccount(completeAddress.address, completeAddress);
|
|
237
|
+
await this.addressStore.addCompleteAddress(completeAddress);
|
|
214
238
|
this.logger.debug(`Created account ${completeAddress.address}`);
|
|
215
239
|
|
|
216
240
|
return completeAddress;
|
|
217
241
|
}
|
|
218
242
|
|
|
219
243
|
async txeAddAuthWitness(address: AztecAddress, messageHash: Fr) {
|
|
220
|
-
const account = await this.
|
|
244
|
+
const account = await this.accountStore.getAccount(address);
|
|
221
245
|
const privateKey = await this.keyStore.getMasterSecretKey(account.publicKeys.masterIncomingViewingPublicKey);
|
|
222
246
|
|
|
223
247
|
const schnorr = new Schnorr();
|
|
@@ -238,19 +262,13 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
238
262
|
const forkedWorldTrees = await this.stateMachine.synchronizer.nativeWorldStateService.fork();
|
|
239
263
|
await insertTxEffectIntoWorldTrees(txEffect, forkedWorldTrees);
|
|
240
264
|
|
|
241
|
-
const
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
version: this.version,
|
|
249
|
-
chainId: this.chainId,
|
|
250
|
-
}),
|
|
251
|
-
),
|
|
252
|
-
new Body([txEffect]),
|
|
253
|
-
);
|
|
265
|
+
const globals = makeGlobalVariables(undefined, {
|
|
266
|
+
blockNumber,
|
|
267
|
+
timestamp: this.nextBlockTimestamp,
|
|
268
|
+
version: this.version,
|
|
269
|
+
chainId: this.chainId,
|
|
270
|
+
});
|
|
271
|
+
const block = await makeTXEBlock(forkedWorldTrees, globals, [txEffect]);
|
|
254
272
|
|
|
255
273
|
await forkedWorldTrees.close();
|
|
256
274
|
|
|
@@ -268,10 +286,10 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
268
286
|
isStaticCall: boolean = false,
|
|
269
287
|
) {
|
|
270
288
|
this.logger.verbose(
|
|
271
|
-
`Executing external function ${await this.
|
|
289
|
+
`Executing external function ${await this.contractStore.getDebugFunctionName(targetContractAddress, functionSelector)}@${targetContractAddress} isStaticCall=${isStaticCall}`,
|
|
272
290
|
);
|
|
273
291
|
|
|
274
|
-
const artifact = await this.
|
|
292
|
+
const artifact = await this.contractStore.getFunctionArtifact(targetContractAddress, functionSelector);
|
|
275
293
|
if (!artifact) {
|
|
276
294
|
const message = functionSelector.equals(await FunctionSelector.fromSignature('verify_private_authwit(Field)'))
|
|
277
295
|
? 'Found no account contract artifact for a private authwit check - use `create_contract_account` instead of `create_light_account` for authwit support.'
|
|
@@ -279,22 +297,32 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
279
297
|
throw new Error(message);
|
|
280
298
|
}
|
|
281
299
|
|
|
300
|
+
// Sync notes before executing private function to discover notes from previous transactions
|
|
301
|
+
const utilityExecutor = async (call: FunctionCall) => {
|
|
302
|
+
await this.executeUtilityCall(call);
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
await syncState(targetContractAddress, this.contractStore, functionSelector, utilityExecutor);
|
|
306
|
+
|
|
282
307
|
const blockNumber = await this.txeGetNextBlockNumber();
|
|
283
308
|
|
|
284
309
|
const callContext = new CallContext(from, targetContractAddress, functionSelector, isStaticCall);
|
|
285
310
|
|
|
286
311
|
const gasLimits = new Gas(DEFAULT_DA_GAS_LIMIT, DEFAULT_L2_GAS_LIMIT);
|
|
287
|
-
|
|
288
312
|
const teardownGasLimits = new Gas(DEFAULT_TEARDOWN_DA_GAS_LIMIT, DEFAULT_TEARDOWN_L2_GAS_LIMIT);
|
|
289
|
-
|
|
290
313
|
const gasSettings = new GasSettings(gasLimits, teardownGasLimits, GasFees.empty(), GasFees.empty());
|
|
291
314
|
|
|
292
315
|
const txContext = new TxContext(this.chainId, this.version, gasSettings);
|
|
293
316
|
|
|
294
|
-
const blockHeader = await this.
|
|
317
|
+
const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
295
318
|
|
|
296
319
|
const protocolNullifier = await computeProtocolNullifier(getSingleTxBlockRequestHash(blockNumber));
|
|
297
320
|
const noteCache = new ExecutionNoteCache(protocolNullifier);
|
|
321
|
+
// In production, the account contract sets the min revertible counter before calling the app function.
|
|
322
|
+
// Since TXE bypasses the account contract, we simulate this by setting minRevertibleSideEffectCounter to 1,
|
|
323
|
+
// marking all side effects as revertible.
|
|
324
|
+
const minRevertibleSideEffectCounter = 1;
|
|
325
|
+
await noteCache.setMinRevertibleSideEffectCounter(minRevertibleSideEffectCounter);
|
|
298
326
|
const taggingIndexCache = new ExecutionTaggingIndexCache();
|
|
299
327
|
|
|
300
328
|
const simulator = new WASMSimulator();
|
|
@@ -305,6 +333,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
305
333
|
callContext,
|
|
306
334
|
/** Header of a block whose state is used during private execution (not the block the transaction is included in). */
|
|
307
335
|
blockHeader,
|
|
336
|
+
utilityExecutor,
|
|
308
337
|
/** List of transient auth witnesses to be used during this simulation */
|
|
309
338
|
Array.from(this.authwits.values()),
|
|
310
339
|
/** List of transient auth witnesses to be used during this simulation */
|
|
@@ -312,9 +341,20 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
312
341
|
HashedValuesCache.create([new HashedValues(args, argsHash)]),
|
|
313
342
|
noteCache,
|
|
314
343
|
taggingIndexCache,
|
|
315
|
-
this.
|
|
316
|
-
|
|
317
|
-
|
|
344
|
+
this.contractStore,
|
|
345
|
+
this.noteStore,
|
|
346
|
+
this.keyStore,
|
|
347
|
+
this.addressStore,
|
|
348
|
+
this.stateMachine.node,
|
|
349
|
+
this.stateMachine.anchorBlockStore,
|
|
350
|
+
this.senderTaggingStore,
|
|
351
|
+
this.recipientTaggingStore,
|
|
352
|
+
this.senderAddressBookStore,
|
|
353
|
+
this.capsuleStore,
|
|
354
|
+
this.privateEventStore,
|
|
355
|
+
this.jobId,
|
|
356
|
+
0, // totalPublicArgsCount
|
|
357
|
+
minRevertibleSideEffectCounter, // (start) sideEffectCounter
|
|
318
358
|
undefined, // log
|
|
319
359
|
undefined, // scopes
|
|
320
360
|
/**
|
|
@@ -350,19 +390,21 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
350
390
|
}),
|
|
351
391
|
);
|
|
352
392
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
result = new PrivateExecutionResult(executionResult, Fr.ZERO, publicFunctionsCalldata);
|
|
393
|
+
noteCache.finish();
|
|
394
|
+
const nonceGenerator = noteCache.getNonceGenerator();
|
|
395
|
+
result = new PrivateExecutionResult(executionResult, nonceGenerator, publicFunctionsCalldata);
|
|
357
396
|
} catch (err) {
|
|
358
397
|
throw createSimulationError(err instanceof Error ? err : new Error('Unknown error during private execution'));
|
|
359
398
|
}
|
|
360
399
|
|
|
361
|
-
// According to the protocol rules,
|
|
362
|
-
//
|
|
363
|
-
//
|
|
364
|
-
const
|
|
365
|
-
|
|
400
|
+
// According to the protocol rules, there must be at least one nullifier in the tx. The first nullifier is used as
|
|
401
|
+
// the nonce generator for the note hashes.
|
|
402
|
+
// We pass the non-zero minRevertibleSideEffectCounter to make sure the side effects are split correctly.
|
|
403
|
+
const { publicInputs } = await generateSimulatedProvingResult(
|
|
404
|
+
result,
|
|
405
|
+
this.contractStore,
|
|
406
|
+
minRevertibleSideEffectCounter,
|
|
407
|
+
);
|
|
366
408
|
|
|
367
409
|
const globals = makeGlobalVariables();
|
|
368
410
|
globals.blockNumber = blockNumber;
|
|
@@ -373,7 +415,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
373
415
|
|
|
374
416
|
const forkedWorldTrees = await this.stateMachine.synchronizer.nativeWorldStateService.fork();
|
|
375
417
|
|
|
376
|
-
const contractsDB = new PublicContractsDB(new TXEPublicContractDataSource(blockNumber, this.
|
|
418
|
+
const contractsDB = new PublicContractsDB(new TXEPublicContractDataSource(blockNumber, this.contractStore));
|
|
377
419
|
const guardedMerkleTrees = new GuardedMerkleTreeOperations(forkedWorldTrees);
|
|
378
420
|
const config = PublicSimulatorConfig.from({
|
|
379
421
|
skipFeeEnforcement: true,
|
|
@@ -412,7 +454,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
412
454
|
} else if (!processedTx.revertCode.isOK()) {
|
|
413
455
|
if (processedTx.revertReason) {
|
|
414
456
|
try {
|
|
415
|
-
await enrichPublicSimulationError(processedTx.revertReason, this.
|
|
457
|
+
await enrichPublicSimulationError(processedTx.revertReason, this.contractStore, this.logger);
|
|
416
458
|
// eslint-disable-next-line no-empty
|
|
417
459
|
} catch {}
|
|
418
460
|
throw new Error(`Contract execution has reverted: ${processedTx.revertReason.getMessage()}`);
|
|
@@ -441,13 +483,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
441
483
|
const l1ToL2Messages = Array(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP).fill(0).map(Fr.zero);
|
|
442
484
|
await forkedWorldTrees.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, l1ToL2Messages);
|
|
443
485
|
|
|
444
|
-
const
|
|
445
|
-
|
|
446
|
-
const l2Block = new L2Block(
|
|
447
|
-
makeAppendOnlyTreeSnapshot(),
|
|
448
|
-
await makeTXEBlockHeader(forkedWorldTrees, globals),
|
|
449
|
-
body,
|
|
450
|
-
);
|
|
486
|
+
const l2Block = await makeTXEBlock(forkedWorldTrees, globals, [txEffect]);
|
|
451
487
|
|
|
452
488
|
await this.stateMachine.handleL2Block(l2Block);
|
|
453
489
|
|
|
@@ -463,7 +499,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
463
499
|
isStaticCall: boolean,
|
|
464
500
|
) {
|
|
465
501
|
this.logger.verbose(
|
|
466
|
-
`Executing public function ${await this.
|
|
502
|
+
`Executing public function ${await this.contractStore.getDebugFunctionName(targetContractAddress, FunctionSelector.fromField(calldata[0]))}@${targetContractAddress} isStaticCall=${isStaticCall}`,
|
|
467
503
|
);
|
|
468
504
|
|
|
469
505
|
const blockNumber = await this.txeGetNextBlockNumber();
|
|
@@ -476,7 +512,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
476
512
|
|
|
477
513
|
const txContext = new TxContext(this.chainId, this.version, gasSettings);
|
|
478
514
|
|
|
479
|
-
const anchorBlockHeader = await this.
|
|
515
|
+
const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
480
516
|
|
|
481
517
|
const calldataHash = await computeCalldataHash(calldata);
|
|
482
518
|
const calldataHashedValues = new HashedValues(calldata, calldataHash);
|
|
@@ -490,7 +526,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
490
526
|
|
|
491
527
|
const forkedWorldTrees = await this.stateMachine.synchronizer.nativeWorldStateService.fork();
|
|
492
528
|
|
|
493
|
-
const contractsDB = new PublicContractsDB(new TXEPublicContractDataSource(blockNumber, this.
|
|
529
|
+
const contractsDB = new PublicContractsDB(new TXEPublicContractDataSource(blockNumber, this.contractStore));
|
|
494
530
|
const guardedMerkleTrees = new GuardedMerkleTreeOperations(forkedWorldTrees);
|
|
495
531
|
const config = PublicSimulatorConfig.from({
|
|
496
532
|
skipFeeEnforcement: true,
|
|
@@ -558,7 +594,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
558
594
|
} else if (!processedTx.revertCode.isOK()) {
|
|
559
595
|
if (processedTx.revertReason) {
|
|
560
596
|
try {
|
|
561
|
-
await enrichPublicSimulationError(processedTx.revertReason, this.
|
|
597
|
+
await enrichPublicSimulationError(processedTx.revertReason, this.contractStore, this.logger);
|
|
562
598
|
// eslint-disable-next-line no-empty
|
|
563
599
|
} catch {}
|
|
564
600
|
throw new Error(`Contract execution has reverted: ${processedTx.revertReason.getMessage()}`);
|
|
@@ -590,13 +626,7 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
590
626
|
const l1ToL2Messages = Array(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP).fill(0).map(Fr.zero);
|
|
591
627
|
await forkedWorldTrees.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, l1ToL2Messages);
|
|
592
628
|
|
|
593
|
-
const
|
|
594
|
-
|
|
595
|
-
const l2Block = new L2Block(
|
|
596
|
-
makeAppendOnlyTreeSnapshot(),
|
|
597
|
-
await makeTXEBlockHeader(forkedWorldTrees, globals),
|
|
598
|
-
body,
|
|
599
|
-
);
|
|
629
|
+
const l2Block = await makeTXEBlock(forkedWorldTrees, globals, [txEffect]);
|
|
600
630
|
|
|
601
631
|
await this.stateMachine.handleL2Block(l2Block);
|
|
602
632
|
|
|
@@ -610,18 +640,32 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
610
640
|
functionSelector: FunctionSelector,
|
|
611
641
|
args: Fr[],
|
|
612
642
|
) {
|
|
613
|
-
const artifact = await this.
|
|
643
|
+
const artifact = await this.contractStore.getFunctionArtifact(targetContractAddress, functionSelector);
|
|
614
644
|
if (!artifact) {
|
|
615
645
|
throw new Error(`Cannot call ${functionSelector} as there is no artifact found at ${targetContractAddress}.`);
|
|
616
646
|
}
|
|
617
647
|
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
};
|
|
648
|
+
// Sync notes before executing utility function to discover notes from previous transactions
|
|
649
|
+
await syncState(targetContractAddress, this.contractStore, functionSelector, async call => {
|
|
650
|
+
await this.executeUtilityCall(call);
|
|
651
|
+
});
|
|
623
652
|
|
|
624
|
-
const
|
|
653
|
+
const call = new FunctionCall(
|
|
654
|
+
artifact.name,
|
|
655
|
+
targetContractAddress,
|
|
656
|
+
functionSelector,
|
|
657
|
+
FunctionType.UTILITY,
|
|
658
|
+
false,
|
|
659
|
+
false,
|
|
660
|
+
args,
|
|
661
|
+
[],
|
|
662
|
+
);
|
|
663
|
+
|
|
664
|
+
return this.executeUtilityCall(call);
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
private async executeUtilityCall(call: FunctionCall): Promise<Fr[]> {
|
|
668
|
+
const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
|
|
625
669
|
if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
|
|
626
670
|
throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
|
|
627
671
|
}
|
|
@@ -632,9 +676,26 @@ export class TXEOracleTopLevelContext implements IMiscOracle, ITxeExecutionOracl
|
|
|
632
676
|
});
|
|
633
677
|
|
|
634
678
|
try {
|
|
635
|
-
const
|
|
679
|
+
const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
680
|
+
const oracle = new UtilityExecutionOracle(
|
|
681
|
+
call.to,
|
|
682
|
+
[],
|
|
683
|
+
[],
|
|
684
|
+
anchorBlockHeader,
|
|
685
|
+
this.contractStore,
|
|
686
|
+
this.noteStore,
|
|
687
|
+
this.keyStore,
|
|
688
|
+
this.addressStore,
|
|
689
|
+
this.stateMachine.node,
|
|
690
|
+
this.stateMachine.anchorBlockStore,
|
|
691
|
+
this.recipientTaggingStore,
|
|
692
|
+
this.senderAddressBookStore,
|
|
693
|
+
this.capsuleStore,
|
|
694
|
+
this.privateEventStore,
|
|
695
|
+
this.jobId,
|
|
696
|
+
);
|
|
636
697
|
const acirExecutionResult = await new WASMSimulator()
|
|
637
|
-
.executeUserCircuit(toACVMWitness(0, args), entryPointArtifact, new Oracle(oracle).toACIRCallback())
|
|
698
|
+
.executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, new Oracle(oracle).toACIRCallback())
|
|
638
699
|
.catch((err: Error) => {
|
|
639
700
|
err.message = resolveAssertionMessageFromError(err, entryPointArtifact);
|
|
640
701
|
throw new ExecutionError(
|