@aztec/txe 0.0.1-commit.3469e52 → 0.0.1-commit.35158ae7e
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 +23 -23
- package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_top_level_context.js +130 -54
- package/dest/rpc_translator.d.ts +92 -81
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +315 -169
- 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 +8 -9
- package/dest/state_machine/dummy_p2p_client.d.ts +16 -12
- package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
- package/dest/state_machine/dummy_p2p_client.js +28 -16
- 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 +35 -17
- package/dest/state_machine/mock_epoch_cache.d.ts +22 -4
- package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
- package/dest/state_machine/mock_epoch_cache.js +38 -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 +97 -28
- package/dest/util/encoding.d.ts +69 -1
- package/dest/util/encoding.d.ts.map +1 -1
- 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 +160 -102
- package/src/rpc_translator.ts +349 -185
- package/src/state_machine/archiver.ts +9 -11
- package/src/state_machine/dummy_p2p_client.ts +40 -22
- package/src/state_machine/index.ts +54 -19
- package/src/state_machine/mock_epoch_cache.ts +49 -4
- package/src/state_machine/synchronizer.ts +5 -5
- package/src/txe_session.ts +115 -86
- 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
|
@@ -36,15 +36,15 @@ export class TXEOracleTopLevelContext {
|
|
|
36
36
|
senderAddressBookStore;
|
|
37
37
|
capsuleStore;
|
|
38
38
|
privateEventStore;
|
|
39
|
-
jobId;
|
|
40
39
|
nextBlockTimestamp;
|
|
41
40
|
version;
|
|
42
41
|
chainId;
|
|
43
42
|
authwits;
|
|
43
|
+
contractSyncService;
|
|
44
44
|
isMisc;
|
|
45
45
|
isTxe;
|
|
46
46
|
logger;
|
|
47
|
-
constructor(stateMachine, contractStore, noteStore, keyStore, addressStore, accountStore, senderTaggingStore, recipientTaggingStore, senderAddressBookStore, capsuleStore, privateEventStore,
|
|
47
|
+
constructor(stateMachine, contractStore, noteStore, keyStore, addressStore, accountStore, senderTaggingStore, recipientTaggingStore, senderAddressBookStore, capsuleStore, privateEventStore, nextBlockTimestamp, version, chainId, authwits, contractSyncService){
|
|
48
48
|
this.stateMachine = stateMachine;
|
|
49
49
|
this.contractStore = contractStore;
|
|
50
50
|
this.noteStore = noteStore;
|
|
@@ -56,49 +56,50 @@ export class TXEOracleTopLevelContext {
|
|
|
56
56
|
this.senderAddressBookStore = senderAddressBookStore;
|
|
57
57
|
this.capsuleStore = capsuleStore;
|
|
58
58
|
this.privateEventStore = privateEventStore;
|
|
59
|
-
this.jobId = jobId;
|
|
60
59
|
this.nextBlockTimestamp = nextBlockTimestamp;
|
|
61
60
|
this.version = version;
|
|
62
61
|
this.chainId = chainId;
|
|
63
62
|
this.authwits = authwits;
|
|
63
|
+
this.contractSyncService = contractSyncService;
|
|
64
64
|
this.isMisc = true;
|
|
65
65
|
this.isTxe = true;
|
|
66
66
|
this.logger = createLogger('txe:top_level_context');
|
|
67
67
|
this.logger.debug('Entering Top Level Context');
|
|
68
68
|
}
|
|
69
|
-
|
|
69
|
+
assertCompatibleOracleVersion(version) {
|
|
70
70
|
if (version !== ORACLE_VERSION) {
|
|
71
71
|
throw new Error(`Incompatible oracle version. TXE is using version '${ORACLE_VERSION}', but got a request for '${version}'.`);
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
// This is typically only invoked in private contexts, but it is convenient to also have it in top-level for testing
|
|
75
75
|
// setup.
|
|
76
|
-
|
|
76
|
+
getRandomField() {
|
|
77
77
|
return Fr.random();
|
|
78
78
|
}
|
|
79
79
|
// We instruct users to debug contracts via this oracle, so it makes sense that they'd expect it to also work in tests
|
|
80
|
-
|
|
80
|
+
log(level, message, fields) {
|
|
81
81
|
if (!LogLevels[level]) {
|
|
82
|
-
throw new Error(`Invalid
|
|
82
|
+
throw new Error(`Invalid log level: ${level}`);
|
|
83
83
|
}
|
|
84
84
|
const levelName = LogLevels[level];
|
|
85
85
|
this.logger[levelName](`${applyStringFormatting(message, fields)}`, {
|
|
86
86
|
module: `${this.logger.module}:debug_log`
|
|
87
87
|
});
|
|
88
|
+
return Promise.resolve();
|
|
88
89
|
}
|
|
89
|
-
|
|
90
|
+
getDefaultAddress() {
|
|
90
91
|
return DEFAULT_ADDRESS;
|
|
91
92
|
}
|
|
92
|
-
async
|
|
93
|
+
async getNextBlockNumber() {
|
|
93
94
|
return BlockNumber(await this.getLastBlockNumber() + 1);
|
|
94
95
|
}
|
|
95
|
-
|
|
96
|
+
getNextBlockTimestamp() {
|
|
96
97
|
return Promise.resolve(this.nextBlockTimestamp);
|
|
97
98
|
}
|
|
98
|
-
async
|
|
99
|
+
async getLastBlockTimestamp() {
|
|
99
100
|
return (await this.stateMachine.node.getBlockHeader('latest')).globalVariables.timestamp;
|
|
100
101
|
}
|
|
101
|
-
async
|
|
102
|
+
async getLastTxEffects() {
|
|
102
103
|
const latestBlockNumber = await this.stateMachine.archiver.getBlockNumber();
|
|
103
104
|
const block = await this.stateMachine.archiver.getBlock(latestBlockNumber);
|
|
104
105
|
if (block.body.txEffects.length != 1) {
|
|
@@ -112,7 +113,19 @@ export class TXEOracleTopLevelContext {
|
|
|
112
113
|
nullifiers: txEffects.nullifiers
|
|
113
114
|
};
|
|
114
115
|
}
|
|
115
|
-
async
|
|
116
|
+
async syncContractNonOracleMethod(contractAddress, scope, jobId) {
|
|
117
|
+
if (contractAddress.equals(DEFAULT_ADDRESS)) {
|
|
118
|
+
this.logger.debug(`Skipping sync in getPrivateEvents because the events correspond to the default address.`);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
122
|
+
await this.stateMachine.contractSyncService.ensureContractSynced(contractAddress, null, async (call, execScopes)=>{
|
|
123
|
+
await this.executeUtilityCall(call, execScopes, jobId);
|
|
124
|
+
}, blockHeader, jobId, [
|
|
125
|
+
scope
|
|
126
|
+
]);
|
|
127
|
+
}
|
|
128
|
+
async getPrivateEvents(selector, contractAddress, scope) {
|
|
116
129
|
return (await this.privateEventStore.getPrivateEvents(selector, {
|
|
117
130
|
contractAddress,
|
|
118
131
|
scopes: [
|
|
@@ -122,17 +135,17 @@ export class TXEOracleTopLevelContext {
|
|
|
122
135
|
toBlock: await this.getLastBlockNumber() + 1
|
|
123
136
|
})).map((e)=>e.packedEvent);
|
|
124
137
|
}
|
|
125
|
-
async
|
|
138
|
+
async advanceBlocksBy(blocks) {
|
|
126
139
|
this.logger.debug(`time traveling ${blocks} blocks`);
|
|
127
140
|
for(let i = 0; i < blocks; i++){
|
|
128
141
|
await this.mineBlock();
|
|
129
142
|
}
|
|
130
143
|
}
|
|
131
|
-
|
|
144
|
+
advanceTimestampBy(duration) {
|
|
132
145
|
this.logger.debug(`time traveling ${duration} seconds`);
|
|
133
146
|
this.nextBlockTimestamp += duration;
|
|
134
147
|
}
|
|
135
|
-
async
|
|
148
|
+
async deploy(artifact, instance, secret) {
|
|
136
149
|
// Emit deployment nullifier
|
|
137
150
|
await this.mineBlock({
|
|
138
151
|
nullifiers: [
|
|
@@ -140,25 +153,25 @@ export class TXEOracleTopLevelContext {
|
|
|
140
153
|
]
|
|
141
154
|
});
|
|
142
155
|
if (!secret.equals(Fr.ZERO)) {
|
|
143
|
-
await this.
|
|
156
|
+
await this.addAccount(artifact, instance, secret);
|
|
144
157
|
} else {
|
|
145
158
|
await this.contractStore.addContractInstance(instance);
|
|
146
|
-
await this.contractStore.addContractArtifact(
|
|
159
|
+
await this.contractStore.addContractArtifact(artifact);
|
|
147
160
|
this.logger.debug(`Deployed ${artifact.name} at ${instance.address}`);
|
|
148
161
|
}
|
|
149
162
|
}
|
|
150
|
-
async
|
|
163
|
+
async addAccount(artifact, instance, secret) {
|
|
151
164
|
const partialAddress = await computePartialAddress(instance);
|
|
152
165
|
this.logger.debug(`Deployed ${artifact.name} at ${instance.address}`);
|
|
153
166
|
await this.contractStore.addContractInstance(instance);
|
|
154
|
-
await this.contractStore.addContractArtifact(
|
|
167
|
+
await this.contractStore.addContractArtifact(artifact);
|
|
155
168
|
const completeAddress = await this.keyStore.addAccount(secret, partialAddress);
|
|
156
169
|
await this.accountStore.setAccount(completeAddress.address, completeAddress);
|
|
157
170
|
await this.addressStore.addCompleteAddress(completeAddress);
|
|
158
171
|
this.logger.debug(`Created account ${completeAddress.address}`);
|
|
159
172
|
return completeAddress;
|
|
160
173
|
}
|
|
161
|
-
async
|
|
174
|
+
async createAccount(secret) {
|
|
162
175
|
// This is a foot gun !
|
|
163
176
|
const completeAddress = await this.keyStore.addAccount(secret, secret);
|
|
164
177
|
await this.accountStore.setAccount(completeAddress.address, completeAddress);
|
|
@@ -166,7 +179,7 @@ export class TXEOracleTopLevelContext {
|
|
|
166
179
|
this.logger.debug(`Created account ${completeAddress.address}`);
|
|
167
180
|
return completeAddress;
|
|
168
181
|
}
|
|
169
|
-
async
|
|
182
|
+
async addAuthWitness(address, messageHash) {
|
|
170
183
|
const account = await this.accountStore.getAccount(address);
|
|
171
184
|
const privateKey = await this.keyStore.getMasterSecretKey(account.publicKeys.masterIncomingViewingPublicKey);
|
|
172
185
|
const schnorr = new Schnorr();
|
|
@@ -177,7 +190,7 @@ export class TXEOracleTopLevelContext {
|
|
|
177
190
|
this.authwits.set(authWitness.requestHash.toString(), authWitness);
|
|
178
191
|
}
|
|
179
192
|
async mineBlock(options = {}) {
|
|
180
|
-
const blockNumber = await this.
|
|
193
|
+
const blockNumber = await this.getNextBlockNumber();
|
|
181
194
|
const txEffect = TxEffect.empty();
|
|
182
195
|
txEffect.nullifiers = [
|
|
183
196
|
getSingleTxBlockRequestHash(blockNumber),
|
|
@@ -199,25 +212,30 @@ export class TXEOracleTopLevelContext {
|
|
|
199
212
|
this.logger.info(`Created block ${blockNumber} with timestamp ${block.header.globalVariables.timestamp}`);
|
|
200
213
|
await this.stateMachine.handleL2Block(block);
|
|
201
214
|
}
|
|
202
|
-
async
|
|
215
|
+
async privateCallNewFlow(from, targetContractAddress = AztecAddress.zero(), functionSelector = FunctionSelector.empty(), args, argsHash = Fr.zero(), isStaticCall = false, jobId) {
|
|
203
216
|
this.logger.verbose(`Executing external function ${await this.contractStore.getDebugFunctionName(targetContractAddress, functionSelector)}@${targetContractAddress} isStaticCall=${isStaticCall}`);
|
|
204
217
|
const artifact = await this.contractStore.getFunctionArtifact(targetContractAddress, functionSelector);
|
|
205
218
|
if (!artifact) {
|
|
206
219
|
const message = functionSelector.equals(await FunctionSelector.fromSignature('verify_private_authwit(Field)')) ? 'Found no account contract artifact for a private authwit check - use `create_contract_account` instead of `create_light_account` for authwit support.' : 'Function Artifact does not exist';
|
|
207
220
|
throw new Error(message);
|
|
208
221
|
}
|
|
222
|
+
// When `from` is the zero address (e.g. when deploying a new account contract), we return an
|
|
223
|
+
// empty scope list which acts as deny-all: no notes are visible and no keys are accessible.
|
|
224
|
+
const effectiveScopes = from.isZero() ? [] : [
|
|
225
|
+
from
|
|
226
|
+
];
|
|
209
227
|
// Sync notes before executing private function to discover notes from previous transactions
|
|
210
|
-
const utilityExecutor = async (call)=>{
|
|
211
|
-
await this.executeUtilityCall(call);
|
|
228
|
+
const utilityExecutor = async (call, execScopes)=>{
|
|
229
|
+
await this.executeUtilityCall(call, execScopes, jobId);
|
|
212
230
|
};
|
|
213
|
-
await this.
|
|
214
|
-
|
|
231
|
+
const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
232
|
+
await this.stateMachine.contractSyncService.ensureContractSynced(targetContractAddress, functionSelector, utilityExecutor, blockHeader, jobId, effectiveScopes);
|
|
233
|
+
const blockNumber = await this.getNextBlockNumber();
|
|
215
234
|
const callContext = new CallContext(from, targetContractAddress, functionSelector, isStaticCall);
|
|
216
235
|
const gasLimits = new Gas(DEFAULT_DA_GAS_LIMIT, DEFAULT_L2_GAS_LIMIT);
|
|
217
236
|
const teardownGasLimits = new Gas(DEFAULT_TEARDOWN_DA_GAS_LIMIT, DEFAULT_TEARDOWN_L2_GAS_LIMIT);
|
|
218
237
|
const gasSettings = new GasSettings(gasLimits, teardownGasLimits, GasFees.empty(), GasFees.empty());
|
|
219
238
|
const txContext = new TxContext(this.chainId, this.version, gasSettings);
|
|
220
|
-
const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
221
239
|
const protocolNullifier = await computeProtocolNullifier(getSingleTxBlockRequestHash(blockNumber));
|
|
222
240
|
const noteCache = new ExecutionNoteCache(protocolNullifier);
|
|
223
241
|
// In production, the account contract sets the min revertible counter before calling the app function.
|
|
@@ -227,12 +245,40 @@ export class TXEOracleTopLevelContext {
|
|
|
227
245
|
await noteCache.setMinRevertibleSideEffectCounter(minRevertibleSideEffectCounter);
|
|
228
246
|
const taggingIndexCache = new ExecutionTaggingIndexCache();
|
|
229
247
|
const simulator = new WASMSimulator();
|
|
230
|
-
const privateExecutionOracle = new PrivateExecutionOracle(
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
248
|
+
const privateExecutionOracle = new PrivateExecutionOracle({
|
|
249
|
+
argsHash,
|
|
250
|
+
txContext,
|
|
251
|
+
callContext,
|
|
252
|
+
anchorBlockHeader: blockHeader,
|
|
253
|
+
utilityExecutor,
|
|
254
|
+
authWitnesses: Array.from(this.authwits.values()),
|
|
255
|
+
capsules: [],
|
|
256
|
+
executionCache: HashedValuesCache.create([
|
|
257
|
+
new HashedValues(args, argsHash)
|
|
258
|
+
]),
|
|
259
|
+
noteCache,
|
|
260
|
+
taggingIndexCache,
|
|
261
|
+
contractStore: this.contractStore,
|
|
262
|
+
noteStore: this.noteStore,
|
|
263
|
+
keyStore: this.keyStore,
|
|
264
|
+
addressStore: this.addressStore,
|
|
265
|
+
aztecNode: this.stateMachine.node,
|
|
266
|
+
senderTaggingStore: this.senderTaggingStore,
|
|
267
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
268
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
269
|
+
capsuleStore: this.capsuleStore,
|
|
270
|
+
privateEventStore: this.privateEventStore,
|
|
271
|
+
contractSyncService: this.stateMachine.contractSyncService,
|
|
272
|
+
jobId,
|
|
273
|
+
totalPublicCalldataCount: 0,
|
|
274
|
+
sideEffectCounter: minRevertibleSideEffectCounter,
|
|
275
|
+
scopes: effectiveScopes,
|
|
276
|
+
// In TXE, the typical transaction entrypoint is skipped, so we need to simulate the actions that such a
|
|
277
|
+
// contract would perform, including setting senderForTags.
|
|
278
|
+
senderForTags: from,
|
|
279
|
+
simulator,
|
|
280
|
+
messageContextService: this.stateMachine.messageContextService
|
|
281
|
+
});
|
|
236
282
|
// 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.
|
|
237
283
|
let result;
|
|
238
284
|
let executionResult;
|
|
@@ -244,7 +290,7 @@ export class TXEOracleTopLevelContext {
|
|
|
244
290
|
r.publicInputs.publicTeardownCallRequest
|
|
245
291
|
]));
|
|
246
292
|
const publicFunctionsCalldata = await Promise.all(publicCallRequests.map(async (r)=>{
|
|
247
|
-
const calldata = await privateExecutionOracle.
|
|
293
|
+
const calldata = await privateExecutionOracle.loadFromExecutionCache(r.calldataHash);
|
|
248
294
|
return new HashedValues(calldata, r.calldataHash);
|
|
249
295
|
}));
|
|
250
296
|
noteCache.finish();
|
|
@@ -256,7 +302,7 @@ export class TXEOracleTopLevelContext {
|
|
|
256
302
|
// According to the protocol rules, there must be at least one nullifier in the tx. The first nullifier is used as
|
|
257
303
|
// the nonce generator for the note hashes.
|
|
258
304
|
// We pass the non-zero minRevertibleSideEffectCounter to make sure the side effects are split correctly.
|
|
259
|
-
const { publicInputs } = await generateSimulatedProvingResult(result, this.contractStore, minRevertibleSideEffectCounter);
|
|
305
|
+
const { publicInputs } = await generateSimulatedProvingResult(result, (addr, sel)=>this.contractStore.getDebugFunctionName(addr, sel), this.stateMachine.node, minRevertibleSideEffectCounter);
|
|
260
306
|
const globals = makeGlobalVariables();
|
|
261
307
|
globals.blockNumber = blockNumber;
|
|
262
308
|
globals.timestamp = this.nextBlockTimestamp;
|
|
@@ -264,7 +310,8 @@ export class TXEOracleTopLevelContext {
|
|
|
264
310
|
globals.version = this.version;
|
|
265
311
|
globals.gasFees = GasFees.empty();
|
|
266
312
|
const forkedWorldTrees = await this.stateMachine.synchronizer.nativeWorldStateService.fork();
|
|
267
|
-
const
|
|
313
|
+
const bindings = this.logger.getBindings();
|
|
314
|
+
const contractsDB = new PublicContractsDB(new TXEPublicContractDataSource(blockNumber, this.contractStore), bindings);
|
|
268
315
|
const guardedMerkleTrees = new GuardedMerkleTreeOperations(forkedWorldTrees);
|
|
269
316
|
const config = PublicSimulatorConfig.from({
|
|
270
317
|
skipFeeEnforcement: true,
|
|
@@ -273,7 +320,7 @@ export class TXEOracleTopLevelContext {
|
|
|
273
320
|
collectStatistics: false,
|
|
274
321
|
collectCallMetadata: true
|
|
275
322
|
});
|
|
276
|
-
const processor = new PublicProcessor(globals, guardedMerkleTrees, contractsDB, new CppPublicTxSimulator(guardedMerkleTrees, contractsDB, globals, config), new TestDateProvider());
|
|
323
|
+
const processor = new PublicProcessor(globals, guardedMerkleTrees, contractsDB, new CppPublicTxSimulator(guardedMerkleTrees, contractsDB, globals, config, bindings), new TestDateProvider(), undefined, createLogger('simulator:public-processor', bindings));
|
|
277
324
|
const tx = await Tx.create({
|
|
278
325
|
data: publicInputs,
|
|
279
326
|
chonkProof: ChonkProof.empty(),
|
|
@@ -323,9 +370,9 @@ export class TXEOracleTopLevelContext {
|
|
|
323
370
|
await forkedWorldTrees.close();
|
|
324
371
|
return executionResult.returnValues ?? [];
|
|
325
372
|
}
|
|
326
|
-
async
|
|
373
|
+
async publicCallNewFlow(from, targetContractAddress, calldata, isStaticCall) {
|
|
327
374
|
this.logger.verbose(`Executing public function ${await this.contractStore.getDebugFunctionName(targetContractAddress, FunctionSelector.fromField(calldata[0]))}@${targetContractAddress} isStaticCall=${isStaticCall}`);
|
|
328
|
-
const blockNumber = await this.
|
|
375
|
+
const blockNumber = await this.getNextBlockNumber();
|
|
329
376
|
const gasLimits = new Gas(DEFAULT_DA_GAS_LIMIT, DEFAULT_L2_GAS_LIMIT);
|
|
330
377
|
const teardownGasLimits = new Gas(DEFAULT_TEARDOWN_DA_GAS_LIMIT, DEFAULT_TEARDOWN_L2_GAS_LIMIT);
|
|
331
378
|
const gasSettings = new GasSettings(gasLimits, teardownGasLimits, GasFees.empty(), GasFees.empty());
|
|
@@ -340,7 +387,8 @@ export class TXEOracleTopLevelContext {
|
|
|
340
387
|
globals.version = this.version;
|
|
341
388
|
globals.gasFees = GasFees.empty();
|
|
342
389
|
const forkedWorldTrees = await this.stateMachine.synchronizer.nativeWorldStateService.fork();
|
|
343
|
-
const
|
|
390
|
+
const bindings2 = this.logger.getBindings();
|
|
391
|
+
const contractsDB = new PublicContractsDB(new TXEPublicContractDataSource(blockNumber, this.contractStore), bindings2);
|
|
344
392
|
const guardedMerkleTrees = new GuardedMerkleTreeOperations(forkedWorldTrees);
|
|
345
393
|
const config = PublicSimulatorConfig.from({
|
|
346
394
|
skipFeeEnforcement: true,
|
|
@@ -349,8 +397,8 @@ export class TXEOracleTopLevelContext {
|
|
|
349
397
|
collectStatistics: false,
|
|
350
398
|
collectCallMetadata: true
|
|
351
399
|
});
|
|
352
|
-
const simulator = new CppPublicTxSimulator(guardedMerkleTrees, contractsDB, globals, config);
|
|
353
|
-
const processor = new PublicProcessor(globals, guardedMerkleTrees, contractsDB, simulator, new TestDateProvider());
|
|
400
|
+
const simulator = new CppPublicTxSimulator(guardedMerkleTrees, contractsDB, globals, config, bindings2);
|
|
401
|
+
const processor = new PublicProcessor(globals, guardedMerkleTrees, contractsDB, simulator, new TestDateProvider(), undefined, createLogger('simulator:public-processor', bindings2));
|
|
354
402
|
// We're simulating a scenario in which private execution immediately enqueues a public call and halts. The private
|
|
355
403
|
// kernel init would in this case inject a nullifier with the transaction request hash as a non-revertible
|
|
356
404
|
// side-effect, which the AVM then expects to exist in order to use it as the nonce generator when siloing notes as
|
|
@@ -363,7 +411,7 @@ export class TXEOracleTopLevelContext {
|
|
|
363
411
|
revertibleAccumulatedData.publicCallRequests[0] = new PublicCallRequest(from, targetContractAddress, isStaticCall, calldataHash);
|
|
364
412
|
const inputsForPublic = new PartialPrivateTailPublicInputsForPublic(nonRevertibleAccumulatedData, revertibleAccumulatedData, PublicCallRequest.empty());
|
|
365
413
|
const constantData = new TxConstantData(anchorBlockHeader, txContext, Fr.zero(), Fr.zero());
|
|
366
|
-
const txData = new PrivateKernelTailCircuitPublicInputs(constantData, /*gasUsed=*/ new Gas(0, 0), /*feePayer=*/ AztecAddress.zero(), /*
|
|
414
|
+
const txData = new PrivateKernelTailCircuitPublicInputs(constantData, /*gasUsed=*/ new Gas(0, 0), /*feePayer=*/ AztecAddress.zero(), /*expirationTimestamp=*/ 0n, inputsForPublic, undefined);
|
|
367
415
|
const tx = await Tx.create({
|
|
368
416
|
data: txData,
|
|
369
417
|
chonkProof: ChonkProof.empty(),
|
|
@@ -416,19 +464,29 @@ export class TXEOracleTopLevelContext {
|
|
|
416
464
|
await forkedWorldTrees.close();
|
|
417
465
|
return returnValues ?? [];
|
|
418
466
|
}
|
|
419
|
-
async
|
|
467
|
+
async executeUtilityFunction(targetContractAddress, functionSelector, args, jobId) {
|
|
420
468
|
const artifact = await this.contractStore.getFunctionArtifact(targetContractAddress, functionSelector);
|
|
421
469
|
if (!artifact) {
|
|
422
470
|
throw new Error(`Cannot call ${functionSelector} as there is no artifact found at ${targetContractAddress}.`);
|
|
423
471
|
}
|
|
424
472
|
// Sync notes before executing utility function to discover notes from previous transactions
|
|
425
|
-
await this.
|
|
426
|
-
|
|
473
|
+
const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
474
|
+
await this.stateMachine.contractSyncService.ensureContractSynced(targetContractAddress, functionSelector, async (call, execScopes)=>{
|
|
475
|
+
await this.executeUtilityCall(call, execScopes, jobId);
|
|
476
|
+
}, blockHeader, jobId, 'ALL_SCOPES');
|
|
477
|
+
const call = FunctionCall.from({
|
|
478
|
+
name: artifact.name,
|
|
479
|
+
to: targetContractAddress,
|
|
480
|
+
selector: functionSelector,
|
|
481
|
+
type: FunctionType.UTILITY,
|
|
482
|
+
hideMsgSender: false,
|
|
483
|
+
isStatic: false,
|
|
484
|
+
args,
|
|
485
|
+
returnTypes: []
|
|
427
486
|
});
|
|
428
|
-
|
|
429
|
-
return this.executeUtilityCall(call);
|
|
487
|
+
return this.executeUtilityCall(call, 'ALL_SCOPES', jobId);
|
|
430
488
|
}
|
|
431
|
-
async executeUtilityCall(call) {
|
|
489
|
+
async executeUtilityCall(call, scopes, jobId) {
|
|
432
490
|
const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
|
|
433
491
|
if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
|
|
434
492
|
throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
|
|
@@ -439,7 +497,25 @@ export class TXEOracleTopLevelContext {
|
|
|
439
497
|
});
|
|
440
498
|
try {
|
|
441
499
|
const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
442
|
-
const oracle = new UtilityExecutionOracle(
|
|
500
|
+
const oracle = new UtilityExecutionOracle({
|
|
501
|
+
contractAddress: call.to,
|
|
502
|
+
authWitnesses: [],
|
|
503
|
+
capsules: [],
|
|
504
|
+
anchorBlockHeader,
|
|
505
|
+
contractStore: this.contractStore,
|
|
506
|
+
noteStore: this.noteStore,
|
|
507
|
+
keyStore: this.keyStore,
|
|
508
|
+
addressStore: this.addressStore,
|
|
509
|
+
aztecNode: this.stateMachine.node,
|
|
510
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
511
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
512
|
+
capsuleStore: this.capsuleStore,
|
|
513
|
+
privateEventStore: this.privateEventStore,
|
|
514
|
+
messageContextService: this.stateMachine.messageContextService,
|
|
515
|
+
contractSyncService: this.contractSyncService,
|
|
516
|
+
jobId,
|
|
517
|
+
scopes
|
|
518
|
+
});
|
|
443
519
|
const acirExecutionResult = await new WASMSimulator().executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, new Oracle(oracle).toACIRCallback()).catch((err)=>{
|
|
444
520
|
err.message = resolveAssertionMessageFromError(err, entryPointArtifact);
|
|
445
521
|
throw new ExecutionError(err.message, {
|
|
@@ -449,10 +525,10 @@ export class TXEOracleTopLevelContext {
|
|
|
449
525
|
cause: err
|
|
450
526
|
});
|
|
451
527
|
});
|
|
452
|
-
this.logger.verbose(`Utility
|
|
528
|
+
this.logger.verbose(`Utility execution for ${call.to}.${call.selector} completed`);
|
|
453
529
|
return witnessMapToFields(acirExecutionResult.returnWitness);
|
|
454
530
|
} catch (err) {
|
|
455
|
-
throw createSimulationError(err instanceof Error ? err : new Error('Unknown error during utility
|
|
531
|
+
throw createSimulationError(err instanceof Error ? err : new Error('Unknown error during utility execution'));
|
|
456
532
|
}
|
|
457
533
|
}
|
|
458
534
|
close() {
|