Skip to content
This repository was archived by the owner on Mar 3, 2021. It is now read-only.

Commit b9fdc27

Browse files
authored
Merge pull request #1141 from ethereum/constantinople
constantinople support (JSVM)
2 parents 5ddd9b1 + c5b4a65 commit b9fdc27

File tree

9 files changed

+50
-26
lines changed

9 files changed

+50
-26
lines changed

remix-debug/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"dependencies": {
2121
"commander": "^2.19.0",
2222
"ethereumjs-util": "^4.5.0",
23-
"ethereumjs-vm": "2.4.0",
23+
"ethereumjs-vm": "github:yann300/ethereumjs-vm#48db4cb8f884234428682803c2ea5301f5141e96",
2424
"fast-async": "^6.1.2",
2525
"remix-lib": "0.4.1"
2626
},

remix-debug/test/decoder/vmCall.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,15 @@ function initVM (st, privateKey) {
4242
enableHomestead: true,
4343
activatePrecompiles: true
4444
})
45-
vm.stateManager.putAccountBalance(address, 'f00000000000000001', function cb () {})
45+
46+
vm.stateManager.getAccount(address, (error, account) => {
47+
if (error) return console.log(error)
48+
account.balance = '0xf00000000000000001'
49+
vm.stateManager.putAccount(address, account, function cb (error) {
50+
if (error) console.log(error)
51+
})
52+
})
53+
4654
var web3Providers = new Web3Providers()
4755
web3Providers.addVM('VM', vm)
4856
web3Providers.get('VM', function (error, obj) {

remix-debug/test/vmCall.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,15 @@ function initVM (st, privateKey) {
4242
enableHomestead: true,
4343
activatePrecompiles: true
4444
})
45-
vm.stateManager.putAccountBalance(address, 'f00000000000000001', function cb () {})
45+
46+
vm.stateManager.getAccount(address, (error, account) => {
47+
if (error) return console.log(error)
48+
account.balance = '0xf00000000000000001'
49+
vm.stateManager.putAccount(address, account, function cb (error) {
50+
if (error) console.log(error)
51+
})
52+
})
53+
4654
var web3Providers = new Web3Providers()
4755
web3Providers.addVM('VM', vm)
4856
web3Providers.get('VM', function (error, obj) {

remix-lib/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"ethereumjs-block": "^1.6.0",
1919
"ethereumjs-tx": "^1.3.3",
2020
"ethereumjs-util": "^5.1.2",
21-
"ethereumjs-vm": "2.4.0",
21+
"ethereumjs-vm": "github:yann300/ethereumjs-vm#48db4cb8f884234428682803c2ea5301f5141e96",
2222
"ethers": "^3.0.15",
2323
"fast-async": "^6.1.2",
2424
"solc": "^0.5.0",

remix-lib/src/execution/execution-context.js

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,24 @@ class StateManagerCommonStorageDump extends StateManager {
5757
}
5858
}
5959

60-
var stateManager = new StateManagerCommonStorageDump({})
61-
var vm = new EthJSVM({
62-
enableHomestead: true,
63-
activatePrecompiles: true
64-
})
65-
66-
// FIXME: move state manager in EthJSVM ctr
67-
vm.stateManager = stateManager
68-
vm.blockchain = stateManager.blockchain
69-
vm.trie = stateManager.trie
70-
vm.stateManager.checkpoint(() => {})
60+
function createVm (hardfork) {
61+
var stateManager = new StateManagerCommonStorageDump({})
62+
stateManager.checkpoint(() => {})
63+
var vm = new EthJSVM({
64+
activatePrecompiles: true,
65+
blockchain: stateManager.blockchain,
66+
stateManager: stateManager,
67+
hardfork: hardfork
68+
})
69+
var web3vm = new Web3VMProvider()
70+
web3vm.setVM(vm)
71+
return { vm, web3vm, stateManager }
72+
}
7173

72-
var web3VM = new Web3VMProvider()
73-
web3VM.setVM(vm)
74+
var vms = {
75+
byzantium: createVm('byzantium'),
76+
constantinople: createVm('constantinople')
77+
}
7478

7579
var mainNetGenesisHash = '0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3'
7680

@@ -104,7 +108,7 @@ function ExecutionContext () {
104108
}
105109

106110
this.web3 = function () {
107-
return this.isVM() ? web3VM : web3
111+
return this.isVM() ? vms.constantinople.web3vm : web3
108112
}
109113

110114
this.detectNetwork = function (callback) {
@@ -158,7 +162,7 @@ function ExecutionContext () {
158162
}
159163

160164
this.vm = function () {
161-
return vm
165+
return vms.constantinople.vm
162166
}
163167

164168
this.setContext = function (context, endPointUrl, confirmCb, infoCb) {
@@ -171,8 +175,8 @@ function ExecutionContext () {
171175

172176
if (context === 'vm') {
173177
executionContext = context
174-
vm.stateManager.revert(function () {
175-
vm.stateManager.checkpoint()
178+
vms.constantinople.stateManager.revert(() => {
179+
vms.constantinople.stateManager.checkpoint(() => {})
176180
})
177181
self.event.trigger('contextChanged', ['vm'])
178182
return cb()

remix-lib/src/execution/txRunner.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ class TxRunner {
125125
if (!useCall) {
126126
++self.blockNumber
127127
} else {
128-
executionContext.vm().stateManager.checkpoint()
128+
executionContext.vm().stateManager.checkpoint(() => {})
129129
}
130130

131131
executionContext.vm().runTx({block: block, tx: tx, skipBalance: true, skipNonce: true}, function (err, result) {

remix-lib/src/web3Provider/web3VmProvider.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ web3VmProvider.prototype.txWillProcess = function (self, data) {
8888
self.txsReceipt[self.processingHash] = tx
8989
self.storageCache[self.processingHash] = {}
9090
if (tx.to) {
91-
self.vm.stateManager.dumpStorage(tx.to, function (storage) {
91+
const account = ethutil.toBuffer(tx.to)
92+
self.vm.stateManager.dumpStorage(account, function (storage) {
9293
self.storageCache[self.processingHash][tx.to] = storage
9394
})
9495
}
@@ -172,7 +173,8 @@ web3VmProvider.prototype.pushTrace = function (self, data) {
172173
} else {
173174
this.processingAddress = uiutil.normalizeHexAddress(step.stack[step.stack.length - 2])
174175
if (!self.storageCache[self.processingHash][this.processingAddress]) {
175-
self.vm.stateManager.dumpStorage(this.processingAddress, function (storage) {
176+
const account = ethutil.toBuffer(this.processingAddress)
177+
self.vm.stateManager.dumpStorage(account, function (storage) {
176178
self.storageCache[self.processingHash][self.processingAddress] = storage
177179
})
178180
}
@@ -191,7 +193,8 @@ web3VmProvider.prototype.pushTrace = function (self, data) {
191193
}
192194

193195
web3VmProvider.prototype.getCode = function (address, cb) {
194-
this.vm.stateManager.getContractCode(address, function (error, result) {
196+
const account = ethutil.toBuffer(address)
197+
this.vm.stateManager.getContractCode(account, function (error, result) {
195198
cb(error, util.hexConvert(result))
196199
})
197200
}

remix-simulator/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"fast-async": "^6.3.7",
2424
"merge": "^1.2.0",
2525
"remix-lib": "0.4.1",
26+
"standard": "^10.0.3",
2627
"time-stamp": "^2.0.0",
2728
"web3": "1.0.0-beta.27"
2829
},

remix-solidity/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"main": "./index.js",
1616
"dependencies": {
1717
"ethereumjs-util": "^4.5.0",
18-
"ethereumjs-vm": "2.4.0",
18+
"ethereumjs-vm": "github:yann300/ethereumjs-vm#48db4cb8f884234428682803c2ea5301f5141e96",
1919
"fast-async": "^6.1.2",
2020
"remix-lib": "0.4.1",
2121
"solc": "^0.5.0",

0 commit comments

Comments
 (0)