@aztec/txe 0.0.1-commit.86469d5 → 0.0.1-commit.8655d4a
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/ContractClassRegistry-KKNT527R.js +3 -0
- package/dest/ContractClassRegistry-KKNT527R.js.map +7 -0
- package/dest/ContractInstanceRegistry-GSKBNL3Q.js +3 -0
- package/dest/ContractInstanceRegistry-GSKBNL3Q.js.map +7 -0
- package/dest/FeeJuice-GUJ5O6GB.js +3 -0
- package/dest/FeeJuice-GUJ5O6GB.js.map +7 -0
- package/dest/MultiCallEntrypoint-ZQPCKVKL.js +3 -0
- package/dest/MultiCallEntrypoint-ZQPCKVKL.js.map +7 -0
- package/dest/SchnorrAccount-QIXE5DXA.js +3 -0
- package/dest/SchnorrAccount-QIXE5DXA.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 +32 -0
- package/dest/bin/index.js +3 -30
- package/dest/bin/index.js.map +7 -0
- package/dest/chunk-BJVAAXNA.js +3 -0
- package/dest/chunk-BJVAAXNA.js.map +7 -0
- package/dest/chunk-DF6RMOC6.js +304 -0
- package/dest/chunk-DF6RMOC6.js.map +7 -0
- package/dest/chunk-PPJTNNUG.js +265 -0
- package/dest/chunk-PPJTNNUG.js.map +7 -0
- package/dest/constants.d.ts +3 -1
- package/dest/constants.d.ts.map +1 -1
- package/dest/constants.js +5 -0
- package/dest/dispatcher_pool.d.ts +67 -0
- package/dest/dispatcher_pool.d.ts.map +1 -0
- package/dest/dispatcher_pool.js +284 -0
- package/dest/index.d.ts +188 -7
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +148 -75
- package/dest/metafile.json +38147 -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 +40 -28
- package/dest/oracle/interfaces.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.d.ts +18 -13
- package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.js +27 -12
- package/dest/oracle/txe_oracle_top_level_context.d.ts +39 -24
- package/dest/oracle/txe_oracle_top_level_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_top_level_context.js +205 -78
- 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 +140 -84
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +587 -239
- package/dest/server.bundle.js +3 -0
- package/dest/server.bundle.js.map +7 -0
- package/dest/state_machine/archiver.d.ts +4 -4
- package/dest/state_machine/archiver.d.ts.map +1 -1
- package/dest/state_machine/archiver.js +24 -20
- package/dest/state_machine/dummy_p2p_client.d.ts +26 -16
- package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
- package/dest/state_machine/dummy_p2p_client.js +44 -20
- package/dest/state_machine/global_variable_builder.d.ts +9 -4
- package/dest/state_machine/global_variable_builder.d.ts.map +1 -1
- package/dest/state_machine/global_variable_builder.js +9 -3
- package/dest/state_machine/index.d.ts +10 -6
- package/dest/state_machine/index.d.ts.map +1 -1
- package/dest/state_machine/index.js +35 -12
- package/dest/state_machine/mock_epoch_cache.d.ts +20 -3
- package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
- package/dest/state_machine/mock_epoch_cache.js +39 -2
- package/dest/state_machine/synchronizer.d.ts +5 -5
- package/dest/state_machine/synchronizer.d.ts.map +1 -1
- package/dest/state_machine/synchronizer.js +4 -4
- package/dest/txe_oracle_version.d.ts +17 -0
- package/dest/txe_oracle_version.d.ts.map +1 -0
- package/dest/txe_oracle_version.js +14 -0
- package/dest/txe_session.d.ts +71 -10
- package/dest/txe_session.d.ts.map +1 -1
- package/dest/txe_session.js +227 -40
- package/dest/utils/block_creation.d.ts +1 -1
- package/dest/utils/block_creation.d.ts.map +1 -1
- package/dest/utils/block_creation.js +3 -1
- package/dest/utils/encoding.d.ts +191 -0
- package/dest/utils/encoding.d.ts.map +1 -0
- package/dest/{util → utils}/encoding.js +7 -2
- package/dest/{util → utils}/expected_failure_error.d.ts +1 -1
- package/dest/utils/expected_failure_error.d.ts.map +1 -0
- package/dest/{util → utils}/txe_account_store.d.ts +1 -1
- package/dest/utils/txe_account_store.d.ts.map +1 -0
- package/dest/utils/txe_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 +6 -25
- 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 +37 -21
- package/src/bin/check_txe_oracle_version.ts +37 -0
- package/src/bin/index.ts +11 -2
- package/src/constants.ts +6 -0
- package/src/dispatcher_pool.ts +316 -0
- package/src/index.ts +166 -80
- package/src/msgpackr_fr_extension.ts +23 -0
- package/src/oracle/interfaces.ts +48 -34
- package/src/oracle/txe_oracle_public_context.ts +42 -12
- package/src/oracle/txe_oracle_top_level_context.ts +231 -144
- package/src/oracle/txe_private_execution_oracle.ts +30 -0
- package/src/rpc_server.ts +87 -0
- package/src/rpc_translator.ts +662 -316
- package/src/state_machine/archiver.ts +35 -18
- package/src/state_machine/dummy_p2p_client.ts +70 -32
- package/src/state_machine/global_variable_builder.ts +18 -3
- package/src/state_machine/index.ts +48 -13
- package/src/state_machine/mock_epoch_cache.ts +51 -3
- package/src/state_machine/synchronizer.ts +5 -5
- package/src/txe_oracle_version.ts +17 -0
- package/src/txe_session.ts +324 -90
- package/src/utils/block_creation.ts +3 -1
- package/src/{util → utils}/encoding.ts +8 -2
- package/src/{util → utils}/txe_public_contract_data_source.ts +10 -38
- 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/src/util/txe_contract_store.ts +0 -36
- /package/dest/{util → utils}/expected_failure_error.js +0 -0
- /package/dest/{util → utils}/txe_account_store.js +0 -0
- /package/src/{util → utils}/expected_failure_error.ts +0 -0
- /package/src/{util → utils}/txe_account_store.ts +0 -0
package/dest/txe_session.js
CHANGED
|
@@ -2,31 +2,42 @@ import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
|
2
2
|
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
3
3
|
import { createLogger } from '@aztec/foundation/log';
|
|
4
4
|
import { KeyStore } from '@aztec/key-store';
|
|
5
|
-
import {
|
|
6
|
-
import { AddressStore, CapsuleStore, JobCoordinator, NoteService, NoteStore, PrivateEventStore, RecipientTaggingStore, SenderAddressBookStore, SenderTaggingStore } from '@aztec/pxe/server';
|
|
7
|
-
import { ExecutionNoteCache, ExecutionTaggingIndexCache, HashedValuesCache, Oracle,
|
|
5
|
+
import { openEphemeralStore } from '@aztec/kv-store/lmdb-v2';
|
|
6
|
+
import { AddressStore, AnchorBlockStore, CapsuleService, CapsuleStore, JobCoordinator, NoteService, NoteStore, PrivateEventStore, RecipientTaggingStore, SenderAddressBookStore, SenderTaggingStore } from '@aztec/pxe/server';
|
|
7
|
+
import { ExecutionNoteCache, ExecutionTaggingIndexCache, HashedValuesCache, Oracle, UtilityExecutionOracle } from '@aztec/pxe/simulator';
|
|
8
8
|
import { ExecutionError, WASMSimulator, createSimulationError, extractCallStack, resolveAssertionMessageFromError, toACVMWitness } from '@aztec/simulator/client';
|
|
9
|
+
import { STANDARD_AUTH_REGISTRY_ADDRESS } from '@aztec/standard-contracts/auth-registry/constants';
|
|
9
10
|
import { FunctionSelector, FunctionType } from '@aztec/stdlib/abi';
|
|
10
11
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
11
|
-
import { GasSettings } from '@aztec/stdlib/gas';
|
|
12
12
|
import { computeProtocolNullifier } from '@aztec/stdlib/hash';
|
|
13
13
|
import { makeGlobalVariables } from '@aztec/stdlib/testing';
|
|
14
|
-
import { CallContext, TxContext } from '@aztec/stdlib/tx';
|
|
14
|
+
import { CallContext, OFFCHAIN_MESSAGE_IDENTIFIER, TxContext } from '@aztec/stdlib/tx';
|
|
15
15
|
import { z } from 'zod';
|
|
16
|
-
import { DEFAULT_ADDRESS } from './constants.js';
|
|
16
|
+
import { DEFAULT_ADDRESS, MAX_OFFCHAIN_EFFECTS_PER_TXE_QUERY, MAX_OFFCHAIN_EFFECT_LEN } from './constants.js';
|
|
17
17
|
import { TXEOraclePublicContext } from './oracle/txe_oracle_public_context.js';
|
|
18
18
|
import { TXEOracleTopLevelContext } from './oracle/txe_oracle_top_level_context.js';
|
|
19
|
+
import { TXEPrivateExecutionOracle } from './oracle/txe_private_execution_oracle.js';
|
|
19
20
|
import { RPCTranslator } from './rpc_translator.js';
|
|
21
|
+
import { TXEArchiver } from './state_machine/archiver.js';
|
|
20
22
|
import { TXEStateMachine } from './state_machine/index.js';
|
|
21
|
-
import {
|
|
22
|
-
import { TXEContractStore } from './util/txe_contract_store.js';
|
|
23
|
+
import { TXE_ORACLE_VERSION_MAJOR, TXE_ORACLE_VERSION_MINOR } from './txe_oracle_version.js';
|
|
23
24
|
import { getSingleTxBlockRequestHash, insertTxEffectIntoWorldTrees, makeTXEBlock } from './utils/block_creation.js';
|
|
24
25
|
import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
26
|
+
import { TXEAccountStore } from './utils/txe_account_store.js';
|
|
27
|
+
function emptyLastCallState() {
|
|
28
|
+
return {
|
|
29
|
+
offchainEffects: [],
|
|
30
|
+
queried: false,
|
|
31
|
+
txHash: Fr.ZERO,
|
|
32
|
+
anchorBlockTimestamp: 0n
|
|
33
|
+
};
|
|
34
|
+
}
|
|
25
35
|
/**
|
|
26
36
|
* A `TXESession` corresponds to a Noir `#[test]` function, and handles all of its oracle calls, stores test-specific
|
|
27
37
|
* state, etc., independent of all other tests running in parallel.
|
|
28
38
|
*/ export class TXESession {
|
|
29
39
|
logger;
|
|
40
|
+
sessionStore;
|
|
30
41
|
stateMachine;
|
|
31
42
|
oracleHandler;
|
|
32
43
|
contractStore;
|
|
@@ -46,8 +57,12 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
|
46
57
|
nextBlockTimestamp;
|
|
47
58
|
state;
|
|
48
59
|
authwits;
|
|
49
|
-
|
|
60
|
+
lastCallInfo;
|
|
61
|
+
txeOracleVersion;
|
|
62
|
+
disposed;
|
|
63
|
+
constructor(logger, sessionStore, stateMachine, oracleHandler, contractStore, noteStore, keyStore, addressStore, accountStore, senderTaggingStore, recipientTaggingStore, senderAddressBookStore, capsuleStore, privateEventStore, jobCoordinator, currentJobId, chainId, version, nextBlockTimestamp){
|
|
50
64
|
this.logger = logger;
|
|
65
|
+
this.sessionStore = sessionStore;
|
|
51
66
|
this.stateMachine = stateMachine;
|
|
52
67
|
this.oracleHandler = oracleHandler;
|
|
53
68
|
this.contractStore = contractStore;
|
|
@@ -69,12 +84,36 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
|
69
84
|
name: 'TOP_LEVEL'
|
|
70
85
|
};
|
|
71
86
|
this.authwits = new Map();
|
|
87
|
+
this.lastCallInfo = emptyLastCallState();
|
|
88
|
+
this.disposed = false;
|
|
72
89
|
}
|
|
73
|
-
|
|
74
|
-
|
|
90
|
+
/**
|
|
91
|
+
* Closes the per-session `txe-session` LMDB and the `NativeWorldStateService` .
|
|
92
|
+
* Called via IPC when the dispatcher detects the end of a test. Idempotent.
|
|
93
|
+
*/ async dispose() {
|
|
94
|
+
if (this.disposed) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
this.disposed = true;
|
|
98
|
+
try {
|
|
99
|
+
await this.stateMachine.synchronizer.nativeWorldStateService.close();
|
|
100
|
+
} catch (err) {
|
|
101
|
+
this.logger.warn(`Error closing native world state during session dispose`, err);
|
|
102
|
+
}
|
|
103
|
+
try {
|
|
104
|
+
await this.sessionStore.close();
|
|
105
|
+
} catch (err) {
|
|
106
|
+
this.logger.warn(`Error closing session LMDB during dispose`, err);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
static async init(contractStore) {
|
|
110
|
+
// Size LMDB's reader slots to the libuv pool (capped to 2 in bin/index.ts via
|
|
111
|
+
// HARDWARE_CONCURRENCY): each native LMDB read needs a libuv worker thread to run, so any
|
|
112
|
+
// slot beyond the pool size would sit idle while still consuming a semaphore + reader-table
|
|
113
|
+
// entry per session.
|
|
114
|
+
const store = await openEphemeralStore('txe-session', undefined, 2);
|
|
75
115
|
const addressStore = new AddressStore(store);
|
|
76
116
|
const privateEventStore = new PrivateEventStore(store);
|
|
77
|
-
const contractStore = new TXEContractStore(store);
|
|
78
117
|
const noteStore = new NoteStore(store);
|
|
79
118
|
const senderTaggingStore = new SenderTaggingStore(store);
|
|
80
119
|
const recipientTaggingStore = new RecipientTaggingStore(store);
|
|
@@ -82,7 +121,6 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
|
82
121
|
const capsuleStore = new CapsuleStore(store);
|
|
83
122
|
const keyStore = new KeyStore(store);
|
|
84
123
|
const accountStore = new TXEAccountStore(store);
|
|
85
|
-
// Create job coordinator and register staged stores
|
|
86
124
|
const jobCoordinator = new JobCoordinator(store);
|
|
87
125
|
jobCoordinator.registerStores([
|
|
88
126
|
capsuleStore,
|
|
@@ -91,19 +129,19 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
|
91
129
|
privateEventStore,
|
|
92
130
|
noteStore
|
|
93
131
|
]);
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
await contractStore.addContractInstance(instance);
|
|
98
|
-
}
|
|
99
|
-
const stateMachine = await TXEStateMachine.create(store);
|
|
132
|
+
const archiver = new TXEArchiver(store);
|
|
133
|
+
const anchorBlockStore = new AnchorBlockStore(store);
|
|
134
|
+
const stateMachine = await TXEStateMachine.create(archiver, anchorBlockStore, contractStore, noteStore);
|
|
100
135
|
const nextBlockTimestamp = BigInt(Math.floor(new Date().getTime() / 1000));
|
|
101
136
|
const version = new Fr(await stateMachine.node.getVersion());
|
|
102
137
|
const chainId = new Fr(await stateMachine.node.getChainId());
|
|
103
138
|
const initialJobId = jobCoordinator.beginJob();
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
139
|
+
const logger = createLogger('txe:session');
|
|
140
|
+
const topLevelOracleHandler = new TXEOracleTopLevelContext(stateMachine, contractStore, noteStore, keyStore, addressStore, accountStore, senderTaggingStore, recipientTaggingStore, senderAddressBookStore, capsuleStore, privateEventStore, nextBlockTimestamp, version, chainId, new Map());
|
|
141
|
+
await topLevelOracleHandler.mineDeploymentNullifiers([
|
|
142
|
+
STANDARD_AUTH_REGISTRY_ADDRESS
|
|
143
|
+
]);
|
|
144
|
+
return new TXESession(logger, store, stateMachine, topLevelOracleHandler, contractStore, noteStore, keyStore, addressStore, accountStore, senderTaggingStore, recipientTaggingStore, senderAddressBookStore, capsuleStore, privateEventStore, jobCoordinator, initialJobId, version, chainId, nextBlockTimestamp);
|
|
107
145
|
}
|
|
108
146
|
/**
|
|
109
147
|
* Processes an oracle function invoked by the Noir test associated to this session.
|
|
@@ -118,7 +156,15 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
|
118
156
|
return translator[validatedFunctionName](...inputs);
|
|
119
157
|
} catch (error) {
|
|
120
158
|
if (error instanceof z.ZodError) {
|
|
121
|
-
|
|
159
|
+
let versionHint;
|
|
160
|
+
if (!this.txeOracleVersion) {
|
|
161
|
+
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';
|
|
162
|
+
} else if (this.txeOracleVersion.minor > TXE_ORACLE_VERSION_MINOR) {
|
|
163
|
+
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`;
|
|
164
|
+
} else {
|
|
165
|
+
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`;
|
|
166
|
+
}
|
|
167
|
+
throw new Error(`Unknown oracle '${functionName}'.${versionHint}`);
|
|
122
168
|
} else if (error instanceof Error) {
|
|
123
169
|
throw new Error(`Execution error while processing function ${functionName} in state ${this.state.name}: ${error.message}`);
|
|
124
170
|
} else {
|
|
@@ -126,6 +172,68 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
|
126
172
|
}
|
|
127
173
|
}
|
|
128
174
|
}
|
|
175
|
+
getCurrentJob() {
|
|
176
|
+
return this.currentJobId;
|
|
177
|
+
}
|
|
178
|
+
/** Commits the current job and begins a new one. Returns the new job ID. */ async cycleJob() {
|
|
179
|
+
await this.jobCoordinator.commitJob(this.currentJobId);
|
|
180
|
+
this.currentJobId = this.jobCoordinator.beginJob();
|
|
181
|
+
return this.currentJobId;
|
|
182
|
+
}
|
|
183
|
+
resetLastCall() {
|
|
184
|
+
const notQueriedMessageCount = this.lastCallInfo.queried ? 0 : this.lastCallInfo.offchainEffects.filter((payload)=>payload[0]?.equals(OFFCHAIN_MESSAGE_IDENTIFIER)).length;
|
|
185
|
+
if (notQueriedMessageCount > 0) {
|
|
186
|
+
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.`);
|
|
187
|
+
}
|
|
188
|
+
this.lastCallInfo = emptyLastCallState();
|
|
189
|
+
}
|
|
190
|
+
recordOffchainEffect(data) {
|
|
191
|
+
this.lastCallInfo.offchainEffects.push(data);
|
|
192
|
+
}
|
|
193
|
+
setLastCallContext(txHash, anchorBlockTimestamp) {
|
|
194
|
+
this.lastCallInfo.txHash = txHash;
|
|
195
|
+
this.lastCallInfo.anchorBlockTimestamp = anchorBlockTimestamp;
|
|
196
|
+
}
|
|
197
|
+
async withTopLevelCallTracking(work) {
|
|
198
|
+
this.resetLastCall();
|
|
199
|
+
// Capture the anchor *before* `work` runs: private/public executor calls mine a new block as a
|
|
200
|
+
// side effect, and that block's timestamp should not be attributed to this call's anchor.
|
|
201
|
+
const anchorBlockTimestamp = (await this.stateMachine.node.getBlockData('latest')).header.globalVariables.timestamp;
|
|
202
|
+
const { result, txHash } = await work();
|
|
203
|
+
this.setLastCallContext(txHash ?? Fr.ZERO, anchorBlockTimestamp);
|
|
204
|
+
return result;
|
|
205
|
+
}
|
|
206
|
+
getLastCallOffchainEffects() {
|
|
207
|
+
this.lastCallInfo.queried = true;
|
|
208
|
+
const effects = this.lastCallInfo.offchainEffects;
|
|
209
|
+
if (effects.length > MAX_OFFCHAIN_EFFECTS_PER_TXE_QUERY) {
|
|
210
|
+
throw new Error(`${effects.length} offchain effects exceed max ${MAX_OFFCHAIN_EFFECTS_PER_TXE_QUERY}`);
|
|
211
|
+
}
|
|
212
|
+
if (effects.some((e)=>e.length > MAX_OFFCHAIN_EFFECT_LEN)) {
|
|
213
|
+
throw new Error(`Some offchain effect has length larger than max ${MAX_OFFCHAIN_EFFECT_LEN}`);
|
|
214
|
+
}
|
|
215
|
+
return {
|
|
216
|
+
effects
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
getLastCallContext() {
|
|
220
|
+
const { txHash, anchorBlockTimestamp } = this.lastCallInfo;
|
|
221
|
+
return {
|
|
222
|
+
txHash,
|
|
223
|
+
anchorBlockTimestamp
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
setTxeOracleVersion(major, minor) {
|
|
227
|
+
if (major !== TXE_ORACLE_VERSION_MAJOR) {
|
|
228
|
+
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.';
|
|
229
|
+
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})`);
|
|
230
|
+
}
|
|
231
|
+
this.txeOracleVersion = {
|
|
232
|
+
major,
|
|
233
|
+
minor
|
|
234
|
+
};
|
|
235
|
+
this.logger.debug(`Test compiled with test oracle version ${major}.${minor}`);
|
|
236
|
+
}
|
|
129
237
|
async enterTopLevelState() {
|
|
130
238
|
switch(this.state.name){
|
|
131
239
|
case 'PRIVATE':
|
|
@@ -153,22 +261,22 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
|
153
261
|
}
|
|
154
262
|
}
|
|
155
263
|
// Commit all staged stores from the job that was just completed, then begin a new job
|
|
156
|
-
await this.
|
|
157
|
-
this.
|
|
158
|
-
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);
|
|
264
|
+
await this.cycleJob();
|
|
265
|
+
this.oracleHandler = new TXEOracleTopLevelContext(this.stateMachine, this.contractStore, this.noteStore, this.keyStore, this.addressStore, this.accountStore, this.senderTaggingStore, this.recipientTaggingStore, this.senderAddressBookStore, this.capsuleStore, this.privateEventStore, this.nextBlockTimestamp, this.version, this.chainId, this.authwits);
|
|
159
266
|
this.state = {
|
|
160
267
|
name: 'TOP_LEVEL'
|
|
161
268
|
};
|
|
162
269
|
this.logger.debug(`Entered state ${this.state.name}`);
|
|
163
270
|
}
|
|
164
|
-
async enterPrivateState(contractAddress = DEFAULT_ADDRESS, anchorBlockNumber) {
|
|
271
|
+
async enterPrivateState(contractAddress = DEFAULT_ADDRESS, anchorBlockNumber, gasSettings) {
|
|
165
272
|
this.exitTopLevelState();
|
|
273
|
+
this.resetLastCall();
|
|
166
274
|
// Private execution has two associated block numbers: the anchor block (i.e. the historical block that is used to
|
|
167
275
|
// build the proof), and the *next* block, i.e. the one we'll create once the execution ends, and which will contain
|
|
168
276
|
// a single transaction with the effects of what was done in the test.
|
|
169
|
-
const anchorBlock = await this.stateMachine.node.
|
|
170
|
-
await new NoteService(this.noteStore, this.stateMachine.node, anchorBlock, this.currentJobId).syncNoteNullifiers(contractAddress);
|
|
171
|
-
const latestBlock = await this.stateMachine.node.
|
|
277
|
+
const anchorBlock = await this.stateMachine.node.getBlock(anchorBlockNumber ?? 'latest').then((b)=>b?.header);
|
|
278
|
+
await new NoteService(this.noteStore, this.stateMachine.node, anchorBlock, this.currentJobId).syncNoteNullifiers(contractAddress, await this.keyStore.getAccounts());
|
|
279
|
+
const latestBlock = await this.stateMachine.node.getBlock('latest').then((b)=>b?.header);
|
|
172
280
|
const nextBlockGlobalVariables = makeGlobalVariables(undefined, {
|
|
173
281
|
blockNumber: BlockNumber(latestBlock.globalVariables.blockNumber + 1),
|
|
174
282
|
timestamp: this.nextBlockTimestamp,
|
|
@@ -180,7 +288,34 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
|
180
288
|
const noteCache = new ExecutionNoteCache(protocolNullifier);
|
|
181
289
|
const taggingIndexCache = new ExecutionTaggingIndexCache();
|
|
182
290
|
const utilityExecutor = this.utilityExecutorForContractSync(anchorBlock);
|
|
183
|
-
this.oracleHandler = new
|
|
291
|
+
this.oracleHandler = new TXEPrivateExecutionOracle({
|
|
292
|
+
argsHash: Fr.ZERO,
|
|
293
|
+
txContext: new TxContext(this.chainId, this.version, gasSettings),
|
|
294
|
+
callContext: new CallContext(AztecAddress.ZERO, contractAddress, FunctionSelector.empty(), false),
|
|
295
|
+
anchorBlockHeader: anchorBlock,
|
|
296
|
+
utilityExecutor,
|
|
297
|
+
authWitnesses: [],
|
|
298
|
+
capsules: [],
|
|
299
|
+
executionCache: new HashedValuesCache(),
|
|
300
|
+
noteCache,
|
|
301
|
+
taggingIndexCache,
|
|
302
|
+
contractStore: this.contractStore,
|
|
303
|
+
noteStore: this.noteStore,
|
|
304
|
+
keyStore: this.keyStore,
|
|
305
|
+
addressStore: this.addressStore,
|
|
306
|
+
aztecNode: this.stateMachine.node,
|
|
307
|
+
senderTaggingStore: this.senderTaggingStore,
|
|
308
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
309
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
310
|
+
capsuleService: new CapsuleService(this.capsuleStore, await this.keyStore.getAccounts()),
|
|
311
|
+
privateEventStore: this.privateEventStore,
|
|
312
|
+
contractSyncService: this.stateMachine.contractSyncService,
|
|
313
|
+
l2TipsStore: this.stateMachine.l2TipsProvider,
|
|
314
|
+
jobId: this.currentJobId,
|
|
315
|
+
scopes: await this.keyStore.getAccounts(),
|
|
316
|
+
messageContextService: this.stateMachine.messageContextService,
|
|
317
|
+
simulator: new WASMSimulator()
|
|
318
|
+
});
|
|
184
319
|
// We store the note and tagging index caches fed into the PrivateExecutionOracle (along with some other auxiliary
|
|
185
320
|
// data) in order to refer to it later, mimicking the way this object is used by the ContractFunctionSimulator. The
|
|
186
321
|
// difference resides in that the simulator has all information needed in order to run the simulation, while ours
|
|
@@ -193,15 +328,19 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
|
193
328
|
taggingIndexCache
|
|
194
329
|
};
|
|
195
330
|
this.logger.debug(`Entered state ${this.state.name}`);
|
|
331
|
+
// Record the *resolved* anchor's timestamp — if the caller pinned the anchor to a past block
|
|
332
|
+
// via `anchorBlockNumber`, "latest" would be the wrong anchor for offchain-message semantics.
|
|
333
|
+
this.setLastCallContext(Fr.ZERO, anchorBlock.globalVariables.timestamp);
|
|
196
334
|
return this.oracleHandler.getPrivateContextInputs();
|
|
197
335
|
}
|
|
198
336
|
async enterPublicState(contractAddress) {
|
|
199
337
|
this.exitTopLevelState();
|
|
338
|
+
this.resetLastCall();
|
|
200
339
|
// The PublicContext will create a block with a single transaction in it, containing the effects of what was done in
|
|
201
340
|
// the test. The block therefore gets the *next* block number and timestamp.
|
|
202
|
-
const
|
|
341
|
+
const latestHeader = (await this.stateMachine.node.getBlockData('latest')).header;
|
|
203
342
|
const globalVariables = makeGlobalVariables(undefined, {
|
|
204
|
-
blockNumber: BlockNumber(
|
|
343
|
+
blockNumber: BlockNumber(latestHeader.globalVariables.blockNumber + 1),
|
|
205
344
|
timestamp: this.nextBlockTimestamp,
|
|
206
345
|
version: this.version,
|
|
207
346
|
chainId: this.chainId
|
|
@@ -211,21 +350,47 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
|
211
350
|
name: 'PUBLIC'
|
|
212
351
|
};
|
|
213
352
|
this.logger.debug(`Entered state ${this.state.name}`);
|
|
353
|
+
// Public state is anchored at the latest block.
|
|
354
|
+
this.setLastCallContext(Fr.ZERO, latestHeader.globalVariables.timestamp);
|
|
214
355
|
}
|
|
215
356
|
async enterUtilityState(contractAddress = DEFAULT_ADDRESS) {
|
|
216
357
|
this.exitTopLevelState();
|
|
358
|
+
this.resetLastCall();
|
|
217
359
|
const anchorBlockHeader = await this.stateMachine.anchorBlockStore.getBlockHeader();
|
|
218
360
|
// There is no automatic message discovery and contract-driven syncing process in inlined private or utility
|
|
219
361
|
// contexts, which means that known nullifiers are also not searched for, since it is during the tagging sync that
|
|
220
362
|
// we perform this. We therefore search for known nullifiers now, as otherwise notes that were nullified would not
|
|
221
363
|
// be removed from the database.
|
|
222
364
|
// TODO(#12553): make the synchronizer sync here instead and remove this
|
|
223
|
-
await new NoteService(this.noteStore, this.stateMachine.node, anchorBlockHeader, this.currentJobId).syncNoteNullifiers(contractAddress);
|
|
224
|
-
this.oracleHandler = new UtilityExecutionOracle(
|
|
365
|
+
await new NoteService(this.noteStore, this.stateMachine.node, anchorBlockHeader, this.currentJobId).syncNoteNullifiers(contractAddress, await this.keyStore.getAccounts());
|
|
366
|
+
this.oracleHandler = new UtilityExecutionOracle({
|
|
367
|
+
contractAddress,
|
|
368
|
+
authWitnesses: [],
|
|
369
|
+
capsules: [],
|
|
370
|
+
anchorBlockHeader,
|
|
371
|
+
contractStore: this.contractStore,
|
|
372
|
+
noteStore: this.noteStore,
|
|
373
|
+
keyStore: this.keyStore,
|
|
374
|
+
addressStore: this.addressStore,
|
|
375
|
+
aztecNode: this.stateMachine.node,
|
|
376
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
377
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
378
|
+
capsuleService: new CapsuleService(this.capsuleStore, await this.keyStore.getAccounts()),
|
|
379
|
+
privateEventStore: this.privateEventStore,
|
|
380
|
+
messageContextService: this.stateMachine.messageContextService,
|
|
381
|
+
contractSyncService: this.stateMachine.contractSyncService,
|
|
382
|
+
l2TipsStore: this.stateMachine.l2TipsProvider,
|
|
383
|
+
jobId: this.currentJobId,
|
|
384
|
+
scopes: await this.keyStore.getAccounts(),
|
|
385
|
+
simulator: new WASMSimulator(),
|
|
386
|
+
utilityExecutor: this.utilityExecutorForContractSync(anchorBlockHeader)
|
|
387
|
+
});
|
|
225
388
|
this.state = {
|
|
226
389
|
name: 'UTILITY'
|
|
227
390
|
};
|
|
228
391
|
this.logger.debug(`Entered state ${this.state.name}`);
|
|
392
|
+
// Utility state anchors at whatever the anchor block store is pointing to (tracked as latest).
|
|
393
|
+
this.setLastCallContext(Fr.ZERO, anchorBlockHeader.globalVariables.timestamp);
|
|
229
394
|
}
|
|
230
395
|
exitTopLevelState() {
|
|
231
396
|
if (this.state.name != 'TOP_LEVEL') {
|
|
@@ -233,8 +398,8 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
|
233
398
|
}
|
|
234
399
|
// Note that while all public and private contexts do is build a single block that we then process when exiting
|
|
235
400
|
// those, the top level context performs a large number of actions not captured in the following 'close' call. Among
|
|
236
|
-
// others, it will create empty blocks (via `
|
|
237
|
-
// `
|
|
401
|
+
// others, it will create empty blocks (via `advanceBlocksBy` and `deploy`), create blocks with transactions via
|
|
402
|
+
// `privateCallNewFlow` and `publicCallNewFlow`, add accounts to PXE via `addAccount`, etc. This is a
|
|
238
403
|
// slight inconsistency in the working model of this class, but is not too bad.
|
|
239
404
|
// TODO: it's quite unfortunate that we need to capture the authwits created to later pass them again when the top
|
|
240
405
|
// level context is re-created. This is because authwits create a temporary utility context that'd otherwise reset
|
|
@@ -278,14 +443,36 @@ import { makeTxEffect } from './utils/tx_effect_creation.js';
|
|
|
278
443
|
}
|
|
279
444
|
}
|
|
280
445
|
utilityExecutorForContractSync(anchorBlock) {
|
|
281
|
-
return async (call)=>{
|
|
446
|
+
return async (call, scopes)=>{
|
|
282
447
|
const entryPointArtifact = await this.contractStore.getFunctionArtifactWithDebugMetadata(call.to, call.selector);
|
|
283
448
|
if (entryPointArtifact.functionType !== FunctionType.UTILITY) {
|
|
284
449
|
throw new Error(`Cannot run ${entryPointArtifact.functionType} function as utility`);
|
|
285
450
|
}
|
|
286
451
|
try {
|
|
287
|
-
const
|
|
288
|
-
|
|
452
|
+
const simulator = new WASMSimulator();
|
|
453
|
+
const oracle = new UtilityExecutionOracle({
|
|
454
|
+
contractAddress: call.to,
|
|
455
|
+
authWitnesses: [],
|
|
456
|
+
capsules: [],
|
|
457
|
+
anchorBlockHeader: anchorBlock,
|
|
458
|
+
contractStore: this.contractStore,
|
|
459
|
+
noteStore: this.noteStore,
|
|
460
|
+
keyStore: this.keyStore,
|
|
461
|
+
addressStore: this.addressStore,
|
|
462
|
+
aztecNode: this.stateMachine.node,
|
|
463
|
+
recipientTaggingStore: this.recipientTaggingStore,
|
|
464
|
+
senderAddressBookStore: this.senderAddressBookStore,
|
|
465
|
+
capsuleService: new CapsuleService(this.capsuleStore, scopes),
|
|
466
|
+
privateEventStore: this.privateEventStore,
|
|
467
|
+
messageContextService: this.stateMachine.messageContextService,
|
|
468
|
+
contractSyncService: this.stateMachine.contractSyncService,
|
|
469
|
+
l2TipsStore: this.stateMachine.l2TipsProvider,
|
|
470
|
+
jobId: this.currentJobId,
|
|
471
|
+
scopes,
|
|
472
|
+
simulator,
|
|
473
|
+
utilityExecutor: this.utilityExecutorForContractSync(anchorBlock)
|
|
474
|
+
});
|
|
475
|
+
await simulator.executeUserCircuit(toACVMWitness(0, call.args), entryPointArtifact, new Oracle(oracle).toACIRCallback()).catch((err)=>{
|
|
289
476
|
err.message = resolveAssertionMessageFromError(err, entryPointArtifact);
|
|
290
477
|
throw new ExecutionError(err.message, {
|
|
291
478
|
contractAddress: call.to,
|
|
@@ -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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYmxvY2tfY3JlYXRpb24uZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy91dGlscy9ibG9ja19jcmVhdGlvbi50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFNQSxPQUFPLEVBQUUsV0FBVyxFQUEyQyxNQUFNLGlDQUFpQyxDQUFDO0FBRXZHLE9BQU8sRUFBRSxFQUFFLEVBQUUsTUFBTSxnQ0FBZ0MsQ0FBQztBQUNwRCxPQUFPLEVBQVEsT0FBTyxFQUFFLE1BQU0scUJBQXFCLENBQUM7QUFDcEQsT0FBTyxFQUF3QyxLQUFLLHlCQUF5QixFQUFFLE1BQU0scUJBQXFCLENBQUM7QUFDM0csT0FBTyxFQUFFLFdBQVcsRUFBRSxlQUFlLEVBQUUsUUFBUSxFQUFFLE1BQU0sa0JBQWtCLENBQUM7QUFFMUU7Ozs7R0FJRztBQUNILHdCQUFnQiwyQkFBMkIsQ0FBQyxXQUFXLEVBQUUsV0FBVyxHQUFHLEVBQUUsQ0FFeEU7QUFFRCx3QkFBc0IsNEJBQTRCLENBQ2hELFFBQVEsRUFBRSxRQUFRLEVBQ2xCLFVBQVUsRUFBRSx5QkFBeUIsR0FDcEMsT0FBTyxDQUFDLElBQUksQ0FBQyxDQWtCZjtBQUVELHdCQUFzQixrQkFBa0IsQ0FDdEMsVUFBVSxFQUFFLHlCQUF5QixFQUNyQyxlQUFlLEVBQUUsZUFBZSxHQUMvQixPQUFPLENBQUMsV0FBVyxDQUFDLENBWXRCO0FBRUQ7Ozs7Ozs7Ozs7OztHQVlHO0FBQ0gsd0JBQXNCLFlBQVksQ0FDaEMsVUFBVSxFQUFFLHlCQUF5QixFQUNyQyxlQUFlLEVBQUUsZUFBZSxFQUNoQyxTQUFTLEVBQUUsUUFBUSxFQUFFLEdBQ3BCLE9BQU8sQ0FBQyxPQUFPLENBQUMsQ0FpQmxCIn0=
|
|
@@ -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,GACpC,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,
|
|
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,GACpC,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"}
|
|
@@ -49,7 +49,9 @@ export async function makeTXEBlockHeader(worldTrees, globalVariables) {
|
|
|
49
49
|
// Get the new archive state after updating
|
|
50
50
|
const newArchiveInfo = await worldTrees.getTreeInfo(MerkleTreeId.ARCHIVE);
|
|
51
51
|
const newArchive = new AppendOnlyTreeSnapshot(new Fr(newArchiveInfo.root), Number(newArchiveInfo.size));
|
|
52
|
-
// L2Block requires checkpointNumber and indexWithinCheckpoint
|
|
52
|
+
// L2Block requires checkpointNumber and indexWithinCheckpoint.
|
|
53
|
+
// TXE uses 1-block-per-checkpoint for testing simplicity, so we can use block number as checkpoint number.
|
|
54
|
+
// This uses the deprecated fromBlockNumber method intentionally for the TXE testing environment.
|
|
53
55
|
const checkpointNumber = CheckpointNumber.fromBlockNumber(globalVariables.blockNumber);
|
|
54
56
|
const indexWithinCheckpoint = IndexWithinCheckpoint(0);
|
|
55
57
|
return new L2Block(newArchive, header, new Body(txEffects), checkpointNumber, indexWithinCheckpoint);
|