@aztec/txe 0.0.1-commit.5476d83 → 0.0.1-commit.5914bae
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 +91 -56
- package/dest/oracle/interfaces.d.ts +33 -29
- package/dest/oracle/interfaces.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.d.ts +16 -16
- package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.js +20 -22
- package/dest/oracle/txe_oracle_top_level_context.d.ts +42 -27
- package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_top_level_context.js +232 -107
- package/dest/rpc_translator.d.ts +129 -79
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +465 -175
- package/dest/state_machine/archiver.d.ts +21 -52
- package/dest/state_machine/archiver.d.ts.map +1 -1
- package/dest/state_machine/archiver.js +66 -99
- package/dest/state_machine/dummy_p2p_client.d.ts +20 -15
- package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
- package/dest/state_machine/dummy_p2p_client.js +42 -25
- package/dest/state_machine/global_variable_builder.d.ts +6 -5
- 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 +9 -7
- package/dest/state_machine/index.d.ts.map +1 -1
- package/dest/state_machine/index.js +44 -23
- package/dest/state_machine/mock_epoch_cache.d.ts +9 -6
- package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
- package/dest/state_machine/mock_epoch_cache.js +14 -7
- package/dest/state_machine/synchronizer.d.ts +6 -5
- package/dest/state_machine/synchronizer.d.ts.map +1 -1
- package/dest/state_machine/synchronizer.js +8 -7
- package/dest/txe_session.d.ts +27 -15
- package/dest/txe_session.d.ts.map +1 -1
- package/dest/txe_session.js +173 -55
- package/dest/util/encoding.d.ts +617 -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_public_contract_data_source.d.ts +8 -8
- package/dest/util/txe_public_contract_data_source.d.ts.map +1 -1
- package/dest/util/txe_public_contract_data_source.js +12 -29
- package/dest/utils/block_creation.d.ts +21 -6
- package/dest/utils/block_creation.d.ts.map +1 -1
- package/dest/utils/block_creation.js +38 -4
- package/dest/utils/tx_effect_creation.d.ts +3 -3
- package/dest/utils/tx_effect_creation.d.ts.map +1 -1
- package/dest/utils/tx_effect_creation.js +4 -7
- package/package.json +18 -18
- package/src/constants.ts +3 -0
- package/src/index.ts +103 -63
- package/src/oracle/interfaces.ts +36 -32
- package/src/oracle/txe_oracle_public_context.ts +21 -28
- package/src/oracle/txe_oracle_top_level_context.ts +285 -149
- package/src/rpc_translator.ts +552 -193
- package/src/state_machine/archiver.ts +62 -117
- package/src/state_machine/dummy_p2p_client.ts +58 -33
- package/src/state_machine/global_variable_builder.ts +21 -4
- package/src/state_machine/index.ts +64 -21
- package/src/state_machine/mock_epoch_cache.ts +15 -11
- package/src/state_machine/synchronizer.ts +9 -8
- package/src/txe_session.ts +239 -104
- 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_public_contract_data_source.ts +20 -45
- package/src/utils/block_creation.ts +49 -15
- package/src/utils/tx_effect_creation.ts +5 -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
- package/dest/util/txe_contract_data_provider.js +0 -22
- package/src/util/txe_contract_data_provider.ts +0 -36
|
@@ -1,89 +1,117 @@
|
|
|
1
|
-
import { CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS,
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
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
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
3
|
+
import { Schnorr } from '@aztec/foundation/crypto/schnorr';
|
|
4
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
4
5
|
import { LogLevels, applyStringFormatting, createLogger } from '@aztec/foundation/log';
|
|
5
6
|
import { TestDateProvider } from '@aztec/foundation/timer';
|
|
6
|
-
import {
|
|
7
|
+
import { CapsuleService, ORACLE_VERSION_MAJOR, enrichPublicSimulationError } from '@aztec/pxe/server';
|
|
7
8
|
import { ExecutionNoteCache, ExecutionTaggingIndexCache, HashedValuesCache, Oracle, PrivateExecutionOracle, UtilityExecutionOracle, executePrivateFunction, generateSimulatedProvingResult } from '@aztec/pxe/simulator';
|
|
8
9
|
import { ExecutionError, WASMSimulator, createSimulationError, extractCallStack, resolveAssertionMessageFromError, toACVMWitness, witnessMapToFields } from '@aztec/simulator/client';
|
|
9
|
-
import { GuardedMerkleTreeOperations, PublicContractsDB, PublicProcessor
|
|
10
|
-
import { FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
|
|
10
|
+
import { CppPublicTxSimulator, GuardedMerkleTreeOperations, PublicContractsDB, PublicProcessor } from '@aztec/simulator/server';
|
|
11
|
+
import { FunctionCall, FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
|
|
11
12
|
import { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
12
13
|
import { PublicSimulatorConfig } from '@aztec/stdlib/avm';
|
|
13
14
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
14
|
-
import { Body, L2Block } from '@aztec/stdlib/block';
|
|
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';
|
|
20
|
-
import {
|
|
20
|
+
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 } from '../constants.js';
|
|
24
25
|
import { TXEPublicContractDataSource } from '../util/txe_public_contract_data_source.js';
|
|
25
|
-
import { getSingleTxBlockRequestHash, insertTxEffectIntoWorldTrees,
|
|
26
|
+
import { getSingleTxBlockRequestHash, insertTxEffectIntoWorldTrees, makeTXEBlock } from '../utils/block_creation.js';
|
|
26
27
|
export class TXEOracleTopLevelContext {
|
|
27
28
|
stateMachine;
|
|
28
|
-
|
|
29
|
+
contractStore;
|
|
30
|
+
noteStore;
|
|
29
31
|
keyStore;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
addressStore;
|
|
33
|
+
accountStore;
|
|
34
|
+
senderTaggingStore;
|
|
35
|
+
recipientTaggingStore;
|
|
36
|
+
senderAddressBookStore;
|
|
37
|
+
capsuleStore;
|
|
38
|
+
privateEventStore;
|
|
33
39
|
nextBlockTimestamp;
|
|
34
40
|
version;
|
|
35
41
|
chainId;
|
|
36
42
|
authwits;
|
|
43
|
+
contractSyncService;
|
|
37
44
|
isMisc;
|
|
38
45
|
isTxe;
|
|
39
46
|
logger;
|
|
40
|
-
constructor(stateMachine,
|
|
47
|
+
constructor(stateMachine, contractStore, noteStore, keyStore, addressStore, accountStore, senderTaggingStore, recipientTaggingStore, senderAddressBookStore, capsuleStore, privateEventStore, nextBlockTimestamp, version, chainId, authwits, contractSyncService){
|
|
41
48
|
this.stateMachine = stateMachine;
|
|
42
|
-
this.
|
|
49
|
+
this.contractStore = contractStore;
|
|
50
|
+
this.noteStore = noteStore;
|
|
43
51
|
this.keyStore = keyStore;
|
|
44
|
-
this.
|
|
45
|
-
this.
|
|
46
|
-
this.
|
|
52
|
+
this.addressStore = addressStore;
|
|
53
|
+
this.accountStore = accountStore;
|
|
54
|
+
this.senderTaggingStore = senderTaggingStore;
|
|
55
|
+
this.recipientTaggingStore = recipientTaggingStore;
|
|
56
|
+
this.senderAddressBookStore = senderAddressBookStore;
|
|
57
|
+
this.capsuleStore = capsuleStore;
|
|
58
|
+
this.privateEventStore = privateEventStore;
|
|
47
59
|
this.nextBlockTimestamp = nextBlockTimestamp;
|
|
48
60
|
this.version = version;
|
|
49
61
|
this.chainId = chainId;
|
|
50
62
|
this.authwits = authwits;
|
|
63
|
+
this.contractSyncService = contractSyncService;
|
|
51
64
|
this.isMisc = true;
|
|
52
65
|
this.isTxe = true;
|
|
53
66
|
this.logger = createLogger('txe:top_level_context');
|
|
54
67
|
this.logger.debug('Entering Top Level Context');
|
|
55
68
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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})`);
|
|
59
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;
|
|
60
83
|
}
|
|
61
84
|
// This is typically only invoked in private contexts, but it is convenient to also have it in top-level for testing
|
|
62
85
|
// setup.
|
|
63
|
-
|
|
86
|
+
getRandomField() {
|
|
64
87
|
return Fr.random();
|
|
65
88
|
}
|
|
66
89
|
// We instruct users to debug contracts via this oracle, so it makes sense that they'd expect it to also work in tests
|
|
67
|
-
|
|
90
|
+
log(level, message, fields) {
|
|
68
91
|
if (!LogLevels[level]) {
|
|
69
|
-
throw new Error(`Invalid
|
|
92
|
+
throw new Error(`Invalid log level: ${level}`);
|
|
70
93
|
}
|
|
71
94
|
const levelName = LogLevels[level];
|
|
72
95
|
this.logger[levelName](`${applyStringFormatting(message, fields)}`, {
|
|
73
96
|
module: `${this.logger.module}:debug_log`
|
|
74
97
|
});
|
|
98
|
+
return Promise.resolve();
|
|
99
|
+
}
|
|
100
|
+
getDefaultAddress() {
|
|
101
|
+
return DEFAULT_ADDRESS;
|
|
75
102
|
}
|
|
76
|
-
async
|
|
77
|
-
return await this.getLastBlockNumber() + 1;
|
|
103
|
+
async getNextBlockNumber() {
|
|
104
|
+
return BlockNumber(await this.getLastBlockNumber() + 1);
|
|
78
105
|
}
|
|
79
|
-
|
|
106
|
+
getNextBlockTimestamp() {
|
|
80
107
|
return Promise.resolve(this.nextBlockTimestamp);
|
|
81
108
|
}
|
|
82
|
-
async
|
|
109
|
+
async getLastBlockTimestamp() {
|
|
83
110
|
return (await this.stateMachine.node.getBlockHeader('latest')).globalVariables.timestamp;
|
|
84
111
|
}
|
|
85
|
-
async
|
|
86
|
-
const
|
|
112
|
+
async getLastTxEffects() {
|
|
113
|
+
const latestBlockNumber = await this.stateMachine.archiver.getBlockNumber();
|
|
114
|
+
const block = await this.stateMachine.archiver.getBlock(latestBlockNumber);
|
|
87
115
|
if (block.body.txEffects.length != 1) {
|
|
88
116
|
// Note that calls like env.mine() will result in blocks with no transactions, hitting this
|
|
89
117
|
throw new Error(`Expected a single transaction in the last block, found ${block.body.txEffects.length}`);
|
|
@@ -95,17 +123,39 @@ export class TXEOracleTopLevelContext {
|
|
|
95
123
|
nullifiers: txEffects.nullifiers
|
|
96
124
|
};
|
|
97
125
|
}
|
|
98
|
-
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) {
|
|
139
|
+
return (await this.privateEventStore.getPrivateEvents(selector, {
|
|
140
|
+
contractAddress,
|
|
141
|
+
scopes: [
|
|
142
|
+
scope
|
|
143
|
+
],
|
|
144
|
+
fromBlock: 0,
|
|
145
|
+
toBlock: await this.getLastBlockNumber() + 1
|
|
146
|
+
})).map((e)=>e.packedEvent);
|
|
147
|
+
}
|
|
148
|
+
async advanceBlocksBy(blocks) {
|
|
99
149
|
this.logger.debug(`time traveling ${blocks} blocks`);
|
|
100
150
|
for(let i = 0; i < blocks; i++){
|
|
101
151
|
await this.mineBlock();
|
|
102
152
|
}
|
|
103
153
|
}
|
|
104
|
-
|
|
154
|
+
advanceTimestampBy(duration) {
|
|
105
155
|
this.logger.debug(`time traveling ${duration} seconds`);
|
|
106
156
|
this.nextBlockTimestamp += duration;
|
|
107
157
|
}
|
|
108
|
-
async
|
|
158
|
+
async deploy(artifact, instance, secret) {
|
|
109
159
|
// Emit deployment nullifier
|
|
110
160
|
await this.mineBlock({
|
|
111
161
|
nullifiers: [
|
|
@@ -113,34 +163,34 @@ export class TXEOracleTopLevelContext {
|
|
|
113
163
|
]
|
|
114
164
|
});
|
|
115
165
|
if (!secret.equals(Fr.ZERO)) {
|
|
116
|
-
await this.
|
|
166
|
+
await this.addAccount(artifact, instance, secret);
|
|
117
167
|
} else {
|
|
118
|
-
await this.
|
|
119
|
-
await this.
|
|
168
|
+
await this.contractStore.addContractInstance(instance);
|
|
169
|
+
await this.contractStore.addContractArtifact(artifact);
|
|
120
170
|
this.logger.debug(`Deployed ${artifact.name} at ${instance.address}`);
|
|
121
171
|
}
|
|
122
172
|
}
|
|
123
|
-
async
|
|
173
|
+
async addAccount(artifact, instance, secret) {
|
|
124
174
|
const partialAddress = await computePartialAddress(instance);
|
|
125
175
|
this.logger.debug(`Deployed ${artifact.name} at ${instance.address}`);
|
|
126
|
-
await this.
|
|
127
|
-
await this.
|
|
176
|
+
await this.contractStore.addContractInstance(instance);
|
|
177
|
+
await this.contractStore.addContractArtifact(artifact);
|
|
128
178
|
const completeAddress = await this.keyStore.addAccount(secret, partialAddress);
|
|
129
|
-
await this.
|
|
130
|
-
await this.
|
|
179
|
+
await this.accountStore.setAccount(completeAddress.address, completeAddress);
|
|
180
|
+
await this.addressStore.addCompleteAddress(completeAddress);
|
|
131
181
|
this.logger.debug(`Created account ${completeAddress.address}`);
|
|
132
182
|
return completeAddress;
|
|
133
183
|
}
|
|
134
|
-
async
|
|
135
|
-
// This is a
|
|
184
|
+
async createAccount(secret) {
|
|
185
|
+
// This is a foot gun !
|
|
136
186
|
const completeAddress = await this.keyStore.addAccount(secret, secret);
|
|
137
|
-
await this.
|
|
138
|
-
await this.
|
|
187
|
+
await this.accountStore.setAccount(completeAddress.address, completeAddress);
|
|
188
|
+
await this.addressStore.addCompleteAddress(completeAddress);
|
|
139
189
|
this.logger.debug(`Created account ${completeAddress.address}`);
|
|
140
190
|
return completeAddress;
|
|
141
191
|
}
|
|
142
|
-
async
|
|
143
|
-
const account = await this.
|
|
192
|
+
async addAuthWitness(address, messageHash) {
|
|
193
|
+
const account = await this.accountStore.getAccount(address);
|
|
144
194
|
const privateKey = await this.keyStore.getMasterSecretKey(account.publicKeys.masterIncomingViewingPublicKey);
|
|
145
195
|
const schnorr = new Schnorr();
|
|
146
196
|
const signature = await schnorr.constructSignature(messageHash.toBuffer(), privateKey);
|
|
@@ -150,7 +200,7 @@ export class TXEOracleTopLevelContext {
|
|
|
150
200
|
this.authwits.set(authWitness.requestHash.toString(), authWitness);
|
|
151
201
|
}
|
|
152
202
|
async mineBlock(options = {}) {
|
|
153
|
-
const blockNumber = await this.
|
|
203
|
+
const blockNumber = await this.getNextBlockNumber();
|
|
154
204
|
const txEffect = TxEffect.empty();
|
|
155
205
|
txEffect.nullifiers = [
|
|
156
206
|
getSingleTxBlockRequestHash(blockNumber),
|
|
@@ -159,42 +209,87 @@ export class TXEOracleTopLevelContext {
|
|
|
159
209
|
txEffect.txHash = new TxHash(new Fr(blockNumber));
|
|
160
210
|
const forkedWorldTrees = await this.stateMachine.synchronizer.nativeWorldStateService.fork();
|
|
161
211
|
await insertTxEffectIntoWorldTrees(txEffect, forkedWorldTrees);
|
|
162
|
-
const
|
|
212
|
+
const globals = makeGlobalVariables(undefined, {
|
|
163
213
|
blockNumber,
|
|
164
214
|
timestamp: this.nextBlockTimestamp,
|
|
165
215
|
version: this.version,
|
|
166
216
|
chainId: this.chainId
|
|
167
|
-
})
|
|
217
|
+
});
|
|
218
|
+
const block = await makeTXEBlock(forkedWorldTrees, globals, [
|
|
168
219
|
txEffect
|
|
169
|
-
])
|
|
220
|
+
]);
|
|
170
221
|
await forkedWorldTrees.close();
|
|
171
222
|
this.logger.info(`Created block ${blockNumber} with timestamp ${block.header.globalVariables.timestamp}`);
|
|
172
223
|
await this.stateMachine.handleL2Block(block);
|
|
173
224
|
}
|
|
174
|
-
async
|
|
175
|
-
this.logger.verbose(`Executing external function ${await this.
|
|
176
|
-
const artifact = await this.
|
|
225
|
+
async privateCallNewFlow(from, targetContractAddress = AztecAddress.zero(), functionSelector = FunctionSelector.empty(), args, argsHash = Fr.zero(), isStaticCall = false, jobId) {
|
|
226
|
+
this.logger.verbose(`Executing external function ${await this.contractStore.getDebugFunctionName(targetContractAddress, functionSelector)}@${targetContractAddress} isStaticCall=${isStaticCall}`);
|
|
227
|
+
const artifact = await this.contractStore.getFunctionArtifact(targetContractAddress, functionSelector);
|
|
177
228
|
if (!artifact) {
|
|
178
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';
|
|
179
230
|
throw new Error(message);
|
|
180
231
|
}
|
|
181
|
-
|
|
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
|
+
];
|
|
237
|
+
// Sync notes before executing private function to discover notes from previous transactions
|
|
238
|
+
const utilityExecutor = async (call, execScopes)=>{
|
|
239
|
+
await this.executeUtilityCall(call, execScopes, jobId);
|
|
240
|
+
};
|
|
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();
|
|
182
244
|
const callContext = new CallContext(from, targetContractAddress, functionSelector, isStaticCall);
|
|
183
|
-
const gasLimits = new Gas(
|
|
184
|
-
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);
|
|
185
247
|
const gasSettings = new GasSettings(gasLimits, teardownGasLimits, GasFees.empty(), GasFees.empty());
|
|
186
248
|
const txContext = new TxContext(this.chainId, this.version, gasSettings);
|
|
187
|
-
const blockHeader = await this.pxeOracleInterface.getAnchorBlockHeader();
|
|
188
249
|
const protocolNullifier = await computeProtocolNullifier(getSingleTxBlockRequestHash(blockNumber));
|
|
189
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);
|
|
190
256
|
const taggingIndexCache = new ExecutionTaggingIndexCache();
|
|
191
257
|
const simulator = new WASMSimulator();
|
|
192
|
-
const privateExecutionOracle = new PrivateExecutionOracle(
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
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
|
+
});
|
|
198
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.
|
|
199
294
|
let result;
|
|
200
295
|
let executionResult;
|
|
@@ -206,21 +301,19 @@ export class TXEOracleTopLevelContext {
|
|
|
206
301
|
r.publicInputs.publicTeardownCallRequest
|
|
207
302
|
]));
|
|
208
303
|
const publicFunctionsCalldata = await Promise.all(publicCallRequests.map(async (r)=>{
|
|
209
|
-
const calldata = await privateExecutionOracle.
|
|
304
|
+
const calldata = await privateExecutionOracle.getHashPreimage(r.calldataHash);
|
|
210
305
|
return new HashedValues(calldata, r.calldataHash);
|
|
211
306
|
}));
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
result = new PrivateExecutionResult(executionResult, Fr.ZERO, publicFunctionsCalldata);
|
|
307
|
+
noteCache.finish();
|
|
308
|
+
const nonceGenerator = noteCache.getNonceGenerator();
|
|
309
|
+
result = new PrivateExecutionResult(executionResult, nonceGenerator, publicFunctionsCalldata);
|
|
216
310
|
} catch (err) {
|
|
217
311
|
throw createSimulationError(err instanceof Error ? err : new Error('Unknown error during private execution'));
|
|
218
312
|
}
|
|
219
|
-
// According to the protocol rules,
|
|
220
|
-
//
|
|
221
|
-
//
|
|
222
|
-
const
|
|
223
|
-
const { publicInputs } = await generateSimulatedProvingResult(result, nonceGenerator, this.contractDataProvider);
|
|
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);
|
|
224
317
|
const globals = makeGlobalVariables();
|
|
225
318
|
globals.blockNumber = blockNumber;
|
|
226
319
|
globals.timestamp = this.nextBlockTimestamp;
|
|
@@ -228,7 +321,8 @@ export class TXEOracleTopLevelContext {
|
|
|
228
321
|
globals.version = this.version;
|
|
229
322
|
globals.gasFees = GasFees.empty();
|
|
230
323
|
const forkedWorldTrees = await this.stateMachine.synchronizer.nativeWorldStateService.fork();
|
|
231
|
-
const
|
|
324
|
+
const bindings = this.logger.getBindings();
|
|
325
|
+
const contractsDB = new PublicContractsDB(new TXEPublicContractDataSource(blockNumber, this.contractStore), bindings);
|
|
232
326
|
const guardedMerkleTrees = new GuardedMerkleTreeOperations(forkedWorldTrees);
|
|
233
327
|
const config = PublicSimulatorConfig.from({
|
|
234
328
|
skipFeeEnforcement: true,
|
|
@@ -237,7 +331,7 @@ export class TXEOracleTopLevelContext {
|
|
|
237
331
|
collectStatistics: false,
|
|
238
332
|
collectCallMetadata: true
|
|
239
333
|
});
|
|
240
|
-
const processor = new PublicProcessor(globals, guardedMerkleTrees, contractsDB, new
|
|
334
|
+
const processor = new PublicProcessor(globals, guardedMerkleTrees, contractsDB, new CppPublicTxSimulator(guardedMerkleTrees, contractsDB, globals, config, bindings), new TestDateProvider(), undefined, createLogger('simulator:public-processor', bindings));
|
|
241
335
|
const tx = await Tx.create({
|
|
242
336
|
data: publicInputs,
|
|
243
337
|
chonkProof: ChonkProof.empty(),
|
|
@@ -258,7 +352,7 @@ export class TXEOracleTopLevelContext {
|
|
|
258
352
|
} else if (!processedTx.revertCode.isOK()) {
|
|
259
353
|
if (processedTx.revertReason) {
|
|
260
354
|
try {
|
|
261
|
-
await enrichPublicSimulationError(processedTx.revertReason, this.
|
|
355
|
+
await enrichPublicSimulationError(processedTx.revertReason, this.contractStore, this.logger);
|
|
262
356
|
// eslint-disable-next-line no-empty
|
|
263
357
|
} catch {}
|
|
264
358
|
throw new Error(`Contract execution has reverted: ${processedTx.revertReason.getMessage()}`);
|
|
@@ -280,22 +374,21 @@ export class TXEOracleTopLevelContext {
|
|
|
280
374
|
txEffect.txHash = new TxHash(new Fr(blockNumber));
|
|
281
375
|
const l1ToL2Messages = Array(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP).fill(0).map(Fr.zero);
|
|
282
376
|
await forkedWorldTrees.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, l1ToL2Messages);
|
|
283
|
-
const
|
|
377
|
+
const l2Block = await makeTXEBlock(forkedWorldTrees, globals, [
|
|
284
378
|
txEffect
|
|
285
379
|
]);
|
|
286
|
-
const l2Block = new L2Block(makeAppendOnlyTreeSnapshot(), await makeTXEBlockHeader(forkedWorldTrees, globals), body);
|
|
287
380
|
await this.stateMachine.handleL2Block(l2Block);
|
|
288
381
|
await forkedWorldTrees.close();
|
|
289
382
|
return executionResult.returnValues ?? [];
|
|
290
383
|
}
|
|
291
|
-
async
|
|
292
|
-
this.logger.verbose(`Executing public function ${await this.
|
|
293
|
-
const blockNumber = await this.
|
|
294
|
-
const gasLimits = new Gas(
|
|
295
|
-
const teardownGasLimits = new Gas(
|
|
384
|
+
async publicCallNewFlow(from, targetContractAddress, calldata, isStaticCall) {
|
|
385
|
+
this.logger.verbose(`Executing public function ${await this.contractStore.getDebugFunctionName(targetContractAddress, FunctionSelector.fromField(calldata[0]))}@${targetContractAddress} isStaticCall=${isStaticCall}`);
|
|
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);
|
|
296
389
|
const gasSettings = new GasSettings(gasLimits, teardownGasLimits, GasFees.empty(), GasFees.empty());
|
|
297
390
|
const txContext = new TxContext(this.chainId, this.version, gasSettings);
|
|
298
|
-
const anchorBlockHeader = await this.
|
|
391
|
+
const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
299
392
|
const calldataHash = await computeCalldataHash(calldata);
|
|
300
393
|
const calldataHashedValues = new HashedValues(calldata, calldataHash);
|
|
301
394
|
const globals = makeGlobalVariables();
|
|
@@ -305,7 +398,8 @@ export class TXEOracleTopLevelContext {
|
|
|
305
398
|
globals.version = this.version;
|
|
306
399
|
globals.gasFees = GasFees.empty();
|
|
307
400
|
const forkedWorldTrees = await this.stateMachine.synchronizer.nativeWorldStateService.fork();
|
|
308
|
-
const
|
|
401
|
+
const bindings2 = this.logger.getBindings();
|
|
402
|
+
const contractsDB = new PublicContractsDB(new TXEPublicContractDataSource(blockNumber, this.contractStore), bindings2);
|
|
309
403
|
const guardedMerkleTrees = new GuardedMerkleTreeOperations(forkedWorldTrees);
|
|
310
404
|
const config = PublicSimulatorConfig.from({
|
|
311
405
|
skipFeeEnforcement: true,
|
|
@@ -314,23 +408,21 @@ export class TXEOracleTopLevelContext {
|
|
|
314
408
|
collectStatistics: false,
|
|
315
409
|
collectCallMetadata: true
|
|
316
410
|
});
|
|
317
|
-
const simulator = new
|
|
318
|
-
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));
|
|
319
413
|
// We're simulating a scenario in which private execution immediately enqueues a public call and halts. The private
|
|
320
414
|
// kernel init would in this case inject a nullifier with the transaction request hash as a non-revertible
|
|
321
415
|
// side-effect, which the AVM then expects to exist in order to use it as the nonce generator when siloing notes as
|
|
322
416
|
// unique.
|
|
323
417
|
const nonRevertibleAccumulatedData = PrivateToPublicAccumulatedData.empty();
|
|
324
|
-
|
|
325
|
-
nonRevertibleAccumulatedData.nullifiers[0] = getSingleTxBlockRequestHash(blockNumber);
|
|
326
|
-
}
|
|
418
|
+
nonRevertibleAccumulatedData.nullifiers[0] = getSingleTxBlockRequestHash(blockNumber);
|
|
327
419
|
// The enqueued public call itself we make be revertible so that the public execution is itself revertible, as tests
|
|
328
420
|
// may require producing reverts.
|
|
329
421
|
const revertibleAccumulatedData = PrivateToPublicAccumulatedData.empty();
|
|
330
422
|
revertibleAccumulatedData.publicCallRequests[0] = new PublicCallRequest(from, targetContractAddress, isStaticCall, calldataHash);
|
|
331
423
|
const inputsForPublic = new PartialPrivateTailPublicInputsForPublic(nonRevertibleAccumulatedData, revertibleAccumulatedData, PublicCallRequest.empty());
|
|
332
424
|
const constantData = new TxConstantData(anchorBlockHeader, txContext, Fr.zero(), Fr.zero());
|
|
333
|
-
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);
|
|
334
426
|
const tx = await Tx.create({
|
|
335
427
|
data: txData,
|
|
336
428
|
chonkProof: ChonkProof.empty(),
|
|
@@ -353,7 +445,7 @@ export class TXEOracleTopLevelContext {
|
|
|
353
445
|
} else if (!processedTx.revertCode.isOK()) {
|
|
354
446
|
if (processedTx.revertReason) {
|
|
355
447
|
try {
|
|
356
|
-
await enrichPublicSimulationError(processedTx.revertReason, this.
|
|
448
|
+
await enrichPublicSimulationError(processedTx.revertReason, this.contractStore, this.logger);
|
|
357
449
|
// eslint-disable-next-line no-empty
|
|
358
450
|
} catch {}
|
|
359
451
|
throw new Error(`Contract execution has reverted: ${processedTx.revertReason.getMessage()}`);
|
|
@@ -376,25 +468,37 @@ export class TXEOracleTopLevelContext {
|
|
|
376
468
|
txEffect.txHash = new TxHash(new Fr(blockNumber));
|
|
377
469
|
const l1ToL2Messages = Array(NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP).fill(0).map(Fr.zero);
|
|
378
470
|
await forkedWorldTrees.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, l1ToL2Messages);
|
|
379
|
-
const
|
|
471
|
+
const l2Block = await makeTXEBlock(forkedWorldTrees, globals, [
|
|
380
472
|
txEffect
|
|
381
473
|
]);
|
|
382
|
-
const l2Block = new L2Block(makeAppendOnlyTreeSnapshot(), await makeTXEBlockHeader(forkedWorldTrees, globals), body);
|
|
383
474
|
await this.stateMachine.handleL2Block(l2Block);
|
|
384
475
|
await forkedWorldTrees.close();
|
|
385
476
|
return returnValues ?? [];
|
|
386
477
|
}
|
|
387
|
-
async
|
|
388
|
-
const artifact = await this.
|
|
478
|
+
async executeUtilityFunction(targetContractAddress, functionSelector, args, jobId) {
|
|
479
|
+
const artifact = await this.contractStore.getFunctionArtifact(targetContractAddress, functionSelector);
|
|
389
480
|
if (!artifact) {
|
|
390
481
|
throw new Error(`Cannot call ${functionSelector} as there is no artifact found at ${targetContractAddress}.`);
|
|
391
482
|
}
|
|
392
|
-
|
|
483
|
+
// Sync notes before executing utility function to discover notes from previous transactions
|
|
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({
|
|
393
489
|
name: artifact.name,
|
|
490
|
+
to: targetContractAddress,
|
|
394
491
|
selector: functionSelector,
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
492
|
+
type: FunctionType.UTILITY,
|
|
493
|
+
hideMsgSender: false,
|
|
494
|
+
isStatic: false,
|
|
495
|
+
args,
|
|
496
|
+
returnTypes: []
|
|
497
|
+
});
|
|
498
|
+
return this.executeUtilityCall(call, await this.keyStore.getAccounts(), jobId);
|
|
499
|
+
}
|
|
500
|
+
async executeUtilityCall(call, scopes, jobId) {
|
|
501
|
+
const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
|
|
398
502
|
if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
|
|
399
503
|
throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
|
|
400
504
|
}
|
|
@@ -403,8 +507,28 @@ export class TXEOracleTopLevelContext {
|
|
|
403
507
|
selector: call.selector
|
|
404
508
|
});
|
|
405
509
|
try {
|
|
406
|
-
const
|
|
407
|
-
const
|
|
510
|
+
const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
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
|
+
});
|
|
531
|
+
const acirExecutionResult = await new WASMSimulator().executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, new Oracle(oracle).toACIRCallback()).catch((err)=>{
|
|
408
532
|
err.message = resolveAssertionMessageFromError(err, entryPointArtifact);
|
|
409
533
|
throw new ExecutionError(err.message, {
|
|
410
534
|
contractAddress: call.to,
|
|
@@ -413,10 +537,10 @@ export class TXEOracleTopLevelContext {
|
|
|
413
537
|
cause: err
|
|
414
538
|
});
|
|
415
539
|
});
|
|
416
|
-
this.logger.verbose(`Utility
|
|
540
|
+
this.logger.verbose(`Utility execution for ${call.to}.${call.selector} completed`);
|
|
417
541
|
return witnessMapToFields(acirExecutionResult.returnWitness);
|
|
418
542
|
} catch (err) {
|
|
419
|
-
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'));
|
|
420
544
|
}
|
|
421
545
|
}
|
|
422
546
|
close() {
|
|
@@ -427,6 +551,7 @@ export class TXEOracleTopLevelContext {
|
|
|
427
551
|
];
|
|
428
552
|
}
|
|
429
553
|
async getLastBlockNumber() {
|
|
430
|
-
|
|
554
|
+
const header = await this.stateMachine.node.getBlockHeader('latest');
|
|
555
|
+
return header ? header.globalVariables.blockNumber : BlockNumber.ZERO;
|
|
431
556
|
}
|
|
432
557
|
}
|