From 77023030cf8d28e12c514dd06c00dcd450c3998a Mon Sep 17 00:00:00 2001 From: s0n1k Date: Mon, 4 Jun 2018 00:42:15 +0200 Subject: [PATCH 1/6] Add Equihash48_5 Equihash96_3 Equihash96_5 Equihash144_5 Equihash192_7. Rename Equihash to Equihash200_9 --- README.md | 14 +++++----- lib/algoProperties.js | 62 ++++++++++++++++++++++++++++++++++++++++++- lib/jobManager.js | 8 +++--- lib/stratum.js | 5 ++-- package.json | 4 +-- 5 files changed, 79 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index deb1e17..11a0ef5 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,8 @@ 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) +* ✓ __Equihash200_9__ (Zclassic, Zcash) +* ✓ __Equihash192_7__ (LitecoinZ) Requirements ------------ @@ -60,7 +61,7 @@ npm update Create the configuration for your coin: -Possible options for `algorithm`: *equihash*. +Possible options for `algorithm`: *equihash48_5, equihash96_3, equihash96_5, equihash192_7, equihash200_9*. ```javascript var myCoin = { @@ -80,22 +81,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 +359,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..4d1ae15 100644 --- a/lib/algoProperties.js +++ b/lib/algoProperties.js @@ -13,9 +13,69 @@ 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, + solnlength: 202, + hash: function(){ + return function(){ + return ev.verify.apply(this, arguments); + } + } + }, + 'equihash192_7': { + multiplier: 1, + diff: parseInt('0x0007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'), + n: 192, + k: 7, + solnlength: 806, + hash: function(){ + return function(){ + return ev.verify.apply(this, arguments); + } + } + }, + 'equihash200_9': { + multiplier: 1, + diff: parseInt('0x0007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'), + n: 200, + k: 9, + solnlength: 2694, hash: function(){ return function(){ return ev.verify.apply(this, arguments); diff --git a/lib/jobManager.js b/lib/jobManager.js index edf91c4..3d56baa 100644 --- a/lib/jobManager.js +++ b/lib/jobManager.js @@ -209,10 +209,10 @@ var JobManager = module.exports = function JobManager(options) { return shareError([20, 'incorrect size of nonce']); } - if (soln.length !== 2694) { + if (soln.length !== algos[options.coin.algorithm].solnlength) { return shareError([20, 'incorrect size of solution']); } - + if (!isHexString(extraNonce2)) { return shareError([20, 'invalid hex in extraNonce2']); } @@ -237,7 +237,9 @@ 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) { + var n = algos[options.coin.algorithm].n; + var k = algos[options.coin.algorithm].k; + if (hashDigest(headerBuffer, new Buffer(soln.slice(6), '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 } ); diff --git a/package.json b/package.json index 411a951..6878789 100644 --- a/package.json +++ b/package.json @@ -25,10 +25,10 @@ "main": "lib/index.js", "repository": { "type": "git", - "url": "https://github.com/joshuayabut/node-stratum-pool.git" + "url": "https://github.com/litecoinz-project/node-stratum-pool.git" }, "dependencies": { - "equihashverify": "git+https://github.com/zencashofficial/equihashverify.git", + "equihashverify": "git+https://github.com/litecoinz-project/equihashverify.git", "bignum": "*", "base58-native": "*", "async": "*", From d954c0361ac72be6b80de187b7ba5d1d6ec5c669 Mon Sep 17 00:00:00 2001 From: LiteCoinZ <33730928+litecoinz-project@users.noreply.github.com> Date: Wed, 6 Jun 2018 17:49:42 +0200 Subject: [PATCH 2/6] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 11a0ef5..727ede5 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ npm update Create the configuration for your coin: -Possible options for `algorithm`: *equihash48_5, equihash96_3, equihash96_5, equihash192_7, equihash200_9*. +Possible options for `algorithm`: *equihash48_5, equihash96_3, equihash96_5, Equihash144_5, equihash192_7, equihash200_9*. ```javascript var myCoin = { From 0c2d49bd1ed90cc12058d3c76119b92a39dfdc7c Mon Sep 17 00:00:00 2001 From: LiteCoinZ <33730928+litecoinz-project@users.noreply.github.com> Date: Wed, 6 Jun 2018 17:51:48 +0200 Subject: [PATCH 3/6] Update README.md --- README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 727ede5..aeaede6 100644 --- a/README.md +++ b/README.md @@ -38,8 +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: -* ✓ __Equihash200_9__ (Zclassic, Zcash) -* ✓ __Equihash192_7__ (LitecoinZ) +* ✓ __Equihash48_5__ +* ✓ __Equihash96_3__ +* ✓ __Equihash96_5__ +* ✓ __Equihash144_5__ +* ✓ __Equihash192_7__ +* ✓ __Equihash200_9__ + Requirements ------------ From 869b0e28dacb0147d7133068bbde4591feb9f7ec Mon Sep 17 00:00:00 2001 From: LiteCoinZ <33730928+litecoinz-project@users.noreply.github.com> Date: Wed, 6 Jun 2018 17:55:18 +0200 Subject: [PATCH 4/6] Update package.json --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 6878789..411a951 100644 --- a/package.json +++ b/package.json @@ -25,10 +25,10 @@ "main": "lib/index.js", "repository": { "type": "git", - "url": "https://github.com/litecoinz-project/node-stratum-pool.git" + "url": "https://github.com/joshuayabut/node-stratum-pool.git" }, "dependencies": { - "equihashverify": "git+https://github.com/litecoinz-project/equihashverify.git", + "equihashverify": "git+https://github.com/zencashofficial/equihashverify.git", "bignum": "*", "base58-native": "*", "async": "*", From 759c0181d1b46316a2627e9f2ce30ae6514a97c3 Mon Sep 17 00:00:00 2001 From: LiteCoinZ <33730928+litecoinz-project@users.noreply.github.com> Date: Wed, 13 Jun 2018 15:11:58 +0200 Subject: [PATCH 5/6] Embedded solution size --- lib/algoProperties.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/algoProperties.js b/lib/algoProperties.js index 4d1ae15..4f4736e 100644 --- a/lib/algoProperties.js +++ b/lib/algoProperties.js @@ -51,7 +51,6 @@ var algos = module.exports = global.algos = { diff: parseInt('0x0007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'), n: 144, k: 5, - solnlength: 202, hash: function(){ return function(){ return ev.verify.apply(this, arguments); @@ -63,7 +62,6 @@ var algos = module.exports = global.algos = { diff: parseInt('0x0007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'), n: 192, k: 7, - solnlength: 806, hash: function(){ return function(){ return ev.verify.apply(this, arguments); @@ -75,7 +73,6 @@ var algos = module.exports = global.algos = { diff: parseInt('0x0007ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'), n: 200, k: 9, - solnlength: 2694, hash: function(){ return function(){ return ev.verify.apply(this, arguments); From d7d8a5c3bc1ac3752af69bf9a7ff7158104dee63 Mon Sep 17 00:00:00 2001 From: LiteCoinZ <33730928+litecoinz-project@users.noreply.github.com> Date: Wed, 13 Jun 2018 15:16:11 +0200 Subject: [PATCH 6/6] Embedded solution size --- lib/jobManager.js | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/lib/jobManager.js b/lib/jobManager.js index 3d56baa..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 !== algos[options.coin.algorithm].solnlength) { - 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,9 +254,7 @@ var JobManager = module.exports = function JobManager(options) { var blockDiffAdjusted = job.difficulty * shareMultiplier; // check if valid solution - var n = algos[options.coin.algorithm].n; - var k = algos[options.coin.algorithm].k; - if (hashDigest(headerBuffer, new Buffer(soln.slice(6), 'hex'), n, k) !== true) { + if (hashDigest(headerBuffer, new Buffer(soln.slice(solutionSlice), 'hex'), n, k) !== true) { return shareError([20, 'invalid solution']); } //check if block candidate