Compare commits

...

10 Commits

Author SHA1 Message Date
ahmedbodi
094f8d464d Merge pull request #2 from ahmedbodi/master
Cleanup
2014-02-27 11:46:45 +00:00
ahmedbodi
e15f45ac95 Merge pull request #1 from Crypto-Expert/maxcoin
Maxcoin
2014-02-27 11:45:54 +00:00
ahmedbodi
2ebb24bac6 MaxCoin Main Fixes 2014-02-27 11:17:34 +00:00
ahmedbodi
2ed1bec0b4 MaxCoin Main Fixes 2014-02-27 11:11:31 +00:00
ahmedbodi
759532479f MaxCoin Main Fixes 2014-02-27 11:04:37 +00:00
ahmedbodi
098c99c3a1 Update bitcoin_rpc.py 2014-02-08 16:59:37 +00:00
ahmedbodi
e9d8e34ab4 MaxCoin 2014-02-08 15:47:47 +00:00
ahmedbodi
f5ee1f0b69 Update template_registry.py 2014-02-08 15:39:39 +00:00
ahmedbodi
5eb505331f MaxCoin 2014-02-08 15:38:13 +00:00
root
3c4f9d4537 Added MaxCoin Hash 2014-02-08 16:18:53 +01:00
7 changed files with 124 additions and 29 deletions

3
.gitmodules vendored
View File

@ -10,3 +10,6 @@
[submodule "externals/quarkcoin-hash"]
path = externals/quarkcoin-hash
url = https://github.com/Neisklar/quarkcoin-hash-python
[submodule "externals/maxcoin-hash-python"]
path = externals/maxcoin-hash-python
url = https://github.com/Prydie/maxcoin-hash-python

1
externals/maxcoin-hash-python vendored Submodule

@ -0,0 +1 @@
Subproject commit 30cfcd105ae2914ae12b750ae7471e27f79c28ed

View File

@ -34,6 +34,8 @@ class BitcoinRPC(object):
)
def _call(self, method, params):
#log.debug("RPC Call: %s" % json.dumps({'jsonrpc': '2.0', 'method':
#method,'params': params,'id': '1'}))
return self._call_raw(json.dumps({
'jsonrpc': '2.0',
'method': method,

View File

@ -26,16 +26,15 @@ if settings.COINDAEMON_ALGO == 'scrypt':
elif settings.COINDAEMON_ALGO == 'quark':
log.debug("########################################### Loading Quark Support #########################################################")
import quark_hash
elif settings.COINDAEMON_ALGO == 'max':
log.debug("########################################### Loading Max Support #########################################################")
import max_hash
from sha3 import sha3_256
elif settings.COINDAEMON_ALGO == 'keccak':
import sha3
else:
log.debug("########################################### Loading SHA256 Support ######################################################")
#if settings.COINDAEMON_Reward == 'POS':
# log.debug("########################################### Loading POS Support #########################################################")
# pass
#else:
# log.debug("########################################### Loading POW Support ######################################################")
# pass
if settings.COINDAEMON_TX == 'yes':
log.debug("########################################### Loading SHA256 Transaction Message Support #########################################################")
pass
@ -156,6 +155,8 @@ class CTxOut(object):
class CTransaction(object):
def __init__(self):
if settings.COINDAEMON_ALGO == 'max':
self.sha3 = None
if settings.COINDAEMON_Reward == 'POW':
self.nVersion = 1
if settings.COINDAEMON_TX == 'yes':
@ -239,6 +240,10 @@ class CBlock(object):
self.scrypt = None
elif settings.COINDAEMON_ALGO == 'quark':
self.quark = None
elif settings.COINDAEMON_ALGO == 'max':
self.max = None
elif settings.COINDAEMON_ALGO == 'keccak':
self.sha3 = None
else: pass
if settings.COINDAEMON_Reward == 'POS':
self.signature = b""
@ -294,6 +299,36 @@ class CBlock(object):
r.append(struct.pack("<I", self.nNonce))
self.quark = uint256_from_str(quark_hash.getPoWHash(''.join(r)))
return self.quark
elif settings.COINDAEMON_ALGO == 'max':
def calc_max(self):
if self.max is None:
r = []
r.append(struct.pack("<i", self.nVersion))
r.append(ser_uint256(self.hashPrevBlock))
r.append(ser_uint256(self.hashMerkleRoot))
r.append(struct.pack("<I", self.nTime))
r.append(struct.pack("<I", self.nBits))
r.append(struct.pack("<I", self.nNonce))
self.max = uint256_from_str(sha3_256(''.join(r)).digest())
return self.max
elif settings.COINDAEMON_ALGO == 'keccak':
def calc_sha3(self):
if self.sha3 is None:
r = []
r.append(struct.pack("<i", self.nVersion))
r.append(ser_uint256(self.hashPrevBlock))
r.append(ser_uint256(self.hashMerkleRoot))
r.append(struct.pack("<I", self.nTime))
r.append(struct.pack("<I", self.nBits))
r.append(struct.pack("<I", self.nNonce))
s = sha3.SHA3256()
s.update(''.join(r) + str(self.nTime))
# hash_bin_temp = s.hexdigest()
# s = sha3.SHA3256()
# s.update(hash_bin_temp)
block_hash_bin = s.hexdigest()
self.sha3 = uint256_from_str(block_hash_bin)
return self.sha3
else:
def calc_sha256(self):
if self.sha256 is None:
@ -313,6 +348,10 @@ class CBlock(object):
self.calc_scrypt()
elif settings.COINDAEMON_ALGO == 'quark':
self.calc_quark()
elif settings.COINDAEMON_ALGO == 'max':
self.calc_max()
elif settings.COINDAEMON_ALGO == 'keccak':
self.calc_sha3()
else:
self.calc_sha256()
@ -324,6 +363,12 @@ class CBlock(object):
elif settings.COINDAEMON_ALGO == 'quark':
if self.quark > target:
return False
elif settings.COINDAEMON_ALGO == 'max':
if self.max > target:
return False
elif settings.COINDAEMON_ALGO == 'sha3':
if self.sha3 > target:
return False
else:
if self.sha256 > target:
return False

View File

@ -3,18 +3,24 @@ import binascii
import util
import StringIO
import settings
from hashlib import sha256
if settings.COINDAEMON_ALGO == 'scrypt':
import ltc_scrypt
elif settings.COINDAEMON_ALGO == 'scrypt-jane':
import yac_scrypt
elif settings.COINDAEMON_ALGO == 'quark':
import quark_hash
elif settings.COINDAEMON_ALGO == 'max':
import max_hash
from sha3 import sha3_256
elif settings.COINDAEMON_ALGO == 'skeinhash':
import skeinhash
elif settings.COINDAEMON_ALGO == 'keccak':
import sha3
else: pass
from twisted.internet import defer
from lib.exceptions import SubmitException
import lib.logger
log = lib.logger.get_logger('template_registry')
log.debug("Got to Template Registry")
@ -22,7 +28,6 @@ from mining.interfaces import Interfaces
from extranonce_counter import ExtranonceCounter
import lib.settings as settings
class JobIdGenerator(object):
'''Generate pseudo-unique job_id. It does not need to be absolutely unique,
because pool sends "clean_jobs" flag to clients and they should drop all previous jobs.'''
@ -126,8 +131,8 @@ class TemplateRegistry(object):
self.update_in_progress = True
self.last_update = Interfaces.timestamper.time()
d = self.bitcoin_rpc.getblocktemplate()
d = self.bitcoin_rpc.getblocktemplate()
d.addCallback(self._update_block)
d.addErrback(self._update_block_failed)
@ -137,8 +142,7 @@ class TemplateRegistry(object):
def _update_block(self, data):
start = Interfaces.timestamper.time()
template = self.block_template_class(Interfaces.timestamper, self.coinbaser, JobIdGenerator.get_new_id())
template = self.block_template_class(Interfaces.timestamper, self.coinbaser, JobIdGenerator.get_new_id())
log.info(template.fill_from_rpc(data))
self.add_template(template,data['height'])
@ -154,9 +158,12 @@ class TemplateRegistry(object):
diff1 = 0x0000ffff00000000000000000000000000000000000000000000000000000000
elif settings.COINDAEMON_ALGO == 'quark':
diff1 = 0x000000ffff000000000000000000000000000000000000000000000000000000
elif settings.coindaemon_algo == 'max':
diff1 = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000
elif settings.COINDAEMON_ALGO == 'keccak':
diff1 = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000
else:
diff1 = 0x00000000ffff0000000000000000000000000000000000000000000000000000
return diff1 / difficulty
def get_job(self, job_id):
@ -228,7 +235,10 @@ class TemplateRegistry(object):
# 1. Build coinbase
coinbase_bin = job.serialize_coinbase(extranonce1_bin, extranonce2_bin)
coinbase_hash = util.doublesha(coinbase_bin)
if settings.COINDAEMON_ALGO == 'max':
coinbase_hash = sha256(coinbase_bin).digest()
else:
coinbase_hash = util.doublesha(coinbase_bin)
# 2. Calculate merkle root
merkle_root_bin = job.merkletree.withFirst(coinbase_hash)
@ -244,9 +254,17 @@ class TemplateRegistry(object):
hash_bin = yac_scrypt.getPoWHash(''.join([ header_bin[i*4:i*4+4][::-1] for i in range(0, 20) ]), int(ntime, 16))
elif settings.COINDAEMON_ALGO == 'quark':
hash_bin = quark_hash.getPoWHash(''.join([ header_bin[i*4:i*4+4][::-1] for i in range(0, 20) ]))
elif settings.COINDAEMON_ALGO == 'max':
hash_bin = max_hash.getPoWHash(''.join([ header_bin[i*4:i*4+4][::-1] for i in range(0, 20) ]))
hash_bin = sha3_256(''.join([ header_bin[i*4:i*4+4][::-1] for i in range(0, 20) ])).digest()[0:33]
elif settings.COINDAEMON_ALGO == 'skeinhash':
hash_bin = skeinhash.skeinhash(''.join([ header_bin[i*4:i*4+4][::-1] for i in range(0, 20) ]))
else:
elif settings.COINDAEMON_ALGO == 'keccak':
s = sha3.sha3_256()
ntime1 = str(int(ntime, 16))
s.update(''.join([ header_bin[i*4:i*4+4][::-1] for i in range(0, 20) ]) + ntime1)
hash_bin = s.hexdigest()
else:
hash_bin = util.doublesha(''.join([ header_bin[i*4:i*4+4][::-1] for i in range(0, 20) ]))
hash_int = util.uint256_from_str(hash_bin)
@ -256,11 +274,14 @@ class TemplateRegistry(object):
header_hex = header_hex+"000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000"
elif settings.COINDAEMON_ALGO == 'quark':
header_hex = header_hex+"000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000"
#elif settings.COINDAEMON_ALGO == 'max':
#header_hex = header_hex+"000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000"
else: pass
target_user = self.diff_to_target(difficulty)
if hash_int > target_user:
raise SubmitException("Share is above target")
raise SubmitException("Share is above target. Hash: %s",
scrypt_hash_hex)
# Mostly for debugging purposes
target_info = self.diff_to_target(100000)
@ -276,12 +297,18 @@ class TemplateRegistry(object):
log.info("We found a block candidate! %s" % scrypt_hash_hex)
# Reverse the header and get the potential block hash (for scrypt only)
#if settings.COINDAEMON_ALGO == 'scrypt' or settings.COINDAEMON_ALGO == 'sha256d':
# if settings.COINDAEMON_Reward == 'POW':
block_hash_bin = util.doublesha(''.join([ header_bin[i*4:i*4+4][::-1] for i in range(0, 20) ]))
if settings.COINDAEMON_ALGO == 'max':
block_hash_bin = sha3_256(''.join([ header_bin[i*4:i*4+4][::-1]
for i in range(0, 20) ]) + str(int(ntime, 16))).hexdigest()
elif settings.COINDAEMON_ALGO == 'keccak':
s = sha3.SHA3256()
ntime1 = str(int(ntime, 16))
s.update(''.join([ header_bin[i*4:i*4+4][::-1] for i in range(0, 20) ]) + ntime1)
else:
block_hash_bin = util.doublesha(''.join([ header_bin[i*4:i*4+4][::-1] for i in range(0, 20) ]))
block_hash_hex = block_hash_bin[::-1].encode('hex_codec')
#else: block_hash_hex = hash_bin[::-1].encode('hex_codec')
#else: block_hash_hex = hash_bin[::-1].encode('hex_codec')
if settings.COINDAEMON_ALGO != 'max':
block_hash_hex = hash_bin[::-1].encode('hex_codec')
# 6. Finalize and serialize block object
job.finalize(merkle_root_int, extranonce1_bin, extranonce2_bin, int(ntime, 16), int(nonce, 16))
@ -291,7 +318,7 @@ class TemplateRegistry(object):
# 7. Submit block to the network
serialized = binascii.hexlify(job.serialize())
on_submit = self.bitcoin_rpc.submitblock(serialized, block_hash_hex, scrypt_hash_hex)
on_submit = self.bitcoin_rpc.submitblock(serialized, block_hash_hex, scrypt_hash_hex)
if on_submit:
self.update_block()
@ -302,8 +329,14 @@ class TemplateRegistry(object):
if settings.SOLUTION_BLOCK_HASH:
# Reverse the header and get the potential block hash (for scrypt only) only do this if we want to send in the block hash to the shares table
block_hash_bin = util.doublesha(''.join([ header_bin[i*4:i*4+4][::-1] for i in range(0, 20) ]))
block_hash_hex = block_hash_bin[::-1].encode('hex_codec')
return (header_hex, block_hash_hex, share_diff, None)
if settings.COINDAEMON_ALGO == 'keccak':
s = sha3.sha3_256()
ntime1 = str(int(ntime, 16))
s.update(''.join([ header_bin[i*4:i*4+4][::-1] for i in range(0, 20) ]) + ntime1)
block_hash_bin = s.hexdigest()
else:
block_hash_bin = util.doublesha(''.join([ header_bin[i*4:i*4+4][::-1] for i in range(0, 20) ]))
block_hash_hex = block_hash_bin[::-1].encode('hex_codec')
return (header_hex, block_hash_hex, share_diff, None)
else:
return (header_hex, scrypt_hash_hex, share_diff, None)

View File

@ -7,6 +7,11 @@ import settings
import bitcoin_rpc
from hashlib import sha256
if settings.COINDAEMON_ALGO == 'keccak':
import sha3
from sha3 import sha3_256
def deser_string(f):
nit = struct.unpack("<B", f.read(1))[0]
if nit == 253:
@ -176,14 +181,19 @@ def address_to_pubkeyhash(addr):
if addr is None:
return None
ver = addr[0]
cksumA = addr[-4:]
cksumB = doublesha(addr[:-4])[:4]
if settings.COINDAEMON_ALGO != 'max':
cksumB = doublesha(addr[:-4])[:4]
#TODO: We should clean this up so that it works with not Keccek implementations too.
else:
cksumB = sha3_256(addr[:-4]).digest()[:4]
if cksumA != cksumB:
return None
return (ver, addr[1:-4])
def ser_uint256_be(u):

1
maxcoin-hash-python Submodule

@ -0,0 +1 @@
Subproject commit 30cfcd105ae2914ae12b750ae7471e27f79c28ed