@aztec/txe 0.0.1-commit.d431d1c → 0.0.1-commit.d58ff9d0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dest/AuthRegistry-QVGDDH5X.js +3 -0
- package/dest/AuthRegistry-QVGDDH5X.js.map +7 -0
- package/dest/ContractClassRegistry-VWR3F42P.js +3 -0
- package/dest/ContractClassRegistry-VWR3F42P.js.map +7 -0
- package/dest/ContractInstanceRegistry-FHIWE33X.js +3 -0
- package/dest/ContractInstanceRegistry-FHIWE33X.js.map +7 -0
- package/dest/FeeJuice-SAOWVGG7.js +3 -0
- package/dest/FeeJuice-SAOWVGG7.js.map +7 -0
- package/dest/HandshakeRegistry-GY5CPEPS.js +3 -0
- package/dest/HandshakeRegistry-GY5CPEPS.js.map +7 -0
- package/dest/MultiCallEntrypoint-QG5H33ZZ.js +3 -0
- package/dest/MultiCallEntrypoint-QG5H33ZZ.js.map +7 -0
- package/dest/SchnorrAccount-NME3E45O.js +3 -0
- package/dest/SchnorrAccount-NME3E45O.js.map +7 -0
- package/dest/SchnorrInitializerlessAccount-WTGXU6SW.js +3 -0
- package/dest/SchnorrInitializerlessAccount-WTGXU6SW.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-32UHX7YY.js +3 -0
- package/dest/chunk-32UHX7YY.js.map +7 -0
- package/dest/chunk-GSUKUCKV.js +260 -0
- package/dest/chunk-GSUKUCKV.js.map +7 -0
- package/dest/chunk-UP4KKUVA.js +304 -0
- package/dest/chunk-UP4KKUVA.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 +38759 -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 +40 -16
- package/dest/oracle/txe_oracle_public_context.d.ts.map +1 -1
- package/dest/oracle/txe_oracle_public_context.js +65 -17
- 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 +608 -277
- 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 -222
- package/dest/rpc_translator.d.ts.map +1 -1
- package/dest/rpc_translator.js +901 -600
- package/dest/server.bundle.js +3 -0
- package/dest/server.bundle.js.map +7 -0
- package/dest/state_machine/archiver.d.ts +7 -6
- package/dest/state_machine/archiver.d.ts.map +1 -1
- package/dest/state_machine/archiver.js +31 -22
- package/dest/state_machine/dummy_p2p_client.d.ts +29 -16
- package/dest/state_machine/dummy_p2p_client.d.ts.map +1 -1
- package/dest/state_machine/dummy_p2p_client.js +53 -20
- 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 +13 -7
- package/dest/state_machine/index.d.ts.map +1 -1
- package/dest/state_machine/index.js +75 -21
- package/dest/state_machine/mock_epoch_cache.d.ts +21 -4
- package/dest/state_machine/mock_epoch_cache.d.ts.map +1 -1
- package/dest/state_machine/mock_epoch_cache.js +35 -3
- package/dest/state_machine/synchronizer.d.ts +14 -6
- package/dest/state_machine/synchronizer.d.ts.map +1 -1
- package/dest/state_machine/synchronizer.js +22 -9
- package/dest/txe_session.d.ts +90 -16
- package/dest/txe_session.d.ts.map +1 -1
- package/dest/txe_session.js +381 -59
- package/dest/utils/block_creation.d.ts +6 -6
- package/dest/utils/block_creation.d.ts.map +1 -1
- package/dest/utils/block_creation.js +9 -7
- 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 +80 -20
- package/src/oracle/txe_oracle_registry.ts +556 -0
- package/src/oracle/txe_oracle_top_level_context.ts +486 -180
- 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 -974
- package/src/state_machine/archiver.ts +45 -26
- package/src/state_machine/dummy_p2p_client.ts +83 -32
- package/src/state_machine/global_variable_builder.ts +12 -11
- package/src/state_machine/index.ts +105 -40
- package/src/state_machine/mock_epoch_cache.ts +45 -4
- package/src/state_machine/synchronizer.ts +31 -10
- package/src/txe_session.ts +630 -129
- package/src/utils/block_creation.ts +10 -7
- 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
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export class TXEPublicContractDataSource {
|
|
2
|
+
blockNumber;
|
|
3
|
+
contractStore;
|
|
4
|
+
constructor(blockNumber, contractStore){
|
|
5
|
+
this.blockNumber = blockNumber;
|
|
6
|
+
this.contractStore = contractStore;
|
|
7
|
+
}
|
|
8
|
+
getBlockNumber() {
|
|
9
|
+
return Promise.resolve(this.blockNumber);
|
|
10
|
+
}
|
|
11
|
+
async getContractClass(id) {
|
|
12
|
+
const contractClass = await this.contractStore.getContractClassWithPreimage(id);
|
|
13
|
+
if (!contractClass) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
return {
|
|
17
|
+
id: contractClass.id,
|
|
18
|
+
artifactHash: contractClass.artifactHash,
|
|
19
|
+
packedBytecode: contractClass.packedBytecode,
|
|
20
|
+
privateFunctionsRoot: contractClass.privateFunctionsRoot,
|
|
21
|
+
version: contractClass.version
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
async getBytecodeCommitment(id) {
|
|
25
|
+
const contractClass = await this.contractStore.getContractClassWithPreimage(id);
|
|
26
|
+
return contractClass?.publicBytecodeCommitment;
|
|
27
|
+
}
|
|
28
|
+
async getContract(address) {
|
|
29
|
+
const instance = await this.contractStore.getContractInstance(address);
|
|
30
|
+
// TXE has no contract updates, so the current class always equals the original.
|
|
31
|
+
return instance && {
|
|
32
|
+
...instance,
|
|
33
|
+
address,
|
|
34
|
+
currentContractClassId: instance.originalContractClassId
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
getContractClassIds() {
|
|
38
|
+
throw new Error('Method not implemented.');
|
|
39
|
+
}
|
|
40
|
+
async getContractArtifact(address) {
|
|
41
|
+
const instance = await this.getContract(address);
|
|
42
|
+
return instance && this.contractStore.getContractArtifact(instance.originalContractClassId);
|
|
43
|
+
}
|
|
44
|
+
async getDebugFunctionName(address, selector) {
|
|
45
|
+
const instance = await this.getContract(address);
|
|
46
|
+
return instance && this.contractStore.getDebugFunctionName(instance.originalContractClassId, selector);
|
|
47
|
+
}
|
|
48
|
+
registerContractFunctionSignatures(_signatures) {
|
|
49
|
+
return Promise.resolve();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { createRequire as __txeCreateRequire } from 'node:module';
|
|
2
|
+
const require = __txeCreateRequire(import.meta.url);
|
|
3
|
+
import{TXEDispatcher,activeSessionCount,createLogger}from"./chunk-GSUKUCKV.js";import{__name}from"./chunk-32UHX7YY.js";import{BackendType,Barretenberg,BarretenbergSync}from"@aztec/bb.js";import{parentPort,workerData}from"node:worker_threads";Barretenberg.initSingleton({backend:BackendType.Wasm,skipSrsInit:!0,threads:1});BarretenbergSync.initSingleton({backend:BackendType.Wasm});if(!parentPort)throw new Error("worker.ts must be loaded as a worker_thread");var port=parentPort,logger=createLogger("txe:worker"),dispatcherOpts={contractStoreSourceDir:workerData.contractStoreSourceDir,schnorrClassId:workerData.schnorrClassId},dispatcher=new TXEDispatcher(logger,dispatcherOpts);function serializeError(err){return err instanceof Error?{message:err.message,name:err.name,stack:err.stack}:{message:String(err)}}__name(serializeError,"serializeError");process.env.TXE_WORKER_MEMSTAT==="1"&&setInterval(()=>{let m=process.memoryUsage();port.postMessage({type:"memstat",sessions:activeSessionCount(),rss:m.rss,heapTotal:m.heapTotal,heapUsed:m.heapUsed,external:m.external,arrayBuffers:m.arrayBuffers})},2e3).unref();port.on("message",msg=>{switch(msg.type){case"foreign-call":(async()=>{try{let value=await dispatcher.resolve_foreign_call(msg.callData);port.postMessage({type:"result",requestId:msg.requestId,ok:!0,value})}catch(err){port.postMessage({type:"result",requestId:msg.requestId,ok:!1,error:serializeError(err)})}})();return;case"dispose-session":dispatcher.disposeSession(msg.sessionId).catch(err=>logger.warn("disposeSession failed",err));return}});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/worker.ts"],
|
|
4
|
+
"sourcesContent": ["import { BackendType, Barretenberg, BarretenbergSync } from '@aztec/bb.js';\nimport { type Logger, createLogger } from '@aztec/foundation/log';\n\nimport { parentPort, workerData } from 'node:worker_threads';\n\n// Importing `./index.js` registers the msgpackr Fr extension transitively (via\n// ./msgpackr_fr_extension.js); this must happen before any `sendMessage` call.\nimport { TXEDispatcher, type TXEDispatcherOptions, type TXEForeignCallInput, activeSessionCount } from './index.js';\n\n// Seed both bb.js singletons with the WASM backend before any crypto call. `initSingleton`\n// binds the singleton to whichever backend the first call requests, so this pre-empts the\n// implicit `Barretenberg.initSingleton()` inside `poseidon2Hash` from `@aztec/foundation/crypto`.\n// TXE only needs hashing (no proving, no verification), so WASM is sufficient and\n// `skipSrsInit: true` skips the CRS load. `threads: 1` keeps the WASM backend on a single\n// thread \u2014 additional threads would each spawn a nested worker_thread, multiplying memory cost\n// per pool worker.\nvoid Barretenberg.initSingleton({ backend: BackendType.Wasm, skipSrsInit: true, threads: 1 });\nvoid BarretenbergSync.initSingleton({ backend: BackendType.Wasm });\n\nif (!parentPort) {\n throw new Error('worker.ts must be loaded as a worker_thread');\n}\n\nconst port = parentPort;\nconst logger: Logger = createLogger('txe:worker');\n\n// The pool builds a template LMDB containing the protocol contracts + the SchnorrAccount\n// artifact on the main thread and passes its data dir via `workerData`. The dispatcher clones\n// that LMDB into a per-worker store on first use, so this worker gets a writable copy already\n// populated.\nconst dispatcherOpts: TXEDispatcherOptions = {\n contractStoreSourceDir: workerData.contractStoreSourceDir,\n schnorrClassId: workerData.schnorrClassId,\n};\nconst dispatcher = new TXEDispatcher(logger, dispatcherOpts);\n\ninterface ForeignCallRequest {\n type: 'foreign-call';\n requestId: number;\n callData: TXEForeignCallInput;\n}\n\ninterface DisposeSessionMessage {\n type: 'dispose-session';\n sessionId: number;\n}\n\ntype IncomingMessage = ForeignCallRequest | DisposeSessionMessage;\n\ninterface SerializedError {\n message: string;\n name?: string;\n stack?: string;\n}\n\nfunction serializeError(err: unknown): SerializedError {\n if (err instanceof Error) {\n return { message: err.message, name: err.name, stack: err.stack };\n }\n return { message: String(err) };\n}\n\n// Periodic memstat for diagnostic builds \u2014 set TXE_WORKER_MEMSTAT=1 to enable. Posts JS-heap\n// breakdown + active-session count back to the dispatcher so we can attribute RSS growth\n// between V8 heap (would show in heapUsed) and native (LMDB / world-state / WASM).\nif (process.env.TXE_WORKER_MEMSTAT === '1') {\n setInterval(() => {\n const m = process.memoryUsage();\n port.postMessage({\n type: 'memstat',\n sessions: activeSessionCount(),\n rss: m.rss,\n heapTotal: m.heapTotal,\n heapUsed: m.heapUsed,\n external: m.external,\n arrayBuffers: m.arrayBuffers,\n });\n }, 2000).unref();\n}\n\nport.on('message', (msg: IncomingMessage) => {\n switch (msg.type) {\n case 'foreign-call':\n void (async () => {\n try {\n const value = await dispatcher.resolve_foreign_call(msg.callData);\n port.postMessage({ type: 'result', requestId: msg.requestId, ok: true, value });\n } catch (err) {\n port.postMessage({ type: 'result', requestId: msg.requestId, ok: false, error: serializeError(err) });\n }\n })();\n return;\n case 'dispose-session':\n // Fire-and-forget; the main thread does not wait for confirmation.\n void dispatcher.disposeSession(msg.sessionId).catch(err => logger.warn(`disposeSession failed`, err));\n return;\n }\n});\n"],
|
|
5
|
+
"mappings": ";;uHAAA,OAAS,YAAa,aAAc,qBAAwB,eAG5D,OAAS,WAAY,eAAkB,sBAalC,aAAa,cAAc,CAAE,QAAS,YAAY,KAAM,YAAa,GAAM,QAAS,CAAE,CAAC,EACvF,iBAAiB,cAAc,CAAE,QAAS,YAAY,IAAK,CAAC,EAEjE,GAAI,CAAC,WACH,MAAM,IAAI,MAAM,6CAA6C,EAG/D,IAAM,KAAO,WACP,OAAiB,aAAa,YAAY,EAM1C,eAAuC,CAC3C,uBAAwB,WAAW,uBACnC,eAAgB,WAAW,cAC7B,EACM,WAAa,IAAI,cAAc,OAAQ,cAAc,EAqB3D,SAAS,eAAe,IAA+B,CACrD,OAAI,eAAe,MACV,CAAE,QAAS,IAAI,QAAS,KAAM,IAAI,KAAM,MAAO,IAAI,KAAM,EAE3D,CAAE,QAAS,OAAO,GAAG,CAAE,CAChC,CALS,wCAUL,QAAQ,IAAI,qBAAuB,KACrC,YAAY,IAAM,CAChB,IAAM,EAAI,QAAQ,YAAY,EAC9B,KAAK,YAAY,CACf,KAAM,UACN,SAAU,mBAAmB,EAC7B,IAAK,EAAE,IACP,UAAW,EAAE,UACb,SAAU,EAAE,SACZ,SAAU,EAAE,SACZ,aAAc,EAAE,YAClB,CAAC,CACH,EAAG,GAAI,EAAE,MAAM,EAGjB,KAAK,GAAG,UAAY,KAAyB,CAC3C,OAAQ,IAAI,KAAM,CAChB,IAAK,gBACG,SAAY,CAChB,GAAI,CACF,IAAM,MAAQ,MAAM,WAAW,qBAAqB,IAAI,QAAQ,EAChE,KAAK,YAAY,CAAE,KAAM,SAAU,UAAW,IAAI,UAAW,GAAI,GAAM,KAAM,CAAC,CAChF,OAAS,IAAK,CACZ,KAAK,YAAY,CAAE,KAAM,SAAU,UAAW,IAAI,UAAW,GAAI,GAAO,MAAO,eAAe,GAAG,CAAE,CAAC,CACtG,CACF,GAAG,EACH,OACF,IAAK,kBAEE,WAAW,eAAe,IAAI,SAAS,EAAE,MAAM,KAAO,OAAO,KAAK,wBAAyB,GAAG,CAAC,EACpG,MACJ,CACF,CAAC",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dest/worker.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../src/worker.ts"],"names":[],"mappings":""}
|
package/dest/worker.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { BackendType, Barretenberg, BarretenbergSync } from '@aztec/bb.js';
|
|
2
|
+
import { createLogger } from '@aztec/foundation/log';
|
|
3
|
+
import { parentPort, workerData } from 'node:worker_threads';
|
|
4
|
+
// Importing `./index.js` registers the msgpackr Fr extension transitively (via
|
|
5
|
+
// ./msgpackr_fr_extension.js); this must happen before any `sendMessage` call.
|
|
6
|
+
import { TXEDispatcher, activeSessionCount } from './index.js';
|
|
7
|
+
// Seed both bb.js singletons with the WASM backend before any crypto call. `initSingleton`
|
|
8
|
+
// binds the singleton to whichever backend the first call requests, so this pre-empts the
|
|
9
|
+
// implicit `Barretenberg.initSingleton()` inside `poseidon2Hash` from `@aztec/foundation/crypto`.
|
|
10
|
+
// TXE only needs hashing (no proving, no verification), so WASM is sufficient and
|
|
11
|
+
// `skipSrsInit: true` skips the CRS load. `threads: 1` keeps the WASM backend on a single
|
|
12
|
+
// thread — additional threads would each spawn a nested worker_thread, multiplying memory cost
|
|
13
|
+
// per pool worker.
|
|
14
|
+
void Barretenberg.initSingleton({
|
|
15
|
+
backend: BackendType.Wasm,
|
|
16
|
+
skipSrsInit: true,
|
|
17
|
+
threads: 1
|
|
18
|
+
});
|
|
19
|
+
void BarretenbergSync.initSingleton({
|
|
20
|
+
backend: BackendType.Wasm
|
|
21
|
+
});
|
|
22
|
+
if (!parentPort) {
|
|
23
|
+
throw new Error('worker.ts must be loaded as a worker_thread');
|
|
24
|
+
}
|
|
25
|
+
const port = parentPort;
|
|
26
|
+
const logger = createLogger('txe:worker');
|
|
27
|
+
// The pool builds a template LMDB containing the protocol contracts + the SchnorrAccount
|
|
28
|
+
// artifact on the main thread and passes its data dir via `workerData`. The dispatcher clones
|
|
29
|
+
// that LMDB into a per-worker store on first use, so this worker gets a writable copy already
|
|
30
|
+
// populated.
|
|
31
|
+
const dispatcherOpts = {
|
|
32
|
+
contractStoreSourceDir: workerData.contractStoreSourceDir,
|
|
33
|
+
schnorrClassId: workerData.schnorrClassId
|
|
34
|
+
};
|
|
35
|
+
const dispatcher = new TXEDispatcher(logger, dispatcherOpts);
|
|
36
|
+
function serializeError(err) {
|
|
37
|
+
if (err instanceof Error) {
|
|
38
|
+
return {
|
|
39
|
+
message: err.message,
|
|
40
|
+
name: err.name,
|
|
41
|
+
stack: err.stack
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
message: String(err)
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
// Periodic memstat for diagnostic builds — set TXE_WORKER_MEMSTAT=1 to enable. Posts JS-heap
|
|
49
|
+
// breakdown + active-session count back to the dispatcher so we can attribute RSS growth
|
|
50
|
+
// between V8 heap (would show in heapUsed) and native (LMDB / world-state / WASM).
|
|
51
|
+
if (process.env.TXE_WORKER_MEMSTAT === '1') {
|
|
52
|
+
setInterval(()=>{
|
|
53
|
+
const m = process.memoryUsage();
|
|
54
|
+
port.postMessage({
|
|
55
|
+
type: 'memstat',
|
|
56
|
+
sessions: activeSessionCount(),
|
|
57
|
+
rss: m.rss,
|
|
58
|
+
heapTotal: m.heapTotal,
|
|
59
|
+
heapUsed: m.heapUsed,
|
|
60
|
+
external: m.external,
|
|
61
|
+
arrayBuffers: m.arrayBuffers
|
|
62
|
+
});
|
|
63
|
+
}, 2000).unref();
|
|
64
|
+
}
|
|
65
|
+
port.on('message', (msg)=>{
|
|
66
|
+
switch(msg.type){
|
|
67
|
+
case 'foreign-call':
|
|
68
|
+
void (async ()=>{
|
|
69
|
+
try {
|
|
70
|
+
const value = await dispatcher.resolve_foreign_call(msg.callData);
|
|
71
|
+
port.postMessage({
|
|
72
|
+
type: 'result',
|
|
73
|
+
requestId: msg.requestId,
|
|
74
|
+
ok: true,
|
|
75
|
+
value
|
|
76
|
+
});
|
|
77
|
+
} catch (err) {
|
|
78
|
+
port.postMessage({
|
|
79
|
+
type: 'result',
|
|
80
|
+
requestId: msg.requestId,
|
|
81
|
+
ok: false,
|
|
82
|
+
error: serializeError(err)
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
})();
|
|
86
|
+
return;
|
|
87
|
+
case 'dispose-session':
|
|
88
|
+
// Fire-and-forget; the main thread does not wait for confirmation.
|
|
89
|
+
void dispatcher.disposeSession(msg.sessionId).catch((err)=>logger.warn(`disposeSession failed`, err));
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
});
|
package/package.json
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/txe",
|
|
3
|
-
"version": "0.0.1-commit.
|
|
3
|
+
"version": "0.0.1-commit.d58ff9d0",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"exports":
|
|
5
|
+
"exports": {
|
|
6
|
+
"./server": {
|
|
7
|
+
"types": "./dest/rpc_server.d.ts",
|
|
8
|
+
"import": "./dest/server.bundle.js"
|
|
9
|
+
}
|
|
10
|
+
},
|
|
6
11
|
"bin": "./dest/bin/index.js",
|
|
7
12
|
"typedocOptions": {
|
|
8
13
|
"entryPoints": [
|
|
@@ -12,15 +17,18 @@
|
|
|
12
17
|
"tsconfig": "./tsconfig.json"
|
|
13
18
|
},
|
|
14
19
|
"scripts": {
|
|
15
|
-
"build": "yarn clean && ../scripts/tsc.sh",
|
|
20
|
+
"build": "yarn clean && ../scripts/tsc.sh && node ./esbuild.config.mjs",
|
|
16
21
|
"build:dev": "../scripts/tsc.sh --watch",
|
|
17
22
|
"clean": "rm -rf ./dest .tsbuildinfo",
|
|
18
23
|
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}",
|
|
19
24
|
"dev": "LOG_LEVEL=\"debug; trace: simulator:state_manager; info: json-rpc:proxy\" node ./dest/bin/index.js",
|
|
20
|
-
"start": "node --no-warnings ./dest/bin/index.js"
|
|
25
|
+
"start": "node --no-warnings ./dest/bin/index.js",
|
|
26
|
+
"start:oracle-test-resolver": "node --no-warnings ./dest/bin/oracle_test_server.js",
|
|
27
|
+
"check_txe_oracle_version": "node ./dest/bin/check_txe_oracle_version.js"
|
|
21
28
|
},
|
|
22
29
|
"inherits": [
|
|
23
|
-
"../package.common.json"
|
|
30
|
+
"../package.common.json",
|
|
31
|
+
"./package.local.json"
|
|
24
32
|
],
|
|
25
33
|
"jest": {
|
|
26
34
|
"moduleNameMapper": {
|
|
@@ -61,38 +69,47 @@
|
|
|
61
69
|
]
|
|
62
70
|
},
|
|
63
71
|
"dependencies": {
|
|
64
|
-
"@aztec/accounts": "0.0.1-commit.
|
|
65
|
-
"@aztec/archiver": "0.0.1-commit.
|
|
66
|
-
"@aztec/aztec-node": "0.0.1-commit.
|
|
67
|
-
"@aztec/aztec.js": "0.0.1-commit.
|
|
68
|
-
"@aztec/bb-prover": "0.0.1-commit.
|
|
69
|
-
"@aztec/
|
|
70
|
-
"@aztec/
|
|
71
|
-
"@aztec/
|
|
72
|
-
"@aztec/
|
|
73
|
-
"@aztec/
|
|
74
|
-
"@aztec/
|
|
75
|
-
"@aztec/
|
|
76
|
-
"@aztec/
|
|
77
|
-
"@aztec/
|
|
78
|
-
"
|
|
72
|
+
"@aztec/accounts": "0.0.1-commit.d58ff9d0",
|
|
73
|
+
"@aztec/archiver": "0.0.1-commit.d58ff9d0",
|
|
74
|
+
"@aztec/aztec-node": "0.0.1-commit.d58ff9d0",
|
|
75
|
+
"@aztec/aztec.js": "0.0.1-commit.d58ff9d0",
|
|
76
|
+
"@aztec/bb-prover": "0.0.1-commit.d58ff9d0",
|
|
77
|
+
"@aztec/bb.js": "0.0.1-commit.d58ff9d0",
|
|
78
|
+
"@aztec/constants": "0.0.1-commit.d58ff9d0",
|
|
79
|
+
"@aztec/foundation": "0.0.1-commit.d58ff9d0",
|
|
80
|
+
"@aztec/key-store": "0.0.1-commit.d58ff9d0",
|
|
81
|
+
"@aztec/kv-store": "0.0.1-commit.d58ff9d0",
|
|
82
|
+
"@aztec/protocol-contracts": "0.0.1-commit.d58ff9d0",
|
|
83
|
+
"@aztec/pxe": "0.0.1-commit.d58ff9d0",
|
|
84
|
+
"@aztec/simulator": "0.0.1-commit.d58ff9d0",
|
|
85
|
+
"@aztec/standard-contracts": "0.0.1-commit.d58ff9d0",
|
|
86
|
+
"@aztec/stdlib": "0.0.1-commit.d58ff9d0",
|
|
87
|
+
"@aztec/world-state": "0.0.1-commit.d58ff9d0",
|
|
88
|
+
"msgpackr": "^1.11.2",
|
|
89
|
+
"zod": "^4"
|
|
79
90
|
},
|
|
80
91
|
"devDependencies": {
|
|
81
92
|
"@jest/globals": "^30.0.0",
|
|
82
93
|
"@types/jest": "^30.0.0",
|
|
83
94
|
"@types/node": "^22.15.17",
|
|
84
95
|
"@typescript/native-preview": "7.0.0-dev.20260113.1",
|
|
96
|
+
"esbuild": "^0.27.0",
|
|
85
97
|
"jest": "^30.0.0",
|
|
86
98
|
"jest-mock-extended": "^4.0.0",
|
|
87
99
|
"ts-node": "^10.9.1",
|
|
88
100
|
"typescript": "^5.3.3"
|
|
89
101
|
},
|
|
90
102
|
"files": [
|
|
103
|
+
"dest/bin/index.js",
|
|
104
|
+
"dest/worker.bundle.js",
|
|
105
|
+
"dest/server.bundle.js",
|
|
106
|
+
"dest/chunk-*.js",
|
|
107
|
+
"dest/*-*.js",
|
|
108
|
+
"dest/rpc_server.d.ts",
|
|
91
109
|
"dest",
|
|
92
110
|
"src",
|
|
93
111
|
"!*.test.*"
|
|
94
112
|
],
|
|
95
|
-
"types": "./dest/index.d.ts",
|
|
96
113
|
"engines": {
|
|
97
114
|
"node": ">=20.10"
|
|
98
115
|
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { keccak256String } from '@aztec/foundation/crypto/keccak';
|
|
2
|
+
import { getOracleRegistrySignature, readNumericGlobal } from '@aztec/pxe/bin';
|
|
3
|
+
import { ORACLE_REGISTRY, type OracleRegistryEntry } from '@aztec/pxe/simulator';
|
|
4
|
+
|
|
5
|
+
import { dirname, join } from 'path';
|
|
6
|
+
import { fileURLToPath } from 'url';
|
|
7
|
+
|
|
8
|
+
import { TXE_ORACLE_REGISTRY } from '../oracle/txe_oracle_registry.js';
|
|
9
|
+
import { TXE_ORACLE_INTERFACE_HASH, TXE_ORACLE_VERSION_MAJOR } from '../oracle/txe_oracle_version.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Verifies that the TXE oracle interfaces match the expected interface hash.
|
|
13
|
+
*
|
|
14
|
+
* The TXE oracle interfaces need to be versioned to ensure compatibility between Aztec.nr tests and TXE. This function
|
|
15
|
+
* computes a hash of the TXE-specific entries in `TXE_ORACLE_REGISTRY` (the shared PXE entries are covered by the PXE
|
|
16
|
+
* oracle version check) and compares it against a known hash. If they don't match, it means an
|
|
17
|
+
* interface has changed and the TXE oracle version needs to be bumped:
|
|
18
|
+
* - If the change is backward-breaking (e.g. removing/renaming an oracle), bump TXE_ORACLE_VERSION_MAJOR.
|
|
19
|
+
* - If the change is an oracle addition (non-breaking), bump TXE_ORACLE_VERSION_MINOR.
|
|
20
|
+
*/
|
|
21
|
+
function assertTxeOracleInterfaceMatches(): void {
|
|
22
|
+
const txeOnlyEntries: Record<string, OracleRegistryEntry> = Object.fromEntries(
|
|
23
|
+
Object.entries(TXE_ORACLE_REGISTRY).filter(([name]) => !(name in ORACLE_REGISTRY)),
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
const txeOracleInterfaceHash = keccak256String(getOracleRegistrySignature(txeOnlyEntries));
|
|
27
|
+
if (txeOracleInterfaceHash !== TXE_ORACLE_INTERFACE_HASH) {
|
|
28
|
+
throw new Error(
|
|
29
|
+
`The TXE oracle interface has changed. Update TXE_ORACLE_INTERFACE_HASH to ${txeOracleInterfaceHash} in txe/src/oracle/txe_oracle_version.ts and bump the TXE oracle version (TXE_ORACLE_VERSION_MAJOR for breaking changes, TXE_ORACLE_VERSION_MINOR for oracle additions).`,
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Verifies that `TXE_ORACLE_VERSION_MAJOR` is identical across its two hand-maintained copies: the TXE TypeScript
|
|
36
|
+
* constant and the Aztec.nr Noir test helper constant. These layers can't import each other, so the major version is
|
|
37
|
+
* duplicated by hand and a mismatch otherwise only surfaces at runtime. This is the TXE counterpart of the contract
|
|
38
|
+
* oracle version check in `pxe/src/bin/check_oracle_version.ts`; the two version families are tracked separately.
|
|
39
|
+
*
|
|
40
|
+
* Only the major version is checked: the minor version legitimately diverges under the "environment minor >= contract
|
|
41
|
+
* minor" tolerance, so asserting minor equality would false-positive.
|
|
42
|
+
*/
|
|
43
|
+
function assertTxeOracleVersionMajorInSync(): void {
|
|
44
|
+
const currentDir = dirname(fileURLToPath(import.meta.url));
|
|
45
|
+
// Go up from dest/bin/ or src/bin/ to the package root (txe/), then up two more to the git root.
|
|
46
|
+
const packageRoot = dirname(dirname(currentDir));
|
|
47
|
+
const gitRoot = join(packageRoot, '..', '..');
|
|
48
|
+
|
|
49
|
+
const copies = [
|
|
50
|
+
{ label: 'txe/src/txe_oracle_version.ts', value: TXE_ORACLE_VERSION_MAJOR },
|
|
51
|
+
{
|
|
52
|
+
label: 'aztec-nr/aztec/src/test/helpers/txe_oracles.nr',
|
|
53
|
+
value: readNumericGlobal(
|
|
54
|
+
join(gitRoot, 'noir-projects/aztec-nr/aztec/src/test/helpers/txe_oracles.nr'),
|
|
55
|
+
'TXE_ORACLE_VERSION_MAJOR',
|
|
56
|
+
),
|
|
57
|
+
},
|
|
58
|
+
];
|
|
59
|
+
|
|
60
|
+
if (new Set(copies.map(copy => copy.value)).size > 1) {
|
|
61
|
+
const details = copies.map(copy => `${copy.label}=${copy.value}`).join(', ');
|
|
62
|
+
throw new Error(`TXE_ORACLE_VERSION_MAJOR is out of sync: ${details}. Bump all copies together.`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
assertTxeOracleInterfaceMatches();
|
|
67
|
+
assertTxeOracleVersionMajorInSync();
|
package/src/bin/index.ts
CHANGED
|
@@ -2,7 +2,16 @@
|
|
|
2
2
|
import { createLogger } from '@aztec/aztec.js/log';
|
|
3
3
|
import { startHttpRpcServer } from '@aztec/foundation/json-rpc/server';
|
|
4
4
|
|
|
5
|
-
import { createTXERpcServer } from '../
|
|
5
|
+
import { createTXERpcServer } from '../rpc_server.js';
|
|
6
|
+
|
|
7
|
+
// Cap the native world-state thread pool before any import touches @aztec/world-state.
|
|
8
|
+
// `MAX_WORLD_STATE_THREADS` reads HARDWARE_CONCURRENCY at module load and defaults to 16; the
|
|
9
|
+
// pool's worker threads inherit `process.env`, so setting the cap here covers every worker.
|
|
10
|
+
//
|
|
11
|
+
// CAVEAT: HARDWARE_CONCURRENCY is process-global — bb prove/verify, the LMDB reader pool, and
|
|
12
|
+
// the world-state native thread pool all read it. Safe at 2 today because TXE never proves or
|
|
13
|
+
// verifies and only performs light tree updates; raise it if that ever changes.
|
|
14
|
+
process.env.HARDWARE_CONCURRENCY ??= '2';
|
|
6
15
|
|
|
7
16
|
/**
|
|
8
17
|
* Create and start a new TXE HTTP Server
|
|
@@ -23,7 +32,7 @@ async function main() {
|
|
|
23
32
|
const logger = createLogger('txe:rpc');
|
|
24
33
|
logger.info(`Setting up TXE...`);
|
|
25
34
|
|
|
26
|
-
const txeServer = createTXERpcServer(logger);
|
|
35
|
+
const txeServer = await createTXERpcServer(logger);
|
|
27
36
|
const { port } = await startHttpRpcServer(txeServer, {
|
|
28
37
|
host: '127.0.0.1',
|
|
29
38
|
port: TXE_PORT,
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
#!/usr/bin/env -S node --no-warnings
|
|
2
|
+
import { createLogger } from '@aztec/aztec.js/log';
|
|
3
|
+
import { startHttpRpcServer } from '@aztec/foundation/json-rpc/server';
|
|
4
|
+
|
|
5
|
+
import { createOracleTestRpcServer } from '../oracle/test-resolver/index.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Starts an HTTP RPC server that resolves oracle foreign calls using auto-synthesized fixture scenarios. Used by
|
|
9
|
+
* `nargo test --oracle-resolver` to run `#[generate_oracle_tests]` serialization tests against a dedicated resolver.
|
|
10
|
+
* Logs fixture coverage on shutdown.
|
|
11
|
+
*/
|
|
12
|
+
async function main() {
|
|
13
|
+
const { ORACLE_TEST_PORT = 14830 } = process.env;
|
|
14
|
+
|
|
15
|
+
const logger = createLogger('txe:oracle-test');
|
|
16
|
+
|
|
17
|
+
logger.info('Setting up oracle test resolver...');
|
|
18
|
+
const { server, resolver } = createOracleTestRpcServer(logger);
|
|
19
|
+
|
|
20
|
+
function logCoverageAndExit() {
|
|
21
|
+
const uncalled = resolver.getUncalledFixtures();
|
|
22
|
+
const missing = resolver.getMissingFixtures();
|
|
23
|
+
if (uncalled.length > 0) {
|
|
24
|
+
logger.warn(`Fixtures never called by any test: ${uncalled.join(', ')}`);
|
|
25
|
+
}
|
|
26
|
+
if (missing.length > 0) {
|
|
27
|
+
logger.debug(`Oracles with no fixture defined: ${missing.join(', ')}`);
|
|
28
|
+
}
|
|
29
|
+
if (uncalled.length === 0) {
|
|
30
|
+
logger.info('All fixture oracles were called.');
|
|
31
|
+
}
|
|
32
|
+
process.exit(0);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
process.on('SIGTERM', logCoverageAndExit);
|
|
36
|
+
process.on('SIGINT', logCoverageAndExit);
|
|
37
|
+
|
|
38
|
+
const { port } = await startHttpRpcServer(server, {
|
|
39
|
+
host: '127.0.0.1',
|
|
40
|
+
port: ORACLE_TEST_PORT,
|
|
41
|
+
timeoutMs: 1e3 * 60 * 5,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
logger.info(`Oracle test resolver listening on port ${port}`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
main().catch(err => {
|
|
48
|
+
// eslint-disable-next-line no-console
|
|
49
|
+
console.error(err);
|
|
50
|
+
process.exit(1);
|
|
51
|
+
});
|
package/src/constants.ts
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
import { PRIVATE_LOG_CIPHERTEXT_LEN } from '@aztec/constants';
|
|
1
2
|
import { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
2
3
|
|
|
3
|
-
export const DEFAULT_ADDRESS = AztecAddress.
|
|
4
|
+
export const DEFAULT_ADDRESS = AztecAddress.fromNumberUnsafe(42);
|
|
5
|
+
|
|
6
|
+
// This is MAX_MESSAGE_CONTENT_LEN - PRIVATE_EVENT_MSG_PLAINTEXT_RESERVED_FIELDS_LEN
|
|
7
|
+
export const MAX_PRIVATE_EVENT_LEN = 10;
|
|
8
|
+
export const MAX_PRIVATE_EVENTS_PER_TXE_QUERY = 5;
|
|
9
|
+
|
|
10
|
+
// Arbitrarily set at 64 because we need a bound. Nothing inherent about it.
|
|
11
|
+
export const MAX_OFFCHAIN_EFFECTS_PER_TXE_QUERY = 64;
|
|
12
|
+
// Must match MAX_OFFCHAIN_EFFECT_LEN in noir-projects/aztec-nr/aztec/src/test/helpers/txe_oracles.nr.
|
|
13
|
+
export const MAX_OFFCHAIN_EFFECT_LEN = 2 + PRIVATE_LOG_CIPHERTEXT_LEN;
|