@aztec/txe 0.0.1-commit.96dac018d → 0.0.1-commit.9a89641
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/AuthRegistry-QVGDDH5X.js +3 -0
- package/dest/AuthRegistry-QVGDDH5X.js.map +7 -0
- package/dest/ContractClassRegistry-PVNCKGG7.js +3 -0
- package/dest/ContractClassRegistry-PVNCKGG7.js.map +7 -0
- package/dest/ContractInstanceRegistry-WLOZKTR6.js +3 -0
- package/dest/ContractInstanceRegistry-WLOZKTR6.js.map +7 -0
- package/dest/FeeJuice-MAQJU53K.js +3 -0
- package/dest/FeeJuice-MAQJU53K.js.map +7 -0
- package/dest/HandshakeRegistry-GY5CPEPS.js +3 -0
- package/dest/HandshakeRegistry-GY5CPEPS.js.map +7 -0
- package/dest/MultiCallEntrypoint-QG5H33ZZ.js +3 -0
- package/dest/MultiCallEntrypoint-QG5H33ZZ.js.map +7 -0
- package/dest/SchnorrAccount-ADD65DYA.js +3 -0
- package/dest/SchnorrAccount-ADD65DYA.js.map +7 -0
- package/dest/SchnorrInitializerlessAccount-TWGKRUSY.js +3 -0
- package/dest/SchnorrInitializerlessAccount-TWGKRUSY.js.map +7 -0
- package/dest/bin/check_txe_oracle_version.d.ts +2 -0
- package/dest/bin/check_txe_oracle_version.d.ts.map +1 -0
- package/dest/bin/check_txe_oracle_version.js +22 -0
- package/dest/bin/index.js +3 -30
- package/dest/bin/index.js.map +7 -0
- package/dest/bin/oracle_test_server.d.ts +3 -0
- package/dest/bin/oracle_test_server.d.ts.map +1 -0
- package/dest/bin/oracle_test_server.js +41 -0
- package/dest/chunk-32UHX7YY.js +3 -0
- package/dest/chunk-32UHX7YY.js.map +7 -0
- package/dest/chunk-RVEPNDEP.js +304 -0
- package/dest/chunk-RVEPNDEP.js.map +7 -0
- package/dest/chunk-XWIMXLKD.js +258 -0
- package/dest/chunk-XWIMXLKD.js.map +7 -0
- package/dest/constants.d.ts +5 -1
- package/dest/constants.d.ts.map +1 -1
- package/dest/constants.js +9 -1
- package/dest/dispatcher_pool.d.ts +67 -0
- package/dest/dispatcher_pool.d.ts.map +1 -0
- package/dest/dispatcher_pool.js +286 -0
- package/dest/index.d.ts +51 -7
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +72 -188
- package/dest/metafile.json +38833 -0
- package/dest/msgpackr_fr_extension.d.ts +2 -0
- package/dest/msgpackr_fr_extension.d.ts.map +1 -0
- package/dest/msgpackr_fr_extension.js +21 -0
- package/dest/oracle/interfaces.d.ts +68 -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 +16 -0
- package/dest/oracle/test-resolver/default_fixtures.d.ts.map +1 -0
- package/dest/oracle/test-resolver/default_fixtures.js +200 -0
- package/dest/oracle/test-resolver/index.d.ts +9 -0
- package/dest/oracle/test-resolver/index.d.ts.map +1 -0
- package/dest/oracle/test-resolver/index.js +32 -0
- package/dest/oracle/test-resolver/resolver.d.ts +48 -0
- package/dest/oracle/test-resolver/resolver.d.ts.map +1 -0
- package/dest/oracle/test-resolver/resolver.js +181 -0
- package/dest/oracle/txe_oracle_public_context.d.ts +38 -14
- package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.js +61 -13
- package/dest/oracle/txe_oracle_registry.d.ts +172 -0
- package/dest/oracle/txe_oracle_registry.d.ts.map +1 -0
- package/dest/oracle/txe_oracle_registry.js +767 -0
- package/dest/oracle/txe_oracle_top_level_context.d.ts +68 -27
- package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_top_level_context.js +571 -312
- package/dest/oracle/txe_oracle_version.d.ts +17 -0
- package/dest/oracle/txe_oracle_version.d.ts.map +1 -0
- package/dest/oracle/txe_oracle_version.js +14 -0
- package/dest/oracle/txe_private_execution_oracle.d.ts +17 -0
- package/dest/oracle/txe_private_execution_oracle.d.ts.map +1 -0
- package/dest/oracle/txe_private_execution_oracle.js +15 -0
- package/dest/rpc_server.d.ts +14 -0
- package/dest/rpc_server.d.ts.map +1 -0
- package/dest/rpc_server.js +78 -0
- package/dest/rpc_translator.d.ts +116 -228
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +909 -636
- 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 +28 -20
- package/dest/state_machine/dummy_p2p_client.d.ts +16 -7
- package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
- package/dest/state_machine/dummy_p2p_client.js +25 -4
- package/dest/state_machine/global_variable_builder.d.ts +10 -6
- package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
- package/dest/state_machine/global_variable_builder.js +8 -5
- package/dest/state_machine/index.d.ts +11 -5
- package/dest/state_machine/index.d.ts.map +1 -1
- package/dest/state_machine/index.js +50 -10
- package/dest/state_machine/mock_epoch_cache.d.ts +17 -3
- package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
- package/dest/state_machine/mock_epoch_cache.js +32 -2
- package/dest/state_machine/synchronizer.d.ts +14 -6
- package/dest/state_machine/synchronizer.d.ts.map +1 -1
- package/dest/state_machine/synchronizer.js +22 -9
- package/dest/txe_session.d.ts +92 -19
- package/dest/txe_session.d.ts.map +1 -1
- package/dest/txe_session.js +325 -61
- package/dest/utils/block_creation.d.ts +2 -2
- package/dest/utils/block_creation.d.ts.map +1 -1
- package/dest/utils/block_creation.js +2 -2
- package/dest/utils/encoding.d.ts +194 -0
- package/dest/utils/encoding.d.ts.map +1 -0
- package/dest/{util → utils}/encoding.js +7 -2
- package/dest/{util → utils}/expected_failure_error.d.ts +1 -1
- package/dest/utils/expected_failure_error.d.ts.map +1 -0
- package/dest/utils/tx_effect_creation.d.ts +1 -1
- package/dest/utils/tx_effect_creation.d.ts.map +1 -1
- package/dest/utils/tx_effect_creation.js +0 -1
- package/dest/{util → utils}/txe_account_store.d.ts +1 -1
- package/dest/utils/txe_account_store.d.ts.map +1 -0
- package/dest/utils/txe_artifact_resolver.d.ts +37 -0
- package/dest/utils/txe_artifact_resolver.d.ts.map +1 -0
- package/dest/utils/txe_artifact_resolver.js +161 -0
- package/dest/utils/txe_public_contract_data_source.d.ts +20 -0
- package/dest/utils/txe_public_contract_data_source.d.ts.map +1 -0
- package/dest/{util → utils}/txe_public_contract_data_source.js +8 -7
- package/dest/worker.bundle.js +3 -0
- package/dest/worker.bundle.js.map +7 -0
- package/dest/worker.d.ts +2 -0
- package/dest/worker.d.ts.map +1 -0
- package/dest/worker.js +92 -0
- package/package.json +38 -21
- package/src/bin/check_txe_oracle_version.ts +31 -0
- package/src/bin/index.ts +11 -2
- package/src/bin/oracle_test_server.ts +51 -0
- package/src/constants.ts +11 -1
- package/src/dispatcher_pool.ts +317 -0
- package/src/index.ts +99 -224
- package/src/msgpackr_fr_extension.ts +23 -0
- package/src/oracle/interfaces.ts +70 -35
- package/src/oracle/tagging_secret_strategy.ts +25 -0
- package/src/oracle/test-resolver/default_fixtures.ts +271 -0
- package/src/oracle/test-resolver/index.ts +44 -0
- package/src/oracle/test-resolver/resolver.ts +245 -0
- package/src/oracle/txe_oracle_public_context.ts +74 -12
- package/src/oracle/txe_oracle_registry.ts +556 -0
- package/src/oracle/txe_oracle_top_level_context.ts +380 -128
- 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 +1126 -1021
- package/src/state_machine/archiver.ts +41 -20
- package/src/state_machine/dummy_p2p_client.ts +44 -11
- package/src/state_machine/global_variable_builder.ts +12 -11
- package/src/state_machine/index.ts +63 -28
- package/src/state_machine/mock_epoch_cache.ts +42 -3
- package/src/state_machine/synchronizer.ts +31 -10
- package/src/txe_session.ts +564 -75
- package/src/utils/block_creation.ts +2 -1
- package/src/{util → utils}/encoding.ts +8 -2
- package/src/utils/tx_effect_creation.ts +0 -2
- package/src/utils/txe_artifact_resolver.ts +217 -0
- package/src/{util → utils}/txe_public_contract_data_source.ts +6 -6
- 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_public_contract_data_source.d.ts +0 -20
- package/dest/util/txe_public_contract_data_source.d.ts.map +0 -1
- /package/dest/{util → utils}/expected_failure_error.js +0 -0
- /package/dest/{util → utils}/txe_account_store.js +0 -0
- /package/src/{util → utils}/expected_failure_error.ts +0 -0
- /package/src/{util → utils}/txe_account_store.ts +0 -0
package/dest/txe_session.js
CHANGED
|
@@ -2,31 +2,44 @@ import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
|
2
2
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
3
|
import { createLogger } from '@aztec/foundation/log';
|
|
4
4
|
import { KeyStore } from '@aztec/key-store';
|
|
5
|
-
import {
|
|
6
|
-
import { AddressStore, AnchorBlockStore, CapsuleStore, JobCoordinator, NoteService, NoteStore, PrivateEventStore, RecipientTaggingStore,
|
|
7
|
-
import { ExecutionNoteCache, ExecutionTaggingIndexCache, HashedValuesCache,
|
|
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
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';
|
|
9
10
|
import { FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
|
|
10
11
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
11
|
-
import { GasSettings } from '@aztec/stdlib/gas';
|
|
12
12
|
import { computeProtocolNullifier } from '@aztec/stdlib/hash';
|
|
13
13
|
import { makeGlobalVariables } from '@aztec/stdlib/testing';
|
|
14
|
-
import { CallContext, TxContext } from '@aztec/stdlib/tx';
|
|
14
|
+
import { CallContext, OFFCHAIN_MESSAGE_IDENTIFIER, TxContext } from '@aztec/stdlib/tx';
|
|
15
15
|
import { z } from 'zod';
|
|
16
|
-
import { DEFAULT_ADDRESS } from './constants.js';
|
|
16
|
+
import { DEFAULT_ADDRESS, MAX_OFFCHAIN_EFFECTS_PER_TXE_QUERY, MAX_OFFCHAIN_EFFECT_LEN } from './constants.js';
|
|
17
|
+
import { makeResolveTaggingSecretStrategyHook } from './oracle/tagging_secret_strategy.js';
|
|
17
18
|
import { TXEOraclePublicContext } from './oracle/txe_oracle_public_context.js';
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
19
|
+
import { callTxeLegacyHandler } from './oracle/txe_oracle_registry.js';
|
|
20
|
+
import { TXEOracleTopLevelContext, authorizeAllUtilityCallsHook } from './oracle/txe_oracle_top_level_context.js';
|
|
21
|
+
import { TXE_ORACLE_VERSION_MAJOR, TXE_ORACLE_VERSION_MINOR } from './oracle/txe_oracle_version.js';
|
|
22
|
+
import { TXEPrivateExecutionOracle } from './oracle/txe_private_execution_oracle.js';
|
|
23
|
+
import { RPCTranslator, UnavailableOracleError } from './rpc_translator.js';
|
|
20
24
|
import { TXEArchiver } from './state_machine/archiver.js';
|
|
21
25
|
import { TXEStateMachine } from './state_machine/index.js';
|
|
22
|
-
import { TXEAccountStore } from './util/txe_account_store.js';
|
|
23
26
|
import { getSingleTxBlockRequestHash, insertTxEffectIntoWorldTrees, makeTXEBlock } from './utils/block_creation.js';
|
|
24
27
|
import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
28
|
+
import { TXEAccountStore } from './utils/txe_account_store.js';
|
|
29
|
+
function emptyLastCallState() {
|
|
30
|
+
return {
|
|
31
|
+
offchainEffects: [],
|
|
32
|
+
queried: false,
|
|
33
|
+
txHash: Fr.ZERO,
|
|
34
|
+
anchorBlockTimestamp: 0n
|
|
35
|
+
};
|
|
36
|
+
}
|
|
25
37
|
/**
|
|
26
38
|
* A `TXESession` corresponds to a Noir `#[test]` function, and handles all of its oracle calls, stores test-specific
|
|
27
39
|
* state, etc., independent of all other tests running in parallel.
|
|
28
40
|
*/ export class TXESession {
|
|
29
41
|
logger;
|
|
42
|
+
sessionStore;
|
|
30
43
|
stateMachine;
|
|
31
44
|
oracleHandler;
|
|
32
45
|
contractStore;
|
|
@@ -36,18 +49,28 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
|
36
49
|
accountStore;
|
|
37
50
|
senderTaggingStore;
|
|
38
51
|
recipientTaggingStore;
|
|
39
|
-
|
|
52
|
+
taggingSecretSourcesStore;
|
|
40
53
|
capsuleStore;
|
|
54
|
+
factStore;
|
|
41
55
|
privateEventStore;
|
|
42
56
|
jobCoordinator;
|
|
43
57
|
currentJobId;
|
|
44
58
|
chainId;
|
|
45
59
|
version;
|
|
46
60
|
nextBlockTimestamp;
|
|
61
|
+
artifactResolver;
|
|
62
|
+
rootPath;
|
|
63
|
+
packageName;
|
|
47
64
|
state;
|
|
48
65
|
authwits;
|
|
49
|
-
|
|
66
|
+
taggingSecretStrategies;
|
|
67
|
+
authorizeAllUtilityCallTargets;
|
|
68
|
+
lastCallInfo;
|
|
69
|
+
txeOracleVersion;
|
|
70
|
+
disposed;
|
|
71
|
+
constructor(logger, sessionStore, stateMachine, oracleHandler, contractStore, noteStore, keyStore, addressStore, accountStore, senderTaggingStore, recipientTaggingStore, taggingSecretSourcesStore, capsuleStore, factStore, privateEventStore, jobCoordinator, currentJobId, chainId, version, nextBlockTimestamp, artifactResolver, rootPath, packageName){
|
|
50
72
|
this.logger = logger;
|
|
73
|
+
this.sessionStore = sessionStore;
|
|
51
74
|
this.stateMachine = stateMachine;
|
|
52
75
|
this.oracleHandler = oracleHandler;
|
|
53
76
|
this.contractStore = contractStore;
|
|
@@ -57,34 +80,74 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
|
57
80
|
this.accountStore = accountStore;
|
|
58
81
|
this.senderTaggingStore = senderTaggingStore;
|
|
59
82
|
this.recipientTaggingStore = recipientTaggingStore;
|
|
60
|
-
this.
|
|
83
|
+
this.taggingSecretSourcesStore = taggingSecretSourcesStore;
|
|
61
84
|
this.capsuleStore = capsuleStore;
|
|
85
|
+
this.factStore = factStore;
|
|
62
86
|
this.privateEventStore = privateEventStore;
|
|
63
87
|
this.jobCoordinator = jobCoordinator;
|
|
64
88
|
this.currentJobId = currentJobId;
|
|
65
89
|
this.chainId = chainId;
|
|
66
90
|
this.version = version;
|
|
67
91
|
this.nextBlockTimestamp = nextBlockTimestamp;
|
|
92
|
+
this.artifactResolver = artifactResolver;
|
|
93
|
+
this.rootPath = rootPath;
|
|
94
|
+
this.packageName = packageName;
|
|
68
95
|
this.state = {
|
|
69
96
|
name: 'TOP_LEVEL'
|
|
70
97
|
};
|
|
71
98
|
this.authwits = new Map();
|
|
99
|
+
this.taggingSecretStrategies = new Map();
|
|
100
|
+
this.authorizeAllUtilityCallTargets = false;
|
|
101
|
+
this.lastCallInfo = emptyLastCallState();
|
|
102
|
+
this.disposed = false;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Tears down the per-session AVM simulator (process pool + CDB server), the `NativeWorldStateService`,
|
|
106
|
+
* and the `txe-session` LMDB. Called via IPC when the dispatcher detects the end of a test. Idempotent.
|
|
107
|
+
*/ async dispose() {
|
|
108
|
+
if (this.disposed) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
this.disposed = true;
|
|
112
|
+
// Dispose the AVM pool before the world state: it kills the bb-avm-sim processes so they release their
|
|
113
|
+
// connection to the WSDB server, letting it shut down cleanly. Skipping this leaks a bb-avm-sim process
|
|
114
|
+
// (and keeps its WSDB alive) per session.
|
|
115
|
+
try {
|
|
116
|
+
await this.stateMachine.synchronizer.closeIpc();
|
|
117
|
+
} catch (err) {
|
|
118
|
+
this.logger.warn(`Error closing AVM simulator during session dispose`, err);
|
|
119
|
+
}
|
|
120
|
+
try {
|
|
121
|
+
await this.stateMachine.synchronizer.nativeWorldStateService.close();
|
|
122
|
+
} catch (err) {
|
|
123
|
+
this.logger.warn(`Error closing native world state during session dispose`, err);
|
|
124
|
+
}
|
|
125
|
+
try {
|
|
126
|
+
await this.sessionStore.close();
|
|
127
|
+
} catch (err) {
|
|
128
|
+
this.logger.warn(`Error closing session LMDB during dispose`, err);
|
|
129
|
+
}
|
|
72
130
|
}
|
|
73
|
-
static async init(contractStore) {
|
|
74
|
-
|
|
131
|
+
static async init(contractStore, artifactResolver, rootPath, packageName) {
|
|
132
|
+
// Size LMDB's reader slots to the libuv pool (capped to 2 in bin/index.ts via
|
|
133
|
+
// HARDWARE_CONCURRENCY): each native LMDB read needs a libuv worker thread to run, so any
|
|
134
|
+
// slot beyond the pool size would sit idle while still consuming a semaphore + reader-table
|
|
135
|
+
// entry per session.
|
|
136
|
+
const store = await openEphemeralStore('txe-session', undefined, 2);
|
|
75
137
|
const addressStore = new AddressStore(store);
|
|
76
138
|
const privateEventStore = new PrivateEventStore(store);
|
|
77
139
|
const noteStore = new NoteStore(store);
|
|
78
140
|
const senderTaggingStore = new SenderTaggingStore(store);
|
|
79
141
|
const recipientTaggingStore = new RecipientTaggingStore(store);
|
|
80
|
-
const
|
|
142
|
+
const taggingSecretSourcesStore = new TaggingSecretSourcesStore(store);
|
|
81
143
|
const capsuleStore = new CapsuleStore(store);
|
|
144
|
+
const factStore = new FactStore(store);
|
|
82
145
|
const keyStore = new KeyStore(store);
|
|
83
146
|
const accountStore = new TXEAccountStore(store);
|
|
84
|
-
// Create job coordinator and register staged stores
|
|
85
147
|
const jobCoordinator = new JobCoordinator(store);
|
|
86
148
|
jobCoordinator.registerStores([
|
|
87
149
|
capsuleStore,
|
|
150
|
+
factStore,
|
|
88
151
|
senderTaggingStore,
|
|
89
152
|
recipientTaggingStore,
|
|
90
153
|
privateEventStore,
|
|
@@ -97,9 +160,12 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
|
97
160
|
const version = new Fr(await stateMachine.node.getVersion());
|
|
98
161
|
const chainId = new Fr(await stateMachine.node.getChainId());
|
|
99
162
|
const initialJobId = jobCoordinator.beginJob();
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
163
|
+
const logger = createLogger('txe:session');
|
|
164
|
+
const topLevelOracleHandler = new TXEOracleTopLevelContext(stateMachine, contractStore, noteStore, keyStore, addressStore, accountStore, senderTaggingStore, recipientTaggingStore, taggingSecretSourcesStore, capsuleStore, factStore, privateEventStore, nextBlockTimestamp, version, chainId, new Map(), new Map(), false, artifactResolver, rootPath, packageName);
|
|
165
|
+
await topLevelOracleHandler.mineDeploymentNullifiers([
|
|
166
|
+
STANDARD_AUTH_REGISTRY_ADDRESS
|
|
167
|
+
]);
|
|
168
|
+
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);
|
|
103
169
|
}
|
|
104
170
|
/**
|
|
105
171
|
* Processes an oracle function invoked by the Noir test associated to this session.
|
|
@@ -108,13 +174,28 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
|
108
174
|
* @returns The oracle return values.
|
|
109
175
|
*/ processFunction(functionName, inputs) {
|
|
110
176
|
try {
|
|
177
|
+
// Oracles retired into the PXE legacy registry have no translator method; dispatch them through the same
|
|
178
|
+
// buildACIRCallback legacy path that contract execution uses, keeping TXE's two oracle paths in sync.
|
|
179
|
+
// Use an own-property check: `in` would match inherited `Object.prototype` keys (e.g. `constructor`), routing
|
|
180
|
+
// them into the legacy path instead of letting them fall through to the unknown-oracle error.
|
|
181
|
+
if (Object.hasOwn(LEGACY_ORACLE_REGISTRY, functionName)) {
|
|
182
|
+
return callTxeLegacyHandler(functionName, inputs, this.oracleHandler);
|
|
183
|
+
}
|
|
111
184
|
const translator = new RPCTranslator(this, this.oracleHandler);
|
|
112
185
|
// We perform a runtime validation to check that the function name corresponds to a real oracle handler.
|
|
113
186
|
const validatedFunctionName = z.string().refine((fn)=>typeof translator[fn] === 'function' && !fn.startsWith('handlerAs') && fn !== 'constructor').parse(functionName);
|
|
114
187
|
return translator[validatedFunctionName](...inputs);
|
|
115
188
|
} catch (error) {
|
|
116
189
|
if (error instanceof z.ZodError) {
|
|
117
|
-
|
|
190
|
+
let versionHint;
|
|
191
|
+
if (!this.txeOracleVersion) {
|
|
192
|
+
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';
|
|
193
|
+
} else if (this.txeOracleVersion.minor > TXE_ORACLE_VERSION_MINOR) {
|
|
194
|
+
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`;
|
|
195
|
+
} else {
|
|
196
|
+
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`;
|
|
197
|
+
}
|
|
198
|
+
throw new Error(`Unknown oracle '${functionName}'.${versionHint}`);
|
|
118
199
|
} else if (error instanceof Error) {
|
|
119
200
|
throw new Error(`Execution error while processing function ${functionName} in state ${this.state.name}: ${error.message}`);
|
|
120
201
|
} else {
|
|
@@ -122,14 +203,132 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
|
122
203
|
}
|
|
123
204
|
}
|
|
124
205
|
}
|
|
125
|
-
getCurrentJob() {
|
|
126
|
-
return this.currentJobId;
|
|
127
|
-
}
|
|
128
206
|
/** Commits the current job and begins a new one. Returns the new job ID. */ async cycleJob() {
|
|
129
207
|
await this.jobCoordinator.commitJob(this.currentJobId);
|
|
130
208
|
this.currentJobId = this.jobCoordinator.beginJob();
|
|
131
209
|
return this.currentJobId;
|
|
132
210
|
}
|
|
211
|
+
resetLastCall() {
|
|
212
|
+
const notQueriedMessageCount = this.lastCallInfo.queried ? 0 : this.lastCallInfo.offchainEffects.filter((payload)=>payload[0]?.equals(OFFCHAIN_MESSAGE_IDENTIFIER)).length;
|
|
213
|
+
if (notQueriedMessageCount > 0) {
|
|
214
|
+
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.`);
|
|
215
|
+
}
|
|
216
|
+
this.lastCallInfo = emptyLastCallState();
|
|
217
|
+
}
|
|
218
|
+
recordOffchainEffect(data) {
|
|
219
|
+
this.lastCallInfo.offchainEffects.push(data);
|
|
220
|
+
}
|
|
221
|
+
setLastCallContext(txHash, anchorBlockTimestamp) {
|
|
222
|
+
this.lastCallInfo.txHash = txHash;
|
|
223
|
+
this.lastCallInfo.anchorBlockTimestamp = anchorBlockTimestamp;
|
|
224
|
+
}
|
|
225
|
+
async withTopLevelCallTracking(work) {
|
|
226
|
+
this.resetLastCall();
|
|
227
|
+
// Capture the anchor *before* `work` runs: private/public executor calls mine a new block as a
|
|
228
|
+
// side effect, and that block's timestamp should not be attributed to this call's anchor.
|
|
229
|
+
const anchorBlockTimestamp = (await this.stateMachine.node.getBlockData('latest')).header.globalVariables.timestamp;
|
|
230
|
+
const { result, txHash } = await work();
|
|
231
|
+
this.setLastCallContext(txHash ?? Fr.ZERO, anchorBlockTimestamp);
|
|
232
|
+
return result;
|
|
233
|
+
}
|
|
234
|
+
getLastCallOffchainEffects() {
|
|
235
|
+
this.lastCallInfo.queried = true;
|
|
236
|
+
const effects = this.lastCallInfo.offchainEffects;
|
|
237
|
+
if (effects.length > MAX_OFFCHAIN_EFFECTS_PER_TXE_QUERY) {
|
|
238
|
+
throw new Error(`${effects.length} offchain effects exceed max ${MAX_OFFCHAIN_EFFECTS_PER_TXE_QUERY}`);
|
|
239
|
+
}
|
|
240
|
+
if (effects.some((e)=>e.length > MAX_OFFCHAIN_EFFECT_LEN)) {
|
|
241
|
+
throw new Error(`Some offchain effect has length larger than max ${MAX_OFFCHAIN_EFFECT_LEN}`);
|
|
242
|
+
}
|
|
243
|
+
return {
|
|
244
|
+
effects
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
getLastCallContext() {
|
|
248
|
+
const { txHash, anchorBlockTimestamp } = this.lastCallInfo;
|
|
249
|
+
return {
|
|
250
|
+
txHash,
|
|
251
|
+
anchorBlockTimestamp
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
async executePrivateCall(from, targetContractAddress, functionSelector, args, argsHash, isStaticCall, additionalScopes, authorizedUtilityCallTargets, gasSettings) {
|
|
255
|
+
const handler = this.handlerAsTxe();
|
|
256
|
+
return await this.withTopLevelCallTracking(async ()=>{
|
|
257
|
+
const { returnValues, offchainEffects } = await handler.privateCallNewFlow(from?.value, targetContractAddress, functionSelector, args, argsHash, isStaticCall, additionalScopes, this.currentJobId, authorizedUtilityCallTargets, gasSettings);
|
|
258
|
+
// Private execution collects offchain effects inside PXE's PrivateExecutionOracle rather than round-tripping
|
|
259
|
+
// them through `aztec_utl_emitOffchainEffect`, so the session buffer is empty at this point. Drain the effects
|
|
260
|
+
// from the execution tree into the session buffer so the next `env.offchain_messages()` call in the test sees
|
|
261
|
+
// them.
|
|
262
|
+
for (const data of offchainEffects){
|
|
263
|
+
this.recordOffchainEffect(data);
|
|
264
|
+
}
|
|
265
|
+
await this.cycleJob();
|
|
266
|
+
if (isStaticCall) {
|
|
267
|
+
// Static calls revert their checkpoint and mine no block, so there is no tx hash to tag offchain effects
|
|
268
|
+
// with. Querying `getLastTxEffects()` here would return an unrelated predecessor tx.
|
|
269
|
+
return {
|
|
270
|
+
result: returnValues
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
const { txHash } = await handler.getLastTxEffects();
|
|
274
|
+
return {
|
|
275
|
+
result: returnValues,
|
|
276
|
+
txHash: txHash.hash
|
|
277
|
+
};
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
async executeUtilityFunction(from, targetContractAddress, functionSelector, args, authorizedUtilityCallTargets) {
|
|
281
|
+
const handler = this.handlerAsTxe();
|
|
282
|
+
return await this.withTopLevelCallTracking(async ()=>{
|
|
283
|
+
const returnValues = await handler.executeUtilityFunction(from?.value, targetContractAddress, functionSelector, args, this.currentJobId, authorizedUtilityCallTargets);
|
|
284
|
+
await this.cycleJob();
|
|
285
|
+
return {
|
|
286
|
+
result: returnValues
|
|
287
|
+
};
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
async executePublicCall(from, targetContractAddress, calldata, isStaticCall, gasSettings) {
|
|
291
|
+
const handler = this.handlerAsTxe();
|
|
292
|
+
return await this.withTopLevelCallTracking(async ()=>{
|
|
293
|
+
const returnValues = await handler.publicCallNewFlow(from?.value, targetContractAddress, calldata, isStaticCall, gasSettings);
|
|
294
|
+
await this.cycleJob();
|
|
295
|
+
if (isStaticCall) {
|
|
296
|
+
// See the equivalent branch in `executePrivateCall`.
|
|
297
|
+
return {
|
|
298
|
+
result: returnValues
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
const { txHash } = await handler.getLastTxEffects();
|
|
302
|
+
return {
|
|
303
|
+
result: returnValues,
|
|
304
|
+
txHash: txHash.hash
|
|
305
|
+
};
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
async getPrivateEvents(selector, contractAddress, scope) {
|
|
309
|
+
const handler = this.handlerAsTxe();
|
|
310
|
+
await handler.syncContractNonOracleMethod(contractAddress, scope, this.currentJobId);
|
|
311
|
+
// Cycle the job to commit the stores after the contract sync.
|
|
312
|
+
await this.cycleJob();
|
|
313
|
+
return handler.getPrivateEvents(selector, contractAddress, scope);
|
|
314
|
+
}
|
|
315
|
+
handlerAsTxe() {
|
|
316
|
+
if (!('isTxe' in this.oracleHandler)) {
|
|
317
|
+
throw new UnavailableOracleError('Txe');
|
|
318
|
+
}
|
|
319
|
+
return this.oracleHandler;
|
|
320
|
+
}
|
|
321
|
+
setTxeOracleVersion(major, minor) {
|
|
322
|
+
if (major !== TXE_ORACLE_VERSION_MAJOR) {
|
|
323
|
+
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.';
|
|
324
|
+
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})`);
|
|
325
|
+
}
|
|
326
|
+
this.txeOracleVersion = {
|
|
327
|
+
major,
|
|
328
|
+
minor
|
|
329
|
+
};
|
|
330
|
+
this.logger.debug(`Test compiled with test oracle version ${major}.${minor}`);
|
|
331
|
+
}
|
|
133
332
|
async enterTopLevelState() {
|
|
134
333
|
switch(this.state.name){
|
|
135
334
|
case 'PRIVATE':
|
|
@@ -158,20 +357,23 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
|
158
357
|
}
|
|
159
358
|
// Commit all staged stores from the job that was just completed, then begin a new job
|
|
160
359
|
await this.cycleJob();
|
|
161
|
-
this.oracleHandler = new TXEOracleTopLevelContext(this.stateMachine, this.contractStore, this.noteStore, this.keyStore, this.addressStore, this.accountStore, this.senderTaggingStore, this.recipientTaggingStore, this.
|
|
360
|
+
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.taggingSecretStrategies, this.authorizeAllUtilityCallTargets, this.artifactResolver, this.rootPath, this.packageName);
|
|
162
361
|
this.state = {
|
|
163
362
|
name: 'TOP_LEVEL'
|
|
164
363
|
};
|
|
165
364
|
this.logger.debug(`Entered state ${this.state.name}`);
|
|
166
365
|
}
|
|
167
|
-
async enterPrivateState(
|
|
366
|
+
async enterPrivateState(contractAddressOpt, anchorBlockNumberOpt, gasSettings) {
|
|
367
|
+
const contractAddress = contractAddressOpt?.value ?? DEFAULT_ADDRESS;
|
|
368
|
+
const anchorBlockNumber = anchorBlockNumberOpt?.value;
|
|
168
369
|
this.exitTopLevelState();
|
|
370
|
+
this.resetLastCall();
|
|
169
371
|
// Private execution has two associated block numbers: the anchor block (i.e. the historical block that is used to
|
|
170
372
|
// build the proof), and the *next* block, i.e. the one we'll create once the execution ends, and which will contain
|
|
171
373
|
// a single transaction with the effects of what was done in the test.
|
|
172
|
-
const anchorBlock = await this.stateMachine.node.
|
|
173
|
-
await new NoteService(this.noteStore, this.stateMachine.node, anchorBlock, this.currentJobId).syncNoteNullifiers(contractAddress,
|
|
174
|
-
const latestBlock = await this.stateMachine.node.
|
|
374
|
+
const anchorBlock = await this.stateMachine.node.getBlock(anchorBlockNumber ?? 'latest').then((b)=>b?.header);
|
|
375
|
+
await new NoteService(this.noteStore, this.stateMachine.node, anchorBlock, this.currentJobId).syncNoteNullifiers(contractAddress, await this.keyStore.getAccounts());
|
|
376
|
+
const latestBlock = await this.stateMachine.node.getBlock('latest').then((b)=>b?.header);
|
|
175
377
|
const nextBlockGlobalVariables = makeGlobalVariables(undefined, {
|
|
176
378
|
blockNumber: BlockNumber(latestBlock.globalVariables.blockNumber + 1),
|
|
177
379
|
timestamp: this.nextBlockTimestamp,
|
|
@@ -183,9 +385,12 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
|
183
385
|
const noteCache = new ExecutionNoteCache(protocolNullifier);
|
|
184
386
|
const taggingIndexCache = new ExecutionTaggingIndexCache();
|
|
185
387
|
const utilityExecutor = this.utilityExecutorForContractSync(anchorBlock);
|
|
186
|
-
|
|
388
|
+
const transientArrayService = new TransientArrayService();
|
|
389
|
+
const anchoredContractData = new AnchoredContractData(this.contractStore, this.stateMachine.contractClassService, anchorBlock);
|
|
390
|
+
this.oracleHandler = new TXEPrivateExecutionOracle({
|
|
187
391
|
argsHash: Fr.ZERO,
|
|
188
|
-
txContext: new TxContext(this.chainId, this.version,
|
|
392
|
+
txContext: new TxContext(this.chainId, this.version, gasSettings),
|
|
393
|
+
txRequestSalt: Fr.ZERO,
|
|
189
394
|
callContext: new CallContext(AztecAddress.ZERO, contractAddress, FunctionSelector.empty(), false),
|
|
190
395
|
anchorBlockHeader: anchorBlock,
|
|
191
396
|
utilityExecutor,
|
|
@@ -194,19 +399,25 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
|
194
399
|
executionCache: new HashedValuesCache(),
|
|
195
400
|
noteCache,
|
|
196
401
|
taggingIndexCache,
|
|
197
|
-
|
|
402
|
+
anchoredContractData,
|
|
198
403
|
noteStore: this.noteStore,
|
|
199
404
|
keyStore: this.keyStore,
|
|
200
405
|
addressStore: this.addressStore,
|
|
201
406
|
aztecNode: this.stateMachine.node,
|
|
202
407
|
senderTaggingStore: this.senderTaggingStore,
|
|
203
408
|
recipientTaggingStore: this.recipientTaggingStore,
|
|
204
|
-
|
|
205
|
-
|
|
409
|
+
taggingSecretSourcesStore: this.taggingSecretSourcesStore,
|
|
410
|
+
capsuleService: new CapsuleService(this.capsuleStore, await this.keyStore.getAccounts()),
|
|
411
|
+
factService: new FactService(this.factStore, await this.keyStore.getAccounts()),
|
|
206
412
|
privateEventStore: this.privateEventStore,
|
|
207
413
|
contractSyncService: this.stateMachine.contractSyncService,
|
|
414
|
+
l2TipsStore: this.stateMachine.l2TipsProvider,
|
|
208
415
|
jobId: this.currentJobId,
|
|
209
|
-
scopes:
|
|
416
|
+
scopes: await this.keyStore.getAccounts(),
|
|
417
|
+
txResolver: this.stateMachine.txResolver,
|
|
418
|
+
simulator: new WASMSimulator(),
|
|
419
|
+
hooks: this.buildExecutionHooks(),
|
|
420
|
+
transientArrayService
|
|
210
421
|
});
|
|
211
422
|
// We store the note and tagging index caches fed into the PrivateExecutionOracle (along with some other auxiliary
|
|
212
423
|
// data) in order to refer to it later, mimicking the way this object is used by the ContractFunctionSimulator. The
|
|
@@ -220,70 +431,98 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
|
220
431
|
taggingIndexCache
|
|
221
432
|
};
|
|
222
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);
|
|
223
437
|
return this.oracleHandler.getPrivateContextInputs();
|
|
224
438
|
}
|
|
225
|
-
async enterPublicState(
|
|
439
|
+
async enterPublicState(contractAddressOpt) {
|
|
440
|
+
const contractAddress = contractAddressOpt?.value ?? DEFAULT_ADDRESS;
|
|
226
441
|
this.exitTopLevelState();
|
|
442
|
+
this.resetLastCall();
|
|
227
443
|
// The PublicContext will create a block with a single transaction in it, containing the effects of what was done in
|
|
228
444
|
// the test. The block therefore gets the *next* block number and timestamp.
|
|
229
|
-
const
|
|
445
|
+
const latestHeader = (await this.stateMachine.node.getBlockData('latest')).header;
|
|
230
446
|
const globalVariables = makeGlobalVariables(undefined, {
|
|
231
|
-
blockNumber: BlockNumber(
|
|
447
|
+
blockNumber: BlockNumber(latestHeader.globalVariables.blockNumber + 1),
|
|
232
448
|
timestamp: this.nextBlockTimestamp,
|
|
233
449
|
version: this.version,
|
|
234
450
|
chainId: this.chainId
|
|
235
451
|
});
|
|
236
|
-
this.oracleHandler = new TXEOraclePublicContext(contractAddress
|
|
452
|
+
this.oracleHandler = new TXEOraclePublicContext(contractAddress, await this.stateMachine.synchronizer.nativeWorldStateService.fork(), getSingleTxBlockRequestHash(globalVariables.blockNumber), globalVariables, this.contractStore);
|
|
237
453
|
this.state = {
|
|
238
454
|
name: 'PUBLIC'
|
|
239
455
|
};
|
|
240
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);
|
|
241
459
|
}
|
|
242
|
-
async enterUtilityState(
|
|
460
|
+
async enterUtilityState(contractAddressOpt) {
|
|
461
|
+
const contractAddress = contractAddressOpt?.value ?? DEFAULT_ADDRESS;
|
|
243
462
|
this.exitTopLevelState();
|
|
463
|
+
this.resetLastCall();
|
|
244
464
|
const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
245
465
|
// There is no automatic message discovery and contract-driven syncing process in inlined private or utility
|
|
246
466
|
// contexts, which means that known nullifiers are also not searched for, since it is during the tagging sync that
|
|
247
467
|
// we perform this. We therefore search for known nullifiers now, as otherwise notes that were nullified would not
|
|
248
468
|
// be removed from the database.
|
|
249
469
|
// TODO(#12553): make the synchronizer sync here instead and remove this
|
|
250
|
-
await new NoteService(this.noteStore, this.stateMachine.node, anchorBlockHeader, this.currentJobId).syncNoteNullifiers(contractAddress,
|
|
470
|
+
await new NoteService(this.noteStore, this.stateMachine.node, anchorBlockHeader, this.currentJobId).syncNoteNullifiers(contractAddress, await this.keyStore.getAccounts());
|
|
251
471
|
this.oracleHandler = new UtilityExecutionOracle({
|
|
252
|
-
|
|
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
|
+
}),
|
|
253
479
|
authWitnesses: [],
|
|
254
480
|
capsules: [],
|
|
255
481
|
anchorBlockHeader,
|
|
256
|
-
|
|
482
|
+
anchoredContractData: new AnchoredContractData(this.contractStore, this.stateMachine.contractClassService, anchorBlockHeader),
|
|
257
483
|
noteStore: this.noteStore,
|
|
258
484
|
keyStore: this.keyStore,
|
|
259
485
|
addressStore: this.addressStore,
|
|
260
486
|
aztecNode: this.stateMachine.node,
|
|
261
487
|
recipientTaggingStore: this.recipientTaggingStore,
|
|
262
|
-
|
|
263
|
-
|
|
488
|
+
taggingSecretSourcesStore: this.taggingSecretSourcesStore,
|
|
489
|
+
capsuleService: new CapsuleService(this.capsuleStore, await this.keyStore.getAccounts()),
|
|
490
|
+
factService: new FactService(this.factStore, await this.keyStore.getAccounts()),
|
|
264
491
|
privateEventStore: this.privateEventStore,
|
|
492
|
+
txResolver: this.stateMachine.txResolver,
|
|
493
|
+
contractSyncService: this.stateMachine.contractSyncService,
|
|
494
|
+
l2TipsStore: this.stateMachine.l2TipsProvider,
|
|
265
495
|
jobId: this.currentJobId,
|
|
266
|
-
scopes:
|
|
496
|
+
scopes: await this.keyStore.getAccounts(),
|
|
497
|
+
simulator: new WASMSimulator(),
|
|
498
|
+
utilityExecutor: this.utilityExecutorForContractSync(anchorBlockHeader),
|
|
499
|
+
hooks: this.buildExecutionHooks(),
|
|
500
|
+
// Execution-tree root (top-level utility run): own store; nested frames inherit it.
|
|
501
|
+
transientArrayService: new TransientArrayService()
|
|
267
502
|
});
|
|
268
503
|
this.state = {
|
|
269
504
|
name: 'UTILITY'
|
|
270
505
|
};
|
|
271
506
|
this.logger.debug(`Entered state ${this.state.name}`);
|
|
507
|
+
// Utility state anchors at whatever the anchor block store is pointing to (tracked as latest).
|
|
508
|
+
this.setLastCallContext(Fr.ZERO, anchorBlockHeader.globalVariables.timestamp);
|
|
272
509
|
}
|
|
273
510
|
exitTopLevelState() {
|
|
274
511
|
if (this.state.name != 'TOP_LEVEL') {
|
|
275
512
|
throw new Error(`Expected to be in state 'TOP_LEVEL', but got '${this.state.name}' instead`);
|
|
276
513
|
}
|
|
277
514
|
// Note that while all public and private contexts do is build a single block that we then process when exiting
|
|
278
|
-
//
|
|
279
|
-
//
|
|
280
|
-
//
|
|
281
|
-
//
|
|
282
|
-
//
|
|
283
|
-
//
|
|
284
|
-
// the
|
|
285
|
-
//
|
|
286
|
-
|
|
515
|
+
// them, the top level context does most of its work as it goes: it creates empty blocks (via `advanceBlocksBy`
|
|
516
|
+
// and `deploy`), creates blocks with transactions (via `privateCallNewFlow` and `publicCallNewFlow`), adds
|
|
517
|
+
// accounts to PXE (via `addAccount`), etc. This is a slight inconsistency in the working model of this class, but
|
|
518
|
+
// is not too bad. The `close` call below therefore only hands back the session-scoped values that a test
|
|
519
|
+
// sets directly at the top level, outside any contract execution (e.g. via `advanceTimestampBy`,
|
|
520
|
+
// `addAuthWitness`, `setTaggingSecretStrategies`). The oracle handler is discarded on every state transition,
|
|
521
|
+
// so the session must seed these values into the contexts it creates later.
|
|
522
|
+
// TODO: persisting authwits this way is quite unfortunate: they create a temporary utility context that would
|
|
523
|
+
// otherwise reset them, so we'd not be able to pass more than one per execution. Ideally authwits would be passed
|
|
524
|
+
// alongside a contract call instead of pre-seeded.
|
|
525
|
+
({ nextBlockTimestamp: this.nextBlockTimestamp, authwits: this.authwits, taggingSecretStrategies: this.taggingSecretStrategies, authorizeAllUtilityCallTargets: this.authorizeAllUtilityCallTargets } = this.oracleHandler.close());
|
|
287
526
|
}
|
|
288
527
|
async exitPrivateState() {
|
|
289
528
|
if (this.state.name != 'PRIVATE') {
|
|
@@ -322,29 +561,48 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
|
322
561
|
}
|
|
323
562
|
utilityExecutorForContractSync(anchorBlock) {
|
|
324
563
|
return async (call, scopes)=>{
|
|
325
|
-
const
|
|
564
|
+
const anchoredContractData = new AnchoredContractData(this.contractStore, this.stateMachine.contractClassService, anchorBlock);
|
|
565
|
+
const entryPointArtifact = await anchoredContractData.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
|
|
566
|
+
if (!entryPointArtifact) {
|
|
567
|
+
throw new Error(`Cannot run function ${call.selector} on ${call.to}: the contract is not registered.`);
|
|
568
|
+
}
|
|
326
569
|
if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
|
|
327
570
|
throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
|
|
328
571
|
}
|
|
329
572
|
try {
|
|
573
|
+
const simulator = new WASMSimulator();
|
|
330
574
|
const oracle = new UtilityExecutionOracle({
|
|
331
|
-
|
|
575
|
+
callContext: CallContext.from({
|
|
576
|
+
msgSender: AztecAddress.NULL_MSG_SENDER,
|
|
577
|
+
contractAddress: call.to,
|
|
578
|
+
functionSelector: call.selector,
|
|
579
|
+
isStaticCall: true
|
|
580
|
+
}),
|
|
332
581
|
authWitnesses: [],
|
|
333
582
|
capsules: [],
|
|
334
583
|
anchorBlockHeader: anchorBlock,
|
|
335
|
-
|
|
584
|
+
anchoredContractData,
|
|
336
585
|
noteStore: this.noteStore,
|
|
337
586
|
keyStore: this.keyStore,
|
|
338
587
|
addressStore: this.addressStore,
|
|
339
588
|
aztecNode: this.stateMachine.node,
|
|
340
589
|
recipientTaggingStore: this.recipientTaggingStore,
|
|
341
|
-
|
|
342
|
-
|
|
590
|
+
taggingSecretSourcesStore: this.taggingSecretSourcesStore,
|
|
591
|
+
capsuleService: new CapsuleService(this.capsuleStore, scopes),
|
|
592
|
+
factService: new FactService(this.factStore, scopes),
|
|
343
593
|
privateEventStore: this.privateEventStore,
|
|
594
|
+
txResolver: this.stateMachine.txResolver,
|
|
595
|
+
contractSyncService: this.stateMachine.contractSyncService,
|
|
596
|
+
l2TipsStore: this.stateMachine.l2TipsProvider,
|
|
344
597
|
jobId: this.currentJobId,
|
|
345
|
-
scopes
|
|
598
|
+
scopes,
|
|
599
|
+
simulator,
|
|
600
|
+
utilityExecutor: this.utilityExecutorForContractSync(anchorBlock),
|
|
601
|
+
hooks: this.buildExecutionHooks(),
|
|
602
|
+
// Top-level utility entrypoint: gets a fresh store. Nested frames inherit it via UtilityExecutionOracle.
|
|
603
|
+
transientArrayService: new TransientArrayService()
|
|
346
604
|
});
|
|
347
|
-
await
|
|
605
|
+
await simulator.executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, buildACIRCallback(oracle)).catch((err)=>{
|
|
348
606
|
err.message = resolveAssertionMessageFromError(err, entryPointArtifact);
|
|
349
607
|
throw new ExecutionError(err.message, {
|
|
350
608
|
contractAddress: call.to,
|
|
@@ -358,4 +616,10 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
|
358
616
|
}
|
|
359
617
|
};
|
|
360
618
|
}
|
|
619
|
+
/** Execution hooks for the oracles this session builds. Every oracle construction site must use this. */ buildExecutionHooks() {
|
|
620
|
+
return composeHooks({
|
|
621
|
+
resolveTaggingSecretStrategy: makeResolveTaggingSecretStrategyHook(this.taggingSecretStrategies),
|
|
622
|
+
authorizeUtilityCall: this.authorizeAllUtilityCallTargets ? authorizeAllUtilityCallsHook : undefined
|
|
623
|
+
});
|
|
624
|
+
}
|
|
361
625
|
}
|
|
@@ -9,7 +9,7 @@ import { BlockHeader, GlobalVariables, TxEffect } from '@aztec/stdlib/tx';
|
|
|
9
9
|
* @returns The transaction request hash.
|
|
10
10
|
*/
|
|
11
11
|
export declare function getSingleTxBlockRequestHash(blockNumber: BlockNumber): Fr;
|
|
12
|
-
export declare function insertTxEffectIntoWorldTrees(txEffect: TxEffect, worldTrees: MerkleTreeWriteOperations): Promise<void>;
|
|
12
|
+
export declare function insertTxEffectIntoWorldTrees(txEffect: TxEffect, worldTrees: MerkleTreeWriteOperations, l1ToL2Messages?: Fr[]): Promise<void>;
|
|
13
13
|
export declare function makeTXEBlockHeader(worldTrees: MerkleTreeWriteOperations, globalVariables: GlobalVariables): Promise<BlockHeader>;
|
|
14
14
|
/**
|
|
15
15
|
* Creates an L2Block with proper archive chaining.
|
|
@@ -25,4 +25,4 @@ export declare function makeTXEBlockHeader(worldTrees: MerkleTreeWriteOperations
|
|
|
25
25
|
* @returns The created L2Block with proper archive chaining
|
|
26
26
|
*/
|
|
27
27
|
export declare function makeTXEBlock(worldTrees: MerkleTreeWriteOperations, globalVariables: GlobalVariables, txEffects: TxEffect[]): Promise<L2Block>;
|
|
28
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
28
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYmxvY2tfY3JlYXRpb24uZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy91dGlscy9ibG9ja19jcmVhdGlvbi50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFNQSxPQUFPLEVBQUUsV0FBVyxFQUEyQyxNQUFNLGlDQUFpQyxDQUFDO0FBRXZHLE9BQU8sRUFBRSxFQUFFLEVBQUUsTUFBTSxnQ0FBZ0MsQ0FBQztBQUNwRCxPQUFPLEVBQVEsT0FBTyxFQUFFLE1BQU0scUJBQXFCLENBQUM7QUFDcEQsT0FBTyxFQUF3QyxLQUFLLHlCQUF5QixFQUFFLE1BQU0scUJBQXFCLENBQUM7QUFDM0csT0FBTyxFQUFFLFdBQVcsRUFBRSxlQUFlLEVBQUUsUUFBUSxFQUFFLE1BQU0sa0JBQWtCLENBQUM7QUFFMUU7Ozs7R0FJRztBQUNILHdCQUFnQiwyQkFBMkIsQ0FBQyxXQUFXLEVBQUUsV0FBVyxHQUFHLEVBQUUsQ0FFeEU7QUFFRCx3QkFBc0IsNEJBQTRCLENBQ2hELFFBQVEsRUFBRSxRQUFRLEVBQ2xCLFVBQVUsRUFBRSx5QkFBeUIsRUFDckMsY0FBYyxHQUFFLEVBQUUsRUFBTyxHQUN4QixPQUFPLENBQUMsSUFBSSxDQUFDLENBa0JmO0FBRUQsd0JBQXNCLGtCQUFrQixDQUN0QyxVQUFVLEVBQUUseUJBQXlCLEVBQ3JDLGVBQWUsRUFBRSxlQUFlLEdBQy9CLE9BQU8sQ0FBQyxXQUFXLENBQUMsQ0FZdEI7QUFFRDs7Ozs7Ozs7Ozs7O0dBWUc7QUFDSCx3QkFBc0IsWUFBWSxDQUNoQyxVQUFVLEVBQUUseUJBQXlCLEVBQ3JDLGVBQWUsRUFBRSxlQUFlLEVBQ2hDLFNBQVMsRUFBRSxRQUFRLEVBQUUsR0FDcEIsT0FBTyxDQUFDLE9BQU8sQ0FBQyxDQWlCbEIifQ==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block_creation.d.ts","sourceRoot":"","sources":["../../src/utils/block_creation.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,WAAW,EAA2C,MAAM,iCAAiC,CAAC;AAEvG,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AACpD,OAAO,EAAQ,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAwC,KAAK,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAC3G,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE1E;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,WAAW,EAAE,WAAW,GAAG,EAAE,CAExE;AAED,wBAAsB,4BAA4B,CAChD,QAAQ,EAAE,QAAQ,EAClB,UAAU,EAAE,yBAAyB,
|
|
1
|
+
{"version":3,"file":"block_creation.d.ts","sourceRoot":"","sources":["../../src/utils/block_creation.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,WAAW,EAA2C,MAAM,iCAAiC,CAAC;AAEvG,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AACpD,OAAO,EAAQ,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAwC,KAAK,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAC3G,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE1E;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,WAAW,EAAE,WAAW,GAAG,EAAE,CAExE;AAED,wBAAsB,4BAA4B,CAChD,QAAQ,EAAE,QAAQ,EAClB,UAAU,EAAE,yBAAyB,EACrC,cAAc,GAAE,EAAE,EAAO,GACxB,OAAO,CAAC,IAAI,CAAC,CAkBf;AAED,wBAAsB,kBAAkB,CACtC,UAAU,EAAE,yBAAyB,EACrC,eAAe,EAAE,eAAe,GAC/B,OAAO,CAAC,WAAW,CAAC,CAYtB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,YAAY,CAChC,UAAU,EAAE,yBAAyB,EACrC,eAAe,EAAE,eAAe,EAChC,SAAS,EAAE,QAAQ,EAAE,GACpB,OAAO,CAAC,OAAO,CAAC,CAiBlB"}
|