Skip to content

Commit f2215c0

Browse files
authored
Merge branch 'master' into istanbul/eip-2200
2 parents d6a7e84 + 2d9cdd8 commit f2215c0

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

lib/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,14 @@ export interface VMOpts {
4040
*/
4141
blockchain?: Blockchain
4242
/**
43-
* If true, create entries in the state tree for the precompiled contracts
43+
* If true, create entries in the state tree for the precompiled contracts, saving some gas the
44+
* first time each of them is called.
45+
*
46+
* If this parameter is false, the first call to each of them has to pay an extra 25000 gas
47+
* for creating the account.
48+
*
49+
* Setting this to true has the effect of precompiled contracts' gas costs matching mainnet's from
50+
* the very first call, which is intended for testing networks.
4451
*/
4552
activatePrecompiles?: boolean
4653
/**

lib/state/stateManager.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,11 @@ export default class StateManager {
526526
addresses,
527527
(address: string, done: any) => {
528528
const account = new Account()
529-
account.balance = new BN(initState[address]).toArrayLike(Buffer)
529+
if (initState[address].slice(0, 2) === '0x') {
530+
account.balance = new BN(initState[address].slice(2), 16).toArrayLike(Buffer)
531+
} else {
532+
account.balance = new BN(initState[address]).toArrayLike(Buffer)
533+
}
530534
const addressBuffer = utils.toBuffer(address)
531535
this._trie.put(addressBuffer, account.serialize(), done)
532536
},

tests/api/state/stateManager.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,25 @@ tape('StateManager', (t) => {
138138
st.end()
139139
})
140140

141+
t.test('should generate correct genesis state root for all chains', async (st) => {
142+
const chains = ['mainnet', 'ropsten', 'rinkeby', 'kovan', 'goerli']
143+
for (const chain of chains) {
144+
const common = new Common(chain, 'petersburg')
145+
const expectedStateRoot = Buffer.from(common.genesis().stateRoot.slice(2), 'hex')
146+
const stateManager = new StateManager({ common: common })
147+
148+
const generateCanonicalGenesis = promisify((...args) => stateManager.generateCanonicalGenesis(...args))
149+
const getStateRoot = promisify((...args) => stateManager.getStateRoot(...args))
150+
151+
await generateCanonicalGenesis()
152+
let stateRoot = await getStateRoot()
153+
154+
st.true(stateRoot.equals(expectedStateRoot), `generateCanonicalGenesis should produce correct state root for ${chain}`)
155+
}
156+
157+
st.end()
158+
})
159+
141160
t.test('should dump storage', async st => {
142161
const stateManager = new StateManager()
143162
const addressBuffer = Buffer.from('a94f5374fce5edbc8e2a8697c15331677e6ebf0b', 'hex')

0 commit comments

Comments
 (0)