git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit 8703ef363b38c0652c4ef86ba883fef73c99b1d9

Merge pull request #47 from ewasm/system-contracts-api

Kernel: use new API for system contracts
wanderer authored on 8/31/2016, 2:14:30 PM
GitHub committed on 8/31/2016, 2:14:30 PM
Parent: 49dfa5e4a80eda9422f7a27a0d55fb30ffc77639
Parent: c4a7bb9447b7405533c5fd047199ec404f449bab

Files changed

index.jschanged
precompile.jschanged
index.jsView
@@ -97,8 +97,14 @@
9797
9898 // Transcompile code
9999 // FIXME: decide if these are the right values here: from: 0, gasLimit: 0, value: 0
100100 code = this.callHandler({ from: Address.zero(), to: transcompilerContract, gasLimit: 0, value: new U256(0), data: code }).returnValue
101+
102+ if (code[0] === 0) {
103+ code = code.slice(1)
104+ } else {
105+ throw new Error('Transcompilation failed: ' + Buffer.from(code).slice(1).toString())
106+ }
101107 }
102108
103109 // creats a new Kernel
104110 const environment = new Environment()
@@ -148,8 +154,14 @@
148154 // Inject metering
149155 if (Utils.isWASMCode(code)) {
150156 // FIXME: decide if these are the right values here: from: 0, gasLimit: 0, value: 0
151157 code = this.callHandler({ from: Address.zero(), to: meteringContract, gasLimit: 0, value: new U256(0), data: code }).returnValue
158+
159+ if (code[0] === 0) {
160+ code = code.slice(1)
161+ } else {
162+ throw new Error('Metering injection failed: ' + Buffer.from(code).slice(1).toString())
163+ }
152164 }
153165
154166 let address = Utils.newAccountAddress(create.from, code)
155167
precompile.jsView
@@ -1,20 +1,25 @@
11 // const evm2wasm = require('evm2wasm')
22 // const metering = require('wasm-metering')
33
4+function craftResponse (status, msg) {
5+ // NOTE: why does this has to be so hard?
6+ return Uint8Array.from(Buffer.concat([ new Buffer([ status ]), new Buffer(msg) ]))
7+}
8+
49 module.exports.meteringInjector = function (call) {
510 console.log('Executing metering injector')
611 return {
712 // returnValue: metering.injectWAST(call.data, 2).slice(0)
8- returnValue: call.data.slice(0)
13+ returnValue: craftResponse(0, call.data)
914 }
1015 }
1116
1217 module.exports.transcompiler = function (call) {
1318 console.log('Executing transcompiler')
1419 return {
1520 // returnValue: evm2wasm.compileEVM(call.data).slice(0)
16- returnValue: call.data.slice(0)
21+ returnValue: craftResponse(1, 'Code not supported: ' + Buffer.from(call.data.slice(0, 8)).toString('hex') + '...')
1722 }
1823 }
1924
2025 module.exports.identity = function (call) {

Built with git-ssb-web