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