ethereumjs / ethashjs Goto Github PK
View Code? Open in Web Editor NEWProject is in active development and has been moved to the EthereumJS VM monorepo.
License: Mozilla Public License 2.0
Project is in active development and has been moved to the EthereumJS VM monorepo.
License: Mozilla Public License 2.0
Hmm, this library got a bit forgotten (last release 4 (!) years ago sigh), but it is actually actively used as a dependency within the blockchain library to verify POW for a block.
Not sure if it is worth to port to TypeScript
(but on the other hand: why not?) but we should at least give this some maintenance love and update dependencies.
@ryanio Can you do a CI update here?
Eventually the library is also a candidate for a monorepo integration, the blockchain library is actually the only consumer with the EthereumJS ecosystem.
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)
})
});
published version contains console.log
s, please bump to 0.0.4
Hi Ethereum Javascripters,
I'm a web developer who's interested in ethereum in javascript and am very interested in mining with javascript (I know it'll be slower).
While I've read Dagger-hashimoto and a lot of blockchain material, I'm confused with how to use ethashjs.
I see that it says it can be browserified but I have no idea how to actually use it.
I have geth running with jsonrpc enabled and working with curl requests. But I can't figure out what I need from geth in order to run ethashjs.
Perhaps someone here could help me, what should I be doing to try and mine in the browser using ethashjs?
After having slept a night on this I think it would actually a lot of sense to add this to the monorepo.
@evertonfraga What do you think? Would this be a substantial additional integration effort or is this relatively easily doable now?
Follow-up on #20
Tests should be upgraded to the latest test state from the ethereum/tests repository (not sure if necessary though since tests are not updated there for quite some time as well).
Along the ethereumjs-testing
dependency should be removed analogue to e.g. ethereumjs/ethereumjs-block#61, since the dependency is super-heavy (several 100 MBs) and the tests rarely change.
This would be a pre-requisite for #20 (the monorepo part), since we don't want to draw in this dependency within the monorepo.
For debuging
console.log('Ethash.prototype.calcDatasetItem 1');
console.log(mix);
console.log('i:' + i + ' n:' + n + ' r:' + r);
mix.writeInt32LE(mix.readUInt32LE(0) ^ i)
Ethash.prototype.calcDatasetItem 1
<Buffer 62 8e 0a 0d e9 eb 22 c1 0a b0 d7 b3 29 e0 ae f4 f0 b9 f2 5e ef da c5 9d b8 e3 a7 ee 7c 08 66 8a f8 c2 1c 1e b0 13 34 61 4f b9 5a 43 27 24 6d af 1c 86 5c ...>
i:12511692 n:264179 r:16
buffer.js:786
throw TypeError('offset is not uint');
^
Hi,
I'm getting the following error from ethashjs/index.js. The text fullSize, n, w, s and mixhashes are just my additional debugging logs. The problem occurred before I added the debugging information.
block number (hex) 0x1199e1
fullSize : 1392507008
n : 21757922
w : 32
s : ?1w�V��FJ��Ey��[��fj�#��V.
g�)����Bm��eU\y��cB3�?�f�[�� �i�ٗ
mixhashes: 2
/home/beef/BeefPool/node_modules/ethashjs/index.js:60
var mix = Buffer.concat(Array(mixhashes).fill(s))
^
TypeError: Object , has no method 'fill'
at Ethash.run (/home/beef/BeefPool/node_modules/ethashjs/index.js:60:44)
at /home/beef/BeefPool/shareHandler.js:43:19
at Object._onImmediate (/home/beef/BeefPool/node_modules/ethashjs/node_modules/levelup/lib/levelup.js:258:9)
at processImmediate as _immediateCallback
The snippet from ethashjs/index.js modified with my debugging information:
Ethash.prototype.run = function (val, nonce, fullSize) {
fullSize = fullSize || this.fullSize
console.log("fullSize : " + fullSize);
const n = Math.floor(fullSize / ethHashUtil.params.HASH_BYTES)
console.log("n : " + n);
const w = Math.floor(ethHashUtil.params.MIX_BYTES / ethHashUtil.params.WORD_BYTES)
console.log("w : " + w);
const s = ethUtil.sha3(Buffer.concat([val, ethHashUtil.bufReverse(nonce)]), 512)
console.log("s : " + s);
const mixhashes = Math.floor(ethHashUtil.params.MIX_BYTES / ethHashUtil.params.HASH_BYTES)
console.log("mixhashes: " + mixhashes);
var mix = Buffer.concat(Array(mixhashes).fill(s))
This library is very sparely tests, both with running tests on real world block data as well as testing the different algorithm components.
Maybe some test data from go-ethereum
can be used to improve test coverage:
https://github.com/ethereum/go-ethereum/blob/master/consensus/ethash/algorithm_test.go
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.