Skip to content

Commit 1270116

Browse files
authored
Merge pull request ethereumjs#415 from ethereumjs/fix-trie-overwrite-issue-on-activeprecompiles
Bugfix for opts.state overwrite
2 parents 1587bef + 240dab6 commit 1270116

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

lib/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ function VM (opts = {}) {
5757
} else {
5858
var trie = opts.state || new Trie()
5959
if (opts.activatePrecompiles) {
60-
trie = new Trie()
6160
for (var i = 1; i <= 8; i++) {
6261
trie.put(new BN(i).toArrayLike(Buffer, 'be', 20), new Account().serialize())
6362
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"ethereumjs-util": "^6.0.0",
4242
"fake-merkle-patricia-tree": "^1.0.1",
4343
"functional-red-black-tree": "^1.0.1",
44-
"merkle-patricia-tree": "^2.1.2",
44+
"merkle-patricia-tree": "^2.3.2",
4545
"rustbn.js": "~0.2.0",
4646
"safe-buffer": "^5.1.1"
4747
},

tests/api/index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ const { promisify } = require('util')
22
const tape = require('tape')
33
const util = require('ethereumjs-util')
44
const Block = require('ethereumjs-block')
5+
const Trie = require('merkle-patricia-tree/secure')
56
const VM = require('../../lib/index')
67
const { setupVM } = require('./utils')
78
const { setupPreConditions } = require('../util')
89
const testData = require('./testdata.json')
910

1011
tape('VM with fake blockchain', (t) => {
11-
t.test('should insantiate without params', (st) => {
12+
t.test('should instantiate without params', (st) => {
1213
const vm = new VM()
1314
st.ok(vm.stateManager)
1415
st.deepEqual(vm.stateManager._trie.root, util.KECCAK256_RLP, 'it has default trie')
@@ -22,6 +23,15 @@ tape('VM with fake blockchain', (t) => {
2223
st.end()
2324
})
2425

26+
t.test('should work with trie (state) provided', (st) => {
27+
let trie = new Trie()
28+
trie.isTestTrie = true
29+
let vm = new VM({ state: trie, activatePrecompiles: true })
30+
st.notEqual(vm.stateManager._trie.root, util.KECCAK256_RLP, 'it has different root')
31+
st.ok(vm.stateManager._trie.isTestTrie, 'it works on trie provided')
32+
st.end()
33+
})
34+
2535
t.test('should only accept valid chain and fork', (st) => {
2636
let vm = new VM({ chain: 'ropsten', hardfork: 'byzantium' })
2737
st.equal(vm.stateManager._common.param('gasPrices', 'ecAdd'), 500)

0 commit comments

Comments
 (0)