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