Skip to content
This repository has been archived by the owner on Dec 10, 2020. It is now read-only.

verify from RPC #16

Open
bit-warrior opened this issue Mar 4, 2018 · 1 comment
Open

verify from RPC #16

bit-warrior opened this issue Mar 4, 2018 · 1 comment

Comments

@bit-warrior
Copy link

Why is this block not verifying using ethhash

var Promise= require('bluebird');
var Web3 = require('web3');
var web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
const ethUtil = require('ethereumjs-util')
const Ethash = require('ethashjs')
const Block = require('ethereumjs-block')
const levelup = require('levelup')
const memdown = require('memdown')
const rlp = require('rlp')
const fromrpc=require('./from-rpc.js')
var cacheDB = levelup('', {
  db: memdown
})


var ethash = new Ethash(cacheDB);

  web3.eth.getBlock(220).then(function(data) {

		  	console.log(data)

		        var validblock = new fromrpc(data)
		ethash.verifyPOW(validblock, function (result) {
		  console.log(result)
		})
});
@holgerd77
Copy link
Member

holgerd77 commented Mar 5, 2018

Hi, I'm not the maintainer of this library, but had a short look into this and can confirm that PoW mixHash is not verified within this example, not sure about the reason though.

Here is a modified code snippet of the example above which can be run directly from this library for further debugging:

var Promise= require('bluebird')
var Web3 = require('web3')
var web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"))
const ethUtil = require('ethereumjs-util')
const Ethash = require('./index.js')
const Block = require('ethereumjs-block')
const levelup = require('levelup')
const memdown = require('memdown')
const rlp = require('rlp')
const fromrpc = require('ethereumjs-block/from-rpc.js')
var cacheDB = levelup('', {
  db: memdown
})


var ethash = new Ethash(cacheDB)

web3.eth.getBlock(220).then(function(data) { 
  var validBlock = new fromrpc(data)
  console.log(data)
  ethash.verifyPOW(validBlock, function (result) {
    console.log(result)
  })
})

Testing requires a running geth node (or other), e.g. with (after having synced to block 220):

geth --rpc --syncmode="full" --maxpeers=0

Also these libraries have to be installed manually:

npm install bluebird --no-save
npm install web3 --no-save

Verification already fails when trying to verify the main block header (not the uncles), on this comparison both boolean values are evaluated as false.

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

No branches or pull requests

2 participants