diff --git a/README.md b/README.md index deb1e17..aeaede6 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,13 @@ Features * When started with a coin deamon that hasn't finished syncing to the network it shows the blockchain download progress and initializes once synced #### Hashing algorithms supported: -* ✓ __Equihash__ (Zclassic, Zcash) +* ✓ __Equihash48_5__ +* ✓ __Equihash96_3__ +* ✓ __Equihash96_5__ +* ✓ __Equihash144_5__ +* ✓ __Equihash192_7__ +* ✓ __Equihash200_9__ + Requirements ------------ @@ -60,7 +66,7 @@ npm update Create the configuration for your coin: -Possible options for `algorithm`: *equihash*. +Possible options for `algorithm`: *equihash48_5, equihash96_3, equihash96_5, Equihash144_5, equihash192_7, equihash200_9*. ```javascript var myCoin = { @@ -80,22 +86,22 @@ var myCoin = { }; ``` -If you are an equihash coin that doesn't have any founder's rewards, +If you are an equihash (n=200, k=9) coin that doesn't have any founder's rewards, ```javascript var myCoin = { "name": "Zclassic", "symbol": "ZCL", - "algorithm": "equihash", + "algorithm": "equihash200_9", }; ``` -If you are using an equihash coin that has founder's rewards, you need to include details about the FR system, +If you are using an equihash (n=200, k=9) coin that has founder's rewards, you need to include details about the FR system, ```javascript var myCoin = { "name": "zcash_testnet", "symbol": "taz", - "algorithm": "equihash", + "algorithm": "equihash200_9", "payFoundersReward": true, "percentFoundersReward": 20, @@ -358,6 +364,7 @@ Credits * [viperaus](//github.com/viperaus/stratum-mining) - scrypt adaptions to python code * [ahmedbodi](//github.com/ahmedbodi/stratum-mining) - more algo adaptions to python code * [steveshit](//github.com/steveshit) - ported X11 hashing algo from python to node module +* [litecoinz](//github.com/litecoinz-project) - add equihash48_5, equihash96_3, equihash96_5 and equihash192_7 support Donations diff --git a/lib/algoProperties.js b/lib/algoProperties.js index f2375e8..4f4736e 100644 --- a/lib/algoProperties.js +++ b/lib/algoProperties.js @@ -13,9 +13,66 @@ var algos = module.exports = global.algos = { } } }, - 'equihash': { + 'equihash48_5': { multiplier: 1, diff: parseInt('0x0007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'), + n: 48, + k: 5, + hash: function(){ + return function(){ + return ev.verify.apply(this, arguments); + } + } + }, + 'equihash96_3': { + multiplier: 1, + diff: parseInt('0x0007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'), + n: 96, + k: 3, + hash: function(){ + return function(){ + return ev.verify.apply(this, arguments); + } + } + }, + 'equihash96_5': { + multiplier: 1, + diff: parseInt('0x0007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'), + n: 96, + k: 5, + hash: function(){ + return function(){ + return ev.verify.apply(this, arguments); + } + } + }, + 'equihash144_5': { + multiplier: 1, + diff: parseInt('0x0007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'), + n: 144, + k: 5, + hash: function(){ + return function(){ + return ev.verify.apply(this, arguments); + } + } + }, + 'equihash192_7': { + multiplier: 1, + diff: parseInt('0x0007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'), + n: 192, + k: 7, + hash: function(){ + return function(){ + return ev.verify.apply(this, arguments); + } + } + }, + 'equihash200_9': { + multiplier: 1, + diff: parseInt('0x0007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'), + n: 200, + k: 9, hash: function(){ return function(){ return ev.verify.apply(this, arguments); diff --git a/lib/jobManager.js b/lib/jobManager.js index edf91c4..7614d16 100644 --- a/lib/jobManager.js +++ b/lib/jobManager.js @@ -209,10 +209,27 @@ var JobManager = module.exports = function JobManager(options) { return shareError([20, 'incorrect size of nonce']); } - if (soln.length !== 2694) { - return shareError([20, 'incorrect size of solution']); + var n = algos[options.coin.algorithm].n; + var k = algos[options.coin.algorithm].k; + + // Default n=200, k=0 + var expectedLength = 2694; + var solutionSlice = 6; + + if ((n == 200) && (k == 9)) { + expectedLength = 2694; + solutionSlice = 6; + } else if ((n == 144) && (k == 5)) { + expectedLength = 202; + solutionSlice = 2; + } else if ((n == 192) && (k == 7)) { + expectedLength = 806; + solutionSlice = 6; } - + + if (soln.length !== expectedLength) { + return shareError([20, 'Error: Incorrect size of solution (' + soln.length + '), expected ' + expectedLength]); + if (!isHexString(extraNonce2)) { return shareError([20, 'invalid hex in extraNonce2']); } @@ -237,7 +254,7 @@ var JobManager = module.exports = function JobManager(options) { var blockDiffAdjusted = job.difficulty * shareMultiplier; // check if valid solution - if (hashDigest(headerBuffer, new Buffer(soln.slice(6), 'hex')) !== true) { + if (hashDigest(headerBuffer, new Buffer(soln.slice(solutionSlice), 'hex'), n, k) !== true) { return shareError([20, 'invalid solution']); } //check if block candidate diff --git a/lib/stratum.js b/lib/stratum.js index 0bb096a..43c9fbc 100644 --- a/lib/stratum.js +++ b/lib/stratum.js @@ -291,7 +291,7 @@ var StratumClient = function(options){ _this.difficulty = difficulty; //powLimit * difficulty - var powLimit = algos.equihash.diff; // TODO: Get algos object from argument + var powLimit = algos[options.coin.algorithm].diff; // TODO: Get algos object from argument var adjPow = powLimit / difficulty; if ((64 - adjPow.toString(16).length) === 0) { var zeroPad = ''; @@ -399,7 +399,8 @@ var StratumServer = exports.Server = function StratumServer(options, authorizeFn socket: socket, banning: options.banning, connectionTimeout: options.connectionTimeout, - tcpProxyProtocol: options.tcpProxyProtocol + tcpProxyProtocol: options.tcpProxyProtocol, + coin: options.coin } );