From f9d50e4d6edb072655ff83d6453181176f624fdb Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 30 Apr 2019 17:47:11 -0400 Subject: [PATCH 01/19] add compiler methods --- remix-simulator/README.md | 6 +++--- remix-simulator/src/methods/misc.js | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/remix-simulator/README.md b/remix-simulator/README.md index 67778c46c0..db6661c3d4 100644 --- a/remix-simulator/README.md +++ b/remix-simulator/README.md @@ -37,9 +37,9 @@ Implemented: * [_] eth_getUncleByBlockHashAndIndex * [_] eth_getUncleByBlockNumberAndIndex * [X] eth_getCompilers (DEPRECATED) -* [_] eth_compileSolidity (DEPRECATED) -* [_] eth_compileLLL (DEPRECATED) -* [_] eth_compileSerpent (DEPRECATED) +* [X] eth_compileSolidity (DEPRECATED) +* [X] eth_compileLLL (DEPRECATED) +* [X] eth_compileSerpent (DEPRECATED) * [_] eth_newFilter * [_] eth_newBlockFilter * [_] eth_newPendingTransactionFilter diff --git a/remix-simulator/src/methods/misc.js b/remix-simulator/src/methods/misc.js index 43af6b860b..dfa48baaed 100644 --- a/remix-simulator/src/methods/misc.js +++ b/remix-simulator/src/methods/misc.js @@ -12,7 +12,10 @@ Misc.prototype.methods = function () { eth_mining: this.eth_mining.bind(this), eth_hashrate: this.eth_hashrate.bind(this), web3_sha3: this.web3_sha3.bind(this), - eth_getCompilers: this.eth_getCompilers.bind(this) + eth_getCompilers: this.eth_getCompilers.bind(this), + eth_compileSolidity: this.eth_compileSolidity.bind(this), + eth_compileLLL: this.eth_compileLLL.bind(this), + eth_compileSerpent: this.eth_compileSerpent.bind(this) } } @@ -46,4 +49,16 @@ Misc.prototype.eth_getCompilers = function (payload, cb) { cb(null, []) } +Misc.prototype.eth_compileSolidity = function (payload, cb) { + cb(null, "unsupported") +} + +Misc.prototype.eth_compileLLL = function (payload, cb) { + cb(null, "unsupported") +} + +Misc.prototype.eth_compileSerpent = function (payload, cb) { + cb(null, "unsupported") +} + module.exports = Misc From b94b7b3e3a7349ce9f21d4d96b70501a7e2d407f Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Thu, 30 May 2019 13:12:07 -0400 Subject: [PATCH 02/19] implement/fix getTransactionReceipt, eth_getCode, eth_getTransactionByHash --- remix-lib/src/execution/execution-context.js | 19 +++- remix-lib/src/execution/txRunner.js | 112 ++++++++++++++++--- remix-lib/src/web3Provider/web3VmProvider.js | 2 + remix-simulator/src/methods/blocks.js | 8 ++ remix-simulator/src/methods/transactions.js | 76 +++++++++---- 5 files changed, 178 insertions(+), 39 deletions(-) diff --git a/remix-lib/src/execution/execution-context.js b/remix-lib/src/execution/execution-context.js index dc66ca77c7..01be466c71 100644 --- a/remix-lib/src/execution/execution-context.js +++ b/remix-lib/src/execution/execution-context.js @@ -67,6 +67,7 @@ function createVm (hardfork) { stateManager: stateManager, hardfork: hardfork }) + vm.blockchain.validate = false var web3vm = new Web3VMProvider() web3vm.setVM(vm) return { vm, web3vm, stateManager } @@ -91,6 +92,8 @@ function ExecutionContext () { this.blockGasLimitDefault = 4300000 this.blockGasLimit = this.blockGasLimitDefault this.customNetWorks = {} + this.blocks = {} + this.txs = {} this.init = function (config) { if (config.get('settings/always-use-vm')) { @@ -115,6 +118,8 @@ function ExecutionContext () { } this.web3 = function () { + console.dir("isVM") + console.dir(this.isVM()) return this.isVM() ? vms.constantinople.web3vm : web3 } @@ -183,9 +188,9 @@ function ExecutionContext () { if (context === 'vm') { executionContext = context - vms.constantinople.stateManager.revert(() => { - vms.constantinople.stateManager.checkpoint(() => {}) - }) + // vms.constantinople.stateManager.revert(() => { + // vms.constantinople.stateManager.checkpoint(() => {}) + // }) self.event.trigger('contextChanged', ['vm']) return cb() } @@ -274,6 +279,14 @@ function ExecutionContext () { return transactionDetailsLinks[network] + hash } } + + this.addBlock = function (block) { + self.blocks["0x" + block.hash().toString('hex')] = block + } + + this.trackTx = function(tx, block) { + self.txs[tx] = block + } } var transactionDetailsLinks = { diff --git a/remix-lib/src/execution/txRunner.js b/remix-lib/src/execution/txRunner.js index 08f037a7db..cb77229f6d 100644 --- a/remix-lib/src/execution/txRunner.js +++ b/remix-lib/src/execution/txRunner.js @@ -13,12 +13,14 @@ class TxRunner { this.blockNumber = 0 this.runAsync = true if (executionContext.isVM()) { - this.blockNumber = 1150000 // The VM is running in Homestead mode, which started at this block. + //this.blockNumber = 1150000 // The VM is running in Homestead mode, which started at this block. + this.blockNumber = 1 // The VM is running in Homestead mode, which started at this block. this.runAsync = false // We have to run like this cause the VM Event Manager does not support running multiple txs at the same time. } this.pendingTxs = {} this.vmaccounts = vmaccounts this.queusTxs = [] + this.blocks = [] } rawRun (args, confirmationCb, gasEstimationForceSend, promptCb, cb) { @@ -115,11 +117,16 @@ class TxRunner { header: { timestamp: timestamp || (new Date().getTime() / 1000 | 0), number: self.blockNumber, - coinbase: coinbases[self.blockNumber % coinbases.length], - difficulty: difficulties[self.blockNumber % difficulties.length], - gasLimit: new BN(gasLimit, 10).imuln(2) + // coinbase: coinbases[self.blockNumber % coinbases.length], + // difficulty: difficulties[self.blockNumber % difficulties.length], + // coinbase: coinbases[0], + //difficulty: difficulties[0], + coinbase: coinbases[0], + // gasLimit: new BN(gasLimit, 10).imuln(200), + gasLimit: new BN("5000000").imuln(1) }, - transactions: [], + transactions: [tx], + //transactions: [], uncleHeaders: [] }) if (!useCall) { @@ -128,17 +135,90 @@ class TxRunner { executionContext.vm().stateManager.checkpoint(() => {}) } - executionContext.vm().runTx({block: block, tx: tx, skipBalance: true, skipNonce: true}, function (err, result) { - if (useCall) { - executionContext.vm().stateManager.revert(function () {}) - } - err = err ? err.message : err - if (result) { - result.status = '0x' + result.vm.exception.toString(16) - } - callback(err, { - result: result, - transactionHash: ethJSUtil.bufferToHex(Buffer.from(tx.hash())) + //block.transactions.push(tx); + + this.checkpointAndCommit(() => { + + //executionContext.vm().blockchain.getLatestBlock((a, b) => { + + // console.dir("b.hash()") + // console.dir(b.hash()) + // console.dir(b.hash().length) + // console.dir(b.hash().toString('hex')) + // console.dir(b.hash().toString('hex').length) + + // block.header.parentHash = b.hash() + + // block.header.parentHash = b.hash().toString('hex') + + //block.header.parentHash = Buffer.from(b.hash(), 'hex') + //block.header.parentHash = "4599f6765f1d5a50Bf1E3DBFa14A72dF" + + + // block.header.parentHash = b.hash() + // block.header.difficulty = block.header.canonicalDifficulty(b) + + //executionContext.vm().runTx({block: block, tx: tx, skipBalance: true, skipNonce: true}, function (err, result) { + executionContext.vm().runBlock({block: block, generate: true, skipBlockValidation: true, skipBalance: false}, function (err, results) { + console.dir("-- runBlock result") + console.dir(err) + //console.dir(results) + let result = results.results[0] + console.dir(result) + if (useCall) { + executionContext.vm().stateManager.revert(function () {}) + } + err = err ? err.message : err + if (result) { + result.status = '0x' + result.vm.exception.toString(16) + } + + //executionContext.vm().blockchain.putBlock(block, (err, savedBlock) => { + + executionContext.addBlock(block) + executionContext.trackTx("0x" + tx.hash().toString('hex'), block) + + // result.blockHash = "0x" + block.hash().toString('hex') + // result.blockNumber = "0x" + block.header.number.toString('hex') + + callback(err, { + result: result, + transactionHash: ethJSUtil.bufferToHex(Buffer.from(tx.hash())) + }) + //}) + + }) + + + //}) + + + }) + //}) + } + + checkpointAndCommit (cb) { + console.dir("------------------------") + console.dir("------------------------") + console.dir("------------------------") + console.dir("------------------------") + console.dir("------------------------") + console.dir("------------------------") + console.dir(executionContext.vm().stateManager._checkpointCount) + console.dir("------------------------") + console.dir("------------------------") + console.dir("------------------------") + console.dir("------------------------") + console.dir("------------------------") + console.dir("------------------------") + if (executionContext.vm().stateManager._checkpointCount > 0) { + return executionContext.vm().stateManager.commit(() => { + cb() + }) + } + executionContext.vm().stateManager.checkpoint(() => { + executionContext.vm().stateManager.commit(() => { + cb() }) }) } diff --git a/remix-lib/src/web3Provider/web3VmProvider.js b/remix-lib/src/web3Provider/web3VmProvider.js index f5a076a346..b8d1e50080 100644 --- a/remix-lib/src/web3Provider/web3VmProvider.js +++ b/remix-lib/src/web3Provider/web3VmProvider.js @@ -193,6 +193,8 @@ web3VmProvider.prototype.pushTrace = function (self, data) { } web3VmProvider.prototype.getCode = function (address, cb) { + console.dir("===> web3VmProvider: ") + const account = ethutil.toBuffer(address) this.vm.stateManager.getContractCode(account, function (error, result) { cb(error, util.hexConvert(result)) diff --git a/remix-simulator/src/methods/blocks.js b/remix-simulator/src/methods/blocks.js index 662de3ea32..f4c48b8d25 100644 --- a/remix-simulator/src/methods/blocks.js +++ b/remix-simulator/src/methods/blocks.js @@ -1,4 +1,6 @@ var Web3 = require('web3') +var RemixLib = require('remix-lib') +var executionContext = RemixLib.execution.executionContext var Blocks = function (_options) { const options = _options || {} @@ -43,6 +45,12 @@ Blocks.prototype.eth_getBlockByNumber = function (payload, cb) { } Blocks.prototype.eth_getBlockByHash = function (payload, cb) { + console.dir("eth_getBlockByHash") + console.dir(payload) + console.dir(Object.keys(executionContext.blocks)) + console.dir("== toJSON") + console.dir(executionContext.blocks[payload.params[0]].toJSON()) + let b = { 'difficulty': '0x0', 'extraData': '0x', diff --git a/remix-simulator/src/methods/transactions.js b/remix-simulator/src/methods/transactions.js index 1e4d099998..db873cf5cb 100644 --- a/remix-simulator/src/methods/transactions.js +++ b/remix-simulator/src/methods/transactions.js @@ -38,18 +38,22 @@ Transactions.prototype.eth_sendTransaction = function (payload, cb) { } Transactions.prototype.eth_getTransactionReceipt = function (payload, cb) { + console.dir("== eth_getTransactionReceipt") + console.dir(payload.params) executionContext.web3().eth.getTransactionReceipt(payload.params[0], (error, receipt) => { if (error) { return cb(error) } + var txBlock = executionContext.txs[receipt.hash]; + var r = { 'transactionHash': receipt.hash, 'transactionIndex': '0x00', - 'blockHash': '0x766d18646a06cf74faeabf38597314f84a82c3851859d9da9d94fc8d037269e5', - 'blockNumber': '0x06', - 'gasUsed': '0x06345f', - 'cumulativeGasUsed': '0x06345f', + 'blockHash': "0x" + txBlock.hash().toString('hex'), + 'blockNumber': "0x" + txBlock.header.number.toString('hex'), + 'gasUsed': web3.utils.toHex(receipt.gas), + 'cumulativeGasUsed': web3.utils.toHex(receipt.gas), 'contractAddress': receipt.contractAddress, 'logs': receipt.logs, 'status': receipt.status @@ -64,13 +68,24 @@ Transactions.prototype.eth_estimateGas = function (payload, cb) { } Transactions.prototype.eth_getCode = function (payload, cb) { + console.dir("== eth_getCode") + console.dir(payload.params) let address = payload.params[0] - - const account = ethJSUtil.toBuffer(address) - - executionContext.vm().stateManager.getContractCode(account, (error, result) => { - cb(error, hexConvert(result)) - }) + console.dir(address); + + // const account = ethJSUtil.toBuffer(address) + // console.dir(account) + + //executionContext.vm().stateManager.getContractCode(account, (error, result) => { + //executionContext.web3().eth.getContractCode(address, (error, result) => { + executionContext.web3().eth.getCode(address, (error, result) => { + if (error) { + console.dir("error getting code"); + console.dir(error); + } + //cb(error, hexConvert(result)) + cb(error, result) + }) } Transactions.prototype.eth_call = function (payload, cb) { @@ -90,6 +105,8 @@ Transactions.prototype.eth_getTransactionCount = function (payload, cb) { } Transactions.prototype.eth_getTransactionByHash = function (payload, cb) { + console.dir("== eth_getTransactionByHash") + console.dir(payload.params) const address = payload.params[0] executionContext.web3().eth.getTransactionReceipt(address, (error, receipt) => { @@ -97,19 +114,38 @@ Transactions.prototype.eth_getTransactionByHash = function (payload, cb) { return cb(error) } + console.dir("== receipt") + console.dir(receipt) + + var test = executionContext.web3(); + + var txBlock = executionContext.txs[receipt.transactionHash]; + // executionContext.web3().eth.getBlock(receipt.hash).then((block) => { - const r = { + let r = { + 'blockHash': "0x" + txBlock.hash().toString('hex'), + 'blockNumber': "0x" + txBlock.header.number.toString('hex'), + 'from': receipt.from, + 'gas': web3.utils.toHex(receipt.gas), + // 'gasPrice': '2000000000000', // 0x123 + "gasPrice":"0x4a817c800", // 20000000000 'hash': receipt.transactionHash, - // "nonce": 2, - 'blockHash': receipt.hash, - // 'blockNumber': block.number, + 'input': receipt.input, + // "nonce": 2, // 0x15 // "transactionIndex": 0, - 'from': receipt.from, - 'to': receipt.to, - 'value': receipt.value, - 'gas': receipt.gas, - 'gasPrice': '2000000000000', - 'input': receipt.input + "value": receipt.value + // "value":"0xf3dbb76162000" // 4290000000000000 + // "v": "0x25", // 37 + // "r": "0x1b5e176d927f8e9ab405058b2d2457392da3e20f328b16ddabcebc33eaac5fea", + // "s": "0x4ba69724e8f69de52f0125ad8b3c5c2cef33019bac3249e2c0a2192766d1721c" + } + + if (receipt.to) { + r.to = receipt.to + } + + if (r.value === "0x") { + r.value = "0x0" } cb(null, r) From 90b0f8bbbd90a8edc33a88d16bd2dd1dc7620625 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Thu, 30 May 2019 17:18:53 -0400 Subject: [PATCH 03/19] implement/fix eth_getTransactionByBlockNumber and eth_getBlockByHash --- remix-lib/src/execution/execution-context.js | 4 + remix-lib/src/web3Provider/web3VmProvider.js | 1 + remix-simulator/src/methods/blocks.js | 88 +++++++++++--------- 3 files changed, 55 insertions(+), 38 deletions(-) diff --git a/remix-lib/src/execution/execution-context.js b/remix-lib/src/execution/execution-context.js index 01be466c71..4fcbb77af9 100644 --- a/remix-lib/src/execution/execution-context.js +++ b/remix-lib/src/execution/execution-context.js @@ -281,7 +281,11 @@ function ExecutionContext () { } this.addBlock = function (block) { + let blockNumber = "0x" + block.header.number.toString('hex') + blockNumber = web3.toHex(web3.toBigNumber(blockNumber)) + self.blocks["0x" + block.hash().toString('hex')] = block + self.blocks[blockNumber] = block } this.trackTx = function(tx, block) { diff --git a/remix-lib/src/web3Provider/web3VmProvider.js b/remix-lib/src/web3Provider/web3VmProvider.js index b8d1e50080..250c6ab20d 100644 --- a/remix-lib/src/web3Provider/web3VmProvider.js +++ b/remix-lib/src/web3Provider/web3VmProvider.js @@ -40,6 +40,7 @@ function web3VmProvider () { this.toWei = function () { return self.web3.toWei.apply(self.web3, arguments) } this.toBigNumber = function () { return self.web3.toBigNumber.apply(self.web3, arguments) } this.isAddress = function () { return self.web3.isAddress.apply(self.web3, arguments) } + this.utils = Web3.utils || [] } web3VmProvider.prototype.setVM = function (vm) { diff --git a/remix-simulator/src/methods/blocks.js b/remix-simulator/src/methods/blocks.js index f4c48b8d25..0df94a0bbc 100644 --- a/remix-simulator/src/methods/blocks.js +++ b/remix-simulator/src/methods/blocks.js @@ -19,31 +19,40 @@ Blocks.prototype.methods = function () { } Blocks.prototype.eth_getBlockByNumber = function (payload, cb) { + var block = executionContext.blocks[payload.params[0]] + let b = { - 'difficulty': '0x0', - 'extraData': '0x', - 'gasLimit': '0x7a1200', - 'gasUsed': '0x0', - 'hash': '0xdb731f3622ef37b4da8db36903de029220dba74c41185f8429f916058b86559f', - 'logsBloom': '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', + 'number': toHex(block.header.number), + "hash": toHex(block.hash()), + 'parentHash': toHex(block.header.parentHash), + 'nonce': toHex(block.header.nonce), + "sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "logsBloom": "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331", + "transactionsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "stateRoot": toHex(block.header.stateRoot), 'miner': this.coinbase, - 'mixHash': '0x0000000000000000000000000000000000000000000000000000000000000000', - 'nonce': '0x0000000000000042', - 'number': Web3.utils.toHex(this.blockNumber), - 'parentHash': '0x0000000000000000000000000000000000000000000000000000000000000000', - 'receiptsRoot': '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', - 'sha3Uncles': '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347', - 'size': '0x1f8', - 'stateRoot': '0xb7917653f92e62394d2207d0f39a1320ff1cb93d1cee80d3c492627e00b219ff', - 'timestamp': '0x0', - 'totalDifficulty': '0x0', - 'transactions': [], - 'transactionsRoot': '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', - 'uncles': [] + 'difficulty': toHex(block.header.difficulty), + "totalDifficulty": toHex(block.header.totalDifficulty), + 'extraData': toHex(block.header.extraData), + "size": "0x027f07", // 163591 + 'gasLimit': toHex(block.header.gasLimit), + 'gasUsed': toHex(block.header.gasUsed), + "timestamp": toHex(block.header.timestamp), + // TODO: add transactions + // block.transactions + "transactions": [], + "uncles": [] } + cb(null, b) } +function toHex(value) { + if (!value) return "0x0" + let v = value.toString('hex') + return ((v === "0x" || v === "") ? "0x0" : ("0x" + v)) +} + Blocks.prototype.eth_getBlockByHash = function (payload, cb) { console.dir("eth_getBlockByHash") console.dir(payload) @@ -51,28 +60,31 @@ Blocks.prototype.eth_getBlockByHash = function (payload, cb) { console.dir("== toJSON") console.dir(executionContext.blocks[payload.params[0]].toJSON()) + var block = executionContext.blocks[payload.params[0]] + let b = { - 'difficulty': '0x0', - 'extraData': '0x', - 'gasLimit': '0x7a1200', - 'gasUsed': '0x0', - 'hash': '0xdb731f3622ef37b4da8db36903de029220dba74c41185f8429f916058b86559f', - 'logsBloom': '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', + 'number': toHex(block.header.number), + "hash": toHex(block.hash()), + 'parentHash': toHex(block.header.parentHash), + 'nonce': toHex(block.header.nonce), + "sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", + "logsBloom": "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331", + "transactionsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", + "stateRoot": toHex(block.header.stateRoot), 'miner': this.coinbase, - 'mixHash': '0x0000000000000000000000000000000000000000000000000000000000000000', - 'nonce': '0x0000000000000042', - 'number': Web3.utils.toHex(this.blockNumber), - 'parentHash': '0x0000000000000000000000000000000000000000000000000000000000000000', - 'receiptsRoot': '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', - 'sha3Uncles': '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347', - 'size': '0x1f8', - 'stateRoot': '0xb7917653f92e62394d2207d0f39a1320ff1cb93d1cee80d3c492627e00b219ff', - 'timestamp': '0x0', - 'totalDifficulty': '0x0', - 'transactions': [], - 'transactionsRoot': '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', - 'uncles': [] + 'difficulty': toHex(block.header.difficulty), + "totalDifficulty": toHex(block.header.totalDifficulty), + 'extraData': toHex(block.header.extraData), + "size": "0x027f07", // 163591 + 'gasLimit': toHex(block.header.gasLimit), + 'gasUsed': toHex(block.header.gasUsed), + "timestamp": toHex(block.header.timestamp), + // TODO: add transactions + // block.transactions + "transactions": [], + "uncles": [] } + cb(null, b) } From ae74f03b9d7b4e40322e4f7a97c7d0a1349cc7c2 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Thu, 30 May 2019 17:32:35 -0400 Subject: [PATCH 04/19] add transactions to get block methods --- remix-simulator/src/methods/blocks.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/remix-simulator/src/methods/blocks.js b/remix-simulator/src/methods/blocks.js index 0df94a0bbc..f9a831f117 100644 --- a/remix-simulator/src/methods/blocks.js +++ b/remix-simulator/src/methods/blocks.js @@ -38,9 +38,7 @@ Blocks.prototype.eth_getBlockByNumber = function (payload, cb) { 'gasLimit': toHex(block.header.gasLimit), 'gasUsed': toHex(block.header.gasUsed), "timestamp": toHex(block.header.timestamp), - // TODO: add transactions - // block.transactions - "transactions": [], + "transactions": block.transactions.map((t) => "0x" + t.hash().toString('hex')), "uncles": [] } @@ -79,9 +77,7 @@ Blocks.prototype.eth_getBlockByHash = function (payload, cb) { 'gasLimit': toHex(block.header.gasLimit), 'gasUsed': toHex(block.header.gasUsed), "timestamp": toHex(block.header.timestamp), - // TODO: add transactions - // block.transactions - "transactions": [], + "transactions": block.transactions.map((t) => "0x" + t.hash().toString('hex')), "uncles": [] } From 0afc54d45c880525ef2e67a28d1fa67a900cfc15 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Thu, 30 May 2019 18:04:22 -0400 Subject: [PATCH 05/19] add/fix eth_getTransactionByBlockHashAndIndex and eth_getTransactionByBlockNumberAndIndex --- remix-simulator/README.md | 12 +-- remix-simulator/src/methods/transactions.js | 98 ++++++++++++++++++++- 2 files changed, 102 insertions(+), 8 deletions(-) diff --git a/remix-simulator/README.md b/remix-simulator/README.md index db6661c3d4..fe095c78da 100644 --- a/remix-simulator/README.md +++ b/remix-simulator/README.md @@ -28,12 +28,12 @@ Implemented: * [_] eth_sendRawTransaction * [X] eth_call * [~] eth_estimateGas -* [~] eth_getBlockByHash -* [~] eth_getBlockByNumber -* [~] eth_getTransactionByHash -* [_] eth_getTransactionByBlockHashAndIndex -* [_] eth_getTransactionByBlockNumberAndIndex -* [~] eth_getTransactionReceipt +* [V] eth_getBlockByHash +* [V] eth_getBlockByNumber +* [V] eth_getTransactionByHash +* [V] eth_getTransactionByBlockHashAndIndex +* [V] eth_getTransactionByBlockNumberAndIndex +* [V] eth_getTransactionReceipt * [_] eth_getUncleByBlockHashAndIndex * [_] eth_getUncleByBlockNumberAndIndex * [X] eth_getCompilers (DEPRECATED) diff --git a/remix-simulator/src/methods/transactions.js b/remix-simulator/src/methods/transactions.js index db873cf5cb..23faa32bfa 100644 --- a/remix-simulator/src/methods/transactions.js +++ b/remix-simulator/src/methods/transactions.js @@ -29,7 +29,9 @@ Transactions.prototype.methods = function () { eth_call: this.eth_call.bind(this), eth_estimateGas: this.eth_estimateGas.bind(this), eth_getTransactionCount: this.eth_getTransactionCount.bind(this), - eth_getTransactionByHash: this.eth_getTransactionByHash.bind(this) + eth_getTransactionByHash: this.eth_getTransactionByHash.bind(this), + eth_getTransactionByBlockHashAndIndex: this.eth_getTransactionByBlockHashAndIndex.bind(this), + eth_getTransactionByBlockNumberAndIndex: this.eth_getTransactionByBlockNumberAndIndex.bind(this) } } @@ -153,4 +155,96 @@ Transactions.prototype.eth_getTransactionByHash = function (payload, cb) { }) } -module.exports = Transactions +Transactions.prototype.eth_getTransactionByBlockHashAndIndex = function (payload, cb) { + console.dir("== eth_getTransactionByHash") + console.dir(payload.params) + // const address = payload.params[0] + const txIndex = payload.params[1] + + var txBlock = executionContext.blocks[payload.params[0]] + const txHash = "0x" + txBlock.transactions[web3.utils.toDecimal(txIndex)].hash().toString('hex') + + executionContext.web3().eth.getTransactionReceipt(txHash, (error, receipt) => { + if (error) { + return cb(error) + } + + // executionContext.web3().eth.getBlock(receipt.hash).then((block) => { + let r = { + 'blockHash': "0x" + txBlock.hash().toString('hex'), + 'blockNumber': "0x" + txBlock.header.number.toString('hex'), + 'from': receipt.from, + 'gas': web3.utils.toHex(receipt.gas), + // 'gasPrice': '2000000000000', // 0x123 + "gasPrice": "0x4a817c800", // 20000000000 + 'hash': receipt.transactionHash, + 'input': receipt.input, + // "nonce": 2, // 0x15 + // "transactionIndex": 0, + "value": receipt.value + // "value":"0xf3dbb76162000" // 4290000000000000 + // "v": "0x25", // 37 + // "r": "0x1b5e176d927f8e9ab405058b2d2457392da3e20f328b16ddabcebc33eaac5fea", + // "s": "0x4ba69724e8f69de52f0125ad8b3c5c2cef33019bac3249e2c0a2192766d1721c" + } + + if (receipt.to) { + r.to = receipt.to + } + + if (r.value === "0x") { + r.value = "0x0" + } + + cb(null, r) + // }) + }) +} + +Transactions.prototype.eth_getTransactionByBlockNumberAndIndex = function (payload, cb) { + console.dir("== eth_getTransactionByHash") + console.dir(payload.params) + // const address = payload.params[0] + const txIndex = payload.params[1] + + var txBlock = executionContext.blocks[payload.params[0]] + const txHash = "0x" + txBlock.transactions[web3.utils.toDecimal(txIndex)].hash().toString('hex') + + executionContext.web3().eth.getTransactionReceipt(txHash, (error, receipt) => { + if (error) { + return cb(error) + } + + // executionContext.web3().eth.getBlock(receipt.hash).then((block) => { + let r = { + 'blockHash': "0x" + txBlock.hash().toString('hex'), + 'blockNumber': "0x" + txBlock.header.number.toString('hex'), + 'from': receipt.from, + 'gas': web3.utils.toHex(receipt.gas), + // 'gasPrice': '2000000000000', // 0x123 + "gasPrice": "0x4a817c800", // 20000000000 + 'hash': receipt.transactionHash, + 'input': receipt.input, + // "nonce": 2, // 0x15 + // "transactionIndex": 0, + "value": receipt.value + // "value":"0xf3dbb76162000" // 4290000000000000 + // "v": "0x25", // 37 + // "r": "0x1b5e176d927f8e9ab405058b2d2457392da3e20f328b16ddabcebc33eaac5fea", + // "s": "0x4ba69724e8f69de52f0125ad8b3c5c2cef33019bac3249e2c0a2192766d1721c" + } + + if (receipt.to) { + r.to = receipt.to + } + + if (r.value === "0x") { + r.value = "0x0" + } + + cb(null, r) + // }) + }) +} + +module.exports = Transactions \ No newline at end of file From 89d19fc29cf362d42f103fa5185ad262523d75af Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Thu, 30 May 2019 18:18:57 -0400 Subject: [PATCH 06/19] add eth_getBlockTransactionCountByHash and eth_getBlockTransactionCountByNumber --- remix-simulator/README.md | 18 +++++++++--------- remix-simulator/src/methods/blocks.js | 17 ++++++++++++++++- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/remix-simulator/README.md b/remix-simulator/README.md index fe095c78da..c3411a0deb 100644 --- a/remix-simulator/README.md +++ b/remix-simulator/README.md @@ -17,9 +17,9 @@ Implemented: * [X] eth_blockNumber * [X] eth_getBalance * [_] eth_getStorageAt -* [~] eth_getTransactionCount -* [_] eth_getBlockTransactionCountByHash -* [_] eth_getBlockTransactionCountByNumber +* [X] eth_getTransactionCount +* [X] eth_getBlockTransactionCountByHash +* [X] eth_getBlockTransactionCountByNumber * [_] eth_getUncleCountByBlockHash * [_] eth_getUncleCountByBlockNumber * [X] eth_getCode @@ -28,12 +28,12 @@ Implemented: * [_] eth_sendRawTransaction * [X] eth_call * [~] eth_estimateGas -* [V] eth_getBlockByHash -* [V] eth_getBlockByNumber -* [V] eth_getTransactionByHash -* [V] eth_getTransactionByBlockHashAndIndex -* [V] eth_getTransactionByBlockNumberAndIndex -* [V] eth_getTransactionReceipt +* [X] eth_getBlockByHash +* [X] eth_getBlockByNumber +* [X] eth_getTransactionByHash +* [X] eth_getTransactionByBlockHashAndIndex +* [X] eth_getTransactionByBlockNumberAndIndex +* [X] eth_getTransactionReceipt * [_] eth_getUncleByBlockHashAndIndex * [_] eth_getUncleByBlockNumberAndIndex * [X] eth_getCompilers (DEPRECATED) diff --git a/remix-simulator/src/methods/blocks.js b/remix-simulator/src/methods/blocks.js index f9a831f117..d710c969fc 100644 --- a/remix-simulator/src/methods/blocks.js +++ b/remix-simulator/src/methods/blocks.js @@ -14,7 +14,9 @@ Blocks.prototype.methods = function () { eth_gasPrice: this.eth_gasPrice.bind(this), eth_coinbase: this.eth_coinbase.bind(this), eth_blockNumber: this.eth_blockNumber.bind(this), - eth_getBlockByHash: this.eth_getBlockByHash.bind(this) + eth_getBlockByHash: this.eth_getBlockByHash.bind(this), + eth_getBlockTransactionCountByHash: this.eth_getBlockTransactionCountByHash.bind(this), + eth_getBlockTransactionCountByNumber: this.eth_getBlockTransactionCountByNumber.bind(this) } } @@ -96,4 +98,17 @@ Blocks.prototype.eth_blockNumber = function (payload, cb) { cb(null, this.blockNumber) } +Blocks.prototype.eth_getBlockTransactionCountByHash = function (payload, cb) { + var block = executionContext.blocks[payload.params[0]] + + cb(null, block.transactions.length) +} + +Blocks.prototype.eth_getBlockTransactionCountByNumber = function (payload, cb) { + var block = executionContext.blocks[payload.params[0]] + + cb(null, block.transactions.length) +} + + module.exports = Blocks From 3938ce89c45672093826120a28c66e90388c1244 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Thu, 30 May 2019 18:24:30 -0400 Subject: [PATCH 07/19] add eth_getUncleCountByBlockHash and eth_getUncleCountByBlockNumber --- remix-simulator/src/methods/blocks.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/remix-simulator/src/methods/blocks.js b/remix-simulator/src/methods/blocks.js index d710c969fc..c9705cb3d5 100644 --- a/remix-simulator/src/methods/blocks.js +++ b/remix-simulator/src/methods/blocks.js @@ -16,7 +16,9 @@ Blocks.prototype.methods = function () { eth_blockNumber: this.eth_blockNumber.bind(this), eth_getBlockByHash: this.eth_getBlockByHash.bind(this), eth_getBlockTransactionCountByHash: this.eth_getBlockTransactionCountByHash.bind(this), - eth_getBlockTransactionCountByNumber: this.eth_getBlockTransactionCountByNumber.bind(this) + eth_getBlockTransactionCountByNumber: this.eth_getBlockTransactionCountByNumber.bind(this), + eth_getUncleCountByBlockHash: this.eth_getUncleCountByBlockHash.bind(this), + eth_getUncleCountByBlockNumber: this.eth_getUncleCountByBlockNumber.bind(this) } } @@ -110,5 +112,12 @@ Blocks.prototype.eth_getBlockTransactionCountByNumber = function (payload, cb) { cb(null, block.transactions.length) } +Blocks.prototype.eth_getUncleCountByBlockHash = function (payload, cb) { + cb(null, 0) +} + +Blocks.prototype.eth_getUncleCountByBlockNumber = function (payload, cb) { + cb(null, 0) +} -module.exports = Blocks +module.exports = Blocks \ No newline at end of file From 9d88fb70e74a4f25e5fca92c3a9a113cca7b479e Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 4 Jun 2019 12:35:09 -0400 Subject: [PATCH 08/19] update README --- remix-simulator/README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/remix-simulator/README.md b/remix-simulator/README.md index c3411a0deb..aeba1ec207 100644 --- a/remix-simulator/README.md +++ b/remix-simulator/README.md @@ -20,8 +20,8 @@ Implemented: * [X] eth_getTransactionCount * [X] eth_getBlockTransactionCountByHash * [X] eth_getBlockTransactionCountByNumber -* [_] eth_getUncleCountByBlockHash -* [_] eth_getUncleCountByBlockNumber +* [~] eth_getUncleCountByBlockHash +* [~] eth_getUncleCountByBlockNumber * [X] eth_getCode * [~] eth_sign * [X] eth_sendTransaction @@ -81,4 +81,3 @@ Implemented: * [_] rpc_modules * [_] web3_clientVersion * [_] web3_sha3 - From 7882c2340f6a70e168b4d5aa5993eb64877a85cf Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 4 Jun 2019 12:48:08 -0400 Subject: [PATCH 09/19] cleanup --- remix-lib/src/execution/execution-context.js | 5 - remix-lib/src/execution/txRunner.js | 100 ++++--------------- remix-lib/src/web3Provider/web3VmProvider.js | 2 - remix-simulator/src/methods/blocks.js | 6 -- remix-simulator/src/methods/transactions.js | 31 +----- 5 files changed, 25 insertions(+), 119 deletions(-) diff --git a/remix-lib/src/execution/execution-context.js b/remix-lib/src/execution/execution-context.js index 4fcbb77af9..b9a317e74a 100644 --- a/remix-lib/src/execution/execution-context.js +++ b/remix-lib/src/execution/execution-context.js @@ -118,8 +118,6 @@ function ExecutionContext () { } this.web3 = function () { - console.dir("isVM") - console.dir(this.isVM()) return this.isVM() ? vms.constantinople.web3vm : web3 } @@ -188,9 +186,6 @@ function ExecutionContext () { if (context === 'vm') { executionContext = context - // vms.constantinople.stateManager.revert(() => { - // vms.constantinople.stateManager.checkpoint(() => {}) - // }) self.event.trigger('contextChanged', ['vm']) return cb() } diff --git a/remix-lib/src/execution/txRunner.js b/remix-lib/src/execution/txRunner.js index cb77229f6d..dc2a9e584b 100644 --- a/remix-lib/src/execution/txRunner.js +++ b/remix-lib/src/execution/txRunner.js @@ -94,7 +94,7 @@ class TxRunner { } } - runInVm (from, to, data, value, gasLimit, useCall, timestamp, callback) { + runInVm(from, to, data, value, gasLimit, useCall, timestamp, callback) { const self = this var account = self.vmaccounts[from] if (!account) { @@ -111,106 +111,50 @@ class TxRunner { }) tx.sign(account.privateKey) - const coinbases = [ '0x0e9281e9c6a0808672eaba6bd1220e144c9bb07a', '0x8945a1288dc78a6d8952a92c77aee6730b414778', '0x94d76e24f818426ae84aa404140e8d5f60e10e7e' ] - const difficulties = [ new BN('69762765929000', 10), new BN('70762765929000', 10), new BN('71762765929000', 10) ] + const coinbases = ['0x0e9281e9c6a0808672eaba6bd1220e144c9bb07a', '0x8945a1288dc78a6d8952a92c77aee6730b414778', '0x94d76e24f818426ae84aa404140e8d5f60e10e7e'] + const difficulties = [new BN('69762765929000', 10), new BN('70762765929000', 10), new BN('71762765929000', 10)] var block = new EthJSBlock({ header: { timestamp: timestamp || (new Date().getTime() / 1000 | 0), number: self.blockNumber, - // coinbase: coinbases[self.blockNumber % coinbases.length], - // difficulty: difficulties[self.blockNumber % difficulties.length], - // coinbase: coinbases[0], - //difficulty: difficulties[0], + coinbase: coinbases[self.blockNumber % coinbases.length], + difficulty: difficulties[self.blockNumber % difficulties.length], coinbase: coinbases[0], - // gasLimit: new BN(gasLimit, 10).imuln(200), gasLimit: new BN("5000000").imuln(1) }, transactions: [tx], - //transactions: [], uncleHeaders: [] }) if (!useCall) { ++self.blockNumber } else { - executionContext.vm().stateManager.checkpoint(() => {}) + executionContext.vm().stateManager.checkpoint(() => { }) } - //block.transactions.push(tx); - this.checkpointAndCommit(() => { + executionContext.vm().runBlock({ block: block, generate: true, skipBlockValidation: true, skipBalance: false }, function (err, results) { + let result = results.results[0] + console.dir(result) + if (useCall) { + executionContext.vm().stateManager.revert(function () { }) + } + err = err ? err.message : err + if (result) { + result.status = '0x' + result.vm.exception.toString(16) + } - //executionContext.vm().blockchain.getLatestBlock((a, b) => { - - // console.dir("b.hash()") - // console.dir(b.hash()) - // console.dir(b.hash().length) - // console.dir(b.hash().toString('hex')) - // console.dir(b.hash().toString('hex').length) - - // block.header.parentHash = b.hash() - - // block.header.parentHash = b.hash().toString('hex') - - //block.header.parentHash = Buffer.from(b.hash(), 'hex') - //block.header.parentHash = "4599f6765f1d5a50Bf1E3DBFa14A72dF" - - - // block.header.parentHash = b.hash() - // block.header.difficulty = block.header.canonicalDifficulty(b) - - //executionContext.vm().runTx({block: block, tx: tx, skipBalance: true, skipNonce: true}, function (err, result) { - executionContext.vm().runBlock({block: block, generate: true, skipBlockValidation: true, skipBalance: false}, function (err, results) { - console.dir("-- runBlock result") - console.dir(err) - //console.dir(results) - let result = results.results[0] - console.dir(result) - if (useCall) { - executionContext.vm().stateManager.revert(function () {}) - } - err = err ? err.message : err - if (result) { - result.status = '0x' + result.vm.exception.toString(16) - } - - //executionContext.vm().blockchain.putBlock(block, (err, savedBlock) => { - - executionContext.addBlock(block) - executionContext.trackTx("0x" + tx.hash().toString('hex'), block) - - // result.blockHash = "0x" + block.hash().toString('hex') - // result.blockNumber = "0x" + block.header.number.toString('hex') - - callback(err, { - result: result, - transactionHash: ethJSUtil.bufferToHex(Buffer.from(tx.hash())) - }) - //}) + executionContext.addBlock(block) + executionContext.trackTx("0x" + tx.hash().toString('hex'), block) + callback(err, { + result: result, + transactionHash: ethJSUtil.bufferToHex(Buffer.from(tx.hash())) }) - - - //}) - - + }) }) - //}) } checkpointAndCommit (cb) { - console.dir("------------------------") - console.dir("------------------------") - console.dir("------------------------") - console.dir("------------------------") - console.dir("------------------------") - console.dir("------------------------") - console.dir(executionContext.vm().stateManager._checkpointCount) - console.dir("------------------------") - console.dir("------------------------") - console.dir("------------------------") - console.dir("------------------------") - console.dir("------------------------") - console.dir("------------------------") if (executionContext.vm().stateManager._checkpointCount > 0) { return executionContext.vm().stateManager.commit(() => { cb() diff --git a/remix-lib/src/web3Provider/web3VmProvider.js b/remix-lib/src/web3Provider/web3VmProvider.js index 250c6ab20d..8cc8d344ad 100644 --- a/remix-lib/src/web3Provider/web3VmProvider.js +++ b/remix-lib/src/web3Provider/web3VmProvider.js @@ -194,8 +194,6 @@ web3VmProvider.prototype.pushTrace = function (self, data) { } web3VmProvider.prototype.getCode = function (address, cb) { - console.dir("===> web3VmProvider: ") - const account = ethutil.toBuffer(address) this.vm.stateManager.getContractCode(account, function (error, result) { cb(error, util.hexConvert(result)) diff --git a/remix-simulator/src/methods/blocks.js b/remix-simulator/src/methods/blocks.js index c9705cb3d5..d8486fb179 100644 --- a/remix-simulator/src/methods/blocks.js +++ b/remix-simulator/src/methods/blocks.js @@ -56,12 +56,6 @@ function toHex(value) { } Blocks.prototype.eth_getBlockByHash = function (payload, cb) { - console.dir("eth_getBlockByHash") - console.dir(payload) - console.dir(Object.keys(executionContext.blocks)) - console.dir("== toJSON") - console.dir(executionContext.blocks[payload.params[0]].toJSON()) - var block = executionContext.blocks[payload.params[0]] let b = { diff --git a/remix-simulator/src/methods/transactions.js b/remix-simulator/src/methods/transactions.js index 23faa32bfa..f51df66d7f 100644 --- a/remix-simulator/src/methods/transactions.js +++ b/remix-simulator/src/methods/transactions.js @@ -40,8 +40,6 @@ Transactions.prototype.eth_sendTransaction = function (payload, cb) { } Transactions.prototype.eth_getTransactionReceipt = function (payload, cb) { - console.dir("== eth_getTransactionReceipt") - console.dir(payload.params) executionContext.web3().eth.getTransactionReceipt(payload.params[0], (error, receipt) => { if (error) { return cb(error) @@ -70,22 +68,13 @@ Transactions.prototype.eth_estimateGas = function (payload, cb) { } Transactions.prototype.eth_getCode = function (payload, cb) { - console.dir("== eth_getCode") - console.dir(payload.params) let address = payload.params[0] - console.dir(address); - // const account = ethJSUtil.toBuffer(address) - // console.dir(account) - - //executionContext.vm().stateManager.getContractCode(account, (error, result) => { - //executionContext.web3().eth.getContractCode(address, (error, result) => { executionContext.web3().eth.getCode(address, (error, result) => { if (error) { console.dir("error getting code"); console.dir(error); } - //cb(error, hexConvert(result)) cb(error, result) }) } @@ -107,8 +96,6 @@ Transactions.prototype.eth_getTransactionCount = function (payload, cb) { } Transactions.prototype.eth_getTransactionByHash = function (payload, cb) { - console.dir("== eth_getTransactionByHash") - console.dir(payload.params) const address = payload.params[0] executionContext.web3().eth.getTransactionReceipt(address, (error, receipt) => { @@ -116,14 +103,11 @@ Transactions.prototype.eth_getTransactionByHash = function (payload, cb) { return cb(error) } - console.dir("== receipt") - console.dir(receipt) - var test = executionContext.web3(); var txBlock = executionContext.txs[receipt.transactionHash]; - // executionContext.web3().eth.getBlock(receipt.hash).then((block) => { + // TODO: params to add later let r = { 'blockHash': "0x" + txBlock.hash().toString('hex'), 'blockNumber': "0x" + txBlock.header.number.toString('hex'), @@ -151,14 +135,10 @@ Transactions.prototype.eth_getTransactionByHash = function (payload, cb) { } cb(null, r) - // }) }) } Transactions.prototype.eth_getTransactionByBlockHashAndIndex = function (payload, cb) { - console.dir("== eth_getTransactionByHash") - console.dir(payload.params) - // const address = payload.params[0] const txIndex = payload.params[1] var txBlock = executionContext.blocks[payload.params[0]] @@ -169,7 +149,7 @@ Transactions.prototype.eth_getTransactionByBlockHashAndIndex = function (payload return cb(error) } - // executionContext.web3().eth.getBlock(receipt.hash).then((block) => { + // TODO: params to add later let r = { 'blockHash': "0x" + txBlock.hash().toString('hex'), 'blockNumber': "0x" + txBlock.header.number.toString('hex'), @@ -197,14 +177,10 @@ Transactions.prototype.eth_getTransactionByBlockHashAndIndex = function (payload } cb(null, r) - // }) }) } Transactions.prototype.eth_getTransactionByBlockNumberAndIndex = function (payload, cb) { - console.dir("== eth_getTransactionByHash") - console.dir(payload.params) - // const address = payload.params[0] const txIndex = payload.params[1] var txBlock = executionContext.blocks[payload.params[0]] @@ -215,7 +191,7 @@ Transactions.prototype.eth_getTransactionByBlockNumberAndIndex = function (paylo return cb(error) } - // executionContext.web3().eth.getBlock(receipt.hash).then((block) => { + // TODO: params to add later let r = { 'blockHash': "0x" + txBlock.hash().toString('hex'), 'blockNumber': "0x" + txBlock.header.number.toString('hex'), @@ -243,7 +219,6 @@ Transactions.prototype.eth_getTransactionByBlockNumberAndIndex = function (paylo } cb(null, r) - // }) }) } From c6f72c4eda97831a49860cb3ead7f58a06680c65 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Wed, 12 Jun 2019 07:49:38 -0400 Subject: [PATCH 10/19] fix linting issues --- remix-simulator/src/methods/blocks.js | 53 ++++++------ remix-simulator/src/methods/misc.js | 6 +- remix-simulator/src/methods/transactions.js | 96 +++++++++------------ 3 files changed, 72 insertions(+), 83 deletions(-) diff --git a/remix-simulator/src/methods/blocks.js b/remix-simulator/src/methods/blocks.js index d8486fb179..0291c6275e 100644 --- a/remix-simulator/src/methods/blocks.js +++ b/remix-simulator/src/methods/blocks.js @@ -1,4 +1,3 @@ -var Web3 = require('web3') var RemixLib = require('remix-lib') var executionContext = RemixLib.execution.executionContext @@ -25,34 +24,38 @@ Blocks.prototype.methods = function () { Blocks.prototype.eth_getBlockByNumber = function (payload, cb) { var block = executionContext.blocks[payload.params[0]] + if (!block) { + return cb(new Error('block not found')) + } + let b = { 'number': toHex(block.header.number), - "hash": toHex(block.hash()), + 'hash': toHex(block.hash()), 'parentHash': toHex(block.header.parentHash), 'nonce': toHex(block.header.nonce), - "sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", - "logsBloom": "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331", - "transactionsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "stateRoot": toHex(block.header.stateRoot), + 'sha3Uncles': '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347', + 'logsBloom': '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331', + 'transactionsRoot': '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', + 'stateRoot': toHex(block.header.stateRoot), 'miner': this.coinbase, 'difficulty': toHex(block.header.difficulty), - "totalDifficulty": toHex(block.header.totalDifficulty), + 'totalDifficulty': toHex(block.header.totalDifficulty), 'extraData': toHex(block.header.extraData), - "size": "0x027f07", // 163591 + 'size': '0x027f07', // 163591 'gasLimit': toHex(block.header.gasLimit), 'gasUsed': toHex(block.header.gasUsed), - "timestamp": toHex(block.header.timestamp), - "transactions": block.transactions.map((t) => "0x" + t.hash().toString('hex')), - "uncles": [] + 'timestamp': toHex(block.header.timestamp), + 'transactions': block.transactions.map((t) => '0x' + t.hash().toString('hex')), + 'uncles': [] } cb(null, b) } -function toHex(value) { - if (!value) return "0x0" +function toHex (value) { + if (!value) return '0x0' let v = value.toString('hex') - return ((v === "0x" || v === "") ? "0x0" : ("0x" + v)) + return ((v === '0x' || v === '') ? '0x0' : ('0x' + v)) } Blocks.prototype.eth_getBlockByHash = function (payload, cb) { @@ -60,23 +63,23 @@ Blocks.prototype.eth_getBlockByHash = function (payload, cb) { let b = { 'number': toHex(block.header.number), - "hash": toHex(block.hash()), + 'hash': toHex(block.hash()), 'parentHash': toHex(block.header.parentHash), 'nonce': toHex(block.header.nonce), - "sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", - "logsBloom": "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331", - "transactionsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", - "stateRoot": toHex(block.header.stateRoot), + 'sha3Uncles': '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347', + 'logsBloom': '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331', + 'transactionsRoot': '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', + 'stateRoot': toHex(block.header.stateRoot), 'miner': this.coinbase, 'difficulty': toHex(block.header.difficulty), - "totalDifficulty": toHex(block.header.totalDifficulty), + 'totalDifficulty': toHex(block.header.totalDifficulty), 'extraData': toHex(block.header.extraData), - "size": "0x027f07", // 163591 + 'size': '0x027f07', // 163591 'gasLimit': toHex(block.header.gasLimit), 'gasUsed': toHex(block.header.gasUsed), - "timestamp": toHex(block.header.timestamp), - "transactions": block.transactions.map((t) => "0x" + t.hash().toString('hex')), - "uncles": [] + 'timestamp': toHex(block.header.timestamp), + 'transactions': block.transactions.map((t) => '0x' + t.hash().toString('hex')), + 'uncles': [] } cb(null, b) @@ -114,4 +117,4 @@ Blocks.prototype.eth_getUncleCountByBlockNumber = function (payload, cb) { cb(null, 0) } -module.exports = Blocks \ No newline at end of file +module.exports = Blocks diff --git a/remix-simulator/src/methods/misc.js b/remix-simulator/src/methods/misc.js index dfa48baaed..590ca5bb1c 100644 --- a/remix-simulator/src/methods/misc.js +++ b/remix-simulator/src/methods/misc.js @@ -50,15 +50,15 @@ Misc.prototype.eth_getCompilers = function (payload, cb) { } Misc.prototype.eth_compileSolidity = function (payload, cb) { - cb(null, "unsupported") + cb(null, 'unsupported') } Misc.prototype.eth_compileLLL = function (payload, cb) { - cb(null, "unsupported") + cb(null, 'unsupported') } Misc.prototype.eth_compileSerpent = function (payload, cb) { - cb(null, "unsupported") + cb(null, 'unsupported') } module.exports = Misc diff --git a/remix-simulator/src/methods/transactions.js b/remix-simulator/src/methods/transactions.js index f51df66d7f..754b191604 100644 --- a/remix-simulator/src/methods/transactions.js +++ b/remix-simulator/src/methods/transactions.js @@ -1,22 +1,10 @@ +var Web3 = require('web3') var RemixLib = require('remix-lib') var executionContext = RemixLib.execution.executionContext var ethJSUtil = require('ethereumjs-util') var processTx = require('./txProcess.js') var BN = ethJSUtil.BN -function hexConvert (ints) { - var ret = '0x' - for (var i = 0; i < ints.length; i++) { - var h = ints[i] - if (h) { - ret += (h <= 0xf ? '0' : '') + h.toString(16) - } else { - ret += '00' - } - } - return ret -} - var Transactions = function (accounts) { this.accounts = accounts } @@ -45,15 +33,15 @@ Transactions.prototype.eth_getTransactionReceipt = function (payload, cb) { return cb(error) } - var txBlock = executionContext.txs[receipt.hash]; + var txBlock = executionContext.txs[receipt.hash] var r = { 'transactionHash': receipt.hash, 'transactionIndex': '0x00', - 'blockHash': "0x" + txBlock.hash().toString('hex'), - 'blockNumber': "0x" + txBlock.header.number.toString('hex'), - 'gasUsed': web3.utils.toHex(receipt.gas), - 'cumulativeGasUsed': web3.utils.toHex(receipt.gas), + 'blockHash': '0x' + txBlock.hash().toString('hex'), + 'blockNumber': '0x' + txBlock.header.number.toString('hex'), + 'gasUsed': Web3.utils.toHex(receipt.gas), + 'cumulativeGasUsed': Web3.utils.toHex(receipt.gas), 'contractAddress': receipt.contractAddress, 'logs': receipt.logs, 'status': receipt.status @@ -70,13 +58,13 @@ Transactions.prototype.eth_estimateGas = function (payload, cb) { Transactions.prototype.eth_getCode = function (payload, cb) { let address = payload.params[0] - executionContext.web3().eth.getCode(address, (error, result) => { - if (error) { - console.dir("error getting code"); - console.dir(error); - } - cb(error, result) - }) + executionContext.web3().eth.getCode(address, (error, result) => { + if (error) { + console.dir('error getting code') + console.dir(error) + } + cb(error, result) + }) } Transactions.prototype.eth_call = function (payload, cb) { @@ -103,35 +91,33 @@ Transactions.prototype.eth_getTransactionByHash = function (payload, cb) { return cb(error) } - var test = executionContext.web3(); - - var txBlock = executionContext.txs[receipt.transactionHash]; + var txBlock = executionContext.txs[receipt.transactionHash] // TODO: params to add later let r = { - 'blockHash': "0x" + txBlock.hash().toString('hex'), - 'blockNumber': "0x" + txBlock.header.number.toString('hex'), + 'blockHash': '0x' + txBlock.hash().toString('hex'), + 'blockNumber': '0x' + txBlock.header.number.toString('hex'), 'from': receipt.from, - 'gas': web3.utils.toHex(receipt.gas), + 'gas': Web3.utils.toHex(receipt.gas), // 'gasPrice': '2000000000000', // 0x123 - "gasPrice":"0x4a817c800", // 20000000000 + 'gasPrice': '0x4a817c800', // 20000000000 'hash': receipt.transactionHash, 'input': receipt.input, // "nonce": 2, // 0x15 // "transactionIndex": 0, - "value": receipt.value + 'value': receipt.value // "value":"0xf3dbb76162000" // 4290000000000000 - // "v": "0x25", // 37 - // "r": "0x1b5e176d927f8e9ab405058b2d2457392da3e20f328b16ddabcebc33eaac5fea", - // "s": "0x4ba69724e8f69de52f0125ad8b3c5c2cef33019bac3249e2c0a2192766d1721c" + // "v": "0x25", // 37 + // "r": "0x1b5e176d927f8e9ab405058b2d2457392da3e20f328b16ddabcebc33eaac5fea", + // "s": "0x4ba69724e8f69de52f0125ad8b3c5c2cef33019bac3249e2c0a2192766d1721c" } if (receipt.to) { r.to = receipt.to } - if (r.value === "0x") { - r.value = "0x0" + if (r.value === '0x') { + r.value = '0x0' } cb(null, r) @@ -142,7 +128,7 @@ Transactions.prototype.eth_getTransactionByBlockHashAndIndex = function (payload const txIndex = payload.params[1] var txBlock = executionContext.blocks[payload.params[0]] - const txHash = "0x" + txBlock.transactions[web3.utils.toDecimal(txIndex)].hash().toString('hex') + const txHash = '0x' + txBlock.transactions[Web3.utils.toDecimal(txIndex)].hash().toString('hex') executionContext.web3().eth.getTransactionReceipt(txHash, (error, receipt) => { if (error) { @@ -151,17 +137,17 @@ Transactions.prototype.eth_getTransactionByBlockHashAndIndex = function (payload // TODO: params to add later let r = { - 'blockHash': "0x" + txBlock.hash().toString('hex'), - 'blockNumber': "0x" + txBlock.header.number.toString('hex'), + 'blockHash': '0x' + txBlock.hash().toString('hex'), + 'blockNumber': '0x' + txBlock.header.number.toString('hex'), 'from': receipt.from, - 'gas': web3.utils.toHex(receipt.gas), + 'gas': Web3.utils.toHex(receipt.gas), // 'gasPrice': '2000000000000', // 0x123 - "gasPrice": "0x4a817c800", // 20000000000 + 'gasPrice': '0x4a817c800', // 20000000000 'hash': receipt.transactionHash, 'input': receipt.input, // "nonce": 2, // 0x15 // "transactionIndex": 0, - "value": receipt.value + 'value': receipt.value // "value":"0xf3dbb76162000" // 4290000000000000 // "v": "0x25", // 37 // "r": "0x1b5e176d927f8e9ab405058b2d2457392da3e20f328b16ddabcebc33eaac5fea", @@ -172,8 +158,8 @@ Transactions.prototype.eth_getTransactionByBlockHashAndIndex = function (payload r.to = receipt.to } - if (r.value === "0x") { - r.value = "0x0" + if (r.value === '0x') { + r.value = '0x0' } cb(null, r) @@ -184,7 +170,7 @@ Transactions.prototype.eth_getTransactionByBlockNumberAndIndex = function (paylo const txIndex = payload.params[1] var txBlock = executionContext.blocks[payload.params[0]] - const txHash = "0x" + txBlock.transactions[web3.utils.toDecimal(txIndex)].hash().toString('hex') + const txHash = '0x' + txBlock.transactions[Web3.utils.toDecimal(txIndex)].hash().toString('hex') executionContext.web3().eth.getTransactionReceipt(txHash, (error, receipt) => { if (error) { @@ -193,17 +179,17 @@ Transactions.prototype.eth_getTransactionByBlockNumberAndIndex = function (paylo // TODO: params to add later let r = { - 'blockHash': "0x" + txBlock.hash().toString('hex'), - 'blockNumber': "0x" + txBlock.header.number.toString('hex'), + 'blockHash': '0x' + txBlock.hash().toString('hex'), + 'blockNumber': '0x' + txBlock.header.number.toString('hex'), 'from': receipt.from, - 'gas': web3.utils.toHex(receipt.gas), + 'gas': Web3.utils.toHex(receipt.gas), // 'gasPrice': '2000000000000', // 0x123 - "gasPrice": "0x4a817c800", // 20000000000 + 'gasPrice': '0x4a817c800', // 20000000000 'hash': receipt.transactionHash, 'input': receipt.input, // "nonce": 2, // 0x15 // "transactionIndex": 0, - "value": receipt.value + 'value': receipt.value // "value":"0xf3dbb76162000" // 4290000000000000 // "v": "0x25", // 37 // "r": "0x1b5e176d927f8e9ab405058b2d2457392da3e20f328b16ddabcebc33eaac5fea", @@ -214,12 +200,12 @@ Transactions.prototype.eth_getTransactionByBlockNumberAndIndex = function (paylo r.to = receipt.to } - if (r.value === "0x") { - r.value = "0x0" + if (r.value === '0x') { + r.value = '0x0' } cb(null, r) }) } -module.exports = Transactions \ No newline at end of file +module.exports = Transactions From f88a15cdea62bbf12f841245b49a16a5e9c8fd76 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Wed, 12 Jun 2019 09:19:24 -0400 Subject: [PATCH 11/19] fix tests; add method to generate empty block --- remix-lib/src/execution/txRunner.js | 2 +- remix-simulator/src/genesis.js | 40 +++++++++++++++++++++++++++++ remix-simulator/src/provider.js | 6 ++++- remix-simulator/test/blocks.js | 22 ++++++++-------- 4 files changed, 56 insertions(+), 14 deletions(-) create mode 100644 remix-simulator/src/genesis.js diff --git a/remix-lib/src/execution/txRunner.js b/remix-lib/src/execution/txRunner.js index dc2a9e584b..cda299cd72 100644 --- a/remix-lib/src/execution/txRunner.js +++ b/remix-lib/src/execution/txRunner.js @@ -14,7 +14,7 @@ class TxRunner { this.runAsync = true if (executionContext.isVM()) { //this.blockNumber = 1150000 // The VM is running in Homestead mode, which started at this block. - this.blockNumber = 1 // The VM is running in Homestead mode, which started at this block. + this.blockNumber = 2 // The VM is running in Homestead mode, which started at this block. this.runAsync = false // We have to run like this cause the VM Event Manager does not support running multiple txs at the same time. } this.pendingTxs = {} diff --git a/remix-simulator/src/genesis.js b/remix-simulator/src/genesis.js new file mode 100644 index 0000000000..40bf11e8a7 --- /dev/null +++ b/remix-simulator/src/genesis.js @@ -0,0 +1,40 @@ +var EthJSBlock = require('ethereumjs-block') +var RemixLib = require('remix-lib') +var executionContext = RemixLib.execution.executionContext +var ethJSUtil = require('ethereumjs-util') +var BN = ethJSUtil.BN + +function checkpointAndCommit (cb) { + if (executionContext.vm().stateManager._checkpointCount > 0) { + return executionContext.vm().stateManager.commit(() => { + cb() + }) + } + executionContext.vm().stateManager.checkpoint(() => { + executionContext.vm().stateManager.commit(() => { + cb() + }) + }) +} + +function generateBlock () { + var block = new EthJSBlock({ + header: { + timestamp: (new Date().getTime() / 1000 | 0), + number: 1, + coinbase: '0x0e9281e9c6a0808672eaba6bd1220e144c9bb07a', + difficulty: (new BN('69762765929000', 10)), + gasLimit: new BN('5000000').imuln(1) + }, + transactions: [], + uncleHeaders: [] + }) + + checkpointAndCommit(() => { + executionContext.vm().runBlock({ block: block, generate: true, skipBlockValidation: true, skipBalance: false }, function () { + executionContext.addBlock(block) + }) + }) +} + +module.exports = generateBlock \ No newline at end of file diff --git a/remix-simulator/src/provider.js b/remix-simulator/src/provider.js index cf38200d4c..3a28adfd9f 100644 --- a/remix-simulator/src/provider.js +++ b/remix-simulator/src/provider.js @@ -8,6 +8,8 @@ const Net = require('./methods/net.js') const Transactions = require('./methods/transactions.js') const Whisper = require('./methods/whisper.js') +const generateBlock = require('./genesis.js') + var Provider = function (options) { this.Accounts = new Accounts() @@ -18,6 +20,8 @@ var Provider = function (options) { this.methods = merge(this.methods, (new Net()).methods()) this.methods = merge(this.methods, (new Transactions(this.Accounts.accounts)).methods()) this.methods = merge(this.methods, (new Whisper()).methods()) + + generateBlock() } Provider.prototype.sendAsync = function (payload, callback) { @@ -44,4 +48,4 @@ Provider.prototype.isConnected = function () { return true } -module.exports = Provider +module.exports = Provider \ No newline at end of file diff --git a/remix-simulator/test/blocks.js b/remix-simulator/test/blocks.js index d56deee4c8..60b87dbb55 100644 --- a/remix-simulator/test/blocks.js +++ b/remix-simulator/test/blocks.js @@ -16,22 +16,20 @@ describe('blocks', function () { let block = await web3.eth.getBlock(1) let expectedBlock = { - difficulty: '0', - extraData: '0x', - gasLimit: 8000000, + difficulty: '69762765929000', + extraData: '0x0', + gasLimit: 5000000, gasUsed: 0, - hash: '0xdb731f3622ef37b4da8db36903de029220dba74c41185f8429f916058b86559f', - logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', + hash: block.hash.toString('hex'), + logsBloom: '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331', miner: '0x0000000000000000000000000000000000000001', - mixHash: '0x0000000000000000000000000000000000000000000000000000000000000000', - nonce: '0x0000000000000042', - number: 0, + nonce: '0x0000000000000000', + number: 1, parentHash: '0x0000000000000000000000000000000000000000000000000000000000000000', - receiptsRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', sha3Uncles: '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347', - size: 504, - stateRoot: '0xb7917653f92e62394d2207d0f39a1320ff1cb93d1cee80d3c492627e00b219ff', - timestamp: 0, + size: 163591, + stateRoot: '0xa633ca0e8f0ae4e86d4d572b048ea93d84eb4b11e2c988b48cb3a5f6f10b3c68', + timestamp: block.timestamp, totalDifficulty: '0', transactions: [], transactionsRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', From f0ee2dce90a1b4373710e431d9239b9be04c9804 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Wed, 12 Jun 2019 09:20:34 -0400 Subject: [PATCH 12/19] fix linting issues --- remix-lib/src/execution/execution-context.js | 6 +++--- remix-lib/src/execution/txRunner.js | 9 ++++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/remix-lib/src/execution/execution-context.js b/remix-lib/src/execution/execution-context.js index b9a317e74a..c352519826 100644 --- a/remix-lib/src/execution/execution-context.js +++ b/remix-lib/src/execution/execution-context.js @@ -276,14 +276,14 @@ function ExecutionContext () { } this.addBlock = function (block) { - let blockNumber = "0x" + block.header.number.toString('hex') + let blockNumber = '0x' + block.header.number.toString('hex') blockNumber = web3.toHex(web3.toBigNumber(blockNumber)) - self.blocks["0x" + block.hash().toString('hex')] = block + self.blocks['0x' + block.hash().toString('hex')] = block self.blocks[blockNumber] = block } - this.trackTx = function(tx, block) { + this.trackTx = function (tx, block) { self.txs[tx] = block } } diff --git a/remix-lib/src/execution/txRunner.js b/remix-lib/src/execution/txRunner.js index cda299cd72..4dc07b87f8 100644 --- a/remix-lib/src/execution/txRunner.js +++ b/remix-lib/src/execution/txRunner.js @@ -13,7 +13,7 @@ class TxRunner { this.blockNumber = 0 this.runAsync = true if (executionContext.isVM()) { - //this.blockNumber = 1150000 // The VM is running in Homestead mode, which started at this block. + // this.blockNumber = 1150000 // The VM is running in Homestead mode, which started at this block. this.blockNumber = 2 // The VM is running in Homestead mode, which started at this block. this.runAsync = false // We have to run like this cause the VM Event Manager does not support running multiple txs at the same time. } @@ -94,7 +94,7 @@ class TxRunner { } } - runInVm(from, to, data, value, gasLimit, useCall, timestamp, callback) { + runInVm (from, to, data, value, gasLimit, useCall, timestamp, callback) { const self = this var account = self.vmaccounts[from] if (!account) { @@ -119,8 +119,7 @@ class TxRunner { number: self.blockNumber, coinbase: coinbases[self.blockNumber % coinbases.length], difficulty: difficulties[self.blockNumber % difficulties.length], - coinbase: coinbases[0], - gasLimit: new BN("5000000").imuln(1) + gasLimit: new BN('5000000').imuln(1) }, transactions: [tx], uncleHeaders: [] @@ -144,7 +143,7 @@ class TxRunner { } executionContext.addBlock(block) - executionContext.trackTx("0x" + tx.hash().toString('hex'), block) + executionContext.trackTx('0x' + tx.hash().toString('hex'), block) callback(err, { result: result, From 3c49f437f089e452f21f60ee6f9c141bdc0936a4 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Wed, 12 Jun 2019 09:26:50 -0400 Subject: [PATCH 13/19] fix linting issues --- remix-simulator/src/genesis.js | 2 +- remix-simulator/src/provider.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/remix-simulator/src/genesis.js b/remix-simulator/src/genesis.js index 40bf11e8a7..57112fef1d 100644 --- a/remix-simulator/src/genesis.js +++ b/remix-simulator/src/genesis.js @@ -37,4 +37,4 @@ function generateBlock () { }) } -module.exports = generateBlock \ No newline at end of file +module.exports = generateBlock diff --git a/remix-simulator/src/provider.js b/remix-simulator/src/provider.js index 3a28adfd9f..3778b58876 100644 --- a/remix-simulator/src/provider.js +++ b/remix-simulator/src/provider.js @@ -48,4 +48,4 @@ Provider.prototype.isConnected = function () { return true } -module.exports = Provider \ No newline at end of file +module.exports = Provider From f373aa22b81e28921386fc114f44f68e056e307c Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Sat, 15 Jun 2019 10:06:29 -0400 Subject: [PATCH 14/19] fix remix-tests; fix commit condition --- remix-lib/src/execution/txRunner.js | 12 +++++++----- remix-simulator/src/genesis.js | 2 +- remix-simulator/test/blocks.js | 2 +- remix-tests/src/testRunner.ts | 1 + remix-tests/tests/testRunner.ts | 6 +++++- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/remix-lib/src/execution/txRunner.js b/remix-lib/src/execution/txRunner.js index 4dc07b87f8..14b22c2a93 100644 --- a/remix-lib/src/execution/txRunner.js +++ b/remix-lib/src/execution/txRunner.js @@ -104,7 +104,7 @@ class TxRunner { timestamp: timestamp, nonce: new BN(account.nonce++), gasPrice: new BN(1), - gasLimit: new BN(gasLimit, 10), + gasLimit: gasLimit, to: to, value: new BN(value, 10), data: Buffer.from(data.slice(2), 'hex') @@ -119,7 +119,7 @@ class TxRunner { number: self.blockNumber, coinbase: coinbases[self.blockNumber % coinbases.length], difficulty: difficulties[self.blockNumber % difficulties.length], - gasLimit: new BN('5000000').imuln(1) + gasLimit: new BN('8000000').imuln(1) }, transactions: [tx], uncleHeaders: [] @@ -132,12 +132,14 @@ class TxRunner { this.checkpointAndCommit(() => { executionContext.vm().runBlock({ block: block, generate: true, skipBlockValidation: true, skipBalance: false }, function (err, results) { + err = err ? err.message : err + if (err) { + return callback(err) + } let result = results.results[0] - console.dir(result) if (useCall) { executionContext.vm().stateManager.revert(function () { }) } - err = err ? err.message : err if (result) { result.status = '0x' + result.vm.exception.toString(16) } @@ -154,7 +156,7 @@ class TxRunner { } checkpointAndCommit (cb) { - if (executionContext.vm().stateManager._checkpointCount > 0) { + if (executionContext.vm().stateManager._checkpointCount > 1) { return executionContext.vm().stateManager.commit(() => { cb() }) diff --git a/remix-simulator/src/genesis.js b/remix-simulator/src/genesis.js index 57112fef1d..542930a2a8 100644 --- a/remix-simulator/src/genesis.js +++ b/remix-simulator/src/genesis.js @@ -24,7 +24,7 @@ function generateBlock () { number: 1, coinbase: '0x0e9281e9c6a0808672eaba6bd1220e144c9bb07a', difficulty: (new BN('69762765929000', 10)), - gasLimit: new BN('5000000').imuln(1) + gasLimit: new BN('8000000').imuln(1) }, transactions: [], uncleHeaders: [] diff --git a/remix-simulator/test/blocks.js b/remix-simulator/test/blocks.js index 60b87dbb55..eafc0f3ec4 100644 --- a/remix-simulator/test/blocks.js +++ b/remix-simulator/test/blocks.js @@ -18,7 +18,7 @@ describe('blocks', function () { let expectedBlock = { difficulty: '69762765929000', extraData: '0x0', - gasLimit: 5000000, + gasLimit: 8000000, gasUsed: 0, hash: block.hash.toString('hex'), logsBloom: '0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331', diff --git a/remix-tests/src/testRunner.ts b/remix-tests/src/testRunner.ts index 2b1791d1ce..476ecf812b 100644 --- a/remix-tests/src/testRunner.ts +++ b/remix-tests/src/testRunner.ts @@ -76,6 +76,7 @@ export function runTest (testName, testObject: any, contractDetails: any, opts: value: testName, filename: testObject.filename } + testCallback(undefined, resp) async.eachOfLimit(runList, 1, function (func, index, next) { let sender diff --git a/remix-tests/tests/testRunner.ts b/remix-tests/tests/testRunner.ts index db93804514..fe324cbcfe 100644 --- a/remix-tests/tests/testRunner.ts +++ b/remix-tests/tests/testRunner.ts @@ -9,15 +9,18 @@ import { deployAll } from '../dist/deployer' import { runTest } from '../dist/index' import { ResultsInterface, TestCbInterface, ResultCbInterface } from '../dist/index' +var provider = new Provider() + function compileAndDeploy(filename: string, callback: Function) { let web3: Web3 = new Web3() - web3.setProvider(new Provider()) + web3.setProvider(provider) let compilationData: object let accounts: string[] async.waterfall([ function getAccountList(next: Function): void { web3.eth.getAccounts((_err: Error | null | undefined, _accounts: string[]) => { accounts = _accounts + web3.eth.defaultAccount = accounts[0] next(_err) }) }, @@ -93,6 +96,7 @@ describe('testRunner', () => { results = _results done() } + runTest('MyTest', contracts.MyTest, compilationData[filename]['MyTest'], { accounts }, testCallback, resultsCallback) }) }) From b778f28ecec9c1c3ff1c042991cec7ff04d464d5 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Wed, 17 Jul 2019 08:40:23 -0400 Subject: [PATCH 15/19] re-add revert on context change --- remix-lib/src/execution/execution-context.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/remix-lib/src/execution/execution-context.js b/remix-lib/src/execution/execution-context.js index c352519826..9aa3d34efa 100644 --- a/remix-lib/src/execution/execution-context.js +++ b/remix-lib/src/execution/execution-context.js @@ -186,6 +186,9 @@ function ExecutionContext () { if (context === 'vm') { executionContext = context + vms.constantinople.stateManager.revert(() => { + vms.constantinople.stateManager.checkpoint(() => {}) + }) self.event.trigger('contextChanged', ['vm']) return cb() } From 56deb3499f9f695dde0e7ca0436654adca46e374 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 23 Jul 2019 10:32:32 -0400 Subject: [PATCH 16/19] ensure gasLimit is a BN --- remix-lib/src/execution/txRunner.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/remix-lib/src/execution/txRunner.js b/remix-lib/src/execution/txRunner.js index 14b22c2a93..3f274d4e75 100644 --- a/remix-lib/src/execution/txRunner.js +++ b/remix-lib/src/execution/txRunner.js @@ -94,12 +94,17 @@ class TxRunner { } } - runInVm (from, to, data, value, gasLimit, useCall, timestamp, callback) { + runInVm (from, to, data, value, _gasLimit, useCall, timestamp, callback) { const self = this var account = self.vmaccounts[from] if (!account) { return callback('Invalid account selected') } + let gasLimit = _gasLimit + if (!BN.isBN(_gasLimit)) { + gasLimit = new BN(_gasLimit) + } + var tx = new EthJSTX({ timestamp: timestamp, nonce: new BN(account.nonce++), From 3862f1a12dca37c0286cbcf7a9821309ae98ba99 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 23 Jul 2019 10:42:37 -0400 Subject: [PATCH 17/19] remove duplicated checkpointAndCommit --- remix-lib/src/execution/execution-context.js | 13 +++++++++++++ remix-lib/src/execution/txRunner.js | 17 ++--------------- remix-simulator/src/genesis.js | 15 +-------------- 3 files changed, 16 insertions(+), 29 deletions(-) diff --git a/remix-lib/src/execution/execution-context.js b/remix-lib/src/execution/execution-context.js index 9aa3d34efa..08b9b2ce06 100644 --- a/remix-lib/src/execution/execution-context.js +++ b/remix-lib/src/execution/execution-context.js @@ -220,6 +220,19 @@ function ExecutionContext () { } } + this.checkpointAndCommit = function (cb, checkpointCount) { + if (this.vm().stateManager._checkpointCount > (checkpointCount || 0)) { + return this.vm().stateManager.commit(() => { + cb() + }) + } + this.vm().stateManager.checkpoint(() => { + this.vm().stateManager.commit(() => { + cb() + }) + }) + } + this.currentblockGasLimit = function () { return this.blockGasLimit } diff --git a/remix-lib/src/execution/txRunner.js b/remix-lib/src/execution/txRunner.js index 3f274d4e75..7ad38fb02c 100644 --- a/remix-lib/src/execution/txRunner.js +++ b/remix-lib/src/execution/txRunner.js @@ -135,7 +135,7 @@ class TxRunner { executionContext.vm().stateManager.checkpoint(() => { }) } - this.checkpointAndCommit(() => { + executionContext.checkpointAndCommit(() => { executionContext.vm().runBlock({ block: block, generate: true, skipBlockValidation: true, skipBalance: false }, function (err, results) { err = err ? err.message : err if (err) { @@ -157,20 +157,7 @@ class TxRunner { transactionHash: ethJSUtil.bufferToHex(Buffer.from(tx.hash())) }) }) - }) - } - - checkpointAndCommit (cb) { - if (executionContext.vm().stateManager._checkpointCount > 1) { - return executionContext.vm().stateManager.commit(() => { - cb() - }) - } - executionContext.vm().stateManager.checkpoint(() => { - executionContext.vm().stateManager.commit(() => { - cb() - }) - }) + }, 1) } runInNode (from, to, data, value, gasLimit, useCall, confirmCb, gasEstimationForceSend, promptCb, callback) { diff --git a/remix-simulator/src/genesis.js b/remix-simulator/src/genesis.js index 542930a2a8..295cb935f4 100644 --- a/remix-simulator/src/genesis.js +++ b/remix-simulator/src/genesis.js @@ -4,19 +4,6 @@ var executionContext = RemixLib.execution.executionContext var ethJSUtil = require('ethereumjs-util') var BN = ethJSUtil.BN -function checkpointAndCommit (cb) { - if (executionContext.vm().stateManager._checkpointCount > 0) { - return executionContext.vm().stateManager.commit(() => { - cb() - }) - } - executionContext.vm().stateManager.checkpoint(() => { - executionContext.vm().stateManager.commit(() => { - cb() - }) - }) -} - function generateBlock () { var block = new EthJSBlock({ header: { @@ -30,7 +17,7 @@ function generateBlock () { uncleHeaders: [] }) - checkpointAndCommit(() => { + executionContext.checkpointAndCommit(() => { executionContext.vm().runBlock({ block: block, generate: true, skipBlockValidation: true, skipBalance: false }, function () { executionContext.addBlock(block) }) From fa3623e4416327a86e6de39ffd25de156e86f810 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 23 Jul 2019 11:00:30 -0400 Subject: [PATCH 18/19] revert changes made to gasLimit --- remix-lib/src/execution/txRunner.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/remix-lib/src/execution/txRunner.js b/remix-lib/src/execution/txRunner.js index 7ad38fb02c..a8911981b8 100644 --- a/remix-lib/src/execution/txRunner.js +++ b/remix-lib/src/execution/txRunner.js @@ -94,16 +94,12 @@ class TxRunner { } } - runInVm (from, to, data, value, _gasLimit, useCall, timestamp, callback) { + runInVm (from, to, data, value, gasLimit, useCall, timestamp, callback) { const self = this var account = self.vmaccounts[from] if (!account) { return callback('Invalid account selected') } - let gasLimit = _gasLimit - if (!BN.isBN(_gasLimit)) { - gasLimit = new BN(_gasLimit) - } var tx = new EthJSTX({ timestamp: timestamp, @@ -124,7 +120,7 @@ class TxRunner { number: self.blockNumber, coinbase: coinbases[self.blockNumber % coinbases.length], difficulty: difficulties[self.blockNumber % difficulties.length], - gasLimit: new BN('8000000').imuln(1) + gasLimit: new BN(gasLimit, 10).imuln(2) }, transactions: [tx], uncleHeaders: [] From d4f0c63a139615c4c91654562a91ad67ba53c608 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Wed, 7 Aug 2019 11:26:36 -0400 Subject: [PATCH 19/19] add comment explaining the the reason for checking the checkpointCount variable --- remix-lib/src/execution/execution-context.js | 1 + 1 file changed, 1 insertion(+) diff --git a/remix-lib/src/execution/execution-context.js b/remix-lib/src/execution/execution-context.js index 08b9b2ce06..b9b130c72d 100644 --- a/remix-lib/src/execution/execution-context.js +++ b/remix-lib/src/execution/execution-context.js @@ -221,6 +221,7 @@ function ExecutionContext () { } this.checkpointAndCommit = function (cb, checkpointCount) { + // due to issue https://github.com/ethereumjs/ethereumjs-vm/issues/567 if (this.vm().stateManager._checkpointCount > (checkpointCount || 0)) { return this.vm().stateManager.commit(() => { cb()