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