@aztec/txe 0.0.1-commit.1142ef1 → 0.0.1-commit.11bf3dd6e
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 +1 -2
- package/dest/constants.d.ts.map +1 -1
- package/dest/constants.js +0 -1
- 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 +16 -16
- package/dest/oracle/txe_oracle_top_level_context.d.ts +28 -22
- package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_top_level_context.js +165 -71
- package/dest/rpc_translator.d.ts +125 -81
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +426 -179
- package/dest/state_machine/archiver.d.ts +20 -69
- package/dest/state_machine/archiver.d.ts.map +1 -1
- package/dest/state_machine/archiver.js +36 -179
- 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 +9 -4
- package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
- package/dest/state_machine/global_variable_builder.js +9 -3
- 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 +40 -13
- package/dest/state_machine/mock_epoch_cache.d.ts +25 -8
- package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
- package/dest/state_machine/mock_epoch_cache.js +46 -9
- 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 +12 -6
- package/dest/txe_session.d.ts.map +1 -1
- package/dest/txe_session.js +115 -28
- package/dest/util/encoding.d.ts +88 -18
- package/dest/util/encoding.d.ts.map +1 -1
- package/dest/util/encoding.js +4 -0
- 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 +4 -4
- package/dest/utils/block_creation.d.ts.map +1 -1
- package/dest/utils/block_creation.js +18 -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 +3 -6
- package/package.json +16 -16
- package/src/constants.ts +0 -1
- package/src/index.ts +89 -52
- package/src/oracle/interfaces.ts +32 -31
- package/src/oracle/txe_oracle_public_context.ts +16 -18
- package/src/oracle/txe_oracle_top_level_context.ts +208 -123
- package/src/rpc_translator.ts +493 -204
- package/src/state_machine/archiver.ts +38 -234
- package/src/state_machine/dummy_p2p_client.ts +46 -24
- package/src/state_machine/global_variable_builder.ts +18 -3
- package/src/state_machine/index.ts +56 -12
- package/src/state_machine/mock_epoch_cache.ts +57 -14
- package/src/state_machine/synchronizer.ts +5 -5
- package/src/txe_session.ts +132 -88
- package/src/util/encoding.ts +5 -0
- package/src/util/txe_public_contract_data_source.ts +10 -38
- package/src/utils/block_creation.ts +19 -16
- package/src/utils/tx_effect_creation.ts +3 -11
- 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
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS,
|
|
1
|
+
import { CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS, MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT, MAX_PROCESSABLE_L2_GAS, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/constants';
|
|
2
2
|
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
3
3
|
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 {
|
|
7
|
+
import { CapsuleService, ORACLE_VERSION_MAJOR, 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';
|
|
@@ -13,7 +13,7 @@ import { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
|
13
13
|
import { PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
14
14
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
15
15
|
import { computePartialAddress } from '@aztec/stdlib/contract';
|
|
16
|
-
import { Gas, GasFees, GasSettings } from '@aztec/stdlib/gas';
|
|
16
|
+
import { FALLBACK_TEARDOWN_DA_GAS_LIMIT, FALLBACK_TEARDOWN_L2_GAS_LIMIT, Gas, GasFees, GasSettings } from '@aztec/stdlib/gas';
|
|
17
17
|
import { computeCalldataHash, computeProtocolNullifier, siloNullifier } from '@aztec/stdlib/hash';
|
|
18
18
|
import { PartialPrivateTailPublicInputsForPublic, PrivateKernelTailCircuitPublicInputs, PrivateToPublicAccumulatedData, PublicCallRequest } from '@aztec/stdlib/kernel';
|
|
19
19
|
import { ChonkProof } from '@aztec/stdlib/proofs';
|
|
@@ -21,7 +21,7 @@ import { makeGlobalVariables } from '@aztec/stdlib/testing';
|
|
|
21
21
|
import { MerkleTreeId } from '@aztec/stdlib/trees';
|
|
22
22
|
import { CallContext, HashedValues, PrivateExecutionResult, Tx, TxConstantData, TxContext, TxEffect, TxHash, collectNested } from '@aztec/stdlib/tx';
|
|
23
23
|
import { ForkCheckpoint } from '@aztec/world-state';
|
|
24
|
-
import { DEFAULT_ADDRESS
|
|
24
|
+
import { DEFAULT_ADDRESS } from '../constants.js';
|
|
25
25
|
import { TXEPublicContractDataSource } from '../util/txe_public_contract_data_source.js';
|
|
26
26
|
import { getSingleTxBlockRequestHash, insertTxEffectIntoWorldTrees, makeTXEBlock } from '../utils/block_creation.js';
|
|
27
27
|
export class TXEOracleTopLevelContext {
|
|
@@ -40,10 +40,11 @@ export class TXEOracleTopLevelContext {
|
|
|
40
40
|
version;
|
|
41
41
|
chainId;
|
|
42
42
|
authwits;
|
|
43
|
+
contractSyncService;
|
|
43
44
|
isMisc;
|
|
44
45
|
isTxe;
|
|
45
46
|
logger;
|
|
46
|
-
constructor(stateMachine, contractStore, noteStore, keyStore, addressStore, accountStore, senderTaggingStore, recipientTaggingStore, senderAddressBookStore, capsuleStore, privateEventStore, nextBlockTimestamp, version, chainId, authwits){
|
|
47
|
+
constructor(stateMachine, contractStore, noteStore, keyStore, addressStore, accountStore, senderTaggingStore, recipientTaggingStore, senderAddressBookStore, capsuleStore, privateEventStore, nextBlockTimestamp, version, chainId, authwits, contractSyncService){
|
|
47
48
|
this.stateMachine = stateMachine;
|
|
48
49
|
this.contractStore = contractStore;
|
|
49
50
|
this.noteStore = noteStore;
|
|
@@ -59,45 +60,58 @@ export class TXEOracleTopLevelContext {
|
|
|
59
60
|
this.version = version;
|
|
60
61
|
this.chainId = chainId;
|
|
61
62
|
this.authwits = authwits;
|
|
63
|
+
this.contractSyncService = contractSyncService;
|
|
62
64
|
this.isMisc = true;
|
|
63
65
|
this.isTxe = true;
|
|
64
66
|
this.logger = createLogger('txe:top_level_context');
|
|
65
67
|
this.logger.debug('Entering Top Level Context');
|
|
66
68
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
69
|
+
contractOracleVersion;
|
|
70
|
+
assertCompatibleOracleVersion(major, minor) {
|
|
71
|
+
if (major !== ORACLE_VERSION_MAJOR) {
|
|
72
|
+
const hint = major > ORACLE_VERSION_MAJOR ? '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.';
|
|
73
|
+
throw new Error(`Incompatible aztec cli version: ${hint} See https://docs.aztec.network/errors/8 (expected oracle major version ${ORACLE_VERSION_MAJOR}, got ${major})`);
|
|
70
74
|
}
|
|
75
|
+
this.contractOracleVersion = {
|
|
76
|
+
major,
|
|
77
|
+
minor
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
// Prefixed with "nonOracleFunction" as it is not used as an oracle handler.
|
|
81
|
+
nonOracleFunctionGetContractOracleVersion() {
|
|
82
|
+
return this.contractOracleVersion;
|
|
71
83
|
}
|
|
72
84
|
// This is typically only invoked in private contexts, but it is convenient to also have it in top-level for testing
|
|
73
85
|
// setup.
|
|
74
|
-
|
|
86
|
+
getRandomField() {
|
|
75
87
|
return Fr.random();
|
|
76
88
|
}
|
|
77
89
|
// We instruct users to debug contracts via this oracle, so it makes sense that they'd expect it to also work in tests
|
|
78
|
-
|
|
90
|
+
log(level, message, fields) {
|
|
79
91
|
if (!LogLevels[level]) {
|
|
80
|
-
throw new Error(`Invalid
|
|
92
|
+
throw new Error(`Invalid log level: ${level}`);
|
|
81
93
|
}
|
|
82
94
|
const levelName = LogLevels[level];
|
|
83
95
|
this.logger[levelName](`${applyStringFormatting(message, fields)}`, {
|
|
84
96
|
module: `${this.logger.module}:debug_log`
|
|
85
97
|
});
|
|
98
|
+
return Promise.resolve();
|
|
86
99
|
}
|
|
87
|
-
|
|
100
|
+
getDefaultAddress() {
|
|
88
101
|
return DEFAULT_ADDRESS;
|
|
89
102
|
}
|
|
90
|
-
async
|
|
103
|
+
async getNextBlockNumber() {
|
|
91
104
|
return BlockNumber(await this.getLastBlockNumber() + 1);
|
|
92
105
|
}
|
|
93
|
-
|
|
106
|
+
getNextBlockTimestamp() {
|
|
94
107
|
return Promise.resolve(this.nextBlockTimestamp);
|
|
95
108
|
}
|
|
96
|
-
async
|
|
109
|
+
async getLastBlockTimestamp() {
|
|
97
110
|
return (await this.stateMachine.node.getBlockHeader('latest')).globalVariables.timestamp;
|
|
98
111
|
}
|
|
99
|
-
async
|
|
100
|
-
const
|
|
112
|
+
async getLastTxEffects() {
|
|
113
|
+
const latestBlockNumber = await this.stateMachine.archiver.getBlockNumber();
|
|
114
|
+
const block = await this.stateMachine.archiver.getBlock(latestBlockNumber);
|
|
101
115
|
if (block.body.txEffects.length != 1) {
|
|
102
116
|
// Note that calls like env.mine() will result in blocks with no transactions, hitting this
|
|
103
117
|
throw new Error(`Expected a single transaction in the last block, found ${block.body.txEffects.length}`);
|
|
@@ -109,7 +123,19 @@ export class TXEOracleTopLevelContext {
|
|
|
109
123
|
nullifiers: txEffects.nullifiers
|
|
110
124
|
};
|
|
111
125
|
}
|
|
112
|
-
async
|
|
126
|
+
async syncContractNonOracleMethod(contractAddress, scope, jobId) {
|
|
127
|
+
if (contractAddress.equals(DEFAULT_ADDRESS)) {
|
|
128
|
+
this.logger.debug(`Skipping sync in getPrivateEvents because the events correspond to the default address.`);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
132
|
+
await this.stateMachine.contractSyncService.ensureContractSynced(contractAddress, null, async (call, execScopes)=>{
|
|
133
|
+
await this.executeUtilityCall(call, execScopes, jobId);
|
|
134
|
+
}, blockHeader, jobId, [
|
|
135
|
+
scope
|
|
136
|
+
]);
|
|
137
|
+
}
|
|
138
|
+
async getPrivateEvents(selector, contractAddress, scope) {
|
|
113
139
|
return (await this.privateEventStore.getPrivateEvents(selector, {
|
|
114
140
|
contractAddress,
|
|
115
141
|
scopes: [
|
|
@@ -119,17 +145,17 @@ export class TXEOracleTopLevelContext {
|
|
|
119
145
|
toBlock: await this.getLastBlockNumber() + 1
|
|
120
146
|
})).map((e)=>e.packedEvent);
|
|
121
147
|
}
|
|
122
|
-
async
|
|
148
|
+
async advanceBlocksBy(blocks) {
|
|
123
149
|
this.logger.debug(`time traveling ${blocks} blocks`);
|
|
124
150
|
for(let i = 0; i < blocks; i++){
|
|
125
151
|
await this.mineBlock();
|
|
126
152
|
}
|
|
127
153
|
}
|
|
128
|
-
|
|
154
|
+
advanceTimestampBy(duration) {
|
|
129
155
|
this.logger.debug(`time traveling ${duration} seconds`);
|
|
130
156
|
this.nextBlockTimestamp += duration;
|
|
131
157
|
}
|
|
132
|
-
async
|
|
158
|
+
async deploy(artifact, instance, secret) {
|
|
133
159
|
// Emit deployment nullifier
|
|
134
160
|
await this.mineBlock({
|
|
135
161
|
nullifiers: [
|
|
@@ -137,25 +163,25 @@ export class TXEOracleTopLevelContext {
|
|
|
137
163
|
]
|
|
138
164
|
});
|
|
139
165
|
if (!secret.equals(Fr.ZERO)) {
|
|
140
|
-
await this.
|
|
166
|
+
await this.addAccount(artifact, instance, secret);
|
|
141
167
|
} else {
|
|
142
168
|
await this.contractStore.addContractInstance(instance);
|
|
143
|
-
await this.contractStore.addContractArtifact(
|
|
169
|
+
await this.contractStore.addContractArtifact(artifact);
|
|
144
170
|
this.logger.debug(`Deployed ${artifact.name} at ${instance.address}`);
|
|
145
171
|
}
|
|
146
172
|
}
|
|
147
|
-
async
|
|
173
|
+
async addAccount(artifact, instance, secret) {
|
|
148
174
|
const partialAddress = await computePartialAddress(instance);
|
|
149
175
|
this.logger.debug(`Deployed ${artifact.name} at ${instance.address}`);
|
|
150
176
|
await this.contractStore.addContractInstance(instance);
|
|
151
|
-
await this.contractStore.addContractArtifact(
|
|
177
|
+
await this.contractStore.addContractArtifact(artifact);
|
|
152
178
|
const completeAddress = await this.keyStore.addAccount(secret, partialAddress);
|
|
153
179
|
await this.accountStore.setAccount(completeAddress.address, completeAddress);
|
|
154
180
|
await this.addressStore.addCompleteAddress(completeAddress);
|
|
155
181
|
this.logger.debug(`Created account ${completeAddress.address}`);
|
|
156
182
|
return completeAddress;
|
|
157
183
|
}
|
|
158
|
-
async
|
|
184
|
+
async createAccount(secret) {
|
|
159
185
|
// This is a foot gun !
|
|
160
186
|
const completeAddress = await this.keyStore.addAccount(secret, secret);
|
|
161
187
|
await this.accountStore.setAccount(completeAddress.address, completeAddress);
|
|
@@ -163,7 +189,7 @@ export class TXEOracleTopLevelContext {
|
|
|
163
189
|
this.logger.debug(`Created account ${completeAddress.address}`);
|
|
164
190
|
return completeAddress;
|
|
165
191
|
}
|
|
166
|
-
async
|
|
192
|
+
async addAuthWitness(address, messageHash) {
|
|
167
193
|
const account = await this.accountStore.getAccount(address);
|
|
168
194
|
const privateKey = await this.keyStore.getMasterSecretKey(account.publicKeys.masterIncomingViewingPublicKey);
|
|
169
195
|
const schnorr = new Schnorr();
|
|
@@ -174,7 +200,7 @@ export class TXEOracleTopLevelContext {
|
|
|
174
200
|
this.authwits.set(authWitness.requestHash.toString(), authWitness);
|
|
175
201
|
}
|
|
176
202
|
async mineBlock(options = {}) {
|
|
177
|
-
const blockNumber = await this.
|
|
203
|
+
const blockNumber = await this.getNextBlockNumber();
|
|
178
204
|
const txEffect = TxEffect.empty();
|
|
179
205
|
txEffect.nullifiers = [
|
|
180
206
|
getSingleTxBlockRequestHash(blockNumber),
|
|
@@ -196,35 +222,74 @@ export class TXEOracleTopLevelContext {
|
|
|
196
222
|
this.logger.info(`Created block ${blockNumber} with timestamp ${block.header.globalVariables.timestamp}`);
|
|
197
223
|
await this.stateMachine.handleL2Block(block);
|
|
198
224
|
}
|
|
199
|
-
async
|
|
225
|
+
async privateCallNewFlow(from, targetContractAddress = AztecAddress.zero(), functionSelector = FunctionSelector.empty(), args, argsHash = Fr.zero(), isStaticCall = false, jobId) {
|
|
200
226
|
this.logger.verbose(`Executing external function ${await this.contractStore.getDebugFunctionName(targetContractAddress, functionSelector)}@${targetContractAddress} isStaticCall=${isStaticCall}`);
|
|
201
227
|
const artifact = await this.contractStore.getFunctionArtifact(targetContractAddress, functionSelector);
|
|
202
228
|
if (!artifact) {
|
|
203
229
|
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';
|
|
204
230
|
throw new Error(message);
|
|
205
231
|
}
|
|
232
|
+
// When `from` is the zero address (e.g. when deploying a new account contract), we return an
|
|
233
|
+
// empty scope list which acts as deny-all: no notes are visible and no keys are accessible.
|
|
234
|
+
const effectiveScopes = from.isZero() ? [] : [
|
|
235
|
+
from
|
|
236
|
+
];
|
|
206
237
|
// Sync notes before executing private function to discover notes from previous transactions
|
|
207
|
-
const utilityExecutor = async (call)=>{
|
|
208
|
-
await this.executeUtilityCall(call);
|
|
238
|
+
const utilityExecutor = async (call, execScopes)=>{
|
|
239
|
+
await this.executeUtilityCall(call, execScopes, jobId);
|
|
209
240
|
};
|
|
210
|
-
await this.
|
|
211
|
-
|
|
241
|
+
const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
242
|
+
await this.stateMachine.contractSyncService.ensureContractSynced(targetContractAddress, functionSelector, utilityExecutor, blockHeader, jobId, effectiveScopes);
|
|
243
|
+
const blockNumber = await this.getNextBlockNumber();
|
|
212
244
|
const callContext = new CallContext(from, targetContractAddress, functionSelector, isStaticCall);
|
|
213
|
-
const gasLimits = new Gas(
|
|
214
|
-
const teardownGasLimits = new Gas(
|
|
245
|
+
const gasLimits = new Gas(MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT, MAX_PROCESSABLE_L2_GAS);
|
|
246
|
+
const teardownGasLimits = new Gas(FALLBACK_TEARDOWN_DA_GAS_LIMIT, FALLBACK_TEARDOWN_L2_GAS_LIMIT);
|
|
215
247
|
const gasSettings = new GasSettings(gasLimits, teardownGasLimits, GasFees.empty(), GasFees.empty());
|
|
216
248
|
const txContext = new TxContext(this.chainId, this.version, gasSettings);
|
|
217
|
-
const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
218
249
|
const protocolNullifier = await computeProtocolNullifier(getSingleTxBlockRequestHash(blockNumber));
|
|
219
250
|
const noteCache = new ExecutionNoteCache(protocolNullifier);
|
|
251
|
+
// In production, the account contract sets the min revertible counter before calling the app function.
|
|
252
|
+
// Since TXE bypasses the account contract, we simulate this by setting minRevertibleSideEffectCounter to 1,
|
|
253
|
+
// marking all side effects as revertible.
|
|
254
|
+
const minRevertibleSideEffectCounter = 1;
|
|
255
|
+
await noteCache.setMinRevertibleSideEffectCounter(minRevertibleSideEffectCounter);
|
|
220
256
|
const taggingIndexCache = new ExecutionTaggingIndexCache();
|
|
221
257
|
const simulator = new WASMSimulator();
|
|
222
|
-
const privateExecutionOracle = new PrivateExecutionOracle(
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
258
|
+
const privateExecutionOracle = new PrivateExecutionOracle({
|
|
259
|
+
argsHash,
|
|
260
|
+
txContext,
|
|
261
|
+
callContext,
|
|
262
|
+
anchorBlockHeader: blockHeader,
|
|
263
|
+
utilityExecutor,
|
|
264
|
+
authWitnesses: Array.from(this.authwits.values()),
|
|
265
|
+
capsules: [],
|
|
266
|
+
executionCache: HashedValuesCache.create([
|
|
267
|
+
new HashedValues(args, argsHash)
|
|
268
|
+
]),
|
|
269
|
+
noteCache,
|
|
270
|
+
taggingIndexCache,
|
|
271
|
+
contractStore: this.contractStore,
|
|
272
|
+
noteStore: this.noteStore,
|
|
273
|
+
keyStore: this.keyStore,
|
|
274
|
+
addressStore: this.addressStore,
|
|
275
|
+
aztecNode: this.stateMachine.node,
|
|
276
|
+
senderTaggingStore: this.senderTaggingStore,
|
|
277
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
278
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
279
|
+
capsuleService: new CapsuleService(this.capsuleStore, effectiveScopes),
|
|
280
|
+
privateEventStore: this.privateEventStore,
|
|
281
|
+
contractSyncService: this.stateMachine.contractSyncService,
|
|
282
|
+
jobId,
|
|
283
|
+
totalPublicCalldataCount: 0,
|
|
284
|
+
sideEffectCounter: minRevertibleSideEffectCounter,
|
|
285
|
+
scopes: effectiveScopes,
|
|
286
|
+
// In TXE, the typical transaction entrypoint is skipped, so we need to simulate the actions that such a
|
|
287
|
+
// contract would perform, including setting senderForTags.
|
|
288
|
+
senderForTags: from,
|
|
289
|
+
simulator,
|
|
290
|
+
messageContextService: this.stateMachine.messageContextService,
|
|
291
|
+
l2TipsStore: this.stateMachine.node
|
|
292
|
+
});
|
|
228
293
|
// 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.
|
|
229
294
|
let result;
|
|
230
295
|
let executionResult;
|
|
@@ -236,21 +301,19 @@ export class TXEOracleTopLevelContext {
|
|
|
236
301
|
r.publicInputs.publicTeardownCallRequest
|
|
237
302
|
]));
|
|
238
303
|
const publicFunctionsCalldata = await Promise.all(publicCallRequests.map(async (r)=>{
|
|
239
|
-
const calldata = await privateExecutionOracle.
|
|
304
|
+
const calldata = await privateExecutionOracle.getHashPreimage(r.calldataHash);
|
|
240
305
|
return new HashedValues(calldata, r.calldataHash);
|
|
241
306
|
}));
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
result = new PrivateExecutionResult(executionResult, Fr.ZERO, publicFunctionsCalldata);
|
|
307
|
+
noteCache.finish();
|
|
308
|
+
const nonceGenerator = noteCache.getNonceGenerator();
|
|
309
|
+
result = new PrivateExecutionResult(executionResult, nonceGenerator, publicFunctionsCalldata);
|
|
246
310
|
} catch (err) {
|
|
247
311
|
throw createSimulationError(err instanceof Error ? err : new Error('Unknown error during private execution'));
|
|
248
312
|
}
|
|
249
|
-
// According to the protocol rules,
|
|
250
|
-
//
|
|
251
|
-
//
|
|
252
|
-
const
|
|
253
|
-
const { publicInputs } = await generateSimulatedProvingResult(result, nonceGenerator, this.contractStore);
|
|
313
|
+
// According to the protocol rules, there must be at least one nullifier in the tx. The first nullifier is used as
|
|
314
|
+
// the nonce generator for the note hashes.
|
|
315
|
+
// We pass the non-zero minRevertibleSideEffectCounter to make sure the side effects are split correctly.
|
|
316
|
+
const { publicInputs } = await generateSimulatedProvingResult(result, (addr, sel)=>this.contractStore.getDebugFunctionName(addr, sel), this.stateMachine.node, minRevertibleSideEffectCounter);
|
|
254
317
|
const globals = makeGlobalVariables();
|
|
255
318
|
globals.blockNumber = blockNumber;
|
|
256
319
|
globals.timestamp = this.nextBlockTimestamp;
|
|
@@ -258,7 +321,8 @@ export class TXEOracleTopLevelContext {
|
|
|
258
321
|
globals.version = this.version;
|
|
259
322
|
globals.gasFees = GasFees.empty();
|
|
260
323
|
const forkedWorldTrees = await this.stateMachine.synchronizer.nativeWorldStateService.fork();
|
|
261
|
-
const
|
|
324
|
+
const bindings = this.logger.getBindings();
|
|
325
|
+
const contractsDB = new PublicContractsDB(new TXEPublicContractDataSource(blockNumber, this.contractStore), bindings);
|
|
262
326
|
const guardedMerkleTrees = new GuardedMerkleTreeOperations(forkedWorldTrees);
|
|
263
327
|
const config = PublicSimulatorConfig.from({
|
|
264
328
|
skipFeeEnforcement: true,
|
|
@@ -267,7 +331,7 @@ export class TXEOracleTopLevelContext {
|
|
|
267
331
|
collectStatistics: false,
|
|
268
332
|
collectCallMetadata: true
|
|
269
333
|
});
|
|
270
|
-
const processor = new PublicProcessor(globals, guardedMerkleTrees, contractsDB, new CppPublicTxSimulator(guardedMerkleTrees, contractsDB, globals, config), new TestDateProvider());
|
|
334
|
+
const processor = new PublicProcessor(globals, guardedMerkleTrees, contractsDB, new CppPublicTxSimulator(guardedMerkleTrees, contractsDB, globals, config, bindings), new TestDateProvider(), undefined, createLogger('simulator:public-processor', bindings));
|
|
271
335
|
const tx = await Tx.create({
|
|
272
336
|
data: publicInputs,
|
|
273
337
|
chonkProof: ChonkProof.empty(),
|
|
@@ -317,11 +381,11 @@ export class TXEOracleTopLevelContext {
|
|
|
317
381
|
await forkedWorldTrees.close();
|
|
318
382
|
return executionResult.returnValues ?? [];
|
|
319
383
|
}
|
|
320
|
-
async
|
|
384
|
+
async publicCallNewFlow(from, targetContractAddress, calldata, isStaticCall) {
|
|
321
385
|
this.logger.verbose(`Executing public function ${await this.contractStore.getDebugFunctionName(targetContractAddress, FunctionSelector.fromField(calldata[0]))}@${targetContractAddress} isStaticCall=${isStaticCall}`);
|
|
322
|
-
const blockNumber = await this.
|
|
323
|
-
const gasLimits = new Gas(
|
|
324
|
-
const teardownGasLimits = new Gas(
|
|
386
|
+
const blockNumber = await this.getNextBlockNumber();
|
|
387
|
+
const gasLimits = new Gas(MAX_PROCESSABLE_DA_GAS_PER_CHECKPOINT, MAX_PROCESSABLE_L2_GAS);
|
|
388
|
+
const teardownGasLimits = new Gas(FALLBACK_TEARDOWN_DA_GAS_LIMIT, FALLBACK_TEARDOWN_L2_GAS_LIMIT);
|
|
325
389
|
const gasSettings = new GasSettings(gasLimits, teardownGasLimits, GasFees.empty(), GasFees.empty());
|
|
326
390
|
const txContext = new TxContext(this.chainId, this.version, gasSettings);
|
|
327
391
|
const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
@@ -334,7 +398,8 @@ export class TXEOracleTopLevelContext {
|
|
|
334
398
|
globals.version = this.version;
|
|
335
399
|
globals.gasFees = GasFees.empty();
|
|
336
400
|
const forkedWorldTrees = await this.stateMachine.synchronizer.nativeWorldStateService.fork();
|
|
337
|
-
const
|
|
401
|
+
const bindings2 = this.logger.getBindings();
|
|
402
|
+
const contractsDB = new PublicContractsDB(new TXEPublicContractDataSource(blockNumber, this.contractStore), bindings2);
|
|
338
403
|
const guardedMerkleTrees = new GuardedMerkleTreeOperations(forkedWorldTrees);
|
|
339
404
|
const config = PublicSimulatorConfig.from({
|
|
340
405
|
skipFeeEnforcement: true,
|
|
@@ -343,8 +408,8 @@ export class TXEOracleTopLevelContext {
|
|
|
343
408
|
collectStatistics: false,
|
|
344
409
|
collectCallMetadata: true
|
|
345
410
|
});
|
|
346
|
-
const simulator = new CppPublicTxSimulator(guardedMerkleTrees, contractsDB, globals, config);
|
|
347
|
-
const processor = new PublicProcessor(globals, guardedMerkleTrees, contractsDB, simulator, new TestDateProvider());
|
|
411
|
+
const simulator = new CppPublicTxSimulator(guardedMerkleTrees, contractsDB, globals, config, bindings2);
|
|
412
|
+
const processor = new PublicProcessor(globals, guardedMerkleTrees, contractsDB, simulator, new TestDateProvider(), undefined, createLogger('simulator:public-processor', bindings2));
|
|
348
413
|
// We're simulating a scenario in which private execution immediately enqueues a public call and halts. The private
|
|
349
414
|
// kernel init would in this case inject a nullifier with the transaction request hash as a non-revertible
|
|
350
415
|
// side-effect, which the AVM then expects to exist in order to use it as the nonce generator when siloing notes as
|
|
@@ -357,7 +422,7 @@ export class TXEOracleTopLevelContext {
|
|
|
357
422
|
revertibleAccumulatedData.publicCallRequests[0] = new PublicCallRequest(from, targetContractAddress, isStaticCall, calldataHash);
|
|
358
423
|
const inputsForPublic = new PartialPrivateTailPublicInputsForPublic(nonRevertibleAccumulatedData, revertibleAccumulatedData, PublicCallRequest.empty());
|
|
359
424
|
const constantData = new TxConstantData(anchorBlockHeader, txContext, Fr.zero(), Fr.zero());
|
|
360
|
-
const txData = new PrivateKernelTailCircuitPublicInputs(constantData, /*gasUsed=*/ new Gas(0, 0), /*feePayer=*/ AztecAddress.zero(), /*
|
|
425
|
+
const txData = new PrivateKernelTailCircuitPublicInputs(constantData, /*gasUsed=*/ new Gas(0, 0), /*feePayer=*/ AztecAddress.zero(), /*expirationTimestamp=*/ 0n, inputsForPublic, undefined);
|
|
361
426
|
const tx = await Tx.create({
|
|
362
427
|
data: txData,
|
|
363
428
|
chonkProof: ChonkProof.empty(),
|
|
@@ -410,19 +475,29 @@ export class TXEOracleTopLevelContext {
|
|
|
410
475
|
await forkedWorldTrees.close();
|
|
411
476
|
return returnValues ?? [];
|
|
412
477
|
}
|
|
413
|
-
async
|
|
478
|
+
async executeUtilityFunction(targetContractAddress, functionSelector, args, jobId) {
|
|
414
479
|
const artifact = await this.contractStore.getFunctionArtifact(targetContractAddress, functionSelector);
|
|
415
480
|
if (!artifact) {
|
|
416
481
|
throw new Error(`Cannot call ${functionSelector} as there is no artifact found at ${targetContractAddress}.`);
|
|
417
482
|
}
|
|
418
483
|
// Sync notes before executing utility function to discover notes from previous transactions
|
|
419
|
-
await this.
|
|
420
|
-
|
|
484
|
+
const blockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
485
|
+
await this.stateMachine.contractSyncService.ensureContractSynced(targetContractAddress, functionSelector, async (call, execScopes)=>{
|
|
486
|
+
await this.executeUtilityCall(call, execScopes, jobId);
|
|
487
|
+
}, blockHeader, jobId, await this.keyStore.getAccounts());
|
|
488
|
+
const call = FunctionCall.from({
|
|
489
|
+
name: artifact.name,
|
|
490
|
+
to: targetContractAddress,
|
|
491
|
+
selector: functionSelector,
|
|
492
|
+
type: FunctionType.UTILITY,
|
|
493
|
+
hideMsgSender: false,
|
|
494
|
+
isStatic: false,
|
|
495
|
+
args,
|
|
496
|
+
returnTypes: []
|
|
421
497
|
});
|
|
422
|
-
|
|
423
|
-
return this.executeUtilityCall(call);
|
|
498
|
+
return this.executeUtilityCall(call, await this.keyStore.getAccounts(), jobId);
|
|
424
499
|
}
|
|
425
|
-
async executeUtilityCall(call) {
|
|
500
|
+
async executeUtilityCall(call, scopes, jobId) {
|
|
426
501
|
const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
|
|
427
502
|
if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
|
|
428
503
|
throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
|
|
@@ -433,7 +508,26 @@ export class TXEOracleTopLevelContext {
|
|
|
433
508
|
});
|
|
434
509
|
try {
|
|
435
510
|
const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
436
|
-
const oracle = new UtilityExecutionOracle(
|
|
511
|
+
const oracle = new UtilityExecutionOracle({
|
|
512
|
+
contractAddress: call.to,
|
|
513
|
+
authWitnesses: [],
|
|
514
|
+
capsules: [],
|
|
515
|
+
anchorBlockHeader,
|
|
516
|
+
contractStore: this.contractStore,
|
|
517
|
+
noteStore: this.noteStore,
|
|
518
|
+
keyStore: this.keyStore,
|
|
519
|
+
addressStore: this.addressStore,
|
|
520
|
+
aztecNode: this.stateMachine.node,
|
|
521
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
522
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
523
|
+
capsuleService: new CapsuleService(this.capsuleStore, scopes),
|
|
524
|
+
privateEventStore: this.privateEventStore,
|
|
525
|
+
messageContextService: this.stateMachine.messageContextService,
|
|
526
|
+
contractSyncService: this.contractSyncService,
|
|
527
|
+
l2TipsStore: this.stateMachine.node,
|
|
528
|
+
jobId,
|
|
529
|
+
scopes
|
|
530
|
+
});
|
|
437
531
|
const acirExecutionResult = await new WASMSimulator().executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, new Oracle(oracle).toACIRCallback()).catch((err)=>{
|
|
438
532
|
err.message = resolveAssertionMessageFromError(err, entryPointArtifact);
|
|
439
533
|
throw new ExecutionError(err.message, {
|
|
@@ -443,10 +537,10 @@ export class TXEOracleTopLevelContext {
|
|
|
443
537
|
cause: err
|
|
444
538
|
});
|
|
445
539
|
});
|
|
446
|
-
this.logger.verbose(`Utility
|
|
540
|
+
this.logger.verbose(`Utility execution for ${call.to}.${call.selector} completed`);
|
|
447
541
|
return witnessMapToFields(acirExecutionResult.returnWitness);
|
|
448
542
|
} catch (err) {
|
|
449
|
-
throw createSimulationError(err instanceof Error ? err : new Error('Unknown error during utility
|
|
543
|
+
throw createSimulationError(err instanceof Error ? err : new Error('Unknown error during utility execution'));
|
|
450
544
|
}
|
|
451
545
|
}
|
|
452
546
|
close() {
|