git ssb

0+

wanderer🌟 / js-primea-hypervisor



Tree: 53d0a8449b654d395b0965a2e0d05bb3cd6782fa

Files: 53d0a8449b654d395b0965a2e0d05bb3cd6782fa / index.js

2758 bytesRaw
1/**
2 * This implements the Ethereum Kernel
3 * Kernels must implement two methods `codeHandler` and `callHandler` (and `linkHandler` for sharding)
4 * The Kernel Contract handles the following
5 * - Interprocess communications
6 * - Intializing the VM and exposes ROM to it (codeHandler)
7 * - Expose namespace which VM instance exists and Intializes the Environment (callHandler)
8 * - Provides some built in contract (runTx, runBlock)
9 * - Provides resource sharing and limiting via gas
10 *
11 * All State should be stored in the Environment.
12 *
13 */
14
15// The Kernel Exposes this Interface to VM instances it makes
16const Interface = require('./interface.js')
17
18// The Kernel Stores all of its state in the Environment. The Interface is used
19// to by the VM to retrive infromation from the Environment.
20const Environment = require('./environment.js')
21
22const DebugInterface = require('./debugInterface.js')
23
24module.exports = class Kernel {
25 // runs some code in the VM
26 constructor (environment = new Environment()) {
27 this.environment = environment
28 }
29
30 // handles running code.
31 static codeHandler (code, ethInterface = new Interface(new Environment())) {
32 const debugInterface = new DebugInterface(ethInterface.environment)
33
34 const instance = Wasm.instantiateModule(code, {
35 'ethereum': ethInterface.exportTable,
36 'debug': debugInterface.exportTable,
37
38 // export this for Rust
39 // FIXME: remove once Rust has proper imports, see https://github.com/ethereum/evm2.0-design/issues/15
40 'spectest': ethInterface.exportTable,
41
42 // export this for Binaryen
43 // FIXME: remove once C has proper imports, see https://github.com/ethereum/evm2.0-design/issues/16
44 'env': ethInterface.exportTable
45 })
46
47 ethInterface.setModule(instance)
48 debugInterface.setModule(instance)
49
50 if (instance.exports.main) {
51 instance.exports.main()
52 }
53 return instance
54 }
55
56 // loads code from the merkle trie and delegates the message
57 // Detects if code is EVM or WASM
58 // Detects if the code injection is needed
59 // Detects if transcompilation is needed
60 static callHandler (path, data) {
61 // creats a new Kernel
62 // const environment = new Environment(data)
63 // environment.parent = this
64 // const kernel = new Kernel(this, environment)
65 // kernel.codeHandler(code)
66 }
67
68 // run tx; the tx message handler
69 runTx (tx, environment = new Environment()) {
70 // verify tx then send to call Handler
71 this.callHandler(tx, environment)
72 }
73
74 // run block; the block message handler
75 runBlock (block, environment = new Environment()) {
76 // verify block then run each tx
77 block.tx.forEach((tx) => {
78 this.runTx(tx, environment)
79 })
80 }
81
82 // run blockchain
83 // runBlockchain () {}
84}
85

Built with git-ssb-web