@aztec/txe 0.0.1-commit.b655e406 → 0.0.1-commit.b8a057fa
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-HMC7WEOJ.js +3 -0
- package/dest/AuthRegistry-HMC7WEOJ.js.map +7 -0
- package/dest/ContractClassRegistry-TXCDCFNC.js +3 -0
- package/dest/ContractClassRegistry-TXCDCFNC.js.map +7 -0
- package/dest/ContractInstanceRegistry-2TZHWOTT.js +3 -0
- package/dest/ContractInstanceRegistry-2TZHWOTT.js.map +7 -0
- package/dest/FeeJuice-FDF3J2Q5.js +3 -0
- package/dest/FeeJuice-FDF3J2Q5.js.map +7 -0
- package/dest/HandshakeRegistry-C7JF4R54.js +3 -0
- package/dest/HandshakeRegistry-C7JF4R54.js.map +7 -0
- package/dest/MultiCallEntrypoint-IGLO227K.js +3 -0
- package/dest/MultiCallEntrypoint-IGLO227K.js.map +7 -0
- package/dest/SchnorrAccount-KCIHUCXS.js +3 -0
- package/dest/SchnorrAccount-KCIHUCXS.js.map +7 -0
- package/dest/SchnorrInitializerlessAccount-PVR6XUSN.js +3 -0
- package/dest/SchnorrInitializerlessAccount-PVR6XUSN.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.d.ts +1 -1
- package/dest/bin/index.js +3 -30
- package/dest/bin/index.js.map +7 -0
- package/dest/bin/oracle_test_server.d.ts +3 -0
- package/dest/bin/oracle_test_server.d.ts.map +1 -0
- package/dest/bin/oracle_test_server.js +41 -0
- package/dest/chunk-32UHX7YY.js +3 -0
- package/dest/chunk-32UHX7YY.js.map +7 -0
- package/dest/chunk-FRF5YZEO.js +304 -0
- package/dest/chunk-FRF5YZEO.js.map +7 -0
- package/dest/chunk-O57S6W5S.js +260 -0
- package/dest/chunk-O57S6W5S.js.map +7 -0
- package/dest/constants.d.ts +7 -0
- package/dest/constants.d.ts.map +1 -0
- package/dest/constants.js +10 -0
- 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 +75 -158
- package/dest/metafile.json +38497 -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 -31
- package/dest/oracle/interfaces.d.ts.map +1 -1
- 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 +41 -17
- package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.js +69 -23
- package/dest/oracle/txe_oracle_registry.d.ts +169 -0
- package/dest/oracle/txe_oracle_registry.d.ts.map +1 -0
- package/dest/oracle/txe_oracle_registry.js +745 -0
- package/dest/oracle/txe_oracle_top_level_context.d.ts +66 -30
- package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_top_level_context.js +630 -275
- 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 +112 -213
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +877 -550
- package/dest/server.bundle.js +3 -0
- package/dest/server.bundle.js.map +7 -0
- package/dest/state_machine/archiver.d.ts +23 -52
- package/dest/state_machine/archiver.d.ts.map +1 -1
- package/dest/state_machine/archiver.js +76 -99
- package/dest/state_machine/dummy_p2p_client.d.ts +31 -15
- package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
- package/dest/state_machine/dummy_p2p_client.js +63 -22
- package/dest/state_machine/global_variable_builder.d.ts +10 -4
- package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
- package/dest/state_machine/global_variable_builder.js +20 -5
- package/dest/state_machine/index.d.ts +14 -8
- package/dest/state_machine/index.d.ts.map +1 -1
- package/dest/state_machine/index.js +84 -27
- package/dest/state_machine/mock_epoch_cache.d.ts +29 -12
- package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
- package/dest/state_machine/mock_epoch_cache.js +50 -15
- package/dest/state_machine/synchronizer.d.ts +15 -6
- package/dest/state_machine/synchronizer.d.ts.map +1 -1
- package/dest/state_machine/synchronizer.js +27 -13
- package/dest/txe_session.d.ts +102 -21
- package/dest/txe_session.d.ts.map +1 -1
- package/dest/txe_session.js +440 -76
- package/dest/utils/block_creation.d.ts +22 -7
- package/dest/utils/block_creation.d.ts.map +1 -1
- package/dest/utils/block_creation.js +40 -6
- package/dest/utils/encoding.d.ts +192 -0
- package/dest/utils/encoding.d.ts.map +1 -0
- package/dest/{util → utils}/encoding.js +8 -3
- package/dest/utils/expected_failure_error.d.ts +4 -0
- package/dest/utils/expected_failure_error.d.ts.map +1 -0
- package/dest/utils/tx_effect_creation.d.ts +3 -3
- package/dest/utils/tx_effect_creation.d.ts.map +1 -1
- package/dest/utils/tx_effect_creation.js +3 -7
- package/dest/utils/txe_account_store.d.ts +10 -0
- package/dest/utils/txe_account_store.d.ts.map +1 -0
- package/dest/{util/txe_account_data_provider.js → utils/txe_account_store.js} +1 -1
- 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 +40 -22
- 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 +13 -0
- package/src/dispatcher_pool.ts +317 -0
- package/src/index.ts +113 -201
- package/src/msgpackr_fr_extension.ts +23 -0
- package/src/oracle/interfaces.ts +68 -36
- 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 +83 -28
- package/src/oracle/txe_oracle_registry.ts +536 -0
- package/src/oracle/txe_oracle_top_level_context.ts +539 -199
- 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 +1086 -909
- package/src/state_machine/archiver.ts +82 -115
- package/src/state_machine/dummy_p2p_client.ts +96 -33
- package/src/state_machine/global_variable_builder.ts +28 -9
- package/src/state_machine/index.ts +118 -44
- package/src/state_machine/mock_epoch_cache.ts +63 -23
- package/src/state_machine/synchronizer.ts +36 -14
- package/src/txe_session.ts +719 -125
- package/src/utils/block_creation.ts +51 -15
- package/src/{util → utils}/encoding.ts +9 -3
- package/src/utils/tx_effect_creation.ts +4 -13
- package/src/{util/txe_account_data_provider.ts → utils/txe_account_store.ts} +1 -1
- 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 -121
- package/dest/util/encoding.d.ts.map +0 -1
- package/dest/util/expected_failure_error.d.ts +0 -4
- package/dest/util/expected_failure_error.d.ts.map +0 -1
- package/dest/util/txe_account_data_provider.d.ts +0 -10
- package/dest/util/txe_account_data_provider.d.ts.map +0 -1
- package/dest/util/txe_contract_data_provider.d.ts +0 -12
- package/dest/util/txe_contract_data_provider.d.ts.map +0 -1
- package/dest/util/txe_contract_data_provider.js +0 -22
- package/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/txe_public_contract_data_source.js +0 -67
- package/src/util/txe_contract_data_provider.ts +0 -36
- package/src/util/txe_public_contract_data_source.ts +0 -85
- /package/dest/{util → utils}/expected_failure_error.js +0 -0
- /package/src/{util → utils}/expected_failure_error.ts +0 -0
package/dest/txe_session.js
CHANGED
|
@@ -1,82 +1,168 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
3
|
import { createLogger } from '@aztec/foundation/log';
|
|
3
4
|
import { KeyStore } from '@aztec/key-store';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { ExecutionNoteCache, ExecutionTaggingIndexCache, HashedValuesCache,
|
|
7
|
-
import {
|
|
5
|
+
import { openEphemeralStore } from '@aztec/kv-store/lmdb-v2';
|
|
6
|
+
import { AddressStore, AnchorBlockStore, AnchoredContractData, CapsuleService, CapsuleStore, FactService, FactStore, JobCoordinator, NoteService, NoteStore, PrivateEventStore, RecipientTaggingStore, SenderTaggingStore, TaggingSecretSourcesStore, composeHooks } from '@aztec/pxe/server';
|
|
7
|
+
import { ExecutionNoteCache, ExecutionTaggingIndexCache, HashedValuesCache, LEGACY_ORACLE_REGISTRY, TransientArrayService, UtilityExecutionOracle, buildACIRCallback } from '@aztec/pxe/simulator';
|
|
8
|
+
import { ExecutionError, WASMSimulator, createSimulationError, extractCallStack, resolveAssertionMessageFromError, toACVMWitness } from '@aztec/simulator/client';
|
|
9
|
+
import { STANDARD_AUTH_REGISTRY_ADDRESS } from '@aztec/standard-contracts/auth-registry/constants';
|
|
10
|
+
import { FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
|
|
8
11
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import { CallContext, TxContext } from '@aztec/stdlib/tx';
|
|
12
|
+
import { computeProtocolNullifier } from '@aztec/stdlib/hash';
|
|
13
|
+
import { makeGlobalVariables } from '@aztec/stdlib/testing';
|
|
14
|
+
import { CallContext, OFFCHAIN_MESSAGE_IDENTIFIER, TxContext } from '@aztec/stdlib/tx';
|
|
13
15
|
import { z } from 'zod';
|
|
16
|
+
import { DEFAULT_ADDRESS, MAX_OFFCHAIN_EFFECTS_PER_TXE_QUERY, MAX_OFFCHAIN_EFFECT_LEN } from './constants.js';
|
|
14
17
|
import { TXEOraclePublicContext } from './oracle/txe_oracle_public_context.js';
|
|
18
|
+
import { callTxeLegacyHandler } from './oracle/txe_oracle_registry.js';
|
|
15
19
|
import { TXEOracleTopLevelContext } from './oracle/txe_oracle_top_level_context.js';
|
|
16
|
-
import {
|
|
20
|
+
import { TXE_ORACLE_VERSION_MAJOR, TXE_ORACLE_VERSION_MINOR } from './oracle/txe_oracle_version.js';
|
|
21
|
+
import { TXEPrivateExecutionOracle } from './oracle/txe_private_execution_oracle.js';
|
|
22
|
+
import { RPCTranslator, UnavailableOracleError } from './rpc_translator.js';
|
|
23
|
+
import { TXEArchiver } from './state_machine/archiver.js';
|
|
17
24
|
import { TXEStateMachine } from './state_machine/index.js';
|
|
18
|
-
import {
|
|
19
|
-
import { TXEContractDataProvider } from './util/txe_contract_data_provider.js';
|
|
20
|
-
import { getSingleTxBlockRequestHash, insertTxEffectIntoWorldTrees, makeTXEBlockHeader } from './utils/block_creation.js';
|
|
25
|
+
import { getSingleTxBlockRequestHash, insertTxEffectIntoWorldTrees, makeTXEBlock } from './utils/block_creation.js';
|
|
21
26
|
import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
22
|
-
|
|
27
|
+
import { TXEAccountStore } from './utils/txe_account_store.js';
|
|
28
|
+
function emptyLastCallState() {
|
|
29
|
+
return {
|
|
30
|
+
offchainEffects: [],
|
|
31
|
+
queried: false,
|
|
32
|
+
txHash: Fr.ZERO,
|
|
33
|
+
anchorBlockTimestamp: 0n
|
|
34
|
+
};
|
|
35
|
+
}
|
|
23
36
|
/**
|
|
24
37
|
* A `TXESession` corresponds to a Noir `#[test]` function, and handles all of its oracle calls, stores test-specific
|
|
25
38
|
* state, etc., independent of all other tests running in parallel.
|
|
26
39
|
*/ export class TXESession {
|
|
27
40
|
logger;
|
|
41
|
+
sessionStore;
|
|
28
42
|
stateMachine;
|
|
29
43
|
oracleHandler;
|
|
30
|
-
|
|
44
|
+
contractStore;
|
|
45
|
+
noteStore;
|
|
31
46
|
keyStore;
|
|
32
|
-
|
|
33
|
-
|
|
47
|
+
addressStore;
|
|
48
|
+
accountStore;
|
|
49
|
+
senderTaggingStore;
|
|
50
|
+
recipientTaggingStore;
|
|
51
|
+
taggingSecretSourcesStore;
|
|
52
|
+
capsuleStore;
|
|
53
|
+
factStore;
|
|
54
|
+
privateEventStore;
|
|
55
|
+
jobCoordinator;
|
|
56
|
+
currentJobId;
|
|
34
57
|
chainId;
|
|
35
58
|
version;
|
|
36
59
|
nextBlockTimestamp;
|
|
37
|
-
|
|
60
|
+
artifactResolver;
|
|
61
|
+
rootPath;
|
|
62
|
+
packageName;
|
|
38
63
|
state;
|
|
39
64
|
authwits;
|
|
40
|
-
|
|
65
|
+
taggingSecretStrategy;
|
|
66
|
+
lastCallInfo;
|
|
67
|
+
txeOracleVersion;
|
|
68
|
+
disposed;
|
|
69
|
+
constructor(logger, sessionStore, stateMachine, oracleHandler, contractStore, noteStore, keyStore, addressStore, accountStore, senderTaggingStore, recipientTaggingStore, taggingSecretSourcesStore, capsuleStore, factStore, privateEventStore, jobCoordinator, currentJobId, chainId, version, nextBlockTimestamp, artifactResolver, rootPath, packageName){
|
|
41
70
|
this.logger = logger;
|
|
71
|
+
this.sessionStore = sessionStore;
|
|
42
72
|
this.stateMachine = stateMachine;
|
|
43
73
|
this.oracleHandler = oracleHandler;
|
|
44
|
-
this.
|
|
74
|
+
this.contractStore = contractStore;
|
|
75
|
+
this.noteStore = noteStore;
|
|
45
76
|
this.keyStore = keyStore;
|
|
46
|
-
this.
|
|
47
|
-
this.
|
|
77
|
+
this.addressStore = addressStore;
|
|
78
|
+
this.accountStore = accountStore;
|
|
79
|
+
this.senderTaggingStore = senderTaggingStore;
|
|
80
|
+
this.recipientTaggingStore = recipientTaggingStore;
|
|
81
|
+
this.taggingSecretSourcesStore = taggingSecretSourcesStore;
|
|
82
|
+
this.capsuleStore = capsuleStore;
|
|
83
|
+
this.factStore = factStore;
|
|
84
|
+
this.privateEventStore = privateEventStore;
|
|
85
|
+
this.jobCoordinator = jobCoordinator;
|
|
86
|
+
this.currentJobId = currentJobId;
|
|
48
87
|
this.chainId = chainId;
|
|
49
88
|
this.version = version;
|
|
50
89
|
this.nextBlockTimestamp = nextBlockTimestamp;
|
|
51
|
-
this.
|
|
90
|
+
this.artifactResolver = artifactResolver;
|
|
91
|
+
this.rootPath = rootPath;
|
|
92
|
+
this.packageName = packageName;
|
|
52
93
|
this.state = {
|
|
53
94
|
name: 'TOP_LEVEL'
|
|
54
95
|
};
|
|
55
96
|
this.authwits = new Map();
|
|
97
|
+
this.taggingSecretStrategy = undefined;
|
|
98
|
+
this.lastCallInfo = emptyLastCallState();
|
|
99
|
+
this.disposed = false;
|
|
56
100
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
//
|
|
68
|
-
|
|
69
|
-
await
|
|
70
|
-
|
|
101
|
+
/**
|
|
102
|
+
* Tears down the per-session AVM simulator (process pool + CDB server), the `NativeWorldStateService`,
|
|
103
|
+
* and the `txe-session` LMDB. Called via IPC when the dispatcher detects the end of a test. Idempotent.
|
|
104
|
+
*/ async dispose() {
|
|
105
|
+
if (this.disposed) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
this.disposed = true;
|
|
109
|
+
// Dispose the AVM pool before the world state: it kills the bb-avm-sim processes so they release their
|
|
110
|
+
// connection to the WSDB server, letting it shut down cleanly. Skipping this leaks a bb-avm-sim process
|
|
111
|
+
// (and keeps its WSDB alive) per session.
|
|
112
|
+
try {
|
|
113
|
+
await this.stateMachine.synchronizer.closeIpc();
|
|
114
|
+
} catch (err) {
|
|
115
|
+
this.logger.warn(`Error closing AVM simulator during session dispose`, err);
|
|
116
|
+
}
|
|
117
|
+
try {
|
|
118
|
+
await this.stateMachine.synchronizer.nativeWorldStateService.close();
|
|
119
|
+
} catch (err) {
|
|
120
|
+
this.logger.warn(`Error closing native world state during session dispose`, err);
|
|
71
121
|
}
|
|
72
|
-
|
|
122
|
+
try {
|
|
123
|
+
await this.sessionStore.close();
|
|
124
|
+
} catch (err) {
|
|
125
|
+
this.logger.warn(`Error closing session LMDB during dispose`, err);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
static async init(contractStore, artifactResolver, rootPath, packageName) {
|
|
129
|
+
// Size LMDB's reader slots to the libuv pool (capped to 2 in bin/index.ts via
|
|
130
|
+
// HARDWARE_CONCURRENCY): each native LMDB read needs a libuv worker thread to run, so any
|
|
131
|
+
// slot beyond the pool size would sit idle while still consuming a semaphore + reader-table
|
|
132
|
+
// entry per session.
|
|
133
|
+
const store = await openEphemeralStore('txe-session', undefined, 2);
|
|
134
|
+
const addressStore = new AddressStore(store);
|
|
135
|
+
const privateEventStore = new PrivateEventStore(store);
|
|
136
|
+
const noteStore = new NoteStore(store);
|
|
137
|
+
const senderTaggingStore = new SenderTaggingStore(store);
|
|
138
|
+
const recipientTaggingStore = new RecipientTaggingStore(store);
|
|
139
|
+
const taggingSecretSourcesStore = new TaggingSecretSourcesStore(store);
|
|
140
|
+
const capsuleStore = new CapsuleStore(store);
|
|
141
|
+
const factStore = new FactStore(store);
|
|
142
|
+
const keyStore = new KeyStore(store);
|
|
143
|
+
const accountStore = new TXEAccountStore(store);
|
|
144
|
+
const jobCoordinator = new JobCoordinator(store);
|
|
145
|
+
jobCoordinator.registerStores([
|
|
146
|
+
capsuleStore,
|
|
147
|
+
factStore,
|
|
148
|
+
senderTaggingStore,
|
|
149
|
+
recipientTaggingStore,
|
|
150
|
+
privateEventStore,
|
|
151
|
+
noteStore
|
|
152
|
+
]);
|
|
153
|
+
const archiver = new TXEArchiver(store);
|
|
154
|
+
const anchorBlockStore = new AnchorBlockStore(store);
|
|
155
|
+
const stateMachine = await TXEStateMachine.create(archiver, anchorBlockStore, contractStore, noteStore);
|
|
73
156
|
const nextBlockTimestamp = BigInt(Math.floor(new Date().getTime() / 1000));
|
|
74
157
|
const version = new Fr(await stateMachine.node.getVersion());
|
|
75
158
|
const chainId = new Fr(await stateMachine.node.getChainId());
|
|
76
|
-
const
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
159
|
+
const initialJobId = jobCoordinator.beginJob();
|
|
160
|
+
const logger = createLogger('txe:session');
|
|
161
|
+
const topLevelOracleHandler = new TXEOracleTopLevelContext(stateMachine, contractStore, noteStore, keyStore, addressStore, accountStore, senderTaggingStore, recipientTaggingStore, taggingSecretSourcesStore, capsuleStore, factStore, privateEventStore, nextBlockTimestamp, version, chainId, new Map(), undefined, artifactResolver, rootPath, packageName);
|
|
162
|
+
await topLevelOracleHandler.mineDeploymentNullifiers([
|
|
163
|
+
STANDARD_AUTH_REGISTRY_ADDRESS
|
|
164
|
+
]);
|
|
165
|
+
return new TXESession(logger, store, stateMachine, topLevelOracleHandler, contractStore, noteStore, keyStore, addressStore, accountStore, senderTaggingStore, recipientTaggingStore, taggingSecretSourcesStore, capsuleStore, factStore, privateEventStore, jobCoordinator, initialJobId, version, chainId, nextBlockTimestamp, artifactResolver, rootPath, packageName);
|
|
80
166
|
}
|
|
81
167
|
/**
|
|
82
168
|
* Processes an oracle function invoked by the Noir test associated to this session.
|
|
@@ -85,13 +171,28 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
|
|
|
85
171
|
* @returns The oracle return values.
|
|
86
172
|
*/ processFunction(functionName, inputs) {
|
|
87
173
|
try {
|
|
174
|
+
// Oracles retired into the PXE legacy registry have no translator method; dispatch them through the same
|
|
175
|
+
// buildACIRCallback legacy path that contract execution uses, keeping TXE's two oracle paths in sync.
|
|
176
|
+
// Use an own-property check: `in` would match inherited `Object.prototype` keys (e.g. `constructor`), routing
|
|
177
|
+
// them into the legacy path instead of letting them fall through to the unknown-oracle error.
|
|
178
|
+
if (Object.hasOwn(LEGACY_ORACLE_REGISTRY, functionName)) {
|
|
179
|
+
return callTxeLegacyHandler(functionName, inputs, this.oracleHandler);
|
|
180
|
+
}
|
|
88
181
|
const translator = new RPCTranslator(this, this.oracleHandler);
|
|
89
182
|
// We perform a runtime validation to check that the function name corresponds to a real oracle handler.
|
|
90
183
|
const validatedFunctionName = z.string().refine((fn)=>typeof translator[fn] === 'function' && !fn.startsWith('handlerAs') && fn !== 'constructor').parse(functionName);
|
|
91
184
|
return translator[validatedFunctionName](...inputs);
|
|
92
185
|
} catch (error) {
|
|
93
186
|
if (error instanceof z.ZodError) {
|
|
94
|
-
|
|
187
|
+
let versionHint;
|
|
188
|
+
if (!this.txeOracleVersion) {
|
|
189
|
+
versionHint = ' The test appears to use an older version of Aztec.nr that does not' + ' support test environment oracle versioning. Update Aztec.nr to a compatible version.' + ' See https://docs.aztec.network/errors/12';
|
|
190
|
+
} else if (this.txeOracleVersion.minor > TXE_ORACLE_VERSION_MINOR) {
|
|
191
|
+
versionHint = ` The test uses Aztec.nr test oracle version` + ` ${this.txeOracleVersion.major}.${this.txeOracleVersion.minor}, but this test environment` + ` only supports up to ${TXE_ORACLE_VERSION_MAJOR}.${TXE_ORACLE_VERSION_MINOR}.` + ` Upgrade the Aztec CLI to a compatible version.` + ` See https://docs.aztec.network/errors/12`;
|
|
192
|
+
} else {
|
|
193
|
+
versionHint = ` The test's oracle version (${this.txeOracleVersion.major}.${this.txeOracleVersion.minor})` + ` is compatible with this test environment` + ` (${TXE_ORACLE_VERSION_MAJOR}.${TXE_ORACLE_VERSION_MINOR}), so this oracle should be` + ` available. This is an unexpected error, please report it.` + ` See https://docs.aztec.network/errors/13`;
|
|
194
|
+
}
|
|
195
|
+
throw new Error(`Unknown oracle '${functionName}'.${versionHint}`);
|
|
95
196
|
} else if (error instanceof Error) {
|
|
96
197
|
throw new Error(`Execution error while processing function ${functionName} in state ${this.state.name}: ${error.message}`);
|
|
97
198
|
} else {
|
|
@@ -99,6 +200,132 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
|
|
|
99
200
|
}
|
|
100
201
|
}
|
|
101
202
|
}
|
|
203
|
+
/** Commits the current job and begins a new one. Returns the new job ID. */ async cycleJob() {
|
|
204
|
+
await this.jobCoordinator.commitJob(this.currentJobId);
|
|
205
|
+
this.currentJobId = this.jobCoordinator.beginJob();
|
|
206
|
+
return this.currentJobId;
|
|
207
|
+
}
|
|
208
|
+
resetLastCall() {
|
|
209
|
+
const notQueriedMessageCount = this.lastCallInfo.queried ? 0 : this.lastCallInfo.offchainEffects.filter((payload)=>payload[0]?.equals(OFFCHAIN_MESSAGE_IDENTIFIER)).length;
|
|
210
|
+
if (notQueriedMessageCount > 0) {
|
|
211
|
+
this.logger.warn(`Dropping ${notQueriedMessageCount} unqueried offchain message(s) from the previous top-level call. ` + `To deliver them, call \`env.offchain_messages()\` and forward the result to the recipient contract's ` + `\`offchain_receive\` utility before issuing another top-level call. To intentionally discard, assign ` + `to \`let _ = env.offchain_messages()\` to silence this warning.`);
|
|
212
|
+
}
|
|
213
|
+
this.lastCallInfo = emptyLastCallState();
|
|
214
|
+
}
|
|
215
|
+
recordOffchainEffect(data) {
|
|
216
|
+
this.lastCallInfo.offchainEffects.push(data);
|
|
217
|
+
}
|
|
218
|
+
setLastCallContext(txHash, anchorBlockTimestamp) {
|
|
219
|
+
this.lastCallInfo.txHash = txHash;
|
|
220
|
+
this.lastCallInfo.anchorBlockTimestamp = anchorBlockTimestamp;
|
|
221
|
+
}
|
|
222
|
+
async withTopLevelCallTracking(work) {
|
|
223
|
+
this.resetLastCall();
|
|
224
|
+
// Capture the anchor *before* `work` runs: private/public executor calls mine a new block as a
|
|
225
|
+
// side effect, and that block's timestamp should not be attributed to this call's anchor.
|
|
226
|
+
const anchorBlockTimestamp = (await this.stateMachine.node.getBlockData('latest')).header.globalVariables.timestamp;
|
|
227
|
+
const { result, txHash } = await work();
|
|
228
|
+
this.setLastCallContext(txHash ?? Fr.ZERO, anchorBlockTimestamp);
|
|
229
|
+
return result;
|
|
230
|
+
}
|
|
231
|
+
getLastCallOffchainEffects() {
|
|
232
|
+
this.lastCallInfo.queried = true;
|
|
233
|
+
const effects = this.lastCallInfo.offchainEffects;
|
|
234
|
+
if (effects.length > MAX_OFFCHAIN_EFFECTS_PER_TXE_QUERY) {
|
|
235
|
+
throw new Error(`${effects.length} offchain effects exceed max ${MAX_OFFCHAIN_EFFECTS_PER_TXE_QUERY}`);
|
|
236
|
+
}
|
|
237
|
+
if (effects.some((e)=>e.length > MAX_OFFCHAIN_EFFECT_LEN)) {
|
|
238
|
+
throw new Error(`Some offchain effect has length larger than max ${MAX_OFFCHAIN_EFFECT_LEN}`);
|
|
239
|
+
}
|
|
240
|
+
return {
|
|
241
|
+
effects
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
getLastCallContext() {
|
|
245
|
+
const { txHash, anchorBlockTimestamp } = this.lastCallInfo;
|
|
246
|
+
return {
|
|
247
|
+
txHash,
|
|
248
|
+
anchorBlockTimestamp
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
async executePrivateCall(from, targetContractAddress, functionSelector, args, argsHash, isStaticCall, additionalScopes, authorizedUtilityCallTargets, gasSettings) {
|
|
252
|
+
const handler = this.handlerAsTxe();
|
|
253
|
+
return await this.withTopLevelCallTracking(async ()=>{
|
|
254
|
+
const { returnValues, offchainEffects } = await handler.privateCallNewFlow(from?.value, targetContractAddress, functionSelector, args, argsHash, isStaticCall, additionalScopes, this.currentJobId, authorizedUtilityCallTargets, gasSettings);
|
|
255
|
+
// Private execution collects offchain effects inside PXE's PrivateExecutionOracle rather than round-tripping
|
|
256
|
+
// them through `aztec_utl_emitOffchainEffect`, so the session buffer is empty at this point. Drain the effects
|
|
257
|
+
// from the execution tree into the session buffer so the next `env.offchain_messages()` call in the test sees
|
|
258
|
+
// them.
|
|
259
|
+
for (const data of offchainEffects){
|
|
260
|
+
this.recordOffchainEffect(data);
|
|
261
|
+
}
|
|
262
|
+
await this.cycleJob();
|
|
263
|
+
if (isStaticCall) {
|
|
264
|
+
// Static calls revert their checkpoint and mine no block, so there is no tx hash to tag offchain effects
|
|
265
|
+
// with. Querying `getLastTxEffects()` here would return an unrelated predecessor tx.
|
|
266
|
+
return {
|
|
267
|
+
result: returnValues
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
const { txHash } = await handler.getLastTxEffects();
|
|
271
|
+
return {
|
|
272
|
+
result: returnValues,
|
|
273
|
+
txHash: txHash.hash
|
|
274
|
+
};
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
async executeUtilityFunction(from, targetContractAddress, functionSelector, args, authorizedUtilityCallTargets) {
|
|
278
|
+
const handler = this.handlerAsTxe();
|
|
279
|
+
return await this.withTopLevelCallTracking(async ()=>{
|
|
280
|
+
const returnValues = await handler.executeUtilityFunction(from?.value, targetContractAddress, functionSelector, args, this.currentJobId, authorizedUtilityCallTargets);
|
|
281
|
+
await this.cycleJob();
|
|
282
|
+
return {
|
|
283
|
+
result: returnValues
|
|
284
|
+
};
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
async executePublicCall(from, targetContractAddress, calldata, isStaticCall, gasSettings) {
|
|
288
|
+
const handler = this.handlerAsTxe();
|
|
289
|
+
return await this.withTopLevelCallTracking(async ()=>{
|
|
290
|
+
const returnValues = await handler.publicCallNewFlow(from?.value, targetContractAddress, calldata, isStaticCall, gasSettings);
|
|
291
|
+
await this.cycleJob();
|
|
292
|
+
if (isStaticCall) {
|
|
293
|
+
// See the equivalent branch in `executePrivateCall`.
|
|
294
|
+
return {
|
|
295
|
+
result: returnValues
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
const { txHash } = await handler.getLastTxEffects();
|
|
299
|
+
return {
|
|
300
|
+
result: returnValues,
|
|
301
|
+
txHash: txHash.hash
|
|
302
|
+
};
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
async getPrivateEvents(selector, contractAddress, scope) {
|
|
306
|
+
const handler = this.handlerAsTxe();
|
|
307
|
+
await handler.syncContractNonOracleMethod(contractAddress, scope, this.currentJobId);
|
|
308
|
+
// Cycle the job to commit the stores after the contract sync.
|
|
309
|
+
await this.cycleJob();
|
|
310
|
+
return handler.getPrivateEvents(selector, contractAddress, scope);
|
|
311
|
+
}
|
|
312
|
+
handlerAsTxe() {
|
|
313
|
+
if (!('isTxe' in this.oracleHandler)) {
|
|
314
|
+
throw new UnavailableOracleError('Txe');
|
|
315
|
+
}
|
|
316
|
+
return this.oracleHandler;
|
|
317
|
+
}
|
|
318
|
+
setTxeOracleVersion(major, minor) {
|
|
319
|
+
if (major !== TXE_ORACLE_VERSION_MAJOR) {
|
|
320
|
+
const hint = major > TXE_ORACLE_VERSION_MAJOR ? 'The test was compiled with a newer version of Aztec.nr than your test environment supports. Upgrade your test environment to a compatible version.' : '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.';
|
|
321
|
+
throw new Error(`Incompatible test environment version: ${hint} See https://docs.aztec.network/errors/12 (expected test oracle major version ${TXE_ORACLE_VERSION_MAJOR}, got ${major})`);
|
|
322
|
+
}
|
|
323
|
+
this.txeOracleVersion = {
|
|
324
|
+
major,
|
|
325
|
+
minor
|
|
326
|
+
};
|
|
327
|
+
this.logger.debug(`Test compiled with test oracle version ${major}.${minor}`);
|
|
328
|
+
}
|
|
102
329
|
async enterTopLevelState() {
|
|
103
330
|
switch(this.state.name){
|
|
104
331
|
case 'PRIVATE':
|
|
@@ -125,35 +352,73 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
|
|
|
125
352
|
this.state;
|
|
126
353
|
}
|
|
127
354
|
}
|
|
128
|
-
|
|
355
|
+
// Commit all staged stores from the job that was just completed, then begin a new job
|
|
356
|
+
await this.cycleJob();
|
|
357
|
+
this.oracleHandler = new TXEOracleTopLevelContext(this.stateMachine, this.contractStore, this.noteStore, this.keyStore, this.addressStore, this.accountStore, this.senderTaggingStore, this.recipientTaggingStore, this.taggingSecretSourcesStore, this.capsuleStore, this.factStore, this.privateEventStore, this.nextBlockTimestamp, this.version, this.chainId, this.authwits, this.taggingSecretStrategy, this.artifactResolver, this.rootPath, this.packageName);
|
|
129
358
|
this.state = {
|
|
130
359
|
name: 'TOP_LEVEL'
|
|
131
360
|
};
|
|
132
361
|
this.logger.debug(`Entered state ${this.state.name}`);
|
|
133
362
|
}
|
|
134
|
-
async enterPrivateState(
|
|
363
|
+
async enterPrivateState(contractAddressOpt, anchorBlockNumberOpt, gasSettings) {
|
|
364
|
+
const contractAddress = contractAddressOpt?.value ?? DEFAULT_ADDRESS;
|
|
365
|
+
const anchorBlockNumber = anchorBlockNumberOpt?.value;
|
|
135
366
|
this.exitTopLevelState();
|
|
136
|
-
|
|
137
|
-
// contexts, which means that known nullifiers are also not searched for, since it is during the tagging sync that
|
|
138
|
-
// we perform this. We therefore search for known nullifiers now, as otherwise notes that were nullified would not
|
|
139
|
-
// be removed from the database.
|
|
140
|
-
// TODO(#12553): make the synchronizer sync here instead and remove this
|
|
141
|
-
await this.pxeOracleInterface.syncNoteNullifiers(contractAddress);
|
|
367
|
+
this.resetLastCall();
|
|
142
368
|
// Private execution has two associated block numbers: the anchor block (i.e. the historical block that is used to
|
|
143
369
|
// build the proof), and the *next* block, i.e. the one we'll create once the execution ends, and which will contain
|
|
144
370
|
// a single transaction with the effects of what was done in the test.
|
|
145
|
-
const anchorBlock = await this.stateMachine.node.
|
|
146
|
-
|
|
371
|
+
const anchorBlock = await this.stateMachine.node.getBlock(anchorBlockNumber ?? 'latest').then((b)=>b?.header);
|
|
372
|
+
await new NoteService(this.noteStore, this.stateMachine.node, anchorBlock, this.currentJobId).syncNoteNullifiers(contractAddress, await this.keyStore.getAccounts());
|
|
373
|
+
const latestBlock = await this.stateMachine.node.getBlock('latest').then((b)=>b?.header);
|
|
147
374
|
const nextBlockGlobalVariables = makeGlobalVariables(undefined, {
|
|
148
|
-
blockNumber: latestBlock.globalVariables.blockNumber + 1,
|
|
375
|
+
blockNumber: BlockNumber(latestBlock.globalVariables.blockNumber + 1),
|
|
149
376
|
timestamp: this.nextBlockTimestamp,
|
|
150
377
|
version: this.version,
|
|
151
378
|
chainId: this.chainId
|
|
152
379
|
});
|
|
153
380
|
const txRequestHash = getSingleTxBlockRequestHash(nextBlockGlobalVariables.blockNumber);
|
|
154
|
-
const
|
|
381
|
+
const protocolNullifier = await computeProtocolNullifier(txRequestHash);
|
|
382
|
+
const noteCache = new ExecutionNoteCache(protocolNullifier);
|
|
155
383
|
const taggingIndexCache = new ExecutionTaggingIndexCache();
|
|
156
|
-
|
|
384
|
+
const utilityExecutor = this.utilityExecutorForContractSync(anchorBlock);
|
|
385
|
+
const transientArrayService = new TransientArrayService();
|
|
386
|
+
const anchoredContractData = new AnchoredContractData(this.contractStore, this.stateMachine.contractClassService, anchorBlock);
|
|
387
|
+
const taggingSecretStrategy = this.taggingSecretStrategy;
|
|
388
|
+
this.oracleHandler = new TXEPrivateExecutionOracle({
|
|
389
|
+
argsHash: Fr.ZERO,
|
|
390
|
+
txContext: new TxContext(this.chainId, this.version, gasSettings),
|
|
391
|
+
txRequestSalt: Fr.ZERO,
|
|
392
|
+
callContext: new CallContext(AztecAddress.ZERO, contractAddress, FunctionSelector.empty(), false),
|
|
393
|
+
anchorBlockHeader: anchorBlock,
|
|
394
|
+
utilityExecutor,
|
|
395
|
+
authWitnesses: [],
|
|
396
|
+
capsules: [],
|
|
397
|
+
executionCache: new HashedValuesCache(),
|
|
398
|
+
noteCache,
|
|
399
|
+
taggingIndexCache,
|
|
400
|
+
anchoredContractData,
|
|
401
|
+
noteStore: this.noteStore,
|
|
402
|
+
keyStore: this.keyStore,
|
|
403
|
+
addressStore: this.addressStore,
|
|
404
|
+
aztecNode: this.stateMachine.node,
|
|
405
|
+
senderTaggingStore: this.senderTaggingStore,
|
|
406
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
407
|
+
taggingSecretSourcesStore: this.taggingSecretSourcesStore,
|
|
408
|
+
capsuleService: new CapsuleService(this.capsuleStore, await this.keyStore.getAccounts()),
|
|
409
|
+
factService: new FactService(this.factStore, await this.keyStore.getAccounts()),
|
|
410
|
+
privateEventStore: this.privateEventStore,
|
|
411
|
+
contractSyncService: this.stateMachine.contractSyncService,
|
|
412
|
+
l2TipsStore: this.stateMachine.l2TipsProvider,
|
|
413
|
+
jobId: this.currentJobId,
|
|
414
|
+
scopes: await this.keyStore.getAccounts(),
|
|
415
|
+
txResolver: this.stateMachine.txResolver,
|
|
416
|
+
simulator: new WASMSimulator(),
|
|
417
|
+
hooks: composeHooks({
|
|
418
|
+
resolveTaggingSecretStrategy: taggingSecretStrategy ? ()=>Promise.resolve(taggingSecretStrategy) : undefined
|
|
419
|
+
}),
|
|
420
|
+
transientArrayService
|
|
421
|
+
});
|
|
157
422
|
// We store the note and tagging index caches fed into the PrivateExecutionOracle (along with some other auxiliary
|
|
158
423
|
// data) in order to refer to it later, mimicking the way this object is used by the ContractFunctionSimulator. The
|
|
159
424
|
// difference resides in that the simulator has all information needed in order to run the simulation, while ours
|
|
@@ -162,58 +427,101 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
|
|
|
162
427
|
this.state = {
|
|
163
428
|
name: 'PRIVATE',
|
|
164
429
|
nextBlockGlobalVariables,
|
|
165
|
-
txRequestHash,
|
|
166
430
|
noteCache,
|
|
167
431
|
taggingIndexCache
|
|
168
432
|
};
|
|
169
433
|
this.logger.debug(`Entered state ${this.state.name}`);
|
|
434
|
+
// Record the *resolved* anchor's timestamp — if the caller pinned the anchor to a past block
|
|
435
|
+
// via `anchorBlockNumber`, "latest" would be the wrong anchor for offchain-message semantics.
|
|
436
|
+
this.setLastCallContext(Fr.ZERO, anchorBlock.globalVariables.timestamp);
|
|
170
437
|
return this.oracleHandler.getPrivateContextInputs();
|
|
171
438
|
}
|
|
172
|
-
async enterPublicState(
|
|
439
|
+
async enterPublicState(contractAddressOpt) {
|
|
440
|
+
const contractAddress = contractAddressOpt?.value ?? DEFAULT_ADDRESS;
|
|
173
441
|
this.exitTopLevelState();
|
|
442
|
+
this.resetLastCall();
|
|
174
443
|
// The PublicContext will create a block with a single transaction in it, containing the effects of what was done in
|
|
175
444
|
// the test. The block therefore gets the *next* block number and timestamp.
|
|
176
|
-
const
|
|
445
|
+
const latestHeader = (await this.stateMachine.node.getBlockData('latest')).header;
|
|
177
446
|
const globalVariables = makeGlobalVariables(undefined, {
|
|
178
|
-
blockNumber:
|
|
447
|
+
blockNumber: BlockNumber(latestHeader.globalVariables.blockNumber + 1),
|
|
179
448
|
timestamp: this.nextBlockTimestamp,
|
|
180
449
|
version: this.version,
|
|
181
450
|
chainId: this.chainId
|
|
182
451
|
});
|
|
183
|
-
this.oracleHandler = new TXEOraclePublicContext(contractAddress
|
|
452
|
+
this.oracleHandler = new TXEOraclePublicContext(contractAddress, await this.stateMachine.synchronizer.nativeWorldStateService.fork(), getSingleTxBlockRequestHash(globalVariables.blockNumber), globalVariables, this.contractStore);
|
|
184
453
|
this.state = {
|
|
185
454
|
name: 'PUBLIC'
|
|
186
455
|
};
|
|
187
456
|
this.logger.debug(`Entered state ${this.state.name}`);
|
|
457
|
+
// Public state is anchored at the latest block.
|
|
458
|
+
this.setLastCallContext(Fr.ZERO, latestHeader.globalVariables.timestamp);
|
|
188
459
|
}
|
|
189
|
-
async enterUtilityState(
|
|
460
|
+
async enterUtilityState(contractAddressOpt) {
|
|
461
|
+
const contractAddress = contractAddressOpt?.value ?? DEFAULT_ADDRESS;
|
|
190
462
|
this.exitTopLevelState();
|
|
463
|
+
this.resetLastCall();
|
|
464
|
+
const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
191
465
|
// There is no automatic message discovery and contract-driven syncing process in inlined private or utility
|
|
192
466
|
// contexts, which means that known nullifiers are also not searched for, since it is during the tagging sync that
|
|
193
467
|
// we perform this. We therefore search for known nullifiers now, as otherwise notes that were nullified would not
|
|
194
468
|
// be removed from the database.
|
|
195
469
|
// TODO(#12553): make the synchronizer sync here instead and remove this
|
|
196
|
-
await this.
|
|
197
|
-
this.oracleHandler = new UtilityExecutionOracle(
|
|
470
|
+
await new NoteService(this.noteStore, this.stateMachine.node, anchorBlockHeader, this.currentJobId).syncNoteNullifiers(contractAddress, await this.keyStore.getAccounts());
|
|
471
|
+
this.oracleHandler = new UtilityExecutionOracle({
|
|
472
|
+
callContext: CallContext.from({
|
|
473
|
+
msgSender: AztecAddress.NULL_MSG_SENDER,
|
|
474
|
+
contractAddress,
|
|
475
|
+
// No specific function is being executed in this inlined utility context, hence the empty selector.
|
|
476
|
+
functionSelector: FunctionSelector.empty(),
|
|
477
|
+
isStaticCall: true
|
|
478
|
+
}),
|
|
479
|
+
authWitnesses: [],
|
|
480
|
+
capsules: [],
|
|
481
|
+
anchorBlockHeader,
|
|
482
|
+
anchoredContractData: new AnchoredContractData(this.contractStore, this.stateMachine.contractClassService, anchorBlockHeader),
|
|
483
|
+
noteStore: this.noteStore,
|
|
484
|
+
keyStore: this.keyStore,
|
|
485
|
+
addressStore: this.addressStore,
|
|
486
|
+
aztecNode: this.stateMachine.node,
|
|
487
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
488
|
+
taggingSecretSourcesStore: this.taggingSecretSourcesStore,
|
|
489
|
+
capsuleService: new CapsuleService(this.capsuleStore, await this.keyStore.getAccounts()),
|
|
490
|
+
factService: new FactService(this.factStore, await this.keyStore.getAccounts()),
|
|
491
|
+
privateEventStore: this.privateEventStore,
|
|
492
|
+
txResolver: this.stateMachine.txResolver,
|
|
493
|
+
contractSyncService: this.stateMachine.contractSyncService,
|
|
494
|
+
l2TipsStore: this.stateMachine.l2TipsProvider,
|
|
495
|
+
jobId: this.currentJobId,
|
|
496
|
+
scopes: await this.keyStore.getAccounts(),
|
|
497
|
+
simulator: new WASMSimulator(),
|
|
498
|
+
utilityExecutor: this.utilityExecutorForContractSync(anchorBlockHeader),
|
|
499
|
+
// Execution-tree root (top-level utility run): own store; nested frames inherit it.
|
|
500
|
+
transientArrayService: new TransientArrayService()
|
|
501
|
+
});
|
|
198
502
|
this.state = {
|
|
199
503
|
name: 'UTILITY'
|
|
200
504
|
};
|
|
201
505
|
this.logger.debug(`Entered state ${this.state.name}`);
|
|
506
|
+
// Utility state anchors at whatever the anchor block store is pointing to (tracked as latest).
|
|
507
|
+
this.setLastCallContext(Fr.ZERO, anchorBlockHeader.globalVariables.timestamp);
|
|
202
508
|
}
|
|
203
509
|
exitTopLevelState() {
|
|
204
510
|
if (this.state.name != 'TOP_LEVEL') {
|
|
205
511
|
throw new Error(`Expected to be in state 'TOP_LEVEL', but got '${this.state.name}' instead`);
|
|
206
512
|
}
|
|
207
513
|
// Note that while all public and private contexts do is build a single block that we then process when exiting
|
|
208
|
-
//
|
|
209
|
-
//
|
|
210
|
-
//
|
|
211
|
-
//
|
|
212
|
-
//
|
|
213
|
-
//
|
|
214
|
-
// the
|
|
215
|
-
//
|
|
216
|
-
|
|
514
|
+
// them, the top level context does most of its work as it goes: it creates empty blocks (via `advanceBlocksBy`
|
|
515
|
+
// and `deploy`), creates blocks with transactions (via `privateCallNewFlow` and `publicCallNewFlow`), adds
|
|
516
|
+
// accounts to PXE (via `addAccount`), etc. This is a slight inconsistency in the working model of this class, but
|
|
517
|
+
// is not too bad. The `close` call below therefore only hands back the session-scoped values that a test
|
|
518
|
+
// sets directly at the top level, outside any contract execution (e.g. via `advanceTimestampBy`,
|
|
519
|
+
// `addAuthWitness`, `setTaggingSecretStrategy`). The oracle handler is discarded on every state transition,
|
|
520
|
+
// so the session must seed these values into the contexts it creates later.
|
|
521
|
+
// TODO: persisting authwits this way is quite unfortunate: they create a temporary utility context that would
|
|
522
|
+
// otherwise reset them, so we'd not be able to pass more than one per execution. Ideally authwits would be passed
|
|
523
|
+
// alongside a contract call instead of pre-seeded.
|
|
524
|
+
[this.nextBlockTimestamp, this.authwits, this.taggingSecretStrategy] = this.oracleHandler.close();
|
|
217
525
|
}
|
|
218
526
|
async exitPrivateState() {
|
|
219
527
|
if (this.state.name != 'PRIVATE') {
|
|
@@ -224,13 +532,13 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
|
|
|
224
532
|
});
|
|
225
533
|
// We rely on the note cache to determine the effects of the transaction. This is incomplete as it doesn't private
|
|
226
534
|
// logs (other effects like enqueued public calls don't need to be considered since those are not allowed).
|
|
227
|
-
const txEffect = await makeTxEffect(this.state.noteCache, this.state.
|
|
535
|
+
const txEffect = await makeTxEffect(this.state.noteCache, this.state.nextBlockGlobalVariables.blockNumber);
|
|
228
536
|
// We build a block holding just this transaction
|
|
229
537
|
const forkedWorldTrees = await this.stateMachine.synchronizer.nativeWorldStateService.fork();
|
|
230
538
|
await insertTxEffectIntoWorldTrees(txEffect, forkedWorldTrees);
|
|
231
|
-
const block =
|
|
539
|
+
const block = await makeTXEBlock(forkedWorldTrees, this.state.nextBlockGlobalVariables, [
|
|
232
540
|
txEffect
|
|
233
|
-
])
|
|
541
|
+
]);
|
|
234
542
|
await this.stateMachine.handleL2Block(block);
|
|
235
543
|
await forkedWorldTrees.close();
|
|
236
544
|
this.logger.debug('Exited PublicContext with built block', {
|
|
@@ -250,4 +558,60 @@ const DEFAULT_ADDRESS = AztecAddress.fromNumber(42);
|
|
|
250
558
|
throw new Error(`Expected to be in state 'UTILITY', but got '${this.state.name}' instead`);
|
|
251
559
|
}
|
|
252
560
|
}
|
|
561
|
+
utilityExecutorForContractSync(anchorBlock) {
|
|
562
|
+
return async (call, scopes)=>{
|
|
563
|
+
const anchoredContractData = new AnchoredContractData(this.contractStore, this.stateMachine.contractClassService, anchorBlock);
|
|
564
|
+
const entryPointArtifact = await anchoredContractData.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
|
|
565
|
+
if (!entryPointArtifact) {
|
|
566
|
+
throw new Error(`Cannot run function ${call.selector} on ${call.to}: the contract is not registered.`);
|
|
567
|
+
}
|
|
568
|
+
if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
|
|
569
|
+
throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
|
|
570
|
+
}
|
|
571
|
+
try {
|
|
572
|
+
const simulator = new WASMSimulator();
|
|
573
|
+
const oracle = new UtilityExecutionOracle({
|
|
574
|
+
callContext: CallContext.from({
|
|
575
|
+
msgSender: AztecAddress.NULL_MSG_SENDER,
|
|
576
|
+
contractAddress: call.to,
|
|
577
|
+
functionSelector: call.selector,
|
|
578
|
+
isStaticCall: true
|
|
579
|
+
}),
|
|
580
|
+
authWitnesses: [],
|
|
581
|
+
capsules: [],
|
|
582
|
+
anchorBlockHeader: anchorBlock,
|
|
583
|
+
anchoredContractData,
|
|
584
|
+
noteStore: this.noteStore,
|
|
585
|
+
keyStore: this.keyStore,
|
|
586
|
+
addressStore: this.addressStore,
|
|
587
|
+
aztecNode: this.stateMachine.node,
|
|
588
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
589
|
+
taggingSecretSourcesStore: this.taggingSecretSourcesStore,
|
|
590
|
+
capsuleService: new CapsuleService(this.capsuleStore, scopes),
|
|
591
|
+
factService: new FactService(this.factStore, scopes),
|
|
592
|
+
privateEventStore: this.privateEventStore,
|
|
593
|
+
txResolver: this.stateMachine.txResolver,
|
|
594
|
+
contractSyncService: this.stateMachine.contractSyncService,
|
|
595
|
+
l2TipsStore: this.stateMachine.l2TipsProvider,
|
|
596
|
+
jobId: this.currentJobId,
|
|
597
|
+
scopes,
|
|
598
|
+
simulator,
|
|
599
|
+
utilityExecutor: this.utilityExecutorForContractSync(anchorBlock),
|
|
600
|
+
// Top-level utility entrypoint: gets a fresh store. Nested frames inherit it via UtilityExecutionOracle.
|
|
601
|
+
transientArrayService: new TransientArrayService()
|
|
602
|
+
});
|
|
603
|
+
await simulator.executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, buildACIRCallback(oracle)).catch((err)=>{
|
|
604
|
+
err.message = resolveAssertionMessageFromError(err, entryPointArtifact);
|
|
605
|
+
throw new ExecutionError(err.message, {
|
|
606
|
+
contractAddress: call.to,
|
|
607
|
+
functionSelector: call.selector
|
|
608
|
+
}, extractCallStack(err, entryPointArtifact.debug), {
|
|
609
|
+
cause: err
|
|
610
|
+
});
|
|
611
|
+
});
|
|
612
|
+
} catch (err) {
|
|
613
|
+
throw createSimulationError(err instanceof Error ? err : new Error('Unknown error contract data sync'));
|
|
614
|
+
}
|
|
615
|
+
};
|
|
616
|
+
}
|
|
253
617
|
}
|