ethashjs icon indicating copy to clipboard operation
ethashjs copied to clipboard

verify from RPC

Open bit-warrior opened this issue 7 years ago • 1 comments

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)
		})
});

bit-warrior avatar Mar 04 '18 16:03 bit-warrior

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.

holgerd77 avatar Mar 05 '18 12:03 holgerd77