Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid block stateRoot: runBlockchain for very early blocks from Ropsten / Mainnet #587

Closed
whalelephant opened this issue Aug 31, 2019 · 7 comments

Comments

@whalelephant
Copy link

For a simple case: Export blocks from a node (Ropsten / Mainnet) via JSON-rpc (eth_getBlock) and use vm.runBlockchain to run the blocks and transactions.

I have followed the provided example which runs without any issues.

Below is the modified version to run 1 block

async function main() {

  const common = new Common('mainnet', 'chainstart')
  const blockchain = new Blockchain({ common: common, validate: false })
  const vm = new VM({ common:common, blockchain: blockchain })

  await setupPreConditions(vm, testData)    //not neccessary as it is generated in runBlock
  await setGenesisBlock(blockchain, common) //not neccessary as it is generated in runBlock
  await putBlocks(blockchain, common, testData)
  await vm.runBlockchain(blockchain)
}

async function setupPreConditions(vm: VM, testData: any) {
  const psm = new PStateManager(vm.stateManager)
  await psm.generateCanonicalGenesis()
  await psm.checkpoint()
  await psm.commit()
  const sr = await psm.getStateRoot()
}

async function setGenesisBlock(blockchain: any, common: any) {
  const genesisBlock = new Block(testData.genesisBlock, { common: common })
  await promisify(blockchain.putGenesis.bind(blockchain))(genesisBlock)
}

async function putBlocks(blockchain: any, common: any, testData: any) {
  for (const blockData of testData.blocks) {
    const block = new Block(blockData, { common: common})
    await promisify(blockchain.putBlock.bind(blockchain))(block)
  }
}

The testData is below, genesisBlock is the header from the mainnet genesis block and blocks[0] is from block 1 of the network

{
    "blocks" : [
        {
            "header": {
                "author": "0x05a56e2d52c817161883f50c441c3228cfe54d9f",
                "difficulty": "0x3ff800000",
                "extraData": "0x476574682f76312e302e302f6c696e75782f676f312e342e32",
                "gasLimit": "0x1388",
                "gasUsed": "0x0",
                "hash": "0x88e96d4537bea4d9c05d12549907b32561d3bf31f45aae734cdc119f13406cb6",
                "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
                "miner": "0x05a56e2d52c817161883f50c441c3228cfe54d9f",
                "mixHash": "0x969b900de27b6ac6a67742365dd65f55a0526c41fd18e1b16f1a1215c2e66f59",
                "nonce": "0x539bd4979fef1ec4",
                "number": "0x1",
                "parentHash": "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3",
                "receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
                "sealFields": ["0xa0969b900de27b6ac6a67742365dd65f55a0526c41fd18e1b16f1a1215c2e66f59", "0x88539bd4979fef1ec4"],
                "sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
                "size": "0x219",
                "stateRoot": "0xd67e4d450343046425ae4271474353857ab860dbc0a1dde64b41b5cd3a532bf3",
                "timestamp": "0x55ba4224",
                "totalDifficulty": "0x7ff800000",
                "transactionsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"
            },
            "transactions": [], 
            "uncleHeaders": []
        }
            
    ],
    "genesisBlock" : {
        "header": {
            "author": "0x0000000000000000000000000000000000000000",
            "difficulty": "0x400000000",
            "extraData": "0x11bbe8db4e347b4e8c937c1c8370e4b5ed33adb3db69cbdb7a38e1e50b1b82fa",
            "gasLimit": "0x1388",
            "gasUsed": "0x0",
            "hash": "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3",
            "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
            "miner": "0x0000000000000000000000000000000000000000",
            "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
            "nonce": "0x0000000000000042",
            "number": "0x0",
            "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
            "receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
            "sealFields": ["0xa00000000000000000000000000000000000000000000000000000000000000000", "0x880000000000000042"],
            "sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
            "size": "0x21c",
            "stateRoot": "0xd7f8974fb5ac78d9ac099b9ad5018bedc2ce0a72dad1827a1709da30580f0544",
            "timestamp": "0x0",
            "totalDifficulty": "0x400000000",
            "transactionsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
            "uncles": []
        },
        "transactions" : [], 
        "uncleHeaders": []
    }
}

Error
The error produced is Error: invalid block stateRoot. The stateRoot that is set in [here] (https://github.com/ethereumjs/ethereumjs-vm/blob/master/lib/runBlock.ts#L96), before running the block, is the correct genesis state. I have tried different hardforks but the error is the same even though the stateRoots produced were different.

@s1na
Copy link
Contributor

s1na commented Sep 2, 2019

I wouldn't be surprised if early blocks fail. ethereumjs-vm officially supports from the Byzantium hardforks onwards.

@holgerd77
Copy link
Member

We should really keep this a bit on the plate to backport/re-integrate older HFs - should be much more manageable now with all the latest refactorings and optimizations. Just can't prioritize right now with all the Istanbul and other work.

@s1na
Copy link
Contributor

s1na commented Sep 3, 2019

Yeah I won't be able to look into this until Istanbul support is done. Something valuable would be to collect a list of issues that need to be fixed if anyone is interested (@whalelephant maybe?). My guess is that #543 would solve a set of gas-related issues.

@whalelephant
Copy link
Author

whalelephant commented Sep 3, 2019

@s1na : Can I clarify, you think it will be useful to collect a list of all the fixes required to backport old HF?

@s1na
Copy link
Contributor

s1na commented Sep 4, 2019

Yes. I think as a first step it'll be helpful to have an idea which problems there are. Where the VM diverges from the early hardforks' rules. So that we can fix these problems later on.

I think the main problem is the opcode base gas costs. Found this in the developer docs:

VM tests are disabled since Frontier gas costs are not supported any more.

@alcuadrado
Copy link
Member

We should really keep this a bit on the plate to backport/re-integrate older HFs

I also agree that it would be a good thing to support older HFs, and be able to run mainnet's blockchain.

I think the discussion that happened in this -block PR is super relevant here.

@holgerd77
Copy link
Member

Fixed with the v5 releases #962, will close.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants