Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate equihash solution <n, k> #35

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
------------
Expand All @@ -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 = {
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down
59 changes: 58 additions & 1 deletion lib/algoProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
25 changes: 21 additions & 4 deletions lib/jobManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions lib/stratum.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';
Expand Down Expand Up @@ -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
}
);

Expand Down