git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit f85a2907f19ae1a49abac80203e35a39f173123d

correct address from le -> be

wanderer committed on 11/13/2016, 10:53:35 AM
Parent: de14490c984932fcb886b69855e66ae6d5ba7dac

Files changed

EVMinterface.jschanged
deps/address.jschanged
EVMinterface.jsView
@@ -1,13 +1,15 @@
11 /**
22 * This is the Ethereum interface that is exposed to the WASM instance which
33 * enables to interact with the Ethereum Environment
44 */
5+
6+const fs = require('fs')
7+const path = require('path')
8+const ethUtil = require('ethereumjs-util')
59 const Vertex = require('merkle-trie')
610 const Address = require('./deps/address.js')
711 const U256 = require('./deps/u256.js')
8-const fs = require('fs')
9-const path = require('path')
1012
1113 const U128_SIZE_BYTES = 16
1214 const ADDRESS_SIZE_BYTES = 20
1315 const U256_SIZE_BYTES = 32
@@ -209,12 +211,16 @@
209211 /**
210212 * Gets the size of code running in current environment.
211213 * @return {interger}
212214 */
213- getCodeSize () {
215+ getCodeSize (cbIndex) {
214216 this.takeGas(2)
215217
216- return this.kernel.environment.code.length
218+ const opPromise = this.kernel.environment.state.get('code')
219+ .then(vertex => vertex.value.length)
220+
221+ // wait for all the prevouse async ops to finish before running the callback
222+ this.kernel.pushOpsQueue(opPromise, cbIndex, length => length)
217223 }
218224
219225 /**
220226 * Copys the code running in current environment to memory.
@@ -263,17 +269,28 @@
263269 * @param {integer} resultOffset the memory offset
264270 * @param {integer} codeOffset the code offset
265271 * @param {integer} length the length of code to copy
266272 */
267- externalCodeCopy (addressOffset, resultOffset, codeOffset, length) {
273+ externalCodeCopy (addressOffset, resultOffset, codeOffset, length, cbIndex) {
268274 this.takeGas(20 + Math.ceil(length / 32) * 3)
269275
276+ const address = [...this.getMemory(addressOffset, ADDRESS_SIZE_BYTES), 'code']
277+ let opPromise
278+
270279 if (length) {
271- const address = Address.fromMemory(this.getMemory(addressOffset, ADDRESS_SIZE_BYTES))
272- let code = this.kernel.environment.getCode(address)
280+ opPromise = this.kernel.environment.state.root
281+ .get(address)
282+ .then(vertex => vertex.value)
283+ .catch(() => [])
284+ } else {
285+ opPromise = Promise.resolve([])
286+ }
287+
288+ // wait for all the prevouse async ops to finish before running the callback
289+ this.kernel.pushOpsQueue(opPromise, cbIndex, code => {
273290 code = code.slice(codeOffset, codeOffset + length)
274291 this.setMemory(resultOffset, length, code)
275- }
292+ })
276293 }
277294
278295 /**
279296 * Gets price of gas in current environment.
@@ -403,24 +420,26 @@
403420 * @param {integer} length the data length
404421 * @param (integer} resultOffset the offset to write the new contract address to
405422 * @return {integer} Return 1 or 0 depending on if the VM trapped on the message or not
406423 */
407- create (valueOffset, dataOffset, length, resultOffset) {
424+ create (valueOffset, dataOffset, length, resultOffset, cbIndex) {
408425 this.takeGas(32000)
409426
410427 const value = U256.fromMemory(this.getMemory(valueOffset, U128_SIZE_BYTES))
411- if (length) {
412- const data = this.getMemory(dataOffset, length).slice(0)
413- // const [errorCode, address] = this.environment.create(value, data)
414- }
415- let address
428+ const code = this.getMemory(dataOffset, length).slice(0)
429+ let opPromise
430+
416431 if (value.gt(this.kernel.environment.value)) {
417- address = new Address()
432+ opPromise = Promise.resolve(new Address())
418433 } else {
419- address = new Address('0x945304eb96065b2a98b57a48a06ae28d285a71b5')
434+ // todo actully run the code
435+ opPromise = Promise.resolve(ethUtil.generateAddress(this.kernel.environment.from, this.kernel.environment.nonce))
420436 }
421- this.setMemory(resultOffset, ADDRESS_SIZE_BYTES, address.toMemory())
422- // return errorCode
437+
438+ // wait for all the prevouse async ops to finish before running the callback
439+ this.kernel.pushOpsQueue(opPromise, cbIndex, address => {
440+ this.setMemory(resultOffset, ADDRESS_SIZE_BYTES, address)
441+ })
423442 }
424443
425444 /**
426445 * Sends a message with arbiatary data to a given address path
@@ -538,8 +557,9 @@
538557 * @param {interger} pathOffest the memory offset to load the the path from
539558 * @param {interger} valueOffset the memory offset to load the value from
540559 */
541560 storageStore (pathOffset, valueOffset, cbIndex) {
561+ console.log('storage store');
542562 this.takeGas(5000)
543563 const path = ['storage', ...this.getMemory(pathOffset, U256_SIZE_BYTES)]
544564 // copy the value
545565 const value = this.getMemory(valueOffset, U256_SIZE_BYTES).slice(0)
deps/address.jsView
@@ -10,14 +10,14 @@
1010 }
1111
1212 // This assumes Uint8Array in LSB (WASM code)
1313 static fromMemory (value) {
14- return new Address(new BN(value, 16, 'le'))
14+ return new Address(new BN(value, 16, 'be'))
1515 }
1616
1717 // This assumes Uint8Array in LSB (WASM code)
1818 toMemory () {
19- return this._value.toBuffer('le', 20)
19+ return this._value.toBuffer('be', 20)
2020 }
2121
2222 toBuffer () {
2323 return super.toBuffer(20)

Built with git-ssb-web