@aztec/txe 5.0.0-private.20260318 → 5.0.0-rc.1
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-CPGFQR26.js +3 -0
- package/dest/AuthRegistry-CPGFQR26.js.map +7 -0
- package/dest/ContractClassRegistry-EHVIHGEK.js +3 -0
- package/dest/ContractClassRegistry-EHVIHGEK.js.map +7 -0
- package/dest/ContractInstanceRegistry-DWZDXHRG.js +3 -0
- package/dest/ContractInstanceRegistry-DWZDXHRG.js.map +7 -0
- package/dest/FeeJuice-MI32ZO7B.js +3 -0
- package/dest/FeeJuice-MI32ZO7B.js.map +7 -0
- package/dest/HandshakeRegistry-3KSP3ITH.js +3 -0
- package/dest/HandshakeRegistry-3KSP3ITH.js.map +7 -0
- package/dest/MultiCallEntrypoint-IU7HYFYE.js +3 -0
- package/dest/MultiCallEntrypoint-IU7HYFYE.js.map +7 -0
- package/dest/SchnorrAccount-6TUE7JX4.js +3 -0
- package/dest/SchnorrAccount-6TUE7JX4.js.map +7 -0
- package/dest/SchnorrInitializerlessAccount-S3DU2DJK.js +3 -0
- package/dest/SchnorrInitializerlessAccount-S3DU2DJK.js.map +7 -0
- package/dest/bin/check_txe_oracle_version.d.ts +2 -0
- package/dest/bin/check_txe_oracle_version.d.ts.map +1 -0
- package/dest/bin/check_txe_oracle_version.js +61 -0
- package/dest/bin/index.js +3 -30
- package/dest/bin/index.js.map +7 -0
- package/dest/bin/oracle_test_server.d.ts +3 -0
- package/dest/bin/oracle_test_server.d.ts.map +1 -0
- package/dest/bin/oracle_test_server.js +41 -0
- package/dest/chunk-5U25VAFR.js +265 -0
- package/dest/chunk-5U25VAFR.js.map +7 -0
- package/dest/chunk-BJVAAXNA.js +3 -0
- package/dest/chunk-BJVAAXNA.js.map +7 -0
- package/dest/chunk-UPW55EJX.js +304 -0
- package/dest/chunk-UPW55EJX.js.map +7 -0
- package/dest/constants.d.ts +5 -1
- package/dest/constants.d.ts.map +1 -1
- package/dest/constants.js +8 -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 +70 -190
- package/dest/metafile.json +38829 -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 +33 -8
- package/dest/oracle/interfaces.d.ts.map +1 -1
- package/dest/oracle/test-resolver/fixtures.d.ts +43 -0
- package/dest/oracle/test-resolver/fixtures.d.ts.map +1 -0
- package/dest/oracle/test-resolver/fixtures.js +39 -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 +33 -0
- package/dest/oracle/test-resolver/resolver.d.ts +34 -0
- package/dest/oracle/test-resolver/resolver.d.ts.map +1 -0
- package/dest/oracle/test-resolver/resolver.js +114 -0
- package/dest/oracle/txe_oracle_public_context.d.ts +26 -2
- package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.js +43 -1
- package/dest/oracle/txe_oracle_registry.d.ts +14 -0
- package/dest/oracle/txe_oracle_registry.d.ts.map +1 -0
- package/dest/oracle/txe_oracle_registry.js +562 -0
- package/dest/oracle/txe_oracle_top_level_context.d.ts +32 -18
- package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_top_level_context.js +151 -55
- 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 +103 -230
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +697 -616
- package/dest/server.bundle.js +3 -0
- package/dest/server.bundle.js.map +7 -0
- package/dest/state_machine/archiver.d.ts +4 -3
- package/dest/state_machine/archiver.d.ts.map +1 -1
- package/dest/state_machine/archiver.js +26 -15
- package/dest/state_machine/dummy_p2p_client.d.ts +14 -7
- package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
- package/dest/state_machine/dummy_p2p_client.js +19 -4
- package/dest/state_machine/global_variable_builder.d.ts +9 -4
- package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
- package/dest/state_machine/global_variable_builder.js +9 -3
- package/dest/state_machine/index.d.ts +4 -2
- package/dest/state_machine/index.d.ts.map +1 -1
- package/dest/state_machine/index.js +11 -3
- package/dest/state_machine/mock_epoch_cache.d.ts +16 -3
- package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
- package/dest/state_machine/mock_epoch_cache.js +29 -2
- package/dest/state_machine/synchronizer.js +1 -1
- package/dest/txe_session.d.ts +85 -17
- package/dest/txe_session.d.ts.map +1 -1
- package/dest/txe_session.js +245 -40
- package/dest/utils/encoding.d.ts +191 -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/{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 +1 -3
- package/dest/worker.bundle.js +3 -0
- package/dest/worker.bundle.js.map +7 -0
- package/dest/worker.d.ts +2 -0
- package/dest/worker.d.ts.map +1 -0
- package/dest/worker.js +92 -0
- package/package.json +38 -21
- package/src/bin/check_txe_oracle_version.ts +70 -0
- package/src/bin/index.ts +11 -2
- package/src/bin/oracle_test_server.ts +51 -0
- package/src/constants.ts +10 -0
- package/src/dispatcher_pool.ts +317 -0
- package/src/index.ts +97 -227
- package/src/msgpackr_fr_extension.ts +23 -0
- package/src/oracle/interfaces.ts +29 -7
- package/src/oracle/test-resolver/fixtures.ts +84 -0
- package/src/oracle/test-resolver/index.ts +45 -0
- package/src/oracle/test-resolver/resolver.ts +165 -0
- package/src/oracle/txe_oracle_public_context.ts +60 -0
- package/src/oracle/txe_oracle_registry.ts +401 -0
- package/src/oracle/txe_oracle_top_level_context.ts +185 -64
- 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 +767 -892
- package/src/state_machine/archiver.ts +38 -16
- package/src/state_machine/dummy_p2p_client.ts +35 -11
- package/src/state_machine/global_variable_builder.ts +18 -3
- package/src/state_machine/index.ts +17 -5
- package/src/state_machine/mock_epoch_cache.ts +38 -3
- package/src/state_machine/synchronizer.ts +1 -1
- package/src/txe_session.ts +437 -50
- package/src/{util → utils}/encoding.ts +8 -2
- package/src/utils/txe_artifact_resolver.ts +217 -0
- package/src/{util → utils}/txe_public_contract_data_source.ts +0 -2
- 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,42 @@ 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, SenderAddressBookStore, SenderTaggingStore } from '@aztec/pxe/server';
|
|
7
|
-
import { ExecutionNoteCache, ExecutionTaggingIndexCache, HashedValuesCache,
|
|
5
|
+
import { openEphemeralStore } from '@aztec/kv-store/lmdb-v2';
|
|
6
|
+
import { AddressStore, AnchorBlockStore, CapsuleService, CapsuleStore, JobCoordinator, NoteService, NoteStore, PrivateEventStore, RecipientTaggingStore, SenderAddressBookStore, SenderTaggingStore } from '@aztec/pxe/server';
|
|
7
|
+
import { ExecutionNoteCache, ExecutionTaggingIndexCache, HashedValuesCache, 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
17
|
import { TXEOraclePublicContext } from './oracle/txe_oracle_public_context.js';
|
|
18
18
|
import { TXEOracleTopLevelContext } from './oracle/txe_oracle_top_level_context.js';
|
|
19
|
-
import {
|
|
19
|
+
import { TXE_ORACLE_VERSION_MAJOR, TXE_ORACLE_VERSION_MINOR } from './oracle/txe_oracle_version.js';
|
|
20
|
+
import { TXEPrivateExecutionOracle } from './oracle/txe_private_execution_oracle.js';
|
|
21
|
+
import { RPCTranslator, UnavailableOracleError } from './rpc_translator.js';
|
|
20
22
|
import { TXEArchiver } from './state_machine/archiver.js';
|
|
21
23
|
import { TXEStateMachine } from './state_machine/index.js';
|
|
22
|
-
import { TXEAccountStore } from './util/txe_account_store.js';
|
|
23
24
|
import { getSingleTxBlockRequestHash, insertTxEffectIntoWorldTrees, makeTXEBlock } from './utils/block_creation.js';
|
|
24
25
|
import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
26
|
+
import { TXEAccountStore } from './utils/txe_account_store.js';
|
|
27
|
+
function emptyLastCallState() {
|
|
28
|
+
return {
|
|
29
|
+
offchainEffects: [],
|
|
30
|
+
queried: false,
|
|
31
|
+
txHash: Fr.ZERO,
|
|
32
|
+
anchorBlockTimestamp: 0n
|
|
33
|
+
};
|
|
34
|
+
}
|
|
25
35
|
/**
|
|
26
36
|
* A `TXESession` corresponds to a Noir `#[test]` function, and handles all of its oracle calls, stores test-specific
|
|
27
37
|
* state, etc., independent of all other tests running in parallel.
|
|
28
38
|
*/ export class TXESession {
|
|
29
39
|
logger;
|
|
40
|
+
sessionStore;
|
|
30
41
|
stateMachine;
|
|
31
42
|
oracleHandler;
|
|
32
43
|
contractStore;
|
|
@@ -44,10 +55,17 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
|
44
55
|
chainId;
|
|
45
56
|
version;
|
|
46
57
|
nextBlockTimestamp;
|
|
58
|
+
artifactResolver;
|
|
59
|
+
rootPath;
|
|
60
|
+
packageName;
|
|
47
61
|
state;
|
|
48
62
|
authwits;
|
|
49
|
-
|
|
63
|
+
lastCallInfo;
|
|
64
|
+
txeOracleVersion;
|
|
65
|
+
disposed;
|
|
66
|
+
constructor(logger, sessionStore, stateMachine, oracleHandler, contractStore, noteStore, keyStore, addressStore, accountStore, senderTaggingStore, recipientTaggingStore, senderAddressBookStore, capsuleStore, privateEventStore, jobCoordinator, currentJobId, chainId, version, nextBlockTimestamp, artifactResolver, rootPath, packageName){
|
|
50
67
|
this.logger = logger;
|
|
68
|
+
this.sessionStore = sessionStore;
|
|
51
69
|
this.stateMachine = stateMachine;
|
|
52
70
|
this.oracleHandler = oracleHandler;
|
|
53
71
|
this.contractStore = contractStore;
|
|
@@ -65,13 +83,41 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
|
65
83
|
this.chainId = chainId;
|
|
66
84
|
this.version = version;
|
|
67
85
|
this.nextBlockTimestamp = nextBlockTimestamp;
|
|
86
|
+
this.artifactResolver = artifactResolver;
|
|
87
|
+
this.rootPath = rootPath;
|
|
88
|
+
this.packageName = packageName;
|
|
68
89
|
this.state = {
|
|
69
90
|
name: 'TOP_LEVEL'
|
|
70
91
|
};
|
|
71
92
|
this.authwits = new Map();
|
|
93
|
+
this.lastCallInfo = emptyLastCallState();
|
|
94
|
+
this.disposed = false;
|
|
72
95
|
}
|
|
73
|
-
|
|
74
|
-
|
|
96
|
+
/**
|
|
97
|
+
* Closes the per-session `txe-session` LMDB and the `NativeWorldStateService` .
|
|
98
|
+
* Called via IPC when the dispatcher detects the end of a test. Idempotent.
|
|
99
|
+
*/ async dispose() {
|
|
100
|
+
if (this.disposed) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
this.disposed = true;
|
|
104
|
+
try {
|
|
105
|
+
await this.stateMachine.synchronizer.nativeWorldStateService.close();
|
|
106
|
+
} catch (err) {
|
|
107
|
+
this.logger.warn(`Error closing native world state during session dispose`, err);
|
|
108
|
+
}
|
|
109
|
+
try {
|
|
110
|
+
await this.sessionStore.close();
|
|
111
|
+
} catch (err) {
|
|
112
|
+
this.logger.warn(`Error closing session LMDB during dispose`, err);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
static async init(contractStore, artifactResolver, rootPath, packageName) {
|
|
116
|
+
// Size LMDB's reader slots to the libuv pool (capped to 2 in bin/index.ts via
|
|
117
|
+
// HARDWARE_CONCURRENCY): each native LMDB read needs a libuv worker thread to run, so any
|
|
118
|
+
// slot beyond the pool size would sit idle while still consuming a semaphore + reader-table
|
|
119
|
+
// entry per session.
|
|
120
|
+
const store = await openEphemeralStore('txe-session', undefined, 2);
|
|
75
121
|
const addressStore = new AddressStore(store);
|
|
76
122
|
const privateEventStore = new PrivateEventStore(store);
|
|
77
123
|
const noteStore = new NoteStore(store);
|
|
@@ -81,7 +127,6 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
|
81
127
|
const capsuleStore = new CapsuleStore(store);
|
|
82
128
|
const keyStore = new KeyStore(store);
|
|
83
129
|
const accountStore = new TXEAccountStore(store);
|
|
84
|
-
// Create job coordinator and register staged stores
|
|
85
130
|
const jobCoordinator = new JobCoordinator(store);
|
|
86
131
|
jobCoordinator.registerStores([
|
|
87
132
|
capsuleStore,
|
|
@@ -97,9 +142,12 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
|
97
142
|
const version = new Fr(await stateMachine.node.getVersion());
|
|
98
143
|
const chainId = new Fr(await stateMachine.node.getChainId());
|
|
99
144
|
const initialJobId = jobCoordinator.beginJob();
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
145
|
+
const logger = createLogger('txe:session');
|
|
146
|
+
const topLevelOracleHandler = new TXEOracleTopLevelContext(stateMachine, contractStore, noteStore, keyStore, addressStore, accountStore, senderTaggingStore, recipientTaggingStore, senderAddressBookStore, capsuleStore, privateEventStore, nextBlockTimestamp, version, chainId, new Map(), artifactResolver, rootPath, packageName);
|
|
147
|
+
await topLevelOracleHandler.mineDeploymentNullifiers([
|
|
148
|
+
STANDARD_AUTH_REGISTRY_ADDRESS
|
|
149
|
+
]);
|
|
150
|
+
return new TXESession(logger, store, stateMachine, topLevelOracleHandler, contractStore, noteStore, keyStore, addressStore, accountStore, senderTaggingStore, recipientTaggingStore, senderAddressBookStore, capsuleStore, privateEventStore, jobCoordinator, initialJobId, version, chainId, nextBlockTimestamp, artifactResolver, rootPath, packageName);
|
|
103
151
|
}
|
|
104
152
|
/**
|
|
105
153
|
* Processes an oracle function invoked by the Noir test associated to this session.
|
|
@@ -114,7 +162,15 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
|
114
162
|
return translator[validatedFunctionName](...inputs);
|
|
115
163
|
} catch (error) {
|
|
116
164
|
if (error instanceof z.ZodError) {
|
|
117
|
-
|
|
165
|
+
let versionHint;
|
|
166
|
+
if (!this.txeOracleVersion) {
|
|
167
|
+
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';
|
|
168
|
+
} else if (this.txeOracleVersion.minor > TXE_ORACLE_VERSION_MINOR) {
|
|
169
|
+
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`;
|
|
170
|
+
} else {
|
|
171
|
+
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`;
|
|
172
|
+
}
|
|
173
|
+
throw new Error(`Unknown oracle '${functionName}'.${versionHint}`);
|
|
118
174
|
} else if (error instanceof Error) {
|
|
119
175
|
throw new Error(`Execution error while processing function ${functionName} in state ${this.state.name}: ${error.message}`);
|
|
120
176
|
} else {
|
|
@@ -122,14 +178,132 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
|
122
178
|
}
|
|
123
179
|
}
|
|
124
180
|
}
|
|
125
|
-
getCurrentJob() {
|
|
126
|
-
return this.currentJobId;
|
|
127
|
-
}
|
|
128
181
|
/** Commits the current job and begins a new one. Returns the new job ID. */ async cycleJob() {
|
|
129
182
|
await this.jobCoordinator.commitJob(this.currentJobId);
|
|
130
183
|
this.currentJobId = this.jobCoordinator.beginJob();
|
|
131
184
|
return this.currentJobId;
|
|
132
185
|
}
|
|
186
|
+
resetLastCall() {
|
|
187
|
+
const notQueriedMessageCount = this.lastCallInfo.queried ? 0 : this.lastCallInfo.offchainEffects.filter((payload)=>payload[0]?.equals(OFFCHAIN_MESSAGE_IDENTIFIER)).length;
|
|
188
|
+
if (notQueriedMessageCount > 0) {
|
|
189
|
+
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.`);
|
|
190
|
+
}
|
|
191
|
+
this.lastCallInfo = emptyLastCallState();
|
|
192
|
+
}
|
|
193
|
+
recordOffchainEffect(data) {
|
|
194
|
+
this.lastCallInfo.offchainEffects.push(data);
|
|
195
|
+
}
|
|
196
|
+
setLastCallContext(txHash, anchorBlockTimestamp) {
|
|
197
|
+
this.lastCallInfo.txHash = txHash;
|
|
198
|
+
this.lastCallInfo.anchorBlockTimestamp = anchorBlockTimestamp;
|
|
199
|
+
}
|
|
200
|
+
async withTopLevelCallTracking(work) {
|
|
201
|
+
this.resetLastCall();
|
|
202
|
+
// Capture the anchor *before* `work` runs: private/public executor calls mine a new block as a
|
|
203
|
+
// side effect, and that block's timestamp should not be attributed to this call's anchor.
|
|
204
|
+
const anchorBlockTimestamp = (await this.stateMachine.node.getBlockData('latest')).header.globalVariables.timestamp;
|
|
205
|
+
const { result, txHash } = await work();
|
|
206
|
+
this.setLastCallContext(txHash ?? Fr.ZERO, anchorBlockTimestamp);
|
|
207
|
+
return result;
|
|
208
|
+
}
|
|
209
|
+
getLastCallOffchainEffects() {
|
|
210
|
+
this.lastCallInfo.queried = true;
|
|
211
|
+
const effects = this.lastCallInfo.offchainEffects;
|
|
212
|
+
if (effects.length > MAX_OFFCHAIN_EFFECTS_PER_TXE_QUERY) {
|
|
213
|
+
throw new Error(`${effects.length} offchain effects exceed max ${MAX_OFFCHAIN_EFFECTS_PER_TXE_QUERY}`);
|
|
214
|
+
}
|
|
215
|
+
if (effects.some((e)=>e.length > MAX_OFFCHAIN_EFFECT_LEN)) {
|
|
216
|
+
throw new Error(`Some offchain effect has length larger than max ${MAX_OFFCHAIN_EFFECT_LEN}`);
|
|
217
|
+
}
|
|
218
|
+
return {
|
|
219
|
+
effects
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
getLastCallContext() {
|
|
223
|
+
const { txHash, anchorBlockTimestamp } = this.lastCallInfo;
|
|
224
|
+
return {
|
|
225
|
+
txHash,
|
|
226
|
+
anchorBlockTimestamp
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
async executePrivateCall(from, targetContractAddress, functionSelector, args, argsHash, isStaticCall, additionalScopes, authorizedUtilityCallTargets, gasSettings) {
|
|
230
|
+
const handler = this.handlerAsTxe();
|
|
231
|
+
return await this.withTopLevelCallTracking(async ()=>{
|
|
232
|
+
const { returnValues, offchainEffects } = await handler.privateCallNewFlow(from?.value, targetContractAddress, functionSelector, args, argsHash, isStaticCall, additionalScopes, this.currentJobId, authorizedUtilityCallTargets, gasSettings);
|
|
233
|
+
// Private execution collects offchain effects inside PXE's PrivateExecutionOracle rather than round-tripping
|
|
234
|
+
// them through `aztec_utl_emitOffchainEffect`, so the session buffer is empty at this point. Drain the effects
|
|
235
|
+
// from the execution tree into the session buffer so the next `env.offchain_messages()` call in the test sees
|
|
236
|
+
// them.
|
|
237
|
+
for (const data of offchainEffects){
|
|
238
|
+
this.recordOffchainEffect(data);
|
|
239
|
+
}
|
|
240
|
+
await this.cycleJob();
|
|
241
|
+
if (isStaticCall) {
|
|
242
|
+
// Static calls revert their checkpoint and mine no block, so there is no tx hash to tag offchain effects
|
|
243
|
+
// with. Querying `getLastTxEffects()` here would return an unrelated predecessor tx.
|
|
244
|
+
return {
|
|
245
|
+
result: returnValues
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
const { txHash } = await handler.getLastTxEffects();
|
|
249
|
+
return {
|
|
250
|
+
result: returnValues,
|
|
251
|
+
txHash: txHash.hash
|
|
252
|
+
};
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
async executeUtilityFunction(targetContractAddress, functionSelector, args, authorizedUtilityCallTargets) {
|
|
256
|
+
const handler = this.handlerAsTxe();
|
|
257
|
+
return await this.withTopLevelCallTracking(async ()=>{
|
|
258
|
+
const returnValues = await handler.executeUtilityFunction(targetContractAddress, functionSelector, args, this.currentJobId, authorizedUtilityCallTargets);
|
|
259
|
+
await this.cycleJob();
|
|
260
|
+
return {
|
|
261
|
+
result: returnValues
|
|
262
|
+
};
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
async executePublicCall(from, targetContractAddress, calldata, isStaticCall, gasSettings) {
|
|
266
|
+
const handler = this.handlerAsTxe();
|
|
267
|
+
return await this.withTopLevelCallTracking(async ()=>{
|
|
268
|
+
const returnValues = await handler.publicCallNewFlow(from?.value, targetContractAddress, calldata, isStaticCall, gasSettings);
|
|
269
|
+
await this.cycleJob();
|
|
270
|
+
if (isStaticCall) {
|
|
271
|
+
// See the equivalent branch in `executePrivateCall`.
|
|
272
|
+
return {
|
|
273
|
+
result: returnValues
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
const { txHash } = await handler.getLastTxEffects();
|
|
277
|
+
return {
|
|
278
|
+
result: returnValues,
|
|
279
|
+
txHash: txHash.hash
|
|
280
|
+
};
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
async getPrivateEvents(selector, contractAddress, scope) {
|
|
284
|
+
const handler = this.handlerAsTxe();
|
|
285
|
+
await handler.syncContractNonOracleMethod(contractAddress, scope, this.currentJobId);
|
|
286
|
+
// Cycle the job to commit the stores after the contract sync.
|
|
287
|
+
await this.cycleJob();
|
|
288
|
+
return handler.getPrivateEvents(selector, contractAddress, scope);
|
|
289
|
+
}
|
|
290
|
+
handlerAsTxe() {
|
|
291
|
+
if (!('isTxe' in this.oracleHandler)) {
|
|
292
|
+
throw new UnavailableOracleError('Txe');
|
|
293
|
+
}
|
|
294
|
+
return this.oracleHandler;
|
|
295
|
+
}
|
|
296
|
+
setTxeOracleVersion(major, minor) {
|
|
297
|
+
if (major !== TXE_ORACLE_VERSION_MAJOR) {
|
|
298
|
+
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.';
|
|
299
|
+
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})`);
|
|
300
|
+
}
|
|
301
|
+
this.txeOracleVersion = {
|
|
302
|
+
major,
|
|
303
|
+
minor
|
|
304
|
+
};
|
|
305
|
+
this.logger.debug(`Test compiled with test oracle version ${major}.${minor}`);
|
|
306
|
+
}
|
|
133
307
|
async enterTopLevelState() {
|
|
134
308
|
switch(this.state.name){
|
|
135
309
|
case 'PRIVATE':
|
|
@@ -158,20 +332,23 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
|
158
332
|
}
|
|
159
333
|
// Commit all staged stores from the job that was just completed, then begin a new job
|
|
160
334
|
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.senderAddressBookStore, this.capsuleStore, this.privateEventStore, this.nextBlockTimestamp, this.version, this.chainId, this.authwits);
|
|
335
|
+
this.oracleHandler = new TXEOracleTopLevelContext(this.stateMachine, this.contractStore, this.noteStore, this.keyStore, this.addressStore, this.accountStore, this.senderTaggingStore, this.recipientTaggingStore, this.senderAddressBookStore, this.capsuleStore, this.privateEventStore, this.nextBlockTimestamp, this.version, this.chainId, this.authwits, this.artifactResolver, this.rootPath, this.packageName);
|
|
162
336
|
this.state = {
|
|
163
337
|
name: 'TOP_LEVEL'
|
|
164
338
|
};
|
|
165
339
|
this.logger.debug(`Entered state ${this.state.name}`);
|
|
166
340
|
}
|
|
167
|
-
async enterPrivateState(
|
|
341
|
+
async enterPrivateState(contractAddressOpt, anchorBlockNumberOpt, gasSettings) {
|
|
342
|
+
const contractAddress = contractAddressOpt?.value ?? DEFAULT_ADDRESS;
|
|
343
|
+
const anchorBlockNumber = anchorBlockNumberOpt?.value;
|
|
168
344
|
this.exitTopLevelState();
|
|
345
|
+
this.resetLastCall();
|
|
169
346
|
// Private execution has two associated block numbers: the anchor block (i.e. the historical block that is used to
|
|
170
347
|
// build the proof), and the *next* block, i.e. the one we'll create once the execution ends, and which will contain
|
|
171
348
|
// 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.
|
|
349
|
+
const anchorBlock = await this.stateMachine.node.getBlock(anchorBlockNumber ?? 'latest').then((b)=>b?.header);
|
|
350
|
+
await new NoteService(this.noteStore, this.stateMachine.node, anchorBlock, this.currentJobId).syncNoteNullifiers(contractAddress, await this.keyStore.getAccounts());
|
|
351
|
+
const latestBlock = await this.stateMachine.node.getBlock('latest').then((b)=>b?.header);
|
|
175
352
|
const nextBlockGlobalVariables = makeGlobalVariables(undefined, {
|
|
176
353
|
blockNumber: BlockNumber(latestBlock.globalVariables.blockNumber + 1),
|
|
177
354
|
timestamp: this.nextBlockTimestamp,
|
|
@@ -183,9 +360,10 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
|
183
360
|
const noteCache = new ExecutionNoteCache(protocolNullifier);
|
|
184
361
|
const taggingIndexCache = new ExecutionTaggingIndexCache();
|
|
185
362
|
const utilityExecutor = this.utilityExecutorForContractSync(anchorBlock);
|
|
186
|
-
|
|
363
|
+
const transientArrayService = new TransientArrayService();
|
|
364
|
+
this.oracleHandler = new TXEPrivateExecutionOracle({
|
|
187
365
|
argsHash: Fr.ZERO,
|
|
188
|
-
txContext: new TxContext(this.chainId, this.version,
|
|
366
|
+
txContext: new TxContext(this.chainId, this.version, gasSettings),
|
|
189
367
|
callContext: new CallContext(AztecAddress.ZERO, contractAddress, FunctionSelector.empty(), false),
|
|
190
368
|
anchorBlockHeader: anchorBlock,
|
|
191
369
|
utilityExecutor,
|
|
@@ -202,12 +380,15 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
|
202
380
|
senderTaggingStore: this.senderTaggingStore,
|
|
203
381
|
recipientTaggingStore: this.recipientTaggingStore,
|
|
204
382
|
senderAddressBookStore: this.senderAddressBookStore,
|
|
205
|
-
|
|
383
|
+
capsuleService: new CapsuleService(this.capsuleStore, await this.keyStore.getAccounts()),
|
|
206
384
|
privateEventStore: this.privateEventStore,
|
|
207
385
|
contractSyncService: this.stateMachine.contractSyncService,
|
|
386
|
+
l2TipsStore: this.stateMachine.l2TipsProvider,
|
|
208
387
|
jobId: this.currentJobId,
|
|
209
|
-
scopes:
|
|
210
|
-
messageContextService: this.stateMachine.messageContextService
|
|
388
|
+
scopes: await this.keyStore.getAccounts(),
|
|
389
|
+
messageContextService: this.stateMachine.messageContextService,
|
|
390
|
+
simulator: new WASMSimulator(),
|
|
391
|
+
transientArrayService
|
|
211
392
|
});
|
|
212
393
|
// We store the note and tagging index caches fed into the PrivateExecutionOracle (along with some other auxiliary
|
|
213
394
|
// data) in order to refer to it later, mimicking the way this object is used by the ContractFunctionSimulator. The
|
|
@@ -221,34 +402,43 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
|
221
402
|
taggingIndexCache
|
|
222
403
|
};
|
|
223
404
|
this.logger.debug(`Entered state ${this.state.name}`);
|
|
405
|
+
// Record the *resolved* anchor's timestamp — if the caller pinned the anchor to a past block
|
|
406
|
+
// via `anchorBlockNumber`, "latest" would be the wrong anchor for offchain-message semantics.
|
|
407
|
+
this.setLastCallContext(Fr.ZERO, anchorBlock.globalVariables.timestamp);
|
|
224
408
|
return this.oracleHandler.getPrivateContextInputs();
|
|
225
409
|
}
|
|
226
|
-
async enterPublicState(
|
|
410
|
+
async enterPublicState(contractAddressOpt) {
|
|
411
|
+
const contractAddress = contractAddressOpt?.value ?? DEFAULT_ADDRESS;
|
|
227
412
|
this.exitTopLevelState();
|
|
413
|
+
this.resetLastCall();
|
|
228
414
|
// The PublicContext will create a block with a single transaction in it, containing the effects of what was done in
|
|
229
415
|
// the test. The block therefore gets the *next* block number and timestamp.
|
|
230
|
-
const
|
|
416
|
+
const latestHeader = (await this.stateMachine.node.getBlockData('latest')).header;
|
|
231
417
|
const globalVariables = makeGlobalVariables(undefined, {
|
|
232
|
-
blockNumber: BlockNumber(
|
|
418
|
+
blockNumber: BlockNumber(latestHeader.globalVariables.blockNumber + 1),
|
|
233
419
|
timestamp: this.nextBlockTimestamp,
|
|
234
420
|
version: this.version,
|
|
235
421
|
chainId: this.chainId
|
|
236
422
|
});
|
|
237
|
-
this.oracleHandler = new TXEOraclePublicContext(contractAddress
|
|
423
|
+
this.oracleHandler = new TXEOraclePublicContext(contractAddress, await this.stateMachine.synchronizer.nativeWorldStateService.fork(), getSingleTxBlockRequestHash(globalVariables.blockNumber), globalVariables, this.contractStore);
|
|
238
424
|
this.state = {
|
|
239
425
|
name: 'PUBLIC'
|
|
240
426
|
};
|
|
241
427
|
this.logger.debug(`Entered state ${this.state.name}`);
|
|
428
|
+
// Public state is anchored at the latest block.
|
|
429
|
+
this.setLastCallContext(Fr.ZERO, latestHeader.globalVariables.timestamp);
|
|
242
430
|
}
|
|
243
|
-
async enterUtilityState(
|
|
431
|
+
async enterUtilityState(contractAddressOpt) {
|
|
432
|
+
const contractAddress = contractAddressOpt?.value ?? DEFAULT_ADDRESS;
|
|
244
433
|
this.exitTopLevelState();
|
|
434
|
+
this.resetLastCall();
|
|
245
435
|
const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
246
436
|
// There is no automatic message discovery and contract-driven syncing process in inlined private or utility
|
|
247
437
|
// contexts, which means that known nullifiers are also not searched for, since it is during the tagging sync that
|
|
248
438
|
// we perform this. We therefore search for known nullifiers now, as otherwise notes that were nullified would not
|
|
249
439
|
// be removed from the database.
|
|
250
440
|
// TODO(#12553): make the synchronizer sync here instead and remove this
|
|
251
|
-
await new NoteService(this.noteStore, this.stateMachine.node, anchorBlockHeader, this.currentJobId).syncNoteNullifiers(contractAddress,
|
|
441
|
+
await new NoteService(this.noteStore, this.stateMachine.node, anchorBlockHeader, this.currentJobId).syncNoteNullifiers(contractAddress, await this.keyStore.getAccounts());
|
|
252
442
|
this.oracleHandler = new UtilityExecutionOracle({
|
|
253
443
|
contractAddress,
|
|
254
444
|
authWitnesses: [],
|
|
@@ -261,16 +451,24 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
|
261
451
|
aztecNode: this.stateMachine.node,
|
|
262
452
|
recipientTaggingStore: this.recipientTaggingStore,
|
|
263
453
|
senderAddressBookStore: this.senderAddressBookStore,
|
|
264
|
-
|
|
454
|
+
capsuleService: new CapsuleService(this.capsuleStore, await this.keyStore.getAccounts()),
|
|
265
455
|
privateEventStore: this.privateEventStore,
|
|
266
456
|
messageContextService: this.stateMachine.messageContextService,
|
|
457
|
+
contractSyncService: this.stateMachine.contractSyncService,
|
|
458
|
+
l2TipsStore: this.stateMachine.l2TipsProvider,
|
|
267
459
|
jobId: this.currentJobId,
|
|
268
|
-
scopes:
|
|
460
|
+
scopes: await this.keyStore.getAccounts(),
|
|
461
|
+
simulator: new WASMSimulator(),
|
|
462
|
+
utilityExecutor: this.utilityExecutorForContractSync(anchorBlockHeader),
|
|
463
|
+
// Execution-tree root (top-level utility run): own store; nested frames inherit it.
|
|
464
|
+
transientArrayService: new TransientArrayService()
|
|
269
465
|
});
|
|
270
466
|
this.state = {
|
|
271
467
|
name: 'UTILITY'
|
|
272
468
|
};
|
|
273
469
|
this.logger.debug(`Entered state ${this.state.name}`);
|
|
470
|
+
// Utility state anchors at whatever the anchor block store is pointing to (tracked as latest).
|
|
471
|
+
this.setLastCallContext(Fr.ZERO, anchorBlockHeader.globalVariables.timestamp);
|
|
274
472
|
}
|
|
275
473
|
exitTopLevelState() {
|
|
276
474
|
if (this.state.name != 'TOP_LEVEL') {
|
|
@@ -329,6 +527,7 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
|
329
527
|
throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
|
|
330
528
|
}
|
|
331
529
|
try {
|
|
530
|
+
const simulator = new WASMSimulator();
|
|
332
531
|
const oracle = new UtilityExecutionOracle({
|
|
333
532
|
contractAddress: call.to,
|
|
334
533
|
authWitnesses: [],
|
|
@@ -341,13 +540,19 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
|
341
540
|
aztecNode: this.stateMachine.node,
|
|
342
541
|
recipientTaggingStore: this.recipientTaggingStore,
|
|
343
542
|
senderAddressBookStore: this.senderAddressBookStore,
|
|
344
|
-
|
|
543
|
+
capsuleService: new CapsuleService(this.capsuleStore, scopes),
|
|
345
544
|
privateEventStore: this.privateEventStore,
|
|
346
545
|
messageContextService: this.stateMachine.messageContextService,
|
|
546
|
+
contractSyncService: this.stateMachine.contractSyncService,
|
|
547
|
+
l2TipsStore: this.stateMachine.l2TipsProvider,
|
|
347
548
|
jobId: this.currentJobId,
|
|
348
|
-
scopes
|
|
549
|
+
scopes,
|
|
550
|
+
simulator,
|
|
551
|
+
utilityExecutor: this.utilityExecutorForContractSync(anchorBlock),
|
|
552
|
+
// Top-level utility entrypoint: gets a fresh store. Nested frames inherit it via UtilityExecutionOracle.
|
|
553
|
+
transientArrayService: new TransientArrayService()
|
|
349
554
|
});
|
|
350
|
-
await
|
|
555
|
+
await simulator.executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, buildACIRCallback(oracle)).catch((err)=>{
|
|
351
556
|
err.message = resolveAssertionMessageFromError(err, entryPointArtifact);
|
|
352
557
|
throw new ExecutionError(err.message, {
|
|
353
558
|
contractAddress: call.to,
|