Skip to content

Commit

Permalink
Merge pull request #2 from cdetrio/rekindle
Browse files Browse the repository at this point in the history
update wasm version
  • Loading branch information
wanderer committed Oct 24, 2017
2 parents 26787af + 6d5919f commit eeb655c
Show file tree
Hide file tree
Showing 18 changed files with 59 additions and 21 deletions.
33 changes: 16 additions & 17 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
sudo: false
os:
- linux

language: node_js
node_js:
- "7"
before_install:
- npm install .
- cd tools
- wget https://storage.googleapis.com/chromium-v8/node-linux-rel/node-linux-rel-41967-121bf38bc0a2973476ba378ddd3ff3b5f97ae494.zip -O nodejs.zip
- unzip nodejs.zip
- cd bin
- "8"

env:
- CXX=g++-4.8
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-4.8
- wget
- unzip

branches:
# We need to whitelist the branches which we want to have "push" automation.
# Pull request automation is not constrained to this set of branches.
only:
- master

matrix:
fast_finish: true
include:
- os: linux
node_js: "7"
env: TEST_SUITE=test
- os: linux
node_js: "7"
node_js: "8"
env: TEST_SUITE=lint
script: ./npm run $TEST_SUITE

- os: linux
node_js: "8"
env: CXX=g++-4.8 TEST_SUITE=test
script: npm run $TEST_SUITE
37 changes: 37 additions & 0 deletions EVMimports.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ const U128_SIZE_BYTES = 16
const ADDRESS_SIZE_BYTES = 20
const U256_SIZE_BYTES = 32

const log = require('loglevel')
log.setLevel('warn') // hide logs
//log.setLevel('debug') // for debugging

// The interface exposed to the WebAessembly Core
module.exports = class Interface {
constructor (kernel) {
Expand Down Expand Up @@ -109,6 +113,7 @@ module.exports = class Interface {
* @param {integer} offset
*/
getAddress (offset) {
log.debug('EVMImports.js getAddress')
this.takeGas(2)

this.setMemory(offset, ADDRESS_SIZE_BYTES, this.kernel.environment.address.toMemory())
Expand All @@ -121,6 +126,7 @@ module.exports = class Interface {
* @param {integer} resultOffset
*/
getBalance (addressOffset, offset, cbIndex) {
log.debug('EVMImports.js getBalance')
this.takeGas(20)

const path = [...this.getMemory(addressOffset, ADDRESS_SIZE_BYTES), 'balance']
Expand All @@ -140,6 +146,7 @@ module.exports = class Interface {
* @param {integer} offset
*/
getTxOrigin (offset) {
log.debug('EVMImports.js getTxOrigin')
this.takeGas(2)

this.setMemory(offset, ADDRESS_SIZE_BYTES, this.kernel.environment.origin.toMemory())
Expand All @@ -151,6 +158,7 @@ module.exports = class Interface {
* @param {integer} offset
*/
getCaller (offset) {
log.debug('EVMImports.js getCaller')
this.takeGas(2)

this.setMemory(offset, ADDRESS_SIZE_BYTES, this.kernel.environment.caller.toMemory())
Expand All @@ -162,6 +170,7 @@ module.exports = class Interface {
* @param {integer} offset
*/
getCallValue (offset) {
log.debug('EVMImports.js getCallValue')
this.takeGas(2)

this.setMemory(offset, U128_SIZE_BYTES, this.kernel.environment.callValue.toMemory(U128_SIZE_BYTES))
Expand All @@ -173,6 +182,7 @@ module.exports = class Interface {
* @return {integer}
*/
getCallDataSize () {
log.debug('EVMImports.js getCallDataSize')
this.takeGas(2)

return this.kernel.environment.callData.length
Expand All @@ -186,6 +196,7 @@ module.exports = class Interface {
* @param {integer} length the length of data to copy
*/
callDataCopy (offset, dataOffset, length) {
log.debug('EVMImports.js callDataCopy')
this.takeGas(3 + Math.ceil(length / 32) * 3)

if (length) {
Expand All @@ -201,6 +212,7 @@ module.exports = class Interface {
* @param {integer} dataOffset the offset in the input data
*/
callDataCopy256 (offset, dataOffset) {
log.debug('EVMImports.js callDataCopy256')
this.takeGas(3)
const callData = this.kernel.environment.callData.slice(dataOffset, dataOffset + 32)
this.setMemory(offset, U256_SIZE_BYTES, callData)
Expand All @@ -211,6 +223,7 @@ module.exports = class Interface {
* @return {interger}
*/
getCodeSize (cbIndex) {
log.debug('EVMImports.js getCodeSize')
this.takeGas(2)

const opPromise = this.kernel.environment.state
Expand All @@ -228,6 +241,7 @@ module.exports = class Interface {
* @param {integer} length the length of code to copy
*/
codeCopy (resultOffset, codeOffset, length, cbIndex) {
log.debug('EVMimports.js codeCopy')
this.takeGas(3 + Math.ceil(length / 32) * 3)

let opPromise
Expand Down Expand Up @@ -255,6 +269,7 @@ module.exports = class Interface {
* @return {integer}
*/
getExternalCodeSize (addressOffset, cbOffset) {
log.debug('EVMImports.js getExternalCodeSize')
this.takeGas(20)
const address = [...this.getMemory(addressOffset, ADDRESS_SIZE_BYTES), 'code']
const opPromise = this.kernel.environment.state.root
Expand All @@ -274,6 +289,7 @@ module.exports = class Interface {
* @param {integer} length the length of code to copy
*/
externalCodeCopy (addressOffset, resultOffset, codeOffset, length, cbIndex) {
log.debug('EVMImports.js externalCodeCopy')
this.takeGas(20 + Math.ceil(length / 32) * 3)

const address = [...this.getMemory(addressOffset, ADDRESS_SIZE_BYTES), 'code']
Expand Down Expand Up @@ -302,6 +318,7 @@ module.exports = class Interface {
* @return {integer}
*/
getTxGasPrice () {
log.debug('EVMImports.js getTxGasPrice')
this.takeGas(2)

return this.kernel.environment.gasPrice
Expand All @@ -313,6 +330,7 @@ module.exports = class Interface {
* @param {integer} offset the offset to load the hash into
*/
getBlockHash (number, offset, cbOffset) {
log.debug('EVMImports.js getBlockHash')
this.takeGas(20)

const diff = this.kernel.environment.block.number - number
Expand All @@ -335,6 +353,8 @@ module.exports = class Interface {
* @param offset
*/
getBlockCoinbase (offset) {
log.debug('EVMImports.js getBlockCoinbase')
log.debug('this.kernel.environment.coinbase:', this.kernel.environment.coinbase)
this.takeGas(2)

this.setMemory(offset, ADDRESS_SIZE_BYTES, this.kernel.environment.coinbase.toMemory())
Expand All @@ -345,6 +365,7 @@ module.exports = class Interface {
* @return {integer}
*/
getBlockTimestamp () {
log.debug('EVMImports.js getBlockTimestamp')
this.takeGas(2)

return this.kernel.environment.block.timestamp
Expand All @@ -355,6 +376,7 @@ module.exports = class Interface {
* @return {integer}
*/
getBlockNumber () {
log.debug('EVMImports.js getBlockNumber')
this.takeGas(2)

return this.kernel.environment.block.number
Expand All @@ -365,6 +387,7 @@ module.exports = class Interface {
* @return {integer}
*/
getBlockDifficulty (offset) {
log.debug('EVMImports.js getBlockDifficulty')
this.takeGas(2)

this.setMemory(offset, U256_SIZE_BYTES, this.kernel.environment.block.difficulty.toMemory())
Expand All @@ -375,6 +398,7 @@ module.exports = class Interface {
* @return {integer}
*/
getBlockGasLimit () {
log.debug('EVMImports.js getBlockGasLimit')
this.takeGas(2)

return this.kernel.environment.block.gasLimit
Expand All @@ -387,6 +411,7 @@ module.exports = class Interface {
* @param {integer} number of topics
*/
log (dataOffset, length, numberOfTopics, topic1, topic2, topic3, topic4) {
log.debug('EVMImports.js log')
if (numberOfTopics < 0 || numberOfTopics > 4) {
throw new Error('Invalid numberOfTopics')
}
Expand Down Expand Up @@ -427,6 +452,7 @@ module.exports = class Interface {
* @return {integer} Return 1 or 0 depending on if the VM trapped on the message or not
*/
create (valueOffset, dataOffset, length, resultOffset, cbIndex) {
log.debug('EVMImports.js create')
this.takeGas(32000)

const value = U256.fromMemory(this.getMemory(valueOffset, U128_SIZE_BYTES))
Expand Down Expand Up @@ -461,6 +487,7 @@ module.exports = class Interface {
* @return {integer} Returns 1 or 0 depending on if the VM trapped on the message or not
*/
_call (gasHigh, gasLow, addressOffset, valueOffset, dataOffset, dataLength, resultOffset, resultLength, cbIndex) {
log.debug('EVMimports.js _call')
this.takeGas(40)

const gas = from64bit(gasHigh, gasLow)
Expand All @@ -474,12 +501,14 @@ module.exports = class Interface {
this.takeGas(-gas)
}

log.debug('EVMimports.js _call calling this.kernel.environment.state.root.get(address)')
let opPromise = this.kernel.environment.state.root.get(address)
.catch(() => {
// why does this exist?
this.takeGas(25000)
})

log.debug('EVMimports.js _call pushing opPromise to pushOpsQueue')
// wait for all the prevouse async ops to finish before running the callback
this.kernel.pushOpsQueue(opPromise, cbIndex, () => {
return 1
Expand All @@ -498,6 +527,7 @@ module.exports = class Interface {
* @return {integer} Returns 1 or 0 depending on if the VM trapped on the message or not
*/
callCode (gas, addressOffset, valueOffset, dataOffset, dataLength, resultOffset, resultLength, cbIndex) {
log.debug('EVMimports.js callCode')
this.takeGas(40)
// Load the params from mem
const path = [...this.getMemory(addressOffset, ADDRESS_SIZE_BYTES), 'code']
Expand All @@ -508,6 +538,9 @@ module.exports = class Interface {
this.takeGas(6700)
}

//log.debug('EVMimports.js callCode this.kernel.environment.state:', this.kernel.environment.state)
// environment.state is a Vertex object

// TODO: should be message?
const opPromise = this.kernel.environment.state.root.get(path)
.catch(() => {
Expand All @@ -534,6 +567,7 @@ module.exports = class Interface {
* @return {integer} Returns 1 or 0 depending on if the VM trapped on the message or not
*/
callDelegate (gas, addressOffset, dataOffset, dataLength, resultOffset, resultLength) {
log.debug('EVMimports.js callDelegate')
// FIXME: count properly
this.takeGas(40)

Expand All @@ -551,6 +585,7 @@ module.exports = class Interface {
* @param {interger} valueOffset the memory offset to load the value from
*/
storageStore (pathOffset, valueOffset, cbIndex) {
log.debug('EVMimports.js storageStore')
this.takeGas(5000)
const path = ['storage', ...this.getMemory(pathOffset, U256_SIZE_BYTES)]
// copy the value
Expand Down Expand Up @@ -584,6 +619,7 @@ module.exports = class Interface {
* @param {interger} resultOffset the memory offset to load the value from
*/
storageLoad (pathOffset, resultOffset, cbIndex) {
log.debug('EVMimports.js storageLoad')
this.takeGas(50)

// convert the path to an array
Expand Down Expand Up @@ -615,6 +651,7 @@ module.exports = class Interface {
* @param {integer} offset the offset to load the address from
*/
selfDestruct (addressOffset) {
log.debug('EVMimports.js selfDestruct')
this.kernel.environment.selfDestruct = true
this.kernel.environment.selfDestructAddress = this.getMemory(addressOffset, ADDRESS_SIZE_BYTES)
this.kernel.environment.gasRefund += 24000
Expand Down
1 change: 1 addition & 0 deletions environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports = class Environment {
const defaults = {
block: new Block(),
blockchain: fakeBlockChain,
coinbase: new Address('0x0000000000000000000000000000000000000000'),
// gas tank
gasPrice: 0,
gasLeft: 1000000,
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scripts": {
"lint": "standard",
"test": "node --harmony --expose-wasm ./tests/interfaceRunner.js",
"build": "node ./tests/buildTests.js && ./tools/wabt/out/wast2wasm ./wasm/interface.wast -o ./wasm/interface.wasm"
"build": "node ./tests/buildTests.js && ./tools/wabt/out/clang/Debug/wat2wasm ./wasm/interface.wast -o ./wasm/interface.wasm"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -40,7 +40,8 @@
"bn.js": "^4.11.6",
"ethereumjs-block": "^1.2.2",
"ethereumjs-tx": "^1.1.2",
"merkle-trie": "0.1.2",
"loglevel": "1.5.1",
"merkle-trie": "0.0.0",
"ethereumjs-util": "^5.0.0"
}
}
2 changes: 1 addition & 1 deletion tests/buildTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ let tests = fs.readdirSync(dir).filter((file) => file.endsWith('.wast'))
for (let testName of tests) {
testName = testName.split('.')[0]
// Compile Command
cp.execSync(`${__dirname}/../tools/wabt/out/wast2wasm ${dir}/${testName}.wast -o ${dir}/${testName}.wasm`)
cp.execSync(`${__dirname}/../tools/wabt/out/clang/Debug/wat2wasm ${dir}/${testName}.wast -o ${dir}/${testName}.wasm`)
}
Binary file modified tests/interface/address.wasm
Binary file not shown.
Binary file modified tests/interface/balance.wasm
Binary file not shown.
Binary file modified tests/interface/basic_gas_ops.wasm
Binary file not shown.
Binary file modified tests/interface/call.wasm
Binary file not shown.
Binary file modified tests/interface/callDataCopy.wasm
Binary file not shown.
Binary file modified tests/interface/callDataSize.wasm
Binary file not shown.
Binary file modified tests/interface/callValue.wasm
Binary file not shown.
Binary file modified tests/interface/caller.wasm
Binary file not shown.
Binary file modified tests/interface/coinbase.wasm
Binary file not shown.
Binary file modified tests/interface/origin.wasm
Binary file not shown.
Binary file modified tests/interface/sstore.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion tools/wabt
Submodule wabt updated 809 files
Binary file modified wasm/interface.wasm
Binary file not shown.

0 comments on commit eeb655c

Please sign in to comment.