git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit e214b19ee2bdfeef044a0c6277beab1b4d7472bb

passing all vm tests

wanderer committed on 11/14/2016, 10:37:59 PM
Parent: 3c2192ab4c4610302da22858ac40084fe5db349d

Files changed

EVMinterface.jschanged
EVMinterface.jsView
@@ -434,12 +434,12 @@
434434
435435 let opPromise
436436
437437 if (value.gt(this.kernel.environment.value)) {
438- opPromise = Promise.resolve(new Address())
438+ opPromise = Promise.resolve(new Buffer(20).fill(0))
439439 } else {
440440 // todo actully run the code
441- opPromise = Promise.resolve(ethUtil.generateAddress(this.kernel.environment.from, this.kernel.environment.nonce))
441+ opPromise = Promise.resolve(ethUtil.generateAddress(this.kernel.environment.address, this.kernel.environment.nonce))
442442 }
443443
444444 // wait for all the prevouse async ops to finish before running the callback
445445 this.kernel.pushOpsQueue(opPromise, cbIndex, address => {
@@ -457,35 +457,32 @@
457457 * @param {integer} resultLength
458458 * @param {integer} gas
459459 * @return {integer} Returns 1 or 0 depending on if the VM trapped on the message or not
460460 */
461- _call (gasHigh, gasLow, addressOffset, valueOffset, dataOffset, dataLength, resultOffset, resultLength) {
461+ _call (gasHigh, gasLow, addressOffset, valueOffset, dataOffset, dataLength, resultOffset, resultLength, cbIndex) {
462462 const gas = from64bit(gasHigh, gasLow)
463463 // Load the params from mem
464464 const address = [...this.getMemory(addressOffset, ADDRESS_SIZE_BYTES)]
465- const value = U256.fromMemory(this.getMemory(valueOffset, U128_SIZE_BYTES))
465+ const value = new U256(this.getMemory(valueOffset, U128_SIZE_BYTES))
466466
467467 this.takeGas(40)
468468
469- // const data = this.getMemory(dataOffset, dataLength).slice(0)
470-
471- // // Special case for calling into empty account
472- // if (!this.environment.isAccountPresent(address)) {
473- // this.takeGas(25000)
474- // }
475- if (address.lt(new U256(4))) {
476- this.takeGas(25000)
477- }
478- // // Special case for non-zero value
469+ // Special case for non-zero value; why does this exist?
479470 if (!value.isZero()) {
480471 this.takeGas(9000 - 2300 + gas)
481472 this.takeGas(-gas)
482473 }
483474
484- // const [errorCode, result] = this.environment.call(gas, address, value, data)
485- // this.setMemory(resultOffset, resultLength, result)
486- // return errorCode
487- return 1
475+ let opPromise = this.kernel.environment.state.root.get(address)
476+ .catch(() => {
477+ // why does this exist?
478+ this.takeGas(25000)
479+ })
480+
481+ // wait for all the prevouse async ops to finish before running the callback
482+ this.kernel.pushOpsQueue(opPromise, cbIndex, () => {
483+ return 1
484+ })
488485 }
489486
490487 /**
491488 * Message-call into this account with an alternative account’s code.
@@ -503,9 +500,9 @@
503500 // Load the params from mem
504501 const path = [...this.getMemory(addressOffset, ADDRESS_SIZE_BYTES), 'code']
505502 const value = U256.fromMemory(this.getMemory(valueOffset, U128_SIZE_BYTES))
506503
507- // Special case for non-zero value
504+ // Special case for non-zero value; why does this exist?
508505 if (!value.isZero()) {
509506 this.takeGas(6700)
510507 }
511508
@@ -517,20 +514,9 @@
517514 return null
518515 })
519516
520517 this.kernel.pushOpsQueue(opPromise, cbIndex, oldValue => {
521- //TODO
522- // const data = this.getMemory(dataOffset, dataLength).slice(0)
523-
524- // // Special case for calling into empty account
525- // if (!this.environment.isAccountPresent(address)) {
526- // this.takeGas(25000)
527- // }
528-
529- // const [errorCode, result] = this.environment.call(gas, address, value, data)
530- // this.setMemory(resultOffset, resultLength, result)
531- // return errorCode
532- //
518+ return 1
533519 })
534520 }
535521
536522 /**

Built with git-ssb-web