Skip to content

Commit

Permalink
vm: fix consensus bug test
Browse files Browse the repository at this point in the history
  • Loading branch information
jochem-brouwer committed Feb 11, 2021
1 parent cb9610f commit 2017d54
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 65 deletions.
2 changes: 0 additions & 2 deletions packages/vm/lib/evm/eei.ts
Original file line number Diff line number Diff line change
Expand Up @@ -564,8 +564,6 @@ export default class EEI {
this._lastReturned = results.execResult.returnValue
}

console.log(results.execResult.exceptionError)

if (
!results.execResult.exceptionError ||
results.execResult.exceptionError.error === ERROR.CODESTORE_OUT_OF_GAS
Expand Down
59 changes: 59 additions & 0 deletions packages/vm/tests/api/consensusBugs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
const level = require('level')
import { Transaction } from '@ethereumjs/tx'
import VM from '../../lib'
import { SecureTrie as Trie } from '@ethereumjs/trie'
import { DefaultStateManager } from '../../lib/state'
import Common from '@ethereumjs/common'
import { Block } from '@ethereumjs/block'
import tape from 'tape'

tape('Consensus bugs', (t) => {
t.test(
'transaction 0x8420dbe268209c4e921bf6b78bc9fb959d9d9553fd16aacb9dd8cad955dbe729 should evaluate to right state root',
async (st) => {
const txData = {
nonce: '0x1a',
gasPrice: '0xba43b7400',
gasLimit: '0x493e0',
to: '0x9ca228250f9d8f86c23690074c2b96d5f5479f79',
value: '0x0',
data:
'0xa9059cbb000000000000000000000000bfe465e7eb5a2928b5bf22bef93ad06089dc6179000000000000000000000000000000000000000000000000006a94d74f430000',
v: '0x1c',
r: '0xc04f048766bea3b20dcea6d2fcaecc92f1a615d337606ab6eec2a1e8e1f27bfe',
s: '0x1c57e62653724560b06c95be750d958840db9fa44ffa777b6625b344bfadbbcf',
}
const common = new Common({ chain: 'mainnet', hardfork: 'chainstart' })
const tx = Transaction.fromTxData(txData, { common })
const trie = new Trie(level('/Users/jochem/Library/Ethereum/ethereumjs/mainnet/state/'))

// Ensure we run on the right root
trie._setRoot(
Buffer.from('9dceb42e227ee6a244449d1d92cc5e0c17c63b520d0ff050d943baa8055d0ca6', 'hex')
)

const stateManager = new DefaultStateManager({ trie, common })
const vm = new VM({ stateManager, common })

const block = Block.fromBlockData(
{
header: {
// Ensures our fees get added to coinbase after we run the Tx (this is important for the state root in the receipt)
coinbase: Buffer.from('52bc44d5378309ee2abf1539bf71de1b7d7be3b5', 'hex'),
timestamp: 1442117987,
},
},
{ common }
)

await vm.runTx({ tx, block })
const expectedRoot = Buffer.from(
'9d735b19daf3205f93e60f3eb02df6b211aebb4d3a2c512cb51055d8ecfb35c1',
'hex'
)

st.ok(expectedRoot.equals(await vm.stateManager.getStateRoot()), 'state root ok')
st.end()
}
)
})
63 changes: 0 additions & 63 deletions packages/vm/tests/runner.ts

This file was deleted.

0 comments on commit 2017d54

Please sign in to comment.