jaelis-node 1.3.1 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +72 -2
- package/lib/JAELIS-VM/lib/adapters/evm-adapter.js +454 -0
- package/lib/JAELIS-VM/lib/adapters/index.js +411 -0
- package/lib/JAELIS-VM/lib/adapters/svm-adapter.js +457 -0
- package/lib/JAELIS-VM/lib/compiler/jir-compiler.js +1097 -0
- package/lib/JAELIS-VM/lib/execution/engine.js +1183 -0
- package/lib/JAELIS-VM/lib/index.js +440 -0
- package/lib/JAELIS-VM/lib/integration/jaelis-integration.js +543 -0
- package/lib/JAELIS-VM/lib/serialization/serializer.js +819 -0
- package/lib/JAELIS-VM/lib/state/state-manager.js +1116 -0
- package/lib/JAELIS-VM/lib/translator/bytecode-translator.js +1222 -0
- package/lib/JAELIS-VM/lib/unified/cross-chain-state.js +836 -0
- package/lib/JAELIS-VM/lib/unified/dynamic-contracts.js +1127 -0
- package/lib/JAELIS-VM/lib/unified/index.js +378 -0
- package/lib/JAELIS-VM/lib/unified/jaelis-abi.js +1150 -0
- package/lib/JAELIS-VM/lib/unified/unified-compiler.js +1350 -0
- package/lib/JAELIS-VM/node_modules/.bin/download-cbor-prebuilds +12 -0
- package/lib/JAELIS-VM/node_modules/.bin/download-cbor-prebuilds.cmd +17 -0
- package/lib/JAELIS-VM/node_modules/.bin/download-cbor-prebuilds.ps1 +28 -0
- package/lib/JAELIS-VM/node_modules/.bin/download-msgpackr-prebuilds +12 -0
- package/lib/JAELIS-VM/node_modules/.bin/download-msgpackr-prebuilds.cmd +17 -0
- package/lib/JAELIS-VM/node_modules/.bin/download-msgpackr-prebuilds.ps1 +28 -0
- package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages +12 -0
- package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages-optional +12 -0
- package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages-optional.cmd +17 -0
- package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages-optional.ps1 +28 -0
- package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages-test +12 -0
- package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages-test.cmd +17 -0
- package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages-test.ps1 +28 -0
- package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages.cmd +17 -0
- package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages.ps1 +28 -0
- package/lib/JAELIS-VM/node_modules/.package-lock.json +127 -0
- package/lib/JAELIS-VM/node_modules/@cbor-extract/cbor-extract-win32-x64/README.md +1 -0
- package/lib/JAELIS-VM/node_modules/@cbor-extract/cbor-extract-win32-x64/index.js +0 -0
- package/lib/JAELIS-VM/node_modules/@cbor-extract/cbor-extract-win32-x64/node.abi115.node +0 -0
- package/lib/JAELIS-VM/node_modules/@cbor-extract/cbor-extract-win32-x64/node.napi.node +0 -0
- package/lib/JAELIS-VM/node_modules/@cbor-extract/cbor-extract-win32-x64/package.json +17 -0
- package/lib/JAELIS-VM/node_modules/@msgpackr-extract/msgpackr-extract-win32-x64/README.md +1 -0
- package/lib/JAELIS-VM/node_modules/@msgpackr-extract/msgpackr-extract-win32-x64/index.js +0 -0
- package/lib/JAELIS-VM/node_modules/@msgpackr-extract/msgpackr-extract-win32-x64/node.abi115.node +0 -0
- package/lib/JAELIS-VM/node_modules/@msgpackr-extract/msgpackr-extract-win32-x64/node.napi.node +0 -0
- package/lib/JAELIS-VM/node_modules/@msgpackr-extract/msgpackr-extract-win32-x64/package.json +17 -0
- package/lib/JAELIS-VM/node_modules/cbor-extract/LICENSE +21 -0
- package/lib/JAELIS-VM/node_modules/cbor-extract/README.md +5 -0
- package/lib/JAELIS-VM/node_modules/cbor-extract/bin/download-prebuilds.js +11 -0
- package/lib/JAELIS-VM/node_modules/cbor-extract/binding.gyp +60 -0
- package/lib/JAELIS-VM/node_modules/cbor-extract/index.js +1 -0
- package/lib/JAELIS-VM/node_modules/cbor-extract/package.json +50 -0
- package/lib/JAELIS-VM/node_modules/cbor-extract/src/extract.cpp +198 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/LICENSE +21 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/README.md +380 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/SECURITY.md +11 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/benchmark.md +73 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/browser.js +11 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/decode.d.ts +2 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/decode.js +1300 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/dist/decode-no-eval.cjs +1244 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/dist/decode-no-eval.cjs.map +1 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/dist/index-no-eval.cjs +2509 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/dist/index-no-eval.cjs.map +1 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/dist/index-no-eval.min.js +2 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/dist/index-no-eval.min.js.map +1 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/dist/index.js +2508 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/dist/index.js.map +1 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/dist/index.min.js +2 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/dist/index.min.js.map +1 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/dist/node.cjs +2629 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/dist/node.cjs.map +1 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/dist/test.js +3343 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/dist/test.js.map +1 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/encode.d.ts +1 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/encode.js +1231 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/index.d.ts +79 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/index.js +3 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/iterators.js +85 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/node-index.js +24 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/package.json +94 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/rollup.config.js +88 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/stream.js +61 -0
- package/lib/JAELIS-VM/node_modules/cbor-x/webpack.config.js +19 -0
- package/lib/JAELIS-VM/node_modules/detect-libc/LICENSE +201 -0
- package/lib/JAELIS-VM/node_modules/detect-libc/README.md +163 -0
- package/lib/JAELIS-VM/node_modules/detect-libc/index.d.ts +14 -0
- package/lib/JAELIS-VM/node_modules/detect-libc/lib/detect-libc.js +313 -0
- package/lib/JAELIS-VM/node_modules/detect-libc/lib/elf.js +39 -0
- package/lib/JAELIS-VM/node_modules/detect-libc/lib/filesystem.js +51 -0
- package/lib/JAELIS-VM/node_modules/detect-libc/lib/process.js +24 -0
- package/lib/JAELIS-VM/node_modules/detect-libc/package.json +44 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/LICENSE +21 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/README.md +372 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/SECURITY.md +11 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/benchmark.md +67 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/dist/index-no-eval.cjs +2407 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/dist/index-no-eval.cjs.map +1 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/dist/index-no-eval.min.js +2 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/dist/index-no-eval.min.js.map +1 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/dist/index.js +2406 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/dist/index.js.map +1 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/dist/index.min.js +2 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/dist/index.min.js.map +1 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/dist/node.cjs +3320 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/dist/node.cjs.map +1 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/dist/test.js +4540 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/dist/test.js.map +1 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/dist/unpack-no-eval.cjs +1250 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/dist/unpack-no-eval.cjs.map +1 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/index.d.cts +91 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/index.d.ts +91 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/index.js +5 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/iterators.js +87 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/node-index.js +25 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/pack.d.cts +1 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/pack.d.ts +1 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/pack.js +1141 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/package.json +104 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/rollup.config.js +88 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/stream.js +57 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/struct.js +815 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/test-worker.js +3 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/unpack.d.cts +2 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/unpack.d.ts +2 -0
- package/lib/JAELIS-VM/node_modules/msgpackr/unpack.js +1221 -0
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/LICENSE +21 -0
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/README.md +5 -0
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/bin/download-prebuilds.js +13 -0
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/binding.gyp +63 -0
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/index.js +1 -0
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages +12 -0
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages-optional +12 -0
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages-optional.cmd +17 -0
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages-optional.ps1 +28 -0
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages-test +12 -0
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages-test.cmd +17 -0
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages-test.ps1 +28 -0
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages.cmd +17 -0
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages.ps1 +28 -0
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/node-gyp-build-optional-packages/LICENSE +21 -0
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/node-gyp-build-optional-packages/README.md +58 -0
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/node-gyp-build-optional-packages/bin.js +82 -0
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/node-gyp-build-optional-packages/build-test.js +19 -0
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/node-gyp-build-optional-packages/index.js +6 -0
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/node-gyp-build-optional-packages/node-gyp-build.js +236 -0
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/node-gyp-build-optional-packages/optional.js +7 -0
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/node-gyp-build-optional-packages/package.json +32 -0
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/package.json +50 -0
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/src/extract.cpp +274 -0
- package/lib/JAELIS-VM/node_modules/node-gyp-build-optional-packages/LICENSE +21 -0
- package/lib/JAELIS-VM/node_modules/node-gyp-build-optional-packages/README.md +58 -0
- package/lib/JAELIS-VM/node_modules/node-gyp-build-optional-packages/bin.js +77 -0
- package/lib/JAELIS-VM/node_modules/node-gyp-build-optional-packages/build-test.js +19 -0
- package/lib/JAELIS-VM/node_modules/node-gyp-build-optional-packages/index.js +224 -0
- package/lib/JAELIS-VM/node_modules/node-gyp-build-optional-packages/optional.js +7 -0
- package/lib/JAELIS-VM/node_modules/node-gyp-build-optional-packages/package.json +32 -0
- package/lib/JAELIS-VM/package-lock.json +284 -0
- package/lib/JAELIS-VM/package.json +38 -0
- package/lib/JAELIS-VM/test/comprehensive.test.js +267 -0
- package/lib/JAELIS-VM/test/cross-chain-test.js +470 -0
- package/lib/JAELIS-VM/test/unified-vm-test.js +459 -0
- package/lib/JAELIS-VM/test/unified.test.js +166 -0
- package/lib/JAELIS-VM/test/vm.test.js +599 -0
- package/lib/index.js +240 -4
- package/package.json +2 -2
|
@@ -0,0 +1,440 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JAELIS UNIVERSAL VIRTUAL MACHINE (JVM)
|
|
3
|
+
*
|
|
4
|
+
* TRUE CROSS-CHAIN INTEROPERABILITY
|
|
5
|
+
*
|
|
6
|
+
* Architecture:
|
|
7
|
+
* ┌─────────────────────────────────────────────────────────────────┐
|
|
8
|
+
* │ JAELIS UNIVERSAL VM │
|
|
9
|
+
* ├─────────────────────────────────────────────────────────────────┤
|
|
10
|
+
* │ Frontend Compilers (Source → JIR) │
|
|
11
|
+
* │ ┌─────────┬─────────┬─────────┬─────────┬─────────┬─────────┐ │
|
|
12
|
+
* │ │Solidity │ Rust │ Move │ FunC │ Cairo │ WASM │ │
|
|
13
|
+
* │ │ (EVM) │ (SVM) │(Aptos) │ (TON) │(Stark) │(Cosmos) │ │
|
|
14
|
+
* │ └────┬────┴────┬────┴────┬────┴────┬────┴────┬────┴────┬────┘ │
|
|
15
|
+
* │ │ │ │ │ │ │ │
|
|
16
|
+
* │ └─────────┴─────────┴────┬────┴─────────┴─────────┘ │
|
|
17
|
+
* │ │ │
|
|
18
|
+
* │ ┌─────────────────────────────▼─────────────────────────────┐ │
|
|
19
|
+
* │ │ JAELIS INTERMEDIATE REPRESENTATION (JIR) │ │
|
|
20
|
+
* │ │ │ │
|
|
21
|
+
* │ │ • WASM 3.0 Core (64-bit addressing, GC, threads) │ │
|
|
22
|
+
* │ │ • Extended opcodes for blockchain operations │ │
|
|
23
|
+
* │ │ • Account model abstraction layer │ │
|
|
24
|
+
* │ │ • Cross-VM state management │ │
|
|
25
|
+
* │ └─────────────────────────────┬─────────────────────────────┘ │
|
|
26
|
+
* │ │ │
|
|
27
|
+
* │ ┌─────────────────────────────▼─────────────────────────────┐ │
|
|
28
|
+
* │ │ EXECUTION ENGINE │ │
|
|
29
|
+
* │ │ │ │
|
|
30
|
+
* │ │ • Interpreter (development/debugging) │ │
|
|
31
|
+
* │ │ • AOT Compiler (production, 10x faster) │ │
|
|
32
|
+
* │ │ • JIT Compiler (hot paths optimization) │ │
|
|
33
|
+
* │ └─────────────────────────────┬─────────────────────────────┘ │
|
|
34
|
+
* │ │ │
|
|
35
|
+
* │ ┌─────────────────────────────▼─────────────────────────────┐ │
|
|
36
|
+
* │ │ SERIALIZATION LAYER │ │
|
|
37
|
+
* │ │ │ │
|
|
38
|
+
* │ │ • CBOR-X (3-10x faster than JSON) │ │
|
|
39
|
+
* │ │ • MessagePack (37% smaller than JSON) │ │
|
|
40
|
+
* │ │ • Wincode-style zero-copy deserialization │ │
|
|
41
|
+
* │ └───────────────────────────────────────────────────────────┘ │
|
|
42
|
+
* └─────────────────────────────────────────────────────────────────┘
|
|
43
|
+
*
|
|
44
|
+
* @version 0.1.0
|
|
45
|
+
* @author Mario Papaleo - JAELIS Foundation
|
|
46
|
+
* @patent PATENT PENDING - Universal Multi-Chain Virtual Machine
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
const EventEmitter = require('events');
|
|
50
|
+
const path = require('path');
|
|
51
|
+
|
|
52
|
+
// Fast serialization
|
|
53
|
+
let cborx, msgpackr;
|
|
54
|
+
try {
|
|
55
|
+
cborx = require('cbor-x');
|
|
56
|
+
msgpackr = require('msgpackr');
|
|
57
|
+
} catch (e) {
|
|
58
|
+
// Will use fallback JSON if not installed
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Import VM components
|
|
62
|
+
const JIRCompiler = require('./compiler/jir-compiler');
|
|
63
|
+
const ExecutionEngine = require('./execution/engine');
|
|
64
|
+
const StateManager = require('./state/state-manager');
|
|
65
|
+
const Serializer = require('./serialization/serializer');
|
|
66
|
+
const BytecodeTranslator = require('./translator/bytecode-translator');
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* JAELIS Universal Virtual Machine
|
|
70
|
+
*
|
|
71
|
+
* Supports execution of bytecode from ANY blockchain:
|
|
72
|
+
* - EVM (Ethereum, BSC, Polygon, Arbitrum, etc.)
|
|
73
|
+
* - SVM (Solana BPF/sBPF)
|
|
74
|
+
* - Move (Aptos, Sui, Movement)
|
|
75
|
+
* - TVM (TON)
|
|
76
|
+
* - WASM (Cosmos, Polkadot, NEAR)
|
|
77
|
+
* - Cairo (Starknet)
|
|
78
|
+
* - Bitcoin Script
|
|
79
|
+
*/
|
|
80
|
+
class JaelisUniversalVM extends EventEmitter {
|
|
81
|
+
constructor(config = {}) {
|
|
82
|
+
super();
|
|
83
|
+
|
|
84
|
+
this.config = {
|
|
85
|
+
// Execution mode: 'interpreter' | 'aot' | 'jit'
|
|
86
|
+
executionMode: config.executionMode || 'interpreter',
|
|
87
|
+
|
|
88
|
+
// Memory limits (WASM 3.0 supports 64-bit!)
|
|
89
|
+
maxMemory: config.maxMemory || 1024 * 1024 * 1024, // 1GB default
|
|
90
|
+
maxStack: config.maxStack || 1024 * 1024 * 64, // 64MB stack
|
|
91
|
+
maxHeap: config.maxHeap || 1024 * 1024 * 512, // 512MB heap
|
|
92
|
+
|
|
93
|
+
// Serialization
|
|
94
|
+
serializer: config.serializer || 'cbor', // 'cbor' | 'msgpack' | 'json'
|
|
95
|
+
|
|
96
|
+
// Gas/Lode metering
|
|
97
|
+
meteringEnabled: config.meteringEnabled !== false,
|
|
98
|
+
maxInstructions: config.maxInstructions || 100000000, // 100M instructions
|
|
99
|
+
|
|
100
|
+
// Debug
|
|
101
|
+
debug: config.debug || false,
|
|
102
|
+
trace: config.trace || false,
|
|
103
|
+
|
|
104
|
+
...config
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
// Core components
|
|
108
|
+
this.compiler = new JIRCompiler(this.config);
|
|
109
|
+
this.engine = new ExecutionEngine(this.config);
|
|
110
|
+
this.state = new StateManager(this.config);
|
|
111
|
+
this.serializer = new Serializer(this.config);
|
|
112
|
+
this.translator = new BytecodeTranslator(this.config);
|
|
113
|
+
|
|
114
|
+
// Supported source VMs
|
|
115
|
+
this.supportedVMs = {
|
|
116
|
+
evm: { name: 'Ethereum Virtual Machine', chains: ['ethereum', 'bsc', 'polygon', 'arbitrum', 'optimism', 'base', 'avalanche'] },
|
|
117
|
+
svm: { name: 'Solana Virtual Machine', chains: ['solana'] },
|
|
118
|
+
move: { name: 'Move Virtual Machine', chains: ['aptos', 'sui', 'movement'] },
|
|
119
|
+
tvm: { name: 'TON Virtual Machine', chains: ['ton'] },
|
|
120
|
+
wasm: { name: 'WebAssembly', chains: ['cosmos', 'polkadot', 'near'] },
|
|
121
|
+
cairo: { name: 'Cairo VM', chains: ['starknet'] },
|
|
122
|
+
bitcoin: { name: 'Bitcoin Script', chains: ['bitcoin', 'litecoin'] }
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
// Metrics
|
|
126
|
+
this.metrics = {
|
|
127
|
+
executionsTotal: 0,
|
|
128
|
+
executionsByVM: new Map(),
|
|
129
|
+
bytesProcessed: 0,
|
|
130
|
+
instructionsExecuted: 0,
|
|
131
|
+
averageExecutionTime: 0
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
// Program cache
|
|
135
|
+
this.programCache = new Map();
|
|
136
|
+
|
|
137
|
+
console.log('═══════════════════════════════════════════════════════════════');
|
|
138
|
+
console.log(' JAELIS UNIVERSAL VIRTUAL MACHINE v0.1.0');
|
|
139
|
+
console.log('═══════════════════════════════════════════════════════════════');
|
|
140
|
+
console.log(' Core: WASM 3.0 (64-bit addressing, GC, threads)');
|
|
141
|
+
console.log(` Mode: ${this.config.executionMode.toUpperCase()}`);
|
|
142
|
+
console.log(` Serialization: ${this.config.serializer.toUpperCase()} (3-10x faster than JSON)`);
|
|
143
|
+
console.log(' Supported VMs:');
|
|
144
|
+
for (const [id, vm] of Object.entries(this.supportedVMs)) {
|
|
145
|
+
console.log(` • ${vm.name} (${id.toUpperCase()})`);
|
|
146
|
+
}
|
|
147
|
+
console.log('═══════════════════════════════════════════════════════════════');
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Compile source code to JIR (JAELIS Intermediate Representation)
|
|
152
|
+
*
|
|
153
|
+
* @param {string} sourceCode - Source code in any supported language
|
|
154
|
+
* @param {string} sourceVM - Source VM type ('evm', 'svm', 'move', etc.)
|
|
155
|
+
* @param {object} options - Compilation options
|
|
156
|
+
* @returns {object} Compiled JIR module
|
|
157
|
+
*/
|
|
158
|
+
async compile(sourceCode, sourceVM, options = {}) {
|
|
159
|
+
const startTime = Date.now();
|
|
160
|
+
|
|
161
|
+
if (!this.supportedVMs[sourceVM]) {
|
|
162
|
+
throw new Error(`Unsupported source VM: ${sourceVM}. Supported: ${Object.keys(this.supportedVMs).join(', ')}`);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
console.log(`[JVM] Compiling ${sourceVM.toUpperCase()} code to JIR...`);
|
|
166
|
+
|
|
167
|
+
// Step 1: Parse source code to AST
|
|
168
|
+
const ast = await this.compiler.parse(sourceCode, sourceVM);
|
|
169
|
+
|
|
170
|
+
// Step 2: Semantic analysis
|
|
171
|
+
const analyzed = await this.compiler.analyze(ast, sourceVM);
|
|
172
|
+
|
|
173
|
+
// Step 3: Generate JIR (JAELIS Intermediate Representation)
|
|
174
|
+
const jir = await this.compiler.generateJIR(analyzed, sourceVM, options);
|
|
175
|
+
|
|
176
|
+
// Step 4: Optimize JIR
|
|
177
|
+
const optimizedJIR = await this.compiler.optimize(jir, options.optimizationLevel || 2);
|
|
178
|
+
|
|
179
|
+
// Step 5: Cache compiled module
|
|
180
|
+
const moduleId = this._generateModuleId(sourceCode, sourceVM);
|
|
181
|
+
this.programCache.set(moduleId, optimizedJIR);
|
|
182
|
+
|
|
183
|
+
const compileTime = Date.now() - startTime;
|
|
184
|
+
console.log(`[JVM] Compilation complete in ${compileTime}ms`);
|
|
185
|
+
console.log(`[JVM] Module ID: ${moduleId.substring(0, 16)}...`);
|
|
186
|
+
console.log(`[JVM] JIR size: ${optimizedJIR.bytecode.length} bytes`);
|
|
187
|
+
|
|
188
|
+
return {
|
|
189
|
+
moduleId,
|
|
190
|
+
jir: optimizedJIR,
|
|
191
|
+
sourceVM,
|
|
192
|
+
compileTime,
|
|
193
|
+
metadata: {
|
|
194
|
+
functions: optimizedJIR.functions?.length || 0,
|
|
195
|
+
imports: optimizedJIR.imports?.length || 0,
|
|
196
|
+
exports: optimizedJIR.exports?.length || 0
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Deploy bytecode from any VM
|
|
203
|
+
*
|
|
204
|
+
* @param {Buffer|string} bytecode - Compiled bytecode from source VM
|
|
205
|
+
* @param {string} sourceVM - Source VM type
|
|
206
|
+
* @param {object} options - Deployment options
|
|
207
|
+
*/
|
|
208
|
+
async deployBytecode(bytecode, sourceVM, options = {}) {
|
|
209
|
+
console.log(`[JVM] Deploying ${sourceVM.toUpperCase()} bytecode...`);
|
|
210
|
+
|
|
211
|
+
// Step 1: Translate bytecode to JIR
|
|
212
|
+
const jir = await this.translator.translateToJIR(bytecode, sourceVM);
|
|
213
|
+
|
|
214
|
+
// Step 2: Validate JIR
|
|
215
|
+
const validation = await this.compiler.validate(jir);
|
|
216
|
+
if (!validation.valid) {
|
|
217
|
+
throw new Error(`Invalid bytecode: ${validation.errors.join(', ')}`);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// Step 3: Generate contract address
|
|
221
|
+
const address = this._generateContractAddress(bytecode, options.deployer);
|
|
222
|
+
|
|
223
|
+
// Step 4: Store in state
|
|
224
|
+
await this.state.storeContract(address, {
|
|
225
|
+
jir,
|
|
226
|
+
sourceVM,
|
|
227
|
+
bytecode: Buffer.from(bytecode),
|
|
228
|
+
deployedAt: Date.now(),
|
|
229
|
+
deployer: options.deployer || '0x0'
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
console.log(`[JVM] Contract deployed at: ${address}`);
|
|
233
|
+
|
|
234
|
+
return {
|
|
235
|
+
address,
|
|
236
|
+
sourceVM,
|
|
237
|
+
jirSize: jir.bytecode.length,
|
|
238
|
+
originalSize: bytecode.length
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Execute a function call
|
|
244
|
+
*
|
|
245
|
+
* @param {string} address - Contract address
|
|
246
|
+
* @param {string} functionName - Function to call
|
|
247
|
+
* @param {array} args - Function arguments
|
|
248
|
+
* @param {object} context - Execution context (msg.sender, value, etc.)
|
|
249
|
+
*/
|
|
250
|
+
async execute(address, functionName, args = [], context = {}) {
|
|
251
|
+
const startTime = Date.now();
|
|
252
|
+
this.metrics.executionsTotal++;
|
|
253
|
+
|
|
254
|
+
console.log(`[JVM] Executing ${functionName} on ${address.substring(0, 10)}...`);
|
|
255
|
+
|
|
256
|
+
// Step 1: Load contract
|
|
257
|
+
const contract = await this.state.getContract(address);
|
|
258
|
+
if (!contract) {
|
|
259
|
+
throw new Error(`Contract not found: ${address}`);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// Step 2: Setup execution context
|
|
263
|
+
const execContext = {
|
|
264
|
+
caller: context.from || context.caller || '0x0',
|
|
265
|
+
value: context.value || 0,
|
|
266
|
+
gasLimit: context.gasLimit || this.config.maxInstructions,
|
|
267
|
+
blockNumber: context.blockNumber || 0,
|
|
268
|
+
timestamp: context.timestamp || Date.now(),
|
|
269
|
+
chainId: context.chainId || 4545, // JAELIS testnet
|
|
270
|
+
...context
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
// Step 3: Serialize arguments (fast!)
|
|
274
|
+
const serializedArgs = this.serializer.serialize(args);
|
|
275
|
+
|
|
276
|
+
// Step 4: Execute on engine
|
|
277
|
+
const result = await this.engine.execute(contract.jir, functionName, serializedArgs, execContext);
|
|
278
|
+
|
|
279
|
+
// Step 5: Deserialize result
|
|
280
|
+
const deserializedResult = this.serializer.deserialize(result.returnData);
|
|
281
|
+
|
|
282
|
+
// Step 6: Update metrics
|
|
283
|
+
const executionTime = Date.now() - startTime;
|
|
284
|
+
this.metrics.instructionsExecuted += result.instructionsUsed || 0;
|
|
285
|
+
this._updateMetrics(contract.sourceVM, executionTime);
|
|
286
|
+
|
|
287
|
+
console.log(`[JVM] Execution complete in ${executionTime}ms`);
|
|
288
|
+
console.log(`[JVM] Instructions: ${result.instructionsUsed || 0}`);
|
|
289
|
+
console.log(`[JVM] Lode: 0 (ZERO FEES!)`);
|
|
290
|
+
|
|
291
|
+
return {
|
|
292
|
+
success: result.success,
|
|
293
|
+
returnValue: deserializedResult,
|
|
294
|
+
executionTime,
|
|
295
|
+
instructionsUsed: result.instructionsUsed || 0,
|
|
296
|
+
lodeUsed: 0, // JAELIS is zero-fee!
|
|
297
|
+
logs: result.logs || [],
|
|
298
|
+
stateChanges: result.stateChanges || []
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Cross-VM call - call a function on another VM's contract
|
|
304
|
+
*
|
|
305
|
+
* @param {string} fromAddress - Calling contract
|
|
306
|
+
* @param {string} toAddress - Target contract
|
|
307
|
+
* @param {string} functionName - Function to call
|
|
308
|
+
* @param {array} args - Arguments (will be translated)
|
|
309
|
+
*/
|
|
310
|
+
async crossVMCall(fromAddress, toAddress, functionName, args = [], context = {}) {
|
|
311
|
+
console.log(`[JVM] Cross-VM call: ${fromAddress.substring(0, 10)}... → ${toAddress.substring(0, 10)}...`);
|
|
312
|
+
|
|
313
|
+
const fromContract = await this.state.getContract(fromAddress);
|
|
314
|
+
const toContract = await this.state.getContract(toAddress);
|
|
315
|
+
|
|
316
|
+
if (!fromContract || !toContract) {
|
|
317
|
+
throw new Error('Contract not found');
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// Translate arguments between VM formats
|
|
321
|
+
const translatedArgs = await this.translator.translateArguments(
|
|
322
|
+
args,
|
|
323
|
+
fromContract.sourceVM,
|
|
324
|
+
toContract.sourceVM
|
|
325
|
+
);
|
|
326
|
+
|
|
327
|
+
// Execute on target
|
|
328
|
+
const result = await this.execute(toAddress, functionName, translatedArgs, {
|
|
329
|
+
...context,
|
|
330
|
+
crossVMCall: true,
|
|
331
|
+
sourceVM: fromContract.sourceVM,
|
|
332
|
+
targetVM: toContract.sourceVM
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
// Translate result back
|
|
336
|
+
const translatedResult = await this.translator.translateResult(
|
|
337
|
+
result.returnValue,
|
|
338
|
+
toContract.sourceVM,
|
|
339
|
+
fromContract.sourceVM
|
|
340
|
+
);
|
|
341
|
+
|
|
342
|
+
return {
|
|
343
|
+
...result,
|
|
344
|
+
returnValue: translatedResult,
|
|
345
|
+
crossVM: {
|
|
346
|
+
from: fromContract.sourceVM,
|
|
347
|
+
to: toContract.sourceVM
|
|
348
|
+
}
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* Get VM statistics
|
|
354
|
+
*/
|
|
355
|
+
getStats() {
|
|
356
|
+
return {
|
|
357
|
+
...this.metrics,
|
|
358
|
+
cachedPrograms: this.programCache.size,
|
|
359
|
+
supportedVMs: Object.keys(this.supportedVMs),
|
|
360
|
+
stateConnected: this.state?.isConnected?.() || false,
|
|
361
|
+
config: {
|
|
362
|
+
executionMode: this.config.executionMode,
|
|
363
|
+
serializer: this.config.serializer,
|
|
364
|
+
maxMemory: this.config.maxMemory
|
|
365
|
+
}
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
// ═══════════════════════════════════════════════════════════════
|
|
370
|
+
// CORE STATEMANAGER CONNECTION (Patent Claim 7d)
|
|
371
|
+
// ═══════════════════════════════════════════════════════════════
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* Connect VM's StateManager to Core StateManager for LevelDB persistence
|
|
375
|
+
* Implements Patent Claim 7d: "unified state manager maintaining
|
|
376
|
+
* consistent state across all virtual machine adapters"
|
|
377
|
+
*
|
|
378
|
+
* @param {Object} coreStateManager - Core's StateManager with LevelDB backend
|
|
379
|
+
*/
|
|
380
|
+
connectCoreState(coreStateManager) {
|
|
381
|
+
if (this.state && this.state.connectCoreState) {
|
|
382
|
+
this.state.connectCoreState(coreStateManager);
|
|
383
|
+
console.log('[JaelisUniversalVM] ✅ Connected to Core StateManager (LevelDB)');
|
|
384
|
+
return true;
|
|
385
|
+
}
|
|
386
|
+
console.warn('[JaelisUniversalVM] StateManager does not support connectCoreState');
|
|
387
|
+
return false;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* Check if VM is connected to persistent storage
|
|
392
|
+
*/
|
|
393
|
+
isPersistenceConnected() {
|
|
394
|
+
return this.state?.isConnected?.() || false;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
// ═══════════════════════════════════════════════════════════════
|
|
398
|
+
// PRIVATE METHODS
|
|
399
|
+
// ═══════════════════════════════════════════════════════════════
|
|
400
|
+
|
|
401
|
+
_generateModuleId(sourceCode, sourceVM) {
|
|
402
|
+
const crypto = require('crypto');
|
|
403
|
+
return crypto.createHash('sha256')
|
|
404
|
+
.update(sourceCode + sourceVM + Date.now())
|
|
405
|
+
.digest('hex');
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
_generateContractAddress(bytecode, deployer) {
|
|
409
|
+
const crypto = require('crypto');
|
|
410
|
+
const input = Buffer.concat([
|
|
411
|
+
Buffer.from(deployer || '0x0'),
|
|
412
|
+
Buffer.from(bytecode),
|
|
413
|
+
Buffer.from(Date.now().toString())
|
|
414
|
+
]);
|
|
415
|
+
return '0x' + crypto.createHash('sha256').update(input).digest('hex').substring(0, 40);
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
_updateMetrics(sourceVM, executionTime) {
|
|
419
|
+
const count = this.metrics.executionsByVM.get(sourceVM) || 0;
|
|
420
|
+
this.metrics.executionsByVM.set(sourceVM, count + 1);
|
|
421
|
+
|
|
422
|
+
// Rolling average
|
|
423
|
+
const total = this.metrics.executionsTotal;
|
|
424
|
+
this.metrics.averageExecutionTime =
|
|
425
|
+
(this.metrics.averageExecutionTime * (total - 1) + executionTime) / total;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
// Also export the NEW Unified VM (NO BRIDGES!)
|
|
430
|
+
const { UnifiedJaelisVM, UnifiedCompiler, DynamicContractManager } = require('./unified');
|
|
431
|
+
|
|
432
|
+
module.exports = {
|
|
433
|
+
// Original VM (with adapters/translation)
|
|
434
|
+
JaelisUniversalVM,
|
|
435
|
+
|
|
436
|
+
// NEW Unified VM (NO BRIDGES, NO ADAPTERS!)
|
|
437
|
+
UnifiedJaelisVM,
|
|
438
|
+
UnifiedCompiler,
|
|
439
|
+
DynamicContractManager
|
|
440
|
+
};
|