@aztec/txe 0.0.1-commit.3fd054f6 → 0.0.1-commit.431c48d
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-56AMRLSQ.js +3 -0
- package/dest/AuthRegistry-56AMRLSQ.js.map +7 -0
- package/dest/ContractClassRegistry-CRN27URB.js +3 -0
- package/dest/ContractClassRegistry-CRN27URB.js.map +7 -0
- package/dest/ContractInstanceRegistry-GRGL26IC.js +3 -0
- package/dest/ContractInstanceRegistry-GRGL26IC.js.map +7 -0
- package/dest/FeeJuice-J23RVHLW.js +3 -0
- package/dest/FeeJuice-J23RVHLW.js.map +7 -0
- package/dest/HandshakeRegistry-5.0.1-PEFCLEGP.js +3 -0
- package/dest/HandshakeRegistry-5.0.1-PEFCLEGP.js.map +7 -0
- package/dest/HandshakeRegistry-GNFACTEE.js +3 -0
- package/dest/HandshakeRegistry-GNFACTEE.js.map +7 -0
- package/dest/MultiCallEntrypoint-MIDICLQB.js +3 -0
- package/dest/MultiCallEntrypoint-MIDICLQB.js.map +7 -0
- package/dest/SchnorrAccount-ZRENHSMV.js +3 -0
- package/dest/SchnorrAccount-ZRENHSMV.js.map +7 -0
- package/dest/SchnorrInitializerlessAccount-L56LOFSV.js +3 -0
- package/dest/SchnorrInitializerlessAccount-L56LOFSV.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 +53 -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-BJVAAXNA.js +3 -0
- package/dest/chunk-BJVAAXNA.js.map +7 -0
- package/dest/chunk-LVLJKGGH.js +266 -0
- package/dest/chunk-LVLJKGGH.js.map +7 -0
- package/dest/chunk-OVMCQ5A6.js +304 -0
- package/dest/chunk-OVMCQ5A6.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 +40494 -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 +288 -98
- 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 +115 -233
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +791 -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 +18 -8
- package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
- package/dest/state_machine/dummy_p2p_client.js +31 -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 +52 -14
- package/dest/state_machine/mock_epoch_cache.d.ts +1 -2
- package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
- package/dest/state_machine/mock_epoch_cache.js +0 -3
- package/dest/state_machine/synchronizer.d.ts +5 -2
- package/dest/state_machine/synchronizer.d.ts.map +1 -1
- package/dest/state_machine/synchronizer.js +7 -3
- package/dest/txe_session.d.ts +90 -20
- package/dest/txe_session.d.ts.map +1 -1
- package/dest/txe_session.js +319 -73
- 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 +192 -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 +67 -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 -121
- 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 +880 -902
- package/src/state_machine/archiver.ts +37 -16
- package/src/state_machine/dummy_p2p_client.ts +49 -12
- package/src/state_machine/global_variable_builder.ts +12 -11
- package/src/state_machine/index.ts +63 -32
- package/src/state_machine/mock_epoch_cache.ts +0 -4
- package/src/state_machine/synchronizer.ts +9 -3
- package/src/txe_session.ts +554 -89
- 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,44 +264,79 @@ 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
|
+
* Closes the per-session `txe-session` LMDB and the `NativeWorldStateService` .
|
|
283
|
+
* 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
|
+
try {
|
|
291
|
+
await this.stateMachine.synchronizer.nativeWorldStateService.close();
|
|
292
|
+
} catch (err) {
|
|
293
|
+
this.logger.warn(`Error closing native world state during session dispose`, err);
|
|
294
|
+
}
|
|
295
|
+
try {
|
|
296
|
+
await this.sessionStore.close();
|
|
297
|
+
} catch (err) {
|
|
298
|
+
this.logger.warn(`Error closing session LMDB during dispose`, err);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
static async init(
|
|
303
|
+
contractStore: ContractStore,
|
|
304
|
+
artifactResolver: TXEArtifactResolver,
|
|
305
|
+
rootPath: string,
|
|
306
|
+
packageName: string,
|
|
307
|
+
) {
|
|
308
|
+
// Size LMDB's reader slots to the libuv pool (capped to 2 in bin/index.ts via
|
|
309
|
+
// HARDWARE_CONCURRENCY): each native LMDB read needs a libuv worker thread to run, so any
|
|
310
|
+
// slot beyond the pool size would sit idle while still consuming a semaphore + reader-table
|
|
311
|
+
// entry per session.
|
|
312
|
+
const store = await openEphemeralStore('txe-session', undefined, 2);
|
|
159
313
|
|
|
160
314
|
const addressStore = new AddressStore(store);
|
|
161
315
|
const privateEventStore = new PrivateEventStore(store);
|
|
162
316
|
const noteStore = new NoteStore(store);
|
|
163
317
|
const senderTaggingStore = new SenderTaggingStore(store);
|
|
164
318
|
const recipientTaggingStore = new RecipientTaggingStore(store);
|
|
165
|
-
const
|
|
319
|
+
const taggingSecretSourcesStore = new TaggingSecretSourcesStore(store);
|
|
166
320
|
const capsuleStore = new CapsuleStore(store);
|
|
321
|
+
const factStore = new FactStore(store);
|
|
167
322
|
const keyStore = new KeyStore(store);
|
|
168
323
|
const accountStore = new TXEAccountStore(store);
|
|
169
324
|
|
|
170
|
-
|
|
325
|
+
const archiver = new TXEArchiver(store);
|
|
326
|
+
const anchorBlockStore = new AnchorBlockStore(store);
|
|
327
|
+
const stateMachine = await TXEStateMachine.create(archiver, anchorBlockStore, contractStore, noteStore);
|
|
328
|
+
|
|
171
329
|
const jobCoordinator = new JobCoordinator(store);
|
|
172
330
|
jobCoordinator.registerStores([
|
|
173
331
|
capsuleStore,
|
|
332
|
+
factStore,
|
|
174
333
|
senderTaggingStore,
|
|
175
334
|
recipientTaggingStore,
|
|
176
335
|
privateEventStore,
|
|
177
336
|
noteStore,
|
|
337
|
+
stateMachine.contractSyncService,
|
|
178
338
|
]);
|
|
179
339
|
|
|
180
|
-
const archiver = new TXEArchiver(store);
|
|
181
|
-
const anchorBlockStore = new AnchorBlockStore(store);
|
|
182
|
-
const stateMachine = await TXEStateMachine.create(archiver, anchorBlockStore, contractStore, noteStore);
|
|
183
|
-
|
|
184
340
|
const nextBlockTimestamp = BigInt(Math.floor(new Date().getTime() / 1000));
|
|
185
341
|
const version = new Fr(await stateMachine.node.getVersion());
|
|
186
342
|
const chainId = new Fr(await stateMachine.node.getChainId());
|
|
@@ -188,7 +344,6 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
188
344
|
const initialJobId = jobCoordinator.beginJob();
|
|
189
345
|
|
|
190
346
|
const logger = createLogger('txe:session');
|
|
191
|
-
const contractSyncService = new ContractSyncService(stateMachine.node, contractStore, noteStore, logger);
|
|
192
347
|
|
|
193
348
|
const topLevelOracleHandler = new TXEOracleTopLevelContext(
|
|
194
349
|
stateMachine,
|
|
@@ -199,19 +354,26 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
199
354
|
accountStore,
|
|
200
355
|
senderTaggingStore,
|
|
201
356
|
recipientTaggingStore,
|
|
202
|
-
|
|
357
|
+
taggingSecretSourcesStore,
|
|
203
358
|
capsuleStore,
|
|
359
|
+
factStore,
|
|
204
360
|
privateEventStore,
|
|
205
361
|
nextBlockTimestamp,
|
|
206
362
|
version,
|
|
207
363
|
chainId,
|
|
208
364
|
new Map(),
|
|
209
|
-
|
|
365
|
+
new Map(),
|
|
366
|
+
false, // authorizeAllUtilityCallTargets
|
|
367
|
+
artifactResolver,
|
|
368
|
+
rootPath,
|
|
369
|
+
packageName,
|
|
210
370
|
);
|
|
211
|
-
|
|
371
|
+
|
|
372
|
+
await topLevelOracleHandler.mineDeploymentNullifiers([STANDARD_AUTH_REGISTRY_ADDRESS]);
|
|
212
373
|
|
|
213
374
|
return new TXESession(
|
|
214
375
|
logger,
|
|
376
|
+
store,
|
|
215
377
|
stateMachine,
|
|
216
378
|
topLevelOracleHandler,
|
|
217
379
|
contractStore,
|
|
@@ -221,15 +383,18 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
221
383
|
accountStore,
|
|
222
384
|
senderTaggingStore,
|
|
223
385
|
recipientTaggingStore,
|
|
224
|
-
|
|
386
|
+
taggingSecretSourcesStore,
|
|
225
387
|
capsuleStore,
|
|
388
|
+
factStore,
|
|
226
389
|
privateEventStore,
|
|
227
390
|
jobCoordinator,
|
|
228
391
|
initialJobId,
|
|
229
392
|
version,
|
|
230
393
|
chainId,
|
|
231
394
|
nextBlockTimestamp,
|
|
232
|
-
|
|
395
|
+
artifactResolver,
|
|
396
|
+
rootPath,
|
|
397
|
+
packageName,
|
|
233
398
|
);
|
|
234
399
|
}
|
|
235
400
|
|
|
@@ -241,6 +406,18 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
241
406
|
*/
|
|
242
407
|
processFunction(functionName: TXEOracleFunctionName, inputs: ForeignCallArgs): Promise<ForeignCallResult> {
|
|
243
408
|
try {
|
|
409
|
+
// Oracles retired into the PXE legacy registry have no translator method; dispatch them through the same
|
|
410
|
+
// buildACIRCallback legacy path that contract execution uses, keeping TXE's two oracle paths in sync.
|
|
411
|
+
// Use an own-property check: `in` would match inherited `Object.prototype` keys (e.g. `constructor`), routing
|
|
412
|
+
// them into the legacy path instead of letting them fall through to the unknown-oracle error.
|
|
413
|
+
if (Object.hasOwn(LEGACY_ORACLE_REGISTRY, functionName)) {
|
|
414
|
+
return callTxeLegacyHandler(
|
|
415
|
+
functionName,
|
|
416
|
+
inputs,
|
|
417
|
+
this.oracleHandler as Parameters<typeof buildACIRCallback>[0],
|
|
418
|
+
);
|
|
419
|
+
}
|
|
420
|
+
|
|
244
421
|
const translator = new RPCTranslator(this, this.oracleHandler) as any;
|
|
245
422
|
// We perform a runtime validation to check that the function name corresponds to a real oracle handler.
|
|
246
423
|
const validatedFunctionName = z
|
|
@@ -251,7 +428,28 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
251
428
|
return translator[validatedFunctionName](...inputs);
|
|
252
429
|
} catch (error) {
|
|
253
430
|
if (error instanceof z.ZodError) {
|
|
254
|
-
|
|
431
|
+
let versionHint: string;
|
|
432
|
+
if (!this.txeOracleVersion) {
|
|
433
|
+
versionHint =
|
|
434
|
+
' The test appears to use an older version of Aztec.nr that does not' +
|
|
435
|
+
' support test environment oracle versioning. Update Aztec.nr to a compatible version.' +
|
|
436
|
+
' See https://docs.aztec.network/errors/12';
|
|
437
|
+
} else if (this.txeOracleVersion.minor > TXE_ORACLE_VERSION_MINOR) {
|
|
438
|
+
versionHint =
|
|
439
|
+
` The test uses Aztec.nr test oracle version` +
|
|
440
|
+
` ${this.txeOracleVersion.major}.${this.txeOracleVersion.minor}, but this test environment` +
|
|
441
|
+
` only supports up to ${TXE_ORACLE_VERSION_MAJOR}.${TXE_ORACLE_VERSION_MINOR}.` +
|
|
442
|
+
` Upgrade the Aztec CLI to a compatible version.` +
|
|
443
|
+
` See https://docs.aztec.network/errors/12`;
|
|
444
|
+
} else {
|
|
445
|
+
versionHint =
|
|
446
|
+
` The test's oracle version (${this.txeOracleVersion.major}.${this.txeOracleVersion.minor})` +
|
|
447
|
+
` is compatible with this test environment` +
|
|
448
|
+
` (${TXE_ORACLE_VERSION_MAJOR}.${TXE_ORACLE_VERSION_MINOR}), so this oracle should be` +
|
|
449
|
+
` available. This is an unexpected error, please report it.` +
|
|
450
|
+
` See https://docs.aztec.network/errors/13`;
|
|
451
|
+
}
|
|
452
|
+
throw new Error(`Unknown oracle '${functionName}'.${versionHint}`);
|
|
255
453
|
} else if (error instanceof Error) {
|
|
256
454
|
throw new Error(
|
|
257
455
|
`Execution error while processing function ${functionName} in state ${this.state.name}: ${error.message}`,
|
|
@@ -264,17 +462,195 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
264
462
|
}
|
|
265
463
|
}
|
|
266
464
|
|
|
267
|
-
getCurrentJob(): string {
|
|
268
|
-
return this.currentJobId;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
465
|
/** Commits the current job and begins a new one. Returns the new job ID. */
|
|
272
|
-
async cycleJob(): Promise<string> {
|
|
466
|
+
private async cycleJob(): Promise<string> {
|
|
273
467
|
await this.jobCoordinator.commitJob(this.currentJobId);
|
|
274
468
|
this.currentJobId = this.jobCoordinator.beginJob();
|
|
275
469
|
return this.currentJobId;
|
|
276
470
|
}
|
|
277
471
|
|
|
472
|
+
private resetLastCall(): void {
|
|
473
|
+
const notQueriedMessageCount = this.lastCallInfo.queried
|
|
474
|
+
? 0
|
|
475
|
+
: this.lastCallInfo.offchainEffects.filter(payload => payload[0]?.equals(OFFCHAIN_MESSAGE_IDENTIFIER)).length;
|
|
476
|
+
if (notQueriedMessageCount > 0) {
|
|
477
|
+
this.logger.warn(
|
|
478
|
+
`Dropping ${notQueriedMessageCount} unqueried offchain message(s) from the previous top-level call. ` +
|
|
479
|
+
`To deliver them, call \`env.offchain_messages()\` and forward the result to the recipient contract's ` +
|
|
480
|
+
`\`offchain_receive\` utility before issuing another top-level call. To intentionally discard, assign ` +
|
|
481
|
+
`to \`let _ = env.offchain_messages()\` to silence this warning.`,
|
|
482
|
+
);
|
|
483
|
+
}
|
|
484
|
+
this.lastCallInfo = emptyLastCallState();
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
recordOffchainEffect(data: Fr[]): void {
|
|
488
|
+
this.lastCallInfo.offchainEffects.push(data);
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
private setLastCallContext(txHash: Fr, anchorBlockTimestamp: bigint): void {
|
|
492
|
+
this.lastCallInfo.txHash = txHash;
|
|
493
|
+
this.lastCallInfo.anchorBlockTimestamp = anchorBlockTimestamp;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
private async withTopLevelCallTracking<T>(work: () => Promise<{ result: T; txHash?: Fr }>): Promise<T> {
|
|
497
|
+
this.resetLastCall();
|
|
498
|
+
// Capture the anchor *before* `work` runs: private/public executor calls mine a new block as a
|
|
499
|
+
// side effect, and that block's timestamp should not be attributed to this call's anchor.
|
|
500
|
+
const anchorBlockTimestamp = (await this.stateMachine.node.getBlockData('latest'))!.header.globalVariables
|
|
501
|
+
.timestamp;
|
|
502
|
+
const { result, txHash } = await work();
|
|
503
|
+
this.setLastCallContext(txHash ?? Fr.ZERO, anchorBlockTimestamp);
|
|
504
|
+
return result;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
getLastCallOffchainEffects(): { effects: Fr[][] } {
|
|
508
|
+
this.lastCallInfo.queried = true;
|
|
509
|
+
const effects = this.lastCallInfo.offchainEffects;
|
|
510
|
+
|
|
511
|
+
if (effects.length > MAX_OFFCHAIN_EFFECTS_PER_TXE_QUERY) {
|
|
512
|
+
throw new Error(`${effects.length} offchain effects exceed max ${MAX_OFFCHAIN_EFFECTS_PER_TXE_QUERY}`);
|
|
513
|
+
}
|
|
514
|
+
if (effects.some(e => e.length > MAX_OFFCHAIN_EFFECT_LEN)) {
|
|
515
|
+
throw new Error(`Some offchain effect has length larger than max ${MAX_OFFCHAIN_EFFECT_LEN}`);
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
return { effects };
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
getLastCallContext(): { txHash: Fr; anchorBlockTimestamp: bigint } {
|
|
522
|
+
const { txHash, anchorBlockTimestamp } = this.lastCallInfo;
|
|
523
|
+
return { txHash, anchorBlockTimestamp };
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
async executePrivateCall(
|
|
527
|
+
from: Option<AztecAddress>,
|
|
528
|
+
targetContractAddress: AztecAddress,
|
|
529
|
+
functionSelector: FunctionSelector,
|
|
530
|
+
args: Fr[],
|
|
531
|
+
argsHash: Fr,
|
|
532
|
+
isStaticCall: boolean,
|
|
533
|
+
additionalScopes: AztecAddress[],
|
|
534
|
+
authorizedUtilityCallTargets: AztecAddress[],
|
|
535
|
+
gasSettings: GasSettings,
|
|
536
|
+
): Promise<Fr[]> {
|
|
537
|
+
const handler = this.handlerAsTxe();
|
|
538
|
+
return await this.withTopLevelCallTracking(async () => {
|
|
539
|
+
const { returnValues, offchainEffects } = await handler.privateCallNewFlow(
|
|
540
|
+
from?.value,
|
|
541
|
+
targetContractAddress,
|
|
542
|
+
functionSelector,
|
|
543
|
+
args,
|
|
544
|
+
argsHash,
|
|
545
|
+
isStaticCall,
|
|
546
|
+
additionalScopes,
|
|
547
|
+
this.currentJobId,
|
|
548
|
+
authorizedUtilityCallTargets,
|
|
549
|
+
gasSettings,
|
|
550
|
+
);
|
|
551
|
+
|
|
552
|
+
// Private execution collects offchain effects inside PXE's PrivateExecutionOracle rather than round-tripping
|
|
553
|
+
// them through `aztec_utl_emitOffchainEffect`, so the session buffer is empty at this point. Drain the effects
|
|
554
|
+
// from the execution tree into the session buffer so the next `env.offchain_messages()` call in the test sees
|
|
555
|
+
// them.
|
|
556
|
+
for (const data of offchainEffects) {
|
|
557
|
+
this.recordOffchainEffect(data);
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
await this.cycleJob();
|
|
561
|
+
|
|
562
|
+
if (isStaticCall) {
|
|
563
|
+
// Static calls revert their checkpoint and mine no block, so there is no tx hash to tag offchain effects
|
|
564
|
+
// with. Querying `getLastTxEffects()` here would return an unrelated predecessor tx.
|
|
565
|
+
return { result: returnValues };
|
|
566
|
+
}
|
|
567
|
+
const { txHash } = await handler.getLastTxEffects();
|
|
568
|
+
return { result: returnValues, txHash: txHash.hash };
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
async executeUtilityFunction(
|
|
573
|
+
from: Option<AztecAddress>,
|
|
574
|
+
targetContractAddress: AztecAddress,
|
|
575
|
+
functionSelector: FunctionSelector,
|
|
576
|
+
args: Fr[],
|
|
577
|
+
authorizedUtilityCallTargets: AztecAddress[],
|
|
578
|
+
): Promise<Fr[]> {
|
|
579
|
+
const handler = this.handlerAsTxe();
|
|
580
|
+
return await this.withTopLevelCallTracking(async () => {
|
|
581
|
+
const returnValues = await handler.executeUtilityFunction(
|
|
582
|
+
from?.value,
|
|
583
|
+
targetContractAddress,
|
|
584
|
+
functionSelector,
|
|
585
|
+
args,
|
|
586
|
+
this.currentJobId,
|
|
587
|
+
authorizedUtilityCallTargets,
|
|
588
|
+
);
|
|
589
|
+
|
|
590
|
+
await this.cycleJob();
|
|
591
|
+
|
|
592
|
+
return { result: returnValues };
|
|
593
|
+
});
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
async executePublicCall(
|
|
597
|
+
from: Option<AztecAddress>,
|
|
598
|
+
targetContractAddress: AztecAddress,
|
|
599
|
+
calldata: Fr[],
|
|
600
|
+
isStaticCall: boolean,
|
|
601
|
+
gasSettings: GasSettings,
|
|
602
|
+
): Promise<Fr[]> {
|
|
603
|
+
const handler = this.handlerAsTxe();
|
|
604
|
+
return await this.withTopLevelCallTracking(async () => {
|
|
605
|
+
const returnValues = await handler.publicCallNewFlow(
|
|
606
|
+
from?.value,
|
|
607
|
+
targetContractAddress,
|
|
608
|
+
calldata,
|
|
609
|
+
isStaticCall,
|
|
610
|
+
gasSettings,
|
|
611
|
+
);
|
|
612
|
+
|
|
613
|
+
await this.cycleJob();
|
|
614
|
+
|
|
615
|
+
if (isStaticCall) {
|
|
616
|
+
// See the equivalent branch in `executePrivateCall`.
|
|
617
|
+
return { result: returnValues };
|
|
618
|
+
}
|
|
619
|
+
const { txHash } = await handler.getLastTxEffects();
|
|
620
|
+
return { result: returnValues, txHash: txHash.hash };
|
|
621
|
+
});
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
async getPrivateEvents(selector: EventSelector, contractAddress: AztecAddress, scope: AztecAddress): Promise<Fr[][]> {
|
|
625
|
+
const handler = this.handlerAsTxe();
|
|
626
|
+
await handler.syncContractNonOracleMethod(contractAddress, scope, this.currentJobId);
|
|
627
|
+
// Cycle the job to commit the stores after the contract sync.
|
|
628
|
+
await this.cycleJob();
|
|
629
|
+
return handler.getPrivateEvents(selector, contractAddress, scope);
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
private handlerAsTxe(): ITxeExecutionOracle {
|
|
633
|
+
if (!('isTxe' in this.oracleHandler)) {
|
|
634
|
+
throw new UnavailableOracleError('Txe');
|
|
635
|
+
}
|
|
636
|
+
return this.oracleHandler;
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
setTxeOracleVersion(major: number, minor: number): void {
|
|
640
|
+
if (major !== TXE_ORACLE_VERSION_MAJOR) {
|
|
641
|
+
const hint =
|
|
642
|
+
major > TXE_ORACLE_VERSION_MAJOR
|
|
643
|
+
? 'The test was compiled with a newer version of Aztec.nr than your test environment supports. Upgrade your test environment to a compatible version.'
|
|
644
|
+
: '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.';
|
|
645
|
+
throw new Error(
|
|
646
|
+
`Incompatible test environment version: ${hint} See https://docs.aztec.network/errors/12 (expected test oracle major version ${TXE_ORACLE_VERSION_MAJOR}, got ${major})`,
|
|
647
|
+
);
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
this.txeOracleVersion = { major, minor };
|
|
651
|
+
this.logger.debug(`Test compiled with test oracle version ${major}.${minor}`);
|
|
652
|
+
}
|
|
653
|
+
|
|
278
654
|
async enterTopLevelState() {
|
|
279
655
|
switch (this.state.name) {
|
|
280
656
|
case 'PRIVATE': {
|
|
@@ -309,14 +685,19 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
309
685
|
this.accountStore,
|
|
310
686
|
this.senderTaggingStore,
|
|
311
687
|
this.recipientTaggingStore,
|
|
312
|
-
this.
|
|
688
|
+
this.taggingSecretSourcesStore,
|
|
313
689
|
this.capsuleStore,
|
|
690
|
+
this.factStore,
|
|
314
691
|
this.privateEventStore,
|
|
315
692
|
this.nextBlockTimestamp,
|
|
316
693
|
this.version,
|
|
317
694
|
this.chainId,
|
|
318
695
|
this.authwits,
|
|
319
|
-
this.
|
|
696
|
+
this.taggingSecretStrategies,
|
|
697
|
+
this.authorizeAllUtilityCallTargets,
|
|
698
|
+
this.artifactResolver,
|
|
699
|
+
this.rootPath,
|
|
700
|
+
this.packageName,
|
|
320
701
|
);
|
|
321
702
|
|
|
322
703
|
this.state = { name: 'TOP_LEVEL' };
|
|
@@ -324,21 +705,25 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
324
705
|
}
|
|
325
706
|
|
|
326
707
|
async enterPrivateState(
|
|
327
|
-
|
|
328
|
-
|
|
708
|
+
contractAddressOpt: Option<AztecAddress>,
|
|
709
|
+
anchorBlockNumberOpt: Option<BlockNumber>,
|
|
710
|
+
gasSettings: GasSettings,
|
|
329
711
|
): Promise<PrivateContextInputs> {
|
|
712
|
+
const contractAddress = contractAddressOpt?.value ?? DEFAULT_ADDRESS;
|
|
713
|
+
const anchorBlockNumber = anchorBlockNumberOpt?.value;
|
|
330
714
|
this.exitTopLevelState();
|
|
715
|
+
this.resetLastCall();
|
|
331
716
|
|
|
332
717
|
// Private execution has two associated block numbers: the anchor block (i.e. the historical block that is used to
|
|
333
718
|
// build the proof), and the *next* block, i.e. the one we'll create once the execution ends, and which will contain
|
|
334
719
|
// a single transaction with the effects of what was done in the test.
|
|
335
|
-
const anchorBlock = await this.stateMachine.node.
|
|
720
|
+
const anchorBlock = await this.stateMachine.node.getBlock(anchorBlockNumber ?? 'latest').then(b => b?.header);
|
|
336
721
|
|
|
337
722
|
await new NoteService(this.noteStore, this.stateMachine.node, anchorBlock!, this.currentJobId).syncNoteNullifiers(
|
|
338
723
|
contractAddress,
|
|
339
|
-
|
|
724
|
+
await this.keyStore.getAccounts(),
|
|
340
725
|
);
|
|
341
|
-
const latestBlock = await this.stateMachine.node.
|
|
726
|
+
const latestBlock = await this.stateMachine.node.getBlock('latest').then(b => b?.header);
|
|
342
727
|
|
|
343
728
|
const nextBlockGlobalVariables = makeGlobalVariables(undefined, {
|
|
344
729
|
blockNumber: BlockNumber(latestBlock!.globalVariables.blockNumber + 1),
|
|
@@ -353,9 +738,16 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
353
738
|
const taggingIndexCache = new ExecutionTaggingIndexCache();
|
|
354
739
|
|
|
355
740
|
const utilityExecutor = this.utilityExecutorForContractSync(anchorBlock);
|
|
356
|
-
|
|
741
|
+
const transientArrayService = new TransientArrayService();
|
|
742
|
+
const anchoredContractData = new AnchoredContractData(
|
|
743
|
+
this.contractStore,
|
|
744
|
+
this.stateMachine.contractClassService,
|
|
745
|
+
anchorBlock!,
|
|
746
|
+
);
|
|
747
|
+
this.oracleHandler = new TXEPrivateExecutionOracle({
|
|
357
748
|
argsHash: Fr.ZERO,
|
|
358
|
-
txContext: new TxContext(this.chainId, this.version,
|
|
749
|
+
txContext: new TxContext(this.chainId, this.version, gasSettings),
|
|
750
|
+
txRequestSalt: Fr.ZERO,
|
|
359
751
|
callContext: new CallContext(AztecAddress.ZERO, contractAddress, FunctionSelector.empty(), false),
|
|
360
752
|
anchorBlockHeader: anchorBlock!,
|
|
361
753
|
utilityExecutor,
|
|
@@ -364,20 +756,28 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
364
756
|
executionCache: new HashedValuesCache(),
|
|
365
757
|
noteCache,
|
|
366
758
|
taggingIndexCache,
|
|
367
|
-
|
|
759
|
+
anchoredContractData,
|
|
368
760
|
noteStore: this.noteStore,
|
|
369
761
|
keyStore: this.keyStore,
|
|
370
762
|
addressStore: this.addressStore,
|
|
371
763
|
aztecNode: this.stateMachine.node,
|
|
372
764
|
senderTaggingStore: this.senderTaggingStore,
|
|
373
765
|
recipientTaggingStore: this.recipientTaggingStore,
|
|
374
|
-
|
|
375
|
-
|
|
766
|
+
taggingSecretSourcesStore: this.taggingSecretSourcesStore,
|
|
767
|
+
capsuleService: new CapsuleService(this.capsuleStore, await this.keyStore.getAccounts()),
|
|
768
|
+
factService: new FactService(this.factStore, await this.keyStore.getAccounts()),
|
|
376
769
|
privateEventStore: this.privateEventStore,
|
|
377
770
|
contractSyncService: this.stateMachine.contractSyncService,
|
|
771
|
+
l2TipsStore: this.stateMachine.l2TipsProvider,
|
|
378
772
|
jobId: this.currentJobId,
|
|
379
|
-
scopes:
|
|
380
|
-
|
|
773
|
+
scopes: await this.keyStore.getAccounts(),
|
|
774
|
+
txResolver: this.stateMachine.txResolver,
|
|
775
|
+
simulator: new WASMSimulator(),
|
|
776
|
+
hooks: composeHooks({
|
|
777
|
+
resolveTaggingSecretStrategy: makeResolveTaggingSecretStrategyHook(this.taggingSecretStrategies),
|
|
778
|
+
authorizeUtilityCall: this.authorizeAllUtilityCallTargets ? authorizeAllUtilityCallsHook : undefined,
|
|
779
|
+
}),
|
|
780
|
+
transientArrayService,
|
|
381
781
|
});
|
|
382
782
|
|
|
383
783
|
// We store the note and tagging index caches fed into the PrivateExecutionOracle (along with some other auxiliary
|
|
@@ -388,35 +788,47 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
388
788
|
this.state = { name: 'PRIVATE', nextBlockGlobalVariables, noteCache, taggingIndexCache };
|
|
389
789
|
this.logger.debug(`Entered state ${this.state.name}`);
|
|
390
790
|
|
|
391
|
-
|
|
791
|
+
// Record the *resolved* anchor's timestamp — if the caller pinned the anchor to a past block
|
|
792
|
+
// via `anchorBlockNumber`, "latest" would be the wrong anchor for offchain-message semantics.
|
|
793
|
+
this.setLastCallContext(Fr.ZERO, anchorBlock!.globalVariables.timestamp);
|
|
794
|
+
|
|
795
|
+
return (this.oracleHandler as TXEPrivateExecutionOracle).getPrivateContextInputs();
|
|
392
796
|
}
|
|
393
797
|
|
|
394
|
-
async enterPublicState(
|
|
798
|
+
async enterPublicState(contractAddressOpt: Option<AztecAddress>) {
|
|
799
|
+
const contractAddress = contractAddressOpt?.value ?? DEFAULT_ADDRESS;
|
|
395
800
|
this.exitTopLevelState();
|
|
801
|
+
this.resetLastCall();
|
|
396
802
|
|
|
397
803
|
// The PublicContext will create a block with a single transaction in it, containing the effects of what was done in
|
|
398
804
|
// the test. The block therefore gets the *next* block number and timestamp.
|
|
399
|
-
const
|
|
805
|
+
const latestHeader = (await this.stateMachine.node.getBlockData('latest'))!.header;
|
|
400
806
|
const globalVariables = makeGlobalVariables(undefined, {
|
|
401
|
-
blockNumber: BlockNumber(
|
|
807
|
+
blockNumber: BlockNumber(latestHeader.globalVariables.blockNumber + 1),
|
|
402
808
|
timestamp: this.nextBlockTimestamp,
|
|
403
809
|
version: this.version,
|
|
404
810
|
chainId: this.chainId,
|
|
405
811
|
});
|
|
406
812
|
|
|
407
813
|
this.oracleHandler = new TXEOraclePublicContext(
|
|
408
|
-
contractAddress
|
|
814
|
+
contractAddress,
|
|
409
815
|
await this.stateMachine.synchronizer.nativeWorldStateService.fork(),
|
|
410
816
|
getSingleTxBlockRequestHash(globalVariables.blockNumber),
|
|
411
817
|
globalVariables,
|
|
818
|
+
this.contractStore,
|
|
412
819
|
);
|
|
413
820
|
|
|
414
821
|
this.state = { name: 'PUBLIC' };
|
|
415
822
|
this.logger.debug(`Entered state ${this.state.name}`);
|
|
823
|
+
|
|
824
|
+
// Public state is anchored at the latest block.
|
|
825
|
+
this.setLastCallContext(Fr.ZERO, latestHeader.globalVariables.timestamp);
|
|
416
826
|
}
|
|
417
827
|
|
|
418
|
-
async enterUtilityState(
|
|
828
|
+
async enterUtilityState(contractAddressOpt: Option<AztecAddress>) {
|
|
829
|
+
const contractAddress = contractAddressOpt?.value ?? DEFAULT_ADDRESS;
|
|
419
830
|
this.exitTopLevelState();
|
|
831
|
+
this.resetLastCall();
|
|
420
832
|
|
|
421
833
|
const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
422
834
|
|
|
@@ -430,30 +842,52 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
430
842
|
this.stateMachine.node,
|
|
431
843
|
anchorBlockHeader,
|
|
432
844
|
this.currentJobId,
|
|
433
|
-
).syncNoteNullifiers(contractAddress,
|
|
845
|
+
).syncNoteNullifiers(contractAddress, await this.keyStore.getAccounts());
|
|
434
846
|
|
|
435
847
|
this.oracleHandler = new UtilityExecutionOracle({
|
|
436
|
-
|
|
848
|
+
callContext: CallContext.from({
|
|
849
|
+
msgSender: AztecAddress.NULL_MSG_SENDER,
|
|
850
|
+
contractAddress,
|
|
851
|
+
// No specific function is being executed in this inlined utility context, hence the empty selector.
|
|
852
|
+
functionSelector: FunctionSelector.empty(),
|
|
853
|
+
isStaticCall: true,
|
|
854
|
+
}),
|
|
437
855
|
authWitnesses: [],
|
|
438
856
|
capsules: [],
|
|
439
857
|
anchorBlockHeader,
|
|
440
|
-
|
|
858
|
+
anchoredContractData: new AnchoredContractData(
|
|
859
|
+
this.contractStore,
|
|
860
|
+
this.stateMachine.contractClassService,
|
|
861
|
+
anchorBlockHeader,
|
|
862
|
+
),
|
|
441
863
|
noteStore: this.noteStore,
|
|
442
864
|
keyStore: this.keyStore,
|
|
443
865
|
addressStore: this.addressStore,
|
|
444
866
|
aztecNode: this.stateMachine.node,
|
|
445
867
|
recipientTaggingStore: this.recipientTaggingStore,
|
|
446
|
-
|
|
447
|
-
|
|
868
|
+
taggingSecretSourcesStore: this.taggingSecretSourcesStore,
|
|
869
|
+
capsuleService: new CapsuleService(this.capsuleStore, await this.keyStore.getAccounts()),
|
|
870
|
+
factService: new FactService(this.factStore, await this.keyStore.getAccounts()),
|
|
448
871
|
privateEventStore: this.privateEventStore,
|
|
449
|
-
|
|
450
|
-
contractSyncService: this.contractSyncService,
|
|
872
|
+
txResolver: this.stateMachine.txResolver,
|
|
873
|
+
contractSyncService: this.stateMachine.contractSyncService,
|
|
874
|
+
l2TipsStore: this.stateMachine.l2TipsProvider,
|
|
451
875
|
jobId: this.currentJobId,
|
|
452
|
-
scopes:
|
|
876
|
+
scopes: await this.keyStore.getAccounts(),
|
|
877
|
+
simulator: new WASMSimulator(),
|
|
878
|
+
utilityExecutor: this.utilityExecutorForContractSync(anchorBlockHeader),
|
|
879
|
+
hooks: composeHooks({
|
|
880
|
+
authorizeUtilityCall: this.authorizeAllUtilityCallTargets ? authorizeAllUtilityCallsHook : undefined,
|
|
881
|
+
}),
|
|
882
|
+
// Execution-tree root (top-level utility run): own store; nested frames inherit it.
|
|
883
|
+
transientArrayService: new TransientArrayService(),
|
|
453
884
|
});
|
|
454
885
|
|
|
455
886
|
this.state = { name: 'UTILITY' };
|
|
456
887
|
this.logger.debug(`Entered state ${this.state.name}`);
|
|
888
|
+
|
|
889
|
+
// Utility state anchors at whatever the anchor block store is pointing to (tracked as latest).
|
|
890
|
+
this.setLastCallContext(Fr.ZERO, anchorBlockHeader.globalVariables.timestamp);
|
|
457
891
|
}
|
|
458
892
|
|
|
459
893
|
private exitTopLevelState() {
|
|
@@ -462,15 +896,23 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
462
896
|
}
|
|
463
897
|
|
|
464
898
|
// 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
|
-
|
|
899
|
+
// them, the top level context does most of its work as it goes: it creates empty blocks (via `advanceBlocksBy`
|
|
900
|
+
// and `deploy`), creates blocks with transactions (via `privateCallNewFlow` and `publicCallNewFlow`), adds
|
|
901
|
+
// accounts to PXE (via `addAccount`), etc. This is a slight inconsistency in the working model of this class, but
|
|
902
|
+
// is not too bad. The `close` call below therefore only hands back the session-scoped values that a test
|
|
903
|
+
// sets directly at the top level, outside any contract execution (e.g. via `advanceTimestampBy`,
|
|
904
|
+
// `addAuthWitness`, `setTaggingSecretStrategies`). The oracle handler is discarded on every state transition,
|
|
905
|
+
// so the session must seed these values into the contexts it creates later.
|
|
906
|
+
|
|
907
|
+
// TODO: persisting authwits this way is quite unfortunate: they create a temporary utility context that would
|
|
908
|
+
// otherwise reset them, so we'd not be able to pass more than one per execution. Ideally authwits would be passed
|
|
909
|
+
// alongside a contract call instead of pre-seeded.
|
|
910
|
+
({
|
|
911
|
+
nextBlockTimestamp: this.nextBlockTimestamp,
|
|
912
|
+
authwits: this.authwits,
|
|
913
|
+
taggingSecretStrategies: this.taggingSecretStrategies,
|
|
914
|
+
authorizeAllUtilityCallTargets: this.authorizeAllUtilityCallTargets,
|
|
915
|
+
} = (this.oracleHandler as TXEOracleTopLevelContext).close());
|
|
474
916
|
}
|
|
475
917
|
|
|
476
918
|
private async exitPrivateState() {
|
|
@@ -518,34 +960,57 @@ export class TXESession implements TXESessionStateHandler {
|
|
|
518
960
|
}
|
|
519
961
|
|
|
520
962
|
private utilityExecutorForContractSync(anchorBlock: any) {
|
|
521
|
-
return async (call: FunctionCall, scopes:
|
|
522
|
-
const
|
|
963
|
+
return async (call: FunctionCall, scopes: AztecAddress[]) => {
|
|
964
|
+
const anchoredContractData = new AnchoredContractData(
|
|
965
|
+
this.contractStore,
|
|
966
|
+
this.stateMachine.contractClassService,
|
|
967
|
+
anchorBlock!,
|
|
968
|
+
);
|
|
969
|
+
const entryPointArtifact = await anchoredContractData.getFunctionArtifactWithDebugMetadata(
|
|
970
|
+
call.to,
|
|
971
|
+
call.selector,
|
|
972
|
+
);
|
|
973
|
+
if (!entryPointArtifact) {
|
|
974
|
+
throw new Error(`Cannot run function ${call.selector} on ${call.to}: the contract is not registered.`);
|
|
975
|
+
}
|
|
523
976
|
if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
|
|
524
977
|
throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
|
|
525
978
|
}
|
|
526
979
|
|
|
527
980
|
try {
|
|
981
|
+
const simulator = new WASMSimulator();
|
|
528
982
|
const oracle = new UtilityExecutionOracle({
|
|
529
|
-
|
|
983
|
+
callContext: CallContext.from({
|
|
984
|
+
msgSender: AztecAddress.NULL_MSG_SENDER,
|
|
985
|
+
contractAddress: call.to,
|
|
986
|
+
functionSelector: call.selector,
|
|
987
|
+
isStaticCall: true,
|
|
988
|
+
}),
|
|
530
989
|
authWitnesses: [],
|
|
531
990
|
capsules: [],
|
|
532
991
|
anchorBlockHeader: anchorBlock!,
|
|
533
|
-
|
|
992
|
+
anchoredContractData,
|
|
534
993
|
noteStore: this.noteStore,
|
|
535
994
|
keyStore: this.keyStore,
|
|
536
995
|
addressStore: this.addressStore,
|
|
537
996
|
aztecNode: this.stateMachine.node,
|
|
538
997
|
recipientTaggingStore: this.recipientTaggingStore,
|
|
539
|
-
|
|
540
|
-
|
|
998
|
+
taggingSecretSourcesStore: this.taggingSecretSourcesStore,
|
|
999
|
+
capsuleService: new CapsuleService(this.capsuleStore, scopes),
|
|
1000
|
+
factService: new FactService(this.factStore, scopes),
|
|
541
1001
|
privateEventStore: this.privateEventStore,
|
|
542
|
-
|
|
543
|
-
contractSyncService: this.contractSyncService,
|
|
1002
|
+
txResolver: this.stateMachine.txResolver,
|
|
1003
|
+
contractSyncService: this.stateMachine.contractSyncService,
|
|
1004
|
+
l2TipsStore: this.stateMachine.l2TipsProvider,
|
|
544
1005
|
jobId: this.currentJobId,
|
|
545
1006
|
scopes,
|
|
1007
|
+
simulator,
|
|
1008
|
+
utilityExecutor: this.utilityExecutorForContractSync(anchorBlock),
|
|
1009
|
+
// Top-level utility entrypoint: gets a fresh store. Nested frames inherit it via UtilityExecutionOracle.
|
|
1010
|
+
transientArrayService: new TransientArrayService(),
|
|
546
1011
|
});
|
|
547
|
-
await
|
|
548
|
-
.executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact,
|
|
1012
|
+
await simulator
|
|
1013
|
+
.executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, buildACIRCallback(oracle))
|
|
549
1014
|
.catch((err: Error) => {
|
|
550
1015
|
err.message = resolveAssertionMessageFromError(err, entryPointArtifact);
|
|
551
1016
|
throw new ExecutionError(
|