From 759532479fe4c6ea344b962dc1891bc01ce30651 Mon Sep 17 00:00:00 2001 From: ahmedbodi Date: Thu, 27 Feb 2014 11:04:37 +0000 Subject: [PATCH 1/3] MaxCoin Main Fixes --- lib/halfnode.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/lib/halfnode.py b/lib/halfnode.py index 08aa56d..47f2613 100644 --- a/lib/halfnode.py +++ b/lib/halfnode.py @@ -11,7 +11,6 @@ import sys import random import cStringIO from Crypto.Hash import SHA256 -from sha3 import sha3_256 from twisted.internet.protocol import Protocol from util import * @@ -30,18 +29,12 @@ elif settings.COINDAEMON_ALGO == 'quark': 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 @@ -162,7 +155,8 @@ class CTxOut(object): class CTransaction(object): def __init__(self): - self.sha3 = None + if settings.COINDAEMON_ALGO == 'max': + self.sha3 = None if settings.COINDAEMON_Reward == 'POW': self.nVersion = 1 if settings.COINDAEMON_TX == 'yes': @@ -315,7 +309,6 @@ class CBlock(object): r.append(struct.pack(" Date: Thu, 27 Feb 2014 11:11:31 +0000 Subject: [PATCH 2/3] MaxCoin Main Fixes --- lib/template_registry.py | 44 ++++++++++++---------------------------- 1 file changed, 13 insertions(+), 31 deletions(-) diff --git a/lib/template_registry.py b/lib/template_registry.py index 190110b..c031723 100644 --- a/lib/template_registry.py +++ b/lib/template_registry.py @@ -3,6 +3,7 @@ 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': @@ -11,7 +12,7 @@ elif settings.COINDAEMON_ALGO == 'quark': import quark_hash elif settings.COINDAEMON_ALGO == 'max': import max_hash - from hashlib import sha256 + from sha3 import sha3_256 elif settings.COINDAEMON_ALGO == 'skeinhash': import skeinhash elif settings.COINDAEMON_ALGO == 'keccak': @@ -27,9 +28,6 @@ from mining.interfaces import Interfaces from extranonce_counter import ExtranonceCounter import lib.settings as settings -from sha3 import sha3_256 - - 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.''' @@ -134,8 +132,7 @@ class TemplateRegistry(object): self.update_in_progress = True self.last_update = Interfaces.timestamper.time() - log.debug("calling self.bitcoin_rpc.getblocktemplate()") - d = self.bitcoin_rpc.getblocktemplate() + d = self.bitcoin_rpc.getblocktemplate() d.addCallback(self._update_block) d.addErrback(self._update_block_failed) @@ -145,9 +142,7 @@ class TemplateRegistry(object): def _update_block(self, data): start = Interfaces.timestamper.time() - log.debug("_update_block") - #log.info(template.fill_from_rpc(data)) - 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']) @@ -163,15 +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 == 'max': diff1 = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000 elif settings.COINDAEMON_ALGO == 'keccak': diff1 = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000 else: diff1 = 0x00000000ffff0000000000000000000000000000000000000000000000000000 - return diff1 / difficulty def get_job(self, job_id): @@ -243,9 +235,10 @@ class TemplateRegistry(object): # 1. Build coinbase coinbase_bin = job.serialize_coinbase(extranonce1_bin, extranonce2_bin) - #coinbase_hash = util.doublesha(coinbase_bin) - coinbase_hash = sha256(coinbase_bin).digest() - + 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) @@ -270,9 +263,6 @@ class TemplateRegistry(object): 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_temp = s.hexdigest() - #s = sha3.sha3_256() - #s.update(hash_bin_temp) hash_bin = s.hexdigest() else: hash_bin = util.doublesha(''.join([ header_bin[i*4:i*4+4][::-1] for i in range(0, 20) ])) @@ -307,24 +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': 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() - else: - block_hash_bin = util.doublesha(''.join([ header_bin[i*4:i*4+4][::-1] for i in range(0, 20) ])) - if settings.COINDAEMON_ALGO == 'keccak': + 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) - #hash_bin_temp = s.hexdigest() - #s = sha3.SHA3256() - #s.update(hash_bin_temp) - 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') + 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)) @@ -349,11 +333,9 @@ class TemplateRegistry(object): 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_temp = s.hexdigest() - #s = sha3.sha3_256() - #s.update(hash_bin_temp) 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) ])) + 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: From 2ebb24bac6e13b66f2f9f2680850fd8e4bf035a2 Mon Sep 17 00:00:00 2001 From: ahmedbodi Date: Thu, 27 Feb 2014 11:17:34 +0000 Subject: [PATCH 3/3] MaxCoin Main Fixes --- lib/util.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/util.py b/lib/util.py index 1c2d3e8..35a7051 100644 --- a/lib/util.py +++ b/lib/util.py @@ -6,10 +6,10 @@ import binascii import settings import bitcoin_rpc from hashlib import sha256 -from sha3 import sha3_256 if settings.COINDAEMON_ALGO == 'keccak': import sha3 + from sha3 import sha3_256 def deser_string(f): @@ -184,10 +184,12 @@ def address_to_pubkeyhash(addr): ver = addr[0] cksumA = addr[-4:] - #TODO: We should clean this up so that it works with not Keccek implementations too. - cksumB = sha3_256(addr[:-4]).digest()[: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] - #cksumB = sha3.sha3_256(addr[:-4]).digest()[:4] if cksumA != cksumB: return None