@aztec/txe 0.0.1-commit.343b43af6 → 0.0.1-commit.350e0a4d
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-2RDAZOGB.js +3 -0
- package/dest/AuthRegistry-2RDAZOGB.js.map +7 -0
- package/dest/ContractClassRegistry-L5F3G33N.js +3 -0
- package/dest/ContractClassRegistry-L5F3G33N.js.map +7 -0
- package/dest/ContractInstanceRegistry-IJOBAWAC.js +3 -0
- package/dest/ContractInstanceRegistry-IJOBAWAC.js.map +7 -0
- package/dest/FeeJuice-J3XDQPFS.js +3 -0
- package/dest/FeeJuice-J3XDQPFS.js.map +7 -0
- package/dest/HandshakeRegistry-QGWZJYVS.js +3 -0
- package/dest/HandshakeRegistry-QGWZJYVS.js.map +7 -0
- package/dest/MultiCallEntrypoint-WZHPRFJ6.js +3 -0
- package/dest/MultiCallEntrypoint-WZHPRFJ6.js.map +7 -0
- package/dest/SchnorrAccount-II4XD6MI.js +3 -0
- package/dest/SchnorrAccount-II4XD6MI.js.map +7 -0
- package/dest/SchnorrInitializerlessAccount-FXIOXUQQ.js +3 -0
- package/dest/SchnorrInitializerlessAccount-FXIOXUQQ.js.map +7 -0
- package/dest/bin/check_txe_oracle_version.d.ts +2 -0
- package/dest/bin/check_txe_oracle_version.d.ts.map +1 -0
- package/dest/bin/check_txe_oracle_version.js +61 -0
- package/dest/bin/index.js +3 -30
- package/dest/bin/index.js.map +7 -0
- package/dest/bin/oracle_test_server.d.ts +3 -0
- package/dest/bin/oracle_test_server.d.ts.map +1 -0
- package/dest/bin/oracle_test_server.js +41 -0
- package/dest/chunk-BJVAAXNA.js +3 -0
- package/dest/chunk-BJVAAXNA.js.map +7 -0
- package/dest/chunk-OMH3BDML.js +304 -0
- package/dest/chunk-OMH3BDML.js.map +7 -0
- package/dest/chunk-R3ZWQEFL.js +260 -0
- package/dest/chunk-R3ZWQEFL.js.map +7 -0
- package/dest/constants.d.ts +5 -1
- package/dest/constants.d.ts.map +1 -1
- package/dest/constants.js +9 -1
- package/dest/dispatcher_pool.d.ts +67 -0
- package/dest/dispatcher_pool.d.ts.map +1 -0
- package/dest/dispatcher_pool.js +286 -0
- package/dest/index.d.ts +51 -7
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +72 -190
- package/dest/metafile.json +38140 -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 +38 -8
- 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 +26 -2
- package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.js +49 -1
- package/dest/oracle/txe_oracle_registry.d.ts +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 +43 -16
- package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_top_level_context.js +233 -86
- 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 -227
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +769 -607
- package/dest/server.bundle.js +3 -0
- package/dest/server.bundle.js.map +7 -0
- package/dest/state_machine/archiver.d.ts +4 -3
- package/dest/state_machine/archiver.d.ts.map +1 -1
- package/dest/state_machine/archiver.js +24 -14
- package/dest/state_machine/dummy_p2p_client.d.ts +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 +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.d.ts +9 -6
- package/dest/state_machine/synchronizer.d.ts.map +1 -1
- package/dest/state_machine/synchronizer.js +10 -6
- package/dest/txe_session.d.ts +89 -19
- package/dest/txe_session.d.ts.map +1 -1
- package/dest/txe_session.js +308 -60
- package/dest/utils/block_creation.d.ts +2 -2
- package/dest/utils/block_creation.d.ts.map +1 -1
- package/dest/utils/block_creation.js +2 -2
- package/dest/utils/encoding.d.ts +192 -0
- package/dest/utils/encoding.d.ts.map +1 -0
- package/dest/{util → utils}/encoding.js +7 -2
- package/dest/{util → utils}/expected_failure_error.d.ts +1 -1
- package/dest/utils/expected_failure_error.d.ts.map +1 -0
- package/dest/utils/tx_effect_creation.d.ts +1 -1
- package/dest/utils/tx_effect_creation.d.ts.map +1 -1
- package/dest/utils/tx_effect_creation.js +0 -1
- package/dest/{util → utils}/txe_account_store.d.ts +1 -1
- package/dest/utils/txe_account_store.d.ts.map +1 -0
- package/dest/utils/txe_artifact_resolver.d.ts +37 -0
- package/dest/utils/txe_artifact_resolver.d.ts.map +1 -0
- package/dest/utils/txe_artifact_resolver.js +161 -0
- package/dest/utils/txe_public_contract_data_source.d.ts +20 -0
- package/dest/utils/txe_public_contract_data_source.d.ts.map +1 -0
- package/dest/{util → utils}/txe_public_contract_data_source.js +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 +70 -0
- package/src/bin/index.ts +11 -2
- package/src/bin/oracle_test_server.ts +51 -0
- package/src/constants.ts +11 -1
- package/src/dispatcher_pool.ts +317 -0
- package/src/index.ts +99 -227
- package/src/msgpackr_fr_extension.ts +23 -0
- package/src/oracle/interfaces.ts +35 -7
- 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 +62 -0
- package/src/oracle/txe_oracle_registry.ts +536 -0
- package/src/oracle/txe_oracle_top_level_context.ts +307 -98
- 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 +858 -866
- package/src/state_machine/archiver.ts +37 -16
- 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 +38 -3
- package/src/state_machine/synchronizer.ts +13 -7
- package/src/txe_session.ts +539 -74
- 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,43 @@ 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
17
|
import { TXEOraclePublicContext } from './oracle/txe_oracle_public_context.js';
|
|
18
|
+
import { callTxeLegacyHandler } from './oracle/txe_oracle_registry.js';
|
|
18
19
|
import { TXEOracleTopLevelContext } from './oracle/txe_oracle_top_level_context.js';
|
|
19
|
-
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';
|
|
20
23
|
import { TXEArchiver } from './state_machine/archiver.js';
|
|
21
24
|
import { TXEStateMachine } from './state_machine/index.js';
|
|
22
|
-
import { TXEAccountStore } from './util/txe_account_store.js';
|
|
23
25
|
import { getSingleTxBlockRequestHash, insertTxEffectIntoWorldTrees, makeTXEBlock } from './utils/block_creation.js';
|
|
24
26
|
import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
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
|
+
}
|
|
25
36
|
/**
|
|
26
37
|
* A `TXESession` corresponds to a Noir `#[test]` function, and handles all of its oracle calls, stores test-specific
|
|
27
38
|
* state, etc., independent of all other tests running in parallel.
|
|
28
39
|
*/ export class TXESession {
|
|
29
40
|
logger;
|
|
41
|
+
sessionStore;
|
|
30
42
|
stateMachine;
|
|
31
43
|
oracleHandler;
|
|
32
44
|
contractStore;
|
|
@@ -36,18 +48,27 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
|
36
48
|
accountStore;
|
|
37
49
|
senderTaggingStore;
|
|
38
50
|
recipientTaggingStore;
|
|
39
|
-
|
|
51
|
+
taggingSecretSourcesStore;
|
|
40
52
|
capsuleStore;
|
|
53
|
+
factStore;
|
|
41
54
|
privateEventStore;
|
|
42
55
|
jobCoordinator;
|
|
43
56
|
currentJobId;
|
|
44
57
|
chainId;
|
|
45
58
|
version;
|
|
46
59
|
nextBlockTimestamp;
|
|
60
|
+
artifactResolver;
|
|
61
|
+
rootPath;
|
|
62
|
+
packageName;
|
|
47
63
|
state;
|
|
48
64
|
authwits;
|
|
49
|
-
|
|
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){
|
|
50
70
|
this.logger = logger;
|
|
71
|
+
this.sessionStore = sessionStore;
|
|
51
72
|
this.stateMachine = stateMachine;
|
|
52
73
|
this.oracleHandler = oracleHandler;
|
|
53
74
|
this.contractStore = contractStore;
|
|
@@ -57,34 +78,65 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
|
57
78
|
this.accountStore = accountStore;
|
|
58
79
|
this.senderTaggingStore = senderTaggingStore;
|
|
59
80
|
this.recipientTaggingStore = recipientTaggingStore;
|
|
60
|
-
this.
|
|
81
|
+
this.taggingSecretSourcesStore = taggingSecretSourcesStore;
|
|
61
82
|
this.capsuleStore = capsuleStore;
|
|
83
|
+
this.factStore = factStore;
|
|
62
84
|
this.privateEventStore = privateEventStore;
|
|
63
85
|
this.jobCoordinator = jobCoordinator;
|
|
64
86
|
this.currentJobId = currentJobId;
|
|
65
87
|
this.chainId = chainId;
|
|
66
88
|
this.version = version;
|
|
67
89
|
this.nextBlockTimestamp = nextBlockTimestamp;
|
|
90
|
+
this.artifactResolver = artifactResolver;
|
|
91
|
+
this.rootPath = rootPath;
|
|
92
|
+
this.packageName = packageName;
|
|
68
93
|
this.state = {
|
|
69
94
|
name: 'TOP_LEVEL'
|
|
70
95
|
};
|
|
71
96
|
this.authwits = new Map();
|
|
97
|
+
this.taggingSecretStrategy = undefined;
|
|
98
|
+
this.lastCallInfo = emptyLastCallState();
|
|
99
|
+
this.disposed = false;
|
|
72
100
|
}
|
|
73
|
-
|
|
74
|
-
|
|
101
|
+
/**
|
|
102
|
+
* Closes the per-session `txe-session` LMDB and the `NativeWorldStateService` .
|
|
103
|
+
* 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
|
+
try {
|
|
110
|
+
await this.stateMachine.synchronizer.nativeWorldStateService.close();
|
|
111
|
+
} catch (err) {
|
|
112
|
+
this.logger.warn(`Error closing native world state during session dispose`, err);
|
|
113
|
+
}
|
|
114
|
+
try {
|
|
115
|
+
await this.sessionStore.close();
|
|
116
|
+
} catch (err) {
|
|
117
|
+
this.logger.warn(`Error closing session LMDB during dispose`, err);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
static async init(contractStore, artifactResolver, rootPath, packageName) {
|
|
121
|
+
// Size LMDB's reader slots to the libuv pool (capped to 2 in bin/index.ts via
|
|
122
|
+
// HARDWARE_CONCURRENCY): each native LMDB read needs a libuv worker thread to run, so any
|
|
123
|
+
// slot beyond the pool size would sit idle while still consuming a semaphore + reader-table
|
|
124
|
+
// entry per session.
|
|
125
|
+
const store = await openEphemeralStore('txe-session', undefined, 2);
|
|
75
126
|
const addressStore = new AddressStore(store);
|
|
76
127
|
const privateEventStore = new PrivateEventStore(store);
|
|
77
128
|
const noteStore = new NoteStore(store);
|
|
78
129
|
const senderTaggingStore = new SenderTaggingStore(store);
|
|
79
130
|
const recipientTaggingStore = new RecipientTaggingStore(store);
|
|
80
|
-
const
|
|
131
|
+
const taggingSecretSourcesStore = new TaggingSecretSourcesStore(store);
|
|
81
132
|
const capsuleStore = new CapsuleStore(store);
|
|
133
|
+
const factStore = new FactStore(store);
|
|
82
134
|
const keyStore = new KeyStore(store);
|
|
83
135
|
const accountStore = new TXEAccountStore(store);
|
|
84
|
-
// Create job coordinator and register staged stores
|
|
85
136
|
const jobCoordinator = new JobCoordinator(store);
|
|
86
137
|
jobCoordinator.registerStores([
|
|
87
138
|
capsuleStore,
|
|
139
|
+
factStore,
|
|
88
140
|
senderTaggingStore,
|
|
89
141
|
recipientTaggingStore,
|
|
90
142
|
privateEventStore,
|
|
@@ -97,9 +149,12 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
|
97
149
|
const version = new Fr(await stateMachine.node.getVersion());
|
|
98
150
|
const chainId = new Fr(await stateMachine.node.getChainId());
|
|
99
151
|
const initialJobId = jobCoordinator.beginJob();
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
152
|
+
const logger = createLogger('txe:session');
|
|
153
|
+
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);
|
|
154
|
+
await topLevelOracleHandler.mineDeploymentNullifiers([
|
|
155
|
+
STANDARD_AUTH_REGISTRY_ADDRESS
|
|
156
|
+
]);
|
|
157
|
+
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
158
|
}
|
|
104
159
|
/**
|
|
105
160
|
* Processes an oracle function invoked by the Noir test associated to this session.
|
|
@@ -108,13 +163,28 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
|
108
163
|
* @returns The oracle return values.
|
|
109
164
|
*/ processFunction(functionName, inputs) {
|
|
110
165
|
try {
|
|
166
|
+
// Oracles retired into the PXE legacy registry have no translator method; dispatch them through the same
|
|
167
|
+
// buildACIRCallback legacy path that contract execution uses, keeping TXE's two oracle paths in sync.
|
|
168
|
+
// Use an own-property check: `in` would match inherited `Object.prototype` keys (e.g. `constructor`), routing
|
|
169
|
+
// them into the legacy path instead of letting them fall through to the unknown-oracle error.
|
|
170
|
+
if (Object.hasOwn(LEGACY_ORACLE_REGISTRY, functionName)) {
|
|
171
|
+
return callTxeLegacyHandler(functionName, inputs, this.oracleHandler);
|
|
172
|
+
}
|
|
111
173
|
const translator = new RPCTranslator(this, this.oracleHandler);
|
|
112
174
|
// We perform a runtime validation to check that the function name corresponds to a real oracle handler.
|
|
113
175
|
const validatedFunctionName = z.string().refine((fn)=>typeof translator[fn] === 'function' && !fn.startsWith('handlerAs') && fn !== 'constructor').parse(functionName);
|
|
114
176
|
return translator[validatedFunctionName](...inputs);
|
|
115
177
|
} catch (error) {
|
|
116
178
|
if (error instanceof z.ZodError) {
|
|
117
|
-
|
|
179
|
+
let versionHint;
|
|
180
|
+
if (!this.txeOracleVersion) {
|
|
181
|
+
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';
|
|
182
|
+
} else if (this.txeOracleVersion.minor > TXE_ORACLE_VERSION_MINOR) {
|
|
183
|
+
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`;
|
|
184
|
+
} else {
|
|
185
|
+
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`;
|
|
186
|
+
}
|
|
187
|
+
throw new Error(`Unknown oracle '${functionName}'.${versionHint}`);
|
|
118
188
|
} else if (error instanceof Error) {
|
|
119
189
|
throw new Error(`Execution error while processing function ${functionName} in state ${this.state.name}: ${error.message}`);
|
|
120
190
|
} else {
|
|
@@ -122,14 +192,132 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
|
122
192
|
}
|
|
123
193
|
}
|
|
124
194
|
}
|
|
125
|
-
getCurrentJob() {
|
|
126
|
-
return this.currentJobId;
|
|
127
|
-
}
|
|
128
195
|
/** Commits the current job and begins a new one. Returns the new job ID. */ async cycleJob() {
|
|
129
196
|
await this.jobCoordinator.commitJob(this.currentJobId);
|
|
130
197
|
this.currentJobId = this.jobCoordinator.beginJob();
|
|
131
198
|
return this.currentJobId;
|
|
132
199
|
}
|
|
200
|
+
resetLastCall() {
|
|
201
|
+
const notQueriedMessageCount = this.lastCallInfo.queried ? 0 : this.lastCallInfo.offchainEffects.filter((payload)=>payload[0]?.equals(OFFCHAIN_MESSAGE_IDENTIFIER)).length;
|
|
202
|
+
if (notQueriedMessageCount > 0) {
|
|
203
|
+
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.`);
|
|
204
|
+
}
|
|
205
|
+
this.lastCallInfo = emptyLastCallState();
|
|
206
|
+
}
|
|
207
|
+
recordOffchainEffect(data) {
|
|
208
|
+
this.lastCallInfo.offchainEffects.push(data);
|
|
209
|
+
}
|
|
210
|
+
setLastCallContext(txHash, anchorBlockTimestamp) {
|
|
211
|
+
this.lastCallInfo.txHash = txHash;
|
|
212
|
+
this.lastCallInfo.anchorBlockTimestamp = anchorBlockTimestamp;
|
|
213
|
+
}
|
|
214
|
+
async withTopLevelCallTracking(work) {
|
|
215
|
+
this.resetLastCall();
|
|
216
|
+
// Capture the anchor *before* `work` runs: private/public executor calls mine a new block as a
|
|
217
|
+
// side effect, and that block's timestamp should not be attributed to this call's anchor.
|
|
218
|
+
const anchorBlockTimestamp = (await this.stateMachine.node.getBlockData('latest')).header.globalVariables.timestamp;
|
|
219
|
+
const { result, txHash } = await work();
|
|
220
|
+
this.setLastCallContext(txHash ?? Fr.ZERO, anchorBlockTimestamp);
|
|
221
|
+
return result;
|
|
222
|
+
}
|
|
223
|
+
getLastCallOffchainEffects() {
|
|
224
|
+
this.lastCallInfo.queried = true;
|
|
225
|
+
const effects = this.lastCallInfo.offchainEffects;
|
|
226
|
+
if (effects.length > MAX_OFFCHAIN_EFFECTS_PER_TXE_QUERY) {
|
|
227
|
+
throw new Error(`${effects.length} offchain effects exceed max ${MAX_OFFCHAIN_EFFECTS_PER_TXE_QUERY}`);
|
|
228
|
+
}
|
|
229
|
+
if (effects.some((e)=>e.length > MAX_OFFCHAIN_EFFECT_LEN)) {
|
|
230
|
+
throw new Error(`Some offchain effect has length larger than max ${MAX_OFFCHAIN_EFFECT_LEN}`);
|
|
231
|
+
}
|
|
232
|
+
return {
|
|
233
|
+
effects
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
getLastCallContext() {
|
|
237
|
+
const { txHash, anchorBlockTimestamp } = this.lastCallInfo;
|
|
238
|
+
return {
|
|
239
|
+
txHash,
|
|
240
|
+
anchorBlockTimestamp
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
async executePrivateCall(from, targetContractAddress, functionSelector, args, argsHash, isStaticCall, additionalScopes, authorizedUtilityCallTargets, gasSettings) {
|
|
244
|
+
const handler = this.handlerAsTxe();
|
|
245
|
+
return await this.withTopLevelCallTracking(async ()=>{
|
|
246
|
+
const { returnValues, offchainEffects } = await handler.privateCallNewFlow(from?.value, targetContractAddress, functionSelector, args, argsHash, isStaticCall, additionalScopes, this.currentJobId, authorizedUtilityCallTargets, gasSettings);
|
|
247
|
+
// Private execution collects offchain effects inside PXE's PrivateExecutionOracle rather than round-tripping
|
|
248
|
+
// them through `aztec_utl_emitOffchainEffect`, so the session buffer is empty at this point. Drain the effects
|
|
249
|
+
// from the execution tree into the session buffer so the next `env.offchain_messages()` call in the test sees
|
|
250
|
+
// them.
|
|
251
|
+
for (const data of offchainEffects){
|
|
252
|
+
this.recordOffchainEffect(data);
|
|
253
|
+
}
|
|
254
|
+
await this.cycleJob();
|
|
255
|
+
if (isStaticCall) {
|
|
256
|
+
// Static calls revert their checkpoint and mine no block, so there is no tx hash to tag offchain effects
|
|
257
|
+
// with. Querying `getLastTxEffects()` here would return an unrelated predecessor tx.
|
|
258
|
+
return {
|
|
259
|
+
result: returnValues
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
const { txHash } = await handler.getLastTxEffects();
|
|
263
|
+
return {
|
|
264
|
+
result: returnValues,
|
|
265
|
+
txHash: txHash.hash
|
|
266
|
+
};
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
async executeUtilityFunction(from, targetContractAddress, functionSelector, args, authorizedUtilityCallTargets) {
|
|
270
|
+
const handler = this.handlerAsTxe();
|
|
271
|
+
return await this.withTopLevelCallTracking(async ()=>{
|
|
272
|
+
const returnValues = await handler.executeUtilityFunction(from?.value, targetContractAddress, functionSelector, args, this.currentJobId, authorizedUtilityCallTargets);
|
|
273
|
+
await this.cycleJob();
|
|
274
|
+
return {
|
|
275
|
+
result: returnValues
|
|
276
|
+
};
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
async executePublicCall(from, targetContractAddress, calldata, isStaticCall, gasSettings) {
|
|
280
|
+
const handler = this.handlerAsTxe();
|
|
281
|
+
return await this.withTopLevelCallTracking(async ()=>{
|
|
282
|
+
const returnValues = await handler.publicCallNewFlow(from?.value, targetContractAddress, calldata, isStaticCall, gasSettings);
|
|
283
|
+
await this.cycleJob();
|
|
284
|
+
if (isStaticCall) {
|
|
285
|
+
// See the equivalent branch in `executePrivateCall`.
|
|
286
|
+
return {
|
|
287
|
+
result: returnValues
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
const { txHash } = await handler.getLastTxEffects();
|
|
291
|
+
return {
|
|
292
|
+
result: returnValues,
|
|
293
|
+
txHash: txHash.hash
|
|
294
|
+
};
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
async getPrivateEvents(selector, contractAddress, scope) {
|
|
298
|
+
const handler = this.handlerAsTxe();
|
|
299
|
+
await handler.syncContractNonOracleMethod(contractAddress, scope, this.currentJobId);
|
|
300
|
+
// Cycle the job to commit the stores after the contract sync.
|
|
301
|
+
await this.cycleJob();
|
|
302
|
+
return handler.getPrivateEvents(selector, contractAddress, scope);
|
|
303
|
+
}
|
|
304
|
+
handlerAsTxe() {
|
|
305
|
+
if (!('isTxe' in this.oracleHandler)) {
|
|
306
|
+
throw new UnavailableOracleError('Txe');
|
|
307
|
+
}
|
|
308
|
+
return this.oracleHandler;
|
|
309
|
+
}
|
|
310
|
+
setTxeOracleVersion(major, minor) {
|
|
311
|
+
if (major !== TXE_ORACLE_VERSION_MAJOR) {
|
|
312
|
+
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.';
|
|
313
|
+
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})`);
|
|
314
|
+
}
|
|
315
|
+
this.txeOracleVersion = {
|
|
316
|
+
major,
|
|
317
|
+
minor
|
|
318
|
+
};
|
|
319
|
+
this.logger.debug(`Test compiled with test oracle version ${major}.${minor}`);
|
|
320
|
+
}
|
|
133
321
|
async enterTopLevelState() {
|
|
134
322
|
switch(this.state.name){
|
|
135
323
|
case 'PRIVATE':
|
|
@@ -158,20 +346,23 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
|
158
346
|
}
|
|
159
347
|
// Commit all staged stores from the job that was just completed, then begin a new job
|
|
160
348
|
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.
|
|
349
|
+
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);
|
|
162
350
|
this.state = {
|
|
163
351
|
name: 'TOP_LEVEL'
|
|
164
352
|
};
|
|
165
353
|
this.logger.debug(`Entered state ${this.state.name}`);
|
|
166
354
|
}
|
|
167
|
-
async enterPrivateState(
|
|
355
|
+
async enterPrivateState(contractAddressOpt, anchorBlockNumberOpt, gasSettings) {
|
|
356
|
+
const contractAddress = contractAddressOpt?.value ?? DEFAULT_ADDRESS;
|
|
357
|
+
const anchorBlockNumber = anchorBlockNumberOpt?.value;
|
|
168
358
|
this.exitTopLevelState();
|
|
359
|
+
this.resetLastCall();
|
|
169
360
|
// Private execution has two associated block numbers: the anchor block (i.e. the historical block that is used to
|
|
170
361
|
// build the proof), and the *next* block, i.e. the one we'll create once the execution ends, and which will contain
|
|
171
362
|
// 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.
|
|
363
|
+
const anchorBlock = await this.stateMachine.node.getBlock(anchorBlockNumber ?? 'latest').then((b)=>b?.header);
|
|
364
|
+
await new NoteService(this.noteStore, this.stateMachine.node, anchorBlock, this.currentJobId).syncNoteNullifiers(contractAddress, await this.keyStore.getAccounts());
|
|
365
|
+
const latestBlock = await this.stateMachine.node.getBlock('latest').then((b)=>b?.header);
|
|
175
366
|
const nextBlockGlobalVariables = makeGlobalVariables(undefined, {
|
|
176
367
|
blockNumber: BlockNumber(latestBlock.globalVariables.blockNumber + 1),
|
|
177
368
|
timestamp: this.nextBlockTimestamp,
|
|
@@ -183,9 +374,13 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
|
183
374
|
const noteCache = new ExecutionNoteCache(protocolNullifier);
|
|
184
375
|
const taggingIndexCache = new ExecutionTaggingIndexCache();
|
|
185
376
|
const utilityExecutor = this.utilityExecutorForContractSync(anchorBlock);
|
|
186
|
-
|
|
377
|
+
const transientArrayService = new TransientArrayService();
|
|
378
|
+
const anchoredContractData = new AnchoredContractData(this.contractStore, this.stateMachine.contractClassService, anchorBlock);
|
|
379
|
+
const taggingSecretStrategy = this.taggingSecretStrategy;
|
|
380
|
+
this.oracleHandler = new TXEPrivateExecutionOracle({
|
|
187
381
|
argsHash: Fr.ZERO,
|
|
188
|
-
txContext: new TxContext(this.chainId, this.version,
|
|
382
|
+
txContext: new TxContext(this.chainId, this.version, gasSettings),
|
|
383
|
+
txRequestSalt: Fr.ZERO,
|
|
189
384
|
callContext: new CallContext(AztecAddress.ZERO, contractAddress, FunctionSelector.empty(), false),
|
|
190
385
|
anchorBlockHeader: anchorBlock,
|
|
191
386
|
utilityExecutor,
|
|
@@ -194,19 +389,27 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
|
194
389
|
executionCache: new HashedValuesCache(),
|
|
195
390
|
noteCache,
|
|
196
391
|
taggingIndexCache,
|
|
197
|
-
|
|
392
|
+
anchoredContractData,
|
|
198
393
|
noteStore: this.noteStore,
|
|
199
394
|
keyStore: this.keyStore,
|
|
200
395
|
addressStore: this.addressStore,
|
|
201
396
|
aztecNode: this.stateMachine.node,
|
|
202
397
|
senderTaggingStore: this.senderTaggingStore,
|
|
203
398
|
recipientTaggingStore: this.recipientTaggingStore,
|
|
204
|
-
|
|
205
|
-
|
|
399
|
+
taggingSecretSourcesStore: this.taggingSecretSourcesStore,
|
|
400
|
+
capsuleService: new CapsuleService(this.capsuleStore, await this.keyStore.getAccounts()),
|
|
401
|
+
factService: new FactService(this.factStore, await this.keyStore.getAccounts()),
|
|
206
402
|
privateEventStore: this.privateEventStore,
|
|
207
403
|
contractSyncService: this.stateMachine.contractSyncService,
|
|
404
|
+
l2TipsStore: this.stateMachine.l2TipsProvider,
|
|
208
405
|
jobId: this.currentJobId,
|
|
209
|
-
scopes:
|
|
406
|
+
scopes: await this.keyStore.getAccounts(),
|
|
407
|
+
txResolver: this.stateMachine.txResolver,
|
|
408
|
+
simulator: new WASMSimulator(),
|
|
409
|
+
hooks: composeHooks({
|
|
410
|
+
resolveTaggingSecretStrategy: taggingSecretStrategy ? ()=>Promise.resolve(taggingSecretStrategy) : undefined
|
|
411
|
+
}),
|
|
412
|
+
transientArrayService
|
|
210
413
|
});
|
|
211
414
|
// We store the note and tagging index caches fed into the PrivateExecutionOracle (along with some other auxiliary
|
|
212
415
|
// data) in order to refer to it later, mimicking the way this object is used by the ContractFunctionSimulator. The
|
|
@@ -220,70 +423,97 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
|
220
423
|
taggingIndexCache
|
|
221
424
|
};
|
|
222
425
|
this.logger.debug(`Entered state ${this.state.name}`);
|
|
426
|
+
// Record the *resolved* anchor's timestamp — if the caller pinned the anchor to a past block
|
|
427
|
+
// via `anchorBlockNumber`, "latest" would be the wrong anchor for offchain-message semantics.
|
|
428
|
+
this.setLastCallContext(Fr.ZERO, anchorBlock.globalVariables.timestamp);
|
|
223
429
|
return this.oracleHandler.getPrivateContextInputs();
|
|
224
430
|
}
|
|
225
|
-
async enterPublicState(
|
|
431
|
+
async enterPublicState(contractAddressOpt) {
|
|
432
|
+
const contractAddress = contractAddressOpt?.value ?? DEFAULT_ADDRESS;
|
|
226
433
|
this.exitTopLevelState();
|
|
434
|
+
this.resetLastCall();
|
|
227
435
|
// The PublicContext will create a block with a single transaction in it, containing the effects of what was done in
|
|
228
436
|
// the test. The block therefore gets the *next* block number and timestamp.
|
|
229
|
-
const
|
|
437
|
+
const latestHeader = (await this.stateMachine.node.getBlockData('latest')).header;
|
|
230
438
|
const globalVariables = makeGlobalVariables(undefined, {
|
|
231
|
-
blockNumber: BlockNumber(
|
|
439
|
+
blockNumber: BlockNumber(latestHeader.globalVariables.blockNumber + 1),
|
|
232
440
|
timestamp: this.nextBlockTimestamp,
|
|
233
441
|
version: this.version,
|
|
234
442
|
chainId: this.chainId
|
|
235
443
|
});
|
|
236
|
-
this.oracleHandler = new TXEOraclePublicContext(contractAddress
|
|
444
|
+
this.oracleHandler = new TXEOraclePublicContext(contractAddress, await this.stateMachine.synchronizer.nativeWorldStateService.fork(), getSingleTxBlockRequestHash(globalVariables.blockNumber), globalVariables, this.contractStore);
|
|
237
445
|
this.state = {
|
|
238
446
|
name: 'PUBLIC'
|
|
239
447
|
};
|
|
240
448
|
this.logger.debug(`Entered state ${this.state.name}`);
|
|
449
|
+
// Public state is anchored at the latest block.
|
|
450
|
+
this.setLastCallContext(Fr.ZERO, latestHeader.globalVariables.timestamp);
|
|
241
451
|
}
|
|
242
|
-
async enterUtilityState(
|
|
452
|
+
async enterUtilityState(contractAddressOpt) {
|
|
453
|
+
const contractAddress = contractAddressOpt?.value ?? DEFAULT_ADDRESS;
|
|
243
454
|
this.exitTopLevelState();
|
|
455
|
+
this.resetLastCall();
|
|
244
456
|
const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
245
457
|
// There is no automatic message discovery and contract-driven syncing process in inlined private or utility
|
|
246
458
|
// contexts, which means that known nullifiers are also not searched for, since it is during the tagging sync that
|
|
247
459
|
// we perform this. We therefore search for known nullifiers now, as otherwise notes that were nullified would not
|
|
248
460
|
// be removed from the database.
|
|
249
461
|
// 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,
|
|
462
|
+
await new NoteService(this.noteStore, this.stateMachine.node, anchorBlockHeader, this.currentJobId).syncNoteNullifiers(contractAddress, await this.keyStore.getAccounts());
|
|
251
463
|
this.oracleHandler = new UtilityExecutionOracle({
|
|
252
|
-
|
|
464
|
+
callContext: CallContext.from({
|
|
465
|
+
msgSender: AztecAddress.NULL_MSG_SENDER,
|
|
466
|
+
contractAddress,
|
|
467
|
+
// No specific function is being executed in this inlined utility context, hence the empty selector.
|
|
468
|
+
functionSelector: FunctionSelector.empty(),
|
|
469
|
+
isStaticCall: true
|
|
470
|
+
}),
|
|
253
471
|
authWitnesses: [],
|
|
254
472
|
capsules: [],
|
|
255
473
|
anchorBlockHeader,
|
|
256
|
-
|
|
474
|
+
anchoredContractData: new AnchoredContractData(this.contractStore, this.stateMachine.contractClassService, anchorBlockHeader),
|
|
257
475
|
noteStore: this.noteStore,
|
|
258
476
|
keyStore: this.keyStore,
|
|
259
477
|
addressStore: this.addressStore,
|
|
260
478
|
aztecNode: this.stateMachine.node,
|
|
261
479
|
recipientTaggingStore: this.recipientTaggingStore,
|
|
262
|
-
|
|
263
|
-
|
|
480
|
+
taggingSecretSourcesStore: this.taggingSecretSourcesStore,
|
|
481
|
+
capsuleService: new CapsuleService(this.capsuleStore, await this.keyStore.getAccounts()),
|
|
482
|
+
factService: new FactService(this.factStore, await this.keyStore.getAccounts()),
|
|
264
483
|
privateEventStore: this.privateEventStore,
|
|
484
|
+
txResolver: this.stateMachine.txResolver,
|
|
485
|
+
contractSyncService: this.stateMachine.contractSyncService,
|
|
486
|
+
l2TipsStore: this.stateMachine.l2TipsProvider,
|
|
265
487
|
jobId: this.currentJobId,
|
|
266
|
-
scopes:
|
|
488
|
+
scopes: await this.keyStore.getAccounts(),
|
|
489
|
+
simulator: new WASMSimulator(),
|
|
490
|
+
utilityExecutor: this.utilityExecutorForContractSync(anchorBlockHeader),
|
|
491
|
+
// Execution-tree root (top-level utility run): own store; nested frames inherit it.
|
|
492
|
+
transientArrayService: new TransientArrayService()
|
|
267
493
|
});
|
|
268
494
|
this.state = {
|
|
269
495
|
name: 'UTILITY'
|
|
270
496
|
};
|
|
271
497
|
this.logger.debug(`Entered state ${this.state.name}`);
|
|
498
|
+
// Utility state anchors at whatever the anchor block store is pointing to (tracked as latest).
|
|
499
|
+
this.setLastCallContext(Fr.ZERO, anchorBlockHeader.globalVariables.timestamp);
|
|
272
500
|
}
|
|
273
501
|
exitTopLevelState() {
|
|
274
502
|
if (this.state.name != 'TOP_LEVEL') {
|
|
275
503
|
throw new Error(`Expected to be in state 'TOP_LEVEL', but got '${this.state.name}' instead`);
|
|
276
504
|
}
|
|
277
505
|
// 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
|
-
|
|
506
|
+
// them, the top level context does most of its work as it goes: it creates empty blocks (via `advanceBlocksBy`
|
|
507
|
+
// and `deploy`), creates blocks with transactions (via `privateCallNewFlow` and `publicCallNewFlow`), adds
|
|
508
|
+
// accounts to PXE (via `addAccount`), etc. This is a slight inconsistency in the working model of this class, but
|
|
509
|
+
// is not too bad. The `close` call below therefore only hands back the session-scoped values that a test
|
|
510
|
+
// sets directly at the top level, outside any contract execution (e.g. via `advanceTimestampBy`,
|
|
511
|
+
// `addAuthWitness`, `setTaggingSecretStrategy`). The oracle handler is discarded on every state transition,
|
|
512
|
+
// so the session must seed these values into the contexts it creates later.
|
|
513
|
+
// TODO: persisting authwits this way is quite unfortunate: they create a temporary utility context that would
|
|
514
|
+
// otherwise reset them, so we'd not be able to pass more than one per execution. Ideally authwits would be passed
|
|
515
|
+
// alongside a contract call instead of pre-seeded.
|
|
516
|
+
[this.nextBlockTimestamp, this.authwits, this.taggingSecretStrategy] = this.oracleHandler.close();
|
|
287
517
|
}
|
|
288
518
|
async exitPrivateState() {
|
|
289
519
|
if (this.state.name != 'PRIVATE') {
|
|
@@ -322,29 +552,47 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
|
322
552
|
}
|
|
323
553
|
utilityExecutorForContractSync(anchorBlock) {
|
|
324
554
|
return async (call, scopes)=>{
|
|
325
|
-
const
|
|
555
|
+
const anchoredContractData = new AnchoredContractData(this.contractStore, this.stateMachine.contractClassService, anchorBlock);
|
|
556
|
+
const entryPointArtifact = await anchoredContractData.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
|
|
557
|
+
if (!entryPointArtifact) {
|
|
558
|
+
throw new Error(`Cannot run function ${call.selector} on ${call.to}: the contract is not registered.`);
|
|
559
|
+
}
|
|
326
560
|
if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
|
|
327
561
|
throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
|
|
328
562
|
}
|
|
329
563
|
try {
|
|
564
|
+
const simulator = new WASMSimulator();
|
|
330
565
|
const oracle = new UtilityExecutionOracle({
|
|
331
|
-
|
|
566
|
+
callContext: CallContext.from({
|
|
567
|
+
msgSender: AztecAddress.NULL_MSG_SENDER,
|
|
568
|
+
contractAddress: call.to,
|
|
569
|
+
functionSelector: call.selector,
|
|
570
|
+
isStaticCall: true
|
|
571
|
+
}),
|
|
332
572
|
authWitnesses: [],
|
|
333
573
|
capsules: [],
|
|
334
574
|
anchorBlockHeader: anchorBlock,
|
|
335
|
-
|
|
575
|
+
anchoredContractData,
|
|
336
576
|
noteStore: this.noteStore,
|
|
337
577
|
keyStore: this.keyStore,
|
|
338
578
|
addressStore: this.addressStore,
|
|
339
579
|
aztecNode: this.stateMachine.node,
|
|
340
580
|
recipientTaggingStore: this.recipientTaggingStore,
|
|
341
|
-
|
|
342
|
-
|
|
581
|
+
taggingSecretSourcesStore: this.taggingSecretSourcesStore,
|
|
582
|
+
capsuleService: new CapsuleService(this.capsuleStore, scopes),
|
|
583
|
+
factService: new FactService(this.factStore, scopes),
|
|
343
584
|
privateEventStore: this.privateEventStore,
|
|
585
|
+
txResolver: this.stateMachine.txResolver,
|
|
586
|
+
contractSyncService: this.stateMachine.contractSyncService,
|
|
587
|
+
l2TipsStore: this.stateMachine.l2TipsProvider,
|
|
344
588
|
jobId: this.currentJobId,
|
|
345
|
-
scopes
|
|
589
|
+
scopes,
|
|
590
|
+
simulator,
|
|
591
|
+
utilityExecutor: this.utilityExecutorForContractSync(anchorBlock),
|
|
592
|
+
// Top-level utility entrypoint: gets a fresh store. Nested frames inherit it via UtilityExecutionOracle.
|
|
593
|
+
transientArrayService: new TransientArrayService()
|
|
346
594
|
});
|
|
347
|
-
await
|
|
595
|
+
await simulator.executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, buildACIRCallback(oracle)).catch((err)=>{
|
|
348
596
|
err.message = resolveAssertionMessageFromError(err, entryPointArtifact);
|
|
349
597
|
throw new ExecutionError(err.message, {
|
|
350
598
|
contractAddress: call.to,
|
|
@@ -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"}
|
|
@@ -12,10 +12,10 @@ import { BlockHeader } from '@aztec/stdlib/tx';
|
|
|
12
12
|
*/ export function getSingleTxBlockRequestHash(blockNumber) {
|
|
13
13
|
return new Fr(blockNumber + 9999); // Why does this need to be a high number? Why do small numbered nullifiers already exist?
|
|
14
14
|
}
|
|
15
|
-
export async function insertTxEffectIntoWorldTrees(txEffect, worldTrees) {
|
|
15
|
+
export async function insertTxEffectIntoWorldTrees(txEffect, worldTrees, l1ToL2Messages = []) {
|
|
16
16
|
await worldTrees.appendLeaves(MerkleTreeId.NOTE_HASH_TREE, padArrayEnd(txEffect.noteHashes, Fr.ZERO, MAX_NOTE_HASHES_PER_TX));
|
|
17
17
|
await worldTrees.batchInsert(MerkleTreeId.NULLIFIER_TREE, padArrayEnd(txEffect.nullifiers, Fr.ZERO, MAX_NULLIFIERS_PER_TX).map((nullifier)=>nullifier.toBuffer()), NULLIFIER_SUBTREE_HEIGHT);
|
|
18
|
-
await worldTrees.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, padArrayEnd(
|
|
18
|
+
await worldTrees.appendLeaves(MerkleTreeId.L1_TO_L2_MESSAGE_TREE, padArrayEnd(l1ToL2Messages, Fr.ZERO, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP));
|
|
19
19
|
// We do not need to add public data writes because we apply them as we go.
|
|
20
20
|
}
|
|
21
21
|
export async function makeTXEBlockHeader(worldTrees, globalVariables) {
|