@aztec/txe 0.0.1-commit.c2eed6949 → 0.0.1-commit.c52d6e7
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/AuthRegistry-QVGDDH5X.js +3 -0
- package/dest/AuthRegistry-QVGDDH5X.js.map +7 -0
- package/dest/ContractClassRegistry-PVNCKGG7.js +3 -0
- package/dest/ContractClassRegistry-PVNCKGG7.js.map +7 -0
- package/dest/ContractInstanceRegistry-WLOZKTR6.js +3 -0
- package/dest/ContractInstanceRegistry-WLOZKTR6.js.map +7 -0
- package/dest/FeeJuice-MAQJU53K.js +3 -0
- package/dest/FeeJuice-MAQJU53K.js.map +7 -0
- package/dest/HandshakeRegistry-GY5CPEPS.js +3 -0
- package/dest/HandshakeRegistry-GY5CPEPS.js.map +7 -0
- package/dest/MultiCallEntrypoint-QG5H33ZZ.js +3 -0
- package/dest/MultiCallEntrypoint-QG5H33ZZ.js.map +7 -0
- package/dest/SchnorrAccount-ADD65DYA.js +3 -0
- package/dest/SchnorrAccount-ADD65DYA.js.map +7 -0
- package/dest/SchnorrInitializerlessAccount-TWGKRUSY.js +3 -0
- package/dest/SchnorrInitializerlessAccount-TWGKRUSY.js.map +7 -0
- package/dest/bin/check_txe_oracle_version.d.ts +2 -0
- package/dest/bin/check_txe_oracle_version.d.ts.map +1 -0
- package/dest/bin/check_txe_oracle_version.js +22 -0
- package/dest/bin/index.js +3 -30
- package/dest/bin/index.js.map +7 -0
- package/dest/bin/oracle_test_server.d.ts +3 -0
- package/dest/bin/oracle_test_server.d.ts.map +1 -0
- package/dest/bin/oracle_test_server.js +41 -0
- package/dest/chunk-32UHX7YY.js +3 -0
- package/dest/chunk-32UHX7YY.js.map +7 -0
- package/dest/chunk-RVEPNDEP.js +304 -0
- package/dest/chunk-RVEPNDEP.js.map +7 -0
- package/dest/chunk-XWIMXLKD.js +258 -0
- package/dest/chunk-XWIMXLKD.js.map +7 -0
- package/dest/constants.d.ts +5 -1
- package/dest/constants.d.ts.map +1 -1
- package/dest/constants.js +9 -1
- package/dest/dispatcher_pool.d.ts +67 -0
- package/dest/dispatcher_pool.d.ts.map +1 -0
- package/dest/dispatcher_pool.js +286 -0
- package/dest/index.d.ts +51 -7
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +72 -190
- package/dest/metafile.json +38833 -0
- package/dest/msgpackr_fr_extension.d.ts +2 -0
- package/dest/msgpackr_fr_extension.d.ts.map +1 -0
- package/dest/msgpackr_fr_extension.js +21 -0
- package/dest/oracle/interfaces.d.ts +47 -9
- package/dest/oracle/interfaces.d.ts.map +1 -1
- package/dest/oracle/tagging_secret_strategy.d.ts +12 -0
- package/dest/oracle/tagging_secret_strategy.d.ts.map +1 -0
- package/dest/oracle/tagging_secret_strategy.js +12 -0
- package/dest/oracle/test-resolver/default_fixtures.d.ts +16 -0
- package/dest/oracle/test-resolver/default_fixtures.d.ts.map +1 -0
- package/dest/oracle/test-resolver/default_fixtures.js +200 -0
- package/dest/oracle/test-resolver/index.d.ts +9 -0
- package/dest/oracle/test-resolver/index.d.ts.map +1 -0
- package/dest/oracle/test-resolver/index.js +32 -0
- package/dest/oracle/test-resolver/resolver.d.ts +48 -0
- package/dest/oracle/test-resolver/resolver.d.ts.map +1 -0
- package/dest/oracle/test-resolver/resolver.js +181 -0
- package/dest/oracle/txe_oracle_public_context.d.ts +26 -2
- package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.js +49 -1
- package/dest/oracle/txe_oracle_registry.d.ts +172 -0
- package/dest/oracle/txe_oracle_registry.d.ts.map +1 -0
- package/dest/oracle/txe_oracle_registry.js +767 -0
- package/dest/oracle/txe_oracle_top_level_context.d.ts +58 -18
- package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_top_level_context.js +558 -304
- package/dest/oracle/txe_oracle_version.d.ts +17 -0
- package/dest/oracle/txe_oracle_version.d.ts.map +1 -0
- package/dest/oracle/txe_oracle_version.js +14 -0
- package/dest/oracle/txe_private_execution_oracle.d.ts +17 -0
- package/dest/oracle/txe_private_execution_oracle.d.ts.map +1 -0
- package/dest/oracle/txe_private_execution_oracle.js +15 -0
- package/dest/rpc_server.d.ts +14 -0
- package/dest/rpc_server.d.ts.map +1 -0
- package/dest/rpc_server.js +78 -0
- package/dest/rpc_translator.d.ts +116 -233
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +799 -636
- package/dest/server.bundle.js +3 -0
- package/dest/server.bundle.js.map +7 -0
- package/dest/state_machine/archiver.d.ts +4 -3
- package/dest/state_machine/archiver.d.ts.map +1 -1
- package/dest/state_machine/archiver.js +24 -14
- package/dest/state_machine/dummy_p2p_client.d.ts +16 -7
- package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
- package/dest/state_machine/dummy_p2p_client.js +25 -4
- package/dest/state_machine/global_variable_builder.d.ts +10 -6
- package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
- package/dest/state_machine/global_variable_builder.js +8 -5
- package/dest/state_machine/index.d.ts +11 -7
- package/dest/state_machine/index.d.ts.map +1 -1
- package/dest/state_machine/index.js +50 -14
- package/dest/state_machine/mock_epoch_cache.d.ts +2 -2
- package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
- package/dest/state_machine/mock_epoch_cache.js +3 -3
- package/dest/state_machine/synchronizer.d.ts +10 -2
- package/dest/state_machine/synchronizer.d.ts.map +1 -1
- package/dest/state_machine/synchronizer.js +19 -6
- package/dest/txe_session.d.ts +92 -20
- package/dest/txe_session.d.ts.map +1 -1
- package/dest/txe_session.js +324 -69
- package/dest/utils/block_creation.d.ts +2 -2
- package/dest/utils/block_creation.d.ts.map +1 -1
- package/dest/utils/block_creation.js +2 -2
- package/dest/utils/encoding.d.ts +194 -0
- package/dest/utils/encoding.d.ts.map +1 -0
- package/dest/{util → utils}/encoding.js +7 -2
- package/dest/{util → utils}/expected_failure_error.d.ts +1 -1
- package/dest/utils/expected_failure_error.d.ts.map +1 -0
- package/dest/utils/tx_effect_creation.d.ts +1 -1
- package/dest/utils/tx_effect_creation.d.ts.map +1 -1
- package/dest/utils/tx_effect_creation.js +0 -1
- package/dest/{util → utils}/txe_account_store.d.ts +1 -1
- package/dest/utils/txe_account_store.d.ts.map +1 -0
- package/dest/utils/txe_artifact_resolver.d.ts +37 -0
- package/dest/utils/txe_artifact_resolver.d.ts.map +1 -0
- package/dest/utils/txe_artifact_resolver.js +161 -0
- package/dest/utils/txe_public_contract_data_source.d.ts +20 -0
- package/dest/utils/txe_public_contract_data_source.d.ts.map +1 -0
- package/dest/{util → utils}/txe_public_contract_data_source.js +7 -4
- package/dest/worker.bundle.js +3 -0
- package/dest/worker.bundle.js.map +7 -0
- package/dest/worker.d.ts +2 -0
- package/dest/worker.d.ts.map +1 -0
- package/dest/worker.js +92 -0
- package/package.json +38 -21
- package/src/bin/check_txe_oracle_version.ts +31 -0
- package/src/bin/index.ts +11 -2
- package/src/bin/oracle_test_server.ts +51 -0
- package/src/constants.ts +11 -1
- package/src/dispatcher_pool.ts +317 -0
- package/src/index.ts +99 -227
- package/src/msgpackr_fr_extension.ts +23 -0
- package/src/oracle/interfaces.ts +47 -8
- package/src/oracle/tagging_secret_strategy.ts +25 -0
- package/src/oracle/test-resolver/default_fixtures.ts +271 -0
- package/src/oracle/test-resolver/index.ts +44 -0
- package/src/oracle/test-resolver/resolver.ts +245 -0
- package/src/oracle/txe_oracle_public_context.ts +62 -0
- package/src/oracle/txe_oracle_registry.ts +556 -0
- package/src/oracle/txe_oracle_top_level_context.ts +364 -117
- package/src/oracle/txe_oracle_version.ts +17 -0
- package/src/oracle/txe_private_execution_oracle.ts +30 -0
- package/src/rpc_server.ts +87 -0
- package/src/rpc_translator.ts +889 -901
- package/src/state_machine/archiver.ts +37 -16
- package/src/state_machine/dummy_p2p_client.ts +44 -11
- package/src/state_machine/global_variable_builder.ts +12 -11
- package/src/state_machine/index.ts +62 -32
- package/src/state_machine/mock_epoch_cache.ts +4 -4
- package/src/state_machine/synchronizer.ts +27 -6
- package/src/txe_session.ts +561 -85
- package/src/utils/block_creation.ts +2 -1
- package/src/{util → utils}/encoding.ts +8 -2
- package/src/utils/tx_effect_creation.ts +0 -2
- package/src/utils/txe_artifact_resolver.ts +217 -0
- package/src/{util → utils}/txe_public_contract_data_source.ts +6 -4
- package/src/worker.ts +98 -0
- package/dest/util/encoding.d.ts +0 -788
- package/dest/util/encoding.d.ts.map +0 -1
- package/dest/util/expected_failure_error.d.ts.map +0 -1
- package/dest/util/txe_account_store.d.ts.map +0 -1
- package/dest/util/txe_public_contract_data_source.d.ts +0 -20
- package/dest/util/txe_public_contract_data_source.d.ts.map +0 -1
- /package/dest/{util → utils}/expected_failure_error.js +0 -0
- /package/dest/{util → utils}/txe_account_store.js +0 -0
- /package/src/{util → utils}/expected_failure_error.ts +0 -0
- /package/src/{util → utils}/txe_account_store.ts +0 -0
package/src/txe_session.ts
CHANGED
|
@@ -2,31 +2,38 @@ import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
|
2
2
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
3
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
4
4
|
import { KeyStore } from '@aztec/key-store';
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
5
|
+
import type { AztecAsyncKVStore } from '@aztec/kv-store';
|
|
6
|
+
import { openEphemeralStore } from '@aztec/kv-store/lmdb-v2';
|
|
7
7
|
import {
|
|
8
8
|
AddressStore,
|
|
9
9
|
AnchorBlockStore,
|
|
10
|
+
AnchoredContractData,
|
|
11
|
+
CapsuleService,
|
|
10
12
|
CapsuleStore,
|
|
11
13
|
ContractStore,
|
|
12
|
-
|
|
14
|
+
FactService,
|
|
15
|
+
FactStore,
|
|
13
16
|
JobCoordinator,
|
|
14
17
|
NoteService,
|
|
15
18
|
NoteStore,
|
|
16
19
|
PrivateEventStore,
|
|
17
20
|
RecipientTaggingStore,
|
|
18
|
-
SenderAddressBookStore,
|
|
19
21
|
SenderTaggingStore,
|
|
22
|
+
TaggingSecretSourcesStore,
|
|
23
|
+
composeHooks,
|
|
20
24
|
} from '@aztec/pxe/server';
|
|
21
25
|
import {
|
|
22
26
|
ExecutionNoteCache,
|
|
23
27
|
ExecutionTaggingIndexCache,
|
|
24
28
|
HashedValuesCache,
|
|
29
|
+
type IMiscOracle,
|
|
25
30
|
type IPrivateExecutionOracle,
|
|
26
31
|
type IUtilityExecutionOracle,
|
|
27
|
-
|
|
28
|
-
|
|
32
|
+
LEGACY_ORACLE_REGISTRY,
|
|
33
|
+
Option,
|
|
34
|
+
TransientArrayService,
|
|
29
35
|
UtilityExecutionOracle,
|
|
36
|
+
buildACIRCallback,
|
|
30
37
|
} from '@aztec/pxe/simulator';
|
|
31
38
|
import {
|
|
32
39
|
ExecutionError,
|
|
@@ -36,28 +43,37 @@ import {
|
|
|
36
43
|
resolveAssertionMessageFromError,
|
|
37
44
|
toACVMWitness,
|
|
38
45
|
} from '@aztec/simulator/client';
|
|
39
|
-
import {
|
|
46
|
+
import { STANDARD_AUTH_REGISTRY_ADDRESS } from '@aztec/standard-contracts/auth-registry/constants';
|
|
47
|
+
import { EventSelector, FunctionCall, FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
|
|
40
48
|
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
41
49
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
42
|
-
import { GasSettings } from '@aztec/stdlib/gas';
|
|
50
|
+
import type { GasSettings } from '@aztec/stdlib/gas';
|
|
43
51
|
import { computeProtocolNullifier } from '@aztec/stdlib/hash';
|
|
44
52
|
import { PrivateContextInputs } from '@aztec/stdlib/kernel';
|
|
45
53
|
import { makeGlobalVariables } from '@aztec/stdlib/testing';
|
|
46
|
-
import { CallContext, GlobalVariables, TxContext } from '@aztec/stdlib/tx';
|
|
54
|
+
import { CallContext, GlobalVariables, OFFCHAIN_MESSAGE_IDENTIFIER, TxContext } from '@aztec/stdlib/tx';
|
|
47
55
|
|
|
48
56
|
import { z } from 'zod';
|
|
49
57
|
|
|
50
|
-
import { DEFAULT_ADDRESS } from './constants.js';
|
|
58
|
+
import { DEFAULT_ADDRESS, MAX_OFFCHAIN_EFFECTS_PER_TXE_QUERY, MAX_OFFCHAIN_EFFECT_LEN } from './constants.js';
|
|
51
59
|
import type { IAvmExecutionOracle, ITxeExecutionOracle } from './oracle/interfaces.js';
|
|
60
|
+
import {
|
|
61
|
+
type TXETaggingSecretStrategies,
|
|
62
|
+
makeResolveTaggingSecretStrategyHook,
|
|
63
|
+
} from './oracle/tagging_secret_strategy.js';
|
|
52
64
|
import { TXEOraclePublicContext } from './oracle/txe_oracle_public_context.js';
|
|
53
|
-
import {
|
|
54
|
-
import {
|
|
65
|
+
import { callTxeLegacyHandler } from './oracle/txe_oracle_registry.js';
|
|
66
|
+
import { TXEOracleTopLevelContext, authorizeAllUtilityCallsHook } from './oracle/txe_oracle_top_level_context.js';
|
|
67
|
+
import { TXE_ORACLE_VERSION_MAJOR, TXE_ORACLE_VERSION_MINOR } from './oracle/txe_oracle_version.js';
|
|
68
|
+
import { TXEPrivateExecutionOracle } from './oracle/txe_private_execution_oracle.js';
|
|
69
|
+
import { RPCTranslator, UnavailableOracleError } from './rpc_translator.js';
|
|
55
70
|
import { TXEArchiver } from './state_machine/archiver.js';
|
|
56
71
|
import { TXEStateMachine } from './state_machine/index.js';
|
|
57
|
-
import type { ForeignCallArgs, ForeignCallResult } from './util/encoding.js';
|
|
58
|
-
import { TXEAccountStore } from './util/txe_account_store.js';
|
|
59
72
|
import { getSingleTxBlockRequestHash, insertTxEffectIntoWorldTrees, makeTXEBlock } from './utils/block_creation.js';
|
|
73
|
+
import type { ForeignCallArgs, ForeignCallResult } from './utils/encoding.js';
|
|
60
74
|
import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
75
|
+
import { TXEAccountStore } from './utils/txe_account_store.js';
|
|
76
|
+
import type { TXEArtifactResolver } from './utils/txe_artifact_resolver.js';
|
|
61
77
|
|
|
62
78
|
/**
|
|
63
79
|
* A TXE Session can be in one of four states, which change as the test progresses and different oracles are called.
|
|
@@ -110,14 +126,111 @@ export type TXEOracleFunctionName = Exclude<
|
|
|
110
126
|
>;
|
|
111
127
|
|
|
112
128
|
export interface TXESessionStateHandler {
|
|
129
|
+
/** Records the TXE oracle version reported by the Noir test code for diagnostics. */
|
|
130
|
+
setTxeOracleVersion(major: number, minor: number): void;
|
|
131
|
+
|
|
113
132
|
enterTopLevelState(): Promise<void>;
|
|
114
|
-
enterPublicState(contractAddress
|
|
115
|
-
enterPrivateState(
|
|
116
|
-
|
|
133
|
+
enterPublicState(contractAddress: Option<AztecAddress>): Promise<void>;
|
|
134
|
+
enterPrivateState(
|
|
135
|
+
contractAddress: Option<AztecAddress>,
|
|
136
|
+
anchorBlockNumber: Option<BlockNumber>,
|
|
137
|
+
gasSettings: GasSettings,
|
|
138
|
+
): Promise<PrivateContextInputs>;
|
|
139
|
+
enterUtilityState(contractAddress: Option<AztecAddress>): Promise<void>;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Executes a top-level private call: runs the private function, drains its offchain effects into the session buffer,
|
|
143
|
+
* commits the job, and (for non-static calls) tags the result with the mined tx hash.
|
|
144
|
+
*/
|
|
145
|
+
executePrivateCall(
|
|
146
|
+
from: Option<AztecAddress>,
|
|
147
|
+
targetContractAddress: AztecAddress,
|
|
148
|
+
functionSelector: FunctionSelector,
|
|
149
|
+
args: Fr[],
|
|
150
|
+
argsHash: Fr,
|
|
151
|
+
isStaticCall: boolean,
|
|
152
|
+
additionalScopes: AztecAddress[],
|
|
153
|
+
authorizedUtilityCallTargets: AztecAddress[],
|
|
154
|
+
gasSettings: GasSettings,
|
|
155
|
+
): Promise<Fr[]>;
|
|
156
|
+
|
|
157
|
+
/** Executes a top-level utility function and commits the job. */
|
|
158
|
+
executeUtilityFunction(
|
|
159
|
+
from: Option<AztecAddress>,
|
|
160
|
+
targetContractAddress: AztecAddress,
|
|
161
|
+
functionSelector: FunctionSelector,
|
|
162
|
+
args: Fr[],
|
|
163
|
+
authorizedUtilityCallTargets: AztecAddress[],
|
|
164
|
+
): Promise<Fr[]>;
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Executes a top-level public call, commits the job, and (for non-static calls) tags the result with the mined tx
|
|
168
|
+
* hash.
|
|
169
|
+
*/
|
|
170
|
+
executePublicCall(
|
|
171
|
+
from: Option<AztecAddress>,
|
|
172
|
+
targetContractAddress: AztecAddress,
|
|
173
|
+
calldata: Fr[],
|
|
174
|
+
isStaticCall: boolean,
|
|
175
|
+
gasSettings: GasSettings,
|
|
176
|
+
): Promise<Fr[]>;
|
|
177
|
+
|
|
178
|
+
/** Syncs the target contract and returns the private events it emitted matching the given selector and scope. */
|
|
179
|
+
getPrivateEvents(selector: EventSelector, contractAddress: AztecAddress, scope: AztecAddress): Promise<Fr[][]>;
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Captures a raw offchain effect payload for consumption from test environment. Called by the `emit_offchain_effect`
|
|
183
|
+
* oracle handler whenever a contract function emits an offchain message, at any call depth.
|
|
184
|
+
*/
|
|
185
|
+
recordOffchainEffect(data: Fr[]): void;
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Returns the raw offchain effect payloads emitted by the last top-level call. Each payload follows the protocol
|
|
189
|
+
* convention documented on `OFFCHAIN_MESSAGE_IDENTIFIER`, i.e. `[identifier, recipient, ...ciphertext]`. Decoding into
|
|
190
|
+
* `OffchainMessage` structs happens on the Noir side of the test helper. Marks the buffer as queried so the
|
|
191
|
+
* unqueried-messages warning doesn't fire on the next reset.
|
|
192
|
+
*/
|
|
193
|
+
getLastCallOffchainEffects(): { effects: Fr[][] };
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Returns the context of the last top-level call: its tx hash (`Fr.ZERO` if the call was tx-less) and the anchor
|
|
197
|
+
* block timestamp captured at the start of the call. Does *not* mark the buffer as queried — context reads are
|
|
198
|
+
* metadata, not effect consumption.
|
|
199
|
+
*/
|
|
200
|
+
getLastCallContext(): { txHash: Fr; anchorBlockTimestamp: bigint };
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Session state tracking the most recently completed top-level call: the offchain effect buffer it produced, and the
|
|
205
|
+
* call's context (tx hash + anchor block timestamp). The context is refreshed on every top-level call, independently
|
|
206
|
+
* of whether the call produced offchain effects.
|
|
207
|
+
*/
|
|
208
|
+
interface LastCallState {
|
|
209
|
+
/**
|
|
210
|
+
* Raw offchain effect payloads emitted by the currently-executing (or most recently completed) top-level call. Wiped
|
|
211
|
+
* at the start of every top-level entry point, appended to on every `emit_offchain_effect` oracle invocation.
|
|
212
|
+
*/
|
|
213
|
+
offchainEffects: Fr[][];
|
|
214
|
+
/**
|
|
215
|
+
* Tracks whether the test has queried `effects` since the last reset. If a new top-level call clobbers the buffer
|
|
216
|
+
* without it being queried first, any accumulated messages are lost and we emit a warning so tests don't silently
|
|
217
|
+
* drop delivery.
|
|
218
|
+
*/
|
|
219
|
+
queried: boolean;
|
|
220
|
+
/**
|
|
221
|
+
* Tx hash of the most recently completed top-level call, or `Fr.ZERO` if the call was tx-less (context setters,
|
|
222
|
+
* utility execution). Populated by call executor handlers after execution completes.
|
|
223
|
+
*/
|
|
224
|
+
txHash: Fr;
|
|
225
|
+
/**
|
|
226
|
+
* Anchor block timestamp of the most recently completed top-level call, captured from the anchor block header that
|
|
227
|
+
* was active when the call started. Populated by call executor handlers after execution completes.
|
|
228
|
+
*/
|
|
229
|
+
anchorBlockTimestamp: bigint;
|
|
230
|
+
}
|
|
117
231
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
getCurrentJob(): string;
|
|
232
|
+
function emptyLastCallState(): LastCallState {
|
|
233
|
+
return { offchainEffects: [], queried: false, txHash: Fr.ZERO, anchorBlockTimestamp: 0n };
|
|
121
234
|
}
|
|
122
235
|
|
|
123
236
|
/**
|
|
@@ -127,11 +240,19 @@ export interface TXESessionStateHandler {
|
|
|
127
240
|
export class TXESession implements TXESessionStateHandler {
|
|
128
241
|
private state: SessionState = { name: 'TOP_LEVEL' };
|
|
129
242
|
private authwits: Map<string, AuthWitness> = new Map();
|
|
243
|
+
private taggingSecretStrategies: TXETaggingSecretStrategies = new Map();
|
|
244
|
+
private authorizeAllUtilityCallTargets = false;
|
|
245
|
+
private lastCallInfo: LastCallState = emptyLastCallState();
|
|
246
|
+
private txeOracleVersion: { major: number; minor: number } | undefined;
|
|
247
|
+
|
|
248
|
+
private disposed = false;
|
|
130
249
|
|
|
131
250
|
constructor(
|
|
132
251
|
private logger: Logger,
|
|
252
|
+
private sessionStore: AztecAsyncKVStore,
|
|
133
253
|
private stateMachine: TXEStateMachine,
|
|
134
254
|
private oracleHandler:
|
|
255
|
+
| IMiscOracle
|
|
135
256
|
| IUtilityExecutionOracle
|
|
136
257
|
| IPrivateExecutionOracle
|
|
137
258
|
| IAvmExecutionOracle
|
|
@@ -143,34 +264,76 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
143
264
|
private accountStore: TXEAccountStore,
|
|
144
265
|
private senderTaggingStore: SenderTaggingStore,
|
|
145
266
|
private recipientTaggingStore: RecipientTaggingStore,
|
|
146
|
-
private
|
|
267
|
+
private taggingSecretSourcesStore: TaggingSecretSourcesStore,
|
|
147
268
|
private capsuleStore: CapsuleStore,
|
|
269
|
+
private factStore: FactStore,
|
|
148
270
|
private privateEventStore: PrivateEventStore,
|
|
149
271
|
private jobCoordinator: JobCoordinator,
|
|
150
272
|
private currentJobId: string,
|
|
151
273
|
private chainId: Fr,
|
|
152
274
|
private version: Fr,
|
|
153
275
|
private nextBlockTimestamp: bigint,
|
|
154
|
-
private
|
|
276
|
+
private readonly artifactResolver: TXEArtifactResolver,
|
|
277
|
+
private readonly rootPath: string,
|
|
278
|
+
private readonly packageName: string,
|
|
155
279
|
) {}
|
|
156
280
|
|
|
157
|
-
|
|
158
|
-
|
|
281
|
+
/**
|
|
282
|
+
* Tears down the per-session AVM simulator (process pool + CDB server), the `NativeWorldStateService`,
|
|
283
|
+
* and the `txe-session` LMDB. Called via IPC when the dispatcher detects the end of a test. Idempotent.
|
|
284
|
+
*/
|
|
285
|
+
async dispose(): Promise<void> {
|
|
286
|
+
if (this.disposed) {
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
this.disposed = true;
|
|
290
|
+
// Dispose the AVM pool before the world state: it kills the bb-avm-sim processes so they release their
|
|
291
|
+
// connection to the WSDB server, letting it shut down cleanly. Skipping this leaks a bb-avm-sim process
|
|
292
|
+
// (and keeps its WSDB alive) per session.
|
|
293
|
+
try {
|
|
294
|
+
await this.stateMachine.synchronizer.closeIpc();
|
|
295
|
+
} catch (err) {
|
|
296
|
+
this.logger.warn(`Error closing AVM simulator during session dispose`, err);
|
|
297
|
+
}
|
|
298
|
+
try {
|
|
299
|
+
await this.stateMachine.synchronizer.nativeWorldStateService.close();
|
|
300
|
+
} catch (err) {
|
|
301
|
+
this.logger.warn(`Error closing native world state during session dispose`, err);
|
|
302
|
+
}
|
|
303
|
+
try {
|
|
304
|
+
await this.sessionStore.close();
|
|
305
|
+
} catch (err) {
|
|
306
|
+
this.logger.warn(`Error closing session LMDB during dispose`, err);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
static async init(
|
|
311
|
+
contractStore: ContractStore,
|
|
312
|
+
artifactResolver: TXEArtifactResolver,
|
|
313
|
+
rootPath: string,
|
|
314
|
+
packageName: string,
|
|
315
|
+
) {
|
|
316
|
+
// Size LMDB's reader slots to the libuv pool (capped to 2 in bin/index.ts via
|
|
317
|
+
// HARDWARE_CONCURRENCY): each native LMDB read needs a libuv worker thread to run, so any
|
|
318
|
+
// slot beyond the pool size would sit idle while still consuming a semaphore + reader-table
|
|
319
|
+
// entry per session.
|
|
320
|
+
const store = await openEphemeralStore('txe-session', undefined, 2);
|
|
159
321
|
|
|
160
322
|
const addressStore = new AddressStore(store);
|
|
161
323
|
const privateEventStore = new PrivateEventStore(store);
|
|
162
324
|
const noteStore = new NoteStore(store);
|
|
163
325
|
const senderTaggingStore = new SenderTaggingStore(store);
|
|
164
326
|
const recipientTaggingStore = new RecipientTaggingStore(store);
|
|
165
|
-
const
|
|
327
|
+
const taggingSecretSourcesStore = new TaggingSecretSourcesStore(store);
|
|
166
328
|
const capsuleStore = new CapsuleStore(store);
|
|
329
|
+
const factStore = new FactStore(store);
|
|
167
330
|
const keyStore = new KeyStore(store);
|
|
168
331
|
const accountStore = new TXEAccountStore(store);
|
|
169
332
|
|
|
170
|
-
// Create job coordinator and register staged stores
|
|
171
333
|
const jobCoordinator = new JobCoordinator(store);
|
|
172
334
|
jobCoordinator.registerStores([
|
|
173
335
|
capsuleStore,
|
|
336
|
+
factStore,
|
|
174
337
|
senderTaggingStore,
|
|
175
338
|
recipientTaggingStore,
|
|
176
339
|
privateEventStore,
|
|
@@ -188,7 +351,6 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
188
351
|
const initialJobId = jobCoordinator.beginJob();
|
|
189
352
|
|
|
190
353
|
const logger = createLogger('txe:session');
|
|
191
|
-
const contractSyncService = new ContractSyncService(stateMachine.node, contractStore, noteStore, logger);
|
|
192
354
|
|
|
193
355
|
const topLevelOracleHandler = new TXEOracleTopLevelContext(
|
|
194
356
|
stateMachine,
|
|
@@ -199,19 +361,26 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
199
361
|
accountStore,
|
|
200
362
|
senderTaggingStore,
|
|
201
363
|
recipientTaggingStore,
|
|
202
|
-
|
|
364
|
+
taggingSecretSourcesStore,
|
|
203
365
|
capsuleStore,
|
|
366
|
+
factStore,
|
|
204
367
|
privateEventStore,
|
|
205
368
|
nextBlockTimestamp,
|
|
206
369
|
version,
|
|
207
370
|
chainId,
|
|
208
371
|
new Map(),
|
|
209
|
-
|
|
372
|
+
new Map(),
|
|
373
|
+
false, // authorizeAllUtilityCallTargets
|
|
374
|
+
artifactResolver,
|
|
375
|
+
rootPath,
|
|
376
|
+
packageName,
|
|
210
377
|
);
|
|
211
|
-
|
|
378
|
+
|
|
379
|
+
await topLevelOracleHandler.mineDeploymentNullifiers([STANDARD_AUTH_REGISTRY_ADDRESS]);
|
|
212
380
|
|
|
213
381
|
return new TXESession(
|
|
214
382
|
logger,
|
|
383
|
+
store,
|
|
215
384
|
stateMachine,
|
|
216
385
|
topLevelOracleHandler,
|
|
217
386
|
contractStore,
|
|
@@ -221,15 +390,18 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
221
390
|
accountStore,
|
|
222
391
|
senderTaggingStore,
|
|
223
392
|
recipientTaggingStore,
|
|
224
|
-
|
|
393
|
+
taggingSecretSourcesStore,
|
|
225
394
|
capsuleStore,
|
|
395
|
+
factStore,
|
|
226
396
|
privateEventStore,
|
|
227
397
|
jobCoordinator,
|
|
228
398
|
initialJobId,
|
|
229
399
|
version,
|
|
230
400
|
chainId,
|
|
231
401
|
nextBlockTimestamp,
|
|
232
|
-
|
|
402
|
+
artifactResolver,
|
|
403
|
+
rootPath,
|
|
404
|
+
packageName,
|
|
233
405
|
);
|
|
234
406
|
}
|
|
235
407
|
|
|
@@ -241,6 +413,18 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
241
413
|
*/
|
|
242
414
|
processFunction(functionName: TXEOracleFunctionName, inputs: ForeignCallArgs): Promise<ForeignCallResult> {
|
|
243
415
|
try {
|
|
416
|
+
// Oracles retired into the PXE legacy registry have no translator method; dispatch them through the same
|
|
417
|
+
// buildACIRCallback legacy path that contract execution uses, keeping TXE's two oracle paths in sync.
|
|
418
|
+
// Use an own-property check: `in` would match inherited `Object.prototype` keys (e.g. `constructor`), routing
|
|
419
|
+
// them into the legacy path instead of letting them fall through to the unknown-oracle error.
|
|
420
|
+
if (Object.hasOwn(LEGACY_ORACLE_REGISTRY, functionName)) {
|
|
421
|
+
return callTxeLegacyHandler(
|
|
422
|
+
functionName,
|
|
423
|
+
inputs,
|
|
424
|
+
this.oracleHandler as Parameters<typeof buildACIRCallback>[0],
|
|
425
|
+
);
|
|
426
|
+
}
|
|
427
|
+
|
|
244
428
|
const translator = new RPCTranslator(this, this.oracleHandler) as any;
|
|
245
429
|
// We perform a runtime validation to check that the function name corresponds to a real oracle handler.
|
|
246
430
|
const validatedFunctionName = z
|
|
@@ -251,7 +435,28 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
251
435
|
return translator[validatedFunctionName](...inputs);
|
|
252
436
|
} catch (error) {
|
|
253
437
|
if (error instanceof z.ZodError) {
|
|
254
|
-
|
|
438
|
+
let versionHint: string;
|
|
439
|
+
if (!this.txeOracleVersion) {
|
|
440
|
+
versionHint =
|
|
441
|
+
' The test appears to use an older version of Aztec.nr that does not' +
|
|
442
|
+
' support test environment oracle versioning. Update Aztec.nr to a compatible version.' +
|
|
443
|
+
' See https://docs.aztec.network/errors/12';
|
|
444
|
+
} else if (this.txeOracleVersion.minor > TXE_ORACLE_VERSION_MINOR) {
|
|
445
|
+
versionHint =
|
|
446
|
+
` The test uses Aztec.nr test oracle version` +
|
|
447
|
+
` ${this.txeOracleVersion.major}.${this.txeOracleVersion.minor}, but this test environment` +
|
|
448
|
+
` only supports up to ${TXE_ORACLE_VERSION_MAJOR}.${TXE_ORACLE_VERSION_MINOR}.` +
|
|
449
|
+
` Upgrade the Aztec CLI to a compatible version.` +
|
|
450
|
+
` See https://docs.aztec.network/errors/12`;
|
|
451
|
+
} else {
|
|
452
|
+
versionHint =
|
|
453
|
+
` The test's oracle version (${this.txeOracleVersion.major}.${this.txeOracleVersion.minor})` +
|
|
454
|
+
` is compatible with this test environment` +
|
|
455
|
+
` (${TXE_ORACLE_VERSION_MAJOR}.${TXE_ORACLE_VERSION_MINOR}), so this oracle should be` +
|
|
456
|
+
` available. This is an unexpected error, please report it.` +
|
|
457
|
+
` See https://docs.aztec.network/errors/13`;
|
|
458
|
+
}
|
|
459
|
+
throw new Error(`Unknown oracle '${functionName}'.${versionHint}`);
|
|
255
460
|
} else if (error instanceof Error) {
|
|
256
461
|
throw new Error(
|
|
257
462
|
`Execution error while processing function ${functionName} in state ${this.state.name}: ${error.message}`,
|
|
@@ -264,17 +469,195 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
264
469
|
}
|
|
265
470
|
}
|
|
266
471
|
|
|
267
|
-
getCurrentJob(): string {
|
|
268
|
-
return this.currentJobId;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
472
|
/** Commits the current job and begins a new one. Returns the new job ID. */
|
|
272
|
-
async cycleJob(): Promise<string> {
|
|
473
|
+
private async cycleJob(): Promise<string> {
|
|
273
474
|
await this.jobCoordinator.commitJob(this.currentJobId);
|
|
274
475
|
this.currentJobId = this.jobCoordinator.beginJob();
|
|
275
476
|
return this.currentJobId;
|
|
276
477
|
}
|
|
277
478
|
|
|
479
|
+
private resetLastCall(): void {
|
|
480
|
+
const notQueriedMessageCount = this.lastCallInfo.queried
|
|
481
|
+
? 0
|
|
482
|
+
: this.lastCallInfo.offchainEffects.filter(payload => payload[0]?.equals(OFFCHAIN_MESSAGE_IDENTIFIER)).length;
|
|
483
|
+
if (notQueriedMessageCount > 0) {
|
|
484
|
+
this.logger.warn(
|
|
485
|
+
`Dropping ${notQueriedMessageCount} unqueried offchain message(s) from the previous top-level call. ` +
|
|
486
|
+
`To deliver them, call \`env.offchain_messages()\` and forward the result to the recipient contract's ` +
|
|
487
|
+
`\`offchain_receive\` utility before issuing another top-level call. To intentionally discard, assign ` +
|
|
488
|
+
`to \`let _ = env.offchain_messages()\` to silence this warning.`,
|
|
489
|
+
);
|
|
490
|
+
}
|
|
491
|
+
this.lastCallInfo = emptyLastCallState();
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
recordOffchainEffect(data: Fr[]): void {
|
|
495
|
+
this.lastCallInfo.offchainEffects.push(data);
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
private setLastCallContext(txHash: Fr, anchorBlockTimestamp: bigint): void {
|
|
499
|
+
this.lastCallInfo.txHash = txHash;
|
|
500
|
+
this.lastCallInfo.anchorBlockTimestamp = anchorBlockTimestamp;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
private async withTopLevelCallTracking<T>(work: () => Promise<{ result: T; txHash?: Fr }>): Promise<T> {
|
|
504
|
+
this.resetLastCall();
|
|
505
|
+
// Capture the anchor *before* `work` runs: private/public executor calls mine a new block as a
|
|
506
|
+
// side effect, and that block's timestamp should not be attributed to this call's anchor.
|
|
507
|
+
const anchorBlockTimestamp = (await this.stateMachine.node.getBlockData('latest'))!.header.globalVariables
|
|
508
|
+
.timestamp;
|
|
509
|
+
const { result, txHash } = await work();
|
|
510
|
+
this.setLastCallContext(txHash ?? Fr.ZERO, anchorBlockTimestamp);
|
|
511
|
+
return result;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
getLastCallOffchainEffects(): { effects: Fr[][] } {
|
|
515
|
+
this.lastCallInfo.queried = true;
|
|
516
|
+
const effects = this.lastCallInfo.offchainEffects;
|
|
517
|
+
|
|
518
|
+
if (effects.length > MAX_OFFCHAIN_EFFECTS_PER_TXE_QUERY) {
|
|
519
|
+
throw new Error(`${effects.length} offchain effects exceed max ${MAX_OFFCHAIN_EFFECTS_PER_TXE_QUERY}`);
|
|
520
|
+
}
|
|
521
|
+
if (effects.some(e => e.length > MAX_OFFCHAIN_EFFECT_LEN)) {
|
|
522
|
+
throw new Error(`Some offchain effect has length larger than max ${MAX_OFFCHAIN_EFFECT_LEN}`);
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
return { effects };
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
getLastCallContext(): { txHash: Fr; anchorBlockTimestamp: bigint } {
|
|
529
|
+
const { txHash, anchorBlockTimestamp } = this.lastCallInfo;
|
|
530
|
+
return { txHash, anchorBlockTimestamp };
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
async executePrivateCall(
|
|
534
|
+
from: Option<AztecAddress>,
|
|
535
|
+
targetContractAddress: AztecAddress,
|
|
536
|
+
functionSelector: FunctionSelector,
|
|
537
|
+
args: Fr[],
|
|
538
|
+
argsHash: Fr,
|
|
539
|
+
isStaticCall: boolean,
|
|
540
|
+
additionalScopes: AztecAddress[],
|
|
541
|
+
authorizedUtilityCallTargets: AztecAddress[],
|
|
542
|
+
gasSettings: GasSettings,
|
|
543
|
+
): Promise<Fr[]> {
|
|
544
|
+
const handler = this.handlerAsTxe();
|
|
545
|
+
return await this.withTopLevelCallTracking(async () => {
|
|
546
|
+
const { returnValues, offchainEffects } = await handler.privateCallNewFlow(
|
|
547
|
+
from?.value,
|
|
548
|
+
targetContractAddress,
|
|
549
|
+
functionSelector,
|
|
550
|
+
args,
|
|
551
|
+
argsHash,
|
|
552
|
+
isStaticCall,
|
|
553
|
+
additionalScopes,
|
|
554
|
+
this.currentJobId,
|
|
555
|
+
authorizedUtilityCallTargets,
|
|
556
|
+
gasSettings,
|
|
557
|
+
);
|
|
558
|
+
|
|
559
|
+
// Private execution collects offchain effects inside PXE's PrivateExecutionOracle rather than round-tripping
|
|
560
|
+
// them through `aztec_utl_emitOffchainEffect`, so the session buffer is empty at this point. Drain the effects
|
|
561
|
+
// from the execution tree into the session buffer so the next `env.offchain_messages()` call in the test sees
|
|
562
|
+
// them.
|
|
563
|
+
for (const data of offchainEffects) {
|
|
564
|
+
this.recordOffchainEffect(data);
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
await this.cycleJob();
|
|
568
|
+
|
|
569
|
+
if (isStaticCall) {
|
|
570
|
+
// Static calls revert their checkpoint and mine no block, so there is no tx hash to tag offchain effects
|
|
571
|
+
// with. Querying `getLastTxEffects()` here would return an unrelated predecessor tx.
|
|
572
|
+
return { result: returnValues };
|
|
573
|
+
}
|
|
574
|
+
const { txHash } = await handler.getLastTxEffects();
|
|
575
|
+
return { result: returnValues, txHash: txHash.hash };
|
|
576
|
+
});
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
async executeUtilityFunction(
|
|
580
|
+
from: Option<AztecAddress>,
|
|
581
|
+
targetContractAddress: AztecAddress,
|
|
582
|
+
functionSelector: FunctionSelector,
|
|
583
|
+
args: Fr[],
|
|
584
|
+
authorizedUtilityCallTargets: AztecAddress[],
|
|
585
|
+
): Promise<Fr[]> {
|
|
586
|
+
const handler = this.handlerAsTxe();
|
|
587
|
+
return await this.withTopLevelCallTracking(async () => {
|
|
588
|
+
const returnValues = await handler.executeUtilityFunction(
|
|
589
|
+
from?.value,
|
|
590
|
+
targetContractAddress,
|
|
591
|
+
functionSelector,
|
|
592
|
+
args,
|
|
593
|
+
this.currentJobId,
|
|
594
|
+
authorizedUtilityCallTargets,
|
|
595
|
+
);
|
|
596
|
+
|
|
597
|
+
await this.cycleJob();
|
|
598
|
+
|
|
599
|
+
return { result: returnValues };
|
|
600
|
+
});
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
async executePublicCall(
|
|
604
|
+
from: Option<AztecAddress>,
|
|
605
|
+
targetContractAddress: AztecAddress,
|
|
606
|
+
calldata: Fr[],
|
|
607
|
+
isStaticCall: boolean,
|
|
608
|
+
gasSettings: GasSettings,
|
|
609
|
+
): Promise<Fr[]> {
|
|
610
|
+
const handler = this.handlerAsTxe();
|
|
611
|
+
return await this.withTopLevelCallTracking(async () => {
|
|
612
|
+
const returnValues = await handler.publicCallNewFlow(
|
|
613
|
+
from?.value,
|
|
614
|
+
targetContractAddress,
|
|
615
|
+
calldata,
|
|
616
|
+
isStaticCall,
|
|
617
|
+
gasSettings,
|
|
618
|
+
);
|
|
619
|
+
|
|
620
|
+
await this.cycleJob();
|
|
621
|
+
|
|
622
|
+
if (isStaticCall) {
|
|
623
|
+
// See the equivalent branch in `executePrivateCall`.
|
|
624
|
+
return { result: returnValues };
|
|
625
|
+
}
|
|
626
|
+
const { txHash } = await handler.getLastTxEffects();
|
|
627
|
+
return { result: returnValues, txHash: txHash.hash };
|
|
628
|
+
});
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
async getPrivateEvents(selector: EventSelector, contractAddress: AztecAddress, scope: AztecAddress): Promise<Fr[][]> {
|
|
632
|
+
const handler = this.handlerAsTxe();
|
|
633
|
+
await handler.syncContractNonOracleMethod(contractAddress, scope, this.currentJobId);
|
|
634
|
+
// Cycle the job to commit the stores after the contract sync.
|
|
635
|
+
await this.cycleJob();
|
|
636
|
+
return handler.getPrivateEvents(selector, contractAddress, scope);
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
private handlerAsTxe(): ITxeExecutionOracle {
|
|
640
|
+
if (!('isTxe' in this.oracleHandler)) {
|
|
641
|
+
throw new UnavailableOracleError('Txe');
|
|
642
|
+
}
|
|
643
|
+
return this.oracleHandler;
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
setTxeOracleVersion(major: number, minor: number): void {
|
|
647
|
+
if (major !== TXE_ORACLE_VERSION_MAJOR) {
|
|
648
|
+
const hint =
|
|
649
|
+
major > TXE_ORACLE_VERSION_MAJOR
|
|
650
|
+
? 'The test was compiled with a newer version of Aztec.nr than your test environment supports. Upgrade your test environment to a compatible version.'
|
|
651
|
+
: 'The test was compiled with an older version of Aztec.nr than your test environment supports. Recompile the test with a compatible version of Aztec.nr.';
|
|
652
|
+
throw new Error(
|
|
653
|
+
`Incompatible test environment version: ${hint} See https://docs.aztec.network/errors/12 (expected test oracle major version ${TXE_ORACLE_VERSION_MAJOR}, got ${major})`,
|
|
654
|
+
);
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
this.txeOracleVersion = { major, minor };
|
|
658
|
+
this.logger.debug(`Test compiled with test oracle version ${major}.${minor}`);
|
|
659
|
+
}
|
|
660
|
+
|
|
278
661
|
async enterTopLevelState() {
|
|
279
662
|
switch (this.state.name) {
|
|
280
663
|
case 'PRIVATE': {
|
|
@@ -309,14 +692,19 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
309
692
|
this.accountStore,
|
|
310
693
|
this.senderTaggingStore,
|
|
311
694
|
this.recipientTaggingStore,
|
|
312
|
-
this.
|
|
695
|
+
this.taggingSecretSourcesStore,
|
|
313
696
|
this.capsuleStore,
|
|
697
|
+
this.factStore,
|
|
314
698
|
this.privateEventStore,
|
|
315
699
|
this.nextBlockTimestamp,
|
|
316
700
|
this.version,
|
|
317
701
|
this.chainId,
|
|
318
702
|
this.authwits,
|
|
319
|
-
this.
|
|
703
|
+
this.taggingSecretStrategies,
|
|
704
|
+
this.authorizeAllUtilityCallTargets,
|
|
705
|
+
this.artifactResolver,
|
|
706
|
+
this.rootPath,
|
|
707
|
+
this.packageName,
|
|
320
708
|
);
|
|
321
709
|
|
|
322
710
|
this.state = { name: 'TOP_LEVEL' };
|
|
@@ -324,21 +712,25 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
324
712
|
}
|
|
325
713
|
|
|
326
714
|
async enterPrivateState(
|
|
327
|
-
|
|
328
|
-
|
|
715
|
+
contractAddressOpt: Option<AztecAddress>,
|
|
716
|
+
anchorBlockNumberOpt: Option<BlockNumber>,
|
|
717
|
+
gasSettings: GasSettings,
|
|
329
718
|
): Promise<PrivateContextInputs> {
|
|
719
|
+
const contractAddress = contractAddressOpt?.value ?? DEFAULT_ADDRESS;
|
|
720
|
+
const anchorBlockNumber = anchorBlockNumberOpt?.value;
|
|
330
721
|
this.exitTopLevelState();
|
|
722
|
+
this.resetLastCall();
|
|
331
723
|
|
|
332
724
|
// Private execution has two associated block numbers: the anchor block (i.e. the historical block that is used to
|
|
333
725
|
// build the proof), and the *next* block, i.e. the one we'll create once the execution ends, and which will contain
|
|
334
726
|
// a single transaction with the effects of what was done in the test.
|
|
335
|
-
const anchorBlock = await this.stateMachine.node.
|
|
727
|
+
const anchorBlock = await this.stateMachine.node.getBlock(anchorBlockNumber ?? 'latest').then(b => b?.header);
|
|
336
728
|
|
|
337
729
|
await new NoteService(this.noteStore, this.stateMachine.node, anchorBlock!, this.currentJobId).syncNoteNullifiers(
|
|
338
730
|
contractAddress,
|
|
339
|
-
|
|
731
|
+
await this.keyStore.getAccounts(),
|
|
340
732
|
);
|
|
341
|
-
const latestBlock = await this.stateMachine.node.
|
|
733
|
+
const latestBlock = await this.stateMachine.node.getBlock('latest').then(b => b?.header);
|
|
342
734
|
|
|
343
735
|
const nextBlockGlobalVariables = makeGlobalVariables(undefined, {
|
|
344
736
|
blockNumber: BlockNumber(latestBlock!.globalVariables.blockNumber + 1),
|
|
@@ -353,9 +745,16 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
353
745
|
const taggingIndexCache = new ExecutionTaggingIndexCache();
|
|
354
746
|
|
|
355
747
|
const utilityExecutor = this.utilityExecutorForContractSync(anchorBlock);
|
|
356
|
-
|
|
748
|
+
const transientArrayService = new TransientArrayService();
|
|
749
|
+
const anchoredContractData = new AnchoredContractData(
|
|
750
|
+
this.contractStore,
|
|
751
|
+
this.stateMachine.contractClassService,
|
|
752
|
+
anchorBlock!,
|
|
753
|
+
);
|
|
754
|
+
this.oracleHandler = new TXEPrivateExecutionOracle({
|
|
357
755
|
argsHash: Fr.ZERO,
|
|
358
|
-
txContext: new TxContext(this.chainId, this.version,
|
|
756
|
+
txContext: new TxContext(this.chainId, this.version, gasSettings),
|
|
757
|
+
txRequestSalt: Fr.ZERO,
|
|
359
758
|
callContext: new CallContext(AztecAddress.ZERO, contractAddress, FunctionSelector.empty(), false),
|
|
360
759
|
anchorBlockHeader: anchorBlock!,
|
|
361
760
|
utilityExecutor,
|
|
@@ -364,20 +763,25 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
364
763
|
executionCache: new HashedValuesCache(),
|
|
365
764
|
noteCache,
|
|
366
765
|
taggingIndexCache,
|
|
367
|
-
|
|
766
|
+
anchoredContractData,
|
|
368
767
|
noteStore: this.noteStore,
|
|
369
768
|
keyStore: this.keyStore,
|
|
370
769
|
addressStore: this.addressStore,
|
|
371
770
|
aztecNode: this.stateMachine.node,
|
|
372
771
|
senderTaggingStore: this.senderTaggingStore,
|
|
373
772
|
recipientTaggingStore: this.recipientTaggingStore,
|
|
374
|
-
|
|
375
|
-
|
|
773
|
+
taggingSecretSourcesStore: this.taggingSecretSourcesStore,
|
|
774
|
+
capsuleService: new CapsuleService(this.capsuleStore, await this.keyStore.getAccounts()),
|
|
775
|
+
factService: new FactService(this.factStore, await this.keyStore.getAccounts()),
|
|
376
776
|
privateEventStore: this.privateEventStore,
|
|
377
777
|
contractSyncService: this.stateMachine.contractSyncService,
|
|
778
|
+
l2TipsStore: this.stateMachine.l2TipsProvider,
|
|
378
779
|
jobId: this.currentJobId,
|
|
379
|
-
scopes:
|
|
380
|
-
|
|
780
|
+
scopes: await this.keyStore.getAccounts(),
|
|
781
|
+
txResolver: this.stateMachine.txResolver,
|
|
782
|
+
simulator: new WASMSimulator(),
|
|
783
|
+
hooks: this.buildExecutionHooks(),
|
|
784
|
+
transientArrayService,
|
|
381
785
|
});
|
|
382
786
|
|
|
383
787
|
// We store the note and tagging index caches fed into the PrivateExecutionOracle (along with some other auxiliary
|
|
@@ -388,35 +792,47 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
388
792
|
this.state = { name: 'PRIVATE', nextBlockGlobalVariables, noteCache, taggingIndexCache };
|
|
389
793
|
this.logger.debug(`Entered state ${this.state.name}`);
|
|
390
794
|
|
|
391
|
-
|
|
795
|
+
// Record the *resolved* anchor's timestamp — if the caller pinned the anchor to a past block
|
|
796
|
+
// via `anchorBlockNumber`, "latest" would be the wrong anchor for offchain-message semantics.
|
|
797
|
+
this.setLastCallContext(Fr.ZERO, anchorBlock!.globalVariables.timestamp);
|
|
798
|
+
|
|
799
|
+
return (this.oracleHandler as TXEPrivateExecutionOracle).getPrivateContextInputs();
|
|
392
800
|
}
|
|
393
801
|
|
|
394
|
-
async enterPublicState(
|
|
802
|
+
async enterPublicState(contractAddressOpt: Option<AztecAddress>) {
|
|
803
|
+
const contractAddress = contractAddressOpt?.value ?? DEFAULT_ADDRESS;
|
|
395
804
|
this.exitTopLevelState();
|
|
805
|
+
this.resetLastCall();
|
|
396
806
|
|
|
397
807
|
// The PublicContext will create a block with a single transaction in it, containing the effects of what was done in
|
|
398
808
|
// the test. The block therefore gets the *next* block number and timestamp.
|
|
399
|
-
const
|
|
809
|
+
const latestHeader = (await this.stateMachine.node.getBlockData('latest'))!.header;
|
|
400
810
|
const globalVariables = makeGlobalVariables(undefined, {
|
|
401
|
-
blockNumber: BlockNumber(
|
|
811
|
+
blockNumber: BlockNumber(latestHeader.globalVariables.blockNumber + 1),
|
|
402
812
|
timestamp: this.nextBlockTimestamp,
|
|
403
813
|
version: this.version,
|
|
404
814
|
chainId: this.chainId,
|
|
405
815
|
});
|
|
406
816
|
|
|
407
817
|
this.oracleHandler = new TXEOraclePublicContext(
|
|
408
|
-
contractAddress
|
|
818
|
+
contractAddress,
|
|
409
819
|
await this.stateMachine.synchronizer.nativeWorldStateService.fork(),
|
|
410
820
|
getSingleTxBlockRequestHash(globalVariables.blockNumber),
|
|
411
821
|
globalVariables,
|
|
822
|
+
this.contractStore,
|
|
412
823
|
);
|
|
413
824
|
|
|
414
825
|
this.state = { name: 'PUBLIC' };
|
|
415
826
|
this.logger.debug(`Entered state ${this.state.name}`);
|
|
827
|
+
|
|
828
|
+
// Public state is anchored at the latest block.
|
|
829
|
+
this.setLastCallContext(Fr.ZERO, latestHeader.globalVariables.timestamp);
|
|
416
830
|
}
|
|
417
831
|
|
|
418
|
-
async enterUtilityState(
|
|
832
|
+
async enterUtilityState(contractAddressOpt: Option<AztecAddress>) {
|
|
833
|
+
const contractAddress = contractAddressOpt?.value ?? DEFAULT_ADDRESS;
|
|
419
834
|
this.exitTopLevelState();
|
|
835
|
+
this.resetLastCall();
|
|
420
836
|
|
|
421
837
|
const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
422
838
|
|
|
@@ -430,30 +846,50 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
430
846
|
this.stateMachine.node,
|
|
431
847
|
anchorBlockHeader,
|
|
432
848
|
this.currentJobId,
|
|
433
|
-
).syncNoteNullifiers(contractAddress,
|
|
849
|
+
).syncNoteNullifiers(contractAddress, await this.keyStore.getAccounts());
|
|
434
850
|
|
|
435
851
|
this.oracleHandler = new UtilityExecutionOracle({
|
|
436
|
-
|
|
852
|
+
callContext: CallContext.from({
|
|
853
|
+
msgSender: AztecAddress.NULL_MSG_SENDER,
|
|
854
|
+
contractAddress,
|
|
855
|
+
// No specific function is being executed in this inlined utility context, hence the empty selector.
|
|
856
|
+
functionSelector: FunctionSelector.empty(),
|
|
857
|
+
isStaticCall: true,
|
|
858
|
+
}),
|
|
437
859
|
authWitnesses: [],
|
|
438
860
|
capsules: [],
|
|
439
861
|
anchorBlockHeader,
|
|
440
|
-
|
|
862
|
+
anchoredContractData: new AnchoredContractData(
|
|
863
|
+
this.contractStore,
|
|
864
|
+
this.stateMachine.contractClassService,
|
|
865
|
+
anchorBlockHeader,
|
|
866
|
+
),
|
|
441
867
|
noteStore: this.noteStore,
|
|
442
868
|
keyStore: this.keyStore,
|
|
443
869
|
addressStore: this.addressStore,
|
|
444
870
|
aztecNode: this.stateMachine.node,
|
|
445
871
|
recipientTaggingStore: this.recipientTaggingStore,
|
|
446
|
-
|
|
447
|
-
|
|
872
|
+
taggingSecretSourcesStore: this.taggingSecretSourcesStore,
|
|
873
|
+
capsuleService: new CapsuleService(this.capsuleStore, await this.keyStore.getAccounts()),
|
|
874
|
+
factService: new FactService(this.factStore, await this.keyStore.getAccounts()),
|
|
448
875
|
privateEventStore: this.privateEventStore,
|
|
449
|
-
|
|
450
|
-
contractSyncService: this.contractSyncService,
|
|
876
|
+
txResolver: this.stateMachine.txResolver,
|
|
877
|
+
contractSyncService: this.stateMachine.contractSyncService,
|
|
878
|
+
l2TipsStore: this.stateMachine.l2TipsProvider,
|
|
451
879
|
jobId: this.currentJobId,
|
|
452
|
-
scopes:
|
|
880
|
+
scopes: await this.keyStore.getAccounts(),
|
|
881
|
+
simulator: new WASMSimulator(),
|
|
882
|
+
utilityExecutor: this.utilityExecutorForContractSync(anchorBlockHeader),
|
|
883
|
+
hooks: this.buildExecutionHooks(),
|
|
884
|
+
// Execution-tree root (top-level utility run): own store; nested frames inherit it.
|
|
885
|
+
transientArrayService: new TransientArrayService(),
|
|
453
886
|
});
|
|
454
887
|
|
|
455
888
|
this.state = { name: 'UTILITY' };
|
|
456
889
|
this.logger.debug(`Entered state ${this.state.name}`);
|
|
890
|
+
|
|
891
|
+
// Utility state anchors at whatever the anchor block store is pointing to (tracked as latest).
|
|
892
|
+
this.setLastCallContext(Fr.ZERO, anchorBlockHeader.globalVariables.timestamp);
|
|
457
893
|
}
|
|
458
894
|
|
|
459
895
|
private exitTopLevelState() {
|
|
@@ -462,15 +898,23 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
462
898
|
}
|
|
463
899
|
|
|
464
900
|
// Note that while all public and private contexts do is build a single block that we then process when exiting
|
|
465
|
-
//
|
|
466
|
-
//
|
|
467
|
-
//
|
|
468
|
-
//
|
|
469
|
-
//
|
|
470
|
-
//
|
|
471
|
-
// the
|
|
472
|
-
|
|
473
|
-
|
|
901
|
+
// them, the top level context does most of its work as it goes: it creates empty blocks (via `advanceBlocksBy`
|
|
902
|
+
// and `deploy`), creates blocks with transactions (via `privateCallNewFlow` and `publicCallNewFlow`), adds
|
|
903
|
+
// accounts to PXE (via `addAccount`), etc. This is a slight inconsistency in the working model of this class, but
|
|
904
|
+
// is not too bad. The `close` call below therefore only hands back the session-scoped values that a test
|
|
905
|
+
// sets directly at the top level, outside any contract execution (e.g. via `advanceTimestampBy`,
|
|
906
|
+
// `addAuthWitness`, `setTaggingSecretStrategies`). The oracle handler is discarded on every state transition,
|
|
907
|
+
// so the session must seed these values into the contexts it creates later.
|
|
908
|
+
|
|
909
|
+
// TODO: persisting authwits this way is quite unfortunate: they create a temporary utility context that would
|
|
910
|
+
// otherwise reset them, so we'd not be able to pass more than one per execution. Ideally authwits would be passed
|
|
911
|
+
// alongside a contract call instead of pre-seeded.
|
|
912
|
+
({
|
|
913
|
+
nextBlockTimestamp: this.nextBlockTimestamp,
|
|
914
|
+
authwits: this.authwits,
|
|
915
|
+
taggingSecretStrategies: this.taggingSecretStrategies,
|
|
916
|
+
authorizeAllUtilityCallTargets: this.authorizeAllUtilityCallTargets,
|
|
917
|
+
} = (this.oracleHandler as TXEOracleTopLevelContext).close());
|
|
474
918
|
}
|
|
475
919
|
|
|
476
920
|
private async exitPrivateState() {
|
|
@@ -518,34 +962,58 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
518
962
|
}
|
|
519
963
|
|
|
520
964
|
private utilityExecutorForContractSync(anchorBlock: any) {
|
|
521
|
-
return async (call: FunctionCall, scopes:
|
|
522
|
-
const
|
|
965
|
+
return async (call: FunctionCall, scopes: AztecAddress[]) => {
|
|
966
|
+
const anchoredContractData = new AnchoredContractData(
|
|
967
|
+
this.contractStore,
|
|
968
|
+
this.stateMachine.contractClassService,
|
|
969
|
+
anchorBlock!,
|
|
970
|
+
);
|
|
971
|
+
const entryPointArtifact = await anchoredContractData.getFunctionArtifactWithDebugMetadata(
|
|
972
|
+
call.to,
|
|
973
|
+
call.selector,
|
|
974
|
+
);
|
|
975
|
+
if (!entryPointArtifact) {
|
|
976
|
+
throw new Error(`Cannot run function ${call.selector} on ${call.to}: the contract is not registered.`);
|
|
977
|
+
}
|
|
523
978
|
if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
|
|
524
979
|
throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
|
|
525
980
|
}
|
|
526
981
|
|
|
527
982
|
try {
|
|
983
|
+
const simulator = new WASMSimulator();
|
|
528
984
|
const oracle = new UtilityExecutionOracle({
|
|
529
|
-
|
|
985
|
+
callContext: CallContext.from({
|
|
986
|
+
msgSender: AztecAddress.NULL_MSG_SENDER,
|
|
987
|
+
contractAddress: call.to,
|
|
988
|
+
functionSelector: call.selector,
|
|
989
|
+
isStaticCall: true,
|
|
990
|
+
}),
|
|
530
991
|
authWitnesses: [],
|
|
531
992
|
capsules: [],
|
|
532
993
|
anchorBlockHeader: anchorBlock!,
|
|
533
|
-
|
|
994
|
+
anchoredContractData,
|
|
534
995
|
noteStore: this.noteStore,
|
|
535
996
|
keyStore: this.keyStore,
|
|
536
997
|
addressStore: this.addressStore,
|
|
537
998
|
aztecNode: this.stateMachine.node,
|
|
538
999
|
recipientTaggingStore: this.recipientTaggingStore,
|
|
539
|
-
|
|
540
|
-
|
|
1000
|
+
taggingSecretSourcesStore: this.taggingSecretSourcesStore,
|
|
1001
|
+
capsuleService: new CapsuleService(this.capsuleStore, scopes),
|
|
1002
|
+
factService: new FactService(this.factStore, scopes),
|
|
541
1003
|
privateEventStore: this.privateEventStore,
|
|
542
|
-
|
|
543
|
-
contractSyncService: this.contractSyncService,
|
|
1004
|
+
txResolver: this.stateMachine.txResolver,
|
|
1005
|
+
contractSyncService: this.stateMachine.contractSyncService,
|
|
1006
|
+
l2TipsStore: this.stateMachine.l2TipsProvider,
|
|
544
1007
|
jobId: this.currentJobId,
|
|
545
1008
|
scopes,
|
|
1009
|
+
simulator,
|
|
1010
|
+
utilityExecutor: this.utilityExecutorForContractSync(anchorBlock),
|
|
1011
|
+
hooks: this.buildExecutionHooks(),
|
|
1012
|
+
// Top-level utility entrypoint: gets a fresh store. Nested frames inherit it via UtilityExecutionOracle.
|
|
1013
|
+
transientArrayService: new TransientArrayService(),
|
|
546
1014
|
});
|
|
547
|
-
await
|
|
548
|
-
.executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact,
|
|
1015
|
+
await simulator
|
|
1016
|
+
.executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, buildACIRCallback(oracle))
|
|
549
1017
|
.catch((err: Error) => {
|
|
550
1018
|
err.message = resolveAssertionMessageFromError(err, entryPointArtifact);
|
|
551
1019
|
throw new ExecutionError(
|
|
@@ -563,4 +1031,12 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
563
1031
|
}
|
|
564
1032
|
};
|
|
565
1033
|
}
|
|
1034
|
+
|
|
1035
|
+
/** Execution hooks for the oracles this session builds. Every oracle construction site must use this. */
|
|
1036
|
+
private buildExecutionHooks() {
|
|
1037
|
+
return composeHooks({
|
|
1038
|
+
resolveTaggingSecretStrategy: makeResolveTaggingSecretStrategyHook(this.taggingSecretStrategies),
|
|
1039
|
+
authorizeUtilityCall: this.authorizeAllUtilityCallTargets ? authorizeAllUtilityCallsHook : undefined,
|
|
1040
|
+
});
|
|
1041
|
+
}
|
|
566
1042
|
}
|